Created
July 25, 2019 14:23
-
-
Save yangwao/2123b3b2bdca6ea809d3d781e2b91e86 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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