Files
common/docs/examples/util-crypto/03_mnemonic_generate_validate_bip39/index.js
T
Luke Schoen 48008e2cc8 refactor: Extension of #231. Destructuring to combine imports (#237)
* refactor: Destructure imports together from same source in example util-crypto 01

* refactor: Destructure imports together example util-crypto 02. Avoid using default import. Show data to user

* refactor: Destructure imports together example util-crypto 03. Show data to user

* refactor: Split import over two lines looks cleaner

* fix: Address review comments. Update dependencies in examples
2018-11-14 13:26:53 +01:00

25 lines
921 B
JavaScript
Executable File

const { mnemonicGenerate, mnemonicToSeed, mnemonicValidate, naclKeypairFromSeed } = require('@polkadot/util-crypto');
async function main () {
// Create mnemonic string for Alice using BIP39
const mnemonicAlice = mnemonicGenerate();
console.log(`Generated mnemonic: ${mnemonicAlice}`);
// Validate the mnemic string that was generated
const isValidMnemonic = mnemonicValidate(mnemonicAlice);
console.log(`isValidMnemonic: ${isValidMnemonic}`);
// Create valid seed from mnemonic as u8a and convert it to a string
// FIXME - Replace with mnemonicToSeed once exposed
const seedAlice = mnemonicToSeed(mnemonicAlice);
// Generate new public/secret keypair for Alice from the supplied seed
const { secretKey, publicKey } = naclKeypairFromSeed(seedAlice);
// Encrypt, Sign and Validate the message. See Example 'Sign & Verify Message'
}
main().catch(console.error).finally(_ => process.exit());