fromPhrase(phrase, path?)
Feature
Generate a key pair from given mnemonic phrase using the HD wallet method.
Parameters
string
phrase, // mnemonic phrase obtained when executed hdKey()
string
| undefined
path (optional) // derivation path for HD wallet.
Return Value
object
HDAccount {
privatekey
: private key,
publickey
: public key,
address
: address,
phrase
: phrases made up of 12 mnemonic words,
path
: derivation path for HD wallet. Default set to "m/44'/815'/0'/0/0"
}
example
// restore key pair from given mnemonic phrase
const keypair1 = {
privatekey: '210a0059a40d142f558f4fbbbedfd657b9bf40e7f00ea0cedf434bf852c158acfpr',
publickey: '02b54452bf9ddb4bee7e9a7e183185b7e5545369dbade0329c57df5403701ca659fpu',
address: '0x2156f81F51b22be742187E313248bc429e97825Efca',
phrase: 'visa cash blossom vote shuffle enhance dizzy moon worth split outside ensure',
path: "m/44'/815'/0'/0/0"
}
const mnmonic_keypair1 = 'visa cash blossom vote shuffle enhance dizzy moon worth split outside ensure';
const restored_keypair1 = mitum.account.fromPhrase(mnmonic_keypair1);
console.log(keypair1.address === restored_keypair1.address);
// output
true
// restore 10 accounts using fromPhrase()
const N = 10;
const mnemonic = 'visa cash blossom vote shuffle enhance dizzy moon worth split outside ensure';
for (let i=0; i<N; i++) {
const keypair = mitum.account.fromPhrase(mnemonic, `m/44'/815'/0'/0/${i}`)
console.log(`${i}th account address: ${keypair.address}`)
}
// output
0th account address: 0x2156f81F51b22be742187E313248bc429e97825Efca
1th account address: 0xd1C1971518BE876739f7F343fb648bF54B760d2ffca
2th account address: 0xE3D4FBD1e9735c7Ad937345E41b1bc2a6711a5edfca
3th account address: 0xDd16727f6b2b1319E35773Ed2E6ed313c26a1c18fca
4th account address: 0xeaD8e6e44600171F3671dc1204A2cF53243A89bFfca
5th account address: 0xd7A961dc8b0a95677Ae3894BB699f58D4a447042fca
6th account address: 0x7cE5bF670c5fd98565355Ec1F96078b69FAB564dfca
7th account address: 0x9593da1C6a210fBd7a629E34B3b51F8D9f94f678fca
8th account address: 0x133325fb37Fd527359BE2c445a1EC571dDF5f3aefca
9th account address: 0xcb01fF913590E0E38931769C74D0B2622f94AE00fca
Last updated