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++];