@ledgerhq/device-management-kit 0.0.0-develop-20250610001205 → 0.0.0-develop-20250611001326

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.
@@ -0,0 +1,2 @@
1
+ "use strict";var n=require("purify-ts/Either"),e=require("vitest"),i=require("../../device-session/ApduResponse"),p=require("./DeviceConnectionStateMachine"),l=require("./Errors");(0,e.describe)("DeviceConnectionStateMachine",()=>{let s;const o={sendApdu:e.vi.fn(),getDependencies:e.vi.fn(),setDependencies:e.vi.fn(),closeConnection:e.vi.fn(),setupConnection:e.vi.fn()};(0,e.beforeEach)(()=>{e.vi.useFakeTimers(),s=new p.DeviceConnectionStateMachine({deviceId:"deviceId",deviceApduSender:o,timeoutDuration:1e3,onTerminated:e.vi.fn()})}),(0,e.afterEach)(()=>{e.vi.useRealTimers(),e.vi.restoreAllMocks()}),(0,e.describe)("Send APDUs",()=>{(0,e.it)("should send APDU successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),a=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(a));const t=await s.sendApdu(d);(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(t).toStrictEqual((0,n.Right)(a))}),(0,e.it)("should send several APDUs successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));const r=await s.sendApdu(d),u=await s.sendApdu(a);(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(2),(0,e.expect)(r).toStrictEqual((0,n.Right)(t)),(0,e.expect)(u).toStrictEqual((0,n.Right)(t))}),(0,e.it)("should not send several APDUs in parallel",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));const r=s.sendApdu(d),u=await s.sendApdu(a),c=await r;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(c).toStrictEqual((0,n.Right)(t)),(0,e.expect)(u).toStrictEqual((0,n.Left)(new l.AlreadySendingApduError))}),(0,e.it)("Detached while sending APDU",async()=>{const d=Uint8Array.from([1,2,3,4]),a=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(a));const t=s.sendApdu(d);s.eventDeviceDetached();const r=await t;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(r).toStrictEqual((0,n.Left)(new l.DeviceDisconnectedWhileSendingError))}),(0,e.it)("Disconnected while sending APDU",async()=>{const d=Uint8Array.from([1,2,3,4]),a=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(a));const t=s.sendApdu(d);s.closeConnection();const r=await t;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(r).toStrictEqual((0,n.Left)(new l.DeviceDisconnectedWhileSendingError))})}),(0,e.describe)("Send APDUs triggering disconnection",()=>{(0,e.it)("should send one APDU successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),a=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(a));const t=await s.sendApdu(d,!0);(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(t).toStrictEqual((0,n.Right)(a))}),(0,e.it)("should send several APDUs successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));const r=await s.sendApdu(d,!0),u=s.sendApdu(a);s.eventDeviceDetached(),s.eventDeviceAttached();const c=await u;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(2),(0,e.expect)(r).toStrictEqual((0,n.Right)(t)),(0,e.expect)(c).toStrictEqual((0,n.Right)(t))}),(0,e.it)("should send a second APDU after reconnection",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));const r=await s.sendApdu(d,!0);s.eventDeviceDetached(),s.eventDeviceAttached();const u=await s.sendApdu(a);(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(2),(0,e.expect)(r).toStrictEqual((0,n.Right)(t)),(0,e.expect)(u).toStrictEqual((0,n.Right)(t))}),(0,e.it)("should not send several APDUs in parallel",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));const r=s.sendApdu(d,!0),u=await s.sendApdu(a),c=await r;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(c).toStrictEqual((0,n.Right)(t)),(0,e.expect)(u).toStrictEqual((0,n.Left)(new l.AlreadySendingApduError))}),(0,e.it)("should send another APDU in promise handler",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));let r;const u=await s.sendApdu(d,!0).then(A=>(r=s.sendApdu(a),A));s.eventDeviceDetached(),s.eventDeviceAttached();const c=await r;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(2),(0,e.expect)(u).toStrictEqual((0,n.Right)(t)),(0,e.expect)(c).toStrictEqual((0,n.Right)(t))}),(0,e.it)("send an APDU while device is reconnecting",async()=>{const d=Uint8Array.from([1,2,3,4]),a=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(a)),s.eventDeviceDetached();const t=s.sendApdu(d,!0);s.eventDeviceAttached();const r=await t;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(r).toStrictEqual((0,n.Right)(a))}),(0,e.it)("Close while an APDU is waiting for reconnection",async()=>{const d=Uint8Array.from([1,2,3,4]),a=Uint8Array.from([9,2,3,4]),t=new i.ApduResponse({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue((0,n.Right)(t));let r;const u=await s.sendApdu(d,!0);r=s.sendApdu(a),s.closeConnection();const c=await r;(0,e.expect)(o.sendApdu).toHaveBeenCalledTimes(1),(0,e.expect)(u).toStrictEqual((0,n.Right)(t)),(0,e.expect)(c).toStrictEqual((0,n.Left)(new l.DeviceDisconnectedWhileSendingError))})})});
2
+ //# sourceMappingURL=DeviceConnectionStateMachine.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/api/transport/model/DeviceConnectionStateMachine.test.ts"],
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts/Either\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { ApduResponse } from \"@api/device-session/ApduResponse\";\n\nimport { type SendApduResult } from \"./DeviceConnection\";\nimport { DeviceConnectionStateMachine } from \"./DeviceConnectionStateMachine\";\nimport {\n AlreadySendingApduError,\n DeviceDisconnectedWhileSendingError,\n} from \"./Errors\";\n\ndescribe(\"DeviceConnectionStateMachine\", () => {\n let machine: DeviceConnectionStateMachine<void>;\n const mockApduSender = {\n sendApdu: vi.fn(),\n getDependencies: vi.fn(),\n setDependencies: vi.fn(),\n closeConnection: vi.fn(),\n setupConnection: vi.fn(),\n };\n\n beforeEach(() => {\n vi.useFakeTimers();\n machine = new DeviceConnectionStateMachine({\n deviceId: \"deviceId\",\n deviceApduSender: mockApduSender,\n timeoutDuration: 1000,\n onTerminated: vi.fn(),\n });\n });\n\n afterEach(() => {\n vi.useRealTimers();\n vi.restoreAllMocks();\n });\n\n describe(\"Send APDUs\", () => {\n it(\"should send APDU successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should send several APDUs successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu);\n const result2 = await machine.sendApdu(apdu2);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should not send several APDUs in parallel\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu);\n const result2 = await machine.sendApdu(apdu2);\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Left(new AlreadySendingApduError()));\n });\n\n it(\"Detached while sending APDU\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu);\n machine.eventDeviceDetached();\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(\n Left(new DeviceDisconnectedWhileSendingError()),\n );\n });\n\n it(\"Disconnected while sending APDU\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu);\n machine.closeConnection();\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(\n Left(new DeviceDisconnectedWhileSendingError()),\n );\n });\n });\n\n describe(\"Send APDUs triggering disconnection\", () => {\n it(\"should send one APDU successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu, true);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should send several APDUs successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu, true);\n const promise = machine.sendApdu(apdu2);\n machine.eventDeviceDetached();\n machine.eventDeviceAttached();\n const result2 = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should send a second APDU after reconnection\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu, true);\n machine.eventDeviceDetached();\n machine.eventDeviceAttached();\n const result2 = await machine.sendApdu(apdu2);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should not send several APDUs in parallel\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu, true);\n const result2 = await machine.sendApdu(apdu2);\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Left(new AlreadySendingApduError()));\n });\n\n it(\"should send another APDU in promise handler\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n let promise: Promise<SendApduResult> | undefined = undefined;\n const result = await machine.sendApdu(apdu, true).then((value) => {\n promise = machine.sendApdu(apdu2);\n return value;\n });\n machine.eventDeviceDetached();\n machine.eventDeviceAttached();\n const result2 = await promise!;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"send an APDU while device is reconnecting\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n machine.eventDeviceDetached();\n const promise = machine.sendApdu(apdu, true);\n machine.eventDeviceAttached();\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n });\n\n it(\"Close while an APDU is waiting for reconnection\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n let promise: Promise<SendApduResult> | undefined = undefined;\n const result = await machine.sendApdu(apdu, true);\n promise = machine.sendApdu(apdu2);\n machine.closeConnection();\n const result2 = await promise!;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(\n Left(new DeviceDisconnectedWhileSendingError()),\n );\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAA4B,4BAC5BC,EAAgE,kBAEh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M,EAAI,EAC3CF,EAAQ,oBAAoB,EAC5B,MAAMI,EAAS,MAAMG,KAGrB,UAAON,EAAe,QAAQ,EAAE,sBAAsB,CAAC,KACvD,UAAOG,CAAM,EAAE,iBAAc,SAAMD,CAAY,CAAC,CAClD,CAAC,KAED,MAAG,kDAAmD,SAAY,CAEhE,MAAMD,EAAO,WAAW,KAAK,CAAC,EAAG,EAAG,EAAG,CAAC,CAAC,EACnCG,EAAQ,WAAW,KAAK,CAAC,EAAG,EAAG,EAAG,CAAC,CAAC,EACpCF,EAAe,IAAI,eAAa,CACpC,WAAY,WAAW,KAAK,CAAC,IAAM,CAAI,CAAC,EACxC,KAAM,IAAI,UACZ,CAAC,EACDF,EAAe,SAAS,qBAAkB,SAAME,CAAY,CAAC,EAG7D,IAAII,EACJ,MAAMH,EAAS,MAAMJ,EAAQ,SAASE,EAAM,EAAI,EAChDK,EAAUP,EAAQ,SAASK,CAAK,EAChCL,EAAQ,gBAAgB,EACxB,MAAMM,EAAU,MAAMC,KAGtB,UAAON,EAAe,QAAQ,EAAE,sBAAsB,CAAC,KACvD,UAAOG,CAAM,EAAE,iBAAc,SAAMD,CAAY,CAAC,KAChD,UAAOG,CAAO,EAAE,iBACd,QAAK,IAAI,qCAAqC,CAChD,CACF,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["import_Either", "import_vitest", "import_ApduResponse", "import_DeviceConnectionStateMachine", "import_Errors", "machine", "mockApduSender", "apdu", "apduResponse", "result", "apdu2", "result2", "promise", "value"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{Left as A,Right as a}from"purify-ts/Either";import{afterEach as v,beforeEach as w,describe as m,expect as n,it as i,vi as p}from"vitest";import{ApduResponse as c}from"../../device-session/ApduResponse";import{DeviceConnectionStateMachine as D}from"./DeviceConnectionStateMachine";import{AlreadySendingApduError as U,DeviceDisconnectedWhileSendingError as y}from"./Errors";m("DeviceConnectionStateMachine",()=>{let t;const o={sendApdu:p.fn(),getDependencies:p.fn(),setDependencies:p.fn(),closeConnection:p.fn(),setupConnection:p.fn()};w(()=>{p.useFakeTimers(),t=new D({deviceId:"deviceId",deviceApduSender:o,timeoutDuration:1e3,onTerminated:p.fn()})}),v(()=>{p.useRealTimers(),p.restoreAllMocks()}),m("Send APDUs",()=>{i("should send APDU successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),s=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(s));const e=await t.sendApdu(d);n(o.sendApdu).toHaveBeenCalledTimes(1),n(e).toStrictEqual(a(s))}),i("should send several APDUs successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));const r=await t.sendApdu(d),u=await t.sendApdu(s);n(o.sendApdu).toHaveBeenCalledTimes(2),n(r).toStrictEqual(a(e)),n(u).toStrictEqual(a(e))}),i("should not send several APDUs in parallel",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));const r=t.sendApdu(d),u=await t.sendApdu(s),l=await r;n(o.sendApdu).toHaveBeenCalledTimes(1),n(l).toStrictEqual(a(e)),n(u).toStrictEqual(A(new U))}),i("Detached while sending APDU",async()=>{const d=Uint8Array.from([1,2,3,4]),s=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(s));const e=t.sendApdu(d);t.eventDeviceDetached();const r=await e;n(o.sendApdu).toHaveBeenCalledTimes(1),n(r).toStrictEqual(A(new y))}),i("Disconnected while sending APDU",async()=>{const d=Uint8Array.from([1,2,3,4]),s=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(s));const e=t.sendApdu(d);t.closeConnection();const r=await e;n(o.sendApdu).toHaveBeenCalledTimes(1),n(r).toStrictEqual(A(new y))})}),m("Send APDUs triggering disconnection",()=>{i("should send one APDU successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),s=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(s));const e=await t.sendApdu(d,!0);n(o.sendApdu).toHaveBeenCalledTimes(1),n(e).toStrictEqual(a(s))}),i("should send several APDUs successfully",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));const r=await t.sendApdu(d,!0),u=t.sendApdu(s);t.eventDeviceDetached(),t.eventDeviceAttached();const l=await u;n(o.sendApdu).toHaveBeenCalledTimes(2),n(r).toStrictEqual(a(e)),n(l).toStrictEqual(a(e))}),i("should send a second APDU after reconnection",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));const r=await t.sendApdu(d,!0);t.eventDeviceDetached(),t.eventDeviceAttached();const u=await t.sendApdu(s);n(o.sendApdu).toHaveBeenCalledTimes(2),n(r).toStrictEqual(a(e)),n(u).toStrictEqual(a(e))}),i("should not send several APDUs in parallel",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));const r=t.sendApdu(d,!0),u=await t.sendApdu(s),l=await r;n(o.sendApdu).toHaveBeenCalledTimes(1),n(l).toStrictEqual(a(e)),n(u).toStrictEqual(A(new U))}),i("should send another APDU in promise handler",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));let r;const u=await t.sendApdu(d,!0).then(f=>(r=t.sendApdu(s),f));t.eventDeviceDetached(),t.eventDeviceAttached();const l=await r;n(o.sendApdu).toHaveBeenCalledTimes(2),n(u).toStrictEqual(a(e)),n(l).toStrictEqual(a(e))}),i("send an APDU while device is reconnecting",async()=>{const d=Uint8Array.from([1,2,3,4]),s=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(s)),t.eventDeviceDetached();const e=t.sendApdu(d,!0);t.eventDeviceAttached();const r=await e;n(o.sendApdu).toHaveBeenCalledTimes(1),n(r).toStrictEqual(a(s))}),i("Close while an APDU is waiting for reconnection",async()=>{const d=Uint8Array.from([1,2,3,4]),s=Uint8Array.from([9,2,3,4]),e=new c({statusCode:Uint8Array.from([144,0]),data:new Uint8Array});o.sendApdu.mockResolvedValue(a(e));let r;const u=await t.sendApdu(d,!0);r=t.sendApdu(s),t.closeConnection();const l=await r;n(o.sendApdu).toHaveBeenCalledTimes(1),n(u).toStrictEqual(a(e)),n(l).toStrictEqual(A(new y))})})});
2
+ //# sourceMappingURL=DeviceConnectionStateMachine.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/api/transport/model/DeviceConnectionStateMachine.test.ts"],
4
+ "sourcesContent": ["import { Left, Right } from \"purify-ts/Either\";\nimport { afterEach, beforeEach, describe, expect, it, vi } from \"vitest\";\n\nimport { ApduResponse } from \"@api/device-session/ApduResponse\";\n\nimport { type SendApduResult } from \"./DeviceConnection\";\nimport { DeviceConnectionStateMachine } from \"./DeviceConnectionStateMachine\";\nimport {\n AlreadySendingApduError,\n DeviceDisconnectedWhileSendingError,\n} from \"./Errors\";\n\ndescribe(\"DeviceConnectionStateMachine\", () => {\n let machine: DeviceConnectionStateMachine<void>;\n const mockApduSender = {\n sendApdu: vi.fn(),\n getDependencies: vi.fn(),\n setDependencies: vi.fn(),\n closeConnection: vi.fn(),\n setupConnection: vi.fn(),\n };\n\n beforeEach(() => {\n vi.useFakeTimers();\n machine = new DeviceConnectionStateMachine({\n deviceId: \"deviceId\",\n deviceApduSender: mockApduSender,\n timeoutDuration: 1000,\n onTerminated: vi.fn(),\n });\n });\n\n afterEach(() => {\n vi.useRealTimers();\n vi.restoreAllMocks();\n });\n\n describe(\"Send APDUs\", () => {\n it(\"should send APDU successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should send several APDUs successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu);\n const result2 = await machine.sendApdu(apdu2);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should not send several APDUs in parallel\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu);\n const result2 = await machine.sendApdu(apdu2);\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Left(new AlreadySendingApduError()));\n });\n\n it(\"Detached while sending APDU\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu);\n machine.eventDeviceDetached();\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(\n Left(new DeviceDisconnectedWhileSendingError()),\n );\n });\n\n it(\"Disconnected while sending APDU\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu);\n machine.closeConnection();\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(\n Left(new DeviceDisconnectedWhileSendingError()),\n );\n });\n });\n\n describe(\"Send APDUs triggering disconnection\", () => {\n it(\"should send one APDU successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu, true);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should send several APDUs successfully\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu, true);\n const promise = machine.sendApdu(apdu2);\n machine.eventDeviceDetached();\n machine.eventDeviceAttached();\n const result2 = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should send a second APDU after reconnection\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const result = await machine.sendApdu(apdu, true);\n machine.eventDeviceDetached();\n machine.eventDeviceAttached();\n const result2 = await machine.sendApdu(apdu2);\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"should not send several APDUs in parallel\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n const promise = machine.sendApdu(apdu, true);\n const result2 = await machine.sendApdu(apdu2);\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Left(new AlreadySendingApduError()));\n });\n\n it(\"should send another APDU in promise handler\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n let promise: Promise<SendApduResult> | undefined = undefined;\n const result = await machine.sendApdu(apdu, true).then((value) => {\n promise = machine.sendApdu(apdu2);\n return value;\n });\n machine.eventDeviceDetached();\n machine.eventDeviceAttached();\n const result2 = await promise!;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(2);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(Right(apduResponse));\n });\n\n it(\"send an APDU while device is reconnecting\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n machine.eventDeviceDetached();\n const promise = machine.sendApdu(apdu, true);\n machine.eventDeviceAttached();\n const result = await promise;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n });\n\n it(\"Close while an APDU is waiting for reconnection\", async () => {\n // GIVEN\n const apdu = Uint8Array.from([1, 2, 3, 4]);\n const apdu2 = Uint8Array.from([9, 2, 3, 4]);\n const apduResponse = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: new Uint8Array(),\n });\n mockApduSender.sendApdu.mockResolvedValue(Right(apduResponse));\n\n // WHEN\n let promise: Promise<SendApduResult> | undefined = undefined;\n const result = await machine.sendApdu(apdu, true);\n promise = machine.sendApdu(apdu2);\n machine.closeConnection();\n const result2 = await promise!;\n\n // THEN\n expect(mockApduSender.sendApdu).toHaveBeenCalledTimes(1);\n expect(result).toStrictEqual(Right(apduResponse));\n expect(result2).toStrictEqual(\n Left(new DeviceDisconnectedWhileSendingError()),\n );\n });\n });\n});\n"],
5
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foreEach", "describe", "expect", "it", "vi", "ApduResponse", "DeviceConnectionStateMachine", "AlreadySendingApduError", "DeviceDisconnectedWhileSendingError", "machine", "mockApduSender", "apdu", "apduResponse", "result", "apdu2", "result2", "promise", "value"]
7
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=DeviceConnectionStateMachine.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeviceConnectionStateMachine.test.d.ts","sourceRoot":"","sources":["../../../../../../src/api/transport/model/DeviceConnectionStateMachine.test.ts"],"names":[],"mappings":""}