UNPKG

@hazae41/chacha20poly1305

Version:

ChaCha20Poly1305 adapter for WebAssembly and JS implementations

34 lines (31 loc) 1.02 kB
import { Copied } from '../../libs/copiable/index.mjs'; import { Cipher as Cipher$1 } from './abstract.mjs'; function fromNoble(noble) { const { chacha20poly1305 } = noble; function getBytes(bytes) { return "bytes" in bytes ? bytes.bytes : bytes; } class Cipher extends Cipher$1 { key; constructor(key) { super(); this.key = key; } [Symbol.dispose]() { } static create(key) { return new Cipher(key); } static importOrThrow(key) { return new Cipher(getBytes(key).slice()); } encryptOrThrow(message, nonce) { return new Copied(chacha20poly1305(this.key, getBytes(nonce).slice()).encrypt(getBytes(message))); } decryptOrThrow(message, nonce) { return new Copied(chacha20poly1305(this.key, getBytes(nonce).slice()).decrypt(getBytes(message))); } } return { Cipher }; } export { fromNoble }; //# sourceMappingURL=noble.mjs.map