Factom Bip44
Generate addresses off your 12-word mnemonic seed. Same seed as EnterpriseWallet and factom-walletd.
There are faster ways to do this, but this gets the job done easily. It does a lot of computation more than once if you end up generating a lot of addresses.
Example
const bip44 = const seedToPrivateFctAddress getPublicAddress = // Mnemonic seedconst mnemonic = "yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow" // Create the walletconst wallet = mnemonic // Generating private keys. Typically you only need to increment the last parameter,// unless you want to make multiple chains of addressesconst privKey1 = walletconst privKey2 = wallet // Get Fs... private human readable addressconst humanPrivKey = // Get Fa... public human readable addressconst humanPubKey =
For random mnemonics
// Generate a new mnemonicconst mn = bip44 // You can validate it if you want to verifyconst valid = bip44// valid == true because we generated. If user is inputting, if might not be valid
If you are generating many addresses in a row, doing the first example is slow. You can speed it up like so:
const mnemonic = "yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow yellow"const wallet = mnemonic // We will store all the keys hereconst privateKeys = // This chain object saves us some computation for each new addressconst chain = walletfor let i = 0; i < 5; i++ // This is the next key, we will throw it onto our array const next = chainnext privateKeys // Lost the chain? Do it againconst chain = wallet// for (var i = 0; i < 5; i++) { ... }
Chains are the same as the generate, just quicker as the first set of computation is saved, so there is less work. They can only be generated sequentially though
// The 'next()' refer to the next index in the generate function, so:const chain = walletchainnext == walletchainnext == walletchainnext == wallet// etc
Precompiled for Web
Use dist/factombip44.js
and use like so:
// There is a require function to act similar to nodeconst bip44 = // Use like normalconst mn = bip44// ...