From: Chris Duncan Date: Fri, 11 Jul 2025 06:02:06 +0000 (-0700) Subject: Alphabetize methods. X-Git-Tag: v0.10.5~61 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=7b6507f3893a51fe643293bf3844bd2530faaabc;p=libnemo.git Alphabetize methods. --- diff --git a/src/lib/wallets/ledger-wallet.ts b/src/lib/wallets/ledger-wallet.ts index 492a4ad..dbf630d 100644 --- a/src/lib/wallets/ledger-wallet.ts +++ b/src/lib/wallets/ledger-wallet.ts @@ -198,6 +198,22 @@ export class LedgerWallet extends Wallet { } } + /** + * Retrieves an existing Ledger wallet from session storage using its ID. + * + * @param {string} id - Generated when the wallet was initially created + * @returns {LedgerWallet} Restored LedgerWallet + */ + static async restore (id: string): Promise { + if (typeof id !== 'string' || id === '') { + throw new TypeError('Wallet ID is required to restore') + } + LedgerWallet.#isInternal = true + const wallet = new this(await Entropy.import(id)) + await wallet.init() + return wallet + } + /** * Sign a block with the Ledger device. * @@ -228,22 +244,6 @@ export class LedgerWallet extends Wallet { } } - /** - * Retrieves an existing Ledger wallet from session storage using its ID. - * - * @param {string} id - Generated when the wallet was initially created - * @returns {LedgerWallet} Restored LedgerWallet - */ - static async restore (id: string): Promise { - if (typeof id !== 'string' || id === '') { - throw new TypeError('Wallet ID is required to restore') - } - LedgerWallet.#isInternal = true - const wallet = new this(await Entropy.import(id)) - await wallet.init() - return wallet - } - /** * Attempts to connect to the Ledger device. * @@ -348,35 +348,6 @@ export class LedgerWallet extends Wallet { return new Promise(r => setTimeout(r, 1000, { status: LEDGER_STATUS_CODES[response] })) } - /** - * Get the version of the current process. If a specific app is running, get - * the app version. Otherwise, get the Ledger BOLOS version instead. - * - * https://developers.ledger.com/docs/connectivity/ledgerJS/open-close-info-on-apps#get-information - * - * @returns Status, process name, and version - */ - async #version (): Promise { - const transport = await this.DynamicTransport.create(this.openTimeout, this.listenTimeout) - const response = await transport - .send(0xb0, LEDGER_ADPU_CODES.version, LEDGER_ADPU_CODES.paramUnused, LEDGER_ADPU_CODES.paramUnused) - .catch(err => dec.toBytes(err.statusCode)) as Uint8Array - await transport.close() - - const statusCode = bytes.toDec(response.slice(-2)) as number - const status = LEDGER_STATUS_CODES[statusCode] ?? 'UNKNOWN_ERROR' - if (status !== 'OK') { - return { status, name: null, version: null } - } - - const nameLength = response[1] - const name = response.slice(2, 2 + nameLength).toString() - const versionLength = response[2 + nameLength] - const version = response.slice(2 + nameLength + 1, 2 + nameLength + 1 + versionLength).toString() - - return { status, name, version } - } - /** * Request an account at a specific BIP-44 index. * @@ -529,6 +500,35 @@ export class LedgerWallet extends Wallet { throw new Error('Unexpected byte length from device signature', { cause: response }) } + /** + * Get the version of the current process. If a specific app is running, get + * the app version. Otherwise, get the Ledger BOLOS version instead. + * + * https://developers.ledger.com/docs/connectivity/ledgerJS/open-close-info-on-apps#get-information + * + * @returns Status, process name, and version + */ + async #version (): Promise { + const transport = await this.DynamicTransport.create(this.openTimeout, this.listenTimeout) + const response = await transport + .send(0xb0, LEDGER_ADPU_CODES.version, LEDGER_ADPU_CODES.paramUnused, LEDGER_ADPU_CODES.paramUnused) + .catch(err => dec.toBytes(err.statusCode)) as Uint8Array + await transport.close() + + const statusCode = bytes.toDec(response.slice(-2)) as number + const status = LEDGER_STATUS_CODES[statusCode] ?? 'UNKNOWN_ERROR' + if (status !== 'OK') { + return { status, name: null, version: null } + } + + const nameLength = response[1] + const name = response.slice(2, 2 + nameLength).toString() + const versionLength = response[2 + nameLength] + const version = response.slice(2 + nameLength + 1, 2 + nameLength + 1 + versionLength).toString() + + return { status, name, version } + } + /** * Gets the public key for an account from the Ledger device. *