Closed adyvaishnav closed 4 years ago
Please use deserializeHexStr
.
cf. https://github.com/herumi/bls-wasm/blob/master/test.js#L34-L53
Hi Herumi, I went through the solution you suggested but still I am not sure, how we are using the mnemonic or seed for generating the keys(public and private keys).
Can you give me an example where you generate the same keys with a mnemonic.
Let's say, we have this mnemonic:
gloom member visual join oxygen velvet major mail zone select couch luxury
Where can I put this mnemonic in my code to get the same keys if I use the same mnemonic:
const blsSecret = new bls.SecretKey();
blsSecret.setByCSPRNG()
key = blsSecret.getPublicKey().serializeToHexStr();
sKey = blsSecret.serializeToHexStr();
how we are using the mnemonic or seed for generating the keys(public and private keys).
This library does not provide a feature generating a secret from a password. Please use PBKDF2 such as https://www.npmjs.com/package/pbkdf2 .
const pbkdf2 = require('pbkdf2')
const key = pbkdf2.pbkdf2Sync('password', 'salt', 100000, 32, 'sha256')
const sec = new bls.SecretKey()
sec.setLittleEndianMod(key)
pub = sec.getPublicKey()
I failed to understand your question. I'm sorry.
Is there any way in bls-wasm to recover keys from a mnemonic/seed.
The current version does not support the feature.
I'll add the function to set crypto.getRandomValues
in bls.js by user-random-generator.
Please wait a moment.
I've added bls.setRandFunc(f)
at https://github.com/herumi/bls-wasm/commit/b326c3fa8bb13abb58e4b3db7752e0cc9d45bc5f , where f is a function that takes an array and fills it with random numbers.
I've added
bls.setRandFunc(f)
at b326c3f , where f is a function that takes an array and fills it with random numbers.
Can you give an example, how this can be used to generate keys (public and private) with a mnemonic/seed?
What module do you want to use for mnemonic/seed?
For example, for bip39, I think that it is better to use setLittleEndianMod instead of setRandFunc.
const bip39 = require('bip39')
const m = bip39.generateMnemonic()
const sec = new bls.SecretKey()
sec.setLittleEndianMod(bip39.mnemonicToSeedSync('abc'))
const pub = sec.getPublicKey()
Thanks for the solution herumi. Actually we will be having mnemonic as a string given by the user, We are implementing recover wallet functionality. Yes we will be using bip39 to generate the mnemonic.
Thanks Herumi, the solution is working for me.
Is there any way in bls-wasm to recover keys from a mnemonic/seed. I saw the bls-go package also and there I found, we can recover keys like this:
Currently, I am generating keys like this:
but not sure, how we can use mnemonic to get/recover the keys?