UNPKG

872 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import nacl from 'tweetnacl';
4import { ed25519KeypairFromSeed, isReady } from '@polkadot/wasm-crypto';
5/**
6 * @name ed25519PairFromSeed
7 * @summary Creates a new public/secret keypair from a seed.
8 * @description
9 * Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
10 * @example
11 * <BR>
12 *
13 * ```javascript
14 * import { ed25519PairFromSeed } from '@polkadot/util-crypto';
15 *
16 * ed25519PairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
17 * ```
18 */
19
20export function ed25519PairFromSeed(seed, onlyJs) {
21 if (!onlyJs && isReady()) {
22 const full = ed25519KeypairFromSeed(seed);
23 return {
24 publicKey: full.slice(32),
25 secretKey: full.slice(0, 64)
26 };
27 }
28
29 return nacl.sign.keyPair.fromSeed(seed);
30}
\No newline at end of file