}\r
}\r
\r
-export class buffer {\r
- /**\r
- * Converts an ArrayBuffer to a base32 string.\r
- *\r
- * @param {ArrayBuffer} buffer - Buffer to convert\r
- * @returns {string} Base32 string representation of the input buffer\r
- */\r
- static toBase32 (buffer: ArrayBuffer): string {\r
- return bytes.toBase32(new Uint8Array(buffer))\r
- }\r
-\r
- /**\r
- * Converts an ArrayBuffer to a binary string.\r
- *\r
- * @param {ArrayBuffer} buffer - Buffer to convert\r
- * @returns {string} Binary string representation of the input buffer\r
- */\r
- static toBin (buffer: ArrayBuffer): string {\r
- return bytes.toBin(new Uint8Array(buffer))\r
- }\r
-\r
- /**\r
- * Sums an ArrayBuffer to a decimal integer. If the result is larger than\r
- * Number.MAX_SAFE_INTEGER, it will be returned as a bigint.\r
- *\r
- * @param {ArrayBuffer} buffer - Buffer to convert\r
- * @returns {bigint|number} Decimal sum of the literal buffer values\r
- */\r
- static toDec (buffer: ArrayBuffer): bigint | number {\r
- return bytes.toDec(new Uint8Array(buffer))\r
- }\r
-\r
- /**\r
- * Converts an ArrayBuffer to a hexadecimal string.\r
- *\r
- * @param {ArrayBuffer} buffer - Buffer to convert\r
- * @returns {string} Hexadecimal string representation of the input buffer\r
- */\r
- static toHex (buffer: ArrayBuffer): string {\r
- return bytes.toHex(new Uint8Array(buffer))\r
- }\r
-\r
- /**\r
- * Converts an ArrayBuffer to a UTF-8 text string.\r
- *\r
- * @param {ArrayBuffer} buffer - Buffer to convert\r
- * @returns {string} UTF-8 encoded text string\r
- */\r
- static toUtf8 (buffer: ArrayBuffer): string {\r
- return bytes.toUtf8(new Uint8Array(buffer))\r
- }\r
-}\r
-\r
export class bytes {\r
/**\r
* Converts a Uint8Aarray of bytes to a base32 string.\r
export default `\r
const base32 = ${base32}\r
const bin = ${bin}\r
- const buffer = ${buffer}\r
const bytes = ${bytes}\r
const dec = ${dec}\r
const hex = ${hex}\r
'use strict'
-import { buffer, hex, obj, utf8, default as Convert } from '#src/lib/convert.js'
+import { bytes, hex, obj, utf8, default as Convert } from '#src/lib/convert.js'
import { Entropy } from '#src/lib/entropy.js'
import { WorkerInterface } from '#src/lib/pool.js'
passkey = await globalThis.crypto.subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['encrypt'])
const encrypted = await globalThis.crypto.subtle.encrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, utf8.toBytes(data))
const record = {
- encrypted: buffer.toHex(encrypted),
+ encrypted: bytes.toHex(new Uint8Array(encrypted)),
iv: iv.hex
}
return await this.#put(record, name)
}
passkey = await globalThis.crypto.subtle.deriveKey(derivationAlgorithm, passkey, derivedKeyType, false, ['decrypt'])
const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, passkey, encrypted)
- const decoded = buffer.toUtf8(decrypted)
+ const decoded = bytes.toUtf8(new Uint8Array(decrypted))
const data = JSON.parse(decoded)
await this.destroy(name)
return data