/
index.ts
30 lines (27 loc) · 961 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { mnemonicGenerate, cryptoWaitReady } from "@polkadot/util-crypto"
import { Keyring } from "@polkadot/keyring"
/**
* @name generateSeed
* @summary Generate a new seed
* @returns The new seed
*/
export const generateSeed = mnemonicGenerate
/**
* @name getKeyringFromSeed
* @summary Create a keyring from a seed
* @param seed Mnemonic
* @param hardPath Hard path derivation
* @param softPath Soft path derivation
* @param passwordPath Password path derivation
* @returns A keyring pair
*/
export const getKeyringFromSeed = async (seed: string, hardPath?: string, softPath?: string, passwordPath?: string) => {
await cryptoWaitReady()
const _suri =
seed +
`${hardPath ? `//${hardPath}` : ""}` +
`${softPath ? `/${softPath}` : ""}` +
`${passwordPath ? `///${passwordPath}` : ""}`
const keyring = new Keyring()
return keyring.createFromUri(_suri, {}, "sr25519")
}