@ledgerhq/device-transport-kit-web-hid 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/esm/api/model/HIDDevice.stub.js.map +2 -2
- package/lib/esm/api/transport/WebHidApduSender.js +2 -0
- package/lib/esm/api/transport/WebHidApduSender.js.map +7 -0
- package/lib/esm/api/transport/WebHidApduSender.test.js +2 -0
- package/lib/esm/api/transport/WebHidApduSender.test.js.map +7 -0
- package/lib/esm/api/transport/WebHidTransport.js +1 -1
- package/lib/esm/api/transport/WebHidTransport.js.map +3 -3
- package/lib/esm/api/transport/WebHidTransport.test.js +1 -1
- package/lib/esm/api/transport/WebHidTransport.test.js.map +3 -3
- package/lib/esm/package.json +13 -13
- package/lib/types/api/model/HIDDevice.stub.d.ts.map +1 -1
- package/lib/types/api/transport/WebHidApduSender.d.ts +25 -0
- package/lib/types/api/transport/WebHidApduSender.d.ts.map +1 -0
- package/lib/types/api/transport/WebHidApduSender.test.d.ts +2 -0
- package/lib/types/api/transport/WebHidApduSender.test.d.ts.map +1 -0
- package/lib/types/api/transport/WebHidTransport.d.ts +7 -4
- package/lib/types/api/transport/WebHidTransport.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +11 -11
- package/lib/esm/api/transport/WebHidDeviceConnection.js +0 -2
- package/lib/esm/api/transport/WebHidDeviceConnection.js.map +0 -7
- package/lib/esm/api/transport/WebHidDeviceConnection.stub.js +0 -2
- package/lib/esm/api/transport/WebHidDeviceConnection.stub.js.map +0 -7
- package/lib/esm/api/transport/WebHidDeviceConnection.test.js +0 -2
- package/lib/esm/api/transport/WebHidDeviceConnection.test.js.map +0 -7
- package/lib/types/api/transport/WebHidDeviceConnection.d.ts +0 -49
- package/lib/types/api/transport/WebHidDeviceConnection.d.ts.map +0 -1
- package/lib/types/api/transport/WebHidDeviceConnection.stub.d.ts +0 -5
- package/lib/types/api/transport/WebHidDeviceConnection.stub.d.ts.map +0 -1
- package/lib/types/api/transport/WebHidDeviceConnection.test.d.ts +0 -2
- package/lib/types/api/transport/WebHidDeviceConnection.test.d.ts.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/transport/WebHidTransport.test.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: off */\nimport {\n type ApduReceiverServiceFactory,\n type ApduSenderServiceFactory,\n connectedDeviceStubBuilder,\n type DeviceModel,\n DeviceModelId,\n DeviceNotRecognizedError,\n type LoggerPublisherService,\n type LoggerSubscriberService,\n NoAccessibleDeviceError,\n OpeningConnectionError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n UnknownDeviceError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { Subject } from \"rxjs\";\n\nimport { RECONNECT_DEVICE_TIMEOUT } from \"@api/data/WebHidConfig\";\nimport { WebHidTransportNotSupportedError } from \"@api/model/Errors\";\nimport { hidDeviceStubBuilder } from \"@api/model/HIDDevice.stub\";\n\nimport { WebHidTransport } from \"./WebHidTransport\";\n\nclass LoggerPublisherServiceStub implements LoggerPublisherService {\n constructor(subscribers: LoggerSubscriberService[], tag: string) {\n this.subscribers = subscribers;\n this.tag = tag;\n }\n subscribers: LoggerSubscriberService[] = [];\n tag: string = \"\";\n error = vi.fn();\n warn = vi.fn();\n info = vi.fn();\n debug = vi.fn();\n}\n\n// Our StaticDeviceModelDataSource can directly be used in our unit tests\nconst usbDeviceModelDataSource = new StaticDeviceModelDataSource();\nconst logger = new LoggerPublisherServiceStub([], \"web-usb-hid\");\n\nconst stubDevice: HIDDevice = hidDeviceStubBuilder();\n\n/**\n * Flushes all pending promises\n */\nconst flushPromises = async () => {\n const timers = await vi.importActual<typeof import(\"timers\")>(\"timers\");\n return new Promise(timers.setImmediate);\n};\n\ndescribe(\"WebHidTransport\", () => {\n let transport: WebHidTransport;\n let apduReceiverServiceFactoryStub: ApduReceiverServiceFactory;\n let apduSenderServiceFactoryStub: ApduSenderServiceFactory;\n\n function initializeTransport() {\n apduReceiverServiceFactoryStub = vi.fn();\n apduSenderServiceFactoryStub = vi.fn();\n transport = new WebHidTransport(\n usbDeviceModelDataSource,\n () => logger,\n apduSenderServiceFactoryStub,\n apduReceiverServiceFactoryStub,\n );\n }\n\n beforeEach(() => {\n initializeTransport();\n vi.useFakeTimers();\n });\n\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n const discoverDevice = (\n onSuccess: (discoveredDevice: TransportDiscoveredDevice) => void,\n onError?: (error: unknown) => void,\n ) => {\n transport.startDiscovering().subscribe({\n next: onSuccess,\n error: onError,\n });\n };\n\n describe(\"When WebHID API is not supported\", () => {\n it(\"should not support the transport\", () => {\n expect(transport.isSupported()).toBe(false);\n });\n\n it(\"should emit a startDiscovering error\", () =>\n new Promise<void>((resolve, reject) => {\n discoverDevice(\n () => {\n reject(\"Should not emit any value\");\n },\n (error) => {\n expect(error).toBeInstanceOf(WebHidTransportNotSupportedError);\n resolve();\n },\n );\n }));\n });\n\n describe(\"When WebHID API is supported\", () => {\n const mockedGetDevices = vi.fn();\n const mockedRequestDevice = vi.fn();\n\n const connectionEventsSubject = new Subject<HIDConnectionEvent>();\n const disconnectionEventsSubject = new Subject<HIDConnectionEvent>();\n\n function emitHIDConnectionEvent(device: HIDDevice) {\n connectionEventsSubject.next({\n device,\n } as HIDConnectionEvent);\n }\n\n function emitHIDDisconnectionEvent(device: HIDDevice) {\n disconnectionEventsSubject.next({\n device,\n } as HIDConnectionEvent);\n }\n\n beforeEach(() => {\n global.navigator = {\n hid: {\n getDevices: mockedGetDevices,\n requestDevice: mockedRequestDevice,\n addEventListener: (\n eventName: string,\n callback: (event: HIDConnectionEvent) => void,\n ) => {\n if (eventName === \"disconnect\") {\n disconnectionEventsSubject.subscribe(callback);\n } else if (eventName === \"connect\") {\n connectionEventsSubject.subscribe(callback);\n }\n },\n },\n } as unknown as Navigator;\n initializeTransport();\n });\n\n afterEach(() => {\n vi.clearAllMocks();\n global.navigator = undefined as unknown as Navigator;\n });\n\n it(\"should support the transport\", () => {\n expect(transport.isSupported()).toBe(true);\n });\n\n describe(\"startDiscovering\", () => {\n const testCases = usbDeviceModelDataSource\n .getAllDeviceModels()\n .flatMap((deviceModel) => {\n return [\n {\n testTitle: `should emit device if user grants access through hid.requestDevice (${deviceModel.productName})`,\n hidDevice: hidDeviceStubBuilder({\n productId: deviceModel.usbProductId << 8,\n productName: deviceModel.productName,\n }),\n expectedDeviceModel: deviceModel,\n },\n {\n testTitle: `should emit device if user grants access through hid.requestDevice (${deviceModel.productName}, bootloader)`,\n hidDevice: hidDeviceStubBuilder({\n productId: deviceModel.bootloaderUsbProductId,\n productName: deviceModel.productName,\n }),\n expectedDeviceModel: deviceModel,\n },\n ];\n });\n\n testCases.forEach((testCase) => {\n it(\n testCase.testTitle,\n () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([testCase.hidDevice]);\n\n discoverDevice(\n (discoveredDevice) => {\n try {\n expect(discoveredDevice).toEqual(\n expect.objectContaining({\n deviceModel: testCase.expectedDeviceModel,\n }),\n );\n\n resolve();\n } catch (expectError) {\n reject(expectError as Error);\n }\n },\n (error) => {\n reject(error as Error);\n },\n );\n }),\n );\n });\n\n // It does not seem possible for a user to select several devices on the browser popup.\n // But if it was possible, we should emit them\n it(\"should emit devices if new grant accesses\", () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([\n stubDevice,\n {\n ...stubDevice,\n productId: 0x5011,\n productName: \"Ledger Nano S Plus\",\n },\n ]);\n\n let count = 0;\n discoverDevice(\n (discoveredDevice) => {\n try {\n switch (count) {\n case 0:\n expect(discoveredDevice).toEqual(\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n productName: \"Ledger Nano X\",\n usbProductId: 0x40,\n }) as DeviceModel,\n }),\n );\n break;\n case 1:\n expect(discoveredDevice).toEqual(\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_SP,\n productName: \"Ledger Nano S Plus\",\n usbProductId: 0x50,\n }) as DeviceModel,\n }),\n );\n\n resolve();\n break;\n }\n\n count++;\n } catch (expectError) {\n reject(expectError as Error);\n }\n },\n (error) => {\n reject(error as Error);\n },\n );\n }));\n\n it(\"should throw DeviceNotRecognizedError if the device is not recognized\", () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([\n {\n ...stubDevice,\n productId: 0x4242,\n },\n ]);\n\n discoverDevice(\n () => {\n reject(\"should not return a device\");\n },\n (error) => {\n expect(error).toBeInstanceOf(DeviceNotRecognizedError);\n resolve();\n },\n );\n }));\n\n it(\"should emit an error if the request device is in error\", () =>\n new Promise<void>((resolve, reject) => {\n const message = \"request device error\";\n mockedRequestDevice.mockImplementationOnce(() => {\n throw new Error(message);\n });\n\n discoverDevice(\n () => {\n reject(\"should not return a device\");\n },\n (error) => {\n expect(error).toBeInstanceOf(NoAccessibleDeviceError);\n expect(error).toStrictEqual(\n new NoAccessibleDeviceError(new Error(message)),\n );\n resolve();\n },\n );\n }));\n\n // [ASK] Is this the behavior we want when the user does not select any device ?\n it(\"should emit an error if the user did not grant us access to a device (clicking on cancel on the browser popup for ex)\", () =>\n new Promise<void>((resolve, reject) => {\n // When the user does not select any device, the `requestDevice` will return an empty array\n mockedRequestDevice.mockResolvedValueOnce([]);\n\n discoverDevice(\n (discoveredDevice) => {\n reject(\n `Should not emit any value, but emitted ${JSON.stringify(\n discoveredDevice,\n )}`,\n );\n },\n (error) => {\n try {\n expect(error).toBeInstanceOf(NoAccessibleDeviceError);\n resolve();\n } catch (expectError) {\n reject(expectError as Error);\n }\n },\n );\n }));\n\n it(\"should emit the same discoveredDevice object if its discovered twice in a row\", async () => {\n mockedRequestDevice.mockResolvedValue([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n const firstDiscoveredDevice = await new Promise<void>(\n (resolve, reject) => {\n discoverDevice(\n () => resolve(),\n (err) => reject(err),\n );\n },\n );\n const secondDiscoveredDevice = await new Promise<void>(\n (resolve, reject) => {\n discoverDevice(\n () => resolve(),\n (err) => reject(err),\n );\n },\n );\n expect(secondDiscoveredDevice).toBe(firstDiscoveredDevice);\n });\n });\n\n describe(\"destroy\", () => {\n it(\"should stop monitoring connections if the discovery process is halted\", () => {\n const abortSpy = vi.spyOn(AbortController.prototype, \"abort\");\n\n transport.destroy();\n\n expect(abortSpy).toHaveBeenCalled();\n });\n });\n\n describe(\"connect\", () => {\n it(\"should throw UnknownDeviceError if no internal device\", async () => {\n const connectParams = {\n deviceId: \"fake\",\n onDisconnect: vi.fn(),\n };\n\n const connect = await transport.connect(connectParams);\n\n expect(connect).toStrictEqual(\n Left(new UnknownDeviceError(\"Unknown device fake\")),\n );\n });\n\n it(\"should throw OpeningConnectionError if the device is already opened\", async () => {\n const device = {\n deviceId: \"fake\",\n onDisconnect: vi.fn(),\n };\n\n const connect = await transport.connect(device);\n\n expect(connect).toStrictEqual(\n Left(new UnknownDeviceError(\"Unknown device fake\")),\n );\n });\n\n it(\"should throw OpeningConnectionError if the device cannot be opened\", () =>\n new Promise<void>((resolve, reject) => {\n const message = \"cannot be opened\";\n const mockedDevice = {\n ...stubDevice,\n open: () => {\n throw new Error(message);\n },\n };\n mockedRequestDevice.mockResolvedValueOnce([mockedDevice]);\n mockedGetDevices.mockResolvedValue([mockedDevice]);\n\n discoverDevice(\n (discoveredDevice) => {\n transport\n .connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n })\n .then((value) => {\n expect(value).toStrictEqual(\n Left(new OpeningConnectionError(new Error(message))),\n );\n resolve();\n })\n .catch((error) => {\n reject(error);\n });\n },\n (error) => {\n reject(error as Error);\n },\n );\n }));\n\n it(\"should return the opened device\", () =>\n new Promise<void>((resolve, reject) => {\n const mockedDevice = {\n ...stubDevice,\n opened: false,\n open: () => {\n mockedDevice.opened = true;\n return Promise.resolve();\n },\n };\n\n mockedRequestDevice.mockResolvedValue([mockedDevice]);\n mockedGetDevices.mockResolvedValue([mockedDevice]);\n\n discoverDevice(\n (discoveredDevice) => {\n transport\n .connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n })\n .then((connectedDevice) => {\n connectedDevice\n .ifRight((device) => {\n expect(device).toEqual(\n expect.objectContaining({ id: discoveredDevice.id }),\n );\n resolve();\n })\n .ifLeft(() => {\n reject(connectedDevice);\n });\n })\n .catch((error) => {\n reject(error);\n });\n },\n (error) => {\n reject(error as Error);\n },\n );\n }));\n\n it(\"should return a device if available\", () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n discoverDevice(\n (discoveredDevice) => {\n transport\n .connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n })\n .then((connectedDevice) => {\n connectedDevice\n .ifRight((device) => {\n expect(device).toEqual(\n expect.objectContaining({ id: discoveredDevice.id }),\n );\n resolve();\n })\n .ifLeft(() => {\n reject(connectedDevice);\n });\n })\n .catch((error) => {\n reject(error);\n });\n },\n (error) => {\n reject(error as Error);\n },\n );\n }));\n });\n\n describe(\"disconnect\", () => {\n it(\"should throw an error if the device is not connected\", async () => {\n // given\n const connectedDevice = connectedDeviceStubBuilder();\n\n // when\n const disconnect = await transport.disconnect({\n connectedDevice,\n });\n\n expect(disconnect).toStrictEqual(\n Left(new UnknownDeviceError(`Unknown device ${connectedDevice.id}`)),\n );\n });\n\n it(\"should disconnect if the device is connected\", () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n discoverDevice(\n (discoveredDevice) => {\n transport\n .connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n })\n .then((connectedDevice) => {\n connectedDevice\n .ifRight((device) => {\n transport\n .disconnect({ connectedDevice: device })\n .then((value) => {\n expect(value).toStrictEqual(Right(undefined));\n resolve();\n })\n .catch((error) => {\n reject(error);\n });\n })\n .ifLeft(() => {\n reject(connectedDevice);\n });\n })\n .catch((error) => {\n reject(error);\n });\n },\n (error) => {\n reject(error as Error);\n },\n );\n }));\n\n it(\"should call disconnect handler if a connected device is unplugged\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const onDisconnect = vi.fn();\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n // when\n transport.startDiscovering().subscribe({\n next: (discoveredDevice) => {\n const mock = {\n sendApdu: vi.fn(),\n device: stubDevice,\n deviceId: discoveredDevice.id,\n disconnect: onDisconnect,\n lostConnection: vi.fn().mockImplementation(() => {\n setTimeout(() => {\n mock.disconnect();\n }, RECONNECT_DEVICE_TIMEOUT);\n }),\n };\n\n transport\n .connect({\n deviceId: discoveredDevice.id,\n onDisconnect,\n })\n .then(async () => {\n emitHIDDisconnectionEvent(stubDevice);\n\n expect(stubDevice.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the stubDevice.close promise is resolved\n expect(onDisconnect).not.toHaveBeenCalled();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 2);\n expect(onDisconnect).not.toHaveBeenCalled();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 2);\n expect(onDisconnect).toHaveBeenCalled();\n resolve();\n })\n .catch((error) => {\n reject(error);\n });\n },\n });\n }));\n });\n\n describe(\"reconnect\", () => {\n it(\"should stop disconnection if reconnection happen\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const onDisconnect = vi.fn();\n\n const hidDevice1 = hidDeviceStubBuilder();\n const hidDevice2 = hidDeviceStubBuilder();\n\n mockedRequestDevice.mockResolvedValueOnce([hidDevice1]);\n mockedGetDevices.mockResolvedValue([hidDevice1, hidDevice2]);\n\n discoverDevice(async (discoveredDevice) => {\n const mock = {\n sendApdu: vi.fn(),\n device: hidDevice2,\n deviceId: discoveredDevice.id,\n disconnect: onDisconnect,\n lostConnection: vi.fn().mockImplementation(() => {\n setTimeout(() => {\n mock.disconnect();\n }, RECONNECT_DEVICE_TIMEOUT);\n }),\n };\n\n try {\n await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect,\n });\n\n /* Disconnection */\n emitHIDDisconnectionEvent(hidDevice1);\n expect(hidDevice1.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice1.close promise is resolved\n\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 3);\n\n /* Reconnection */\n emitHIDConnectionEvent(hidDevice2);\n\n expect(hidDevice2.open).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice2.open promise is resolved\n\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n expect(onDisconnect).not.toHaveBeenCalled();\n resolve();\n } catch (error) {\n reject(error as Error);\n }\n });\n }));\n\n it(\"should be able to reconnect twice in a row if the device is unplugged and replugged twice\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const onDisconnect = vi.fn();\n\n const hidDevice1 = hidDeviceStubBuilder();\n const hidDevice2 = hidDeviceStubBuilder();\n const hidDevice3 = hidDeviceStubBuilder();\n\n mockedRequestDevice.mockResolvedValueOnce([hidDevice1]);\n mockedGetDevices.mockResolvedValue([\n hidDevice1,\n hidDevice2,\n hidDevice3,\n ]);\n\n // when\n discoverDevice(async (discoveredDevice) => {\n await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect,\n });\n try {\n /* First disconnection */\n emitHIDDisconnectionEvent(hidDevice1);\n expect(hidDevice1.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice1.close promise is resolved\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 3);\n\n /* First reconnection */\n emitHIDConnectionEvent(hidDevice2);\n\n expect(hidDevice2.open).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice2.open promise is resolved\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n expect(onDisconnect).not.toHaveBeenCalled();\n\n /* Second disconnection */\n emitHIDDisconnectionEvent(hidDevice2);\n expect(hidDevice2.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice2.close promise is resolved\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 3);\n\n /* Second reconnection */\n emitHIDConnectionEvent(hidDevice3);\n\n expect(hidDevice3.open).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice3.open promise is resolved\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n expect(onDisconnect).not.toHaveBeenCalled();\n\n resolve();\n } catch (error) {\n reject(error as Error);\n }\n });\n }));\n });\n\n describe(\"Connection event typeguard\", () => {\n it(\"should validate type of an HIDConnectionEvent\", () => {\n // given\n const event = {\n device: stubDevice,\n } as HIDConnectionEvent;\n // when\n // @ts-expect-error trying to access private member\n const result = transport.isHIDConnectionEvent(event);\n // then\n expect(result).toBe(true);\n });\n\n it(\"should not validate type of another event\", () => {\n // given\n const event = new Event(\"disconnect\", {});\n // when\n // @ts-expect-error trying to access private member\n const result = transport.isHIDConnectionEvent(event);\n // then\n expect(result).toBe(false);\n });\n });\n\n describe(\"listenToAvailableDevices\", () => {\n it(\"should emit the devices already connected before listening\", async () => {\n // given\n const hidDevice = hidDeviceStubBuilder();\n mockedGetDevices.mockResolvedValue([hidDevice]);\n\n const onComplete = vi.fn();\n const onError = vi.fn();\n\n let observedDevices: TransportDiscoveredDevice[] = [];\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (knownDevices) => {\n observedDevices = knownDevices;\n },\n complete: onComplete,\n error: onError,\n });\n\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n ]);\n expect(onComplete).not.toHaveBeenCalled();\n expect(onError).not.toHaveBeenCalled();\n });\n\n it(\"should emit the new list of devices after connection and disconnection events\", async () => {\n initializeTransport();\n // given\n const hidDevice1 = hidDeviceStubBuilder({\n productId:\n usbDeviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }).usbProductId << 8,\n });\n const hidDevice2 = hidDeviceStubBuilder({\n productId:\n usbDeviceModelDataSource.getDeviceModel({ id: DeviceModelId.STAX })\n .usbProductId << 8,\n });\n mockedGetDevices.mockResolvedValue([hidDevice1]);\n\n const onComplete = vi.fn();\n const onError = vi.fn();\n\n let observedDevices: TransportDiscoveredDevice[] = [];\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (knownDevices) => {\n observedDevices = knownDevices;\n },\n complete: onComplete,\n error: onError,\n });\n\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n ]);\n\n // When a new device is connected\n mockedGetDevices.mockResolvedValue([hidDevice1, hidDevice2]);\n emitHIDConnectionEvent(hidDevice2);\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.STAX,\n }) as TransportDeviceModel,\n }),\n ]);\n\n // When a device is disconnected\n mockedGetDevices.mockResolvedValue([hidDevice2]);\n emitHIDDisconnectionEvent(hidDevice1);\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.STAX,\n }) as TransportDeviceModel,\n }),\n ]);\n\n expect(onComplete).not.toHaveBeenCalled();\n expect(onError).not.toHaveBeenCalled();\n });\n\n it(\"should preserve DeviceId in case the device has been disconnected and reconnected before the timeout\", async () => {\n // given\n const hidDevice = hidDeviceStubBuilder();\n\n mockedGetDevices.mockResolvedValue([hidDevice]);\n\n const onComplete = vi.fn();\n const onError = vi.fn();\n let observedDevices: TransportDiscoveredDevice[] = [];\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (knownDevices) => {\n observedDevices = knownDevices;\n },\n complete: onComplete,\n error: onError,\n });\n\n await flushPromises();\n\n const firstObservedDeviceId = observedDevices[0]?.id;\n expect(firstObservedDeviceId).toBeTruthy();\n expect(observedDevices[0]?.deviceModel?.id).toBe(DeviceModelId.NANO_X);\n\n // Start a connection with the device\n await transport.connect({\n deviceId: observedDevices[0]!.id,\n onDisconnect: vi.fn(),\n });\n await flushPromises();\n\n // When the device is disconnected\n mockedGetDevices.mockResolvedValue([]);\n emitHIDDisconnectionEvent(hidDevice);\n await flushPromises();\n\n expect(observedDevices).toEqual([]);\n\n // When the device is reconnected\n mockedGetDevices.mockResolvedValue([hidDevice]);\n emitHIDConnectionEvent(hidDevice);\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n ]);\n\n expect(observedDevices[0]?.id).toBeTruthy();\n expect(observedDevices[0]?.id).toBe(firstObservedDeviceId);\n });\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AACA,OAGE,8BAAAA,EAEA,iBAAAC,EACA,4BAAAC,EAGA,2BAAAC,EACA,0BAAAC,EACA,+BAAAC,EAGA,sBAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,WAAAC,MAAe,OAExB,OAAS,4BAAAC,MAAgC,yBACzC,OAAS,oCAAAC,MAAwC,oBACjD,OAAS,wBAAAC,MAA4B,4BAErC,OAAS,mBAAAC,MAAuB,oBAEhC,MAAMC,CAA6D,CACjE,YAAYC,EAAwCC,EAAa,CAC/D,KAAK,YAAcD,EACnB,KAAK,IAAM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zC,OAAOF,EAAgB,CAAC,GAAG,aAAa,EAAE,EAAE,KAAKjE,EAAc,MAAM,EAGrE,MAAMqB,EAAU,QAAQ,CACtB,SAAU4C,EAAgB,CAAC,EAAG,GAC9B,aAAc,GAAG,GAAG,CACtB,CAAC,EACD,MAAM9C,EAAc,EAGpBY,EAAiB,kBAAkB,CAAC,CAAC,EACrCM,EAA0B0B,CAAS,EACnC,MAAM5C,EAAc,EAEpB,OAAO8C,CAAe,EAAE,QAAQ,CAAC,CAAC,EAGlClC,EAAiB,kBAAkB,CAACgC,CAAS,CAAC,EAC9C5B,EAAuB4B,CAAS,EAChC,MAAM5C,EAAc,EAEpB,OAAO8C,CAAe,EAAE,QAAQ,CAC9B,OAAO,iBAAiB,CACtB,YAAa,OAAO,iBAAiB,CACnC,GAAIjE,EAAc,MACpB,CAAC,CACH,CAAC,CACH,CAAC,EAED,OAAOiE,EAAgB,CAAC,GAAG,EAAE,EAAE,WAAW,EAC1C,OAAOA,EAAgB,CAAC,GAAG,EAAE,EAAE,KAAKE,CAAqB,CAC3D,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
-
"names": ["connectedDeviceStubBuilder", "DeviceModelId", "DeviceNotRecognizedError", "NoAccessibleDeviceError", "OpeningConnectionError", "StaticDeviceModelDataSource", "UnknownDeviceError", "Left", "Right", "Subject", "RECONNECT_DEVICE_TIMEOUT", "WebHidTransportNotSupportedError", "hidDeviceStubBuilder", "WebHidTransport", "LoggerPublisherServiceStub", "subscribers", "tag", "usbDeviceModelDataSource", "logger", "stubDevice", "flushPromises", "timers", "transport", "apduReceiverServiceFactoryStub", "apduSenderServiceFactoryStub", "initializeTransport", "discoverDevice", "onSuccess", "onError", "resolve", "reject", "error", "mockedGetDevices", "mockedRequestDevice", "connectionEventsSubject", "disconnectionEventsSubject", "emitHIDConnectionEvent", "device", "emitHIDDisconnectionEvent", "eventName", "callback", "deviceModel", "testCase", "discoveredDevice", "expectError", "count", "message", "firstDiscoveredDevice", "err", "secondDiscoveredDevice", "abortSpy", "connectParams", "connect", "
|
|
4
|
+
"sourcesContent": ["/* eslint @typescript-eslint/consistent-type-imports: off */\nimport {\n type ApduReceiverServiceFactory,\n type ApduResponse,\n type ApduSenderServiceFactory,\n connectedDeviceStubBuilder,\n DeviceConnectionStateMachine,\n type DeviceConnectionStateMachineParams,\n type DeviceModel,\n DeviceModelId,\n DeviceNotRecognizedError,\n type LoggerPublisherService,\n type LoggerSubscriberService,\n NoAccessibleDeviceError,\n OpeningConnectionError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n UnknownDeviceError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\nimport { lastValueFrom, Subject, toArray } from \"rxjs\";\n\nimport { RECONNECT_DEVICE_TIMEOUT } from \"@api/data/WebHidConfig\";\nimport { WebHidTransportNotSupportedError } from \"@api/model/Errors\";\nimport { hidDeviceStubBuilder } from \"@api/model/HIDDevice.stub\";\n\nimport { WebHidApduSender } from \"./WebHidApduSender\";\nimport { WebHidTransport } from \"./WebHidTransport\";\n\nclass LoggerPublisherServiceStub implements LoggerPublisherService {\n constructor(subscribers: LoggerSubscriberService[], tag: string) {\n this.subscribers = subscribers;\n this.tag = tag;\n }\n subscribers: LoggerSubscriberService[] = [];\n tag: string = \"\";\n error = vi.fn();\n warn = vi.fn();\n info = vi.fn();\n debug = vi.fn();\n}\n\n// Our StaticDeviceModelDataSource can directly be used in our unit tests\nconst usbDeviceModelDataSource = new StaticDeviceModelDataSource();\nconst logger = new LoggerPublisherServiceStub([], \"web-usb-hid\");\n\nconst stubDevice: HIDDevice = hidDeviceStubBuilder();\n\n/**\n * Flushes all pending promises\n */\nconst flushPromises = async () => {\n const timers = await vi.importActual<typeof import(\"timers\")>(\"timers\");\n return new Promise(timers.setImmediate);\n};\n\ndescribe(\"WebHidTransport\", () => {\n let transport: WebHidTransport;\n let apduReceiverServiceFactoryStub: ApduReceiverServiceFactory;\n let apduSenderServiceFactoryStub: ApduSenderServiceFactory;\n\n let mockDeviceConnectionStateMachineFactory = vi.fn();\n const mockEventDeviceConnected = vi.fn();\n const mockEventDeviceDisconnected = vi.fn();\n\n const mockDeviceApduSender = {\n sendApdu: vi\n .fn()\n .mockResolvedValue(Right({ data: new Uint8Array() } as ApduResponse)),\n getDependencies: vi.fn().mockReturnValue({ device: stubDevice }),\n setDependencies: vi.fn(),\n closeConnection: vi.fn(),\n setupConnection: vi.fn(),\n };\n\n const mockDeviceConnectionStateMachine = {\n getDependencies: vi.fn().mockReturnValue({ device: stubDevice }),\n setDependencies: vi.fn(),\n getDeviceId: vi.fn(),\n sendApdu: vi\n .fn()\n .mockResolvedValue(Right({ data: new Uint8Array() } as ApduResponse)),\n setupConnection: vi.fn(),\n eventDeviceConnected: mockEventDeviceConnected,\n eventDeviceDisconnected: mockEventDeviceDisconnected,\n closeConnection: vi.fn(),\n };\n\n function initializeTransport() {\n apduReceiverServiceFactoryStub = vi.fn();\n apduSenderServiceFactoryStub = vi.fn();\n mockDeviceConnectionStateMachineFactory = vi.fn(\n (params: DeviceConnectionStateMachineParams<{ device: HIDDevice }>) => {\n return {\n ...mockDeviceConnectionStateMachine,\n getDeviceId: vi.fn().mockReturnValue(params.deviceId),\n getDependencies: params.deviceApduSender.getDependencies,\n setDependencies: params.deviceApduSender.setDependencies,\n } as unknown as DeviceConnectionStateMachine<{ device: HIDDevice }>;\n },\n );\n const mockDeviceApduSenderFactory = vi.fn((params) => {\n return {\n ...mockDeviceApduSender,\n getDependencies: () => params.dependencies,\n setDependencies: (dependencies: { device: HIDDevice }) =>\n (params.dependencies = dependencies),\n } as unknown as WebHidApduSender;\n });\n transport = new WebHidTransport(\n usbDeviceModelDataSource,\n () => logger,\n apduSenderServiceFactoryStub,\n apduReceiverServiceFactoryStub,\n mockDeviceConnectionStateMachineFactory,\n mockDeviceApduSenderFactory,\n );\n }\n\n beforeEach(() => {\n initializeTransport();\n vi.useFakeTimers();\n });\n\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n const discoverDevice = (\n onSuccess: (discoveredDevice: TransportDiscoveredDevice) => void,\n onError?: (error: unknown) => void,\n ) => {\n transport.startDiscovering().subscribe({\n next: onSuccess,\n error: onError,\n });\n };\n\n describe(\"When WebHID API is not supported\", () => {\n it(\"should not support the transport\", () => {\n expect(transport.isSupported()).toBe(false);\n });\n\n it(\"should emit a startDiscovering error\", () =>\n new Promise<void>((resolve, reject) => {\n discoverDevice(\n () => {\n reject(\"Should not emit any value\");\n },\n (error) => {\n expect(error).toBeInstanceOf(WebHidTransportNotSupportedError);\n resolve();\n },\n );\n }));\n });\n\n describe(\"When WebHID API is supported\", () => {\n const mockedGetDevices = vi.fn();\n const mockedRequestDevice = vi.fn();\n\n const connectionEventsSubject = new Subject<HIDConnectionEvent>();\n const disconnectionEventsSubject = new Subject<HIDConnectionEvent>();\n\n function emitHIDConnectionEvent(device: HIDDevice) {\n connectionEventsSubject.next({\n device,\n } as HIDConnectionEvent);\n }\n\n function emitHIDDisconnectionEvent(device: HIDDevice) {\n disconnectionEventsSubject.next({\n device,\n } as HIDConnectionEvent);\n }\n\n beforeEach(() => {\n global.navigator = {\n hid: {\n getDevices: mockedGetDevices,\n requestDevice: mockedRequestDevice,\n addEventListener: (\n eventName: string,\n callback: (event: HIDConnectionEvent) => void,\n ) => {\n if (eventName === \"disconnect\") {\n disconnectionEventsSubject.subscribe(callback);\n } else if (eventName === \"connect\") {\n connectionEventsSubject.subscribe(callback);\n }\n },\n },\n } as unknown as Navigator;\n initializeTransport();\n });\n\n afterEach(() => {\n vi.clearAllMocks();\n global.navigator = undefined as unknown as Navigator;\n });\n\n it(\"should support the transport\", () => {\n expect(transport.isSupported()).toBe(true);\n });\n\n describe(\"startDiscovering\", () => {\n const testCases = usbDeviceModelDataSource\n .getAllDeviceModels()\n .flatMap((deviceModel) => {\n return [\n {\n testTitle: `should emit device if user grants access through hid.requestDevice (${deviceModel.productName})`,\n hidDevice: hidDeviceStubBuilder({\n productId: deviceModel.usbProductId << 8,\n productName: deviceModel.productName,\n }),\n expectedDeviceModel: deviceModel,\n },\n {\n testTitle: `should emit device if user grants access through hid.requestDevice (${deviceModel.productName}, bootloader)`,\n hidDevice: hidDeviceStubBuilder({\n productId: deviceModel.bootloaderUsbProductId,\n productName: deviceModel.productName,\n }),\n expectedDeviceModel: deviceModel,\n },\n ];\n });\n\n testCases.forEach((testCase) => {\n it(\n testCase.testTitle,\n () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([testCase.hidDevice]);\n\n discoverDevice(\n (discoveredDevice) => {\n try {\n expect(discoveredDevice).toEqual(\n expect.objectContaining({\n deviceModel: testCase.expectedDeviceModel,\n }),\n );\n\n resolve();\n } catch (expectError) {\n reject(expectError as Error);\n }\n },\n (error) => {\n reject(error as Error);\n },\n );\n }),\n );\n });\n\n // It does not seem possible for a user to select several devices on the browser popup.\n // But if it was possible, we should emit them\n it(\"should emit devices if new grant accesses\", () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([\n stubDevice,\n {\n ...stubDevice,\n productId: 0x5011,\n productName: \"Ledger Nano S Plus\",\n },\n ]);\n\n let count = 0;\n discoverDevice(\n (discoveredDevice) => {\n try {\n switch (count) {\n case 0:\n expect(discoveredDevice).toEqual(\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n productName: \"Ledger Nano X\",\n usbProductId: 0x40,\n }) as DeviceModel,\n }),\n );\n break;\n case 1:\n expect(discoveredDevice).toEqual(\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_SP,\n productName: \"Ledger Nano S Plus\",\n usbProductId: 0x50,\n }) as DeviceModel,\n }),\n );\n\n resolve();\n break;\n }\n\n count++;\n } catch (expectError) {\n reject(expectError as Error);\n }\n },\n (error) => {\n reject(error as Error);\n },\n );\n }));\n\n it(\"should throw DeviceNotRecognizedError if the device is not recognized\", () =>\n new Promise<void>((resolve, reject) => {\n mockedRequestDevice.mockResolvedValueOnce([\n {\n ...stubDevice,\n productId: 0x4242,\n },\n ]);\n\n discoverDevice(\n () => {\n reject(\"should not return a device\");\n },\n (error) => {\n expect(error).toBeInstanceOf(DeviceNotRecognizedError);\n resolve();\n },\n );\n }));\n\n it(\"should emit an error if the request device is in error\", () =>\n new Promise<void>((resolve, reject) => {\n const message = \"request device error\";\n mockedRequestDevice.mockImplementationOnce(() => {\n throw new Error(message);\n });\n\n discoverDevice(\n () => {\n reject(\"should not return a device\");\n },\n (error) => {\n expect(error).toBeInstanceOf(NoAccessibleDeviceError);\n expect(error).toStrictEqual(\n new NoAccessibleDeviceError(new Error(message)),\n );\n resolve();\n },\n );\n }));\n\n // [ASK] Is this the behavior we want when the user does not select any device ?\n it(\"should emit an error if the user did not grant us access to a device (clicking on cancel on the browser popup for ex)\", () =>\n new Promise<void>((resolve, reject) => {\n // When the user does not select any device, the `requestDevice` will return an empty array\n mockedRequestDevice.mockResolvedValueOnce([]);\n\n discoverDevice(\n (discoveredDevice) => {\n reject(\n `Should not emit any value, but emitted ${JSON.stringify(\n discoveredDevice,\n )}`,\n );\n },\n (error) => {\n try {\n expect(error).toBeInstanceOf(NoAccessibleDeviceError);\n resolve();\n } catch (expectError) {\n reject(expectError as Error);\n }\n },\n );\n }));\n\n it(\"should emit the same discoveredDevice object if its discovered twice in a row\", async () => {\n mockedRequestDevice.mockResolvedValue([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n const firstDiscoveredDevice = await new Promise<void>(\n (resolve, reject) => {\n discoverDevice(\n () => resolve(),\n (err) => reject(err),\n );\n },\n );\n const secondDiscoveredDevice = await new Promise<void>(\n (resolve, reject) => {\n discoverDevice(\n () => resolve(),\n (err) => reject(err),\n );\n },\n );\n expect(secondDiscoveredDevice).toBe(firstDiscoveredDevice);\n });\n });\n\n describe(\"destroy\", () => {\n it(\"should stop monitoring connections if the discovery process is halted\", () => {\n const abortSpy = vi.spyOn(AbortController.prototype, \"abort\");\n\n transport.destroy();\n\n expect(abortSpy).toHaveBeenCalled();\n });\n });\n\n describe(\"connect\", () => {\n it(\"should throw UnknownDeviceError if no internal device\", async () => {\n const connectParams = {\n deviceId: \"fake\",\n onDisconnect: vi.fn(),\n };\n\n const connect = await transport.connect(connectParams);\n\n expect(connect).toStrictEqual(\n Left(new UnknownDeviceError(\"Unknown device fake\")),\n );\n });\n\n it(\"should throw OpeningConnectionError if the device cannot be opened\", async () => {\n const message = \"cannot be opened\";\n mockDeviceApduSender.setupConnection.mockRejectedValue(\n new OpeningConnectionError(message),\n );\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n const discoveredDevice = await lastValueFrom(\n transport.startDiscovering(),\n );\n const connected = await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n });\n expect(connected).toStrictEqual(\n Left(new OpeningConnectionError(message)),\n );\n });\n\n it(\"should return a device if available\", async () => {\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n const discoveredDevice = await lastValueFrom(\n transport.startDiscovering(),\n );\n const connected = await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n });\n expect(connected.isRight()).toStrictEqual(true);\n expect(connected.extract()).toEqual(\n expect.objectContaining({ id: discoveredDevice.id }),\n );\n });\n\n it(\"should return an existing connected device\", async () => {\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n const discoveredDevice = await lastValueFrom(\n transport.startDiscovering(),\n );\n await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n });\n const connected = await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n });\n expect(connected.isRight()).toStrictEqual(true);\n expect(connected.extract()).toEqual(\n expect.objectContaining({ id: discoveredDevice.id }),\n );\n });\n });\n\n describe(\"disconnect\", () => {\n it(\"should throw an error if the device is not connected\", async () => {\n // given\n const connectedDevice = connectedDeviceStubBuilder();\n\n // when\n const disconnect = await transport.disconnect({\n connectedDevice,\n });\n\n expect(disconnect).toStrictEqual(\n Left(new UnknownDeviceError(`Unknown device ${connectedDevice.id}`)),\n );\n });\n\n it(\"should disconnect if the device is connected\", async () => {\n mockedRequestDevice.mockResolvedValueOnce([stubDevice]);\n mockedGetDevices.mockResolvedValue([stubDevice]);\n\n const discoveredDevice = await lastValueFrom(\n transport.startDiscovering(),\n );\n const connected = await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect: vi.fn(),\n });\n expect(connected.isRight()).toStrictEqual(true);\n const result = await transport.disconnect({\n connectedDevice: connected.unsafeCoerce(),\n });\n expect(result).toStrictEqual(Right(undefined));\n });\n\n it(\"should call disconnect handler if a connected device is unplugged\", async () => {\n // Get onTerminated for the first connection only\n let onTerminated1 = vi.fn();\n mockDeviceConnectionStateMachineFactory.mockImplementationOnce(\n (params) => {\n onTerminated1 = params.onTerminated;\n return {\n ...mockDeviceConnectionStateMachine,\n getDeviceId: vi.fn().mockReturnValue(params.deviceId),\n } as unknown as DeviceConnectionStateMachine<{ device: HIDDevice }>;\n },\n );\n\n // Add 2 discoverable devices\n const hidDevice1 = hidDeviceStubBuilder();\n const hidDevice2 = hidDeviceStubBuilder();\n mockedRequestDevice.mockResolvedValueOnce([hidDevice1, hidDevice2]);\n mockedGetDevices.mockResolvedValue([hidDevice1, hidDevice2]);\n\n // Connect the 2 devices\n const discoveredDevices = await lastValueFrom(\n transport.startDiscovering().pipe(toArray()),\n );\n expect(discoveredDevices.length).toStrictEqual(2);\n const onDisconnect1 = vi.fn();\n const connected1 = await transport.connect({\n deviceId: discoveredDevices[0]!.id,\n onDisconnect: onDisconnect1,\n });\n const onDisconnect2 = vi.fn();\n const connected2 = await transport.connect({\n deviceId: discoveredDevices[1]!.id,\n onDisconnect: onDisconnect2,\n });\n expect(connected1.isRight()).toStrictEqual(true);\n expect(connected2.isRight()).toStrictEqual(true);\n\n // unplug the first device\n onTerminated1();\n expect(onDisconnect1).toHaveBeenCalled();\n expect(onDisconnect2).not.toHaveBeenCalled();\n });\n\n it(\"should call disconnect handler if a connected device is unplugged while reconnecting\", async () => {\n // Get onTerminated for the first connection only\n let onTerminated1 = vi.fn();\n let tryToReconnect1 = vi.fn();\n mockDeviceConnectionStateMachineFactory.mockImplementationOnce(\n (params) => {\n onTerminated1 = params.onTerminated;\n tryToReconnect1 = params.tryToReconnect;\n return {\n ...mockDeviceConnectionStateMachine,\n getDeviceId: vi.fn().mockReturnValue(params.deviceId),\n } as unknown as DeviceConnectionStateMachine<{ device: HIDDevice }>;\n },\n );\n\n // Add 2 discoverable devices\n const hidDevice1 = hidDeviceStubBuilder();\n const hidDevice2 = hidDeviceStubBuilder();\n mockedRequestDevice.mockResolvedValueOnce([hidDevice1, hidDevice2]);\n mockedGetDevices.mockResolvedValue([hidDevice1, hidDevice2]);\n\n // Connect the 2 devices\n const discoveredDevices = await lastValueFrom(\n transport.startDiscovering().pipe(toArray()),\n );\n expect(discoveredDevices.length).toStrictEqual(2);\n const onDisconnect1 = vi.fn();\n const connected1 = await transport.connect({\n deviceId: discoveredDevices[0]!.id,\n onDisconnect: onDisconnect1,\n });\n const onDisconnect2 = vi.fn();\n const connected2 = await transport.connect({\n deviceId: discoveredDevices[1]!.id,\n onDisconnect: onDisconnect2,\n });\n expect(connected1.isRight()).toStrictEqual(true);\n expect(connected2.isRight()).toStrictEqual(true);\n\n // Try to reconnect the first device\n tryToReconnect1();\n\n // unplug the first device\n onTerminated1();\n expect(onDisconnect1).toHaveBeenCalled();\n expect(onDisconnect2).not.toHaveBeenCalled();\n });\n });\n\n describe(\"reconnect\", () => {\n it(\"should stop disconnection if reconnection happen\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const onDisconnect = vi.fn();\n let tryToReconnect = vi.fn();\n\n const hidDevice1 = hidDeviceStubBuilder();\n const hidDevice2 = hidDeviceStubBuilder();\n\n mockedRequestDevice.mockResolvedValueOnce([hidDevice1]);\n mockedGetDevices.mockResolvedValue([hidDevice1, hidDevice2]);\n mockDeviceConnectionStateMachineFactory.mockImplementationOnce(\n (params) => {\n tryToReconnect = params.tryToReconnect;\n return {\n ...mockDeviceConnectionStateMachine,\n getDeviceId: vi.fn().mockReturnValue(params.deviceId),\n getDependencies: params.deviceApduSender.getDependencies,\n setDependencies: params.deviceApduSender.setDependencies,\n } as unknown as DeviceConnectionStateMachine<{\n device: HIDDevice;\n }>;\n },\n );\n\n discoverDevice(async (discoveredDevice) => {\n try {\n await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect,\n });\n\n /* Disconnection */\n emitHIDDisconnectionEvent(hidDevice1);\n expect(hidDevice1.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice1.close promise is resolved\n expect(mockEventDeviceDisconnected).toHaveBeenCalled();\n\n tryToReconnect();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 3);\n\n /* Reconnection */\n emitHIDConnectionEvent(hidDevice2);\n\n await Promise.resolve(); // wait for the next tick so the hidDevice2.open promise is resolved\n expect(mockEventDeviceConnected).toHaveBeenCalled();\n\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n expect(onDisconnect).not.toHaveBeenCalled();\n resolve();\n } catch (error) {\n reject(error as Error);\n }\n });\n }));\n\n it(\"should be able to reconnect twice in a row if the device is unplugged and replugged twice\", () =>\n new Promise<void>((resolve, reject) => {\n // given\n const onDisconnect = vi.fn();\n let tryToReconnect = vi.fn();\n\n const hidDevice1 = hidDeviceStubBuilder();\n const hidDevice2 = hidDeviceStubBuilder();\n const hidDevice3 = hidDeviceStubBuilder();\n\n mockedRequestDevice.mockResolvedValueOnce([hidDevice1]);\n mockedGetDevices.mockResolvedValue([\n hidDevice1,\n hidDevice2,\n hidDevice3,\n ]);\n mockDeviceConnectionStateMachineFactory.mockImplementationOnce(\n (params) => {\n tryToReconnect = params.tryToReconnect;\n return {\n ...mockDeviceConnectionStateMachine,\n getDeviceId: vi.fn().mockReturnValue(params.deviceId),\n getDependencies: params.deviceApduSender.getDependencies,\n setDependencies: params.deviceApduSender.setDependencies,\n } as unknown as DeviceConnectionStateMachine<{\n device: HIDDevice;\n }>;\n },\n );\n\n // when\n discoverDevice(async (discoveredDevice) => {\n await transport.connect({\n deviceId: discoveredDevice.id,\n onDisconnect,\n });\n try {\n /* First disconnection */\n emitHIDDisconnectionEvent(hidDevice1);\n expect(hidDevice1.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice1.close promise is resolved\n expect(mockEventDeviceDisconnected).toHaveBeenCalled();\n tryToReconnect();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 3);\n\n /* First reconnection */\n emitHIDConnectionEvent(hidDevice2);\n\n await Promise.resolve(); // wait for the next tick so the hidDevice2.open promise is resolved\n expect(mockEventDeviceConnected).toHaveBeenCalled();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n expect(onDisconnect).not.toHaveBeenCalled();\n\n /* Second disconnection */\n emitHIDDisconnectionEvent(hidDevice2);\n expect(hidDevice2.close).toHaveBeenCalled();\n await Promise.resolve(); // wait for the next tick so the hidDevice2.close promise is resolved\n expect(mockEventDeviceDisconnected).toHaveBeenCalled();\n tryToReconnect();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT / 3);\n\n /* Second reconnection */\n emitHIDConnectionEvent(hidDevice3);\n\n await Promise.resolve(); // wait for the next tick so the hidDevice3.open promise is resolved\n expect(mockEventDeviceConnected).toHaveBeenCalled();\n vi.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n expect(onDisconnect).not.toHaveBeenCalled();\n\n resolve();\n } catch (error) {\n reject(error as Error);\n }\n });\n }));\n });\n\n describe(\"Connection event typeguard\", () => {\n it(\"should validate type of an HIDConnectionEvent\", () => {\n // given\n const event = {\n device: stubDevice,\n } as HIDConnectionEvent;\n // when\n // @ts-expect-error trying to access private member\n const result = transport.isHIDConnectionEvent(event);\n // then\n expect(result).toBe(true);\n });\n\n it(\"should not validate type of another event\", () => {\n // given\n const event = new Event(\"disconnect\", {});\n // when\n // @ts-expect-error trying to access private member\n const result = transport.isHIDConnectionEvent(event);\n // then\n expect(result).toBe(false);\n });\n });\n\n describe(\"listenToAvailableDevices\", () => {\n it(\"should emit the devices already connected before listening\", async () => {\n // given\n const hidDevice = hidDeviceStubBuilder();\n mockedGetDevices.mockResolvedValue([hidDevice]);\n\n const onComplete = vi.fn();\n const onError = vi.fn();\n\n let observedDevices: TransportDiscoveredDevice[] = [];\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (knownDevices) => {\n observedDevices = knownDevices;\n },\n complete: onComplete,\n error: onError,\n });\n\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n ]);\n expect(onComplete).not.toHaveBeenCalled();\n expect(onError).not.toHaveBeenCalled();\n });\n\n it(\"should emit the new list of devices after connection and disconnection events\", async () => {\n initializeTransport();\n // given\n const hidDevice1 = hidDeviceStubBuilder({\n productId:\n usbDeviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }).usbProductId << 8,\n });\n const hidDevice2 = hidDeviceStubBuilder({\n productId:\n usbDeviceModelDataSource.getDeviceModel({ id: DeviceModelId.STAX })\n .usbProductId << 8,\n });\n mockedGetDevices.mockResolvedValue([hidDevice1]);\n\n const onComplete = vi.fn();\n const onError = vi.fn();\n\n let observedDevices: TransportDiscoveredDevice[] = [];\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (knownDevices) => {\n observedDevices = knownDevices;\n },\n complete: onComplete,\n error: onError,\n });\n\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n ]);\n\n // When a new device is connected\n mockedGetDevices.mockResolvedValue([hidDevice1, hidDevice2]);\n emitHIDConnectionEvent(hidDevice2);\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.STAX,\n }) as TransportDeviceModel,\n }),\n ]);\n\n // When a device is disconnected\n mockedGetDevices.mockResolvedValue([hidDevice2]);\n emitHIDDisconnectionEvent(hidDevice1);\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.STAX,\n }) as TransportDeviceModel,\n }),\n ]);\n\n expect(onComplete).not.toHaveBeenCalled();\n expect(onError).not.toHaveBeenCalled();\n });\n\n it(\"should preserve DeviceId in case the device has been disconnected and reconnected before the timeout\", async () => {\n // given\n const hidDevice = hidDeviceStubBuilder();\n\n mockedGetDevices.mockResolvedValue([hidDevice]);\n\n const onComplete = vi.fn();\n const onError = vi.fn();\n let observedDevices: TransportDiscoveredDevice[] = [];\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (knownDevices) => {\n observedDevices = knownDevices;\n },\n complete: onComplete,\n error: onError,\n });\n\n await flushPromises();\n\n const firstObservedDeviceId = observedDevices[0]?.id;\n expect(firstObservedDeviceId).toBeTruthy();\n expect(observedDevices[0]?.deviceModel?.id).toBe(DeviceModelId.NANO_X);\n\n // Start a connection with the device\n await transport.connect({\n deviceId: observedDevices[0]!.id,\n onDisconnect: vi.fn(),\n });\n await flushPromises();\n\n // When the device is disconnected\n mockedGetDevices.mockResolvedValue([]);\n emitHIDDisconnectionEvent(hidDevice);\n await flushPromises();\n\n expect(observedDevices).toEqual([]);\n\n // When the device is reconnected\n mockedGetDevices.mockResolvedValue([hidDevice]);\n emitHIDConnectionEvent(hidDevice);\n await flushPromises();\n\n expect(observedDevices).toEqual([\n expect.objectContaining({\n deviceModel: expect.objectContaining({\n id: DeviceModelId.NANO_X,\n }) as TransportDeviceModel,\n }),\n ]);\n\n expect(observedDevices[0]?.id).toBeTruthy();\n expect(observedDevices[0]?.id).toBe(firstObservedDeviceId);\n });\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AACA,OAIE,8BAAAA,EAIA,iBAAAC,EACA,4BAAAC,EAGA,2BAAAC,EACA,0BAAAC,EACA,+BAAAC,EAGA,sBAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAC5B,OAAS,iBAAAC,EAAe,WAAAC,EAAS,WAAAC,MAAe,OAEhD,OAAS,4BAAAC,MAAgC,yBACzC,OAAS,oCAAAC,MAAwC,oBACjD,OAAS,wBAAAC,MAA4B,4BAGrC,OAAS,mBAAAC,MAAuB,oBAEhC,MAAMC,CAA6D,CACjE,YAAYC,EAAwCC,EAAa,CAC/D,KAAK,YAAcD,EACnB,KAAK,IAAMC,CACb,CACA,YAAyC,CAAC,EAC1C,IAAc,GACd,MAAQ,GAAG,GAAG,EACd,KAAO,GAAG,GAAG,EACb,KAAO,GAAG,GAAG,EACb,MAAQ,GAAG,GAAG,CAChB,CAGA,MAAMC,EAA2B,IAAId,EAC/Be,EAAS,IAAIJ,EAA2B,CAAC,EAAG,aAAa,EAEzDK,EAAwBP,EAAqB,EAK7CQ,EAAgB,SAAY,CAChC,MAAMC,EAAS,MAAM,GAAG,aAAsC,QAAQ,EACtE,OAAO,IAAI,QAAQA,EAAO,YAAY,CACxC,EAEA,SAAS,kBAAmB,IAAM,CAChC,IAAIC,EACAC,EACAC,EAEAC,EAA0C,GAAG,GAAG,EACpD,MAAMC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,EAEpCC,EAAuB,CAC3B,SAAU,GACP,GAAG,EACH,kBAAkBtB,EAAM,CAAE,KAAM,IAAI,UAAa,CAAiB,CAAC,EACtE,gBAAiB,GAAG,GAAG,EAAE,gBAAgB,CAAE,OAAQa,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,CAAe,EAAE,QAAQ,CAC9B,OAAO,iBAAiB,CACtB,YAAa,OAAO,iBAAiB,CACnC,GAAIjF,EAAc,MACpB,CAAC,CACH,CAAC,CACH,CAAC,EAED,OAAOiF,EAAgB,CAAC,GAAG,EAAE,EAAE,WAAW,EAC1C,OAAOA,EAAgB,CAAC,GAAG,EAAE,EAAE,KAAKE,CAAqB,CAC3D,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["connectedDeviceStubBuilder", "DeviceModelId", "DeviceNotRecognizedError", "NoAccessibleDeviceError", "OpeningConnectionError", "StaticDeviceModelDataSource", "UnknownDeviceError", "Left", "Right", "lastValueFrom", "Subject", "toArray", "RECONNECT_DEVICE_TIMEOUT", "WebHidTransportNotSupportedError", "hidDeviceStubBuilder", "WebHidTransport", "LoggerPublisherServiceStub", "subscribers", "tag", "usbDeviceModelDataSource", "logger", "stubDevice", "flushPromises", "timers", "transport", "apduReceiverServiceFactoryStub", "apduSenderServiceFactoryStub", "mockDeviceConnectionStateMachineFactory", "mockEventDeviceConnected", "mockEventDeviceDisconnected", "mockDeviceApduSender", "mockDeviceConnectionStateMachine", "initializeTransport", "params", "mockDeviceApduSenderFactory", "dependencies", "discoverDevice", "onSuccess", "onError", "resolve", "reject", "error", "mockedGetDevices", "mockedRequestDevice", "connectionEventsSubject", "disconnectionEventsSubject", "emitHIDConnectionEvent", "device", "emitHIDDisconnectionEvent", "eventName", "callback", "deviceModel", "testCase", "discoveredDevice", "expectError", "count", "message", "firstDiscoveredDevice", "err", "secondDiscoveredDevice", "abortSpy", "connectParams", "connect", "connected", "connectedDevice", "disconnect", "result", "onTerminated1", "hidDevice1", "hidDevice2", "discoveredDevices", "onDisconnect1", "connected1", "onDisconnect2", "connected2", "tryToReconnect1", "onDisconnect", "tryToReconnect", "hidDevice3", "event", "hidDevice", "onComplete", "observedDevices", "knownDevices", "firstObservedDeviceId"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/device-transport-kit-web-hid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
],
|
|
16
16
|
"scripts": {
|
|
17
17
|
"prebuild": "rimraf lib",
|
|
18
|
-
"build": "pnpm
|
|
18
|
+
"build": "pnpm ldmk-tool build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web",
|
|
19
19
|
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
|
|
20
|
-
"watch:builds": "pnpm
|
|
20
|
+
"watch:builds": "pnpm ldmk-tool watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web",
|
|
21
21
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
|
|
22
22
|
"lint": "eslint",
|
|
23
23
|
"lint:fix": "pnpm lint --fix",
|
|
@@ -30,24 +30,24 @@
|
|
|
30
30
|
"test:coverage": "vitest run --coverage"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@sentry/minimal": "
|
|
34
|
-
"purify-ts": "
|
|
35
|
-
"uuid": "
|
|
33
|
+
"@sentry/minimal": "catalog:",
|
|
34
|
+
"purify-ts": "catalog:",
|
|
35
|
+
"uuid": "catalog:"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@ledgerhq/device-management-kit": "workspace:*",
|
|
39
|
-
"@ledgerhq/
|
|
39
|
+
"@ledgerhq/ldmk-tool": "workspace:*",
|
|
40
40
|
"@ledgerhq/eslint-config-dsdk": "workspace:*",
|
|
41
41
|
"@ledgerhq/prettier-config-dsdk": "workspace:*",
|
|
42
42
|
"@ledgerhq/tsconfig-dsdk": "workspace:*",
|
|
43
43
|
"@ledgerhq/vitest-config-dmk": "workspace:*",
|
|
44
|
-
"@types/uuid": "
|
|
45
|
-
"@types/w3c-web-hid": "
|
|
46
|
-
"rxjs": "
|
|
47
|
-
"ts-node": "
|
|
44
|
+
"@types/uuid": "catalog:",
|
|
45
|
+
"@types/w3c-web-hid": "catalog:",
|
|
46
|
+
"rxjs": "catalog:",
|
|
47
|
+
"ts-node": "catalog:"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@ledgerhq/device-management-kit": "
|
|
51
|
-
"rxjs": "
|
|
50
|
+
"@ledgerhq/device-management-kit": "workspace:*",
|
|
51
|
+
"rxjs": "catalog:"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HIDDevice.stub.d.ts","sourceRoot":"","sources":["../../../../src/api/model/HIDDevice.stub.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"HIDDevice.stub.d.ts","sourceRoot":"","sources":["../../../../src/api/model/HIDDevice.stub.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,GAC/B,QAAO,OAAO,CAAC,SAAS,CAAM,KAC7B,SAiBD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ApduReceiverServiceFactory, type ApduResponse, type ApduSenderServiceFactory, type DeviceApduSender, type DmkError, type LoggerPublisherService } from "@ledgerhq/device-management-kit";
|
|
2
|
+
import { type Either } from "purify-ts";
|
|
3
|
+
export type WebHidApduSenderConstructorArgs = {
|
|
4
|
+
dependencies: WebHidApduSenderDependencies;
|
|
5
|
+
apduSenderFactory: ApduSenderServiceFactory;
|
|
6
|
+
apduReceiverFactory: ApduReceiverServiceFactory;
|
|
7
|
+
};
|
|
8
|
+
export type WebHidApduSenderDependencies = {
|
|
9
|
+
device: HIDDevice;
|
|
10
|
+
};
|
|
11
|
+
export declare class WebHidApduSender implements DeviceApduSender<WebHidApduSenderDependencies> {
|
|
12
|
+
private dependencies;
|
|
13
|
+
private readonly apduSender;
|
|
14
|
+
private readonly apduReceiver;
|
|
15
|
+
private sendApduPromiseResolver;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
constructor({ dependencies, apduSenderFactory, apduReceiverFactory, }: WebHidApduSenderConstructorArgs, loggerServiceFactory: (tag: string) => LoggerPublisherService);
|
|
18
|
+
sendApdu(apdu: Uint8Array, _triggersDisconnection?: boolean, abortTimeout?: number): Promise<Either<DmkError, ApduResponse>>;
|
|
19
|
+
private receiveHidInputReport;
|
|
20
|
+
getDependencies(): WebHidApduSenderDependencies;
|
|
21
|
+
setDependencies(dependencies: WebHidApduSenderDependencies): void;
|
|
22
|
+
setupConnection(): Promise<void>;
|
|
23
|
+
closeConnection(): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=WebHidApduSender.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebHidApduSender.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidApduSender.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EAEjB,KAAK,wBAAwB,EAC7B,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EAEb,KAAK,sBAAsB,EAG5B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,MAAM,EAA+B,MAAM,WAAW,CAAC;AAKrE,MAAM,MAAM,+BAA+B,GAAG;IAC5C,YAAY,EAAE,4BAA4B,CAAC;IAC3C,iBAAiB,EAAE,wBAAwB,CAAC;IAC5C,mBAAmB,EAAE,0BAA0B,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,qBAAa,gBACX,YAAW,gBAAgB,CAAC,4BAA4B,CAAC;IAEzD,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,uBAAuB,CAE7B;IACF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;gBAG9C,EACE,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACpB,EAAE,+BAA+B,EAClC,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAiBzD,QAAQ,CACZ,IAAI,EAAE,UAAU,EAChB,sBAAsB,CAAC,EAAE,OAAO,EAChC,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAyC1C,OAAO,CAAC,qBAAqB;IAoBtB,eAAe;IAIf,eAAe,CAAC,YAAY,EAAE,4BAA4B;IAIpD,eAAe;IAmBrB,eAAe;CAUvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebHidApduSender.test.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidApduSender.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { type ApduReceiverServiceFactory, type ApduSenderServiceFactory, type ConnectError, type DeviceId, type DeviceModelDataSource, type DisconnectHandler, type DmkError, type LoggerPublisherService, type Transport, TransportConnectedDevice, type TransportDiscoveredDevice, type TransportFactory, type TransportIdentifier } from "@ledgerhq/device-management-kit";
|
|
1
|
+
import { type ApduReceiverServiceFactory, type ApduSenderServiceFactory, type ConnectError, DeviceConnectionStateMachine, type DeviceConnectionStateMachineParams, type DeviceId, type DeviceModelDataSource, type DisconnectHandler, type DmkError, type LoggerPublisherService, type Transport, TransportConnectedDevice, type TransportDiscoveredDevice, type TransportFactory, type TransportIdentifier } from "@ledgerhq/device-management-kit";
|
|
2
2
|
import { type Either } from "purify-ts";
|
|
3
3
|
import { type Observable } from "rxjs";
|
|
4
|
+
import { WebHidApduSender, type WebHidApduSenderConstructorArgs, type WebHidApduSenderDependencies } from "./WebHidApduSender";
|
|
4
5
|
export declare const webHidIdentifier: TransportIdentifier;
|
|
5
6
|
export declare class WebHidTransport implements Transport {
|
|
6
7
|
private readonly _deviceModelDataSource;
|
|
7
8
|
private readonly _loggerServiceFactory;
|
|
8
9
|
private readonly _apduSenderFactory;
|
|
9
10
|
private readonly _apduReceiverFactory;
|
|
11
|
+
private readonly _deviceConnectionStateMachineFactory;
|
|
12
|
+
private readonly _deviceApduSenderFactory;
|
|
10
13
|
/** List of HID devices that have been discovered */
|
|
11
14
|
private _transportDiscoveredDevices;
|
|
12
|
-
/** Map of *connected* HIDDevice to their
|
|
15
|
+
/** Map of *connected* HIDDevice to their device connection */
|
|
13
16
|
private _deviceConnectionsByHidDevice;
|
|
14
17
|
/**
|
|
15
|
-
* Set of
|
|
18
|
+
* Set of device connections for which the HIDDevice has been
|
|
16
19
|
* disconnected, so they are waiting for a reconnection
|
|
17
20
|
*/
|
|
18
21
|
private _deviceConnectionsPendingReconnection;
|
|
@@ -21,7 +24,7 @@ export declare class WebHidTransport implements Transport {
|
|
|
21
24
|
private _logger;
|
|
22
25
|
private readonly connectionType;
|
|
23
26
|
private readonly identifier;
|
|
24
|
-
constructor(_deviceModelDataSource: DeviceModelDataSource, _loggerServiceFactory: (tag: string) => LoggerPublisherService, _apduSenderFactory: ApduSenderServiceFactory, _apduReceiverFactory: ApduReceiverServiceFactory);
|
|
27
|
+
constructor(_deviceModelDataSource: DeviceModelDataSource, _loggerServiceFactory: (tag: string) => LoggerPublisherService, _apduSenderFactory: ApduSenderServiceFactory, _apduReceiverFactory: ApduReceiverServiceFactory, _deviceConnectionStateMachineFactory?: (args: DeviceConnectionStateMachineParams<WebHidApduSenderDependencies>) => DeviceConnectionStateMachine<WebHidApduSenderDependencies>, _deviceApduSenderFactory?: (args: WebHidApduSenderConstructorArgs, loggerFactory: (tag: string) => LoggerPublisherService) => WebHidApduSender);
|
|
25
28
|
/**
|
|
26
29
|
* Get the WebHID API if supported or error
|
|
27
30
|
* @returns `Either<WebHidTransportNotSupportedError, HID>`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebHidTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAEjB,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAE1B,KAAK,iBAAiB,EACtB,KAAK,QAAQ,
|
|
1
|
+
{"version":3,"file":"WebHidTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAEjB,4BAA4B,EAC5B,KAAK,kCAAkC,EACvC,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAE1B,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EAEb,KAAK,sBAAsB,EAG3B,KAAK,SAAS,EACd,wBAAwB,EAExB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAEzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,MAAM,EAAmC,MAAM,WAAW,CAAC;AACzE,OAAO,EAA8B,KAAK,UAAU,EAAa,MAAM,MAAM,CAAC;AAM9E,OAAO,EACL,gBAAgB,EAChB,KAAK,+BAA+B,EACpC,KAAK,4BAA4B,EAClC,MAAM,oBAAoB,CAAC;AAU5B,eAAO,MAAM,gBAAgB,EAAE,mBAA+B,CAAC;AAE/D,qBAAa,eAAgB,YAAW,SAAS;IA4B7C,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAGtC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IACrC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