]> git.codecow.com Git - libnemo.git/commitdiff
It's APDU, not ADPU. /facepalm
authorChris Duncan <chris@zoso.dev>
Wed, 24 Sep 2025 06:30:41 +0000 (23:30 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 24 Sep 2025 06:30:41 +0000 (23:30 -0700)
src/lib/ledger/index.ts
src/lib/wallet/index.ts

index 336e23dd84aa8bf4d17635cc127d5aa7910a72e1..2e2e9045603f87d2cbd56944eff144d9b374b483 100644 (file)
@@ -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
 
index d116e436231c4eec55c160b2f5aa2d40dbe22aa5..039c29c64142957029df492aaf422dd8c1259d65 100644 (file)
@@ -290,7 +290,7 @@ export class Wallet {
        * For BIP-44 and BLAKE2b wallets, clears the seed and mnemonic from the vault.\r
        *\r
        * For Ledger hardware wallets, revokes permission granted by the user to\r
-       * access the Ledger device. The 'quit app' ADPU command is uncooperative, so\r
+       * access the Ledger device. The 'quit app' APDU command is uncooperative, so\r
        * this is currently the only way to ensure the connection is severed.\r
        * `setTimeout` is used to expire any lingering transient user activation.\r
        */\r