Skip to content

Instantly share code, notes, and snippets.

@yangwao
Created July 25, 2019 14:23
Show Gist options
  • Save yangwao/2123b3b2bdca6ea809d3d781e2b91e86 to your computer and use it in GitHub Desktop.
Save yangwao/2123b3b2bdca6ea809d3d781e2b91e86 to your computer and use it in GitHub Desktop.
import Keyring from '@polkadot/keyring';
public mnemonicGenerate(): void {
this.mnemonicGenerated = mnemonicGenerate();
this.keyring = new Keyring();
}
public validateMnemonic(): void {
this.isValidMnemonic = mnemonicValidate(this.mnemonicGenerated);
}
public mainGenerateFromMnemonic(): void {
this.validateMnemonic();
if (this.isValidMnemonic) {
this.meta = {
name: this.keyAccountName,
tags: this.accountTags.split(','),
whenCreated: Date.now() };
const pairAlice = this.keyring.addFromMnemonic(this.mnemonicGenerated,
this.meta, this.keyringPairType);
this.keyringPairAddress = this.keyring.getPair(pairAlice.address).address;
this.keyringPairPubKey = u8aToHex(this.keyring.getPair(pairAlice.address).publicKey);
this.currentPair = this.keyring.getPair(pairAlice.address);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment