UNPKG

594 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 naclDecrypt
6 * @summary Decrypts a message using the supplied secretKey and nonce
7 * @description
8 * Returns an decrypted message, using the `secret` and `nonce`.
9 * @example
10 * <BR>
11 *
12 * ```javascript
13 * import { naclDecrypt } from '@polkadot/util-crypto';
14 *
15 * naclDecrypt([...], [...], [...]); // => [...]
16 * ```
17 */
18
19export function naclDecrypt(encrypted, nonce, secret) {
20 return nacl.secretbox.open(encrypted, nonce, secret) || null;
21}
\No newline at end of file