UNPKG

@hazae41/chacha20poly1305

Version:

ChaCha20Poly1305 adapter for WebAssembly and JS implementations

36 lines (32 loc) 1.05 kB
'use strict'; var index = require('../../libs/copiable/index.cjs'); var abstract = require('./abstract.cjs'); function fromNoble(noble) { const { chacha20poly1305 } = noble; function getBytes(bytes) { return "bytes" in bytes ? bytes.bytes : bytes; } class Cipher extends abstract.Cipher { 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 index.Copied(chacha20poly1305(this.key, getBytes(nonce).slice()).encrypt(getBytes(message))); } decryptOrThrow(message, nonce) { return new index.Copied(chacha20poly1305(this.key, getBytes(nonce).slice()).decrypt(getBytes(message))); } } return { Cipher }; } exports.fromNoble = fromNoble; //# sourceMappingURL=noble.cjs.map