UNPKG

662 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util-crypto authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3import nacl from 'tweetnacl';
4/**
5 * @name naclBoxPairFromSecret
6 * @summary Creates a new public/secret box keypair from a secret.
7 * @description
8 * Returns a object containing a box `publicKey` & `secretKey` generated from the supplied secret.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { naclBoxPairFromSecret } from '@polkadot/util-crypto';
14 *
15 * naclBoxPairFromSecret(...); // => { secretKey: [...], publicKey: [...] }
16 * ```
17 */
18
19export function naclBoxPairFromSecret(secret) {
20 return nacl.box.keyPair.fromSecretKey(secret.slice(0, 32));
21}
\No newline at end of file