From bab433ebd93f1984816bd372f64f50b211427b5c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 4 Aug 2025 10:45:47 -0700 Subject: [PATCH] Add entropy in bigint format to enable bitwise operations. --- src/lib/entropy.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib/entropy.ts b/src/lib/entropy.ts index df1e072..bd77362 100644 --- a/src/lib/entropy.ts +++ b/src/lib/entropy.ts @@ -16,8 +16,19 @@ export class Entropy { static #MIN: 16 = 16 static #MAX: 32 = 32 static #MOD: 4 = 4 + #bigint?: bigint #bytes: Uint8Array + get bigint (): bigint { + if (this.#bigint == null) { + this.#bigint = 0n + for (let i = 0; i < this.#bytes.byteLength; i++) { + this.#bigint <<= 8n + this.#bigint |= BigInt(this.#bytes[i]) + } + } + return this.#bigint + } get bits (): string { return bytes.toBin(this.#bytes) } get buffer (): ArrayBuffer { return this.#bytes.buffer } get bytes (): Uint8Array { return this.#bytes } -- 2.47.3