@ondemos/core
Version:
A cryptographic commitment scheme with implied order of ownership wasm module for nodejs and the browser.
48 lines • 1.84 kB
TypeScript
import type { LibDemos } from "@libdemos";
/**
* Encrypts a message with additional data using
* the crypto_aead_chacha20poly1305_ietf_encrypt operation from
* libsodium with a precomputed symmetric key Uint8Array(32).
* The nonce is calculated by taking the second half of the
* sha512 hash of a Uint8Array(64) random array that is produced
* in secure memory on wasm. The auth tag is generated using Poly1305.
*
* If you need to perform bulk encryptions with predictable message
* and additional data sizes then it will be more efficient to preload
* the wasm module and reuse it as follows:
*
* ```ts
* const messageLen = message.length;
* const additionalLen = additionalData.length;
*
* const wasmMemory = demosMemory.encryptSymmetricKeyMemory(messageLen, additionalLen);
* const wasmModule = await demosMethodsModule({ wasmMemory });
* ```
*
* If not all messages and additional data are equal, you can always just use
* the largest Uint8Arrays as inputs.
*
* ```ts
* import demos from \"@deliberative/crypto\"
*
* const message = new Uint8Array(128).fill(1);
* const symmetricKey = new Uint8Array(32).fill(3);
* const additionalData = new Uint8Array(64).fill(2);
*
* const box = await demos.encryptSymmetricKey(
* message,
* symmetricKey,
* additionalData
* );
* ```
*
* @param message - the message to encrypt
* @param symmetricKey - the precomputed symmetric key
* @param additionalData - the additional data for aead
* @param module - wasm module in case of bulk encryptions
*
* @returns Encrypted box [nonce 16 || encrypted_data || auth tag 12]
*/
declare const encryptSymmetric: (message: Uint8Array, symmetricKey: Uint8Array, additionalData: Uint8Array, module?: LibDemos) => Promise<Uint8Array>;
export default encryptSymmetric;
//# sourceMappingURL=encryptSymmetric.d.ts.map