From: Chris Duncan Date: Wed, 24 Sep 2025 06:30:41 +0000 (-0700) Subject: It's APDU, not ADPU. /facepalm X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=576f4f8513095a6a8e9d745a432b105334e077f5;p=libnemo.git It's APDU, not ADPU. /facepalm --- diff --git a/src/lib/ledger/index.ts b/src/lib/ledger/index.ts index 336e23d..2e2e904 100644 --- a/src/lib/ledger/index.ts +++ b/src/lib/ledger/index.ts @@ -33,7 +33,7 @@ interface LedgerSignResponse extends LedgerResponse { } /** -* Ledger hardware wallet created by communicating with a Ledger device via ADPU +* Ledger hardware wallet created by communicating with a Ledger device via APDU * calls. This wallet does not feature any seed nor mnemonic phrase as all * private keys are held in the secure chip of the device. As such, the user * is responsible for using Ledger technology to back up these pieces of data. @@ -48,7 +48,7 @@ export class Ledger { static #queue: { task: Function, resolve: Function, reject: Function }[] = [] static #status: LedgerStatus = 'DISCONNECTED' static #transport: DeviceManagementKit - static #ADPU_CODES: { [key: string]: number } = Object.freeze({ + static #APDU_CODES: { [key: string]: number } = Object.freeze({ class: 0xa1, bip32DerivationLevel: 0x03, version: 0x01, @@ -59,7 +59,7 @@ export class Ledger { paramUnused: 0x00 }) static #DERIVATION_PATH: Uint8Array = new Uint8Array([ - this.#ADPU_CODES.bip32DerivationLevel, + this.#APDU_CODES.bip32DerivationLevel, ...dec.toBytes(BIP44_PURPOSE + HARDENED_OFFSET, 4), ...dec.toBytes(BIP44_COIN_NANO + HARDENED_OFFSET, 4) ]) @@ -132,10 +132,10 @@ export class Ledger { const account = dec.toBytes(index + HARDENED_OFFSET, 4) const data = new Uint8Array([...this.#DERIVATION_PATH, ...account]) const apdu = new ApduBuilder({ - ins: this.#ADPU_CODES.account, - cla: this.#ADPU_CODES.class, + ins: this.#APDU_CODES.account, + cla: this.#APDU_CODES.class, p1: show ? 1 : 0, - p2: this.#ADPU_CODES.paramUnused + p2: this.#APDU_CODES.paramUnused }).addBufferToData(data).build().getRawApdu() const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) @@ -375,11 +375,11 @@ export class Ledger { const representative = hex.toBytes(block.representative.publicKey, 32) const balance = hex.toBytes(block.balance.toString(16), 16) const signature = hex.toBytes(block.signature, 64) - const data = new Uint8Array([this.#ADPU_CODES.bip32DerivationLevel, ...purpose, ...coin, ...account, ...previous, ...link, ...representative, ...balance, ...signature]) + const data = new Uint8Array([this.#APDU_CODES.bip32DerivationLevel, ...purpose, ...coin, ...account, ...previous, ...link, ...representative, ...balance, ...signature]) const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) const response = await transport - .send(this.#ADPU_CODES.class, this.#ADPU_CODES.cacheBlock, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused, data as Buffer) + .send(this.#APDU_CODES.class, this.#APDU_CODES.cacheBlock, this.#APDU_CODES.paramUnused, this.#APDU_CODES.paramUnused, data as Buffer) .then((res: Buffer) => bytes.toDec(res)) .catch((err: any) => err.statusCode) .finally(async () => await transport.close()) as number @@ -409,7 +409,7 @@ export class Ledger { return this.#enqueue(async () => { const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) const response = await transport - .send(0xb0, 0xa7, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused) + .send(0xb0, 0xa7, this.#APDU_CODES.paramUnused, this.#APDU_CODES.paramUnused) .then((res: Buffer) => bytes.toDec(res)) .catch((err: any) => err.statusCode) .finally(async () => await transport.close()) as number @@ -490,7 +490,7 @@ export class Ledger { const name = new TextEncoder().encode('Nano') const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) const response = await transport - .send(0xe0, 0xd8, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused, name as Buffer) + .send(0xe0, 0xd8, this.#APDU_CODES.paramUnused, this.#APDU_CODES.paramUnused, name as Buffer) .then((res: Buffer) => bytes.toDec(res)) .catch((err: any) => err.statusCode) .finally(async () => await transport.close()) as number @@ -559,7 +559,7 @@ export class Ledger { const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) const response = await transport - .send(this.#ADPU_CODES.class, this.#ADPU_CODES.signBlock, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused, data as Buffer) + .send(this.#APDU_CODES.class, this.#APDU_CODES.signBlock, this.#APDU_CODES.paramUnused, this.#APDU_CODES.paramUnused, data as Buffer) .catch((err: any) => dec.toBytes(err.statusCode)) .finally(async () => await transport.close()) as Uint8Array @@ -606,7 +606,7 @@ export class Ledger { const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) const response = await transport - .send(this.#ADPU_CODES.class, this.#ADPU_CODES.signNonce, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused, data as Buffer) + .send(this.#APDU_CODES.class, this.#APDU_CODES.signNonce, this.#APDU_CODES.paramUnused, this.#APDU_CODES.paramUnused, data as Buffer) .catch((err: any) => dec.toBytes(err.statusCode)) .finally(async () => await transport.close()) as Uint8Array @@ -638,7 +638,7 @@ export class Ledger { try { const transport = await this.#transport.create(this.#openTimeout, this.#listenTimeout) const response = await transport - .send(0xb0, this.#ADPU_CODES.version, this.#ADPU_CODES.paramUnused, this.#ADPU_CODES.paramUnused) + .send(0xb0, this.#APDU_CODES.version, this.#APDU_CODES.paramUnused, this.#APDU_CODES.paramUnused) .catch((err: any) => dec.toBytes(err.statusCode)) .finally(async () => await transport.close()) as Uint8Array diff --git a/src/lib/wallet/index.ts b/src/lib/wallet/index.ts index d116e43..039c29c 100644 --- a/src/lib/wallet/index.ts +++ b/src/lib/wallet/index.ts @@ -290,7 +290,7 @@ export class Wallet { * For BIP-44 and BLAKE2b wallets, clears the seed and mnemonic from the vault. * * For Ledger hardware wallets, revokes permission granted by the user to - * access the Ledger device. The 'quit app' ADPU command is uncooperative, so + * access the Ledger device. The 'quit app' APDU command is uncooperative, so * this is currently the only way to ensure the connection is severed. * `setTimeout` is used to expire any lingering transient user activation. */