@ledgerhq/device-transport-kit-web-hid 1.0.1 → 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.
Files changed (33) hide show
  1. package/README.md +1 -1
  2. package/lib/esm/api/model/HIDDevice.stub.js +1 -1
  3. package/lib/esm/api/model/HIDDevice.stub.js.map +2 -2
  4. package/lib/esm/api/transport/WebHidApduSender.js +2 -0
  5. package/lib/esm/api/transport/WebHidApduSender.js.map +7 -0
  6. package/lib/esm/api/transport/WebHidApduSender.test.js +2 -0
  7. package/lib/esm/api/transport/WebHidApduSender.test.js.map +7 -0
  8. package/lib/esm/api/transport/WebHidTransport.js +1 -1
  9. package/lib/esm/api/transport/WebHidTransport.js.map +3 -3
  10. package/lib/esm/api/transport/WebHidTransport.test.js +1 -1
  11. package/lib/esm/api/transport/WebHidTransport.test.js.map +3 -3
  12. package/lib/esm/package.json +17 -17
  13. package/lib/types/api/model/HIDDevice.stub.d.ts.map +1 -1
  14. package/lib/types/api/transport/WebHidApduSender.d.ts +25 -0
  15. package/lib/types/api/transport/WebHidApduSender.d.ts.map +1 -0
  16. package/lib/types/api/transport/WebHidApduSender.test.d.ts +2 -0
  17. package/lib/types/api/transport/WebHidApduSender.test.d.ts.map +1 -0
  18. package/lib/types/api/transport/WebHidTransport.d.ts +8 -5
  19. package/lib/types/api/transport/WebHidTransport.d.ts.map +1 -1
  20. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  21. package/package.json +17 -17
  22. package/lib/esm/api/transport/WebHidDeviceConnection.js +0 -2
  23. package/lib/esm/api/transport/WebHidDeviceConnection.js.map +0 -7
  24. package/lib/esm/api/transport/WebHidDeviceConnection.stub.js +0 -2
  25. package/lib/esm/api/transport/WebHidDeviceConnection.stub.js.map +0 -7
  26. package/lib/esm/api/transport/WebHidDeviceConnection.test.js +0 -2
  27. package/lib/esm/api/transport/WebHidDeviceConnection.test.js.map +0 -7
  28. package/lib/types/api/transport/WebHidDeviceConnection.d.ts +0 -49
  29. package/lib/types/api/transport/WebHidDeviceConnection.d.ts.map +0 -1
  30. package/lib/types/api/transport/WebHidDeviceConnection.stub.d.ts +0 -5
  31. package/lib/types/api/transport/WebHidDeviceConnection.stub.d.ts.map +0 -1
  32. package/lib/types/api/transport/WebHidDeviceConnection.test.d.ts +0 -2
  33. package/lib/types/api/transport/WebHidDeviceConnection.test.d.ts.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/device-transport-kit-web-hid",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "private": false,
6
6
  "exports": {
@@ -14,39 +14,39 @@
14
14
  "package.json"
15
15
  ],
16
16
  "dependencies": {
17
- "@sentry/minimal": "^6.19.7",
18
- "purify-ts": "^2.1.0",
19
- "uuid": "^11.0.3"
17
+ "@sentry/minimal": "6.19.7",
18
+ "purify-ts": "2.1.0",
19
+ "uuid": "11.0.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/uuid": "^10.0.0",
23
23
  "@types/w3c-web-hid": "^1.0.6",
24
- "rxjs": "^7.8.1",
25
- "ts-node": "^10.9.2",
26
- "@ledgerhq/device-management-kit": "0.6.0",
27
- "@ledgerhq/esbuild-tools": "0.0.2",
24
+ "rxjs": "^7.8.2",
25
+ "ts-node": "10.9.2",
26
+ "@ledgerhq/device-management-kit": "0.8.0",
27
+ "@ledgerhq/ldmk-tool": "0.0.1",
28
28
  "@ledgerhq/eslint-config-dsdk": "0.0.2",
29
- "@ledgerhq/jest-config-dsdk": "1.0.1",
29
+ "@ledgerhq/tsconfig-dsdk": "1.0.1",
30
30
  "@ledgerhq/prettier-config-dsdk": "0.0.2",
31
- "@ledgerhq/tsconfig-dsdk": "1.0.1"
31
+ "@ledgerhq/vitest-config-dmk": "0.0.0"
32
32
  },
33
33
  "peerDependencies": {
34
- "@ledgerhq/device-management-kit": ">= 0.6 < 2",
35
- "rxjs": "^7.8.1"
34
+ "rxjs": "^7.8.2",
35
+ "@ledgerhq/device-management-kit": "0.8.0"
36
36
  },
37
37
  "scripts": {
38
38
  "prebuild": "rimraf lib",
39
- "build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web",
39
+ "build": "pnpm ldmk-tool build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web",
40
40
  "dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
41
- "watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web",
41
+ "watch:builds": "pnpm ldmk-tool watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json --platform web",
42
42
  "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
43
43
  "lint": "eslint",
44
44
  "lint:fix": "pnpm lint --fix",
45
45
  "prettier": "prettier . --check",
46
46
  "prettier:fix": "prettier . --write",
47
47
  "typecheck": "tsc --noEmit",
48
- "test": "jest",
49
- "test:watch": "pnpm test -- --watch",
50
- "test:coverage": "pnpm test -- --coverage"
48
+ "test": "vitest run",
49
+ "test:watch": "vitest",
50
+ "test:coverage": "vitest run --coverage"
51
51
  }
