]> git.codecow.com Git - libnemo.git/commitdiff
Add entropy in bigint format to enable bitwise operations.
authorChris Duncan <chris@zoso.dev>
Mon, 4 Aug 2025 17:45:47 +0000 (10:45 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 4 Aug 2025 17:45:47 +0000 (10:45 -0700)
src/lib/entropy.ts

index df1e07268f1babc1b0535efe918f765c60b770b2..bd7736274e541a399800232f94f35b4ef24e4613 100644 (file)
@@ -16,8 +16,19 @@ export class Entropy {
        static #MIN: 16 = 16
        static #MAX: 32 = 32
        static #MOD: 4 = 4
+       #bigint?: bigint
        #bytes: Uint8Array<ArrayBuffer>
 
+       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<ArrayBuffer> { return this.#bytes }