From 673d94a642c5a319cd9722f6d1e3d1b52916b138 Mon Sep 17 00:00:00 2001 From: Juan Cortes Ross Date: Thu, 24 Feb 2022 16:08:22 +0100 Subject: [PATCH] LIVE-1469 Handle onboarded devices in device actions --- src/errors.ts | 1 + src/hw/getAppAndVersion.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/errors.ts b/src/errors.ts index d7d6f81708..b51e92f367 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -23,6 +23,7 @@ export const LowerThanMinimumRelayFee = createCustomErrorClass( export const TransactionRefusedOnDevice = createCustomErrorClass( "TransactionRefusedOnDevice" ); +export const DeviceNotOnboarded = createCustomErrorClass("DeviceNotOnboarded"); export const InvalidAddressBecauseAlreadyDelegated = createCustomErrorClass( "InvalidAddressBecauseAlreadyDelegated" ); diff --git a/src/hw/getAppAndVersion.ts b/src/hw/getAppAndVersion.ts index 6b0466e696..ea17ba368a 100644 --- a/src/hw/getAppAndVersion.ts +++ b/src/hw/getAppAndVersion.ts @@ -1,4 +1,8 @@ -import { GetAppAndVersionUnsupportedFormat } from "../errors"; +import { TransportStatusError } from "@ledgerhq/errors"; +import { + GetAppAndVersionUnsupportedFormat, + DeviceNotOnboarded, +} from "../errors"; import Transport from "@ledgerhq/hw-transport"; export default async ( transport: Transport @@ -7,7 +11,16 @@ export default async ( version: string; flags: number | Buffer; }> => { - const r = await transport.send(0xb0, 0x01, 0x00, 0x00); + const r = await transport.send(0xb0, 0x01, 0x00, 0x00).catch((e) => { + if (e instanceof TransportStatusError) { + // @ts-expect-error typescript not checking agains the instanceof + if (e.statusCode === 0x6d06) { + throw new DeviceNotOnboarded(); + } + } + + throw e; + }); let i = 0; const format = r[i++];