@ledgerhq/device-transport-kit-react-native-hid 0.0.0-rn-hid-issues-20251023081020 → 0.0.0-rn-hid-issues-20251023141003

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.
@@ -43,6 +43,7 @@ import kotlinx.coroutines.flow.shareIn
43
43
  import kotlinx.coroutines.isActive
44
44
  import kotlinx.coroutines.launch
45
45
  import kotlin.time.Duration
46
+ import kotlin.time.Duration.Companion.milliseconds
46
47
  import kotlin.time.Duration.Companion.seconds
47
48
 
48
49
  private val TAG = "DefaultAndroidUsbTransport"
@@ -196,6 +197,7 @@ internal class DefaultAndroidUsbTransport(
196
197
  request = UsbRequest(),
197
198
  loggerService = loggerService
198
199
  )
200
+ delay(POST_CONNECTION_DELAY)
199
201
 
200
202
  if (!usbConnectionsPendingReconnection.contains(deviceConnection)) {
201
203
  /**
@@ -330,6 +332,7 @@ internal class DefaultAndroidUsbTransport(
330
332
  request = UsbRequest(),
331
333
  loggerService = loggerService,
332
334
  )
335
+ delay(POST_CONNECTION_DELAY)
333
336
 
334
337
  val deviceConnection = DeviceConnection(
335
338
  sessionId = sessionId,
@@ -372,6 +375,8 @@ internal class DefaultAndroidUsbTransport(
372
375
  private fun generateSessionId(usbDevice: UsbDevice): String = "usb_${usbDevice.deviceId}"
373
376
  }
374
377
 
378
+ private val POST_CONNECTION_DELAY = 200.milliseconds
379
+
375
380
  private fun List<LedgerUsbDevice>.toScannedDevices(): List<DiscoveryDevice> =
376
381
  this.map {
377
382
  it.toScannedDevice()
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("@ledgerhq/device-management-kit"),a=require("purify-ts"),d=require("../transport/Errors"),c=require("../transport/rnHidTransportIdentifier"),o=require("./mapper");describe("mapper",()=>{const n=new e.StaticDeviceModelDataSource;describe("mapNativeLedgerDeviceToDeviceModel",()=>{[{nativeLedgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceModel:n.getDeviceModel({id:e.DeviceModelId.NANO_S})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x40"},deviceModel:n.getDeviceModel({id:e.DeviceModelId.NANO_X})},{nativeLedgerDevice:{name:"NanoSPlus",usbProductIdMask:"0x50"},deviceModel:n.getDeviceModel({id:e.DeviceModelId.NANO_SP})},{nativeLedgerDevice:{name:"Stax",usbProductIdMask:"0x60"},deviceModel:n.getDeviceModel({id:e.DeviceModelId.STAX})},{nativeLedgerDevice:{name:"Flex",usbProductIdMask:"0x70"},deviceModel:n.getDeviceModel({id:e.DeviceModelId.FLEX})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceModel:null}].forEach(({nativeLedgerDevice:t,deviceModel:i})=>{it(`should map USB device with usbProductIdMask ${t.usbProductIdMask} to ${i?.productName??"null"}`,()=>{expect((0,o.mapNativeLedgerDeviceToDeviceModel)(t,n)).toEqual(i)})})}),describe("mapNativeDiscoveryDeviceToTransportDiscoveredDevice",()=>{it("should map NativeDiscoveryDevice to TransportDiscoveredDevice",()=>{const s={name:"NanoS",uid:"abcd",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"}},t={id:"abcd",deviceModel:n.getDeviceModel({id:e.DeviceModelId.NANO_S}),transport:c.TRANSPORT_IDENTIFIER,name:"NanoS"};expect((0,o.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,n)).toEqual(t)}),it("should return null if the device model is not recognized",()=>{const s={name:"NanoX",uid:"efgh",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x4567890"}};expect((0,o.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,n)).toEqual(null)})}),describe("mapNativeTransportLogToLog",()=>{[{nativeLog:{level:"debug",tag:"tag",message:"debug message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Debug,"debug message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"info",tag:"tag",message:"info message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Info,"info message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"error",tag:"tag",message:"error message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Error,"error message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"warning",tag:"tag",message:"warning message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Warning,"warning message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]}].forEach(({nativeLog:t,log:i})=>{it(`should map NativeLog with level "${t.level}" to Log`,()=>{expect((0,o.mapNativeTransportLogToLog)(t)).toEqual(i)})})}),describe("mapNativeConnectionResultToConnectionResult",()=>{[{testTitle:"Success",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceName:"NanoS"},connectionResult:(0,a.Right)({sessionId:"1234",transportDeviceModel:n.getDeviceModel({id:e.DeviceModelId.NANO_S})})},{testTitle:"Failure",nativeConnectionResult:{success:!1,error:"error message"},connectionResult:(0,a.Left)(new e.OpeningConnectionError("error message"))},{testTitle:"Unknown device model",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceName:"NanoX"},connectionResult:(0,a.Left)(new e.OpeningConnectionError("Could not find device model for the connected device with usbProductIdMask: 0x12345678"))}].forEach(({testTitle:t,nativeConnectionResult:i,connectionResult:r})=>{it(t,()=>{expect((0,o.mapNativeConnectionResultToConnectionResult)(i,n)).toEqual(r)})})}),describe("mapNativeSendApduResultToSendApduResult",()=>{test("success",()=>{const t={success:!0,apdu:"AQIDkAA="},i=(0,a.Right)(new e.ApduResponse({data:new Uint8Array([1,2,3]),statusCode:new Uint8Array([144,0])}));expect((0,o.mapNativeSendApduResultToSendApduResult)(t)).toEqual(i)}),test("failure",()=>{const s={success:!1,error:"error message"},t=(0,a.Left)(new d.HidTransportSendApduUnknownError("error message"));expect((0,o.mapNativeSendApduResultToSendApduResult)(s)).toEqual(t)}),test("timeout error",()=>{const s={success:!1,error:"SendApduTimeout"},t=(0,a.Left)(new e.SendApduTimeoutError("Abort timeout"));expect((0,o.mapNativeSendApduResultToSendApduResult)(s)).toEqual(t)}),test("empty response error",()=>{const s={success:!1,error:"EmptyResponse"},t=(0,a.Left)(new e.SendApduEmptyResponseError("Empty response"));expect((0,o.mapNativeSendApduResultToSendApduResult)(s)).toEqual(t)})}),describe("mapNativeDeviceConnectionLostToDeviceDisconnected",()=>{it("should map NativeDeviceConnectionLost to DeviceDisconnected",()=>{const s={id:"1234"},t={sessionId:"1234"};expect((0,o.mapNativeDeviceConnectionLostToDeviceDisconnected)(s)).toEqual(t)})})});
1
+ "use strict";var e=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),d=require("../transport/Errors"),c=require("../transport/rnHidTransportIdentifier"),s=require("./mapper");describe("mapper",()=>{const a=new e.StaticDeviceModelDataSource;describe("mapNativeLedgerDeviceToDeviceModel",()=>{[{nativeLedgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_S})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x40"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_X})},{nativeLedgerDevice:{name:"NanoSPlus",usbProductIdMask:"0x50"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_SP})},{nativeLedgerDevice:{name:"Stax",usbProductIdMask:"0x60"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.STAX})},{nativeLedgerDevice:{name:"Flex",usbProductIdMask:"0x70"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.FLEX})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceModel:null}].forEach(({nativeLedgerDevice:t,deviceModel:i})=>{it(`should map USB device with usbProductIdMask ${t.usbProductIdMask} to ${i?.productName??"null"}`,()=>{expect((0,s.mapNativeLedgerDeviceToDeviceModel)(t,a)).toEqual(i)})})}),describe("mapNativeDiscoveryDeviceToTransportDiscoveredDevice",()=>{it("should map NativeDiscoveryDevice to TransportDiscoveredDevice",()=>{const o={name:"NanoS",uid:"abcd",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"}},t={id:"abcd",deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_S}),transport:c.TRANSPORT_IDENTIFIER,name:"NanoS"};expect((0,s.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(o,a)).toEqual(t)}),it("should return null if the device model is not recognized",()=>{const o={name:"NanoX",uid:"efgh",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x4567890"}};expect((0,s.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(o,a)).toEqual(null)})}),describe("mapNativeTransportLogToLog",()=>{[{nativeLog:{level:"debug",tag:"tag",message:"debug message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Debug,"debug message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"info",tag:"tag",message:"info message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Info,"info message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"error",tag:"tag",message:"error message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Error,"error message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"warning",tag:"tag",message:"warning message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Warning,"warning message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]}].forEach(({nativeLog:t,log:i})=>{it(`should map NativeLog with level "${t.level}" to Log`,()=>{expect((0,s.mapNativeTransportLogToLog)(t)).toEqual(i)})})}),describe("mapNativeConnectionResultToConnectionResult",()=>{[{testTitle:"Success",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceName:"NanoS"},connectionResult:(0,n.Right)({sessionId:"1234",transportDeviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_S})})},{testTitle:"Failure",nativeConnectionResult:{success:!1,error:"error message"},connectionResult:(0,n.Left)(new e.OpeningConnectionError("error message"))},{testTitle:"Unknown device model",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceName:"NanoX"},connectionResult:(0,n.Left)(new e.OpeningConnectionError("Could not find device model for the connected device with usbProductIdMask: 0x12345678"))}].forEach(({testTitle:t,nativeConnectionResult:i,connectionResult:r})=>{it(t,()=>{expect((0,s.mapNativeConnectionResultToConnectionResult)(i,a)).toEqual(r)})})}),describe("mapNativeSendApduResultToSendApduResult",()=>{test("success",()=>{const t={success:!0,apdu:"AQIDkAA="},i=(0,n.Right)(new e.ApduResponse({data:new Uint8Array([1,2,3]),statusCode:new Uint8Array([144,0])}));expect((0,s.mapNativeSendApduResultToSendApduResult)(t)).toEqual(i)}),test("failure",()=>{const o={success:!1,error:"error message"},t=(0,n.Left)(new d.HidTransportSendApduUnknownError("error message"));expect((0,s.mapNativeSendApduResultToSendApduResult)(o)).toEqual(t)}),test("timeout error",()=>{const o={success:!1,error:"SendApduTimeout"},t=(0,n.Left)(new e.SendApduTimeoutError("Abort timeout"));expect((0,s.mapNativeSendApduResultToSendApduResult)(o)).toEqual(t)}),test("empty response error",()=>{const o={success:!1,error:"EmptyResponse"},t=(0,n.Left)(new e.SendApduEmptyResponseError("Empty response"));expect((0,s.mapNativeSendApduResultToSendApduResult)(o)).toEqual(t)}),test("device not found error",()=>{const o={success:!1,error:"DeviceNotFound"},t=(0,n.Left)(new e.DeviceDisconnectedBeforeSendingApdu);expect((0,s.mapNativeSendApduResultToSendApduResult)(o)).toEqual(t)}),test("no usb endpoint found error",()=>{const o={success:!1,error:"NoUsbEndpointFound"},t=(0,n.Left)(new e.DeviceDisconnectedBeforeSendingApdu);expect((0,s.mapNativeSendApduResultToSendApduResult)(o)).toEqual(t)}),test("unknown error",()=>{const o={success:!1,error:"unknown error"},t=(0,n.Left)(new d.HidTransportSendApduUnknownError("unknown error"));expect((0,s.mapNativeSendApduResultToSendApduResult)(o)).toEqual(t)})}),describe("mapNativeDeviceConnectionLostToDeviceDisconnected",()=>{it("should map NativeDeviceConnectionLost to DeviceDisconnected",()=>{const o={id:"1234"},t={sessionId:"1234"};expect((0,s.mapNativeDeviceConnectionLostToDeviceDisconnected)(o)).toEqual(t)})})});
2
2
  //# sourceMappingURL=mapper.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/bridge/mapper.test.ts"],
4
- "sourcesContent": ["import {\n ApduResponse,\n DeviceModelId,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport { type InternalConnectionResult } from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeLedgerDeviceToDeviceModel,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\ndescribe(\"mapper\", () => {\n const deviceModelDataSource = new StaticDeviceModelDataSource();\n\n describe(\"mapNativeLedgerDeviceToDeviceModel\", () => {\n const testCases: Array<{\n nativeLedgerDevice: NativeLedgerDevice;\n deviceModel: TransportDeviceModel | null;\n }> = [\n {\n nativeLedgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x40\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoSPlus\",\n usbProductIdMask: \"0x50\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Stax\",\n usbProductIdMask: \"0x60\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Flex\",\n usbProductIdMask: \"0x70\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceModel: null, // because the usbProductIdMask is not recognized\n },\n ];\n testCases.forEach(({ nativeLedgerDevice, deviceModel }) => {\n it(`should map USB device with usbProductIdMask ${nativeLedgerDevice.usbProductIdMask} to ${\n deviceModel?.productName ?? \"null\"\n }`, () => {\n expect(\n mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice,\n deviceModelDataSource,\n ),\n ).toEqual(deviceModel);\n });\n });\n });\n\n describe(\"mapNativeDiscoveryDeviceToTransportDiscoveredDevice\", () => {\n it(\"should map NativeDiscoveryDevice to TransportDiscoveredDevice\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoS\",\n uid: \"abcd\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n };\n const expectedDiscoveredDevice: TransportDiscoveredDevice = {\n id: \"abcd\",\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n transport: TRANSPORT_IDENTIFIER,\n name: \"NanoS\",\n };\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n\n it(\"should return null if the device model is not recognized\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoX\",\n uid: \"efgh\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x4567890\", // some invalid value\n },\n };\n const expectedDiscoveredDevice = null; // because the usbProductIdMask is not recognized\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n });\n\n describe(\"mapNativeTransportLogToLog\", () => {\n const testCases: Array<{\n nativeLog: NativeLog;\n log: LogParams;\n }> = [\n {\n // debug\n nativeLog: {\n level: \"debug\",\n tag: \"tag\",\n message: \"debug message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Debug,\n \"debug message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // info\n {\n nativeLog: {\n level: \"info\",\n tag: \"tag\",\n message: \"info message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Info,\n \"info message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // error\n {\n nativeLog: {\n level: \"error\",\n tag: \"tag\",\n message: \"error message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Error,\n \"error message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // warning\n {\n nativeLog: {\n level: \"warning\",\n tag: \"tag\",\n message: \"warning message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Warning,\n \"warning message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n ];\n\n testCases.forEach(({ nativeLog, log }) => {\n it(`should map NativeLog with level \"${nativeLog.level}\" to Log`, () => {\n expect(mapNativeTransportLogToLog(nativeLog)).toEqual(log);\n });\n });\n });\n\n describe(\"mapNativeConnectionResultToConnectionResult\", () => {\n const testCases: Array<{\n nativeConnectionResult: NativeInternalConnectionResult;\n connectionResult: InternalConnectionResult;\n testTitle: string;\n }> = [\n {\n testTitle: \"Success\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceName: \"NanoS\",\n },\n connectionResult: Right({\n sessionId: \"1234\",\n transportDeviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n }),\n },\n {\n testTitle: \"Failure\",\n nativeConnectionResult: {\n success: false,\n error: \"error message\",\n },\n connectionResult: Left(new OpeningConnectionError(\"error message\")),\n },\n {\n testTitle: \"Unknown device model\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceName: \"NanoX\",\n },\n connectionResult: Left(\n new OpeningConnectionError(\n \"Could not find device model for the connected device with usbProductIdMask: 0x12345678\",\n ),\n ),\n },\n ];\n\n testCases.forEach(\n ({ testTitle, nativeConnectionResult, connectionResult }) => {\n it(testTitle, () => {\n expect(\n mapNativeConnectionResultToConnectionResult(\n nativeConnectionResult,\n deviceModelDataSource,\n ),\n ).toEqual(connectionResult);\n });\n },\n );\n });\n\n describe(\"mapNativeSendApduResultToSendApduResult\", () => {\n test(\"success\", () => {\n const resultApduString = \"AQIDkAA=\";\n const nativeSendApduResult: NativeSendApduResult = {\n success: true,\n apdu: resultApduString,\n };\n const expectedSendApduResult: SendApduResult = Right(\n new ApduResponse({\n data: new Uint8Array([0x01, 0x02, 0x03]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"failure\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"error message\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"error message\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"timeout error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"SendApduTimeout\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduTimeoutError(\"Abort timeout\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"empty response error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"EmptyResponse\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduEmptyResponseError(\"Empty response\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n });\n\n describe(\"mapNativeDeviceConnectionLostToDeviceDisconnected\", () => {\n it(\"should map NativeDeviceConnectionLost to DeviceDisconnected\", () => {\n const nativeDeviceConnectionLost = {\n id: \"1234\",\n };\n const expectedDeviceDisconnected = {\n sessionId: \"1234\",\n };\n expect(\n mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost,\n ),\n ).toEqual(expectedDeviceDisconnected);\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAYO,2CACPC,EAA4B,qBAE5BC,EAAiD,iCACjDC,EAAqC,mDAGrCC,EAOO,oBASP,SAAS,SAAU,IAAM,CACvB,MAAMC,EAAwB,IAAI,8BAElC,SAAS,qCAAsC,IAAM,CAI9C,CACH,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,MACpB,EACA,YAAaA,EAAsB,eAAe,CAChD,GAAI,gBA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BAAwB,IAAM,CACjC,MAAMD,EAA6C,CACjD,QAAS,GACT,MAAO,eACT,EACMC,KAAyC,QAC7C,IAAI,6BAA2B,gBAAgB,CACjD,EACA,UACE,2CAAwCD,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,CACH,CAAC,EAED,SAAS,oDAAqD,IAAM,CAClE,GAAG,8DAA+D,IAAM,CACtE,MAAMC,EAA6B,CACjC,GAAI,MACN,EACMC,EAA6B,CACjC,UAAW,MACb,EACA,UACE,qDACED,CACF,CACF,EAAE,QAAQC,CAA0B,CACtC,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n ApduResponse,\n DeviceDisconnectedBeforeSendingApdu,\n DeviceModelId,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport { type InternalConnectionResult } from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeLedgerDeviceToDeviceModel,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\ndescribe(\"mapper\", () => {\n const deviceModelDataSource = new StaticDeviceModelDataSource();\n\n describe(\"mapNativeLedgerDeviceToDeviceModel\", () => {\n const testCases: Array<{\n nativeLedgerDevice: NativeLedgerDevice;\n deviceModel: TransportDeviceModel | null;\n }> = [\n {\n nativeLedgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x40\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoSPlus\",\n usbProductIdMask: \"0x50\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Stax\",\n usbProductIdMask: \"0x60\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Flex\",\n usbProductIdMask: \"0x70\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceModel: null, // because the usbProductIdMask is not recognized\n },\n ];\n testCases.forEach(({ nativeLedgerDevice, deviceModel }) => {\n it(`should map USB device with usbProductIdMask ${nativeLedgerDevice.usbProductIdMask} to ${\n deviceModel?.productName ?? \"null\"\n }`, () => {\n expect(\n mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice,\n deviceModelDataSource,\n ),\n ).toEqual(deviceModel);\n });\n });\n });\n\n describe(\"mapNativeDiscoveryDeviceToTransportDiscoveredDevice\", () => {\n it(\"should map NativeDiscoveryDevice to TransportDiscoveredDevice\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoS\",\n uid: \"abcd\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n };\n const expectedDiscoveredDevice: TransportDiscoveredDevice = {\n id: \"abcd\",\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n transport: TRANSPORT_IDENTIFIER,\n name: \"NanoS\",\n };\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n\n it(\"should return null if the device model is not recognized\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoX\",\n uid: \"efgh\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x4567890\", // some invalid value\n },\n };\n const expectedDiscoveredDevice = null; // because the usbProductIdMask is not recognized\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n });\n\n describe(\"mapNativeTransportLogToLog\", () => {\n const testCases: Array<{\n nativeLog: NativeLog;\n log: LogParams;\n }> = [\n {\n // debug\n nativeLog: {\n level: \"debug\",\n tag: \"tag\",\n message: \"debug message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Debug,\n \"debug message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // info\n {\n nativeLog: {\n level: \"info\",\n tag: \"tag\",\n message: \"info message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Info,\n \"info message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // error\n {\n nativeLog: {\n level: \"error\",\n tag: \"tag\",\n message: \"error message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Error,\n \"error message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // warning\n {\n nativeLog: {\n level: \"warning\",\n tag: \"tag\",\n message: \"warning message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Warning,\n \"warning message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n ];\n\n testCases.forEach(({ nativeLog, log }) => {\n it(`should map NativeLog with level \"${nativeLog.level}\" to Log`, () => {\n expect(mapNativeTransportLogToLog(nativeLog)).toEqual(log);\n });\n });\n });\n\n describe(\"mapNativeConnectionResultToConnectionResult\", () => {\n const testCases: Array<{\n nativeConnectionResult: NativeInternalConnectionResult;\n connectionResult: InternalConnectionResult;\n testTitle: string;\n }> = [\n {\n testTitle: \"Success\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceName: \"NanoS\",\n },\n connectionResult: Right({\n sessionId: \"1234\",\n transportDeviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n }),\n },\n {\n testTitle: \"Failure\",\n nativeConnectionResult: {\n success: false,\n error: \"error message\",\n },\n connectionResult: Left(new OpeningConnectionError(\"error message\")),\n },\n {\n testTitle: \"Unknown device model\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceName: \"NanoX\",\n },\n connectionResult: Left(\n new OpeningConnectionError(\n \"Could not find device model for the connected device with usbProductIdMask: 0x12345678\",\n ),\n ),\n },\n ];\n\n testCases.forEach(\n ({ testTitle, nativeConnectionResult, connectionResult }) => {\n it(testTitle, () => {\n expect(\n mapNativeConnectionResultToConnectionResult(\n nativeConnectionResult,\n deviceModelDataSource,\n ),\n ).toEqual(connectionResult);\n });\n },\n );\n });\n\n describe(\"mapNativeSendApduResultToSendApduResult\", () => {\n test(\"success\", () => {\n const resultApduString = \"AQIDkAA=\";\n const nativeSendApduResult: NativeSendApduResult = {\n success: true,\n apdu: resultApduString,\n };\n const expectedSendApduResult: SendApduResult = Right(\n new ApduResponse({\n data: new Uint8Array([0x01, 0x02, 0x03]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"failure\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"error message\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"error message\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"timeout error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"SendApduTimeout\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduTimeoutError(\"Abort timeout\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"empty response error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"EmptyResponse\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduEmptyResponseError(\"Empty response\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"device not found error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"DeviceNotFound\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new DeviceDisconnectedBeforeSendingApdu(),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"no usb endpoint found error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"NoUsbEndpointFound\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new DeviceDisconnectedBeforeSendingApdu(),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"unknown error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"unknown error\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"unknown error\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n });\n\n describe(\"mapNativeDeviceConnectionLostToDeviceDisconnected\", () => {\n it(\"should map NativeDeviceConnectionLost to DeviceDisconnected\", () => {\n const nativeDeviceConnectionLost = {\n id: \"1234\",\n };\n const expectedDeviceDisconnected = {\n sessionId: \"1234\",\n };\n expect(\n mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost,\n ),\n ).toEqual(expectedDeviceDisconnected);\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAaO,2CACPC,EAA4B,qBAE5BC,EAAiD,iCACjDC,EAAqC,mDAGrCC,EAOO,oBASP,SAAS,SAAU,IAAM,CACvB,MAAMC,EAAwB,IAAI,8BAElC,SAAS,qCAAsC,IAAM,CAI9C,CACH,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,MACpB,EACA,YAAaA,EAAsB,eAAe,CAChD,GAAI,gBAAc,MACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,MACpB,EACA,YAAaA,EAAsB,eAAe,CAChD,GAAI,gBAAc,MACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,YACN,iBAAkB,MACpB,EACA,YAAaA,EAAsB,eAAe,CAChD,GAAI,gBAAc,OACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,OACN,iBAAkB,MACpB,EACA,YAAaA,EAAsB,eAAe,CAChD,GAAI,gBAAc,IACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,OACN,iBAAkB,MACpB,EACA,YAAaA,EAAsB,eAAe,CAChD,GAAI,gBAAc,IACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,YACpB,EACA,YAAa,IACf,CACF,EACU,QA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B,IAAM,CAC1B,MAAMD,EAA6C,CACjD,QAAS,GACT,MAAO,eACT,EACMC,KAAyC,QAC7C,IAAI,mCAAiC,eAAe,CACtD,EACA,UACE,2CAAwCD,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,CACH,CAAC,EAED,SAAS,oDAAqD,IAAM,CAClE,GAAG,8DAA+D,IAAM,CACtE,MAAMC,EAA6B,CACjC,GAAI,MACN,EACMC,EAA6B,CACjC,UAAW,MACb,EACA,UACE,qDACED,CACF,CACF,EAAE,QAAQC,CAA0B,CACtC,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_purify_ts", "import_Errors", "import_rnHidTransportIdentifier", "import_mapper", "deviceModelDataSource", "nativeLedgerDevice", "deviceModel", "nativeDevice", "expectedDiscoveredDevice", "nativeLog", "log", "testTitle", "nativeConnectionResult", "connectionResult", "nativeSendApduResult", "expectedSendApduResult", "nativeDeviceConnectionLost", "expectedDeviceDisconnected"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{ApduResponse as l,DeviceModelId as n,LogLevel as i,OpeningConnectionError as c,SendApduEmptyResponseError as p,SendApduTimeoutError as m,StaticDeviceModelDataSource as g}from"@ledgerhq/device-management-kit";import{Left as a,Right as r}from"purify-ts";import{HidTransportSendApduUnknownError as D}from"../transport/Errors";import{TRANSPORT_IDENTIFIER as N}from"../transport/rnHidTransportIdentifier";import{mapNativeConnectionResultToConnectionResult as S,mapNativeDeviceConnectionLostToDeviceDisconnected as A,mapNativeDiscoveryDeviceToTransportDiscoveredDevice as u,mapNativeLedgerDeviceToDeviceModel as R,mapNativeSendApduResultToSendApduResult as d,mapNativeTransportLogToLog as y}from"./mapper";describe("mapper",()=>{const o=new g;describe("mapNativeLedgerDeviceToDeviceModel",()=>{[{nativeLedgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceModel:o.getDeviceModel({id:n.NANO_S})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x40"},deviceModel:o.getDeviceModel({id:n.NANO_X})},{nativeLedgerDevice:{name:"NanoSPlus",usbProductIdMask:"0x50"},deviceModel:o.getDeviceModel({id:n.NANO_SP})},{nativeLedgerDevice:{name:"Stax",usbProductIdMask:"0x60"},deviceModel:o.getDeviceModel({id:n.STAX})},{nativeLedgerDevice:{name:"Flex",usbProductIdMask:"0x70"},deviceModel:o.getDeviceModel({id:n.FLEX})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceModel:null}].forEach(({nativeLedgerDevice:e,deviceModel:s})=>{it(`should map USB device with usbProductIdMask ${e.usbProductIdMask} to ${s?.productName??"null"}`,()=>{expect(R(e,o)).toEqual(s)})})}),describe("mapNativeDiscoveryDeviceToTransportDiscoveredDevice",()=>{it("should map NativeDiscoveryDevice to TransportDiscoveredDevice",()=>{const t={name:"NanoS",uid:"abcd",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"}},e={id:"abcd",deviceModel:o.getDeviceModel({id:n.NANO_S}),transport:N,name:"NanoS"};expect(u(t,o)).toEqual(e)}),it("should return null if the device model is not recognized",()=>{const t={name:"NanoX",uid:"efgh",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x4567890"}};expect(u(t,o)).toEqual(null)})}),describe("mapNativeTransportLogToLog",()=>{[{nativeLog:{level:"debug",tag:"tag",message:"debug message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[i.Debug,"debug message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"info",tag:"tag",message:"info message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[i.Info,"info message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"error",tag:"tag",message:"error message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[i.Error,"error message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"warning",tag:"tag",message:"warning message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[i.Warning,"warning message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]}].forEach(({nativeLog:e,log:s})=>{it(`should map NativeLog with level "${e.level}" to Log`,()=>{expect(y(e)).toEqual(s)})})}),describe("mapNativeConnectionResultToConnectionResult",()=>{[{testTitle:"Success",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceName:"NanoS"},connectionResult:r({sessionId:"1234",transportDeviceModel:o.getDeviceModel({id:n.NANO_S})})},{testTitle:"Failure",nativeConnectionResult:{success:!1,error:"error message"},connectionResult:a(new c("error message"))},{testTitle:"Unknown device model",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceName:"NanoX"},connectionResult:a(new c("Could not find device model for the connected device with usbProductIdMask: 0x12345678"))}].forEach(({testTitle:e,nativeConnectionResult:s,connectionResult:v})=>{it(e,()=>{expect(S(s,o)).toEqual(v)})})}),describe("mapNativeSendApduResultToSendApduResult",()=>{test("success",()=>{const e={success:!0,apdu:"AQIDkAA="},s=r(new l({data:new Uint8Array([1,2,3]),statusCode:new Uint8Array([144,0])}));expect(d(e)).toEqual(s)}),test("failure",()=>{const t={success:!1,error:"error message"},e=a(new D("error message"));expect(d(t)).toEqual(e)}),test("timeout error",()=>{const t={success:!1,error:"SendApduTimeout"},e=a(new m("Abort timeout"));expect(d(t)).toEqual(e)}),test("empty response error",()=>{const t={success:!1,error:"EmptyResponse"},e=a(new p("Empty response"));expect(d(t)).toEqual(e)})}),describe("mapNativeDeviceConnectionLostToDeviceDisconnected",()=>{it("should map NativeDeviceConnectionLost to DeviceDisconnected",()=>{const t={id:"1234"},e={sessionId:"1234"};expect(A(t)).toEqual(e)})})});
1
+ import{ApduResponse as m,DeviceDisconnectedBeforeSendingApdu as c,DeviceModelId as a,LogLevel as d,OpeningConnectionError as r,SendApduEmptyResponseError as g,SendApduTimeoutError as D,StaticDeviceModelDataSource as N}from"@ledgerhq/device-management-kit";import{Left as n,Right as u}from"purify-ts";import{HidTransportSendApduUnknownError as l}from"../transport/Errors";import{TRANSPORT_IDENTIFIER as S}from"../transport/rnHidTransportIdentifier";import{mapNativeConnectionResultToConnectionResult as A,mapNativeDeviceConnectionLostToDeviceDisconnected as R,mapNativeDiscoveryDeviceToTransportDiscoveredDevice as v,mapNativeLedgerDeviceToDeviceModel as x,mapNativeSendApduResultToSendApduResult as i,mapNativeTransportLogToLog as y}from"./mapper";describe("mapper",()=>{const o=new N;describe("mapNativeLedgerDeviceToDeviceModel",()=>{[{nativeLedgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceModel:o.getDeviceModel({id:a.NANO_S})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x40"},deviceModel:o.getDeviceModel({id:a.NANO_X})},{nativeLedgerDevice:{name:"NanoSPlus",usbProductIdMask:"0x50"},deviceModel:o.getDeviceModel({id:a.NANO_SP})},{nativeLedgerDevice:{name:"Stax",usbProductIdMask:"0x60"},deviceModel:o.getDeviceModel({id:a.STAX})},{nativeLedgerDevice:{name:"Flex",usbProductIdMask:"0x70"},deviceModel:o.getDeviceModel({id:a.FLEX})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceModel:null}].forEach(({nativeLedgerDevice:e,deviceModel:s})=>{it(`should map USB device with usbProductIdMask ${e.usbProductIdMask} to ${s?.productName??"null"}`,()=>{expect(x(e,o)).toEqual(s)})})}),describe("mapNativeDiscoveryDeviceToTransportDiscoveredDevice",()=>{it("should map NativeDiscoveryDevice to TransportDiscoveredDevice",()=>{const t={name:"NanoS",uid:"abcd",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"}},e={id:"abcd",deviceModel:o.getDeviceModel({id:a.NANO_S}),transport:S,name:"NanoS"};expect(v(t,o)).toEqual(e)}),it("should return null if the device model is not recognized",()=>{const t={name:"NanoX",uid:"efgh",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x4567890"}};expect(v(t,o)).toEqual(null)})}),describe("mapNativeTransportLogToLog",()=>{[{nativeLog:{level:"debug",tag:"tag",message:"debug message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[d.Debug,"debug message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"info",tag:"tag",message:"info message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[d.Info,"info message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"error",tag:"tag",message:"error message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[d.Error,"error message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"warning",tag:"tag",message:"warning message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[d.Warning,"warning message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]}].forEach(({nativeLog:e,log:s})=>{it(`should map NativeLog with level "${e.level}" to Log`,()=>{expect(y(e)).toEqual(s)})})}),describe("mapNativeConnectionResultToConnectionResult",()=>{[{testTitle:"Success",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceName:"NanoS"},connectionResult:u({sessionId:"1234",transportDeviceModel:o.getDeviceModel({id:a.NANO_S})})},{testTitle:"Failure",nativeConnectionResult:{success:!1,error:"error message"},connectionResult:n(new r("error message"))},{testTitle:"Unknown device model",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceName:"NanoX"},connectionResult:n(new r("Could not find device model for the connected device with usbProductIdMask: 0x12345678"))}].forEach(({testTitle:e,nativeConnectionResult:s,connectionResult:p})=>{it(e,()=>{expect(A(s,o)).toEqual(p)})})}),describe("mapNativeSendApduResultToSendApduResult",()=>{test("success",()=>{const e={success:!0,apdu:"AQIDkAA="},s=u(new m({data:new Uint8Array([1,2,3]),statusCode:new Uint8Array([144,0])}));expect(i(e)).toEqual(s)}),test("failure",()=>{const t={success:!1,error:"error message"},e=n(new l("error message"));expect(i(t)).toEqual(e)}),test("timeout error",()=>{const t={success:!1,error:"SendApduTimeout"},e=n(new D("Abort timeout"));expect(i(t)).toEqual(e)}),test("empty response error",()=>{const t={success:!1,error:"EmptyResponse"},e=n(new g("Empty response"));expect(i(t)).toEqual(e)}),test("device not found error",()=>{const t={success:!1,error:"DeviceNotFound"},e=n(new c);expect(i(t)).toEqual(e)}),test("no usb endpoint found error",()=>{const t={success:!1,error:"NoUsbEndpointFound"},e=n(new c);expect(i(t)).toEqual(e)}),test("unknown error",()=>{const t={success:!1,error:"unknown error"},e=n(new l("unknown error"));expect(i(t)).toEqual(e)})}),describe("mapNativeDeviceConnectionLostToDeviceDisconnected",()=>{it("should map NativeDeviceConnectionLost to DeviceDisconnected",()=>{const t={id:"1234"},e={sessionId:"1234"};expect(R(t)).toEqual(e)})})});
2
2
  //# sourceMappingURL=mapper.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/bridge/mapper.test.ts"],
4
- "sourcesContent": ["import {\n ApduResponse,\n DeviceModelId,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport { type InternalConnectionResult } from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeLedgerDeviceToDeviceModel,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\ndescribe(\"mapper\", () => {\n const deviceModelDataSource = new StaticDeviceModelDataSource();\n\n describe(\"mapNativeLedgerDeviceToDeviceModel\", () => {\n const testCases: Array<{\n nativeLedgerDevice: NativeLedgerDevice;\n deviceModel: TransportDeviceModel | null;\n }> = [\n {\n nativeLedgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x40\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoSPlus\",\n usbProductIdMask: \"0x50\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Stax\",\n usbProductIdMask: \"0x60\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Flex\",\n usbProductIdMask: \"0x70\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceModel: null, // because the usbProductIdMask is not recognized\n },\n ];\n testCases.forEach(({ nativeLedgerDevice, deviceModel }) => {\n it(`should map USB device with usbProductIdMask ${nativeLedgerDevice.usbProductIdMask} to ${\n deviceModel?.productName ?? \"null\"\n }`, () => {\n expect(\n mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice,\n deviceModelDataSource,\n ),\n ).toEqual(deviceModel);\n });\n });\n });\n\n describe(\"mapNativeDiscoveryDeviceToTransportDiscoveredDevice\", () => {\n it(\"should map NativeDiscoveryDevice to TransportDiscoveredDevice\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoS\",\n uid: \"abcd\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n };\n const expectedDiscoveredDevice: TransportDiscoveredDevice = {\n id: \"abcd\",\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n transport: TRANSPORT_IDENTIFIER,\n name: \"NanoS\",\n };\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n\n it(\"should return null if the device model is not recognized\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoX\",\n uid: \"efgh\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x4567890\", // some invalid value\n },\n };\n const expectedDiscoveredDevice = null; // because the usbProductIdMask is not recognized\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n });\n\n describe(\"mapNativeTransportLogToLog\", () => {\n const testCases: Array<{\n nativeLog: NativeLog;\n log: LogParams;\n }> = [\n {\n // debug\n nativeLog: {\n level: \"debug\",\n tag: \"tag\",\n message: \"debug message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Debug,\n \"debug message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // info\n {\n nativeLog: {\n level: \"info\",\n tag: \"tag\",\n message: \"info message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Info,\n \"info message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // error\n {\n nativeLog: {\n level: \"error\",\n tag: \"tag\",\n message: \"error message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Error,\n \"error message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // warning\n {\n nativeLog: {\n level: \"warning\",\n tag: \"tag\",\n message: \"warning message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Warning,\n \"warning message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n ];\n\n testCases.forEach(({ nativeLog, log }) => {\n it(`should map NativeLog with level \"${nativeLog.level}\" to Log`, () => {\n expect(mapNativeTransportLogToLog(nativeLog)).toEqual(log);\n });\n });\n });\n\n describe(\"mapNativeConnectionResultToConnectionResult\", () => {\n const testCases: Array<{\n nativeConnectionResult: NativeInternalConnectionResult;\n connectionResult: InternalConnectionResult;\n testTitle: string;\n }> = [\n {\n testTitle: \"Success\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceName: \"NanoS\",\n },\n connectionResult: Right({\n sessionId: \"1234\",\n transportDeviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n }),\n },\n {\n testTitle: \"Failure\",\n nativeConnectionResult: {\n success: false,\n error: \"error message\",\n },\n connectionResult: Left(new OpeningConnectionError(\"error message\")),\n },\n {\n testTitle: \"Unknown device model\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceName: \"NanoX\",\n },\n connectionResult: Left(\n new OpeningConnectionError(\n \"Could not find device model for the connected device with usbProductIdMask: 0x12345678\",\n ),\n ),\n },\n ];\n\n testCases.forEach(\n ({ testTitle, nativeConnectionResult, connectionResult }) => {\n it(testTitle, () => {\n expect(\n mapNativeConnectionResultToConnectionResult(\n nativeConnectionResult,\n deviceModelDataSource,\n ),\n ).toEqual(connectionResult);\n });\n },\n );\n });\n\n describe(\"mapNativeSendApduResultToSendApduResult\", () => {\n test(\"success\", () => {\n const resultApduString = \"AQIDkAA=\";\n const nativeSendApduResult: NativeSendApduResult = {\n success: true,\n apdu: resultApduString,\n };\n const expectedSendApduResult: SendApduResult = Right(\n new ApduResponse({\n data: new Uint8Array([0x01, 0x02, 0x03]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"failure\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"error message\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"error message\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"timeout error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"SendApduTimeout\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduTimeoutError(\"Abort timeout\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"empty response error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"EmptyResponse\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduEmptyResponseError(\"Empty response\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n });\n\n describe(\"mapNativeDeviceConnectionLostToDeviceDisconnected\", () => {\n it(\"should map NativeDeviceConnectionLost to DeviceDisconnected\", () => {\n const nativeDeviceConnectionLost = {\n id: \"1234\",\n };\n const expectedDeviceDisconnected = {\n sessionId: \"1234\",\n };\n expect(\n mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost,\n ),\n ).toEqual(expectedDeviceDisconnected);\n });\n });\n});\n"],
5
- "mappings": "AAAA,OACE,gBAAAA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I,CAAC,CACzC,CAAC,CACH,EACA,OACEe,EAAwCY,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,EAED,KAAK,UAAW,IAAM,CACpB,MAAMD,EAA6C,CACjD,QAAS,GACT,MAAO,eACT,EACMC,EAAyCrB,EAC7C,IAAIE,EAAiC,eAAe,CACtD,EACA,OACEM,EAAwCY,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,EAED,KAAK,gBAAiB,IAAM,CAC1B,MAAMD,EAA6C,CACjD,QAAS,GACT,MAAO,iBACT,EACMC,EAAyCrB,EAC7C,IAAIF,EAAqB,eAAe,CAC1C,EACA,OACEU,EAAwCY,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,EAED,KAAK,uBAAwB,IAAM,CACjC,MAAMD,EAA6C,CACjD,QAAS,GACT,MAAO,eACT,EACMC,EAAyCrB,EAC7C,IAAIH,EAA2B,gBAAgB,CACjD,EACA,OACEW,EAAwCY,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,CACH,CAAC,EAED,SAAS,oDAAqD,IAAM,CAClE,GAAG,8DAA+D,IAAM,CACtE,MAAMC,EAA6B,CACjC,GAAI,MACN,EACMC,EAA6B,CACjC,UAAW,MACb,EACA,OACElB,EACEiB,CACF,CACF,EAAE,QAAQC,CAA0B,CACtC,CAAC,CACH,CAAC,CACH,CAAC",
6
- "names": ["ApduResponse", "DeviceModelId", "LogLevel", "OpeningConnectionError", "SendApduEmptyResponseError", "SendApduTimeoutError", "StaticDeviceModelDataSource", "Left", "Right", "HidTransportSendApduUnknownError", "TRANSPORT_IDENTIFIER", "mapNativeConnectionResultToConnectionResult", "mapNativeDeviceConnectionLostToDeviceDisconnected", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "mapNativeLedgerDeviceToDeviceModel", "mapNativeSendApduResultToSendApduResult", "mapNativeTransportLogToLog", "deviceModelDataSource", "nativeLedgerDevice", "deviceModel", "nativeDevice", "expectedDiscoveredDevice", "nativeLog", "log", "testTitle", "nativeConnectionResult", "connectionResult", "nativeSendApduResult", "expectedSendApduResult", "nativeDeviceConnectionLost", "expectedDeviceDisconnected"]
4
+ "sourcesContent": ["import {\n ApduResponse,\n DeviceDisconnectedBeforeSendingApdu,\n DeviceModelId,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport { type InternalConnectionResult } from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeLedgerDeviceToDeviceModel,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\ndescribe(\"mapper\", () => {\n const deviceModelDataSource = new StaticDeviceModelDataSource();\n\n describe(\"mapNativeLedgerDeviceToDeviceModel\", () => {\n const testCases: Array<{\n nativeLedgerDevice: NativeLedgerDevice;\n deviceModel: TransportDeviceModel | null;\n }> = [\n {\n nativeLedgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x40\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoSPlus\",\n usbProductIdMask: \"0x50\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Stax\",\n usbProductIdMask: \"0x60\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Flex\",\n usbProductIdMask: \"0x70\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceModel: null, // because the usbProductIdMask is not recognized\n },\n ];\n testCases.forEach(({ nativeLedgerDevice, deviceModel }) => {\n it(`should map USB device with usbProductIdMask ${nativeLedgerDevice.usbProductIdMask} to ${\n deviceModel?.productName ?? \"null\"\n }`, () => {\n expect(\n mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice,\n deviceModelDataSource,\n ),\n ).toEqual(deviceModel);\n });\n });\n });\n\n describe(\"mapNativeDiscoveryDeviceToTransportDiscoveredDevice\", () => {\n it(\"should map NativeDiscoveryDevice to TransportDiscoveredDevice\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoS\",\n uid: \"abcd\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n };\n const expectedDiscoveredDevice: TransportDiscoveredDevice = {\n id: \"abcd\",\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n transport: TRANSPORT_IDENTIFIER,\n name: \"NanoS\",\n };\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n\n it(\"should return null if the device model is not recognized\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoX\",\n uid: \"efgh\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x4567890\", // some invalid value\n },\n };\n const expectedDiscoveredDevice = null; // because the usbProductIdMask is not recognized\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n });\n\n describe(\"mapNativeTransportLogToLog\", () => {\n const testCases: Array<{\n nativeLog: NativeLog;\n log: LogParams;\n }> = [\n {\n // debug\n nativeLog: {\n level: \"debug\",\n tag: \"tag\",\n message: \"debug message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Debug,\n \"debug message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // info\n {\n nativeLog: {\n level: \"info\",\n tag: \"tag\",\n message: \"info message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Info,\n \"info message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // error\n {\n nativeLog: {\n level: \"error\",\n tag: \"tag\",\n message: \"error message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Error,\n \"error message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // warning\n {\n nativeLog: {\n level: \"warning\",\n tag: \"tag\",\n message: \"warning message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Warning,\n \"warning message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n ];\n\n testCases.forEach(({ nativeLog, log }) => {\n it(`should map NativeLog with level \"${nativeLog.level}\" to Log`, () => {\n expect(mapNativeTransportLogToLog(nativeLog)).toEqual(log);\n });\n });\n });\n\n describe(\"mapNativeConnectionResultToConnectionResult\", () => {\n const testCases: Array<{\n nativeConnectionResult: NativeInternalConnectionResult;\n connectionResult: InternalConnectionResult;\n testTitle: string;\n }> = [\n {\n testTitle: \"Success\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceName: \"NanoS\",\n },\n connectionResult: Right({\n sessionId: \"1234\",\n transportDeviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n }),\n },\n {\n testTitle: \"Failure\",\n nativeConnectionResult: {\n success: false,\n error: \"error message\",\n },\n connectionResult: Left(new OpeningConnectionError(\"error message\")),\n },\n {\n testTitle: \"Unknown device model\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceName: \"NanoX\",\n },\n connectionResult: Left(\n new OpeningConnectionError(\n \"Could not find device model for the connected device with usbProductIdMask: 0x12345678\",\n ),\n ),\n },\n ];\n\n testCases.forEach(\n ({ testTitle, nativeConnectionResult, connectionResult }) => {\n it(testTitle, () => {\n expect(\n mapNativeConnectionResultToConnectionResult(\n nativeConnectionResult,\n deviceModelDataSource,\n ),\n ).toEqual(connectionResult);\n });\n },\n );\n });\n\n describe(\"mapNativeSendApduResultToSendApduResult\", () => {\n test(\"success\", () => {\n const resultApduString = \"AQIDkAA=\";\n const nativeSendApduResult: NativeSendApduResult = {\n success: true,\n apdu: resultApduString,\n };\n const expectedSendApduResult: SendApduResult = Right(\n new ApduResponse({\n data: new Uint8Array([0x01, 0x02, 0x03]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"failure\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"error message\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"error message\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"timeout error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"SendApduTimeout\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduTimeoutError(\"Abort timeout\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"empty response error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"EmptyResponse\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduEmptyResponseError(\"Empty response\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"device not found error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"DeviceNotFound\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new DeviceDisconnectedBeforeSendingApdu(),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"no usb endpoint found error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"NoUsbEndpointFound\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new DeviceDisconnectedBeforeSendingApdu(),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"unknown error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"unknown error\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"unknown error\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n });\n\n describe(\"mapNativeDeviceConnectionLostToDeviceDisconnected\", () => {\n it(\"should map NativeDeviceConnectionLost to DeviceDisconnected\", () => {\n const nativeDeviceConnectionLost = {\n id: \"1234\",\n };\n const expectedDeviceDisconnected = {\n sessionId: \"1234\",\n };\n expect(\n mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost,\n ),\n ).toEqual(expectedDeviceDisconnected);\n });\n });\n});\n"],
5
+ "mappings": "AAAA,OACE,gBAAAA,EACA,uCAAAC,EACA,iBAAAC,EACA,YAAAC,EAEA,0BAAAC,EACA,8BAAAC,EAEA,wBAAAC,EACA,+BAAAC,MAGK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,oCAAAC,MAAwC,wBACjD,OAAS,wBAAAC,MAA4B,0CAGrC,OACE,+CAAAC,EACA,qDAAAC,EACA,uDAAAC,EACA,sCAAAC,EACA,2CAAAC,EACA,8BAAAC,MACK,WASP,SAAS,SAAU,IAAM,CACvB,MAAMC,EAAwB,IAAIX,EAElC,SAAS,qCAAsC,IAAM,CAI9C,CACH,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,MACpB,EACA,YAAaW,EAAsB,eAAe,CAChD,GAAIhB,EAAc,MACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,MACpB,EACA,YAAagB,EAAsB,eAAe,CAChD,GAAIhB,EAAc,MACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,YACN,iBAAkB,MACpB,EACA,YAAagB,EAAsB,eAAe,CAChD,GAAIhB,EAAc,OACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,OACN,iBAAkB,MACpB,EACA,YAAagB,EAAsB,eAAe,CAChD,GAAIhB,EAAc,IACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,OACN,iBAAkB,MACpB,EACA,YAAagB,EAAsB,eAAe,CAChD,GAAIhB,EAAc,IACpB,CAAC,CACH,EACA,CACE,mBAAoB,CAClB,KAAM,QACN,iBAAkB,YACpB,EACA,YAAa,IACf,CACF,EACU,QAAQ,CAAC,CAAE,mBAAAiB,EAAoB,Y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,IAAM,CAC1B,MAAMD,EAA6C,CACjD,QAAS,GACT,MAAO,eACT,EACMC,EAAyCrB,EAC7C,IAAIE,EAAiC,eAAe,CACtD,EACA,OACEM,EAAwCY,CAAoB,CAC9D,EAAE,QAAQC,CAAsB,CAClC,CAAC,CACH,CAAC,EAED,SAAS,oDAAqD,IAAM,CAClE,GAAG,8DAA+D,IAAM,CACtE,MAAMC,EAA6B,CACjC,GAAI,MACN,EACMC,EAA6B,CACjC,UAAW,MACb,EACA,OACElB,EACEiB,CACF,CACF,EAAE,QAAQC,CAA0B,CACtC,CAAC,CACH,CAAC,CACH,CAAC",
6
+ "names": ["ApduResponse", "DeviceDisconnectedBeforeSendingApdu", "DeviceModelId", "LogLevel", "OpeningConnectionError", "SendApduEmptyResponseError", "SendApduTimeoutError", "StaticDeviceModelDataSource", "Left", "Right", "HidTransportSendApduUnknownError", "TRANSPORT_IDENTIFIER", "mapNativeConnectionResultToConnectionResult", "mapNativeDeviceConnectionLostToDeviceDisconnected", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "mapNativeLedgerDeviceToDeviceModel", "mapNativeSendApduResultToSendApduResult", "mapNativeTransportLogToLog", "deviceModelDataSource", "nativeLedgerDevice", "deviceModel", "nativeDevice", "expectedDiscoveredDevice", "nativeLog", "log", "testTitle", "nativeConnectionResult", "connectionResult", "nativeSendApduResult", "expectedSendApduResult", "nativeDeviceConnectionLost", "expectedDeviceDisconnected"]
7
7
  }