* 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
25 lines
921 B
JavaScript
Executable File
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());
|