herumi / mcl-wasm

59 stars 18 forks source link

Export generator for G1 #2

Closed noot closed 5 years ago

noot commented 5 years ago

There is no generator point exported for G1 or G2, if there was it would be simpler to perform scalar base multiplications. Please consider adding it!

herumi commented 5 years ago

G1 and G2 have setHashOf(string) method, which generates a point of G1 and G2, respectively. How about it?

noot commented 5 years ago

Sorry, I should have been more specific! I mean a way to get the fixed base point of G1 or G2 for a given curve. For example, if we want to do P = x*G to make a public key, where G is the base point.

herumi commented 5 years ago

There is no special base point. You can decide a base point freely. For example, if you decide to use G generated by G.setHashOf('0') in your system, then G is the fixed base point.

noot commented 5 years ago

Okay thank you! Which function would I use if I have a integer number that I want to set as the base point? As seen here: https://github.com/zkcrypto/pairing/tree/master/src/bls12_381#g1

I have tried deserializeHexStrToG1 but I'm not sure what the correct formatting is.

herumi commented 5 years ago

Please use setStr('1 <x> <y>') as the followings.

mcl.init(mcl.BLS12_381)

const P = new mcl.G1()
P.setStr('1 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569')

const Q = new mcl.G2()
Q.setStr('1 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582')

For Q, the value of x = a*u + b in zkcrypto is described as b a in my library.

noot commented 5 years ago

Thank you so much! This was very helpful :)