From 4f9ebc0ce9a6a656e2f4689e4887ab2b3792bf95 Mon Sep 17 00:00:00 2001 From: jdabbech-ledger Date: Thu, 2 May 2024 17:42:12 +0200 Subject: [PATCH 1/4] :bug: (core): Browser compatibility with array accessors --- packages/core/src/api/apdu/utils/ApduParser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/src/api/apdu/utils/ApduParser.ts b/packages/core/src/api/apdu/utils/ApduParser.ts index 7c5cb2236..13a6df507 100644 --- a/packages/core/src/api/apdu/utils/ApduParser.ts +++ b/packages/core/src/api/apdu/utils/ApduParser.ts @@ -126,7 +126,7 @@ export class ApduParser { if (prefix) result += "0x"; while (index <= value.length) { - const item = value.at(index)?.toString(16); + const item = value[index]?.toString(16); if (item) result += item.length < 2 ? "0" + item : item; index++; } @@ -145,7 +145,7 @@ export class ApduParser { if (!value) return result; while (index <= value.length) { - const item = value.at(index); + const item = value[index]; if (item) result += String.fromCharCode(item); index++; } From 557e4238d434763a8633a6026019001c12cfdff5 Mon Sep 17 00:00:00 2001 From: jdabbech-ledger Date: Thu, 2 May 2024 17:44:20 +0200 Subject: [PATCH 2/4] :wrench: (core): Exclude test files from ts build --- packages/core/tsconfig.cjs.json | 7 ++++++- packages/core/tsconfig.esm.json | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/core/tsconfig.cjs.json b/packages/core/tsconfig.cjs.json index a797cc717..2c686b0dd 100644 --- a/packages/core/tsconfig.cjs.json +++ b/packages/core/tsconfig.cjs.json @@ -1,6 +1,11 @@ { "extends": "./tsconfig.json", - "exclude": ["src/**/*.test.ts", "jest.*.ts"], + "exclude": [ + "src/**/*.test.ts", + "src/**/*.stub.ts", + "src/**/__mocks__", + "jest.*.ts" + ], "compilerOptions": { "module": "commonjs", "moduleResolution": "node", diff --git a/packages/core/tsconfig.esm.json b/packages/core/tsconfig.esm.json index dd32a6fe4..582fb4f0f 100644 --- a/packages/core/tsconfig.esm.json +++ b/packages/core/tsconfig.esm.json @@ -1,6 +1,11 @@ { "extends": "./tsconfig.json", - "exclude": ["src/**/*.test.ts", "jest.*.ts"], + "exclude": [ + "src/**/*.test.ts", + "src/**/*.stub.ts", + "src/**/__mocks__", + "jest.*.ts" + ], "compilerOptions": { "module": "esnext", "outDir": "./lib/esm", From e3c24c83f82f8aeb9a09d99e48d6a1bbe0369140 Mon Sep 17 00:00:00 2001 From: jdabbech-ledger Date: Thu, 2 May 2024 18:15:05 +0200 Subject: [PATCH 3/4] :truck: (core): Move ApduResponse in @api --- packages/core/src/api/DeviceSdk.ts | 2 +- packages/core/src/api/apdu/utils/ApduParser.test.ts | 2 +- packages/core/src/api/apdu/utils/ApduParser.ts | 2 +- packages/core/src/api/command/Command.ts | 2 +- .../core/src/api/command/os/GetAppAndVersionCommand.test.ts | 2 +- packages/core/src/api/command/os/GetAppAndVersionCommand.ts | 2 +- .../core/src/api/command/os/GetBatteryStatusCommand.test.ts | 2 +- packages/core/src/api/command/os/GetBatteryStatusCommand.ts | 2 +- packages/core/src/api/command/os/GetOsVersionCommand.test.ts | 2 +- packages/core/src/api/command/os/GetOsVersionCommand.ts | 2 +- packages/core/src/api/command/utils/CommandUtils.test.ts | 2 +- packages/core/src/api/command/utils/CommandUtils.ts | 2 +- .../model => api/device-session}/ApduResponse.stub.ts | 0 .../device-session/model => api/device-session}/ApduResponse.ts | 0 packages/core/src/api/index.ts | 2 +- .../src/internal/device-session/service/ApduReceiverService.ts | 2 +- .../device-session/service/DefaultApduReceiverService.test.ts | 2 +- .../device-session/service/DefaultApduReceiverService.ts | 2 +- packages/core/src/internal/send/use-case/SendApduUseCase.ts | 2 +- .../core/src/internal/usb/model/InternalConnectedDevice.stub.ts | 2 +- .../core/src/internal/usb/model/InternalConnectedDevice.test.ts | 2 +- packages/core/src/internal/usb/transport/DeviceConnection.ts | 2 +- .../core/src/internal/usb/transport/UsbHidDeviceConnection.ts | 2 +- 23 files changed, 21 insertions(+), 21 deletions(-) rename packages/core/src/{internal/device-session/model => api/device-session}/ApduResponse.stub.ts (100%) rename packages/core/src/{internal/device-session/model => api/device-session}/ApduResponse.ts (100%) diff --git a/packages/core/src/api/DeviceSdk.ts b/packages/core/src/api/DeviceSdk.ts index 9ac08670b..60f0a53c9 100644 --- a/packages/core/src/api/DeviceSdk.ts +++ b/packages/core/src/api/DeviceSdk.ts @@ -6,13 +6,13 @@ import { SendCommandUseCase, SendCommandUseCaseArgs, } from "@api/command/use-case/SendCommandUseCase"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { DeviceSessionState } from "@api/device-session/DeviceSessionState"; import { DeviceSessionId } from "@api/device-session/types"; import { ConnectedDevice } from "@api/usb/model/ConnectedDevice"; import { configTypes } from "@internal/config/di/configTypes"; import { GetSdkVersionUseCase } from "@internal/config/use-case/GetSdkVersionUseCase"; import { deviceSessionTypes } from "@internal/device-session/di/deviceSessionTypes"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; import { GetDeviceSessionStateUseCase } from "@internal/device-session/use-case/GetDeviceSessionStateUseCase"; import { discoveryTypes } from "@internal/discovery/di/discoveryTypes"; import { diff --git a/packages/core/src/api/apdu/utils/ApduParser.test.ts b/packages/core/src/api/apdu/utils/ApduParser.test.ts index 54033d244..499fedc9d 100644 --- a/packages/core/src/api/apdu/utils/ApduParser.test.ts +++ b/packages/core/src/api/apdu/utils/ApduParser.test.ts @@ -1,4 +1,4 @@ -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { ApduParser } from "./ApduParser"; diff --git a/packages/core/src/api/apdu/utils/ApduParser.ts b/packages/core/src/api/apdu/utils/ApduParser.ts index 13a6df507..9e05c0146 100644 --- a/packages/core/src/api/apdu/utils/ApduParser.ts +++ b/packages/core/src/api/apdu/utils/ApduParser.ts @@ -1,4 +1,4 @@ -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; export type TaggedField = { tag: number; diff --git a/packages/core/src/api/command/Command.ts b/packages/core/src/api/command/Command.ts index 8d9795fde..2f7f6f479 100644 --- a/packages/core/src/api/command/Command.ts +++ b/packages/core/src/api/command/Command.ts @@ -1,6 +1,6 @@ import { Apdu } from "@api/apdu/model/Apdu"; import { DeviceModelId } from "@api/device/DeviceModel"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; export interface Command { getApdu(args?: U): Apdu; diff --git a/packages/core/src/api/command/os/GetAppAndVersionCommand.test.ts b/packages/core/src/api/command/os/GetAppAndVersionCommand.test.ts index 5fc680830..c6268c2b9 100644 --- a/packages/core/src/api/command/os/GetAppAndVersionCommand.test.ts +++ b/packages/core/src/api/command/os/GetAppAndVersionCommand.test.ts @@ -3,7 +3,7 @@ import { InvalidResponseFormatError, InvalidStatusWordError, } from "@api/command/Errors"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { GetAppAndVersionCommand, diff --git a/packages/core/src/api/command/os/GetAppAndVersionCommand.ts b/packages/core/src/api/command/os/GetAppAndVersionCommand.ts index 596fb5ea8..b91178a0e 100644 --- a/packages/core/src/api/command/os/GetAppAndVersionCommand.ts +++ b/packages/core/src/api/command/os/GetAppAndVersionCommand.ts @@ -7,7 +7,7 @@ import { InvalidStatusWordError, } from "@api/command/Errors"; import { CommandUtils } from "@api/command/utils/CommandUtils"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; export type GetAppAndVersionResponse = { name: string; diff --git a/packages/core/src/api/command/os/GetBatteryStatusCommand.test.ts b/packages/core/src/api/command/os/GetBatteryStatusCommand.test.ts index 060997a80..655328605 100644 --- a/packages/core/src/api/command/os/GetBatteryStatusCommand.test.ts +++ b/packages/core/src/api/command/os/GetBatteryStatusCommand.test.ts @@ -3,7 +3,7 @@ import { InvalidBatteryStatusTypeError, InvalidStatusWordError, } from "@api/command/Errors"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { BatteryStatusType, diff --git a/packages/core/src/api/command/os/GetBatteryStatusCommand.ts b/packages/core/src/api/command/os/GetBatteryStatusCommand.ts index 1aaac4345..c692a78da 100644 --- a/packages/core/src/api/command/os/GetBatteryStatusCommand.ts +++ b/packages/core/src/api/command/os/GetBatteryStatusCommand.ts @@ -9,7 +9,7 @@ import { InvalidStatusWordError, } from "@api/command/Errors"; import { CommandUtils } from "@api/command/utils/CommandUtils"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; export enum BatteryStatusType { BATTERY_PERCENTAGE = 0x00, diff --git a/packages/core/src/api/command/os/GetOsVersionCommand.test.ts b/packages/core/src/api/command/os/GetOsVersionCommand.test.ts index fbc8358cc..4deab02bc 100644 --- a/packages/core/src/api/command/os/GetOsVersionCommand.test.ts +++ b/packages/core/src/api/command/os/GetOsVersionCommand.test.ts @@ -1,7 +1,7 @@ import { Command } from "@api/command/Command"; import { InvalidStatusWordError } from "@api/command/Errors"; import { DeviceModelId } from "@api/device/DeviceModel"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { GetOsVersionCommand, diff --git a/packages/core/src/api/command/os/GetOsVersionCommand.ts b/packages/core/src/api/command/os/GetOsVersionCommand.ts index 4dc89c1e5..3eefb3571 100644 --- a/packages/core/src/api/command/os/GetOsVersionCommand.ts +++ b/packages/core/src/api/command/os/GetOsVersionCommand.ts @@ -5,7 +5,7 @@ import { Command } from "@api/command/Command"; import { InvalidStatusWordError } from "@api/command/Errors"; import { CommandUtils } from "@api/command/utils/CommandUtils"; import { DeviceModelId } from "@api/device/DeviceModel"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; export type GetOsVersionResponse = { targetId: string; diff --git a/packages/core/src/api/command/utils/CommandUtils.test.ts b/packages/core/src/api/command/utils/CommandUtils.test.ts index 7f8028faf..f38b16d00 100644 --- a/packages/core/src/api/command/utils/CommandUtils.test.ts +++ b/packages/core/src/api/command/utils/CommandUtils.test.ts @@ -1,4 +1,4 @@ -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { CommandUtils } from "./CommandUtils"; diff --git a/packages/core/src/api/command/utils/CommandUtils.ts b/packages/core/src/api/command/utils/CommandUtils.ts index 7042a0871..bc63a2789 100644 --- a/packages/core/src/api/command/utils/CommandUtils.ts +++ b/packages/core/src/api/command/utils/CommandUtils.ts @@ -1,4 +1,4 @@ -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; export class CommandUtils { static isValidStatusCode(statusCode: Uint8Array) { diff --git a/packages/core/src/internal/device-session/model/ApduResponse.stub.ts b/packages/core/src/api/device-session/ApduResponse.stub.ts similarity index 100% rename from packages/core/src/internal/device-session/model/ApduResponse.stub.ts rename to packages/core/src/api/device-session/ApduResponse.stub.ts diff --git a/packages/core/src/internal/device-session/model/ApduResponse.ts b/packages/core/src/api/device-session/ApduResponse.ts similarity index 100% rename from packages/core/src/internal/device-session/model/ApduResponse.ts rename to packages/core/src/api/device-session/ApduResponse.ts diff --git a/packages/core/src/api/index.ts b/packages/core/src/api/index.ts index 7e7c01e0c..89cd2ca28 100644 --- a/packages/core/src/api/index.ts +++ b/packages/core/src/api/index.ts @@ -2,6 +2,7 @@ export { DeviceModel, DeviceModelId } from "./device/DeviceModel"; export { DeviceStatus } from "./device/DeviceStatus"; +export { ApduResponse } from "./device-session/ApduResponse"; export { DeviceSdk } from "./DeviceSdk"; export { LedgerDeviceSdkBuilder as DeviceSdkBuilder } from "./DeviceSdkBuilder"; export { LogLevel } from "./logger-subscriber/model/LogLevel"; @@ -9,4 +10,3 @@ export { ConsoleLogger } from "./logger-subscriber/service/ConsoleLogger"; export * from "./types"; export { ConnectedDevice } from "./usb/model/ConnectedDevice"; export { DeviceSessionState } from "@api/device-session/DeviceSessionState"; -export { ApduResponse } from "@internal/device-session/model/ApduResponse"; diff --git a/packages/core/src/internal/device-session/service/ApduReceiverService.ts b/packages/core/src/internal/device-session/service/ApduReceiverService.ts index a8407bc21..7185891e8 100644 --- a/packages/core/src/internal/device-session/service/ApduReceiverService.ts +++ b/packages/core/src/internal/device-session/service/ApduReceiverService.ts @@ -1,7 +1,7 @@ import { Either, Maybe } from "purify-ts"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { SdkError } from "@api/Error"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; export interface ApduReceiverService { handleFrame(apdu: Uint8Array): Either>; diff --git a/packages/core/src/internal/device-session/service/DefaultApduReceiverService.test.ts b/packages/core/src/internal/device-session/service/DefaultApduReceiverService.test.ts index d8a603273..d3ea8cf0a 100644 --- a/packages/core/src/internal/device-session/service/DefaultApduReceiverService.test.ts +++ b/packages/core/src/internal/device-session/service/DefaultApduReceiverService.test.ts @@ -3,7 +3,7 @@ jest.mock("uuid"); import { Just, Left, Maybe, Nothing, Right } from "purify-ts"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { ReceiverApduError } from "@internal/device-session/model/Errors"; import { DefaultLoggerPublisherService } from "@internal/logger-publisher/service/DefaultLoggerPublisherService"; diff --git a/packages/core/src/internal/device-session/service/DefaultApduReceiverService.ts b/packages/core/src/internal/device-session/service/DefaultApduReceiverService.ts index f149ed605..805e21a68 100644 --- a/packages/core/src/internal/device-session/service/DefaultApduReceiverService.ts +++ b/packages/core/src/internal/device-session/service/DefaultApduReceiverService.ts @@ -2,6 +2,7 @@ import { inject, injectable } from "inversify"; import { Either, Just, Left, Maybe, Nothing, Right } from "purify-ts"; import { v4 } from "uuid"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { APDU_RESPONSE_STATUS_CODE_LENGTH } from "@internal/device-session/data/ApduResponseConst"; import { APDU_DATA_LENGTH_LENGTH, @@ -9,7 +10,6 @@ import { HEAD_TAG_LENGTH, INDEX_LENGTH, } from "@internal/device-session/data/FramerConst"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; import { ReceiverApduError } from "@internal/device-session/model/Errors"; import { Frame } from "@internal/device-session/model/Frame"; import { FrameHeader } from "@internal/device-session/model/FrameHeader"; diff --git a/packages/core/src/internal/send/use-case/SendApduUseCase.ts b/packages/core/src/internal/send/use-case/SendApduUseCase.ts index a7e6e07f0..248785aa3 100644 --- a/packages/core/src/internal/send/use-case/SendApduUseCase.ts +++ b/packages/core/src/internal/send/use-case/SendApduUseCase.ts @@ -1,8 +1,8 @@ import { inject, injectable } from "inversify"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { DeviceSessionId } from "@api/device-session/types"; import { deviceSessionTypes } from "@internal/device-session/di/deviceSessionTypes"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; import type { DeviceSessionService } from "@internal/device-session/service/DeviceSessionService"; import { loggerTypes } from "@internal/logger-publisher/di/loggerTypes"; import { LoggerPublisherService } from "@internal/logger-publisher/service/LoggerPublisherService"; diff --git a/packages/core/src/internal/usb/model/InternalConnectedDevice.stub.ts b/packages/core/src/internal/usb/model/InternalConnectedDevice.stub.ts index a5502c09b..2d4617dc4 100644 --- a/packages/core/src/internal/usb/model/InternalConnectedDevice.stub.ts +++ b/packages/core/src/internal/usb/model/InternalConnectedDevice.stub.ts @@ -1,7 +1,7 @@ import { Right } from "purify-ts"; +import { defaultApduResponseStubBuilder } from "@api/device-session/ApduResponse.stub"; import { deviceModelStubBuilder } from "@internal/device-model/model/DeviceModel.stub"; -import { defaultApduResponseStubBuilder } from "@internal/device-session/model/ApduResponse.stub"; import { ConnectedDeviceConstructorArgs, InternalConnectedDevice, diff --git a/packages/core/src/internal/usb/model/InternalConnectedDevice.test.ts b/packages/core/src/internal/usb/model/InternalConnectedDevice.test.ts index c6afaf37d..a14f90d9c 100644 --- a/packages/core/src/internal/usb/model/InternalConnectedDevice.test.ts +++ b/packages/core/src/internal/usb/model/InternalConnectedDevice.test.ts @@ -1,5 +1,5 @@ +import { defaultApduResponseStubBuilder } from "@api/device-session/ApduResponse.stub"; import { deviceModelStubBuilder } from "@internal/device-model/model/DeviceModel.stub"; -import { defaultApduResponseStubBuilder } from "@internal/device-session/model/ApduResponse.stub"; import { InternalConnectedDevice } from "@internal/usb/model/InternalConnectedDevice"; import { connectedDeviceStubBuilder } from "@internal/usb/model/InternalConnectedDevice.stub"; diff --git a/packages/core/src/internal/usb/transport/DeviceConnection.ts b/packages/core/src/internal/usb/transport/DeviceConnection.ts index ddf27e177..7f1cb1448 100644 --- a/packages/core/src/internal/usb/transport/DeviceConnection.ts +++ b/packages/core/src/internal/usb/transport/DeviceConnection.ts @@ -1,7 +1,7 @@ import { Either } from "purify-ts"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { SdkError } from "@api/Error"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; export type SendApduFnType = ( apdu: Uint8Array, diff --git a/packages/core/src/internal/usb/transport/UsbHidDeviceConnection.ts b/packages/core/src/internal/usb/transport/UsbHidDeviceConnection.ts index 87b11a403..140796d78 100644 --- a/packages/core/src/internal/usb/transport/UsbHidDeviceConnection.ts +++ b/packages/core/src/internal/usb/transport/UsbHidDeviceConnection.ts @@ -2,7 +2,7 @@ import { inject } from "inversify"; import { Left, Right } from "purify-ts"; import { Subject } from "rxjs"; -import { ApduResponse } from "@internal/device-session/model/ApduResponse"; +import { ApduResponse } from "@api/device-session/ApduResponse"; import { ApduReceiverService } from "@internal/device-session/service/ApduReceiverService"; import { ApduSenderService } from "@internal/device-session/service/ApduSenderService"; import { loggerTypes } from "@internal/logger-publisher/di/loggerTypes"; From 192c63c12bb19f8d5e2314cab00ea7fbf6c93b47 Mon Sep 17 00:00:00 2001 From: jdabbech-ledger Date: Thu, 2 May 2024 17:48:51 +0200 Subject: [PATCH 4/4] :bookmark: (core): Changeset --- .changeset/stupid-boats-tan.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stupid-boats-tan.md diff --git a/.changeset/stupid-boats-tan.md b/.changeset/stupid-boats-tan.md new file mode 100644 index 000000000..db82836c5 --- /dev/null +++ b/.changeset/stupid-boats-tan.md @@ -0,0 +1,5 @@ +--- +"@ledgerhq/device-sdk-core": patch +--- + +Clean exports