UNPKG

988 BJavaScriptView Raw
1import { ed25519 } from '@noble/curves/ed25519';
2import { hasBigInt, u8aConcatStrict } from '@polkadot/util';
3import { ed25519KeypairFromSeed, isReady } from '@polkadot/wasm-crypto';
4/**
5 * @name ed25519PairFromSeed
6 * @summary Creates a new public/secret keypair from a seed.
7 * @description
8 * Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { ed25519PairFromSeed } from '@polkadot/util-crypto';
14 *
15 * ed25519PairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
16 * ```
17 */
18export function ed25519PairFromSeed(seed, onlyJs) {
19 if (!hasBigInt || (!onlyJs && isReady())) {
20 const full = ed25519KeypairFromSeed(seed);
21 return {
22 publicKey: full.slice(32),
23 secretKey: full.slice(0, 64)
24 };
25 }
26 const publicKey = ed25519.getPublicKey(seed);
27 return {
28 publicKey,
29 secretKey: u8aConcatStrict([seed, publicKey])
30 };
31}