UNPKG

@subsocial/utils

Version:
30 lines (29 loc) 1.06 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.naclSeal = void 0; const tweetnacl_1 = __importDefault(require("tweetnacl")); const util_crypto_1 = require("@polkadot/util-crypto"); /** * @name naclSeal * @summary Seals a message using the sender's encrypting secretKey, receiver's public key, and nonce * @description * Returns an encrypted message which can be open only by receiver's secretKey. If the `nonce` was not supplied, a random value is generated. * @example * <BR> * * ```javascript * import { naclSeal } from '@subsocial/utils'; * * naclSeal([...], [...], [...], [...]); // => [...] * ``` */ function naclSeal(message, senderBoxSecret, receiverBoxPublic, nonce = (0, util_crypto_1.randomAsU8a)(24)) { return { nonce, sealed: tweetnacl_1.default.box(message, nonce, receiverBoxPublic, senderBoxSecret) }; } exports.naclSeal = naclSeal;