From: Chris Duncan Date: Mon, 4 Aug 2025 17:45:47 +0000 (-0700) Subject: Add entropy in bigint format to enable bitwise operations. X-Git-Tag: v0.10.5~46^2~13 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=bab433ebd93f1984816bd372f64f50b211427b5c;p=libnemo.git Add entropy in bigint format to enable bitwise operations. --- 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 }