UNPKG

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