EOSIO / eosjs-ecc

Elliptic curve cryptography functions: Private Key, Public Key, Signature, AES, Encryption, Decryption
288 stars 119 forks source link

Creating Address from my own Mnemonic/Seed #14

Closed johnconger closed 6 years ago

johnconger commented 6 years ago
let bip39 = require('bip39');

let {PrivateKey, PublicKey} = require('eosjs-ecc')

let privateWif;
let Address;

let sampleMnemonic = "fun swamp jump history obvious scare struggle deputy cannon village buzz state power play expose moral million lift gravity size chalk grocery scout toss";
let seed = bip39.mnemonicToSeed(sampleMnemonic); 
const privateKey = PrivateKey.fromBuffer(seed);
 privateWif = privateKey.toWif() 
 Address = PrivateKey.fromWif(privateWif).toPublic().toString();
 console.log("Your EOS Seed Address:" + Address);
 console.log("Your Private Key:" + privateWif);

The above code creates a consistent Address & Private Key, but when passing my seed into the Buffer I get a warning message that my buffer is 64 bytes and the fromBuffer() is expecting 32. I can see from this post: https://github.com/EOSIO/eosjs-ecc/issues/7 that I need to divide my seed into a chain code? but I don't see how that is possible.

jcalfee commented 6 years ago

You should probably hash with something after the mnemonic seed to make sure it is both the correct size and unique to EOS..

This is more like a spec, you could just take part of this and use it: https://github.com/EOSIO/eosjs-ecc/issues/7#issuecomment-383617273

dengzz commented 6 years ago

Could use this one for EOS keys?

const hdkey = require('hdkey') const wif = require('wif') const ecc = require('eosjs-ecc') const bip39 = require('bip39') const mnemonic = 'real flame win provide layer trigger soda erode upset rate beef wrist fame design merit' const seed = bip39.mnemonicToSeedHex(mnemonic) const master = hdkey.fromMasterSeed(Buffer(seed, 'hex')) const node = master.derive("m/44'/194'/0'/0/0") console.log("publicKey: "+ecc.PublicKey(node._publicKey).toString()) console.log("privateKey: "+wif.encode(128, node._privateKey, false))

result: publicKey: EOS61oRAVkx1rqPM8mEsBZxPAFAa9Nm6kLa7mQs6mRKTsRTFQaad7 privateKey: 5KX4T16FtxG9LvRJukA31TP9BKq3jYve3xQ3Px3ui8mzuJ7nUYE

jcalfee commented 6 years ago

In my opinion, HD Keys are better suited for change addresses. EOS does not have change addresses.

dengzz commented 6 years ago

could use this one to generate EOS keys for EOSTM Token Distribution?

cdlgz commented 6 years ago

Up, I have the same question.