]> git.codecow.com Git - libnemo.git/commitdiff
Deprecate unnecessary unknown union types.
authorChris Duncan <chris@zoso.dev>
Fri, 8 Aug 2025 02:15:46 +0000 (19:15 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 8 Aug 2025 02:15:46 +0000 (19:15 -0700)
src/lib/blake2b.ts
src/types.d.ts

index 1c539e5c8eba4c0477285dfccb07c455f324d5f9..fbc5e9494e2b75f4808233adbd5c42204dc68e23 100644 (file)
@@ -1,8 +1,6 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
 //! SPDX-License-Identifier: GPL-3.0-or-later AND ISC
 
-import { UnknownNumber, UnknownUint8Array } from "#types"
-
 /**
 * Implementation derived from blake2b@2.1.4. Copyright 2017 Emil Bay
 * <github@tixz.dk> (https://github.com/emilbayes/blake2b). See LICENSES/ISC.txt
@@ -197,7 +195,8 @@ export class Blake2b {
        * @param {Uint8Array} [salt] - (_optional_) Used to simplify randomized hashing for digital signatures
        * @param {Uint8Array} [personal] - (_optional_) Arbitrary user-specified value
        */
-       constructor (length: UnknownNumber, key?: UnknownUint8Array, salt?: UnknownUint8Array, personal?: UnknownUint8Array) {
+       constructor (length: number, key?: Uint8Array<ArrayBuffer>, salt?: Uint8Array<ArrayBuffer>, personal?: Uint8Array<ArrayBuffer>)
+       constructor (length: unknown, key?: unknown, salt?: unknown, personal?: unknown) {
                if (length == null) {
                        throw new TypeError(`length is required`)
                }
index 4e954e2b4f351a40911b0fa96985b9f61618be0c..499ea1db7468e59e6474824b7d49edc82ee6ad48 100644 (file)
@@ -125,12 +125,21 @@ export declare class AccountList extends Object {
 */
 export declare class Bip39Mnemonic {
        #private
-       get phrase (): string
-       private constructor ()
+       /**
+       * Derives a mnemonic phrase from source of entropy or seed.
+       *
+       * The entropy must be between 16-32 bytes (32-64 characters) to stay within
+       * the limit of 128-256 bits defined in BIP-39. Typically, wallets use the
+       * maximum entropy allowed.
+       *
+       * @param {(string|ArrayBuffer|Uint8Array<ArrayBuffer>)} entropy - Cryptographically secure random value
+       * @returns {string} Mnemonic phrase created using the BIP-39 wordlist
+       */
+       static fromEntropy (entropy: string | ArrayBuffer | Uint8Array<ArrayBuffer>): Promise<Bip39Mnemonic>
        /**
        * Imports and validates an existing mnemonic phrase.
        *
-       * The phrase must be valid according to the BIP-39 specification. Typically
+       * The phrase must be valid according to the BIP-39 specification. Typically,
        * wallets use the maximum of 24 words.
        *
        * @param {string} phrase - String of 12, 15, 18, 21, or 24 words
@@ -138,35 +147,27 @@ export declare class Bip39Mnemonic {
        */
        static fromPhrase (phrase: string): Promise<Bip39Mnemonic>
        /**
-       * Derives a mnemonic phrase from source of entropy or seed.
+       * Validates a mnemonic phrase meets the BIP-39 specification.
        *
-       * The entropy must be between 32-64 characters to stay within the defined
-       * limit of 128-256 bits. Typically wallets use the maximum entropy allowed.
-       *
-       * @param {string} entropy - Hexadecimal string
-       * @returns {string} Mnemonic phrase created using the BIP-39 wordlist
+       * @param {string} mnemonic - Mnemonic phrase to validate
+       * @returns {boolean} True if the mnemonic phrase is valid
        */
-       static fromEntropy (entropy: string): Promise<Bip39Mnemonic>
-       /**
-        * SHA-256 hash of entropy that is appended to the entropy and subsequently
-        * used to generate the mnemonic phrase.
-        *
-        * @param {Entropy} entropy - Cryptographically strong pseudorandom data of length N bits
-        * @returns {Promise<string>} First N/32 bits of the hash as a hexadecimal string
-        */
-       static checksum (entropy: Entropy): Promise<string>
+       static validate (mnemonic: string): Promise<boolean>
+       get phrase (): string | undefined
+       private constructor ()
        /**
-       * Erases seed bytes and releases variable references to allow garbage
-       * collection.
+       * Erases seed bytes and releases variable references.
        */
        destroy (): void
        /**
-       * Validates a mnemonic phrase.
+       * Converts the mnemonic phrase to a BIP-39 seed.
        *
-       * @param {string} mnemonic - Mnemonic phrase to validate
-       * @returns {boolean} True if the mnemonic phrase is valid
+       * A passphrase string can be specified. If the passphrase is undefined, null,
+       * or not a string, the empty string ("") is used instead.
+       *
+       * @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: ""
+       * @returns {Promise<Uint8Array<ArrayBuffer>>} Promise for seed as bytes
        */
-       static validate (mnemonic: string): Promise<boolean>
        toBip39Seed (passphrase: string): Promise<Uint8Array<ArrayBuffer>>
        /**
        * Converts the mnemonic phrase to a BIP-39 seed.
@@ -175,14 +176,20 @@ export declare class Bip39Mnemonic {
        * or not a string, the empty string ("") is used instead.
        *
        * @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: ""
-       * @returns {string} Hexadecimal seed
+       * @returns {Promise<string>}  Promise for seed as hexadecimal string
        */
        toBip39Seed (passphrase: string, format: 'hex'): Promise<string>
+       /**
+       * Converts the mnemonic phrase to a BLAKE2b seed.
+       *
+       * @returns {Promise<Uint8Array<ArrayBuffer>>} Promise for seed as bytes
+       */
        toBlake2bSeed (): Promise<Uint8Array<ArrayBuffer>>
        /**
        * Converts the mnemonic phrase to a BLAKE2b seed.
        *
-       * @returns {string} Hexadecimal seed
+       * @param {string} format
+       * @returns {Promise<string>} Promise for seed as hexadecimal string
        */
        toBlake2bSeed (format: 'hex'): Promise<string>
 }
@@ -214,7 +221,7 @@ export declare class Blake2b {
        * @param {Uint8Array} [salt] - (_optional_) Used to simplify randomized hashing for digital signatures
        * @param {Uint8Array} [personal] - (_optional_) Arbitrary user-specified value
        */
-       constructor (length: UnknownNumber, key?: UnknownUint8Array, salt?: UnknownUint8Array, personal?: UnknownUint8Array)
+       constructor (length: number, key?: Uint8Array<ArrayBuffer>, salt?: Uint8Array<ArrayBuffer>, personal?: Uint8Array<ArrayBuffer>)
        update (input: Uint8Array): Blake2b
        digest (): Uint8Array<ArrayBuffer>
        digest (out: 'hex'): string
@@ -928,7 +935,3 @@ export declare class WorkerQueue {
 }
 
 export declare const PasskeyWorker: WorkerQueue
-
-export type UnknownNumber = number | unknown
-
-export type UnknownUint8Array = Uint8Array | unknown