import { LedgerStatus, LedgerTransport } from '.'
import { _account } from './account'
-import { version } from './version'
+import { queue } from './queue'
+import { _version } from './version'
/**
* Check if the Nano app is currently open and set device status accordingly.
export async function _connect (transport: LedgerTransport): Promise<LedgerStatus> {
let status: LedgerStatus = 'DISCONNECTED'
try {
- const v = await version(transport)
+ const v = await queue(async () => _version(transport))
if (v.status === 'LOCKED_DEVICE') {
status = 'LOCKED'
} else if (v.status !== 'OK') {
status = 'DISCONNECTED'
} else if (v.name === 'Nano') {
- const a = await _account(transport)
+ const a = await queue(async () => _account(transport))
if (a.status === 'OK') {
status = 'CONNECTED'
} else if (a.status === 'SECURITY_STATUS_NOT_SATISFIED') {
//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
//! SPDX-License-Identifier: GPL-3.0-or-later
-import { APDU_CODES, LedgerResponse, LedgerTransport, STATUS_CODES, LISTEN_TIMEOUT, OPEN_TIMEOUT } from '.'
+import { APDU_CODES, LedgerResponse, LedgerTransport, LISTEN_TIMEOUT, OPEN_TIMEOUT, STATUS_CODES } from '.'
import { bytes, dec } from '../convert'
-import { queue } from './queue'
interface LedgerVersionResponse extends LedgerResponse {
name: string | null,
*
* @returns Status, process name, and version
*/
-export async function version (transport: LedgerTransport): Promise<LedgerVersionResponse> {
- return queue<LedgerVersionResponse>(async () => {
- try {
- const t = await transport.create(OPEN_TIMEOUT, LISTEN_TIMEOUT)
- const response = await t
- .send(0xb0, APDU_CODES.version, APDU_CODES.paramUnused, APDU_CODES.paramUnused)
- .catch((err: any) => dec.toBytes(err.statusCode))
- .finally(async () => await t.close()) as Uint8Array
+export async function _version (transport: LedgerTransport): Promise<LedgerVersionResponse> {
+ try {
+ const t = await transport.create(OPEN_TIMEOUT, LISTEN_TIMEOUT)
+ const response = await t
+ .send(0xb0, APDU_CODES.version, APDU_CODES.paramUnused, APDU_CODES.paramUnused)
+ .catch((err: any) => dec.toBytes(err.statusCode))
+ .finally(async () => await t.close()) as Uint8Array
- const statusCode = bytes.toDec(response.slice(-2)) as number
- const status = STATUS_CODES[statusCode] ?? 'UNKNOWN_ERROR'
- if (status !== 'OK') {
- return { status, name: null, version: null }
- }
+ const statusCode = bytes.toDec(response.slice(-2)) as number
+ const status = 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()
+ 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 }
- } catch (err: any) {
- console.error('Ledger.#version()', err)
- return { status: err.message, name: null, version: null }
- }
- })
+ return { status, name, version }
+ } catch (err: any) {
+ console.error('Ledger.#version()', err)
+ return { status: err.message, name: null, version: null }
+ }
}