From 2ece8f56c45e7412c1bd5b73c977ea3411884df7 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 5 Jul 2025 01:36:09 -0700 Subject: [PATCH] Deprecate unnecessary and redundant ArrayBuffer convert functions. --- src/lib/convert.ts | 54 ----------------------------------------- src/lib/workers/safe.ts | 6 ++--- 2 files changed, 3 insertions(+), 57 deletions(-) diff --git a/src/lib/convert.ts b/src/lib/convert.ts index 038a9d6..f2a0590 100644 --- a/src/lib/convert.ts +++ b/src/lib/convert.ts @@ -75,59 +75,6 @@ export class bin { } } -export class buffer { - /** - * Converts an ArrayBuffer to a base32 string. - * - * @param {ArrayBuffer} buffer - Buffer to convert - * @returns {string} Base32 string representation of the input buffer - */ - static toBase32 (buffer: ArrayBuffer): string { - return bytes.toBase32(new Uint8Array(buffer)) - } - - /** - * Converts an ArrayBuffer to a binary string. - * - * @param {ArrayBuffer} buffer - Buffer to convert - * @returns {string} Binary string representation of the input buffer - */ - static toBin (buffer: ArrayBuffer): string { - return bytes.toBin(new Uint8Array(buffer)) - } - - /** - * Sums an ArrayBuffer to a decimal integer. If the result is larger than - * Number.MAX_SAFE_INTEGER, it will be returned as a bigint. - * - * @param {ArrayBuffer} buffer - Buffer to convert - * @returns {bigint|number} Decimal sum of the literal buffer values - */ - static toDec (buffer: ArrayBuffer): bigint | number { - return bytes.toDec(new Uint8Array(buffer)) - } - - /** - * Converts an ArrayBuffer to a hexadecimal string. - * - * @param {ArrayBuffer} buffer - Buffer to convert - * @returns {string} Hexadecimal string representation of the input buffer - */ - static toHex (buffer: ArrayBuffer): string { - return bytes.toHex(new Uint8Array(buffer)) - } - - /** - * Converts an ArrayBuffer to a UTF-8 text string. - * - * @param {ArrayBuffer} buffer - Buffer to convert - * @returns {string} UTF-8 encoded text string - */ - static toUtf8 (buffer: ArrayBuffer): string { - return bytes.toUtf8(new Uint8Array(buffer)) - } -} - export class bytes { /** * Converts a Uint8Aarray of bytes to a base32 string. @@ -365,7 +312,6 @@ export class utf8 { export default ` const base32 = ${base32} const bin = ${bin} - const buffer = ${buffer} const bytes = ${bytes} const dec = ${dec} const hex = ${hex} diff --git a/src/lib/workers/safe.ts b/src/lib/workers/safe.ts index 1860874..233af55 100644 --- a/src/lib/workers/safe.ts +++ b/src/lib/workers/safe.ts @@ -3,7 +3,7 @@ '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' @@ -132,7 +132,7 @@ export class Safe extends WorkerInterface { 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) @@ -182,7 +182,7 @@ export class Safe extends WorkerInterface { } 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 -- 2.47.3