UNPKG

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