marvinroger / nanocurrency-js

🔗 A toolkit for the Nano cryptocurrency, allowing you to derive keys, generate seeds, hashes, signatures, proofs of work and blocks.
https://marvinroger.github.io/nanocurrency-js
141 stars 31 forks source link

Generate seed from mnemonic #55

Open imerkle opened 5 years ago

rokanost commented 5 years ago

I generate my seed with:

 let seedBuffer = bip39.mnemonicToSeed(MNEMONIC_PRIVATE_SEED);
 let seed = Buffer.from(seedBuffer).toString('hex');

However, in new version checkSeed() is failing. The length of my seed is 128 characters and maximum allowed for deriveSecretKey() is 64 :/

marvinroger commented 5 years ago

@rokanost what if you comment that line? https://github.com/marvinroger/nanocurrency-js/blob/a8d794af0242b0de64e0e7f3295a8f33106b217f/src/keys.ts#L41

If it's as simple as feeding the blake2b hash with a 128 chars seed instead of a 64 one, it would be easy to be compatible.

rokanost commented 5 years ago

I did comment it out and everything seems fine, but tx now fails on publish with “bad work”

marvinroger commented 5 years ago

Do you generate the work against the previous block hash? If this is the first block on the account chain, you have to use the account's public key.

rokanost commented 5 years ago

All good now, had a little bug in my code.

marvinroger commented 5 years ago

Alright, so it's a bit more complicated than that.

We can't generate a nano seed from a BIP39 mnemonic phrase. We can however derive private keys from the mnemonic phrase with the BIP39 derivation path 44'/165'/0', 0 being the account index.

See https://github.com/nanocurrency/nano-node/wiki/Mnemonic-Seed