]> git.codecow.com Git - libnemo.git/commitdiff
Update mnemonic class comments.
authorChris Duncan <chris@zoso.dev>
Wed, 30 Jul 2025 16:55:09 +0000 (09:55 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 30 Jul 2025 16:55:09 +0000 (09:55 -0700)
src/lib/bip39-mnemonic.ts

index 758bf3e6f66cdc990823e2e6d2eac86a84849d03..a8dab4150af7f6a39689b7b096386d43f10b6046 100644 (file)
@@ -28,10 +28,11 @@ export class Bip39Mnemonic {
        /**\r
        * Derives a mnemonic phrase from source of entropy or seed.\r
        *\r
-       * The entropy must be between 32-64 characters to stay within the defined\r
-       * limit of 128-256 bits. Typically wallets use the maximum entropy allowed.\r
+       * The entropy must be between 16-32 bytes (32-64 characters) to stay within\r
+       * the limit of 128-256 bits defined in BIP-39. Typically, wallets use the\r
+       * maximum entropy allowed.\r
        *\r
-       * @param {string} entropy - Hexadecimal string\r
+       * @param {(string|Uint8Array<ArrayBuffer>)} entropy - Cryptographically secure random value\r
        * @returns {string} Mnemonic phrase created using the BIP-39 wordlist\r
        */\r
        static async fromEntropy (entropy: string | Uint8Array<ArrayBuffer>): Promise<Bip39Mnemonic> {\r
@@ -62,7 +63,7 @@ export class Bip39Mnemonic {
        /**\r
        * Imports and validates an existing mnemonic phrase.\r
        *\r
-       * The phrase must be valid according to the BIP-39 specification. Typically\r
+       * The phrase must be valid according to the BIP-39 specification. Typically,\r
        * wallets use the maximum of 24 words.\r
        *\r
        * @param {string} phrase - String of 12, 15, 18, 21, or 24 words\r
@@ -81,7 +82,7 @@ export class Bip39Mnemonic {
        }\r
 \r
        /**\r
-       * Validates a mnemonic phrase.\r
+       * Validates a mnemonic phrase meets the BIP-39 specification.\r
        *\r
        * @param {string} mnemonic - Mnemonic phrase to validate\r
        * @returns {boolean} True if the mnemonic phrase is valid\r
@@ -142,8 +143,7 @@ export class Bip39Mnemonic {
        }\r
 \r
        /**\r
-       * Erases seed bytes and releases variable references to allow garbage\r
-       * collection.\r
+       * Erases seed bytes and releases variable references.\r
        */\r
        destroy () {\r
                bytes.erase(this.#bip39Seed)\r
@@ -153,6 +153,15 @@ export class Bip39Mnemonic {
                this.#phrase = undefined\r
        }\r
 \r
+       /**\r
+       * Converts the mnemonic phrase to a BIP-39 seed.\r
+       *\r
+       * A passphrase string can be specified. If the passphrase is undefined, null,\r
+       * or not a string, the empty string ("") is used instead.\r
+       *\r
+       * @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: ""\r
+       * @returns {Promise<Uint8Array<ArrayBuffer>>} Promise for seed as bytes\r
+       */\r
        async toBip39Seed (passphrase: string): Promise<Uint8Array<ArrayBuffer>>\r
        /**\r
        * Converts the mnemonic phrase to a BIP-39 seed.\r
@@ -161,10 +170,10 @@ export class Bip39Mnemonic {
        * or not a string, the empty string ("") is used instead.\r
        *\r
        * @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: ""\r
-       * @returns {string} Hexadecimal seed\r
+       * @returns {Promise<string>}  Promise for seed as hexadecimal string\r
        */\r
        async toBip39Seed (passphrase: string, format: 'hex'): Promise<string>\r
-       async toBip39Seed (passphrase: string, format?: 'hex'): Promise<string | Uint8Array> {\r
+       async toBip39Seed (passphrase: string, format?: 'hex'): Promise<string | Uint8Array<ArrayBuffer>> {\r
                if (this.phrase == null) {\r
                        throw new Error('BIP-39 mnemonic phrase not found')\r
                }\r
@@ -205,6 +214,7 @@ export class Bip39Mnemonic {
        /**\r
        * Converts the mnemonic phrase to a BLAKE2b seed.\r
        *\r
+       * @param {string} format\r
        * @returns {Promise<string>} Promise for seed as hexadecimal string\r
        */\r
        async toBlake2bSeed (format: 'hex'): Promise<string>\r