@ledgerhq/device-transport-kit-react-native-hid 0.0.0-no-issue-rn-hid-scan-20251022121009 → 0.0.0-no-issue-npmjs-attestation-1-20251126170021

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/bridge/mapper.ts"],
4
- "sourcesContent": ["import {\n ApduResponse,\n DeviceDisconnectedWhileSendingError,\n type DeviceModelDataSource,\n FramerUtils,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { base64ToUint8Array } from \"@api/helpers/base64Utils\";\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n type NativeDeviceConnectionLost,\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\nexport function mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice: NativeLedgerDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDeviceModel | null {\n return (\n deviceModelDataSource.filterDeviceModels({\n usbProductId: Number.parseInt(nativeLedgerDevice.usbProductIdMask, 16),\n })[0] ?? null\n );\n}\n\nexport function mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice: NativeDiscoveryDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDiscoveredDevice | null {\n const deviceModel = mapNativeLedgerDeviceToDeviceModel(\n nativeDevice.ledgerDevice,\n deviceModelDataSource,\n );\n if (deviceModel == null) return null;\n\n return {\n id: nativeDevice.uid,\n deviceModel,\n transport: TRANSPORT_IDENTIFIER,\n name: nativeDevice.name,\n };\n}\n\nexport function mapNativeTransportLogToLog(log: NativeLog): LogParams {\n let level: LogLevel;\n switch (log.level) {\n case \"error\":\n level = LogLevel.Error;\n break;\n case \"warning\":\n level = LogLevel.Warning;\n break;\n case \"info\":\n level = LogLevel.Info;\n break;\n case \"debug\":\n level = LogLevel.Debug;\n break;\n default:\n assertNever(log.level);\n level = LogLevel.Info;\n break;\n }\n\n return [\n level,\n log.message,\n {\n tag: log.tag,\n data: log.jsonPayload,\n timestamp: Number.parseInt(log.timestamp, 10),\n },\n ];\n}\n\nfunction assertNever(x: never) {\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function mapNativeConnectionResultToConnectionResult(\n result: NativeInternalConnectionResult,\n deviceModelDataSource: DeviceModelDataSource,\n): InternalConnectionResult {\n if (result.success) {\n const transportDeviceModel = mapNativeLedgerDeviceToDeviceModel(\n result.ledgerDevice,\n deviceModelDataSource,\n );\n if (!transportDeviceModel)\n return Left(\n new OpeningConnectionError(\n `Could not find device model for the connected device with usbProductIdMask: ${result.ledgerDevice.usbProductIdMask}`,\n ),\n );\n return Right({ sessionId: result.sessionId, transportDeviceModel });\n } else {\n return Left(new OpeningConnectionError(result.error));\n }\n}\n\nexport function mapNativeSendApduResultToSendApduResult(\n result: NativeSendApduResult,\n): SendApduResult {\n if (result.success) {\n const responseBytes = base64ToUint8Array(result.apdu);\n const data = FramerUtils.getFirstBytesFrom(\n responseBytes,\n responseBytes.length - 2,\n );\n const statusCode = FramerUtils.getLastBytesFrom(responseBytes, 2);\n return Right(new ApduResponse({ data, statusCode }));\n } else if (result.error === \"SendApduTimeout\") {\n return Left(new SendApduTimeoutError(\"Abort timeout\"));\n } else if (result.error === \"EmptyResponse\") {\n return Left(new SendApduEmptyResponseError(\"Empty response\"));\n } else if (result.error === \"DeviceDisconnected\") {\n return Left(new DeviceDisconnectedWhileSendingError(\"Device disconnected\"));\n } else {\n return Left(new HidTransportSendApduUnknownError(result.error));\n }\n}\n\nexport function mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost: NativeDeviceConnectionLost,\n): InternalDeviceDisconnected {\n return {\n sessionId: nativeDeviceConnectionLost.id,\n };\n}\n"],
5
- "mappings": "AAAA,OACE,gBAAAA,EACA,uCAAAC,EAEA,eAAAC,EACA,YAAAC,EAEA,0BAAAC,EACA,8BAAAC,EAEA,wBAAAC,MAGK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,sBAAAC,MAA0B,2BACnC,OAAS,oCAAAC,MAAwC,wBACjD,OAAS,wBAAAC,MAA4B,0CAe9B,SAASC,EACdC,EACAC,EAC6B,CAC7B,OACEA,EAAsB,mBAAmB,CACvC,aAAc,OAAO,SAASD,EAAmB,iBAAkB,EAAE,CACvE,CAAC,EAAE,CAAC,GAAK,IAEb,CAEO,SAASE,EACdC,EACAF,EACkC,CAClC,MAAMG,EAAcL,EAClBI,EAAa,aACbF,CACF,EACA,OAAIG,GAAe,KAAa,KAEzB,CACL,GAAID,EAAa,IACjB,YAAAC,EACA,UAAWN,EACX,KAAMK,EAAa,IACrB,CACF,CAEO,SAASE,EAA2BC,EAA2B,CACpE,IAAIC,EACJ,OAAQD,EAAI,MAAO,CACjB,IAAK,QACHC,EAAQjB,EAAS,MACjB,MACF,IAAK,UACHiB,EAAQjB,EAAS,QACjB,MACF,IAAK,OACHiB,EAAQjB,EAAS,KACjB,MACF,IAAK,QACHiB,EAAQjB,EAAS,MACjB,MACF,QACEkB,EAAYF,EAAI,KAAK,EACrBC,EAAQjB,EAAS,KACjB,KACJ,CAEA,MAAO,CACLiB,EACAD,EAAI,QACJ,CACE,IAAKA,EAAI,IACT,KAAMA,EAAI,YACV,UAAW,OAAO,SAASA,EAAI,UAAW,EAAE,CAC9C,CACF,CACF,CAEA,SAASE,EAAYC,EAAU,CAC7B,MAAM,IAAI,MAAM,sBAAwBA,CAAC,CAC3C,CAEO,SAASC,EACdC,EACAV,EAC0B,CAC1B,GAAIU,EAAO,QAAS,CAClB,MAAMC,EAAuBb,EAC3BY,EAAO,aACPV,CACF,EACA,OAAKW,EAMEjB,EAAM,CAAE,UAAWgB,EAAO,UAAW,qBAAAC,CAAqB,CAAC,EALzDlB,EACL,IAAIH,EACF,+EAA+EoB,EAAO,aAAa,gBAAgB,EACrH,CACF,CAEJ,KACE,QAAOjB,EAAK,IAAIH,EAAuBoB,EAAO,KAAK,CAAC,CAExD,CAEO,SAASE,EACdF,EACgB,CAChB,GAAIA,EAAO,QAAS,CAClB,MAAMG,EAAgBlB,EAAmBe,EAAO,IAAI,EAC9CI,EAAO1B,EAAY,kBACvByB,EACAA,EAAc,OAAS,CACzB,EACME,EAAa3B,EAAY,iBAAiByB,EAAe,CAAC,EAChE,OAAOnB,EAAM,IAAIR,EAAa,CAAE,KAAA4B,EAAM,WAAAC,CAAW,CAAC,CAAC,CACrD,KAAO,QAAIL,EAAO,QAAU,kBACnBjB,EAAK,IAAID,EAAqB,eAAe,CAAC,EAC5CkB,EAAO,QAAU,gBACnBjB,EAAK,IAAIF,EAA2B,gBAAgB,CAAC,EACnDmB,EAAO,QAAU,qBACnBjB,EAAK,IAAIN,EAAoC,qBAAqB,CAAC,EAEnEM,EAAK,IAAIG,EAAiCc,EAAO,KAAK,CAAC,CAElE,CAEO,SAASM,EACdC,EAC4B,CAC5B,MAAO,CACL,UAAWA,EAA2B,EACxC,CACF",
6
- "names": ["ApduResponse", "DeviceDisconnectedWhileSendingError", "FramerUtils", "LogLevel", "OpeningConnectionError", "SendApduEmptyResponseError", "SendApduTimeoutError", "Left", "Right", "base64ToUint8Array", "HidTransportSendApduUnknownError", "TRANSPORT_IDENTIFIER", "mapNativeLedgerDeviceToDeviceModel", "nativeLedgerDevice", "deviceModelDataSource", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "nativeDevice", "deviceModel", "mapNativeTransportLogToLog", "log", "level", "assertNever", "x", "mapNativeConnectionResultToConnectionResult", "result", "transportDeviceModel", "mapNativeSendApduResultToSendApduResult", "responseBytes", "data", "statusCode", "mapNativeDeviceConnectionLostToDeviceDisconnected", "nativeDeviceConnectionLost"]
4
+ "sourcesContent": ["import {\n ApduResponse,\n DeviceDisconnectedBeforeSendingApdu,\n DeviceDisconnectedWhileSendingError,\n type DeviceModelDataSource,\n FramerUtils,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { base64ToUint8Array } from \"@api/helpers/base64Utils\";\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n type NativeDeviceConnectionLost,\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\nexport function mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice: NativeLedgerDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDeviceModel | null {\n return (\n deviceModelDataSource.filterDeviceModels({\n usbProductId: Number.parseInt(nativeLedgerDevice.usbProductIdMask, 16),\n })[0] ?? null\n );\n}\n\nexport function mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice: NativeDiscoveryDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDiscoveredDevice | null {\n const deviceModel = mapNativeLedgerDeviceToDeviceModel(\n nativeDevice.ledgerDevice,\n deviceModelDataSource,\n );\n if (deviceModel == null) return null;\n\n return {\n id: nativeDevice.uid,\n deviceModel,\n transport: TRANSPORT_IDENTIFIER,\n name: nativeDevice.name,\n };\n}\n\nexport function mapNativeTransportLogToLog(log: NativeLog): LogParams {\n let level: LogLevel;\n switch (log.level) {\n case \"error\":\n level = LogLevel.Error;\n break;\n case \"warning\":\n level = LogLevel.Warning;\n break;\n case \"info\":\n level = LogLevel.Info;\n break;\n case \"debug\":\n level = LogLevel.Debug;\n break;\n default:\n assertNever(log.level);\n level = LogLevel.Info;\n break;\n }\n\n return [\n level,\n log.message,\n {\n tag: log.tag,\n data: log.jsonPayload,\n timestamp: Number.parseInt(log.timestamp, 10),\n },\n ];\n}\n\nfunction assertNever(x: never) {\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function mapNativeConnectionResultToConnectionResult(\n result: NativeInternalConnectionResult,\n deviceModelDataSource: DeviceModelDataSource,\n): InternalConnectionResult {\n if (result.success) {\n const transportDeviceModel = mapNativeLedgerDeviceToDeviceModel(\n result.ledgerDevice,\n deviceModelDataSource,\n );\n if (!transportDeviceModel)\n return Left(\n new OpeningConnectionError(\n `Could not find device model for the connected device with usbProductIdMask: ${result.ledgerDevice.usbProductIdMask}`,\n ),\n );\n return Right({ sessionId: result.sessionId, transportDeviceModel });\n } else {\n return Left(new OpeningConnectionError(result.error));\n }\n}\n\nexport function mapNativeSendApduResultToSendApduResult(\n result: NativeSendApduResult,\n): SendApduResult {\n if (result.success) {\n const responseBytes = base64ToUint8Array(result.apdu);\n const data = FramerUtils.getFirstBytesFrom(\n responseBytes,\n responseBytes.length - 2,\n );\n const statusCode = FramerUtils.getLastBytesFrom(responseBytes, 2);\n return Right(new ApduResponse({ data, statusCode }));\n } else {\n switch (result.error) {\n case \"SendApduTimeout\":\n return Left(new SendApduTimeoutError(\"Abort timeout\"));\n case \"EmptyResponse\":\n return Left(new SendApduEmptyResponseError(\"Empty response\"));\n case \"DeviceDisconnected\":\n return Left(\n new DeviceDisconnectedWhileSendingError(\"Device disconnected\"),\n );\n case \"DeviceNotFound\":\n case \"NoUsbEndpointFound\":\n return Left(new DeviceDisconnectedBeforeSendingApdu());\n default:\n return Left(new HidTransportSendApduUnknownError(result.error));\n }\n }\n}\n\nexport function mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost: NativeDeviceConnectionLost,\n): InternalDeviceDisconnected {\n return {\n sessionId: nativeDeviceConnectionLost.id,\n };\n}\n"],
5
+ "mappings": "AAAA,OACE,gBAAAA,EACA,uCAAAC,EACA,uCAAAC,EAEA,eAAAC,EACA,YAAAC,EAEA,0BAAAC,EACA,8BAAAC,EAEA,wBAAAC,MAGK,kCACP,OAAS,QAAAC,EAAM,SAAAC,MAAa,YAE5B,OAAS,sBAAAC,MAA0B,2BACnC,OAAS,oCAAAC,MAAwC,wBACjD,OAAS,wBAAAC,MAA4B,0CAe9B,SAASC,EACdC,EACAC,EAC6B,CAC7B,OACEA,EAAsB,mBAAmB,CACvC,aAAc,OAAO,SAASD,EAAmB,iBAAkB,EAAE,CACvE,CAAC,EAAE,CAAC,GAAK,IAEb,CAEO,SAASE,EACdC,EACAF,EACkC,CAClC,MAAMG,EAAcL,EAClBI,EAAa,aACbF,CACF,EACA,OAAIG,GAAe,KAAa,KAEzB,CACL,GAAID,EAAa,IACjB,YAAAC,EACA,UAAWN,EACX,KAAMK,EAAa,IACrB,CACF,CAEO,SAASE,EAA2BC,EAA2B,CACpE,IAAIC,EACJ,OAAQD,EAAI,MAAO,CACjB,IAAK,QACHC,EAAQjB,EAAS,MACjB,MACF,IAAK,UACHiB,EAAQjB,EAAS,QACjB,MACF,IAAK,OACHiB,EAAQjB,EAAS,KACjB,MACF,IAAK,QACHiB,EAAQjB,EAAS,MACjB,MACF,QACEkB,EAAYF,EAAI,KAAK,EACrBC,EAAQjB,EAAS,KACjB,KACJ,CAEA,MAAO,CACLiB,EACAD,EAAI,QACJ,CACE,IAAKA,EAAI,IACT,KAAMA,EAAI,YACV,UAAW,OAAO,SAASA,EAAI,UAAW,EAAE,CAC9C,CACF,CACF,CAEA,SAASE,EAAYC,EAAU,CAC7B,MAAM,IAAI,MAAM,sBAAwBA,CAAC,CAC3C,CAEO,SAASC,EACdC,EACAV,EAC0B,CAC1B,GAAIU,EAAO,QAAS,CAClB,MAAMC,EAAuBb,EAC3BY,EAAO,aACPV,CACF,EACA,OAAKW,EAMEjB,EAAM,CAAE,UAAWgB,EAAO,UAAW,qBAAAC,CAAqB,CAAC,EALzDlB,EACL,IAAIH,EACF,+EAA+EoB,EAAO,aAAa,gBAAgB,EACrH,CACF,CAEJ,KACE,QAAOjB,EAAK,IAAIH,EAAuBoB,EAAO,KAAK,CAAC,CAExD,CAEO,SAASE,EACdF,EACgB,CAChB,GAAIA,EAAO,QAAS,CAClB,MAAMG,EAAgBlB,EAAmBe,EAAO,IAAI,EAC9CI,EAAO1B,EAAY,kBACvByB,EACAA,EAAc,OAAS,CACzB,EACME,EAAa3B,EAAY,iBAAiByB,EAAe,CAAC,EAChE,OAAOnB,EAAM,IAAIT,EAAa,CAAE,KAAA6B,EAAM,WAAAC,CAAW,CAAC,CAAC,CACrD,KACE,QAAQL,EAAO,MAAO,CACpB,IAAK,kBACH,OAAOjB,EAAK,IAAID,EAAqB,eAAe,CAAC,EACvD,IAAK,gBACH,OAAOC,EAAK,IAAIF,EAA2B,gBAAgB,CAAC,EAC9D,IAAK,qBACH,OAAOE,EACL,IAAIN,EAAoC,qBAAqB,CAC/D,EACF,IAAK,iBACL,IAAK,qBACH,OAAOM,EAAK,IAAIP,CAAqC,EACvD,QACE,OAAOO,EAAK,IAAIG,EAAiCc,EAAO,KAAK,CAAC,CAClE,CAEJ,CAEO,SAASM,EACdC,EAC4B,CAC5B,MAAO,CACL,UAAWA,EAA2B,EACxC,CACF",
6
+ "names": ["ApduResponse", "DeviceDisconnectedBeforeSendingApdu", "DeviceDisconnectedWhileSendingError", "FramerUtils", "LogLevel", "OpeningConnectionError", "SendApduEmptyResponseError", "SendApduTimeoutError", "Left", "Right", "base64ToUint8Array", "HidTransportSendApduUnknownError", "TRANSPORT_IDENTIFIER", "mapNativeLedgerDeviceToDeviceModel", "nativeLedgerDevice", "deviceModelDataSource", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "nativeDevice", "deviceModel", "mapNativeTransportLogToLog", "log", "level", "assertNever", "x", "mapNativeConnectionResultToConnectionResult", "result", "transportDeviceModel", "mapNativeSendApduResultToSendApduResult", "responseBytes", "data", "statusCode", "mapNativeDeviceConnectionLostToDeviceDisconnected", "nativeDeviceConnectionLost"]
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,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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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,w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AC,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
  }