52
52
  }
@@ -1,2 +0,0 @@
1
- import{CommandUtils as g,ReconnectionFailedError as h}from"@ledgerhq/device-management-kit";import{Left as c,Maybe as m,Nothing as d,Right as u}from"purify-ts";import{firstValueFrom as l,from as _,retry as b,Subject as p}from"rxjs";import{RECONNECT_DEVICE_TIMEOUT as f}from"../data/WebHidConfig";import{WebHidSendReportError as s}from"../model/Errors";class C{_device;_deviceId;_apduSender;_apduReceiver;_sendApduSubject=new p;_logger;_pendingApdu=d;_onConnectionTerminated;reconnectionSubject=new p;waitingForReconnection=!1;lostConnectionTimeout=null;terminated=!1;constructor({device:t,deviceId:n,apduSender:o,apduReceiver:r,onConnectionTerminated:e},i){this._apduSender=o,this._apduReceiver=r,this._onConnectionTerminated=e,this._logger=i("WebHidDeviceConnection"),this._device=t,this._device.oninputreport=a=>this.receiveHidInputReport(a),this._deviceId=n,this._logger.info("\u{1F50C} Connected to device")}get device(){return this._device}get deviceId(){return this._deviceId}async sendApdu(t,n){this._sendApduSubject=new p,this._pendingApdu=m.of(t),this._logger.debug("Sending APDU",{data:{apdu:t},tag:"apdu-sender"});const o=new Promise(e=>{this._sendApduSubject.subscribe({next:async i=>{this._pendingApdu=d,n&&g.isSuccessResponse(i)?(await this.waitForReconnection()).caseOf({Left:v=>e(c(v)),Right:()=>e(u(i))}):e(u(i))},error:i=>{this._pendingApdu=d,e(c(i))}})});if(this.waitingForReconnection||!this.device.opened){const e=this.device.opened&&this._pendingApdu.isJust(),i=await this.waitForReconnection(e);if(i.isLeft())return i}const r=this._apduSender.getFrames(t);for(const e of r){this._logger.debug("Sending Frame",{data:{frame:e.getRawData()}});try{await l(_(this._device.sendReport(0,e.getRawData())).pipe(b({count:3,delay:500})))}catch(i){return this._logger.error("Error sending frame",{data:{error:i}}),Promise.resolve(c(new s(i)))}}return o}receiveHidInputReport(t){const n=new Uint8Array(t.data.buffer);this._logger.debug("Received Frame",{data:{frame:n},tag:"apdu-receiver"}),this._apduReceiver.handleFrame(n).caseOf({Right:r=>{r.map(e=>{this._logger.debug("Received APDU Response",{data:{response:e}}),this._sendApduSubject.next(e),this._sendApduSubject.complete()})},Left:r=>{this._sendApduSubject.error(r)}})}waitForReconnection(t=!1){return this.terminated?Promise.resolve(c(new h)):new Promise(n=>{const o=this.reconnectionSubject.subscribe({next:r=>{t&&this._sendApduSubject.error(new s(new Error("Device disconnected while waiting for device response"))),n(r==="success"?u(void 0):c(r)),o.unsubscribe()}})})}lostConnection(){this._logger.info("\u23F1\uFE0F Lost connection, starting timer"),this.waitingForReconnection=!0,this.lostConnectionTimeout=setTimeout(()=>{this._logger.info("\u274C Disconnection timeout, terminating connection"),this.disconnect()},f)}async reconnectHidDevice(t){this._device=t,this._device.oninputreport=n=>this.receiveHidInputReport(n),this.lostConnectionTimeout&&clearTimeout(this.lostConnectionTimeout),this._pendingApdu.isJust()&&this._sendApduSubject.error(new s),await t.open(),this._logger.info("\u23F1\uFE0F\u{1F50C} Device reconnected"),this.waitingForReconnection=!1,this.reconnectionSubject.next("success")}disconnect(){this._pendingApdu.isJust()&&this._sendApduSubject.error(new s),this._logger.info("\u{1F51A} Disconnect"),this.lostConnectionTimeout&&clearTimeout(this.lostConnectionTimeout),this.terminated=!0,this._onConnectionTerminated(),this.reconnectionSubject.next(new h)}}export{C as WebHidDeviceConnection};
2
- //# sourceMappingURL=WebHidDeviceConnection.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/api/transport/WebHidDeviceConnection.ts"],
4
- "sourcesContent": ["import {\n type ApduReceiverService,\n type ApduResponse,\n type ApduSenderService,\n CommandUtils,\n type DeviceConnection,\n type DeviceId,\n type DmkError,\n type LoggerPublisherService,\n ReconnectionFailedError,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Maybe, Nothing, Right } from \"purify-ts\";\nimport { firstValueFrom, from, retry, Subject } from \"rxjs\";\n\nimport { RECONNECT_DEVICE_TIMEOUT } from \"@api/data/WebHidConfig\";\nimport { WebHidSendReportError } from \"@api/model/Errors\";\n\ntype WebHidDeviceConnectionConstructorArgs = {\n device: HIDDevice;\n deviceId: DeviceId;\n apduSender: ApduSenderService;\n apduReceiver: ApduReceiverService;\n onConnectionTerminated: () => void;\n};\n\ntype Timer = ReturnType<typeof setTimeout>;\n\n/**\n * Class to manage the connection with a USB HID device.\n * It sends APDU commands to the device and receives the responses.\n * It handles temporary disconnections and reconnections.\n */\nexport class WebHidDeviceConnection implements DeviceConnection {\n private _device: HIDDevice;\n private _deviceId: DeviceId;\n private readonly _apduSender: ApduSenderService;\n private readonly _apduReceiver: ApduReceiverService;\n private _sendApduSubject: Subject<ApduResponse> = new Subject();\n private readonly _logger: LoggerPublisherService;\n private _pendingApdu: Maybe<Uint8Array> = Nothing;\n\n /** Callback to notify the connection termination */\n private _onConnectionTerminated: () => void;\n /** Subject to notify the reconnection status */\n private reconnectionSubject: Subject<\"success\" | DmkError> = new Subject();\n /** Flag to indicate if the connection is waiting for a reconnection */\n private waitingForReconnection = false;\n /** Timeout to wait for the device to reconnect */\n private lostConnectionTimeout: Timer | null = null;\n /** Flag to indicate if the connection is terminated */\n private terminated = false;\n\n constructor(\n {\n device,\n deviceId,\n apduSender,\n apduReceiver,\n onConnectionTerminated,\n }: WebHidDeviceConnectionConstructorArgs,\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._apduSender = apduSender;\n this._apduReceiver = apduReceiver;\n this._onConnectionTerminated = onConnectionTerminated;\n this._logger = loggerServiceFactory(\"WebHidDeviceConnection\");\n this._device = device;\n this._device.oninputreport = (event) => this.receiveHidInputReport(event);\n this._deviceId = deviceId;\n this._logger.info(\"\uD83D\uDD0C Connected to device\");\n }\n\n public get device() {\n return this._device;\n }\n\n public get deviceId() {\n return this._deviceId;\n }\n\n async sendApdu(\n apdu: Uint8Array,\n triggersDisconnection?: boolean,\n ): Promise<Either<DmkError, ApduResponse>> {\n this._sendApduSubject = new Subject();\n this._pendingApdu = Maybe.of(apdu);\n this._logger.debug(\"Sending APDU\", {\n data: { apdu },\n tag: \"apdu-sender\",\n });\n\n const resultPromise = new Promise<Either<DmkError, ApduResponse>>(\n (resolve) => {\n this._sendApduSubject.subscribe({\n next: async (r) => {\n this._pendingApdu = Nothing;\n if (triggersDisconnection && CommandUtils.isSuccessResponse(r)) {\n // Anticipate the disconnection and wait for the reconnection before resolving\n const reconnectionRes = await this.waitForReconnection();\n reconnectionRes.caseOf({\n Left: (err) => resolve(Left(err)),\n Right: () => resolve(Right(r)),\n });\n } else {\n resolve(Right(r));\n }\n },\n error: (err) => {\n this._pendingApdu = Nothing;\n resolve(Left(err));\n },\n });\n },\n );\n\n if (this.waitingForReconnection || !this.device.opened) {\n const waitingForDeviceResponse =\n this.device.opened && this._pendingApdu.isJust();\n const reconnectionRes = await this.waitForReconnection(\n waitingForDeviceResponse,\n );\n if (reconnectionRes.isLeft()) {\n return reconnectionRes;\n }\n }\n\n const frames = this._apduSender.getFrames(apdu);\n for (const frame of frames) {\n this._logger.debug(\"Sending Frame\", {\n data: { frame: frame.getRawData() },\n });\n\n try {\n await firstValueFrom(\n from(this._device.sendReport(0, frame.getRawData())).pipe(\n retry({\n count: 3,\n delay: 500,\n }),\n ),\n );\n } catch (error) {\n this._logger.error(\"Error sending frame\", { data: { error } });\n return Promise.resolve(Left(new WebHidSendReportError(error)));\n }\n }\n\n return resultPromise;\n }\n\n private receiveHidInputReport(event: HIDInputReportEvent) {\n const data = new Uint8Array(event.data.buffer);\n this._logger.debug(\"Received Frame\", {\n data: { frame: data },\n tag: \"apdu-receiver\",\n });\n const response = this._apduReceiver.handleFrame(data);\n response.caseOf({\n Right: (maybeApduResponse) => {\n maybeApduResponse.map((apduResponse) => {\n this._logger.debug(\"Received APDU Response\", {\n data: { response: apduResponse },\n });\n this._sendApduSubject.next(apduResponse);\n this._sendApduSubject.complete();\n });\n },\n Left: (err) => {\n this._sendApduSubject.error(err);\n },\n });\n }\n\n private waitForReconnection(\n waitingForDeviceResponse: boolean = false,\n ): Promise<Either<DmkError, void>> {\n if (this.terminated) {\n return Promise.resolve(Left(new ReconnectionFailedError()));\n }\n\n return new Promise<Either<DmkError, void>>((resolve) => {\n const sub = this.reconnectionSubject.subscribe({\n next: (res) => {\n if (waitingForDeviceResponse) {\n this._sendApduSubject.error(\n new WebHidSendReportError(\n new Error(\n \"Device disconnected while waiting for device response\",\n ),\n ),\n );\n }\n\n if (res === \"success\") {\n resolve(Right(undefined));\n } else {\n resolve(Left(res));\n }\n\n sub.unsubscribe();\n },\n });\n });\n }\n\n /**\n * Method called when the HIDDevice gets disconnected.\n * It starts a timeout to wait for the device to reconnect.\n * */\n public lostConnection() {\n this._logger.info(\"\u23F1\uFE0F Lost connection, starting timer\");\n this.waitingForReconnection = true;\n this.lostConnectionTimeout = setTimeout(() => {\n this._logger.info(\"\u274C Disconnection timeout, terminating connection\");\n this.disconnect();\n }, RECONNECT_DEVICE_TIMEOUT);\n }\n\n /** Reconnect the device after a disconnection */\n public async reconnectHidDevice(device: HIDDevice) {\n this._device = device;\n this._device.oninputreport = (event) => this.receiveHidInputReport(event);\n\n if (this.lostConnectionTimeout) {\n clearTimeout(this.lostConnectionTimeout);\n }\n\n if (this._pendingApdu.isJust()) {\n this._sendApduSubject.error(new WebHidSendReportError());\n }\n\n await device.open();\n\n this._logger.info(\"\u23F1\uFE0F\uD83D\uDD0C Device reconnected\");\n this.waitingForReconnection = false;\n this.reconnectionSubject.next(\"success\");\n }\n\n public disconnect() {\n if (this._pendingApdu.isJust()) {\n this._sendApduSubject.error(new WebHidSendReportError());\n }\n\n this._logger.info(\"\uD83D\uDD1A Disconnect\");\n if (this.lostConnectionTimeout) clearTimeout(this.lostConnectionTimeout);\n this.terminated = true;\n this._onConnectionTerminated();\n this.reconnectionSubject.next(new ReconnectionFailedError());\n }\n}\n"],
5
- "mappings": "AAAA,OAIE,gBAAAA,EAKA,2BAAAC,MACK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,EAAO,WAAAC,EAAS,SAAAC,MAAa,YACzD,OAAS,kBAAAC,EAAgB,QAAAC,EAAM,SAAAC,EAAO,WAAAC,MAAe,OAErD,OAAS,4BAAAC,MAAgC,yBACzC,OAAS,yBAAAC,MAA6B,oBAiB/B,MAAMC,CAAmD,CACtD,QACA,UACS,YACA,cACT,iBAA0C,IAAIH,EACrC,QACT,aAAkCL,EAGlC,wBAEA,oBAAqD,IAAIK,EAEzD,uBAAyB,GAEzB,sBAAsC,KAEtC,WAAa,GAErB,YACE,CACE,OAAAI,EACA,SAAAC,EACA,WAAAC,EACA,aAAAC,EACA,uBAAAC,CACF,EACAC,EACA,CACA,KAAK,YAAcH,EACnB,KAAK,cAAgBC,EACrB,KAAK,wBAA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,QAAQ,KAAK,8CAAoC,EACtD,KAAK,uBAAyB,GAC9B,KAAK,sBAAwB,WAAW,IAAM,CAC5C,KAAK,QAAQ,KAAK,sDAAiD,EACnE,KAAK,WAAW,CAClB,EAAGxB,CAAwB,CAC7B,CAGA,MAAa,mBAAmBG,EAAmB,CACjD,KAAK,QAAUA,EACf,KAAK,QAAQ,cAAiBM,GAAU,KAAK,sBAAsBA,CAAK,EAEpE,KAAK,uBACP,aAAa,KAAK,qBAAqB,EAGrC,KAAK,aAAa,OAAO,GAC3B,KAAK,iBAAiB,MAAM,IAAIR,CAAuB,EAGzD,MAAME,EAAO,KAAK,EAElB,KAAK,QAAQ,KAAK,0CAAyB,EAC3C,KAAK,uBAAyB,GAC9B,KAAK,oBAAoB,KAAK,SAAS,CACzC,CAEO,YAAa,CACd,KAAK,aAAa,OAAO,GAC3B,KAAK,iBAAiB,MAAM,IAAIF,CAAuB,EAGzD,KAAK,QAAQ,KAAK,sBAAe,EAC7B,KAAK,uBAAuB,aAAa,KAAK,qBAAqB,EACvE,KAAK,WAAa,GAClB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,KAAK,IAAIV,CAAyB,CAC7D,CACF",
6
- "names": ["CommandUtils", "ReconnectionFailedError", "Left", "Maybe", "Nothing", "Right", "firstValueFrom", "from", "retry", "Subject", "RECONNECT_DEVICE_TIMEOUT", "WebHidSendReportError", "WebHidDeviceConnection", "device", "deviceId", "apduSender", "apduReceiver", "onConnectionTerminated", "loggerServiceFactory", "event", "apdu", "triggersDisconnection", "resultPromise", "resolve", "r", "err", "waitingForDeviceResponse", "reconnectionRes", "frames", "frame", "error", "data", "maybeApduResponse", "apduResponse", "sub", "res"]
7
- }
@@ -1,2 +0,0 @@
1
- class n{sendApdu=jest.fn()}export{n as WebHidDeviceConnectionStub};
2
- //# sourceMappingURL=WebHidDeviceConnection.stub.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/api/transport/WebHidDeviceConnection.stub.ts"],
4
- "sourcesContent": ["import {\n type DeviceConnection,\n type SendApduFnType,\n} from \"@ledgerhq/device-management-kit\";\n\nexport class WebHidDeviceConnectionStub implements DeviceConnection {\n sendApdu: SendApduFnType = jest.fn();\n}\n"],
5
- "mappings": "AAKO,MAAMA,CAAuD,CAClE,SAA2B,KAAK,GAAG,CACrC",
6
- "names": ["WebHidDeviceConnectionStub"]
7
- }
@@ -1,2 +0,0 @@
1
- import{defaultApduReceiverServiceStubBuilder as A,defaultApduSenderServiceStubBuilder as y,ReconnectionFailedError as v}from"@ledgerhq/device-management-kit";import{Left as l,Right as w}from"purify-ts";import{RECONNECT_DEVICE_TIMEOUT as m}from"../data/WebHidConfig";import{WebHidSendReportError as h}from"../model/Errors";import{hidDeviceStubBuilder as b}from"../model/HIDDevice.stub";import{WebHidDeviceConnection as c}from"./WebHidDeviceConnection";jest.useFakeTimers();const S=new Uint8Array([170,170,5,0,0,0,2,85,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),p=new Uint8Array([170,170,5,0,0,0,2,144,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);class g{tag;constructor(r,o){this.subscribers=r,this.tag=o}subscribers=[];error=jest.fn();warn=jest.fn();debug=jest.fn();info=jest.fn()}const x=()=>new Promise(jest.requireActual("timers").setImmediate);jest.useFakeTimers();describe("WebHidDeviceConnection",()=>{let e,r,o;const s=()=>{},a="test-device-id",i=t=>new g([],t);beforeEach(()=>{e=b({opened:!0}),r=y(void 0,i),o=A(void 0,i)}),it("should get device",()=>{const n=new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i).device;expect(n).toStrictEqual(e)}),it("should send APDU through hid report",()=>{new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i).sendApdu(new Uint8Array(0)),expect(e.sendReport).toHaveBeenCalled()}),it("should receive APDU through hid report",async()=>{e.sendReport=jest.fn(()=>Promise.resolve(e.oninputreport({type:"inputreport",data:new DataView(Uint8Array.from(p).buffer)})));const n=await new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i).sendApdu(Uint8Array.from([]));expect(n).toEqual(w({statusCode:new Uint8Array([144,0]),data:new Uint8Array([])}))}),describe("anticipating loss of connection after sending an APDU",()=>{it("sendApdu(whatever, true) should wait for reconnection before resolving if the response is a success",async()=>{e.sendReport=jest.fn(()=>Promise.resolve(e.oninputreport({type:"inputreport",data:new DataView(Uint8Array.from(p).buffer)})));const t=new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i);let n=!1;const d=t.sendApdu(Uint8Array.from([]),!0).then(f=>(n=!0,f));t.lostConnection(),await x(),expect(n).toBe(!1),t.reconnectHidDevice(e),await x(),expect(n).toBe(!0);const u=await d;expect(u).toEqual(w({statusCode:new Uint8Array([144,0]),data:new Uint8Array([])}))}),it("sendApdu(whatever, true) should not wait for reconnection if the response is not a success",async()=>{e.sendReport=jest.fn(()=>Promise.resolve(e.oninputreport({type:"inputreport",data:new DataView(Uint8Array.from(S).buffer)})));const n=await new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i).sendApdu(Uint8Array.from([]),!0);expect(n).toEqual(w({statusCode:new Uint8Array([85,21]),data:new Uint8Array([])}))}),it("sendApdu(whatever, true) should return an error if the device gets disconnected while waiting for reconnection",async()=>{e.sendReport=jest.fn(()=>Promise.resolve(e.oninputreport({type:"inputreport",data:new DataView(Uint8Array.from(p).buffer)})));const t=new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i),n=t.sendApdu(Uint8Array.from([]),!0);t.lostConnection(),jest.advanceTimersByTime(m),await x();const d=await n;expect(d).toEqual(l(new v))})}),describe("connection lost before sending an APDU",()=>{it("sendApdu(whatever, false) should return an error if the device connection has been lost and times out",async()=>{e.sendReport=jest.fn(()=>Promise.resolve(e.oninputreport({type:"inputreport",data:new DataView(Uint8Array.from(p).buffer)})));const t=new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i);t.lostConnection(),jest.advanceTimersByTime(m),await x();const n=await t.sendApdu(Uint8Array.from([]),!1);await x(),expect(n).toEqual(l(new v))}),it("sendApdu(whatever, false) should wait for reconnection to resolve",async()=>{e.sendReport=jest.fn(()=>Promise.resolve(e.oninputreport({type:"inputreport",data:new DataView(Uint8Array.from(p).buffer)})));const t=new c({device:e,apduSender:r,apduReceiver:o,onConnectionTerminated:s,deviceId:a},i);t.lostConnection();let n=!1;const d=t.sendApdu(Uint8Array.from([]),!1).then(f=>(n=!0,f));await x(),expect(n).toBe(!1),t.reconnectHidDevice(e),await x(),expect(n).toBe(!0);const u=await d;expect(u).toEqual(l(new h))})})});
2
- //# sourceMappingURL=WebHidDeviceConnection.test.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/api/transport/WebHidDeviceConnection.test.ts"],
4
- "sourcesContent": ["import {\n type ApduReceiverService,\n type ApduSenderService,\n defaultApduReceiverServiceStubBuilder,\n defaultApduSenderServiceStubBuilder,\n type DeviceId,\n type LoggerPublisherService,\n type LoggerSubscriberService,\n ReconnectionFailedError,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { RECONNECT_DEVICE_TIMEOUT } from \"@api/data/WebHidConfig\";\nimport { WebHidSendReportError } from \"@api/model/Errors\";\nimport { hidDeviceStubBuilder } from \"@api/model/HIDDevice.stub\";\n\nimport { WebHidDeviceConnection } from \"./WebHidDeviceConnection\";\n\njest.useFakeTimers();\n\nconst RESPONSE_LOCKED_DEVICE = new Uint8Array([\n 0xaa, 0xaa, 0x05, 0x00, 0x00, 0x00, 0x02, 0x55, 0x15, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n]);\n\nconst RESPONSE_SUCCESS = new Uint8Array([\n 0xaa, 0xaa, 0x05, 0x00, 0x00, 0x00, 0x02, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n]);\n\nclass LoggerPublisherServiceStub implements LoggerPublisherService {\n tag: string;\n constructor(subscribers: LoggerSubscriberService[], tag: string) {\n this.subscribers = subscribers;\n this.tag = tag;\n }\n subscribers: LoggerSubscriberService[] = [];\n error = jest.fn();\n warn = jest.fn();\n debug = jest.fn();\n info = jest.fn();\n}\n\n/**\n * Flushes all pending promises\n */\nconst flushPromises = () =>\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n new Promise(jest.requireActual(\"timers\").setImmediate);\n\njest.useFakeTimers();\n\ndescribe(\"WebHidDeviceConnection\", () => {\n let device: HIDDevice;\n let apduSender: ApduSenderService;\n let apduReceiver: ApduReceiverService;\n const onConnectionTerminated = () => {};\n const deviceId: DeviceId = \"test-device-id\";\n const logger = (tag: string) => new LoggerPublisherServiceStub([], tag);\n\n beforeEach(() => {\n device = hidDeviceStubBuilder({ opened: true });\n apduSender = defaultApduSenderServiceStubBuilder(undefined, logger);\n apduReceiver = defaultApduReceiverServiceStubBuilder(undefined, logger);\n });\n\n it(\"should get device\", () => {\n // given\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n // when\n const cDevice = connection.device;\n // then\n expect(cDevice).toStrictEqual(device);\n });\n\n it(\"should send APDU through hid report\", () => {\n // given\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n // when\n connection.sendApdu(new Uint8Array(0));\n // then\n expect(device.sendReport).toHaveBeenCalled();\n });\n\n it(\"should receive APDU through hid report\", async () => {\n // given\n device.sendReport = jest.fn(() =>\n Promise.resolve(\n device.oninputreport!({\n type: \"inputreport\",\n data: new DataView(Uint8Array.from(RESPONSE_SUCCESS).buffer),\n } as HIDInputReportEvent),\n ),\n );\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n // when\n const response = await connection.sendApdu(Uint8Array.from([]));\n // then\n expect(response).toEqual(\n Right({\n statusCode: new Uint8Array([0x90, 0x00]),\n data: new Uint8Array([]),\n }),\n );\n });\n\n describe(\"anticipating loss of connection after sending an APDU\", () => {\n it(\"sendApdu(whatever, true) should wait for reconnection before resolving if the response is a success\", async () => {\n // given\n device.sendReport = jest.fn(() =>\n Promise.resolve(\n device.oninputreport!({\n type: \"inputreport\",\n data: new DataView(Uint8Array.from(RESPONSE_SUCCESS).buffer),\n } as HIDInputReportEvent),\n ),\n );\n\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n\n let hasResolved = false;\n\n const responsePromise = connection\n .sendApdu(Uint8Array.from([]), true)\n .then((response) => {\n hasResolved = true;\n return response;\n });\n\n connection.lostConnection();\n\n // before reconnecting\n await flushPromises();\n expect(hasResolved).toBe(false);\n\n // when reconnecting\n connection.reconnectHidDevice(device);\n await flushPromises();\n expect(hasResolved).toBe(true);\n\n const response = await responsePromise;\n\n expect(response).toEqual(\n Right({\n statusCode: new Uint8Array([0x90, 0x00]),\n data: new Uint8Array([]),\n }),\n );\n });\n\n it(\"sendApdu(whatever, true) should not wait for reconnection if the response is not a success\", async () => {\n // given\n device.sendReport = jest.fn(() =>\n Promise.resolve(\n device.oninputreport!({\n type: \"inputreport\",\n data: new DataView(Uint8Array.from(RESPONSE_LOCKED_DEVICE).buffer),\n } as HIDInputReportEvent),\n ),\n );\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n\n // when\n const response = await connection.sendApdu(Uint8Array.from([]), true);\n\n // then\n expect(response).toEqual(\n Right({\n statusCode: new Uint8Array([0x55, 0x15]),\n data: new Uint8Array([]),\n }),\n );\n });\n\n it(\"sendApdu(whatever, true) should return an error if the device gets disconnected while waiting for reconnection\", async () => {\n // given\n device.sendReport = jest.fn(() =>\n Promise.resolve(\n device.oninputreport!({\n type: \"inputreport\",\n data: new DataView(Uint8Array.from(RESPONSE_SUCCESS).buffer),\n } as HIDInputReportEvent),\n ),\n );\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n\n const responsePromise = connection.sendApdu(Uint8Array.from([]), true);\n\n // when disconnecting\n connection.lostConnection();\n jest.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n await flushPromises();\n\n // then\n const response = await responsePromise;\n expect(response).toEqual(Left(new ReconnectionFailedError()));\n });\n });\n\n describe(\"connection lost before sending an APDU\", () => {\n it(\"sendApdu(whatever, false) should return an error if the device connection has been lost and times out\", async () => {\n // given\n device.sendReport = jest.fn(() =>\n Promise.resolve(\n device.oninputreport!({\n type: \"inputreport\",\n data: new DataView(Uint8Array.from(RESPONSE_SUCCESS).buffer),\n } as HIDInputReportEvent),\n ),\n );\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n\n // when losing connection\n connection.lostConnection();\n jest.advanceTimersByTime(RECONNECT_DEVICE_TIMEOUT);\n await flushPromises();\n\n // then\n const response = await connection.sendApdu(Uint8Array.from([]), false);\n await flushPromises();\n expect(response).toEqual(Left(new ReconnectionFailedError()));\n });\n\n it(\"sendApdu(whatever, false) should wait for reconnection to resolve\", async () => {\n // given\n device.sendReport = jest.fn(() =>\n Promise.resolve(\n device.oninputreport!({\n type: \"inputreport\",\n data: new DataView(Uint8Array.from(RESPONSE_SUCCESS).buffer),\n } as HIDInputReportEvent),\n ),\n );\n const connection = new WebHidDeviceConnection(\n { device, apduSender, apduReceiver, onConnectionTerminated, deviceId },\n logger,\n );\n\n // when losing connection\n connection.lostConnection();\n\n let hasResolved = false;\n const responsePromise = connection\n .sendApdu(Uint8Array.from([]), false)\n .then((response) => {\n hasResolved = true;\n return response;\n });\n\n // before reconnecting\n await flushPromises();\n expect(hasResolved).toBe(false);\n\n // when reconnecting\n connection.reconnectHidDevice(device);\n await flushPromises();\n expect(hasResolved).toBe(true);\n\n const response = await responsePromise;\n\n expect(response).toEqual(Left(new WebHidSendReportError()));\n });\n });\n});\n"],
5
- "mappings": "AAAA,OAGE,yCAAAA,EACA,uCAAAC,EAIA,2BAAAC,MACK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,4BAAAC,MAAgC,yBACzC,OAAS,yBAAAC,MAA6B,oBACtC,OAAS,wBAAAC,MAA4B,4BAErC,OAAS,0BAAAC,MAA8B,2BAEvC,KAAK,cAAc,EAEnB,MAAMC,EAAyB,IAAI,WAAW,CAC5C,IAAM,IAAM,EAAM,EAAM,EAAM,EAAM,EAAM,GAAM,GAAM,EAAM,EAAM,EAAM,EACxE,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAA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e,EAE1B,IAAIC,EAAc,GAClB,MAAMC,EAAkBF,EACrB,SAAS,WAAW,KAAK,CAAC,CAAC,EAAG,EAAK,EACnC,KAAMD,IACLE,EAAc,GACPF,EACR,EAGH,MAAMR,EAAc,EACpB,OAAOU,CAAW,EAAE,KAAK,EAAK,EAG9BD,EAAW,mBAAmBR,CAAM,EACpC,MAAMD,EAAc,EACpB,OAAOU,CAAW,EAAE,KAAK,EAAI,EAE7B,MAAMF,EAAW,MAAMG,EAEvB,OAAOH,CAAQ,EAAE,QAAQnB,EAAK,IAAIG,CAAuB,CAAC,CAC5D,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["defaultApduReceiverServiceStubBuilder", "defaultApduSenderServiceStubBuilder", "ReconnectionFailedError", "Left", "Right", "RECONNECT_DEVICE_TIMEOUT", "WebHidSendReportError", "hidDeviceStubBuilder", "WebHidDeviceConnection", "RESPONSE_LOCKED_DEVICE", "RESPONSE_SUCCESS", "LoggerPublisherServiceStub", "subscribers", "tag", "flushPromises", "device", "apduSender", "apduReceiver", "onConnectionTerminated", "deviceId", "logger", "cDevice", "response", "connection", "hasResolved", "responsePromise"]
7
- }
@@ -1,49 +0,0 @@
1
- import { type ApduReceiverService, type ApduResponse, type ApduSenderService, type DeviceConnection, type DeviceId, type DmkError, type LoggerPublisherService } from "@ledgerhq/device-management-kit";
2
- import { type Either } from "purify-ts";
3
- type WebHidDeviceConnectionConstructorArgs = {
4
- device: HIDDevice;
5
- deviceId: DeviceId;
6
- apduSender: ApduSenderService;
7
- apduReceiver: ApduReceiverService;
8
- onConnectionTerminated: () => void;
9
- };
10
- /**
11
- * Class to manage the connection with a USB HID device.
12
- * It sends APDU commands to the device and receives the responses.
13
- * It handles temporary disconnections and reconnections.
14
- */
15
- export declare class WebHidDeviceConnection implements DeviceConnection {
16
- private _device;
17
- private _deviceId;
18
- private readonly _apduSender;
19
- private readonly _apduReceiver;
20
- private _sendApduSubject;
21
- private readonly _logger;
22
- private _pendingApdu;
23
- /** Callback to notify the connection termination */
24
- private _onConnectionTerminated;
25
- /** Subject to notify the reconnection status */
26
- private reconnectionSubject;
27
- /** Flag to indicate if the connection is waiting for a reconnection */
28
- private waitingForReconnection;
29
- /** Timeout to wait for the device to reconnect */
30
- private lostConnectionTimeout;
31
- /** Flag to indicate if the connection is terminated */
32
- private terminated;
33
- constructor({ device, deviceId, apduSender, apduReceiver, onConnectionTerminated, }: WebHidDeviceConnectionConstructorArgs, loggerServiceFactory: (tag: string) => LoggerPublisherService);
34
- get device(): HIDDevice;
35
- get deviceId(): string;
36
- sendApdu(apdu: Uint8Array, triggersDisconnection?: boolean): Promise<Either<DmkError, ApduResponse>>;
37
- private receiveHidInputReport;
38
- private waitForReconnection;
39
- /**
40
- * Method called when the HIDDevice gets disconnected.
41
- * It starts a timeout to wait for the device to reconnect.
42
- * */
43
- lostConnection(): void;
44
- /** Reconnect the device after a disconnection */
45
- reconnectHidDevice(device: HIDDevice): Promise<void>;
46
- disconnect(): void;
47
- }
48
- export {};
49
- //# sourceMappingURL=WebHidDeviceConnection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebHidDeviceConnection.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidDeviceConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAEtB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAE5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,MAAM,EAA+B,MAAM,WAAW,CAAC;AAMrE,KAAK,qCAAqC,GAAG;IAC3C,MAAM,EAAE,SAAS,CAAC;IAClB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,iBAAiB,CAAC;IAC9B,YAAY,EAAE,mBAAmB,CAAC;IAClC,sBAAsB,EAAE,MAAM,IAAI,CAAC;CACpC,CAAC;AAIF;;;;GAIG;AACH,qBAAa,sBAAuB,YAAW,gBAAgB;IAC7D,OAAO,CAAC,OAAO,CAAY;IAC3B,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,gBAAgB,CAAwC;IAChE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,YAAY,CAA8B;IAElD,oDAAoD;IACpD,OAAO,CAAC,uBAAuB,CAAa;IAC5C,gDAAgD;IAChD,OAAO,CAAC,mBAAmB,CAAgD;IAC3E,uEAAuE;IACvE,OAAO,CAAC,sBAAsB,CAAS;IACvC,kDAAkD;IAClD,OAAO,CAAC,qBAAqB,CAAsB;IACnD,uDAAuD;IACvD,OAAO,CAAC,UAAU,CAAS;gBAGzB,EACE,MAAM,EACN,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,sBAAsB,GACvB,EAAE,qCAAqC,EACxC,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAY/D,IAAW,MAAM,cAEhB;IAED,IAAW,QAAQ,WAElB;IAEK,QAAQ,CACZ,IAAI,EAAE,UAAU,EAChB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAmE1C,OAAO,CAAC,qBAAqB;IAuB7B,OAAO,CAAC,mBAAmB;IAgC3B;;;SAGK;IACE,cAAc;IASrB,iDAAiD;IACpC,kBAAkB,CAAC,MAAM,EAAE,SAAS;IAmB1C,UAAU;CAWlB"}
@@ -1,5 +0,0 @@
1
- import { type DeviceConnection, type SendApduFnType } from "@ledgerhq/device-management-kit";
2
- export declare class WebHidDeviceConnectionStub implements DeviceConnection {
3
- sendApdu: SendApduFnType;
4
- }
5
- //# sourceMappingURL=WebHidDeviceConnection.stub.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebHidDeviceConnection.stub.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidDeviceConnection.stub.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACpB,MAAM,iCAAiC,CAAC;AAEzC,qBAAa,0BAA2B,YAAW,gBAAgB;IACjE,QAAQ,EAAE,cAAc,CAAa;CACtC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=WebHidDeviceConnection.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebHidDeviceConnection.test.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebHidDeviceConnection.test.ts"],"names":[],"mappings":""}