UNPKG

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