From 909adf367270c48a9d42046c13188b603c1ee6a2 Mon Sep 17 00:00:00 2001 From: Alejo Acosta Date: Wed, 6 Nov 2024 15:10:40 -0300 Subject: [PATCH] add JSDOC comments to methods --- src/wallet/hdwallet.ts | 97 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 18 deletions(-) diff --git a/src/wallet/hdwallet.ts b/src/wallet/hdwallet.ts index 367213d9..526a5fe9 100644 --- a/src/wallet/hdwallet.ts +++ b/src/wallet/hdwallet.ts @@ -140,15 +140,94 @@ export abstract class AbstractHDWallet} Promise that resolves to the next address info + */ abstract getNextAddress(account: number, zone: Zone): Promise; + + /** + * Synchronously gets the next available address for a given account and zone. + * + * @param {number} account - The account number to get the next address for + * @param {Zone} zone - The zone to get the next address in + * @returns {T} The next address info + */ abstract getNextAddressSync(account: number, zone: Zone): T; + + /** + * Gets the address info for a given address string. + * + * @param {string} address - The address to get info for + * @returns {T | null} The address info if found, null otherwise + */ abstract getAddressInfo(address: string): T | null; + + /** + * Gets the private key for a given address. + * + * @param {string} address - The address to get the private key for + * @returns {string} The private key as a hex string + */ abstract getPrivateKey(address: string): string; + + /** + * Gets all addresses belonging to a specific zone. + * + * @param {Zone} zone - The zone to get addresses for + * @returns {T[]} Array of address info objects in the zone + */ abstract getAddressesForZone(zone: Zone): T[]; + + /** + * Gets all addresses belonging to a specific account. + * + * @param {number} account - The account number to get addresses for + * @returns {T[]} Array of address info objects in the account + */ abstract getAddressesForAccount(account: number): T[]; + + /** + * Finds the highest used index for a given account and zone. + * + * @param {T[] | undefined} addresses - Array of address info objects to search + * @param {number} account - The account number to find the last index for + * @param {Zone} zone - The zone to find the last index in + * @returns {number} The highest used index, or -1 if none found + * @protected + */ protected abstract _findLastUsedIndex(addresses: T[] | undefined, account: number, zone: Zone): number; + /** + * Abstract method to sign a message using the private key associated with the given address. + * + * @param {string} address - The address for which the message is to be signed. + * @param {string | Uint8Array} message - The message to be signed, either as a string or Uint8Array. + * @returns {Promise} A promise that resolves to the signature of the message in hexadecimal string format. + * @throws {Error} If the method is not implemented in the subclass. + */ + abstract signMessage(address: string, message: string | Uint8Array): Promise; + + /** + * Abstract method to sign a transaction. + * + * @param {TransactionRequest} tx - The transaction request. + * @returns {Promise} A promise that resolves to the signed transaction. + */ + abstract signTransaction(tx: TransactionRequest): Promise; + /** * Creates an instance of the HD wallet. * @@ -227,14 +306,6 @@ export abstract class AbstractHDWallet} A promise that resolves to the signed transaction. - */ - abstract signTransaction(tx: TransactionRequest): Promise; - /** * Connects the wallet to a provider. * @@ -256,16 +327,6 @@ export abstract class AbstractHDWallet} A promise that resolves to the signature of the message in hexadecimal string format. - * @throws {Error} If the method is not implemented in the subclass. - */ - abstract signMessage(address: string, message: string | Uint8Array): Promise; - /** * Serializes the HD wallet state into a format suitable for storage or transmission. *