Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'
}
generateAddressFromMnemonic (mnemonic: string): string {
const { keyring } = this.context;
const keypair = naclKeypairFromSeed(mnemonicToSeed(mnemonic));
return keyring.encodeAddress(
keypair.publicKey
);
}
export function generateAddressFromMnemonic (keyring: Keyring, mnemonic: string): string {
const keypair = naclKeypairFromSeed(mnemonicToSeed(mnemonic));
return keyring.encodeAddress(
keypair.publicKey
);
}
function generateSeed() {
const mnemonic = generateValidMnemonic();
const seedU8a = mnemonicToSeed(mnemonic);
const seed = u8aToHex(seedU8a);
return { seed, seedU8a, mnemonic};
}
const confirmCreate = () => {
const mnemonic = mnemonicGenerate();
const keypair = naclKeypairFromSeed(mnemonicToSeed(mnemonic));
keyring.encodeAddress(
keypair.publicKey
);
let stashPair = keyring.createAccountMnemonic(mnemonic, stashPassword, { name: 'Stash', type: 'stash' });
let controllerPair = keyring.createAccountMnemonic(mnemonic, controllerPassword, { name: 'Controller', type: 'controller' });
const stashAddress = stashPair.address();
const stashJson = stashPair.toJson(stashPassword);
const controllerAddress = controllerPair.address();
const controllerJson = stashPair.toJson(controllerPassword);
const stashBlob = new Blob([JSON.stringify(stashJson)], { type: 'application/json; charset=utf-8' });
const controllerBlob = new Blob([JSON.stringify(controllerJson)], { type: 'application/json; charset=utf-8' });