]> git.codecow.com Git - libnemo.git/commitdiff
Eliminate self-references to allow esbuild to use anonymous classes.
authorChris Duncan <chris@zoso.dev>
Thu, 4 Sep 2025 14:36:06 +0000 (07:36 -0700)
committerChris Duncan <chris@zoso.dev>
Thu, 4 Sep 2025 14:36:06 +0000 (07:36 -0700)
src/lib/crypto/bip39.ts
src/lib/crypto/blake2b.ts

index 130fe891d90fcca1e6c5da4a8e3e852b6a1bed0d..545cb71aa136205ae537124b0aa8d0ef32fa2b5b 100644 (file)
@@ -230,11 +230,11 @@ export class Bip39 {
                if (this.#blake2bSeed == null) {\r
                        let bits = 0n\r
                        for (const word of this.#phrase) {\r
-                               const wordIndex = Bip39.wordlist.indexOf(word)\r
+                               const wordIndex = (this.constructor as typeof Bip39).wordlist.indexOf(word)\r
                                if (wordIndex === -1) {\r
                                        throw new RangeError('Word not found in BIP-39 list')\r
                                }\r
-                               bits = (bits << 11n) | BigInt(Bip39.wordlist.indexOf(word))\r
+                               bits = (bits << 11n) | BigInt((this.constructor as typeof Bip39).wordlist.indexOf(word))\r
                        }\r
                        bits >>= 8n\r
                        this.#blake2bSeed = new Uint8Array(32)\r
index 29fc4e742bcfc77ece79102d7929a85e799c1357..829dc50a7c2baf010fd460de7a0b395d54f06b88 100644 (file)
@@ -29,7 +29,7 @@ export class Blake2b {
                new DataView(b).setUint32(0, index, false)
                const s = new Uint8Array(seed)
                const i = new Uint8Array(b)
-               const sk = new Blake2b(32).update(s).update(i).digest()
+               const sk = new this(32).update(s).update(i).digest()
                return Promise.resolve(sk.buffer)
        }
 
@@ -69,13 +69,13 @@ export class Blake2b {
        }
 
        #G (r: number, i: number, a: number, b: number, c: number, d: number): void {
-               this.#v[a] += this.#v[b] + this.#m[Blake2b.SIGMA[r][2 * i + 0]]
+               this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][2 * i + 0]]
                this.#v[d] ^= this.#v[a]
                this.#v[d] = (this.#v[d] >> 32n) | (this.#v[d] << 32n)
                this.#v[c] += this.#v[d]
                this.#v[b] ^= this.#v[c]
                this.#v[b] = (this.#v[b] >> 24n) | (this.#v[b] << 40n)
-               this.#v[a] += this.#v[b] + this.#m[Blake2b.SIGMA[r][2 * i + 1]]
+               this.#v[a] += this.#v[b] + this.#m[(this.constructor as typeof Blake2b).SIGMA[r][2 * i + 1]]
                this.#v[d] ^= this.#v[a]
                this.#v[d] = (this.#v[d] >> 16n) | (this.#v[d] << 48n)
                this.#v[c] += this.#v[d]
@@ -105,7 +105,7 @@ export class Blake2b {
                // init work variables
                for (let i = 0; i < 8; i++) {
                        this.#v[i] = this.#h[i]
-                       this.#v[i + 8] = Blake2b.IV[i]
+                       this.#v[i + 8] = (this.constructor as typeof Blake2b).IV[i]
                }
 
                // lo 64 bits of counter
@@ -210,37 +210,38 @@ export class Blake2b {
        */
        constructor (length: number, key?: Uint8Array<ArrayBuffer>, salt?: Uint8Array<ArrayBuffer>, personal?: Uint8Array<ArrayBuffer>)
        constructor (length: unknown, key?: unknown, salt?: unknown, personal?: unknown) {
+               const B = this.constructor as typeof Blake2b
                if (length == null) {
                        throw new TypeError(`length is required`)
                }
                if (typeof length !== 'number') {
                        throw new TypeError(`length must be number`)
                }
-               if (length < Blake2b.OUTBYTES_MIN || length > Blake2b.OUTBYTES_MAX) {
-                       throw new RangeError(`length must be ${Blake2b.OUTBYTES_MIN}-${Blake2b.OUTBYTES_MAX} bytes`)
+               if (length < B.OUTBYTES_MIN || length > B.OUTBYTES_MAX) {
+                       throw new RangeError(`length must be ${B.OUTBYTES_MIN}-${B.OUTBYTES_MAX} bytes`)
                }
                if (key != null) {
                        if (!(key instanceof Uint8Array)) {
                                throw new TypeError(`key must be Uint8Array or Buffer`)
                        }
-                       if (key.length < Blake2b.KEYBYTES_MIN || key.length > Blake2b.KEYBYTES_MAX) {
-                               throw new RangeError(`key must be ${Blake2b.KEYBYTES_MIN}-${Blake2b.KEYBYTES_MAX} bytes`)
+                       if (key.length < B.KEYBYTES_MIN || key.length > B.KEYBYTES_MAX) {
+                               throw new RangeError(`key must be ${B.KEYBYTES_MIN}-${B.KEYBYTES_MAX} bytes`)
                        }
                }
                if (salt != null) {
                        if (!(salt instanceof Uint8Array)) {
                                throw new TypeError(`salt must be Uint8Array or Buffer`)
                        }
-                       if (salt.length !== Blake2b.SALTBYTES) {
-                               throw new RangeError(`salt must be ${Blake2b.SALTBYTES} bytes`)
+                       if (salt.length !== B.SALTBYTES) {
+                               throw new RangeError(`salt must be ${B.SALTBYTES} bytes`)
                        }
                }
                if (personal != null) {
                        if (!(personal instanceof Uint8Array)) {
                                throw new TypeError(`personal must be Uint8Array or Buffer`)
                        }
-                       if (personal.length !== Blake2b.PERSONALBYTES) {
-                               throw new RangeError(`personal must be ${Blake2b.PERSONALBYTES} bytes`)
+                       if (personal.length !== B.PERSONALBYTES) {
+                               throw new RangeError(`personal must be ${B.PERSONALBYTES} bytes`)
                        }
                }
 
@@ -257,7 +258,7 @@ export class Blake2b {
 
                // initialize hash state
                for (let i = 0; i < 8; i++) {
-                       this.#h[i] = Blake2b.IV[i] ^ this.#parameter_view.getBigUint64(i * 8, true)
+                       this.#h[i] = B.IV[i] ^ this.#parameter_view.getBigUint64(i * 8, true)
                }
 
                // key the hash, if applicable