UNPKG

@subsocial/utils

Version:
30 lines (29 loc) 978 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.naclEncrypt = void 0; const tweetnacl_1 = __importDefault(require("tweetnacl")); const util_crypto_1 = require("@polkadot/util-crypto"); /** * @name naclEncrypt * @summary Encrypts a message using the supplied secretKey and nonce * @description * Returns an encrypted message, using the `secretKey` and `nonce`. If the `nonce` was not supplied, a random value is generated. * @example * <BR> * * ```javascript * import { naclEncrypt } from '@subsocial/utils'; * * naclEncrypt([...], [...]); // => [...] * ``` */ function naclEncrypt(message, secret, nonce = (0, util_crypto_1.randomAsU8a)(24)) { return { encrypted: tweetnacl_1.default.secretbox(message, nonce, secret), nonce }; } exports.naclEncrypt = naclEncrypt;