]> git.codecow.com Git - libnemo.git/commitdiff
Type definition updates.
authorChris Duncan <chris@zoso.dev>
Wed, 20 Aug 2025 21:27:24 +0000 (14:27 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 20 Aug 2025 21:27:24 +0000 (14:27 -0700)
src/lib/crypto/blake2b.ts
src/lib/wallet/index.ts
src/types.d.ts
test/test.refresh-accounts.mjs

index fbc5e9494e2b75f4808233adbd5c42204dc68e23..df0a2ac66d3eb71c52d857490386f8e228d0f063 100644 (file)
 */
 
 export class Blake2b {
-       static get OUTBYTES_MIN (): 1 { return 1 }
-       static get OUTBYTES_MAX (): 64 { return 64 }
-       static get KEYBYTES_MIN (): 1 { return 1 }
-       static get KEYBYTES_MAX (): 64 { return 64 }
-       static get SALTBYTES (): 16 { return 16 }
-       static get PERSONALBYTES (): 16 { return 16 }
-       static get IV (): bigint[] {
-               return [
-                       0x6a09e667f3bcc908n,
-                       0xbb67ae8584caa73bn,
-                       0x3c6ef372fe94f82bn,
-                       0xa54ff53a5f1d36f1n,
-                       0x510e527fade682d1n,
-                       0x9b05688c2b3e6c1fn,
-                       0x1f83d9abfb41bd6bn,
-                       0x5be0cd19137e2179n
-               ]
-       }
-       static get SIGMA (): number[][] {
-               return [
-                       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
-                       [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
-                       [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
-                       [7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8],
-                       [9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13],
-                       [2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9],
-                       [12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11],
-                       [13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10],
-                       [6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5],
-                       [10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0],
-                       [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
-                       [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3]
-               ]
-       }
+       static #OUTBYTES_MIN: number = 1
+       static #OUTBYTES_MAX: number = 64
+       static #KEYBYTES_MIN: number = 1
+       static #KEYBYTES_MAX: number = 64
+       static #SALTBYTES: number = 16
+       static #PERSONALBYTES: number = 16
+       static #IV: bigint[] = [
+               0x6a09e667f3bcc908n,
+               0xbb67ae8584caa73bn,
+               0x3c6ef372fe94f82bn,
+               0xa54ff53a5f1d36f1n,
+               0x510e527fade682d1n,
+               0x9b05688c2b3e6c1fn,
+               0x1f83d9abfb41bd6bn,
+               0x5be0cd19137e2179n
+       ]
+       static #SIGMA: number[][] = [
+               [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
+               [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3],
+               [11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4],
+               [7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8],
+               [9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13],
+               [2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9],
+               [12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11],
+               [13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10],
+               [6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5],
+               [10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0],
+               [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
+               [14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3]
+       ]
 
        static #toHex (buf: Uint8Array): string {
                let str = ''
@@ -56,13 +52,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[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[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]
@@ -92,7 +88,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] = Blake2b.#IV[i]
                }
 
                // lo 64 bits of counter
@@ -203,31 +199,31 @@ export class Blake2b {
                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 < Blake2b.#OUTBYTES_MIN || length > Blake2b.#OUTBYTES_MAX) {
+                       throw new RangeError(`length must be ${Blake2b.#OUTBYTES_MIN}-${Blake2b.#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 < Blake2b.#KEYBYTES_MIN || key.length > Blake2b.#KEYBYTES_MAX) {
+                               throw new RangeError(`key must be ${Blake2b.#KEYBYTES_MIN}-${Blake2b.#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 !== Blake2b.#SALTBYTES) {
+                               throw new RangeError(`salt must be ${Blake2b.#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 !== Blake2b.#PERSONALBYTES) {
+                               throw new RangeError(`personal must be ${Blake2b.#PERSONALBYTES} bytes`)
                        }
                }
 
@@ -244,7 +240,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] = Blake2b.#IV[i] ^ this.#parameter_view.getBigUint64(i * 8, true)
                }
 
                // key the hash, if applicable
index 16246a61f84f94170cb85c1f90c6b717fce461dd..c72aaf2820eb3a303f9b185edd72c31077c8bdf3 100644 (file)
@@ -230,7 +230,7 @@ export class Wallet {
        * If `from` is greater than `to`, their values will be swapped.\r
        * @param {number} [from=0] - Start index of accounts. Default: 0\r
        * @param {number} [to=from] - End index of accounts. Default: `from`\r
-       * @returns {AccountList} Promise for a list of Accounts at the specified indexes\r
+       * @returns {Promise<AccountList>} Promise for a list of Accounts at the specified indexes\r
        */\r
        async accounts (from: number = 0, to: number = from): Promise<AccountList> {\r
                return await _accounts(this.type, this.#accounts, this.#vault, from, to)\r
index cb070a22de93d7cdd7463fdadd2cd48325c6875f..441d5c557f17241a3eb543be43b53fd0c6f04734 100644 (file)
@@ -225,14 +225,6 @@ export declare class Bip39 {
 */
 export declare class Blake2b {
        #private
-       static get OUTBYTES_MIN (): 1
-       static get OUTBYTES_MAX (): 64
-       static get KEYBYTES_MIN (): 1
-       static get KEYBYTES_MAX (): 64
-       static get SALTBYTES (): 16
-       static get PERSONALBYTES (): 16
-       static get IV (): bigint[]
-       static get SIGMA (): number[][]
        /**
        * Creates a BLAKE2b hashing context.
        *
@@ -682,7 +674,7 @@ export declare class Wallet {
        * If `from` is greater than `to`, their values will be swapped.
        * @param {number} [from=0] - Start index of accounts. Default: 0
        * @param {number} [to=from] - End index of accounts. Default: `from`
-       * @returns {AccountList} Promise for a list of Accounts at the specified indexes
+       * @returns {Promise<AccountList>} Promise for a list of Accounts at the specified indexes
        */
        accounts (from?: number, to?: number): Promise<AccountList>
        /**
index c2c53c99f68a34c786180bbcea09473abd1c0205..8d3f33bdc496e99c645adc319fd7bed1de056820 100644 (file)
@@ -11,13 +11,13 @@ import { NANO_TEST_VECTORS } from './VECTORS.mjs'
 */
 let Account
 /**
-* @type {typeof import('../dist/types.d.ts').Wallet}
-*/
-let Wallet
-/**
 * @type {typeof import('../dist/types.d.ts').Rpc}
 */
 let Rpc
+/**
+* @type {typeof import('../dist/types.d.ts').Wallet}
+*/
+let Wallet
 if (isNode) {
        ({ Account, Wallet, Rpc } = await import('../dist/nodejs.min.js'))
 } else {