Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Last active December 30, 2021 00:32
Show Gist options
  • Save WietseWind/e9af4a3ba3f406a287dd6e9bd030412f to your computer and use it in GitHub Desktop.
Save WietseWind/e9af4a3ba3f406a287dd6e9bd030412f to your computer and use it in GitHub Desktop.
const bip39 = require("bip39");
const bip32 = require("ripple-bip32");
const ripple = require('ripple-keypairs')
var mnemonic = 'novel matter final only nice cheese address cradle civil crash great flame struggle consider crowd surface purpose saddle mango endless mixed trial tape wrap'
// Or generate:
// mnemonic = bip39.generateMnemonic()
console.log('mnemonic: ' + mnemonic)
const seed = bip39.mnemonicToSeed(mnemonic) // add second argument for 25th word encrypted
console.log('seed: ', seed)
const m = bip32.fromSeedBuffer(seed)
console.log('m: ', m)
const keyPair = m.derivePath("m/44'/144'/0'/0/0").keyPair.getKeyPairs()
const address = ripple.deriveAddress(keyPair.publicKey)
console.log('privateKey: ' + keyPair.privateKey)
console.log('publicKey: ' + keyPair.publicKey)
console.log('address: ' + address)
@sh4dowb
Copy link

sh4dowb commented Jul 7, 2021

I think bip39 has been updated, if it gives you "Promise ..." and throws an error change mnemonicToSeed to mnemonicToSeedSync

@WietseWind
Copy link
Author

@sh4dowb

I think bip39 has been updated, if it gives you "Promise ..." and throws an error change mnemonicToSeed to mnemonicToSeedSync

Definitely possible. The most recent (working, supported) implementation is embedded in https://www.npmjs.com/package/xrpl-accountlib :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment