}
/**
-* 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.
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,
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)
])
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)
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
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
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
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
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
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