@@ -1,2 +1,2 @@
1
- import{DisconnectError as l,LogLevel as n,OpeningConnectionError as g,TransportConnectedDevice as u}from"@ledgerhq/device-management-kit";import{Left as v,Right as b}from"purify-ts";import{Observable as p}from"rxjs";import{getObservableOfArraysNewItems as h}from"../helpers/getObservableOfArraysNewItems";import{TRANSPORT_IDENTIFIER as D}from"../transport/rnHidTransportIdentifier";import{HidTransportSendApduUnknownError as _}from"./Errors";class W{constructor(t,r,i){this._isSupported=t;this._nativeModuleWrapper=r;this._loggerService=i("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[s,o,c]=e,a={[n.Fatal]:this._loggerService.error.bind(this._loggerService),[n.Error]:this._loggerService.error.bind(this._loggerService),[n.Warning]:this._loggerService.warn.bind(this._loggerService),[n.Info]:this._loggerService.info.bind(this._loggerService),[n.Debug]:this._loggerService.debug.bind(this._loggerService)}[s];a(o,c)})}_loggerService;getIdentifier(){return D}isSupported(){return this._isSupported}startDiscovering(){return new p(r=>{const i=h(this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),e=>e.id).subscribe(r);return this._nativeModuleWrapper.startScan().catch(e=>{r.error(e),this._loggerService.error("startDiscovering error",e)}),()=>i.unsubscribe()})}stopDiscovering(){this._loggerService.debug("[stopDiscovering] called"),this._nativeModuleWrapper.stopScan().catch(t=>{this._loggerService.error("stopDiscovering error",t)})}listenToAvailableDevices(){return this._loggerService.debug("[listenToAvailableDevices] called"),new p(r=>{const i=this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents().subscribe(e=>{this._loggerService.debug("[listenToAvailableDevices] devices discovered",{data:{devices:e}}),r.next(e)});return this._nativeModuleWrapper.startScan().catch(e=>{this._loggerService.error("startDiscovering error",e),r.error(e)}),()=>{i.unsubscribe(),this._nativeModuleWrapper.stopScan().catch(e=>{this._loggerService.error("stopDiscovering error",e)})}})}connect(t){return this._nativeModuleWrapper.connectDevice(t.deviceId).then(r=>r.map(({sessionId:i,transportDeviceModel:e})=>{const s=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(o=>{o.sessionId===i&&(t.onDisconnect(i),s.unsubscribe())});return new u({id:i,deviceModel:e,sendApdu:async(o,c=!1,a=-1)=>this._nativeModuleWrapper.sendApdu(i,o,c,a).catch(d=>v(new _(d))),transport:this.getIdentifier(),type:"USB"})})).catch(r=>v(new g(r)))}disconnect(t){return this._nativeModuleWrapper.disconnectDevice(t.connectedDevice.id).then(()=>b(void 0)).catch(r=>v(new l(r)))}}export{W as RNHidTransport};
1
+ import{DisconnectError as g,LogLevel as n,OpeningConnectionError as l,TransportConnectedDevice as u}from"@ledgerhq/device-management-kit";import{Left as p,Right as b}from"purify-ts";import{Observable as v}from"rxjs";import{getObservableOfArraysNewItems as h}from"../helpers/getObservableOfArraysNewItems";import{TRANSPORT_IDENTIFIER as D}from"../transport/rnHidTransportIdentifier";import{HidTransportSendApduUnknownError as _}from"./Errors";class W{constructor(i,r,t){this._isSupported=i;this._nativeModuleWrapper=r;this._loggerService=t("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[s,o,c]=e,a={[n.Fatal]:this._loggerService.error.bind(this._loggerService),[n.Error]:this._loggerService.error.bind(this._loggerService),[n.Warning]:this._loggerService.warn.bind(this._loggerService),[n.Info]:this._loggerService.info.bind(this._loggerService),[n.Debug]:this._loggerService.debug.bind(this._loggerService)}[s];a(o,c)})}_loggerService;getIdentifier(){return D}isSupported(){return this._isSupported}startDiscovering(){return new v(r=>{const t=h(this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),e=>e.id).subscribe(r);return this._nativeModuleWrapper.startScan().catch(e=>{r.error(e),this._loggerService.error("startDiscovering error",e)}),()=>t.unsubscribe()})}stopDiscovering(){this._nativeModuleWrapper.stopScan().catch(i=>{this._loggerService.error("stopDiscovering error",i)})}listenToAvailableDevices(){return new v(r=>{const t=this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents().subscribe(e=>{r.next(e)});return this._nativeModuleWrapper.startScan().catch(e=>{this._loggerService.error("startDiscovering error",e),r.error(e)}),()=>{t.unsubscribe(),this._nativeModuleWrapper.stopScan().catch(e=>{this._loggerService.error("stopDiscovering error",e)})}})}connect(i){return this._nativeModuleWrapper.connectDevice(i.deviceId).then(r=>r.map(({sessionId:t,transportDeviceModel:e})=>{const s=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(o=>{o.sessionId===t&&(i.onDisconnect(t),s.unsubscribe())});return new u({id:t,deviceModel:e,sendApdu:async(o,c=!1,a=-1)=>this._nativeModuleWrapper.sendApdu(t,o,c,a).catch(d=>p(new _(d))),transport:this.getIdentifier(),type:"USB"})})).catch(r=>p(new l(r)))}disconnect(i){return this._nativeModuleWrapper.disconnectDevice(i.connectedDevice.id).then(()=>b(void 0)).catch(r=>p(new g(r)))}}export{W as RNHidTransport};
2
2
  //# sourceMappingURL=RNHidTransport.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/transport/RNHidTransport.ts"],
4
- "sourcesContent": ["import {\n type ConnectError,\n type DeviceId,\n DisconnectError,\n type DisconnectHandler,\n type DmkError,\n type LoggerPublisherService,\n LogLevel,\n OpeningConnectionError,\n type Transport,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { getObservableOfArraysNewItems } from \"@api/helpers/getObservableOfArraysNewItems\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\n\nimport { HidTransportSendApduUnknownError } from \"./Errors\";\nimport { type NativeModuleWrapper } from \"./NativeModuleWrapper\";\n\nexport class RNHidTransport implements Transport {\n private _loggerService: LoggerPublisherService;\n\n constructor(\n private readonly _isSupported: boolean,\n private readonly _nativeModuleWrapper: NativeModuleWrapper,\n _loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._loggerService = _loggerServiceFactory(\"RNHidTransport\");\n this._nativeModuleWrapper.subscribeToTransportLogs().subscribe((log) => {\n const [logLevel, message, options] = log;\n const logMethod = {\n [LogLevel.Fatal]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Error]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Warning]: this._loggerService.warn.bind(this._loggerService),\n [LogLevel.Info]: this._loggerService.info.bind(this._loggerService),\n [LogLevel.Debug]: this._loggerService.debug.bind(this._loggerService),\n }[logLevel];\n logMethod(message, options);\n });\n }\n\n getIdentifier(): TransportIdentifier {\n return TRANSPORT_IDENTIFIER;\n }\n\n isSupported(): boolean {\n return this._isSupported;\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n const observable = new Observable<TransportDiscoveredDevice>(\n (subscriber) => {\n const subscription = getObservableOfArraysNewItems(\n this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),\n (device) => device.id,\n ).subscribe(subscriber);\n\n this._nativeModuleWrapper.startScan().catch((error) => {\n subscriber.error(error);\n this._loggerService.error(\"startDiscovering error\", error);\n });\n return () => subscription.unsubscribe();\n },\n );\n return observable;\n }\n\n stopDiscovering(): void {\n this._loggerService.debug(\"[stopDiscovering] called\");\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n this._loggerService.debug(\"[listenToAvailableDevices] called\");\n /**\n * NB: here we need to define the unsubscribe logic as there is no\n * \"stopListeningToKnownDevices\" method.\n * That's why we create a new observable rather than returning the one\n * returned by subscribeToDiscoveredDevicesEvents.\n */\n const observable = new Observable<TransportDiscoveredDevice[]>(\n (subscriber) => {\n const subscription = this._nativeModuleWrapper\n .subscribeToDiscoveredDevicesEvents()\n .subscribe((devices) => {\n this._loggerService.debug(\n \"[listenToAvailableDevices] devices discovered\",\n { data: { devices } },\n );\n subscriber.next(devices);\n });\n this._nativeModuleWrapper.startScan().catch((error) => {\n this._loggerService.error(\"startDiscovering error\", error);\n subscriber.error(error);\n });\n return () => {\n subscription.unsubscribe();\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n };\n },\n );\n return observable;\n }\n\n connect(_params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n return this._nativeModuleWrapper\n .connectDevice(_params.deviceId)\n .then((result) => {\n return result.map(\n ({ sessionId, transportDeviceModel: deviceModel }) => {\n const sub = this._nativeModuleWrapper\n .subscribeToDeviceDisconnectedEvents()\n .subscribe((device) => {\n if (device.sessionId === sessionId) {\n _params.onDisconnect(sessionId);\n sub.unsubscribe();\n }\n });\n\n return new TransportConnectedDevice({\n id: sessionId,\n deviceModel,\n sendApdu: async (\n apdu,\n triggersDisconnection = false,\n abortTimeout = -1,\n ) => {\n return this._nativeModuleWrapper\n .sendApdu(\n sessionId,\n apdu,\n triggersDisconnection,\n abortTimeout,\n )\n .catch((e) => Left(new HidTransportSendApduUnknownError(e)));\n },\n transport: this.getIdentifier(),\n type: \"USB\",\n });\n },\n );\n })\n .catch((error) => {\n return Left(new OpeningConnectionError(error));\n });\n }\n\n disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n return this._nativeModuleWrapper\n .disconnectDevice(_params.connectedDevice.id)\n .then(() => Right(undefined))\n .catch((error) => {\n return Left(new DisconnectError(error));\n });\n }\n}\n"],
5
- "mappings": "AAAA,OAGE,mBAAAA,EAIA,YAAAC,EACA,0BAAAC,EAEA,4BAAAC,MAGK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,MAAa,YACzC,OAAS,cAAAC,MAAkB,OAE3B,OAAS,iCAAAC,MAAqC,6CAC9C,OAAS,wBAAAC,MAA4B,0CAErC,OAAS,oCAAAC,MAAwC,WAG1C,MAAMC,CAAoC,CAG/C,YACmBC,EACAC,EACjBC,EACA,CAHiB,kBAAAF,EACA,0BAAAC,EAGjB,KAAK,eAAiBC,EAAsB,gBAAgB,EAC5D,KAAK,qBAAqB,yBAAyB,EAAE,UAAWC,GAAQ,CACtE,KAAM,CAACC,EAAUC,EAASC,CAAO,EAAIH,EAC/BI,EAAY,CAChB,CAACjB,EAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAACA,EAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAACA,EAAS,OAAO,EAAG,KAAK,eAAe,KAAK,KAAK,KAAK,cAAc,EACrE,CAACA,EAAS,IAAI,EAAG,KAAK,eAAe,KAAK,KAAK,KAAK,cAAc,EAClE,CAACA,EAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,CACtE,EAAEc,CAAQ,EACVG,EAAUF,EAASC,CAAO,CAC5B,CAAC,CACH,CAnBQ,eAqBR,eAAqC,CACnC,OAAOT,CACT,CAEA,aAAuB,CACrB,OAAO,KAAK,YACd,CAEA,kBAA0D,CAexD,OAdmB,IAAIF,E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EAEH,OAAO,IAAIzB,EAAyB,CAClC,GAAIuB,EACJ,YAAAC,EACA,SAAU,MACRE,EACAC,EAAwB,GACxBC,EAAe,KAER,KAAK,qBACT,SACCL,EACAG,EACAC,EACAC,CACF,EACC,MAAOC,GAAM5B,EAAK,IAAIK,EAAiCuB,CAAC,CAAC,CAAC,EAE/D,UAAW,KAAK,cAAc,EAC9B,KAAM,KACR,CAAC,CACH,CACF,CACD,EACA,MAAOV,GACClB,EAAK,IAAIF,EAAuBoB,CAAK,CAAC,CAC9C,CACL,CAEA,WAAWE,EAEyB,CAClC,OAAO,KAAK,qBACT,iBAAiBA,EAAQ,gBAAgB,EAAE,EAC3C,KAAK,IAAMnB,EAAM,MAAS,CAAC,EAC3B,MAAOiB,GACClB,EAAK,IAAIJ,EAAgBsB,CAAK,CAAC,CACvC,CACL,CACF",
4
+ "sourcesContent": ["import {\n type ConnectError,\n type DeviceId,\n DisconnectError,\n type DisconnectHandler,\n type DmkError,\n type LoggerPublisherService,\n LogLevel,\n OpeningConnectionError,\n type Transport,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { getObservableOfArraysNewItems } from \"@api/helpers/getObservableOfArraysNewItems\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\n\nimport { HidTransportSendApduUnknownError } from \"./Errors\";\nimport { type NativeModuleWrapper } from \"./NativeModuleWrapper\";\n\nexport class RNHidTransport implements Transport {\n private _loggerService: LoggerPublisherService;\n\n constructor(\n private readonly _isSupported: boolean,\n private readonly _nativeModuleWrapper: NativeModuleWrapper,\n _loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._loggerService = _loggerServiceFactory(\"RNHidTransport\");\n this._nativeModuleWrapper.subscribeToTransportLogs().subscribe((log) => {\n const [logLevel, message, options] = log;\n const logMethod = {\n [LogLevel.Fatal]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Error]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Warning]: this._loggerService.warn.bind(this._loggerService),\n [LogLevel.Info]: this._loggerService.info.bind(this._loggerService),\n [LogLevel.Debug]: this._loggerService.debug.bind(this._loggerService),\n }[logLevel];\n logMethod(message, options);\n });\n }\n\n getIdentifier(): TransportIdentifier {\n return TRANSPORT_IDENTIFIER;\n }\n\n isSupported(): boolean {\n return this._isSupported;\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n const observable = new Observable<TransportDiscoveredDevice>(\n (subscriber) => {\n const subscription = getObservableOfArraysNewItems(\n this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),\n (device) => device.id,\n ).subscribe(subscriber);\n\n this._nativeModuleWrapper.startScan().catch((error) => {\n subscriber.error(error);\n this._loggerService.error(\"startDiscovering error\", error);\n });\n return () => subscription.unsubscribe();\n },\n );\n return observable;\n }\n\n stopDiscovering(): void {\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n /**\n * NB: here we need to define the unsubscribe logic as there is no\n * \"stopListeningToKnownDevices\" method.\n * That's why we create a new observable rather than returning the one\n * returned by subscribeToDiscoveredDevicesEvents.\n */\n const observable = new Observable<TransportDiscoveredDevice[]>(\n (subscriber) => {\n const subscription = this._nativeModuleWrapper\n .subscribeToDiscoveredDevicesEvents()\n .subscribe((devices) => {\n subscriber.next(devices);\n });\n this._nativeModuleWrapper.startScan().catch((error) => {\n this._loggerService.error(\"startDiscovering error\", error);\n subscriber.error(error);\n });\n return () => {\n subscription.unsubscribe();\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n };\n },\n );\n return observable;\n }\n\n connect(_params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n return this._nativeModuleWrapper\n .connectDevice(_params.deviceId)\n .then((result) => {\n return result.map(\n ({ sessionId, transportDeviceModel: deviceModel }) => {\n const sub = this._nativeModuleWrapper\n .subscribeToDeviceDisconnectedEvents()\n .subscribe((device) => {\n if (device.sessionId === sessionId) {\n _params.onDisconnect(sessionId);\n sub.unsubscribe();\n }\n });\n\n return new TransportConnectedDevice({\n id: sessionId,\n deviceModel,\n sendApdu: async (\n apdu,\n triggersDisconnection = false,\n abortTimeout = -1,\n ) => {\n return this._nativeModuleWrapper\n .sendApdu(\n sessionId,\n apdu,\n triggersDisconnection,\n abortTimeout,\n )\n .catch((e) => Left(new HidTransportSendApduUnknownError(e)));\n },\n transport: this.getIdentifier(),\n type: \"USB\",\n });\n },\n );\n })\n .catch((error) => {\n return Left(new OpeningConnectionError(error));\n });\n }\n\n disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n return this._nativeModuleWrapper\n .disconnectDevice(_params.connectedDevice.id)\n .then(() => Right(undefined))\n .catch((error) => {\n return Left(new DisconnectError(error));\n });\n }\n}\n"],
5
+ "mappings": "AAAA,OAGE,mBAAAA,EAIA,YAAAC,EACA,0BAAAC,EAEA,4BAAAC,MAGK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,MAAa,YACzC,OAAS,cAAAC,MAAkB,OAE3B,OAAS,iCAAAC,MAAqC,6CAC9C,OAAS,wBAAAC,MAA4B,0CAErC,OAAS,oCAAAC,MAAwC,WAG1C,MAAMC,CAAoC,CAG/C,YACmBC,EACAC,EACjBC,EACA,CAHiB,kBAAAF,EACA,0BAAAC,EAGjB,KAAK,eAAiBC,EAAsB,gBAAgB,EAC5D,KAAK,qBAAqB,yBAAyB,EAAE,UAAWC,GAAQ,CACtE,KAAM,CAACC,EAAUC,EAASC,CAAO,EAAIH,EAC/BI,EAAY,CAChB,CAACjB,EAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,c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1D,CAAC,CACH,CACF,CACF,CAEF,CAEA,QAAQE,EAGoD,CAC1D,OAAO,KAAK,qBACT,cAAcA,EAAQ,QAAQ,EAC9B,KAAMC,GACEA,EAAO,IACZ,CAAC,CAAE,UAAAC,EAAW,qBAAsBC,CAAY,IAAM,CACpD,MAAMC,EAAM,KAAK,qBACd,oCAAoC,EACpC,UAAWP,GAAW,CACjBA,EAAO,YAAcK,IACvBF,EAAQ,aAAaE,CAAS,EAC9BE,EAAI,YAAY,EAEpB,CAAC,EAEH,OAAO,IAAIzB,EAAyB,CAClC,GAAIuB,EACJ,YAAAC,EACA,SAAU,MACRE,EACAC,EAAwB,GACxBC,EAAe,KAER,KAAK,qBACT,SACCL,EACAG,EACAC,EACAC,CACF,EACC,MAAOC,GAAM5B,EAAK,IAAIK,EAAiCuB,CAAC,CAAC,CAAC,EAE/D,UAAW,KAAK,cAAc,EAC9B,KAAM,KACR,CAAC,CACH,CACF,CACD,EACA,MAAOV,GACClB,EAAK,IAAIF,EAAuBoB,CAAK,CAAC,CAC9C,CACL,CAEA,WAAWE,EAEyB,CAClC,OAAO,KAAK,qBACT,iBAAiBA,EAAQ,gBAAgB,EAAE,EAC3C,KAAK,IAAMnB,EAAM,MAAS,CAAC,EAC3B,MAAOiB,GACClB,EAAK,IAAIJ,EAAgBsB,CAAK,CAAC,CACvC,CACL,CACF",
6
6
  "names": ["DisconnectError", "LogLevel", "OpeningConnectionError", "TransportConnectedDevice", "Left", "Right", "Observable", "getObservableOfArraysNewItems", "TRANSPORT_IDENTIFIER", "HidTransportSendApduUnknownError", "RNHidTransport", "_isSupported", "_nativeModuleWrapper", "_loggerServiceFactory", "log", "logLevel", "message", "options", "logMethod", "subscriber", "subscription", "device", "error", "devices", "_params", "result", "sessionId", "deviceModel", "sub", "apdu", "triggersDisconnection", "abortTimeout", "e"]
7
7
  }
package/lib/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{RNHidTransportFactory as t}from"./api/RNHidTransportFactory";import{TRANSPORT_IDENTIFIER as a}from"./api/transport/rnHidTransportIdentifier";export{t as RNHidTransportFactory,a as rnHidTransportIdentifier};
1
+ import{RNHidTransportFactory as n}from"./api/RNHidTransportFactory";import{HidTransportSendApduUnknownError as p}from"./api/transport/Errors";import{TRANSPORT_IDENTIFIER as e}from"./api/transport/rnHidTransportIdentifier";export{p as HidTransportSendApduUnknownError,n as RNHidTransportFactory,e as rnHidTransportIdentifier};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export { RNHidTransportFactory } from \"@api/RNHidTransportFactory\";\nexport { TRANSPORT_IDENTIFIER as rnHidTransportIdentifier } from \"@api/transport/rnHidTransportIdentifier\";\n"],
5
- "mappings": "AAAA,OAAS,yBAAAA,MAA6B,6BACtC,OAAiC,wBAAxBC,MAAwD",
6
- "names": ["RNHidTransportFactory", "TRANSPORT_IDENTIFIER"]
4
+ "sourcesContent": ["export { RNHidTransportFactory } from \"@api/RNHidTransportFactory\";\nexport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nexport { TRANSPORT_IDENTIFIER as rnHidTransportIdentifier } from \"@api/transport/rnHidTransportIdentifier\";\n"],
5
+ "mappings": "AAAA,OAAS,yBAAAA,MAA6B,6BACtC,OAAS,oCAAAC,MAAwC,wBACjD,OAAiC,wBAAxBC,MAAwD",
6
+ "names": ["RNHidTransportFactory", "HidTransportSendApduUnknownError", "TRANSPORT_IDENTIFIER"]
7
7
  }
@@ -1,20 +1,30 @@
1
1
  {
2
- "name": "@ledgerhq/device-transport-kit-react-native-hid",
3
- "version": "1.0.0",
4
- "license": "Apache-2.0",
5
- "private": false,
6
- "react-native": "src/index.ts",
7
- "nativePackage": true,
2
+ "dependencies": {
3
+ "@sentry/minimal": "catalog:",
4
+ "purify-ts": "catalog:",
5
+ "uuid": "catalog:"
6
+ },
7
+ "devDependencies": {
8
+ "@ledgerhq/device-management-kit": "workspace:*",
9
+ "@ledgerhq/eslint-config-dsdk": "workspace:*",
10
+ "@ledgerhq/ldmk-tool": "workspace:*",
11
+ "@ledgerhq/prettier-config-dsdk": "workspace:*",
12
+ "@ledgerhq/tsconfig-dsdk": "workspace:*",
13
+ "@ledgerhq/vitest-config-dmk": "workspace:*",
14
+ "@types/uuid": "catalog:",
15
+ "react-native": "catalog:",
16
+ "rxjs": "catalog:"
17
+ },
8
18
  "exports": {
9
19
  ".": {
10
- "types": "./lib/types/index.d.ts",
11
20
  "import": "./lib/esm/index.js",
12
- "require": "./lib/cjs/index.js"
21
+ "require": "./lib/cjs/index.js",
22
+ "types": "./lib/types/index.d.ts"
13
23
  },
14
24
  "./*": {
15
- "types": "./lib/types/*",
16
25
  "import": "./lib/esm/*",
17
- "require": "./lib/cjs/*"
26
+ "require": "./lib/cjs/*",
27
+ "types": "./lib/types/*"
18
28
  }
19
29
  },
20
30
  "files": [
@@ -26,41 +36,35 @@
26
36
  "!android/gradlew.bat",
27
37
  "!android/local.properties"
28
38
  ],
39
+ "license": "Apache-2.0",
40
+ "name": "@ledgerhq/device-transport-kit-react-native-hid",
41
+ "nativePackage": true,
42
+ "peerDependencies": {
43
+ "@ledgerhq/device-management-kit": "workspace:*",
44
+ "react-native": ">0.74.1",
45
+ "rxjs": "catalog:"
46
+ },
47
+ "private": false,
48
+ "react-native": "src/index.ts",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "https://github.com/LedgerHQ/device-sdk-ts.git"
52
+ },
29
53
  "scripts": {
30
- "prebuild": "rimraf lib",
31
54
  "build": "pnpm ldmk-tool build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
32
55
  "dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
33
- "watch:builds": "pnpm ldmk-tool watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
34
- "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
35
56
  "lint": "eslint src/**/*.ts",
36
57
  "lint:fix": "pnpm lint --fix",
37
58
  "postpack": "find . -name '*.tgz' -exec cp {} ../../../dist/ \\; ",
59
+ "prebuild": "rimraf lib",
38
60
  "prettier": "prettier . --check",
39
61
  "prettier:fix": "prettier . --write",
40
- "typecheck": "tsc --noEmit",
41
62
  "test": "vitest run --passWithNoTests",
63
+ "test:coverage": "vitest run --coverage --passWithNoTests",
42
64
  "test:watch": "vitest --passWithNoTests",
43
- "test:coverage": "vitest run --coverage --passWithNoTests"
44
- },
45
- "dependencies": {
46
- "@sentry/minimal": "catalog:",
47
- "purify-ts": "catalog:",
48
- "uuid": "catalog:"
49
- },
50
- "devDependencies": {
51
- "@ledgerhq/device-management-kit": "workspace:*",
52
- "@ledgerhq/eslint-config-dsdk": "workspace:*",
53
- "@ledgerhq/ldmk-tool": "workspace:*",
54
- "@ledgerhq/vitest-config-dmk": "workspace:*",
55
- "@ledgerhq/prettier-config-dsdk": "workspace:*",
56
- "@ledgerhq/tsconfig-dsdk": "workspace:*",
57
- "@types/uuid": "catalog:",
58
- "react-native": "catalog:",
59
- "rxjs": "catalog:"
65
+ "typecheck": "tsc --noEmit",
66
+ "watch:builds": "pnpm ldmk-tool watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
67
+ "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
60
68
  },
61
- "peerDependencies": {
62
- "@ledgerhq/device-management-kit": "workspace:*",
63
- "react-native": ">0.74.1",
64
- "rxjs": "catalog:"
65
- }
69
+ "version": "0.0.0-no-issue-npmjs-attestation-1-20251126170021"
66
70
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mapper.d.ts","sourceRoot":"","sources":["../../../../src/api/bridge/mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,qBAAqB,EAG1B,KAAK,SAAS,EAGd,KAAK,cAAc,EAEnB,KAAK,oBAAoB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B,EAAE,mBAAmB,EAC1D,qBAAqB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAgBhE,aAAa,IAAI,mBAAmB;IAIpC,WAAW,IAAI,OAAO;IAItB,gBAAgB,IAAI,UAAU,CAAC,yBAAyB,CAAC;IAkBzD,eAAe,IAAI,IAAI;IAMvB,wBAAwB,IAAI,UAAU,CAAC,yBAAyB,EAAE,CAAC;IA6BnE,OAAO,CAAC,OAAO,EAAE;QACf,QAAQ,EAAE,QAAQ,CAAC;QACnB,YAAY,EAAE,iBAAiB,CAAC;KACjC,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;IA2C3D,UAAU,CAAC,OAAO,EAAE;QAClB,eAAe,EAAE,wBAAwB,CAAC;KAC3C,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;CAQpC"}
@@ -1,3 +1,4 @@
1
1
  export { RNHidTransportFactory } from "./api/RNHidTransportFactory";
2
+ export { HidTransportSendApduUnknownError } from "./api/transport/Errors";
2
3
  export { TRANSPORT_IDENTIFIER as rnHidTransportIdentifier } from "./api/transport/rnHidTransportIdentifier";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,oBAAoB,IAAI,wBAAwB,EAAE,MAAM,yCAAyC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,oBAAoB,IAAI,wBAAwB,EAAE,MAAM,yCAAyC,CAAC"}