@ledgerhq/device-transport-kit-speculos 0.0.0-e2e-speculos-20250905084020 → 0.0.0-e2e-speculos-20250908083159

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/lib/cjs/src/api/E2eSpeculosTransport.js +2 -0
  2. package/lib/cjs/src/api/E2eSpeculosTransport.js.map +7 -0
  3. package/lib/cjs/src/api/SpeculosTransport.js +1 -1
  4. package/lib/cjs/src/api/SpeculosTransport.js.map +3 -3
  5. package/lib/cjs/src/index.js +1 -1
  6. package/lib/cjs/src/index.js.map +2 -2
  7. package/lib/cjs/src/internal/datasource/E2eHttpSpeculosDatasource.js +3 -0
  8. package/lib/cjs/src/internal/datasource/E2eHttpSpeculosDatasource.js.map +7 -0
  9. package/lib/cjs/src/internal/datasource/E2eSpeculosDatasource.js +2 -0
  10. package/lib/cjs/src/internal/datasource/E2eSpeculosDatasource.js.map +7 -0
  11. package/lib/cjs/src/internal/datasource/HttpSpeculosDatasource.js +1 -1
  12. package/lib/cjs/src/internal/datasource/HttpSpeculosDatasource.js.map +3 -3
  13. package/lib/cjs/src/internal/datasource/SpeculosDatasource.js +1 -1
  14. package/lib/cjs/src/internal/datasource/SpeculosDatasource.js.map +1 -1
  15. package/lib/cjs/src/internal/utils/axiosInstances.js +2 -0
  16. package/lib/cjs/src/internal/utils/axiosInstances.js.map +7 -0
  17. package/lib/esm/src/api/E2eSpeculosTransport.js +2 -0
  18. package/lib/esm/src/api/E2eSpeculosTransport.js.map +7 -0
  19. package/lib/esm/src/api/SpeculosTransport.js +1 -1
  20. package/lib/esm/src/api/SpeculosTransport.js.map +3 -3
  21. package/lib/esm/src/index.js +1 -1
  22. package/lib/esm/src/index.js.map +2 -2
  23. package/lib/esm/src/internal/datasource/E2eHttpSpeculosDatasource.js +3 -0
  24. package/lib/esm/src/internal/datasource/E2eHttpSpeculosDatasource.js.map +7 -0
  25. package/lib/esm/src/internal/datasource/E2eSpeculosDatasource.js +1 -0
  26. package/lib/esm/src/internal/datasource/E2eSpeculosDatasource.js.map +7 -0
  27. package/lib/esm/src/internal/datasource/HttpSpeculosDatasource.js +1 -1
  28. package/lib/esm/src/internal/datasource/HttpSpeculosDatasource.js.map +3 -3
  29. package/lib/esm/src/internal/utils/axiosInstances.js +2 -0
  30. package/lib/esm/src/internal/utils/axiosInstances.js.map +7 -0
  31. package/lib/types/src/api/{QuietSpeculosTransport.d.ts → E2eSpeculosTransport.d.ts} +3 -3
  32. package/lib/types/src/api/E2eSpeculosTransport.d.ts.map +1 -0
  33. package/lib/types/src/api/SpeculosTransport.d.ts +2 -3
  34. package/lib/types/src/api/SpeculosTransport.d.ts.map +1 -1
  35. package/lib/types/src/index.d.ts +1 -1
  36. package/lib/types/src/index.d.ts.map +1 -1
  37. package/lib/types/src/internal/datasource/{HttpLegacySpeculosDatasource.d.ts → E2eHttpSpeculosDatasource.d.ts} +5 -3
  38. package/lib/types/src/internal/datasource/E2eHttpSpeculosDatasource.d.ts.map +1 -0
  39. package/lib/types/src/internal/datasource/E2eSpeculosDatasource.d.ts +7 -0
  40. package/lib/types/src/internal/datasource/E2eSpeculosDatasource.d.ts.map +1 -0
  41. package/lib/types/src/internal/datasource/HttpSpeculosDatasource.d.ts +1 -0
  42. package/lib/types/src/internal/datasource/HttpSpeculosDatasource.d.ts.map +1 -1
  43. package/lib/types/src/internal/datasource/SpeculosDatasource.d.ts +1 -0
  44. package/lib/types/src/internal/datasource/SpeculosDatasource.d.ts.map +1 -1
  45. package/lib/types/src/internal/utils/axiosInstances.d.ts +4 -0
  46. package/lib/types/src/internal/utils/axiosInstances.d.ts.map +1 -0
  47. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  48. package/package.json +5 -5
  49. package/lib/cjs/src/api/QuietSpeculosTransport.js +0 -2
  50. package/lib/cjs/src/api/QuietSpeculosTransport.js.map +0 -7
  51. package/lib/cjs/src/internal/datasource/HttpLegacySpeculosDatasource.js +0 -3
  52. package/lib/cjs/src/internal/datasource/HttpLegacySpeculosDatasource.js.map +0 -7
  53. package/lib/esm/src/api/QuietSpeculosTransport.js +0 -2
  54. package/lib/esm/src/api/QuietSpeculosTransport.js.map +0 -7
  55. package/lib/esm/src/internal/datasource/HttpLegacySpeculosDatasource.js +0 -3
  56. package/lib/esm/src/internal/datasource/HttpLegacySpeculosDatasource.js.map +0 -7
  57. package/lib/types/src/api/QuietSpeculosTransport.d.ts.map +0 -1
  58. package/lib/types/src/internal/datasource/HttpLegacySpeculosDatasource.d.ts.map +0 -1
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var m=(s,e)=>{for(var r in e)a(s,r,{get:e[r],enumerable:!0})},y=(s,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of D(e))!h.call(s,t)&&t!==r&&a(s,t,{get:()=>e[t],enumerable:!(o=v(e,t))||o.enumerable});return s};var S=s=>y(a({},"__esModule",{value:!0}),s);var f={};m(f,{E2eSpeculosTransport:()=>g,e2eSpeculosTransportFactory:()=>b});module.exports=S(f);var n=require("@ledgerhq/device-management-kit"),i=require("purify-ts"),d=require("rxjs"),u=require("../../src/internal/datasource/E2eHttpSpeculosDatasource"),l=require("./SpeculosTransport");class g{logger;identifier=l.speculosIdentifier;_speculosDataSource;connectedDevice=null;speculosDevice={id:"SpeculosID",deviceModel:{id:n.DeviceModelId.STAX,productName:"Speculos - App Name - version",usbProductId:16,bootloaderUsbProductId:1,getBlockSize(){return 32},blockSize:32,usbOnly:!0,memorySize:320*1024,masks:[823132160]},transport:this.identifier};constructor(e,r,o){this.logger=e("E2eSpeculosTransport"),this._speculosDataSource=new u.E2eHttpSpeculosDatasource(o,1e4,"ldmk-transport-speculos")}isSupported(){return!0}getIdentifier(){return this.identifier}listenToAvailableDevices(){return(0,d.from)([[this.speculosDevice]])}startDiscovering(){return this.logger.debug("startDiscovering"),(0,d.from)([this.speculosDevice])}stopDiscovering(){this.logger.debug("stopDiscovering")}async connect(e){this.logger.debug("connect");try{const r=await this._speculosDataSource.postAdpu("B0010000");this.logger.debug(`Hex Response: ${r}`);const o=this.createApduResponse(r),t=new n.ApduParser(o);t.extract8BitUInt();const c=t.encodeToString(t.extractFieldLVEncoded()),p=t.encodeToString(t.extractFieldLVEncoded());this.logger.debug(`App Name: ${c} and version ${p}`),this.speculosDevice.deviceModel.productName=`Speculos - ${c} - ${p}`}catch{this.logger.debug("Unable to fetch app name and version from Speculos")}try{const r={sendApdu:o=>this.sendApdu(e.deviceId,e.onDisconnect,o),deviceModel:this.speculosDevice.deviceModel,transport:this.identifier,id:"SpeculosID",type:"USB"};return this.connectedDevice=r,(0,i.Right)(r)}catch(r){return(0,i.Left)(new n.OpeningConnectionError(r))}}async disconnect(e){return this.logger.debug("disconnect"),this.connectedDevice=null,Promise.resolve((0,i.Right)(void 0))}async sendApdu(e,r,o){try{const t=(0,n.bufferToHexaString)(o).substring(2).toUpperCase();this.logger.debug(`[E2eSpeculosTransport] send APDU: ${t}`);const c=await this._speculosDataSource.postAdpu(t),p=this.createApduResponse(c);return(0,i.Right)(p)}catch(t){return this.connectedDevice&&(this.logger.debug("disconnecting due to APDU error"),r(e),await this.disconnect({connectedDevice:this.connectedDevice})),(0,i.Left)(new n.GeneralDmkError(t))}}createApduResponse(e){const r=e.slice(-4),o=e.slice(0,-4);return this.logger.debug(`[E2eSpeculosTransport] Status code hex: ${r}`),this.logger.debug(`[E2eSpeculosTransport] data hex: ${o}`),{statusCode:this.fromHexString(r),data:this.fromHexString(o)}}fromHexString(e){return e?new Uint8Array(e.match(/.{1,2}/g).map(r=>parseInt(r,16))):new Uint8Array(0)}}const b=(s="http://127.0.0.1:5000")=>({config:e,loggerServiceFactory:r})=>new g(r,e,s);0&&(module.exports={E2eSpeculosTransport,e2eSpeculosTransportFactory});
2
+ //# sourceMappingURL=E2eSpeculosTransport.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/api/E2eSpeculosTransport.ts"],
4
+ "sourcesContent": ["import {\n ApduParser,\n type ApduResponse,\n bufferToHexaString,\n type ConnectError,\n type DeviceId,\n DeviceModelId,\n type DisconnectHandler,\n type DmkConfig,\n type DmkError,\n GeneralDmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n type TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { type E2eSpeculosDatasource } from \"@internal/datasource/E2eSpeculosDatasource\";\nimport { E2eHttpSpeculosDatasource } from \"@root/src/internal/datasource/E2eHttpSpeculosDatasource\";\n\nimport { speculosIdentifier } from \"./SpeculosTransport\";\n\nexport class E2eSpeculosTransport implements Transport {\n private logger: LoggerPublisherService;\n private readonly identifier: TransportIdentifier = speculosIdentifier;\n\n private readonly _speculosDataSource: E2eSpeculosDatasource;\n\n private connectedDevice: TransportConnectedDevice | null = null;\n\n private readonly speculosDevice: TransportDiscoveredDevice = {\n id: \"SpeculosID\",\n deviceModel: {\n id: DeviceModelId.STAX,\n productName: \"Speculos - App Name - version\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n getBlockSize() {\n return 32;\n },\n blockSize: 32,\n usbOnly: true,\n memorySize: 320 * 1024,\n masks: [0x31100000],\n },\n transport: this.identifier,\n };\n\n constructor(\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n _config: DmkConfig,\n speculosUrl: string,\n ) {\n this.logger = loggerServiceFactory(\"E2eSpeculosTransport\");\n this._speculosDataSource = new E2eHttpSpeculosDatasource(\n speculosUrl,\n 10000,\n \"ldmk-transport-speculos\",\n );\n }\n\n isSupported(): boolean {\n return true;\n }\n\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([[this.speculosDevice]]);\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n this.logger.debug(\"startDiscovering\");\n return from([this.speculosDevice]);\n }\n\n stopDiscovering(): void {\n this.logger.debug(\"stopDiscovering\");\n }\n\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n this.logger.debug(\"connect\");\n\n try {\n const hexResponse = await this._speculosDataSource.postAdpu(\"B0010000\");\n this.logger.debug(`Hex Response: ${hexResponse}`);\n const apduResponse = this.createApduResponse(hexResponse);\n const parser = new ApduParser(apduResponse);\n parser.extract8BitUInt();\n const appName = parser.encodeToString(parser.extractFieldLVEncoded());\n const appVersion = parser.encodeToString(parser.extractFieldLVEncoded());\n this.logger.debug(`App Name: ${appName} and version ${appVersion}`);\n\n this.speculosDevice.deviceModel.productName = `Speculos - ${appName} - ${appVersion}`;\n } catch {\n this.logger.debug(\"Unable to fetch app name and version from Speculos\");\n }\n\n try {\n const connectedDevice: TransportConnectedDevice = {\n sendApdu: (apdu: Uint8Array) =>\n this.sendApdu(params.deviceId, params.onDisconnect, apdu),\n deviceModel: this.speculosDevice.deviceModel,\n transport: this.identifier,\n id: \"SpeculosID\",\n type: \"USB\",\n };\n\n this.connectedDevice = connectedDevice;\n return Right(connectedDevice);\n } catch (error) {\n return Left(new OpeningConnectionError(error as Error));\n }\n }\n\n async disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n this.logger.debug(\"disconnect\");\n this.connectedDevice = null;\n return Promise.resolve(Right(undefined));\n }\n\n async sendApdu(\n deviceId: DeviceId,\n onDisconnect: DisconnectHandler,\n apdu: Uint8Array,\n ): Promise<Either<DmkError, ApduResponse>> {\n try {\n const hex = bufferToHexaString(apdu).substring(2).toUpperCase();\n this.logger.debug(`[E2eSpeculosTransport] send APDU: ${hex}`);\n const hexResponse = await this._speculosDataSource.postAdpu(hex);\n const resp = this.createApduResponse(hexResponse);\n return Right(resp);\n } catch (error) {\n if (this.connectedDevice) {\n this.logger.debug(\"disconnecting due to APDU error\");\n onDisconnect(deviceId);\n await this.disconnect({ connectedDevice: this.connectedDevice });\n }\n return Left(new GeneralDmkError(error as Error));\n }\n }\n\n private createApduResponse(hexApdu: string): ApduResponse {\n const sw = hexApdu.slice(-4);\n const payload = hexApdu.slice(0, -4);\n this.logger.debug(`[E2eSpeculosTransport] Status code hex: ${sw}`);\n this.logger.debug(`[E2eSpeculosTransport] data hex: ${payload}`);\n return {\n statusCode: this.fromHexString(sw),\n data: this.fromHexString(payload),\n };\n }\n\n private fromHexString(hexString: string): Uint8Array {\n if (!hexString) return new Uint8Array(0);\n return new Uint8Array(\n hexString.match(/.{1,2}/g)!.map((b) => parseInt(b, 16)),\n );\n }\n}\n\nexport const e2eSpeculosTransportFactory: (\n speculosUrl?: string,\n) => TransportFactory =\n (speculosUrl = \"http://127.0.0.1:5000\") =>\n ({ config, loggerServiceFactory }) =>\n new E2eSpeculosTransport(loggerServiceFactory, config, speculosUrl);\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,0BAAAE,EAAA,gCAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAkBO,2CACPC,EAAyC,qBACzCC,EAAsC,gBAGtCC,EAA0C,mEAE1CC,EAAmC,+BAE5B,MAAMP,CAA0C,CAC7C,OACS,WAAkC,qBAElC,oBAET,gBAAmD,KAE1C,eAA4C,CAC3D,GAAI,aACJ,YAAa,CACX,GAAI,gBAAc,KAClB,YAAa,gCACb,aAAc,GACd,uBAAwB,EACxB,cAAe,CACb,MAAO,GACT,EACA,UAAW,GACX,QAAS,GACT,WAAY,IAAM,KAClB,MAAO,CAAC,SAAU,CACpB,EACA,UAAW,KAAK,UAClB,EAEA,YACEQ,EACAC,EACAC,EACA,CACA,KAAK,OAASF,EAAqB,sBAAsB,EACzD,KAAK,oBAAsB,IAAI,4BAC7BE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AAC,CACzC,CAEA,MAAM,SACJC,EACAC,EACAJ,EACyC,CACzC,GAAI,CACF,MAAMK,KAAM,sBAAmBL,CAAI,EAAE,UAAU,CAAC,EAAE,YAAY,EAC9D,KAAK,OAAO,MAAM,qCAAqCK,CAAG,EAAE,EAC5D,MAAMX,EAAc,MAAM,KAAK,oBAAoB,SAASW,CAAG,EACzDC,EAAO,KAAK,mBAAmBZ,CAAW,EAChD,SAAO,SAAMY,CAAI,CACnB,OAASL,EAAO,CACd,OAAI,KAAK,kBACP,KAAK,OAAO,MAAM,iCAAiC,EACnDG,EAAaD,CAAQ,EACrB,MAAM,KAAK,WAAW,CAAE,gBAAiB,KAAK,eAAgB,CAAC,MAE1D,QAAK,IAAI,kBAAgBF,CAAc,CAAC,CACjD,CACF,CAEQ,mBAAmBM,EAA+B,CACxD,MAAMC,EAAKD,EAAQ,MAAM,EAAE,EACrBE,EAAUF,EAAQ,MAAM,EAAG,EAAE,EACnC,YAAK,OAAO,MAAM,2CAA2CC,CAAE,EAAE,EACjE,KAAK,OAAO,MAAM,oCAAoCC,CAAO,EAAE,EACxD,CACL,WAAY,KAAK,cAAcD,CAAE,EACjC,KAAM,KAAK,cAAcC,CAAO,CAClC,CACF,CAEQ,cAAcC,EAA+B,CACnD,OAAKA,EACE,IAAI,WACTA,EAAU,MAAM,SAAS,EAAG,IAAKC,GAAM,SAASA,EAAG,EAAE,CAAC,CACxD,EAHuB,IAAI,WAAW,CAAC,CAIzC,CACF,CAEO,MAAM5B,EAGX,CAACS,EAAc,0BACf,CAAC,CAAE,OAAAoB,EAAQ,qBAAAtB,CAAqB,IAC9B,IAAIR,EAAqBQ,EAAsBsB,EAAQpB,CAAW",
6
+ "names": ["E2eSpeculosTransport_exports", "__export", "E2eSpeculosTransport", "e2eSpeculosTransportFactory", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_rxjs", "import_E2eHttpSpeculosDatasource", "import_SpeculosTransport", "loggerServiceFactory", "_config", "speculosUrl", "params", "hexResponse", "apduResponse", "parser", "appName", "appVersion", "connectedDevice", "apdu", "error", "_params", "deviceId", "onDisconnect", "hex", "resp", "hexApdu", "sw", "payload", "hexString", "b", "config"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var I=(o,e)=>{for(var t in e)d(o,t,{get:e[t],enumerable:!0})},T=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of b(e))!S.call(o,r)&&r!==t&&d(o,r,{get:()=>e[r],enumerable:!(n=f(e,r))||n.enumerable});return o};var E=o=>T(d({},"__esModule",{value:!0}),o);var C={};I(C,{SpeculosTransport:()=>h,speculosIdentifier:()=>D,speculosTransportFactory:()=>A});module.exports=E(C);var i=require("@ledgerhq/device-management-kit"),u=require("axios"),c=require("purify-ts"),l=require("rxjs"),g=require("../internal/datasource/HttpLegacySpeculosDatasource"),v=require("../internal/datasource/HttpSpeculosDatasource");const D="SPECULOS_HTTP_TRANSPORT";class h{constructor(e,t,n,r){this.legacyE2ECompatibility=r;this.logger=e("SpeculosTransport"),this._speculosDataSource=this.legacyE2ECompatibility?new g.HttpLegacySpeculosDatasource(n):new v.HttpSpeculosDatasource(n)}logger;identifier=D;_speculosDataSource;connectedDevice=null;disconnectInterval=null;speculosDevice={id:"SpeculosID",deviceModel:{id:i.DeviceModelId.STAX,productName:"Speculos - App Name - version",usbProductId:16,bootloaderUsbProductId:1,getBlockSize(){return 32},blockSize:32,usbOnly:!0,memorySize:320*1024,masks:[823132160]},transport:this.identifier};isSupported(){return!0}getIdentifier(){return this.identifier}listenToAvailableDevices(){return(0,l.from)([[this.speculosDevice]])}startDiscovering(){return this.logger.debug("startDiscovering"),(0,l.from)([this.speculosDevice])}stopDiscovering(){this.logger.debug("stopDiscovering")}async connect(e){this.logger.debug("connect");const t=await this._speculosDataSource.postAdpu("B0010000");this.logger.debug(`Hex Response: ${t}`);const n=this.createApduResponse(t),r=new i.ApduParser(n);r.extract8BitUInt();const s=r.encodeToString(r.extractFieldLVEncoded()),a=r.encodeToString(r.extractFieldLVEncoded());this.logger.debug(`App Name: ${s} and version ${a}`);const y=e.deviceId;try{const p={sendApdu:m=>this.sendApdu(y,e.deviceId,e.onDisconnect,m),deviceModel:{...this.speculosDevice.deviceModel,productName:`Speculos - ${s} - ${a}`,getBlockSize(){return 32}},transport:this.identifier,id:"SpeculosID",type:"USB"};return this.connectedDevice=p,this.legacyE2ECompatibility||this.listenForDisconnect(e.onDisconnect,e.deviceId),(0,c.Right)(p)}catch(p){return(0,c.Left)(new i.OpeningConnectionError(p))}}async disconnect(e){return this.logger.debug("disconnect"),this.connectedDevice=null,Promise.resolve((0,c.Right)(void 0))}async sendApdu(e,t,n,r){try{const s=(0,i.bufferToHexaString)(r).substring(2);this.logger.debug(`send APDU: ${s}`);const a=await this._speculosDataSource.postAdpu(s);return(0,c.Right)(this.createApduResponse(a))}catch(s){return this.connectedDevice&&(this.logger.debug("disconnecting"),n(t),this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval)),(0,c.Left)(new i.GeneralDmkError(s))}}createApduResponse(e){return this.logger.debug(`Status code hex: ${e.substring(e.length-4,e.length)}`),this.logger.debug(`data hex: ${e.substring(0,e.length-4)}`),{statusCode:this.fromHexString(e.substring(e.length-4,e.length)),data:this.fromHexString(e.substring(0,e.length-4))}}fromHexString(e){return e?new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16))):Uint8Array.from([])}listenForDisconnect(e,t){this.disconnectInterval=setInterval(async()=>{try{await this._speculosDataSource.postAdpu("B0010000")}catch(n){if(!(n instanceof u.AxiosError))return;this.logger.info(`Network error, disconnecting speculos device ${t}`),e(t),this.connectedDevice&&await this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval)}},2e3)}}const A=(o="http://127.0.0.1:5000",e=!1)=>({config:t,loggerServiceFactory:n})=>new h(n,t,o,e);0&&(module.exports={SpeculosTransport,speculosIdentifier,speculosTransportFactory});
1
+ "use strict";var l=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var f=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},y=(n,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of b(e))!m.call(n,r)&&r!==t&&l(n,r,{get:()=>e[r],enumerable:!(o=S(e,r))||o.enumerable});return n};var I=n=>y(l({},"__esModule",{value:!0}),n);var A={};f(A,{SpeculosTransport:()=>D,speculosIdentifier:()=>g,speculosTransportFactory:()=>T});module.exports=I(A);var s=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),u=require("rxjs"),v=require("../internal/datasource/HttpSpeculosDatasource");const g="SPECULOS_HTTP_TRANSPORT";class D{logger;identifier=g;_speculosDataSource;connectedDevice=null;disconnectInterval=null;speculosDevice={id:"SpeculosID",deviceModel:{id:s.DeviceModelId.STAX,productName:"Speculos - App Name - version",usbProductId:16,bootloaderUsbProductId:1,getBlockSize(){return 32},blockSize:32,usbOnly:!0,memorySize:320*1024,masks:[823132160]},transport:this.identifier};constructor(e,t,o){this.logger=e("SpeculosTransport"),this._speculosDataSource=new v.HttpSpeculosDatasource(o)}isSupported(){return!0}getIdentifier(){return this.identifier}listenToAvailableDevices(){return(0,u.from)([[this.speculosDevice]])}startDiscovering(){return this.logger.debug("startDiscovering"),(0,u.from)([this.speculosDevice])}stopDiscovering(){this.logger.debug("stopDiscovering")}async connect(e){this.logger.debug("connect");const t=await this._speculosDataSource.postAdpu("B0010000");this.logger.debug(`Hex Response: ${t}`);const o=this.createApduResponse(t),r=new s.ApduParser(o);r.extract8BitUInt();const i=r.encodeToString(r.extractFieldLVEncoded()),a=r.encodeToString(r.extractFieldLVEncoded());this.logger.debug(`App Name: ${i} and version ${a}`);const p=e.deviceId;try{const d={sendApdu:h=>this.sendApdu(p,e.deviceId,e.onDisconnect,h),deviceModel:{...this.speculosDevice.deviceModel,productName:`Speculos - ${i} - ${a}`,getBlockSize(){return 32}},transport:this.identifier,id:"SpeculosID",type:"USB"};return this.connectedDevice=d,this.listenForDisconnect(e.onDisconnect,e.deviceId),(0,c.Right)(d)}catch(d){return(0,c.Left)(new s.OpeningConnectionError(d))}}async disconnect(e){return this.logger.debug("disconnect"),this.connectedDevice=null,Promise.resolve((0,c.Right)(void 0))}async sendApdu(e,t,o,r){try{const i=(0,s.bufferToHexaString)(r).substring(2);this.logger.debug(`send APDU: ${i}`);const a=await this._speculosDataSource.postAdpu(i),p=this.createApduResponse(a);return(0,c.Right)(p)}catch(i){return this.connectedDevice&&(this.logger.debug("disconnecting"),o(t),this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval)),(0,c.Left)(new s.GeneralDmkError(i))}}createApduResponse(e){return this.logger.debug(`Status code hex: ${e.substring(e.length-4,e.length)}`),this.logger.debug(`data hex: ${e.substring(0,e.length-4)}`),{statusCode:this.fromHexString(e.substring(e.length-4,e.length)),data:this.fromHexString(e.substring(0,e.length-4))}}fromHexString(e){return e?new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16))):Uint8Array.from([])}listenForDisconnect(e,t){this.disconnectInterval=setInterval(async()=>{await this._speculosDataSource.isServerAvailable()||(this.logger.info(`Speculos server unavailable, disconnecting device ${t}`),e(t),this.connectedDevice&&await this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval))},2e3)}}const T=(n="http://127.0.0.1:5000")=>({config:e,loggerServiceFactory:t})=>new D(t,e,n);0&&(module.exports={SpeculosTransport,speculosIdentifier,speculosTransportFactory});
2
2
  //# sourceMappingURL=SpeculosTransport.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/SpeculosTransport.ts"],
4
- "sourcesContent": ["import {\n ApduParser,\n type ApduResponse,\n bufferToHexaString,\n type ConnectError,\n type DeviceId,\n DeviceModelId,\n type DisconnectHandler,\n type DmkConfig,\n type DmkError,\n GeneralDmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n type TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { AxiosError } from \"axios\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { HttpLegacySpeculosDatasource } from \"@internal/datasource/HttpLegacySpeculosDatasource\";\nimport { HttpSpeculosDatasource } from \"@internal/datasource/HttpSpeculosDatasource\";\nimport { type SpeculosDatasource } from \"@internal/datasource/SpeculosDatasource\";\n\nexport const speculosIdentifier: TransportIdentifier =\n \"SPECULOS_HTTP_TRANSPORT\";\n\nexport class SpeculosTransport implements Transport {\n private logger: LoggerPublisherService;\n private readonly identifier: TransportIdentifier = speculosIdentifier;\n private readonly _speculosDataSource: SpeculosDatasource;\n private connectedDevice: TransportConnectedDevice | null = null;\n private disconnectInterval: NodeJS.Timeout | null = null;\n private readonly speculosDevice: TransportDiscoveredDevice = {\n id: \"SpeculosID\", //TODO make it dynamic at creation\n deviceModel: {\n id: DeviceModelId.STAX,\n productName: \"Speculos - App Name - version\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n getBlockSize() {\n return 32;\n },\n blockSize: 32,\n usbOnly: true,\n memorySize: 320 * 1024,\n masks: [0x31100000],\n },\n transport: this.identifier,\n };\n\n constructor(\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n _config: DmkConfig,\n speculosUrl: string,\n private readonly legacyE2ECompatibility: boolean,\n ) {\n this.logger = loggerServiceFactory(\"SpeculosTransport\");\n this._speculosDataSource = this.legacyE2ECompatibility\n ? new HttpLegacySpeculosDatasource(speculosUrl)\n : new HttpSpeculosDatasource(speculosUrl);\n }\n\n isSupported(): boolean {\n return true;\n }\n\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([[this.speculosDevice]]);\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n this.logger.debug(\"startDiscovering\");\n return from([this.speculosDevice]);\n }\n\n stopDiscovering(): void {\n //DO NOTHING HERE\n this.logger.debug(\"stopDiscovering\");\n }\n\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n this.logger.debug(\"connect\");\n\n const hexResponse = await this._speculosDataSource.postAdpu(\"B0010000\");\n this.logger.debug(`Hex Response: ${hexResponse}`);\n const apduResponse = this.createApduResponse(hexResponse);\n const parser = new ApduParser(apduResponse);\n\n //Copy paste from GetAppAndVersionCommand\n parser.extract8BitUInt(); //Need otherwise parser is not in the right position\n const appName = parser.encodeToString(parser.extractFieldLVEncoded());\n const appVersion = parser.encodeToString(parser.extractFieldLVEncoded());\n\n this.logger.debug(`App Name: ${appName} and version ${appVersion}`);\n\n const sessionId: string = params.deviceId;\n try {\n const connectedDevice: TransportConnectedDevice = {\n sendApdu: (apdu) => {\n return this.sendApdu(\n sessionId,\n params.deviceId,\n params.onDisconnect,\n apdu,\n );\n },\n deviceModel: {\n ...this.speculosDevice.deviceModel,\n productName: `Speculos - ${appName} - ${appVersion}`,\n getBlockSize() {\n return 32;\n },\n },\n transport: this.identifier,\n id: \"SpeculosID\", //TODO make it dynamic at creation\n type: \"USB\",\n };\n\n this.connectedDevice = connectedDevice;\n if (!this.legacyE2ECompatibility) {\n this.listenForDisconnect(params.onDisconnect, params.deviceId);\n }\n return Right(connectedDevice);\n } catch (error) {\n return Left(new OpeningConnectionError(error as Error));\n }\n }\n\n async disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n this.logger.debug(\"disconnect\");\n this.connectedDevice = null;\n return Promise.resolve(Right(undefined));\n }\n\n async sendApdu(\n _sessionId: string,\n deviceId: DeviceId,\n onDisconnect: DisconnectHandler,\n apdu: Uint8Array,\n ): Promise<Either<DmkError, ApduResponse>> {\n try {\n const hexApdu = bufferToHexaString(apdu).substring(2);\n this.logger.debug(`send APDU: ${hexApdu}`);\n const hexResponse = await this._speculosDataSource.postAdpu(hexApdu);\n return Right(this.createApduResponse(hexResponse));\n } catch (error) {\n if (this.connectedDevice) {\n this.logger.debug(\"disconnecting\");\n onDisconnect(deviceId);\n this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n return Left(new GeneralDmkError(error));\n }\n }\n\n private createApduResponse(hexApdu: string): ApduResponse {\n this.logger.debug(\n `Status code hex: ${hexApdu.substring(hexApdu.length - 4, hexApdu.length)}`,\n );\n this.logger.debug(`data hex: ${hexApdu.substring(0, hexApdu.length - 4)}`);\n\n const apduResponse = {\n statusCode: this.fromHexString(\n hexApdu.substring(hexApdu.length - 4, hexApdu.length),\n ),\n data: this.fromHexString(hexApdu.substring(0, hexApdu.length - 4)),\n };\n return apduResponse;\n }\n\n //TODO: Move this to a helper\n private fromHexString(hexString: string): Uint8Array {\n if (!hexString) {\n return Uint8Array.from([]);\n }\n return new Uint8Array(\n hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)),\n );\n }\n\n private listenForDisconnect(\n onDisconnect: DisconnectHandler,\n deviceId: DeviceId,\n ): void {\n this.disconnectInterval = setInterval(async () => {\n try {\n await this._speculosDataSource.postAdpu(\"B0010000\");\n } catch (error) {\n if (!(error instanceof AxiosError)) return;\n\n this.logger.info(\n `Network error, disconnecting speculos device ${deviceId}`,\n );\n onDisconnect(deviceId);\n\n if (this.connectedDevice) {\n await this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n }\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n }, 2000);\n }\n}\n\nexport const speculosTransportFactory: (\n speculosUrl?: string,\n legacyE2ECompatibility?: boolean,\n) => TransportFactory =\n (speculosUrl = \"http://127.0.0.1:5000\", legacyE2ECompatibility = false) =>\n ({ config, loggerServiceFactory }) =>\n new SpeculosTransport(\n loggerServiceFactory,\n config,\n speculosUrl,\n legacyE2ECompatibility,\n );\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,uBAAAC,EAAA,6BAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAkBO,2CACPC,EAA2B,iBAC3BC,EAAyC,qBACzCC,EAAsC,gBAEtCC,EAA6C,6DAC7CC,EAAuC,uDAGhC,MAAMR,EACX,0BAEK,MAAMD,CAAuC,CAwBlD,YACEU,EACAC,EACAC,EACiBC,EACjB,CADiB,4BAAAA,EAEjB,KAAK,OAASH,EAAqB,mBAAmB,EACtD,KAAK,oBAAsB,KAAK,uBAC5B,IAAI,+BAA6BE,CAAW,EAC5C,IAAI,yBAAuBA,CAAW,CAC5C,CAjCQ,OACS,WAAkCX,EAClC,oBACT,gBAAmD,KACnD,mBAA4C,KACnC,eAA4C,CAC3D,GAAI,aACJ,YAAa,CACX,GAAI,gBAAc,KAClB,YAAa,gCACb,aAAc,GACd,uBAAwB,EACxB,cAAe,CACb,MAAO,GACT,EACA,UAAW,GACX,QAAS,GACT,WAAY,IAAM,KAClB,MAAO,CAAC,SAAU,CACpB,EACA,UAAW,KAAK,UAClB,EAcA,aAAuB,CACrB,MAAO,EACT,CAEA,eAAqC,CACnC,OAAO,KAAK,UACd,CAEA,0BAAoE,CAClE,SAAO,QAAK,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CACrC,CAEA,kBAA0D,CACxD,YAAK,OAAO,MAAM,kBAAkB,KAC7B,QAAK,CAAC,KAAK,cAAc,CAAC,CACnC,CAEA,iBAAwB,CAEtB,KAAK,OAAO,MAAM,iBAAiB,CACrC,CAEA,MAAM,QAAQa,EAG8C,CAC1D,KAAK,OAAO,MAAM,SAAS,EAE3B,MAAMC,EAAc,MAAM,KAAK,oB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"speculosTransportFactory", "__toCommonJS", "import_device_management_kit", "import_axios", "import_purify_ts", "import_rxjs", "import_HttpLegacySpeculosDatasource", "import_HttpSpeculosDatasource", "loggerServiceFactory", "_config", "speculosUrl", "legacyE2ECompatibility", "params", "hexResponse", "apduResponse", "parser", "appName", "appVersion", "sessionId", "connectedDevice", "apdu", "error", "_params", "_sessionId", "deviceId", "onDisconnect", "hexApdu", "hexString", "byte", "config"]
4
+ "sourcesContent": ["import {\n ApduParser,\n type ApduResponse,\n bufferToHexaString,\n type ConnectError,\n type DeviceId,\n DeviceModelId,\n type DisconnectHandler,\n type DmkConfig,\n type DmkError,\n GeneralDmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n type TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { HttpSpeculosDatasource } from \"@internal/datasource/HttpSpeculosDatasource\";\nimport { type SpeculosDatasource } from \"@internal/datasource/SpeculosDatasource\";\n\nexport const speculosIdentifier: TransportIdentifier =\n \"SPECULOS_HTTP_TRANSPORT\";\n\nexport class SpeculosTransport implements Transport {\n private logger: LoggerPublisherService;\n private readonly identifier: TransportIdentifier = speculosIdentifier;\n private readonly _speculosDataSource: SpeculosDatasource;\n private connectedDevice: TransportConnectedDevice | null = null;\n private disconnectInterval: NodeJS.Timeout | null = null;\n private readonly speculosDevice: TransportDiscoveredDevice = {\n id: \"SpeculosID\", //TODO make it dynamic at creation\n deviceModel: {\n id: DeviceModelId.STAX,\n productName: \"Speculos - App Name - version\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n getBlockSize() {\n return 32;\n },\n blockSize: 32,\n usbOnly: true,\n memorySize: 320 * 1024,\n masks: [0x31100000],\n },\n transport: this.identifier,\n };\n\n constructor(\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n _config: DmkConfig,\n speculosUrl: string,\n ) {\n this.logger = loggerServiceFactory(\"SpeculosTransport\");\n this._speculosDataSource = new HttpSpeculosDatasource(speculosUrl); // See how to pass properly speculos config.\n }\n\n isSupported(): boolean {\n return true;\n }\n\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([[this.speculosDevice]]);\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n this.logger.debug(\"startDiscovering\");\n return from([this.speculosDevice]);\n }\n\n stopDiscovering(): void {\n //DO NOTHING HERE\n this.logger.debug(\"stopDiscovering\");\n }\n\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n this.logger.debug(\"connect\");\n\n const hexResponse = await this._speculosDataSource.postAdpu(\"B0010000\");\n this.logger.debug(`Hex Response: ${hexResponse}`);\n const apduResponse = this.createApduResponse(hexResponse);\n const parser = new ApduParser(apduResponse);\n\n //Copy paste from GetAppAndVersionCommand\n parser.extract8BitUInt(); //Need otherwise parser is not in the right position\n const appName = parser.encodeToString(parser.extractFieldLVEncoded());\n const appVersion = parser.encodeToString(parser.extractFieldLVEncoded());\n\n this.logger.debug(`App Name: ${appName} and version ${appVersion}`);\n\n const sessionId: string = params.deviceId;\n try {\n const connectedDevice: TransportConnectedDevice = {\n sendApdu: (apdu) => {\n return this.sendApdu(\n sessionId,\n params.deviceId,\n params.onDisconnect,\n apdu,\n );\n },\n deviceModel: {\n ...this.speculosDevice.deviceModel,\n productName: `Speculos - ${appName} - ${appVersion}`,\n getBlockSize() {\n return 32;\n },\n },\n transport: this.identifier,\n id: \"SpeculosID\", //TODO make it dynamic at creation\n type: \"USB\",\n };\n\n this.connectedDevice = connectedDevice;\n this.listenForDisconnect(params.onDisconnect, params.deviceId);\n return Right(connectedDevice);\n } catch (error) {\n return Left(new OpeningConnectionError(error as Error));\n }\n }\n\n async disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n this.logger.debug(\"disconnect\");\n this.connectedDevice = null;\n return Promise.resolve(Right(undefined));\n }\n\n async sendApdu(\n _sessionId: string,\n deviceId: DeviceId,\n onDisconnect: DisconnectHandler,\n apdu: Uint8Array,\n ): Promise<Either<DmkError, ApduResponse>> {\n try {\n const hexApdu = bufferToHexaString(apdu).substring(2);\n this.logger.debug(`send APDU: ${hexApdu}`);\n const hexResponse: string =\n await this._speculosDataSource.postAdpu(hexApdu);\n const apduResponse = this.createApduResponse(hexResponse);\n return Right(apduResponse);\n } catch (error) {\n if (this.connectedDevice) {\n this.logger.debug(\"disconnecting\");\n onDisconnect(deviceId);\n this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n return Left(new GeneralDmkError(error));\n }\n }\n\n private createApduResponse(hexApdu: string): ApduResponse {\n this.logger.debug(\n `Status code hex: ${hexApdu.substring(hexApdu.length - 4, hexApdu.length)}`,\n );\n this.logger.debug(`data hex: ${hexApdu.substring(0, hexApdu.length - 4)}`);\n\n const apduResponse = {\n statusCode: this.fromHexString(\n hexApdu.substring(hexApdu.length - 4, hexApdu.length),\n ),\n data: this.fromHexString(hexApdu.substring(0, hexApdu.length - 4)),\n };\n return apduResponse;\n }\n\n //TODO: Move this to a helper\n private fromHexString(hexString: string): Uint8Array {\n if (!hexString) {\n return Uint8Array.from([]);\n }\n return new Uint8Array(\n hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)),\n );\n }\n\n private listenForDisconnect(\n onDisconnect: DisconnectHandler,\n deviceId: DeviceId,\n ): void {\n this.disconnectInterval = setInterval(async () => {\n const isServerAvailable =\n await this._speculosDataSource.isServerAvailable();\n\n if (!isServerAvailable) {\n this.logger.info(\n `Speculos server unavailable, disconnecting device ${deviceId}`,\n );\n onDisconnect(deviceId);\n\n if (this.connectedDevice) {\n await this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n }\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n }, 2000);\n }\n}\n\nexport const speculosTransportFactory: (\n speculosUrl?: string,\n) => TransportFactory =\n (speculosUrl = \"http://127.0.0.1:5000\") =>\n ({ config, loggerServiceFactory }) =>\n new SpeculosTransport(loggerServiceFactory, config, speculosUrl);\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,uBAAAE,EAAA,uBAAAC,EAAA,6BAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAkBO,2CACPC,EAAyC,qBACzCC,EAAsC,gBAEtCC,EAAuC,uDAGhC,MAAMN,EACX,0BAEK,MAAMD,CAAuC,CAC1C,OACS,WAAkCC,EAClC,oBACT,gBAAmD,KACnD,mBAA4C,KACnC,eAA4C,CAC3D,GAAI,aACJ,YAAa,CACX,GAAI,gBAAc,KAClB,YAAa,gCACb,aAAc,GACd,uBAAwB,EACxB,cAAe,CACb,MAAO,GACT,EACA,UAAW,GACX,QAAS,GACT,WAAY,IAAM,KAClB,MAAO,CAAC,SAAU,CACpB,EACA,UAAW,KAAK,UAClB,EAEA,YACEO,EACAC,EACAC,EACA,CACA,KAAK,OAASF,EAAqB,mBAAmB,EACtD,KAAK,oBAAsB,IAAI,yBAAuBE,CAAW,CACnE,CAEA,aAAuB,CACrB,MAAO,EACT,CAEA,eAAqC,CACnC,OAAO,KAAK,UACd,CAEA,0BAAoE,CAClE,SAAO,QAAK,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CACrC,CAEA,kBAA0D,CACxD,YAAK,OAAO,MAAM,kBAAkB,KAC7B,QAAK,CAAC,KAAK,cAAc,CAAC,CACnC,CAEA,iBAAwB,CAEtB,KAAK,OAAO,MAAM,iBAAiB,CACrC,CAEA,MAAM,QAAQC,EAG8C,CAC1D,KAAK,OAAO,MAAM,SAAS,EAE3B,MAAMC,EAAc,MAAM,KAAK,oBAAoB,SAAS,UAAU,EACtE,K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,CACd,gBAAiB,KAAK,eACxB,CAAC,EAEG,KAAK,oBACP,cAAc,KAAK,kBAAkB,MAGlC,QAAK,IAAI,kBAAgBH,CAAK,CAAC,CACxC,CACF,CAEQ,mBAAmBK,EAA+B,CACxD,YAAK,OAAO,MACV,oBAAoBA,EAAQ,UAAUA,EAAQ,OAAS,EAAGA,EAAQ,MAAM,CAAC,EAC3E,EACA,KAAK,OAAO,MAAM,aAAaA,EAAQ,UAAU,EAAGA,EAAQ,OAAS,CAAC,CAAC,EAAE,EAEpD,CACnB,WAAY,KAAK,cACfA,EAAQ,UAAUA,EAAQ,OAAS,EAAGA,EAAQ,MAAM,CACtD,EACA,KAAM,KAAK,cAAcA,EAAQ,UAAU,EAAGA,EAAQ,OAAS,CAAC,CAAC,CACnE,CAEF,CAGQ,cAAcC,EAA+B,CACnD,OAAKA,EAGE,IAAI,WACTA,EAAU,MAAM,SAAS,EAAG,IAAKC,GAAS,SAASA,EAAM,EAAE,CAAC,CAC9D,EAJS,WAAW,KAAK,CAAC,CAAC,CAK7B,CAEQ,oBACNH,EACAD,EACM,CACN,KAAK,mBAAqB,YAAY,SAAY,CAE9C,MAAM,KAAK,oBAAoB,kBAAkB,IAGjD,KAAK,OAAO,KACV,qDAAqDA,CAAQ,EAC/D,EACAC,EAAaD,CAAQ,EAEjB,KAAK,iBACP,MAAM,KAAK,WAAW,CACpB,gBAAiB,KAAK,eACxB,CAAC,EAGC,KAAK,oBACP,cAAc,KAAK,kBAAkB,EAG3C,EAAG,GAAI,CACT,CACF,CAEO,MAAMrB,EAGX,CAACQ,EAAc,0BACf,CAAC,CAAE,OAAAkB,EAAQ,qBAAApB,CAAqB,IAC9B,IAAIR,EAAkBQ,EAAsBoB,EAAQlB,CAAW",
6
+ "names": ["SpeculosTransport_exports", "__export", "SpeculosTransport", "speculosIdentifier", "speculosTransportFactory", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_rxjs", "import_HttpSpeculosDatasource", "loggerServiceFactory", "_config", "speculosUrl", "params", "hexResponse", "apduResponse", "parser", "appName", "appVersion", "sessionId", "connectedDevice", "apdu", "error", "_params", "_sessionId", "deviceId", "onDisconnect", "hexApdu", "hexString", "byte", "config"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,o,p,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of c(o))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>o[m],enumerable:!(x=b(o,m))||x.enumerable});return f},e=(f,o,p)=>(t(f,o,"default"),p&&t(p,o,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var r={};module.exports=g(r);e(r,require("./api/QuietSpeculosTransport"),module.exports);e(r,require("./api/SpeculosTransport"),module.exports);0&&(module.exports={...require("./api/QuietSpeculosTransport"),...require("./api/SpeculosTransport")});
1
+ "use strict";var a=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var t=(f,o,p,x)=>{if(o&&typeof o=="object"||typeof o=="function")for(let m of c(o))!d.call(f,m)&&m!==p&&a(f,m,{get:()=>o[m],enumerable:!(x=b(o,m))||x.enumerable});return f},e=(f,o,p)=>(t(f,o,"default"),p&&t(p,o,"default"));var g=f=>t(a({},"__esModule",{value:!0}),f);var r={};module.exports=g(r);e(r,require("./api/E2eSpeculosTransport"),module.exports);e(r,require("./api/SpeculosTransport"),module.exports);0&&(module.exports={...require("./api/E2eSpeculosTransport"),...require("./api/SpeculosTransport")});
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 * from \"./api/QuietSpeculosTransport\";\nexport * from \"./api/SpeculosTransport\";\n"],
5
- "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,wCAAd,gBACAE,EAAAF,EAAc,mCADd",
4
+ "sourcesContent": ["export * from \"./api/E2eSpeculosTransport\";\nexport * from \"./api/SpeculosTransport\";\n"],
5
+ "mappings": "iaAAA,IAAAA,EAAA,kBAAAC,EAAAD,GAAAE,EAAAF,EAAc,sCAAd,gBACAE,EAAAF,EAAc,mCADd",
6
6
  "names": ["src_exports", "__toCommonJS", "__reExport"]
7
7
  }
@@ -0,0 +1,3 @@
1
+ "use strict";var i=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var h=(a,t)=>{for(var e in t)i(a,e,{get:t[e],enumerable:!0})},g=(a,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of d(t))!m.call(a,s)&&s!==e&&i(a,s,{get:()=>t[s],enumerable:!(o=u(t,s))||o.enumerable});return a};var y=a=>g(i({},"__esModule",{value:!0}),a);var v={};h(v,{E2eHttpSpeculosDatasource:()=>S});module.exports=y(v);var n=require("../utils/axiosInstances");class S{constructor(t,e=1e4,o="ldmk-transport-speculos"){this.baseUrl=t;this.timeoutMs=e;this.apduClient=(0,n.makeNoKeepAliveAxios)(t,e,o),this.buttonClient=(0,n.makeNoKeepAliveAxios)(t,Math.min(e,2e3),o),this.sseClient=(0,n.makeKeepAliveAxiosForSSE)(t,o)}apduClient;buttonClient;sseClient;async postAdpu(t){const{data:e}=await this.apduClient.post("/apdu",{data:t},{timeout:this.timeoutMs});return e.data}async pressButton(t){const o={Ll:"left",Rr:"right",LRlr:"both",left:"left",right:"right",both:"both"}[t]??"right";await this.buttonClient.post(`/button/${o}`,{action:"press-and-release"},{timeout:Math.min(this.timeoutMs,1500)})}async openEventStream(t,e){const s=(await this.sseClient.get("/events",{params:{stream:"true"},responseType:"stream",timeout:0,headers:{Accept:"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Accept-Encoding":"identity"}})).data;s.on("data",l=>{l.toString("utf8").split(`
2
+ `).forEach(p=>{if(p.startsWith("data: ")){const c=p.slice(6);try{t(JSON.parse(c))}catch{t({data:c})}}})});const r=()=>e?.();return s.on("close",r),s.on("end",r),s.on("error",r),s}get base(){return this.baseUrl}}0&&(module.exports={E2eHttpSpeculosDatasource});
3
+ //# sourceMappingURL=E2eHttpSpeculosDatasource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/datasource/E2eHttpSpeculosDatasource.ts"],
4
+ "sourcesContent": ["import { type AxiosInstance } from \"axios\";\n\nimport {\n makeKeepAliveAxiosForSSE,\n makeNoKeepAliveAxios,\n} from \"@internal/utils/axiosInstances\";\n\nimport { type E2eSpeculosDatasource } from \"./E2eSpeculosDatasource\";\n\ntype SpeculosApduDTO = { data: string };\n\nexport type SpeculosDeviceButtonsKeys =\n | \"Ll\"\n | \"Rr\"\n | \"LRlr\"\n | \"left\"\n | \"right\"\n | \"both\";\n\nexport class E2eHttpSpeculosDatasource implements E2eSpeculosDatasource {\n private readonly apduClient: AxiosInstance;\n private readonly buttonClient: AxiosInstance;\n private readonly sseClient: AxiosInstance;\n\n constructor(\n private readonly baseUrl: string,\n private readonly timeoutMs: number = 10000,\n clientHeader: string = \"ldmk-transport-speculos\",\n ) {\n this.apduClient = makeNoKeepAliveAxios(baseUrl, timeoutMs, clientHeader);\n this.buttonClient = makeNoKeepAliveAxios(\n baseUrl,\n Math.min(timeoutMs, 2000),\n clientHeader,\n );\n\n this.sseClient = makeKeepAliveAxiosForSSE(baseUrl, clientHeader);\n }\n\n async postAdpu(apdu: string): Promise<string> {\n const { data } = await this.apduClient.post<SpeculosApduDTO>(\n \"/apdu\",\n { data: apdu },\n { timeout: this.timeoutMs },\n );\n return data.data;\n }\n\n async pressButton(but: SpeculosDeviceButtonsKeys): Promise<void> {\n const map: Record<string, \"left\" | \"right\" | \"both\"> = {\n Ll: \"left\",\n Rr: \"right\",\n LRlr: \"both\",\n left: \"left\",\n right: \"right\",\n both: \"both\",\n };\n const input = map[but] ?? \"right\";\n await this.buttonClient.post(\n `/button/${input}`,\n { action: \"press-and-release\" },\n { timeout: Math.min(this.timeoutMs, 1500) },\n );\n }\n\n async openEventStream(\n onEvent: (json: Record<string, unknown>) => void,\n onClose?: () => void,\n ): Promise<NodeJS.ReadableStream> {\n const response = await this.sseClient.get(\"/events\", {\n params: { stream: \"true\" },\n responseType: \"stream\",\n timeout: 0,\n headers: {\n Accept: \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n \"Accept-Encoding\": \"identity\",\n },\n });\n\n const stream = response.data as NodeJS.ReadableStream;\n\n stream.on(\"data\", (chunk: Buffer) => {\n const txt = chunk.toString(\"utf8\");\n txt.split(\"\\n\").forEach((line) => {\n if (line.startsWith(\"data: \")) {\n const payload = line.slice(6);\n try {\n onEvent(JSON.parse(payload));\n } catch {\n onEvent({ data: payload });\n }\n }\n });\n });\n\n const end = () => onClose?.();\n stream.on(\"close\", end);\n stream.on(\"end\", end);\n stream.on(\"error\", end);\n\n return stream;\n }\n\n get base(): string {\n return this.baseUrl;\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAGO,0CAcA,MAAMF,CAA2D,CAKtE,YACmBG,EACAC,EAAoB,IACrCC,EAAuB,0BACvB,CAHiB,aAAAF,EACA,eAAAC,EAGjB,KAAK,cAAa,wBAAqBD,EAASC,EAAWC,CAAY,EACvE,KAAK,gBAAe,wBAClBF,EACA,KAAK,IAAIC,EAAW,GAAI,EACxBC,CACF,EAEA,KAAK,aAAY,4BAAyBF,EAASE,CAAY,CACjE,CAjBiB,WACA,aACA,UAiBjB,MAAM,SAASC,EAA+B,CAC5C,KAAM,CAAE,KAAAC,CAAK,EAAI,MAAM,KAAK,WAAW,KACrC,QACA,CAAE,KAAMD,CAAK,EACb,CAAE,QAAS,KAAK,SAAU,CAC5B,EACA,OAAOC,EAAK,IACd,CAEA,MAAM,YAAYC,EAA+C,CAS/D,MAAMC,EARiD,CACrD,GAAI,OACJ,GAAI,QACJ,KAAM,OACN,KAAM,OACN,MAAO,QACP,KAAM,MACR,EACkBD,CAAG,GAAK,QAC1B,MAAM,KAAK,aAAa,KACtB,WAAWC,CAAK,GAChB,CAAE,OAAQ,mBAAoB,EAC9B,CAAE,QAAS,KAAK,IAAI,KAAK,UAAW,IAAI,CAAE,CAC5C,CACF,CAEA,MAAM,gBACJC,EACAC,EACgC,CAahC,MAAMC,GAZW,MAAM,KAAK,UAAU,IAAI,UAAW,CACnD,OAAQ,CAAE,OAAQ,MAAO,EACzB,aAAc,SACd,QAAS,EACT,QAAS,CACP,OAAQ,oBACR,gBAAiB,WACjB,WAAY,aACZ,kBAAmB,UACrB,CACF,CAAC,GAEuB,KAExBA,EAAO,GAAG,OAASC,GAAkB,CACvBA,EAAM,SAAS,MAAM,EAC7B,MAAM;AAAA,CAAI,EAAE,QAASC,GAAS,CAChC,GAAIA,EAAK,WAAW,QAAQ,EAAG,CAC7B,MAAMC,EAAUD,EAAK,MAAM,CAAC,EAC5B,GAAI,CACFJ,EAAQ,KAAK,MAAMK,CAAO,CAAC,CAC7B,MAAQ,CACNL,EAAQ,CAAE,KAAMK,CAAQ,CAAC,CAC3B,CACF,CACF,CAAC,CACH,CAAC,EAED,MAAMC,EAAM,IAAML,IAAU,EAC5B,OAAAC,EAAO,GAAG,QAASI,CAAG,EACtBJ,EAAO,GAAG,MAAOI,CAAG,EACpBJ,EAAO,GAAG,QAASI,CAAG,EAEfJ,CACT,CAEA,IAAI,MAAe,CACjB,OAAO,KAAK,OACd,CACF",
6
+ "names": ["E2eHttpSpeculosDatasource_exports", "__export", "E2eHttpSpeculosDatasource", "__toCommonJS", "import_axiosInstances", "baseUrl", "timeoutMs", "clientHeader", "apdu", "data", "but", "input", "onEvent", "onClose", "stream", "chunk", "line", "payload", "end"]
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";var n=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var a=(o,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of p(e))!u.call(o,t)&&t!==r&&n(o,t,{get:()=>e[t],enumerable:!(s=i(e,t))||s.enumerable});return o};var c=o=>a(n({},"__esModule",{value:!0}),o);var d={};module.exports=c(d);
2
+ //# sourceMappingURL=E2eSpeculosDatasource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/datasource/E2eSpeculosDatasource.ts"],
4
+ "sourcesContent": ["import { type SpeculosDeviceButtonsKeys } from \"./E2eHttpSpeculosDatasource\";\n\nexport interface E2eSpeculosDatasource {\n postAdpu(apdu: string): Promise<string>;\n pressButton(but: SpeculosDeviceButtonsKeys): Promise<void>;\n openEventStream(\n onEvent: (json: Record<string, unknown>) => void,\n onClose?: () => void,\n ): Promise<NodeJS.ReadableStream>;\n}\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["E2eSpeculosDatasource_exports", "__toCommonJS"]
7
+ }
@@ -1,2 +1,2 @@
1
- "use strict";var i=Object.create;var r=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var S=(s,e)=>{for(var t in e)r(s,t,{get:e[t],enumerable:!0})},p=(s,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of d(e))!D.call(s,o)&&o!==t&&r(s,o,{get:()=>e[o],enumerable:!(a=l(e,o))||a.enumerable});return s};var u=(s,e,t)=>(t=s!=null?i(m(s)):{},p(e||!s||!s.__esModule?r(t,"default",{value:s,enumerable:!0}):t,s)),g=s=>p(r({},"__esModule",{value:!0}),s);var y={};S(y,{HttpSpeculosDatasource:()=>A});module.exports=g(y);var c=u(require("axios")),n=u(require("../../../package.json"));class A{constructor(e){this.baseUrl=e}async postAdpu(e){const t={data:e};return(await c.default.request({method:"POST",url:`${this.baseUrl}/apdu`,data:t,headers:{"X-Ledger-Client-Version":`ldmk-transport-speculos/${n.default.version}`}})).data.data}}0&&(module.exports={HttpSpeculosDatasource});
1
+ "use strict";var i=Object.create;var o=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var y=(e,s)=>{for(var t in s)o(e,t,{get:s[t],enumerable:!0})},p=(e,s,t,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of d(s))!v.call(e,r)&&r!==t&&o(e,r,{get:()=>s[r],enumerable:!(a=c(s,r))||a.enumerable});return e};var l=(e,s,t)=>(t=e!=null?i(m(e)):{},p(s||!e||!e.__esModule?o(t,"default",{value:e,enumerable:!0}):t,e)),S=e=>p(o({},"__esModule",{value:!0}),e);var b={};y(b,{HttpSpeculosDatasource:()=>T});module.exports=S(b);var n=l(require("axios")),u=l(require("../../../package.json"));const D=5e3;class T{constructor(s){this.baseUrl=s}async postAdpu(s){const t={data:s};return(await n.default.request({method:"POST",url:`${this.baseUrl}/apdu`,data:t,headers:{"X-Ledger-Client-Version":`ldmk-transport-speculos/${u.default.version}`}})).data.data}async isServerAvailable(){try{return await n.default.request({method:"GET",url:`${this.baseUrl}/events`,headers:{"X-Ledger-Client-Version":`ldmk-transport-speculos/${u.default.version}`},timeout:D}),!0}catch{return!1}}}0&&(module.exports={HttpSpeculosDatasource});
2
2
  //# sourceMappingURL=HttpSpeculosDatasource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/datasource/HttpSpeculosDatasource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\n\nimport PACKAGE from \"@root/package.json\";\n\nimport { type SpeculosDatasource } from \"./SpeculosDatasource\";\nexport class HttpSpeculosDatasource implements SpeculosDatasource {\n constructor(private readonly baseUrl: string) {}\n\n async postAdpu(apdu: string): Promise<string> {\n const requestDto = {\n data: apdu,\n };\n\n const speculosResponse = await axios.request<SpeculosApduDTO>({\n method: \"POST\",\n url: `${this.baseUrl}/apdu`,\n data: requestDto,\n headers: {\n \"X-Ledger-Client-Version\": `ldmk-transport-speculos/${PACKAGE.version}`,\n },\n });\n\n return speculosResponse.data.data;\n }\n}\n\ntype SpeculosApduDTO = {\n data: string;\n};\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAElBC,EAAoB,iCAGb,MAAMH,CAAqD,CAChE,YAA6BI,EAAiB,CAAjB,aAAAA,CAAkB,CAE/C,MAAM,SAASC,EAA+B,CAC5C,MAAMC,EAAa,CACjB,KAAMD,CACR,EAWA,OATyB,MAAM,EAAAE,QAAM,QAAyB,CAC5D,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,QACpB,KAAMD,EACN,QAAS,CACP,0BAA2B,2BAA2B,EAAAE,QAAQ,OAAO,EACvE,CACF,CAAC,GAEuB,KAAK,IAC/B,CACF",
6
- "names": ["HttpSpeculosDatasource_exports", "__export", "HttpSpeculosDatasource", "__toCommonJS", "import_axios", "import_package", "baseUrl", "apdu", "requestDto", "axios", "PACKAGE"]
4
+ "sourcesContent": ["import axios from \"axios\";\n\nimport PACKAGE from \"@root/package.json\";\n\nimport { type SpeculosDatasource } from \"./SpeculosDatasource\";\n\nconst TIMEOUT = 5000; // 5 second timeout for availability check\n\nexport class HttpSpeculosDatasource implements SpeculosDatasource {\n constructor(private readonly baseUrl: string) {}\n\n async postAdpu(apdu: string): Promise<string> {\n const requestDto = {\n data: apdu,\n };\n\n const speculosResponse = await axios.request<SpeculosApduDTO>({\n method: \"POST\",\n url: `${this.baseUrl}/apdu`,\n data: requestDto,\n headers: {\n \"X-Ledger-Client-Version\": `ldmk-transport-speculos/${PACKAGE.version}`,\n },\n });\n\n return speculosResponse.data.data;\n }\n\n async isServerAvailable(): Promise<boolean> {\n try {\n await axios.request<SpeculosEventsDTO>({\n method: \"GET\",\n url: `${this.baseUrl}/events`,\n headers: {\n \"X-Ledger-Client-Version\": `ldmk-transport-speculos/${PACKAGE.version}`,\n },\n timeout: TIMEOUT,\n });\n return true;\n } catch (_error) {\n return false;\n }\n }\n}\n\ntype SpeculosApduDTO = {\n data: string;\n};\n\ntype SpeculosEventsDTO = {\n events: Array<{\n text?: string;\n x?: number;\n y?: number;\n }>;\n};\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,oBAElBC,EAAoB,iCAIpB,MAAMC,EAAU,IAET,MAAMJ,CAAqD,CAChE,YAA6BK,EAAiB,CAAjB,aAAAA,CAAkB,CAE/C,MAAM,SAASC,EAA+B,CAC5C,MAAMC,EAAa,CACjB,KAAMD,CACR,EAWA,OATyB,MAAM,EAAAE,QAAM,QAAyB,CAC5D,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,QACpB,KAAMD,EACN,QAAS,CACP,0BAA2B,2BAA2B,EAAAE,QAAQ,OAAO,EACvE,CACF,CAAC,GAEuB,KAAK,IAC/B,CAEA,MAAM,mBAAsC,CAC1C,GAAI,CACF,aAAM,EAAAD,QAAM,QAA2B,CACrC,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,UACpB,QAAS,CACP,0BAA2B,2BAA2B,EAAAC,QAAQ,OAAO,EACvE,EACA,QAASL,CACX,CAAC,EACM,EACT,MAAiB,CACf,MAAO,EACT,CACF,CACF",
6
+ "names": ["HttpSpeculosDatasource_exports", "__export", "HttpSpeculosDatasource", "__toCommonJS", "import_axios", "import_package", "TIMEOUT", "baseUrl", "apdu", "requestDto", "axios", "PACKAGE"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(r,e,p,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of i(e))!u.call(r,s)&&s!==p&&o(r,s,{get:()=>e[s],enumerable:!(t=a(e,s))||t.enumerable});return r};var n=r=>c(o({},"__esModule",{value:!0}),r);var d={};module.exports=n(d);
1
+ "use strict";var a=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var n=(r,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of p(e))!l.call(r,o)&&o!==i&&a(r,o,{get:()=>e[o],enumerable:!(s=t(e,o))||s.enumerable});return r};var u=r=>n(a({},"__esModule",{value:!0}),r);var c={};module.exports=u(c);
2
2
  //# sourceMappingURL=SpeculosDatasource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/datasource/SpeculosDatasource.ts"],
4
- "sourcesContent": ["export interface SpeculosDatasource {\n postAdpu(apdu: string): Promise<string>;\n}\n"],
4
+ "sourcesContent": ["export interface SpeculosDatasource {\n postAdpu(apdu: string): Promise<string>;\n isServerAvailable(): Promise<boolean>;\n}\n"],
5
5
  "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
6
  "names": ["SpeculosDatasource_exports", "__toCommonJS"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ "use strict";var m=Object.create;var i=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var k=(e,t)=>{for(var n in t)i(e,n,{get:t[n],enumerable:!0})},l=(e,t,n,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of x(t))!f.call(e,r)&&r!==n&&i(e,r,{get:()=>t[r],enumerable:!(c=A(t,r))||c.enumerable});return e};var o=(e,t,n)=>(n=e!=null?m(g(e)):{},l(t||!e||!e.__esModule?i(n,"default",{value:e,enumerable:!0}):n,e)),u=e=>l(i({},"__esModule",{value:!0}),e);var v={};k(v,{makeKeepAliveAxiosForSSE:()=>S,makeNoKeepAliveAxios:()=>h});module.exports=u(v);var s=o(require("axios")),a=o(require("http")),p=o(require("https"));function h(e,t,n){return s.default.create({baseURL:e.replace(/\/+$/,""),timeout:t,proxy:!1,headers:{"X-Ledger-Client-Version":n,Connection:"close"},httpAgent:new a.default.Agent({keepAlive:!1,maxSockets:1/0}),httpsAgent:new p.default.Agent({keepAlive:!1,maxSockets:1/0}),transitional:{clarifyTimeoutError:!0}})}function S(e,t){return s.default.create({baseURL:e.replace(/\/+$/,""),timeout:0,proxy:!1,headers:{"X-Ledger-Client-Version":t,Connection:"keep-alive"},httpAgent:new a.default.Agent({keepAlive:!0,maxSockets:1,maxFreeSockets:1}),httpsAgent:new p.default.Agent({keepAlive:!0,maxSockets:1,maxFreeSockets:1}),transitional:{clarifyTimeoutError:!0}})}0&&(module.exports={makeKeepAliveAxiosForSSE,makeNoKeepAliveAxios});
2
+ //# sourceMappingURL=axiosInstances.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/utils/axiosInstances.ts"],
4
+ "sourcesContent": ["import axios, { type AxiosInstance } from \"axios\";\nimport http from \"http\";\nimport https from \"https\";\n\nexport function makeNoKeepAliveAxios(\n baseUrl: string,\n timeoutMs: number,\n clientHeader: string,\n): AxiosInstance {\n return axios.create({\n baseURL: baseUrl.replace(/\\/+$/, \"\"),\n timeout: timeoutMs,\n proxy: false,\n headers: {\n \"X-Ledger-Client-Version\": clientHeader,\n Connection: \"close\",\n },\n httpAgent: new http.Agent({ keepAlive: false, maxSockets: Infinity }),\n httpsAgent: new https.Agent({ keepAlive: false, maxSockets: Infinity }),\n transitional: { clarifyTimeoutError: true },\n });\n}\n\nexport function makeKeepAliveAxiosForSSE(\n baseUrl: string,\n clientHeader: string,\n): AxiosInstance {\n return axios.create({\n baseURL: baseUrl.replace(/\\/+$/, \"\"),\n timeout: 0,\n proxy: false,\n headers: {\n \"X-Ledger-Client-Version\": clientHeader,\n\n Connection: \"keep-alive\",\n },\n httpAgent: new http.Agent({\n keepAlive: true,\n maxSockets: 1,\n maxFreeSockets: 1,\n }),\n httpsAgent: new https.Agent({\n keepAlive: true,\n maxSockets: 1,\n maxFreeSockets: 1,\n }),\n transitional: { clarifyTimeoutError: true },\n });\n}\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,EAAA,yBAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAA0C,oBAC1CC,EAAiB,mBACjBC,EAAkB,oBAEX,SAASJ,EACdK,EACAC,EACAC,EACe,CACf,OAAO,EAAAC,QAAM,OAAO,CAClB,QAASH,EAAQ,QAAQ,OAAQ,EAAE,EACnC,QAASC,EACT,MAAO,GACP,QAAS,CACP,0BAA2BC,EAC3B,WAAY,OACd,EACA,UAAW,IAAI,EAAAE,QAAK,MAAM,CAAE,UAAW,GAAO,WAAY,GAAS,CAAC,EACpE,WAAY,IAAI,EAAAC,QAAM,MAAM,CAAE,UAAW,GAAO,WAAY,GAAS,CAAC,EACtE,aAAc,CAAE,oBAAqB,EAAK,CAC5C,CAAC,CACH,CAEO,SAASX,EACdM,EACAE,EACe,CACf,OAAO,EAAAC,QAAM,OAAO,CAClB,QAASH,EAAQ,QAAQ,OAAQ,EAAE,EACnC,QAAS,EACT,MAAO,GACP,QAAS,CACP,0BAA2BE,EAE3B,WAAY,YACd,EACA,UAAW,IAAI,EAAAE,QAAK,MAAM,CACxB,UAAW,GACX,WAAY,EACZ,eAAgB,CAClB,CAAC,EACD,WAAY,IAAI,EAAAC,QAAM,MAAM,CAC1B,UAAW,GACX,WAAY,EACZ,eAAgB,CAClB,CAAC,EACD,aAAc,CAAE,oBAAqB,EAAK,CAC5C,CAAC,CACH",
6
+ "names": ["axiosInstances_exports", "__export", "makeKeepAliveAxiosForSSE", "makeNoKeepAliveAxios", "__toCommonJS", "import_axios", "import_http", "import_https", "baseUrl", "timeoutMs", "clientHeader", "axios", "http", "https"]
7
+ }
@@ -0,0 +1,2 @@
1
+ import{ApduParser as d,bufferToHexaString as u,DeviceModelId as l,GeneralDmkError as g,OpeningConnectionError as v}from"@ledgerhq/device-management-kit";import{Left as p,Right as i}from"purify-ts";import{from as a}from"rxjs";import{E2eHttpSpeculosDatasource as D}from"../../src/internal/datasource/E2eHttpSpeculosDatasource";import{speculosIdentifier as h}from"./SpeculosTransport";class m{logger;identifier=h;_speculosDataSource;connectedDevice=null;speculosDevice={id:"SpeculosID",deviceModel:{id:l.STAX,productName:"Speculos - App Name - version",usbProductId:16,bootloaderUsbProductId:1,getBlockSize(){return 32},blockSize:32,usbOnly:!0,memorySize:320*1024,masks:[823132160]},transport:this.identifier};constructor(r,e,t){this.logger=r("E2eSpeculosTransport"),this._speculosDataSource=new D(t,1e4,"ldmk-transport-speculos")}isSupported(){return!0}getIdentifier(){return this.identifier}listenToAvailableDevices(){return a([[this.speculosDevice]])}startDiscovering(){return this.logger.debug("startDiscovering"),a([this.speculosDevice])}stopDiscovering(){this.logger.debug("stopDiscovering")}async connect(r){this.logger.debug("connect");try{const e=await this._speculosDataSource.postAdpu("B0010000");this.logger.debug(`Hex Response: ${e}`);const t=this.createApduResponse(e),o=new d(t);o.extract8BitUInt();const s=o.encodeToString(o.extractFieldLVEncoded()),n=o.encodeToString(o.extractFieldLVEncoded());this.logger.debug(`App Name: ${s} and version ${n}`),this.speculosDevice.deviceModel.productName=`Speculos - ${s} - ${n}`}catch{this.logger.debug("Unable to fetch app name and version from Speculos")}try{const e={sendApdu:t=>this.sendApdu(r.deviceId,r.onDisconnect,t),deviceModel:this.speculosDevice.deviceModel,transport:this.identifier,id:"SpeculosID",type:"USB"};return this.connectedDevice=e,i(e)}catch(e){return p(new v(e))}}async disconnect(r){return this.logger.debug("disconnect"),this.connectedDevice=null,Promise.resolve(i(void 0))}async sendApdu(r,e,t){try{const o=u(t).substring(2).toUpperCase();this.logger.debug(`[E2eSpeculosTransport] send APDU: ${o}`);const s=await this._speculosDataSource.postAdpu(o),n=this.createApduResponse(s);return i(n)}catch(o){return this.connectedDevice&&(this.logger.debug("disconnecting due to APDU error"),e(r),await this.disconnect({connectedDevice:this.connectedDevice})),p(new g(o))}}createApduResponse(r){const e=r.slice(-4),t=r.slice(0,-4);return this.logger.debug(`[E2eSpeculosTransport] Status code hex: ${e}`),this.logger.debug(`[E2eSpeculosTransport] data hex: ${t}`),{statusCode:this.fromHexString(e),data:this.fromHexString(t)}}fromHexString(r){return r?new Uint8Array(r.match(/.{1,2}/g).map(e=>parseInt(e,16))):new Uint8Array(0)}}const E=(c="http://127.0.0.1:5000")=>({config:r,loggerServiceFactory:e})=>new m(e,r,c);export{m as E2eSpeculosTransport,E as e2eSpeculosTransportFactory};
2
+ //# sourceMappingURL=E2eSpeculosTransport.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/api/E2eSpeculosTransport.ts"],
4
+ "sourcesContent": ["import {\n ApduParser,\n type ApduResponse,\n bufferToHexaString,\n type ConnectError,\n type DeviceId,\n DeviceModelId,\n type DisconnectHandler,\n type DmkConfig,\n type DmkError,\n GeneralDmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n type TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { type E2eSpeculosDatasource } from \"@internal/datasource/E2eSpeculosDatasource\";\nimport { E2eHttpSpeculosDatasource } from \"@root/src/internal/datasource/E2eHttpSpeculosDatasource\";\n\nimport { speculosIdentifier } from \"./SpeculosTransport\";\n\nexport class E2eSpeculosTransport implements Transport {\n private logger: LoggerPublisherService;\n private readonly identifier: TransportIdentifier = speculosIdentifier;\n\n private readonly _speculosDataSource: E2eSpeculosDatasource;\n\n private connectedDevice: TransportConnectedDevice | null = null;\n\n private readonly speculosDevice: TransportDiscoveredDevice = {\n id: \"SpeculosID\",\n deviceModel: {\n id: DeviceModelId.STAX,\n productName: \"Speculos - App Name - version\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n getBlockSize() {\n return 32;\n },\n blockSize: 32,\n usbOnly: true,\n memorySize: 320 * 1024,\n masks: [0x31100000],\n },\n transport: this.identifier,\n };\n\n constructor(\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n _config: DmkConfig,\n speculosUrl: string,\n ) {\n this.logger = loggerServiceFactory(\"E2eSpeculosTransport\");\n this._speculosDataSource = new E2eHttpSpeculosDatasource(\n speculosUrl,\n 10000,\n \"ldmk-transport-speculos\",\n );\n }\n\n isSupported(): boolean {\n return true;\n }\n\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([[this.speculosDevice]]);\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n this.logger.debug(\"startDiscovering\");\n return from([this.speculosDevice]);\n }\n\n stopDiscovering(): void {\n this.logger.debug(\"stopDiscovering\");\n }\n\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n this.logger.debug(\"connect\");\n\n try {\n const hexResponse = await this._speculosDataSource.postAdpu(\"B0010000\");\n this.logger.debug(`Hex Response: ${hexResponse}`);\n const apduResponse = this.createApduResponse(hexResponse);\n const parser = new ApduParser(apduResponse);\n parser.extract8BitUInt();\n const appName = parser.encodeToString(parser.extractFieldLVEncoded());\n const appVersion = parser.encodeToString(parser.extractFieldLVEncoded());\n this.logger.debug(`App Name: ${appName} and version ${appVersion}`);\n\n this.speculosDevice.deviceModel.productName = `Speculos - ${appName} - ${appVersion}`;\n } catch {\n this.logger.debug(\"Unable to fetch app name and version from Speculos\");\n }\n\n try {\n const connectedDevice: TransportConnectedDevice = {\n sendApdu: (apdu: Uint8Array) =>\n this.sendApdu(params.deviceId, params.onDisconnect, apdu),\n deviceModel: this.speculosDevice.deviceModel,\n transport: this.identifier,\n id: \"SpeculosID\",\n type: \"USB\",\n };\n\n this.connectedDevice = connectedDevice;\n return Right(connectedDevice);\n } catch (error) {\n return Left(new OpeningConnectionError(error as Error));\n }\n }\n\n async disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n this.logger.debug(\"disconnect\");\n this.connectedDevice = null;\n return Promise.resolve(Right(undefined));\n }\n\n async sendApdu(\n deviceId: DeviceId,\n onDisconnect: DisconnectHandler,\n apdu: Uint8Array,\n ): Promise<Either<DmkError, ApduResponse>> {\n try {\n const hex = bufferToHexaString(apdu).substring(2).toUpperCase();\n this.logger.debug(`[E2eSpeculosTransport] send APDU: ${hex}`);\n const hexResponse = await this._speculosDataSource.postAdpu(hex);\n const resp = this.createApduResponse(hexResponse);\n return Right(resp);\n } catch (error) {\n if (this.connectedDevice) {\n this.logger.debug(\"disconnecting due to APDU error\");\n onDisconnect(deviceId);\n await this.disconnect({ connectedDevice: this.connectedDevice });\n }\n return Left(new GeneralDmkError(error as Error));\n }\n }\n\n private createApduResponse(hexApdu: string): ApduResponse {\n const sw = hexApdu.slice(-4);\n const payload = hexApdu.slice(0, -4);\n this.logger.debug(`[E2eSpeculosTransport] Status code hex: ${sw}`);\n this.logger.debug(`[E2eSpeculosTransport] data hex: ${payload}`);\n return {\n statusCode: this.fromHexString(sw),\n data: this.fromHexString(payload),\n };\n }\n\n private fromHexString(hexString: string): Uint8Array {\n if (!hexString) return new Uint8Array(0);\n return new Uint8Array(\n hexString.match(/.{1,2}/g)!.map((b) => parseInt(b, 16)),\n );\n }\n}\n\nexport const e2eSpeculosTransportFactory: (\n speculosUrl?: string,\n) => TransportFactory =\n (speculosUrl = \"http://127.0.0.1:5000\") =>\n ({ config, loggerServiceFactory }) =>\n new E2eSpeculosTransport(loggerServiceFactory, config, speculosUrl);\n"],
5
+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E,EAAE,EACjE,KAAK,OAAO,MAAM,oCAAoCC,CAAO,EAAE,EACxD,CACL,WAAY,KAAK,cAAcD,CAAE,EACjC,KAAM,KAAK,cAAcC,CAAO,CAClC,CACF,CAEQ,cAAcC,EAA+B,CACnD,OAAKA,EACE,IAAI,WACTA,EAAU,MAAM,SAAS,EAAG,IAAKC,GAAM,SAASA,EAAG,EAAE,CAAC,CACxD,EAHuB,IAAI,WAAW,CAAC,CAIzC,CACF,CAEO,MAAMC,EAGX,CAACpB,EAAc,0BACf,CAAC,CAAE,OAAAqB,EAAQ,qBAAAvB,CAAqB,IAC9B,IAAID,EAAqBC,EAAsBuB,EAAQrB,CAAW",
6
+ "names": ["ApduParser", "bufferToHexaString", "DeviceModelId", "GeneralDmkError", "OpeningConnectionError", "Left", "Right", "from", "E2eHttpSpeculosDatasource", "speculosIdentifier", "E2eSpeculosTransport", "loggerServiceFactory", "_config", "speculosUrl", "params", "hexResponse", "apduResponse", "parser", "appName", "appVersion", "connectedDevice", "apdu", "error", "_params", "deviceId", "onDisconnect", "hex", "resp", "hexApdu", "sw", "payload", "hexString", "b", "e2eSpeculosTransportFactory", "config"]
7
+ }
@@ -1,2 +1,2 @@
1
- import{ApduParser as g,bufferToHexaString as v,DeviceModelId as D,GeneralDmkError as h,OpeningConnectionError as y}from"@ledgerhq/device-management-kit";import{AxiosError as m}from"axios";import{Left as p,Right as c}from"purify-ts";import{from as d}from"rxjs";import{HttpLegacySpeculosDatasource as f}from"../internal/datasource/HttpLegacySpeculosDatasource";import{HttpSpeculosDatasource as b}from"../internal/datasource/HttpSpeculosDatasource";const S="SPECULOS_HTTP_TRANSPORT";class I{constructor(e,t,r,n){this.legacyE2ECompatibility=n;this.logger=e("SpeculosTransport"),this._speculosDataSource=this.legacyE2ECompatibility?new f(r):new b(r)}logger;identifier=S;_speculosDataSource;connectedDevice=null;disconnectInterval=null;speculosDevice={id:"SpeculosID",deviceModel:{id:D.STAX,productName:"Speculos - App Name - version",usbProductId:16,bootloaderUsbProductId:1,getBlockSize(){return 32},blockSize:32,usbOnly:!0,memorySize:320*1024,masks:[823132160]},transport:this.identifier};isSupported(){return!0}getIdentifier(){return this.identifier}listenToAvailableDevices(){return d([[this.speculosDevice]])}startDiscovering(){return this.logger.debug("startDiscovering"),d([this.speculosDevice])}stopDiscovering(){this.logger.debug("stopDiscovering")}async connect(e){this.logger.debug("connect");const t=await this._speculosDataSource.postAdpu("B0010000");this.logger.debug(`Hex Response: ${t}`);const r=this.createApduResponse(t),n=new g(r);n.extract8BitUInt();const o=n.encodeToString(n.extractFieldLVEncoded()),i=n.encodeToString(n.extractFieldLVEncoded());this.logger.debug(`App Name: ${o} and version ${i}`);const l=e.deviceId;try{const s={sendApdu:u=>this.sendApdu(l,e.deviceId,e.onDisconnect,u),deviceModel:{...this.speculosDevice.deviceModel,productName:`Speculos - ${o} - ${i}`,getBlockSize(){return 32}},transport:this.identifier,id:"SpeculosID",type:"USB"};return this.connectedDevice=s,this.legacyE2ECompatibility||this.listenForDisconnect(e.onDisconnect,e.deviceId),c(s)}catch(s){return p(new y(s))}}async disconnect(e){return this.logger.debug("disconnect"),this.connectedDevice=null,Promise.resolve(c(void 0))}async sendApdu(e,t,r,n){try{const o=v(n).substring(2);this.logger.debug(`send APDU: ${o}`);const i=await this._speculosDataSource.postAdpu(o);return c(this.createApduResponse(i))}catch(o){return this.connectedDevice&&(this.logger.debug("disconnecting"),r(t),this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval)),p(new h(o))}}createApduResponse(e){return this.logger.debug(`Status code hex: ${e.substring(e.length-4,e.length)}`),this.logger.debug(`data hex: ${e.substring(0,e.length-4)}`),{statusCode:this.fromHexString(e.substring(e.length-4,e.length)),data:this.fromHexString(e.substring(0,e.length-4))}}fromHexString(e){return e?new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16))):Uint8Array.from([])}listenForDisconnect(e,t){this.disconnectInterval=setInterval(async()=>{try{await this._speculosDataSource.postAdpu("B0010000")}catch(r){if(!(r instanceof m))return;this.logger.info(`Network error, disconnecting speculos device ${t}`),e(t),this.connectedDevice&&await this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval)}},2e3)}}const w=(a="http://127.0.0.1:5000",e=!1)=>({config:t,loggerServiceFactory:r})=>new I(r,t,a,e);export{I as SpeculosTransport,S as speculosIdentifier,w as speculosTransportFactory};
1
+ import{ApduParser as v,bufferToHexaString as g,DeviceModelId as D,GeneralDmkError as h,OpeningConnectionError as S}from"@ledgerhq/device-management-kit";import{Left as p,Right as a}from"purify-ts";import{from as l}from"rxjs";import{HttpSpeculosDatasource as b}from"../internal/datasource/HttpSpeculosDatasource";const m="SPECULOS_HTTP_TRANSPORT";class f{logger;identifier=m;_speculosDataSource;connectedDevice=null;disconnectInterval=null;speculosDevice={id:"SpeculosID",deviceModel:{id:D.STAX,productName:"Speculos - App Name - version",usbProductId:16,bootloaderUsbProductId:1,getBlockSize(){return 32},blockSize:32,usbOnly:!0,memorySize:320*1024,masks:[823132160]},transport:this.identifier};constructor(e,t,s){this.logger=e("SpeculosTransport"),this._speculosDataSource=new b(s)}isSupported(){return!0}getIdentifier(){return this.identifier}listenToAvailableDevices(){return l([[this.speculosDevice]])}startDiscovering(){return this.logger.debug("startDiscovering"),l([this.speculosDevice])}stopDiscovering(){this.logger.debug("stopDiscovering")}async connect(e){this.logger.debug("connect");const t=await this._speculosDataSource.postAdpu("B0010000");this.logger.debug(`Hex Response: ${t}`);const s=this.createApduResponse(t),r=new v(s);r.extract8BitUInt();const n=r.encodeToString(r.extractFieldLVEncoded()),o=r.encodeToString(r.extractFieldLVEncoded());this.logger.debug(`App Name: ${n} and version ${o}`);const c=e.deviceId;try{const i={sendApdu:u=>this.sendApdu(c,e.deviceId,e.onDisconnect,u),deviceModel:{...this.speculosDevice.deviceModel,productName:`Speculos - ${n} - ${o}`,getBlockSize(){return 32}},transport:this.identifier,id:"SpeculosID",type:"USB"};return this.connectedDevice=i,this.listenForDisconnect(e.onDisconnect,e.deviceId),a(i)}catch(i){return p(new S(i))}}async disconnect(e){return this.logger.debug("disconnect"),this.connectedDevice=null,Promise.resolve(a(void 0))}async sendApdu(e,t,s,r){try{const n=g(r).substring(2);this.logger.debug(`send APDU: ${n}`);const o=await this._speculosDataSource.postAdpu(n),c=this.createApduResponse(o);return a(c)}catch(n){return this.connectedDevice&&(this.logger.debug("disconnecting"),s(t),this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval)),p(new h(n))}}createApduResponse(e){return this.logger.debug(`Status code hex: ${e.substring(e.length-4,e.length)}`),this.logger.debug(`data hex: ${e.substring(0,e.length-4)}`),{statusCode:this.fromHexString(e.substring(e.length-4,e.length)),data:this.fromHexString(e.substring(0,e.length-4))}}fromHexString(e){return e?new Uint8Array(e.match(/.{1,2}/g).map(t=>parseInt(t,16))):Uint8Array.from([])}listenForDisconnect(e,t){this.disconnectInterval=setInterval(async()=>{await this._speculosDataSource.isServerAvailable()||(this.logger.info(`Speculos server unavailable, disconnecting device ${t}`),e(t),this.connectedDevice&&await this.disconnect({connectedDevice:this.connectedDevice}),this.disconnectInterval&&clearInterval(this.disconnectInterval))},2e3)}}const R=(d="http://127.0.0.1:5000")=>({config:e,loggerServiceFactory:t})=>new f(t,e,d);export{f as SpeculosTransport,m as speculosIdentifier,R as speculosTransportFactory};
2
2
  //# sourceMappingURL=SpeculosTransport.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/SpeculosTransport.ts"],
4
- "sourcesContent": ["import {\n ApduParser,\n type ApduResponse,\n bufferToHexaString,\n type ConnectError,\n type DeviceId,\n DeviceModelId,\n type DisconnectHandler,\n type DmkConfig,\n type DmkError,\n GeneralDmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n type TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { AxiosError } from \"axios\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { HttpLegacySpeculosDatasource } from \"@internal/datasource/HttpLegacySpeculosDatasource\";\nimport { HttpSpeculosDatasource } from \"@internal/datasource/HttpSpeculosDatasource\";\nimport { type SpeculosDatasource } from \"@internal/datasource/SpeculosDatasource\";\n\nexport const speculosIdentifier: TransportIdentifier =\n \"SPECULOS_HTTP_TRANSPORT\";\n\nexport class SpeculosTransport implements Transport {\n private logger: LoggerPublisherService;\n private readonly identifier: TransportIdentifier = speculosIdentifier;\n private readonly _speculosDataSource: SpeculosDatasource;\n private connectedDevice: TransportConnectedDevice | null = null;\n private disconnectInterval: NodeJS.Timeout | null = null;\n private readonly speculosDevice: TransportDiscoveredDevice = {\n id: \"SpeculosID\", //TODO make it dynamic at creation\n deviceModel: {\n id: DeviceModelId.STAX,\n productName: \"Speculos - App Name - version\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n getBlockSize() {\n return 32;\n },\n blockSize: 32,\n usbOnly: true,\n memorySize: 320 * 1024,\n masks: [0x31100000],\n },\n transport: this.identifier,\n };\n\n constructor(\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n _config: DmkConfig,\n speculosUrl: string,\n private readonly legacyE2ECompatibility: boolean,\n ) {\n this.logger = loggerServiceFactory(\"SpeculosTransport\");\n this._speculosDataSource = this.legacyE2ECompatibility\n ? new HttpLegacySpeculosDatasource(speculosUrl)\n : new HttpSpeculosDatasource(speculosUrl);\n }\n\n isSupported(): boolean {\n return true;\n }\n\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([[this.speculosDevice]]);\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n this.logger.debug(\"startDiscovering\");\n return from([this.speculosDevice]);\n }\n\n stopDiscovering(): void {\n //DO NOTHING HERE\n this.logger.debug(\"stopDiscovering\");\n }\n\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n this.logger.debug(\"connect\");\n\n const hexResponse = await this._speculosDataSource.postAdpu(\"B0010000\");\n this.logger.debug(`Hex Response: ${hexResponse}`);\n const apduResponse = this.createApduResponse(hexResponse);\n const parser = new ApduParser(apduResponse);\n\n //Copy paste from GetAppAndVersionCommand\n parser.extract8BitUInt(); //Need otherwise parser is not in the right position\n const appName = parser.encodeToString(parser.extractFieldLVEncoded());\n const appVersion = parser.encodeToString(parser.extractFieldLVEncoded());\n\n this.logger.debug(`App Name: ${appName} and version ${appVersion}`);\n\n const sessionId: string = params.deviceId;\n try {\n const connectedDevice: TransportConnectedDevice = {\n sendApdu: (apdu) => {\n return this.sendApdu(\n sessionId,\n params.deviceId,\n params.onDisconnect,\n apdu,\n );\n },\n deviceModel: {\n ...this.speculosDevice.deviceModel,\n productName: `Speculos - ${appName} - ${appVersion}`,\n getBlockSize() {\n return 32;\n },\n },\n transport: this.identifier,\n id: \"SpeculosID\", //TODO make it dynamic at creation\n type: \"USB\",\n };\n\n this.connectedDevice = connectedDevice;\n if (!this.legacyE2ECompatibility) {\n this.listenForDisconnect(params.onDisconnect, params.deviceId);\n }\n return Right(connectedDevice);\n } catch (error) {\n return Left(new OpeningConnectionError(error as Error));\n }\n }\n\n async disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n this.logger.debug(\"disconnect\");\n this.connectedDevice = null;\n return Promise.resolve(Right(undefined));\n }\n\n async sendApdu(\n _sessionId: string,\n deviceId: DeviceId,\n onDisconnect: DisconnectHandler,\n apdu: Uint8Array,\n ): Promise<Either<DmkError, ApduResponse>> {\n try {\n const hexApdu = bufferToHexaString(apdu).substring(2);\n this.logger.debug(`send APDU: ${hexApdu}`);\n const hexResponse = await this._speculosDataSource.postAdpu(hexApdu);\n return Right(this.createApduResponse(hexResponse));\n } catch (error) {\n if (this.connectedDevice) {\n this.logger.debug(\"disconnecting\");\n onDisconnect(deviceId);\n this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n return Left(new GeneralDmkError(error));\n }\n }\n\n private createApduResponse(hexApdu: string): ApduResponse {\n this.logger.debug(\n `Status code hex: ${hexApdu.substring(hexApdu.length - 4, hexApdu.length)}`,\n );\n this.logger.debug(`data hex: ${hexApdu.substring(0, hexApdu.length - 4)}`);\n\n const apduResponse = {\n statusCode: this.fromHexString(\n hexApdu.substring(hexApdu.length - 4, hexApdu.length),\n ),\n data: this.fromHexString(hexApdu.substring(0, hexApdu.length - 4)),\n };\n return apduResponse;\n }\n\n //TODO: Move this to a helper\n private fromHexString(hexString: string): Uint8Array {\n if (!hexString) {\n return Uint8Array.from([]);\n }\n return new Uint8Array(\n hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)),\n );\n }\n\n private listenForDisconnect(\n onDisconnect: DisconnectHandler,\n deviceId: DeviceId,\n ): void {\n this.disconnectInterval = setInterval(async () => {\n try {\n await this._speculosDataSource.postAdpu(\"B0010000\");\n } catch (error) {\n if (!(error instanceof AxiosError)) return;\n\n this.logger.info(\n `Network error, disconnecting speculos device ${deviceId}`,\n );\n onDisconnect(deviceId);\n\n if (this.connectedDevice) {\n await this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n }\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n }, 2000);\n }\n}\n\nexport const speculosTransportFactory: (\n speculosUrl?: string,\n legacyE2ECompatibility?: boolean,\n) => TransportFactory =\n (speculosUrl = \"http://127.0.0.1:5000\", legacyE2ECompatibility = false) =>\n ({ config, loggerServiceFactory }) =>\n new SpeculosTransport(\n loggerServiceFactory,\n config,\n speculosUrl,\n legacyE2ECompatibility,\n );\n"],
5
- "mappings": "AAAA,OACE,cAAAA,EAEA,sBAAAC,EA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,CACF,CAEQ,mBAAmBK,EAA+B,CACxD,YAAK,OAAO,MACV,oBAAoBA,EAAQ,UAAUA,EAAQ,OAAS,EAAGA,EAAQ,MAAM,CAAC,EAC3E,EACA,KAAK,OAAO,MAAM,aAAaA,EAAQ,UAAU,EAAGA,EAAQ,OAAS,CAAC,CAAC,EAAE,EAEpD,CACnB,WAAY,KAAK,cACfA,EAAQ,UAAUA,EAAQ,OAAS,EAAGA,EAAQ,MAAM,CACtD,EACA,KAAM,KAAK,cAAcA,EAAQ,UAAU,EAAGA,EAAQ,OAAS,CAAC,CAAC,CACnE,CAEF,CAGQ,cAAcC,EAA+B,CACnD,OAAKA,EAGE,IAAI,WACTA,EAAU,MAAM,SAAS,EAAG,IAAKC,GAAS,SAASA,EAAM,EAAE,CAAC,CAC9D,EAJS,WAAW,KAAK,CAAC,CAAC,CAK7B,CAEQ,oBACNH,EACAD,EACM,CACN,KAAK,mBAAqB,YAAY,SAAY,CAChD,GAAI,CACF,MAAM,KAAK,oBAAoB,SAAS,UAAU,CACpD,OAASH,EAAO,CACd,GAAI,EAAEA,aAAiBrB,GAAa,OAEpC,KAAK,OAAO,KACV,gDAAgDwB,CAAQ,EAC1D,EACAC,EAAaD,CAAQ,EAEjB,KAAK,iBACP,MAAM,KAAK,WAAW,CACpB,gBAAiB,KAAK,eACxB,CAAC,EAGC,KAAK,oBACP,cAAc,KAAK,kBAAkB,CAEzC,CACF,EAAG,GAAI,CACT,CACF,CAEO,MAAMK,EAIX,CAACnB,EAAc,wBAAyBC,EAAyB,KACjE,CAAC,CAAE,OAAAmB,EAAQ,qBAAAtB,CAAqB,IAC9B,IAAID,EACFC,EACAsB,EACApB,EACAC,CACF",
6
- "names": ["ApduParser", "bufferToHexaString", "DeviceModelId", "GeneralDmkError", "OpeningConnectionError", "AxiosError", "Left", "Right", "from", "HttpLegacySpeculosDatasource", "HttpSpeculosDatasource", "speculosIdentifier", "SpeculosTransport", "loggerServiceFactory", "_config", "speculosUrl", "legacyE2ECompatibility", "params", "hexResponse", "apduResponse", "parser", "appName", "appVersion", "sessionId", "connectedDevice", "apdu", "error", "_params", "_sessionId", "deviceId", "onDisconnect", "hexApdu", "hexString", "byte", "speculosTransportFactory", "config"]
4
+ "sourcesContent": ["import {\n ApduParser,\n type ApduResponse,\n bufferToHexaString,\n type ConnectError,\n type DeviceId,\n DeviceModelId,\n type DisconnectHandler,\n type DmkConfig,\n type DmkError,\n GeneralDmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n type TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { HttpSpeculosDatasource } from \"@internal/datasource/HttpSpeculosDatasource\";\nimport { type SpeculosDatasource } from \"@internal/datasource/SpeculosDatasource\";\n\nexport const speculosIdentifier: TransportIdentifier =\n \"SPECULOS_HTTP_TRANSPORT\";\n\nexport class SpeculosTransport implements Transport {\n private logger: LoggerPublisherService;\n private readonly identifier: TransportIdentifier = speculosIdentifier;\n private readonly _speculosDataSource: SpeculosDatasource;\n private connectedDevice: TransportConnectedDevice | null = null;\n private disconnectInterval: NodeJS.Timeout | null = null;\n private readonly speculosDevice: TransportDiscoveredDevice = {\n id: \"SpeculosID\", //TODO make it dynamic at creation\n deviceModel: {\n id: DeviceModelId.STAX,\n productName: \"Speculos - App Name - version\",\n usbProductId: 0x10,\n bootloaderUsbProductId: 0x0001,\n getBlockSize() {\n return 32;\n },\n blockSize: 32,\n usbOnly: true,\n memorySize: 320 * 1024,\n masks: [0x31100000],\n },\n transport: this.identifier,\n };\n\n constructor(\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n _config: DmkConfig,\n speculosUrl: string,\n ) {\n this.logger = loggerServiceFactory(\"SpeculosTransport\");\n this._speculosDataSource = new HttpSpeculosDatasource(speculosUrl); // See how to pass properly speculos config.\n }\n\n isSupported(): boolean {\n return true;\n }\n\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([[this.speculosDevice]]);\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n this.logger.debug(\"startDiscovering\");\n return from([this.speculosDevice]);\n }\n\n stopDiscovering(): void {\n //DO NOTHING HERE\n this.logger.debug(\"stopDiscovering\");\n }\n\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n this.logger.debug(\"connect\");\n\n const hexResponse = await this._speculosDataSource.postAdpu(\"B0010000\");\n this.logger.debug(`Hex Response: ${hexResponse}`);\n const apduResponse = this.createApduResponse(hexResponse);\n const parser = new ApduParser(apduResponse);\n\n //Copy paste from GetAppAndVersionCommand\n parser.extract8BitUInt(); //Need otherwise parser is not in the right position\n const appName = parser.encodeToString(parser.extractFieldLVEncoded());\n const appVersion = parser.encodeToString(parser.extractFieldLVEncoded());\n\n this.logger.debug(`App Name: ${appName} and version ${appVersion}`);\n\n const sessionId: string = params.deviceId;\n try {\n const connectedDevice: TransportConnectedDevice = {\n sendApdu: (apdu) => {\n return this.sendApdu(\n sessionId,\n params.deviceId,\n params.onDisconnect,\n apdu,\n );\n },\n deviceModel: {\n ...this.speculosDevice.deviceModel,\n productName: `Speculos - ${appName} - ${appVersion}`,\n getBlockSize() {\n return 32;\n },\n },\n transport: this.identifier,\n id: \"SpeculosID\", //TODO make it dynamic at creation\n type: \"USB\",\n };\n\n this.connectedDevice = connectedDevice;\n this.listenForDisconnect(params.onDisconnect, params.deviceId);\n return Right(connectedDevice);\n } catch (error) {\n return Left(new OpeningConnectionError(error as Error));\n }\n }\n\n async disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n this.logger.debug(\"disconnect\");\n this.connectedDevice = null;\n return Promise.resolve(Right(undefined));\n }\n\n async sendApdu(\n _sessionId: string,\n deviceId: DeviceId,\n onDisconnect: DisconnectHandler,\n apdu: Uint8Array,\n ): Promise<Either<DmkError, ApduResponse>> {\n try {\n const hexApdu = bufferToHexaString(apdu).substring(2);\n this.logger.debug(`send APDU: ${hexApdu}`);\n const hexResponse: string =\n await this._speculosDataSource.postAdpu(hexApdu);\n const apduResponse = this.createApduResponse(hexResponse);\n return Right(apduResponse);\n } catch (error) {\n if (this.connectedDevice) {\n this.logger.debug(\"disconnecting\");\n onDisconnect(deviceId);\n this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n return Left(new GeneralDmkError(error));\n }\n }\n\n private createApduResponse(hexApdu: string): ApduResponse {\n this.logger.debug(\n `Status code hex: ${hexApdu.substring(hexApdu.length - 4, hexApdu.length)}`,\n );\n this.logger.debug(`data hex: ${hexApdu.substring(0, hexApdu.length - 4)}`);\n\n const apduResponse = {\n statusCode: this.fromHexString(\n hexApdu.substring(hexApdu.length - 4, hexApdu.length),\n ),\n data: this.fromHexString(hexApdu.substring(0, hexApdu.length - 4)),\n };\n return apduResponse;\n }\n\n //TODO: Move this to a helper\n private fromHexString(hexString: string): Uint8Array {\n if (!hexString) {\n return Uint8Array.from([]);\n }\n return new Uint8Array(\n hexString.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)),\n );\n }\n\n private listenForDisconnect(\n onDisconnect: DisconnectHandler,\n deviceId: DeviceId,\n ): void {\n this.disconnectInterval = setInterval(async () => {\n const isServerAvailable =\n await this._speculosDataSource.isServerAvailable();\n\n if (!isServerAvailable) {\n this.logger.info(\n `Speculos server unavailable, disconnecting device ${deviceId}`,\n );\n onDisconnect(deviceId);\n\n if (this.connectedDevice) {\n await this.disconnect({\n connectedDevice: this.connectedDevice,\n });\n }\n\n if (this.disconnectInterval) {\n clearInterval(this.disconnectInterval);\n }\n }\n }, 2000);\n }\n}\n\nexport const speculosTransportFactory: (\n speculosUrl?: string,\n) => TransportFactory =\n (speculosUrl = \"http://127.0.0.1:5000\") =>\n ({ config, loggerServiceFactory }) =>\n new SpeculosTransport(loggerServiceFactory, config, speculosUrl);\n"],
5
+ "mappings": "AAAA,OACE,cAAAA,EAEA,sBAAAC,EAGA,iBAAAC,EAIA,mBAAAC,EAEA,0BAAAC,MAMK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,MAAa,YACzC,OAAS,QAAAC,MAA6B,OAEtC,OAAS,0BAAAC,MAA8B,8CAGhC,MAAMC,EACX,0BAEK,MAAMC,CAAuC,CAC1C,OACS,WAAkCD,EAClC,oBACT,gBAAmD,KACnD,mBAA4C,KACnC,eAA4C,CAC3D,GAAI,aACJ,YAAa,CACX,GAAIP,EAAc,KAClB,YAAa,gCACb,aAAc,GACd,uBAAwB,EACxB,cAAe,CACb,MAAO,GACT,EACA,UAAW,GACX,QAAS,GACT,WAAY,IAAM,KAClB,MAAO,CAAC,SAAU,CACpB,EACA,UAAW,KAAK,UAClB,EAEA,YACES,EACAC,EACAC,EACA,CACA,KAAK,OAASF,EAAqB,mBAAmB,EACtD,KAAK,oBAAsB,IAAIH,EAAuBK,CAAW,CACnE,CAEA,aAAuB,CACrB,MAAO,EACT,CAEA,eAAqC,CACnC,OAAO,KAAK,UACd,CAEA,0BAAoE,CAClE,OAAON,EAAK,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CACrC,CAEA,kBAA0D,CACxD,YAAK,OAAO,MAAM,kBAAkB,EAC7BA,EAAK,CAAC,KAAK,cAAc,CAAC,CACnC,CAEA,iBAAwB,CAEtB,KAAK,OAAO,MAAM,iBAAiB,CACrC,CAEA,MAAM,QAAQO,EAG8C,CAC1D,KAAK,OAAO,MAAM,SAAS,EAE3B,MAAMC,EAAc,MAAM,KAAK,oBAAoB,SAAS,UAAU,EACtE,KAAK,OAAO,MAAM,iBAAiBA,CAAW,EAAE,EAChD,MAAMC,EAAe,KAAK,mBAAmBD,CAAW,EAClDE,EAAS,IAAIjB,EAAWgB,CAAY,EAG1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K,CAAC,CACxC,CACF,CAEQ,mBAAmBK,EAA+B,CACxD,YAAK,OAAO,MACV,oBAAoBA,EAAQ,UAAUA,EAAQ,OAAS,EAAGA,EAAQ,MAAM,CAAC,EAC3E,EACA,KAAK,OAAO,MAAM,aAAaA,EAAQ,UAAU,EAAGA,EAAQ,OAAS,CAAC,CAAC,EAAE,EAEpD,CACnB,WAAY,KAAK,cACfA,EAAQ,UAAUA,EAAQ,OAAS,EAAGA,EAAQ,MAAM,CACtD,EACA,KAAM,KAAK,cAAcA,EAAQ,UAAU,EAAGA,EAAQ,OAAS,CAAC,CAAC,CACnE,CAEF,CAGQ,cAAcC,EAA+B,CACnD,OAAKA,EAGE,IAAI,WACTA,EAAU,MAAM,SAAS,EAAG,IAAKC,GAAS,SAASA,EAAM,EAAE,CAAC,CAC9D,EAJS,WAAW,KAAK,CAAC,CAAC,CAK7B,CAEQ,oBACNH,EACAD,EACM,CACN,KAAK,mBAAqB,YAAY,SAAY,CAE9C,MAAM,KAAK,oBAAoB,kBAAkB,IAGjD,KAAK,OAAO,KACV,qDAAqDA,CAAQ,EAC/D,EACAC,EAAaD,CAAQ,EAEjB,KAAK,iBACP,MAAM,KAAK,WAAW,CACpB,gBAAiB,KAAK,eACxB,CAAC,EAGC,KAAK,oBACP,cAAc,KAAK,kBAAkB,EAG3C,EAAG,GAAI,CACT,CACF,CAEO,MAAMK,EAGX,CAAClB,EAAc,0BACf,CAAC,CAAE,OAAAmB,EAAQ,qBAAArB,CAAqB,IAC9B,IAAID,EAAkBC,EAAsBqB,EAAQnB,CAAW",
6
+ "names": ["ApduParser", "bufferToHexaString", "DeviceModelId", "GeneralDmkError", "OpeningConnectionError", "Left", "Right", "from", "HttpSpeculosDatasource", "speculosIdentifier", "SpeculosTransport", "loggerServiceFactory", "_config", "speculosUrl", "params", "hexResponse", "apduResponse", "parser", "appName", "appVersion", "sessionId", "connectedDevice", "apdu", "error", "_params", "_sessionId", "deviceId", "onDisconnect", "hexApdu", "hexString", "byte", "speculosTransportFactory", "config"]
7
7
  }
@@ -1,2 +1,2 @@
1
- export*from"./api/QuietSpeculosTransport";export*from"./api/SpeculosTransport";
1
+ export*from"./api/E2eSpeculosTransport";export*from"./api/SpeculosTransport";
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 * from \"./api/QuietSpeculosTransport\";\nexport * from \"./api/SpeculosTransport\";\n"],
5
- "mappings": "AAAA,WAAc,+BACd,WAAc",
4
+ "sourcesContent": ["export * from \"./api/E2eSpeculosTransport\";\nexport * from \"./api/SpeculosTransport\";\n"],
5
+ "mappings": "AAAA,WAAc,6BACd,WAAc",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,3 @@
1
+ import{makeKeepAliveAxiosForSSE as c,makeNoKeepAliveAxios as i}from"../utils/axiosInstances";class m{constructor(t,e=1e4,s="ldmk-transport-speculos"){this.baseUrl=t;this.timeoutMs=e;this.apduClient=i(t,e,s),this.buttonClient=i(t,Math.min(e,2e3),s),this.sseClient=c(t,s)}apduClient;buttonClient;sseClient;async postAdpu(t){const{data:e}=await this.apduClient.post("/apdu",{data:t},{timeout:this.timeoutMs});return e.data}async pressButton(t){const s={Ll:"left",Rr:"right",LRlr:"both",left:"left",right:"right",both:"both"}[t]??"right";await this.buttonClient.post(`/button/${s}`,{action:"press-and-release"},{timeout:Math.min(this.timeoutMs,1500)})}async openEventStream(t,e){const o=(await this.sseClient.get("/events",{params:{stream:"true"},responseType:"stream",timeout:0,headers:{Accept:"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive","Accept-Encoding":"identity"}})).data;o.on("data",p=>{p.toString("utf8").split(`
2
+ `).forEach(n=>{if(n.startsWith("data: ")){const r=n.slice(6);try{t(JSON.parse(r))}catch{t({data:r})}}})});const a=()=>e?.();return o.on("close",a),o.on("end",a),o.on("error",a),o}get base(){return this.baseUrl}}export{m as E2eHttpSpeculosDatasource};
3
+ //# sourceMappingURL=E2eHttpSpeculosDatasource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/datasource/E2eHttpSpeculosDatasource.ts"],
4
+ "sourcesContent": ["import { type AxiosInstance } from \"axios\";\n\nimport {\n makeKeepAliveAxiosForSSE,\n makeNoKeepAliveAxios,\n} from \"@internal/utils/axiosInstances\";\n\nimport { type E2eSpeculosDatasource } from \"./E2eSpeculosDatasource\";\n\ntype SpeculosApduDTO = { data: string };\n\nexport type SpeculosDeviceButtonsKeys =\n | \"Ll\"\n | \"Rr\"\n | \"LRlr\"\n | \"left\"\n | \"right\"\n | \"both\";\n\nexport class E2eHttpSpeculosDatasource implements E2eSpeculosDatasource {\n private readonly apduClient: AxiosInstance;\n private readonly buttonClient: AxiosInstance;\n private readonly sseClient: AxiosInstance;\n\n constructor(\n private readonly baseUrl: string,\n private readonly timeoutMs: number = 10000,\n clientHeader: string = \"ldmk-transport-speculos\",\n ) {\n this.apduClient = makeNoKeepAliveAxios(baseUrl, timeoutMs, clientHeader);\n this.buttonClient = makeNoKeepAliveAxios(\n baseUrl,\n Math.min(timeoutMs, 2000),\n clientHeader,\n );\n\n this.sseClient = makeKeepAliveAxiosForSSE(baseUrl, clientHeader);\n }\n\n async postAdpu(apdu: string): Promise<string> {\n const { data } = await this.apduClient.post<SpeculosApduDTO>(\n \"/apdu\",\n { data: apdu },\n { timeout: this.timeoutMs },\n );\n return data.data;\n }\n\n async pressButton(but: SpeculosDeviceButtonsKeys): Promise<void> {\n const map: Record<string, \"left\" | \"right\" | \"both\"> = {\n Ll: \"left\",\n Rr: \"right\",\n LRlr: \"both\",\n left: \"left\",\n right: \"right\",\n both: \"both\",\n };\n const input = map[but] ?? \"right\";\n await this.buttonClient.post(\n `/button/${input}`,\n { action: \"press-and-release\" },\n { timeout: Math.min(this.timeoutMs, 1500) },\n );\n }\n\n async openEventStream(\n onEvent: (json: Record<string, unknown>) => void,\n onClose?: () => void,\n ): Promise<NodeJS.ReadableStream> {\n const response = await this.sseClient.get(\"/events\", {\n params: { stream: \"true\" },\n responseType: \"stream\",\n timeout: 0,\n headers: {\n Accept: \"text/event-stream\",\n \"Cache-Control\": \"no-cache\",\n Connection: \"keep-alive\",\n \"Accept-Encoding\": \"identity\",\n },\n });\n\n const stream = response.data as NodeJS.ReadableStream;\n\n stream.on(\"data\", (chunk: Buffer) => {\n const txt = chunk.toString(\"utf8\");\n txt.split(\"\\n\").forEach((line) => {\n if (line.startsWith(\"data: \")) {\n const payload = line.slice(6);\n try {\n onEvent(JSON.parse(payload));\n } catch {\n onEvent({ data: payload });\n }\n }\n });\n });\n\n const end = () => onClose?.();\n stream.on(\"close\", end);\n stream.on(\"end\", end);\n stream.on(\"error\", end);\n\n return stream;\n }\n\n get base(): string {\n return this.baseUrl;\n }\n}\n"],
5
+ "mappings": "AAEA,OACE,4BAAAA,EACA,wBAAAC,MACK,iCAcA,MAAMC,CAA2D,CAKtE,YACmBC,EACAC,EAAoB,IACrCC,EAAuB,0BACvB,CAHiB,aAAAF,EACA,eAAAC,EAGjB,KAAK,WAAaH,EAAqBE,EAASC,EAAWC,CAAY,EACvE,KAAK,aAAeJ,EAClBE,EACA,KAAK,IAAIC,EAAW,GAAI,EACxBC,CACF,EAEA,KAAK,UAAYL,EAAyBG,EAASE,CAAY,CACjE,CAjBiB,WACA,aACA,UAiBjB,MAAM,SAASC,EAA+B,CAC5C,KAAM,CAAE,KAAAC,CAAK,EAAI,MAAM,KAAK,WAAW,KACrC,QACA,CAAE,KAAMD,CAAK,EACb,CAAE,QAAS,KAAK,SAAU,CAC5B,EACA,OAAOC,EAAK,IACd,CAEA,MAAM,YAAYC,EAA+C,CAS/D,MAAMC,EARiD,CACrD,GAAI,OACJ,GAAI,QACJ,KAAM,OACN,KAAM,OACN,MAAO,QACP,KAAM,MACR,EACkBD,CAAG,GAAK,QAC1B,MAAM,KAAK,aAAa,KACtB,WAAWC,CAAK,GAChB,CAAE,OAAQ,mBAAoB,EAC9B,CAAE,QAAS,KAAK,IAAI,KAAK,UAAW,IAAI,CAAE,CAC5C,CACF,CAEA,MAAM,gBACJC,EACAC,EACgC,CAahC,MAAMC,GAZW,MAAM,KAAK,UAAU,IAAI,UAAW,CACnD,OAAQ,CAAE,OAAQ,MAAO,EACzB,aAAc,SACd,QAAS,EACT,QAAS,CACP,OAAQ,oBACR,gBAAiB,WACjB,WAAY,aACZ,kBAAmB,UACrB,CACF,CAAC,GAEuB,KAExBA,EAAO,GAAG,OAASC,GAAkB,CACvBA,EAAM,SAAS,MAAM,EAC7B,MAAM;AAAA,CAAI,EAAE,QAASC,GAAS,CAChC,GAAIA,EAAK,WAAW,QAAQ,EAAG,CAC7B,MAAMC,EAAUD,EAAK,MAAM,CAAC,EAC5B,GAAI,CACFJ,EAAQ,KAAK,MAAMK,CAAO,CAAC,CAC7B,MAAQ,CACNL,EAAQ,CAAE,KAAMK,CAAQ,CAAC,CAC3B,CACF,CACF,CAAC,CACH,CAAC,EAED,MAAMC,EAAM,IAAML,IAAU,EAC5B,OAAAC,EAAO,GAAG,QAASI,CAAG,EACtBJ,EAAO,GAAG,MAAOI,CAAG,EACpBJ,EAAO,GAAG,QAASI,CAAG,EAEfJ,CACT,CAEA,IAAI,MAAe,CACjB,OAAO,KAAK,OACd,CACF",
6
+ "names": ["makeKeepAliveAxiosForSSE", "makeNoKeepAliveAxios", "E2eHttpSpeculosDatasource", "baseUrl", "timeoutMs", "clientHeader", "apdu", "data", "but", "input", "onEvent", "onClose", "stream", "chunk", "line", "payload", "end"]
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=E2eSpeculosDatasource.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -1,2 +1,2 @@
1
- import t from"axios";import o from"../../../package.json";class c{constructor(s){this.baseUrl=s}async postAdpu(s){const e={data:s};return(await t.request({method:"POST",url:`${this.baseUrl}/apdu`,data:e,headers:{"X-Ledger-Client-Version":`ldmk-transport-speculos/${o.version}`}})).data.data}}export{c as HttpSpeculosDatasource};
1
+ import s from"axios";import t from"../../../package.json";const o=5e3;class l{constructor(e){this.baseUrl=e}async postAdpu(e){const r={data:e};return(await s.request({method:"POST",url:`${this.baseUrl}/apdu`,data:r,headers:{"X-Ledger-Client-Version":`ldmk-transport-speculos/${t.version}`}})).data.data}async isServerAvailable(){try{return await s.request({method:"GET",url:`${this.baseUrl}/events`,headers:{"X-Ledger-Client-Version":`ldmk-transport-speculos/${t.version}`},timeout:o}),!0}catch{return!1}}}export{l as HttpSpeculosDatasource};
2
2
  //# sourceMappingURL=HttpSpeculosDatasource.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/internal/datasource/HttpSpeculosDatasource.ts"],
4
- "sourcesContent": ["import axios from \"axios\";\n\nimport PACKAGE from \"@root/package.json\";\n\nimport { type SpeculosDatasource } from \"./SpeculosDatasource\";\nexport class HttpSpeculosDatasource implements SpeculosDatasource {\n constructor(private readonly baseUrl: string) {}\n\n async postAdpu(apdu: string): Promise<string> {\n const requestDto = {\n data: apdu,\n };\n\n const speculosResponse = await axios.request<SpeculosApduDTO>({\n method: \"POST\",\n url: `${this.baseUrl}/apdu`,\n data: requestDto,\n headers: {\n \"X-Ledger-Client-Version\": `ldmk-transport-speculos/${PACKAGE.version}`,\n },\n });\n\n return speculosResponse.data.data;\n }\n}\n\ntype SpeculosApduDTO = {\n data: string;\n};\n"],
5
- "mappings": "AAAA,OAAOA,MAAW,QAElB,OAAOC,MAAa,qBAGb,MAAMC,CAAqD,CAChE,YAA6BC,EAAiB,CAAjB,aAAAA,CAAkB,CAE/C,MAAM,SAASC,EAA+B,CAC5C,MAAMC,EAAa,CACjB,KAAMD,CACR,EAWA,OATyB,MAAMJ,EAAM,QAAyB,CAC5D,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,QACpB,KAAMK,EACN,QAAS,CACP,0BAA2B,2BAA2BJ,EAAQ,OAAO,EACvE,CACF,CAAC,GAEuB,KAAK,IAC/B,CACF",
6
- "names": ["axios", "PACKAGE", "HttpSpeculosDatasource", "baseUrl", "apdu", "requestDto"]
4
+ "sourcesContent": ["import axios from \"axios\";\n\nimport PACKAGE from \"@root/package.json\";\n\nimport { type SpeculosDatasource } from \"./SpeculosDatasource\";\n\nconst TIMEOUT = 5000; // 5 second timeout for availability check\n\nexport class HttpSpeculosDatasource implements SpeculosDatasource {\n constructor(private readonly baseUrl: string) {}\n\n async postAdpu(apdu: string): Promise<string> {\n const requestDto = {\n data: apdu,\n };\n\n const speculosResponse = await axios.request<SpeculosApduDTO>({\n method: \"POST\",\n url: `${this.baseUrl}/apdu`,\n data: requestDto,\n headers: {\n \"X-Ledger-Client-Version\": `ldmk-transport-speculos/${PACKAGE.version}`,\n },\n });\n\n return speculosResponse.data.data;\n }\n\n async isServerAvailable(): Promise<boolean> {\n try {\n await axios.request<SpeculosEventsDTO>({\n method: \"GET\",\n url: `${this.baseUrl}/events`,\n headers: {\n \"X-Ledger-Client-Version\": `ldmk-transport-speculos/${PACKAGE.version}`,\n },\n timeout: TIMEOUT,\n });\n return true;\n } catch (_error) {\n return false;\n }\n }\n}\n\ntype SpeculosApduDTO = {\n data: string;\n};\n\ntype SpeculosEventsDTO = {\n events: Array<{\n text?: string;\n x?: number;\n y?: number;\n }>;\n};\n"],
5
+ "mappings": "AAAA,OAAOA,MAAW,QAElB,OAAOC,MAAa,qBAIpB,MAAMC,EAAU,IAET,MAAMC,CAAqD,CAChE,YAA6BC,EAAiB,CAAjB,aAAAA,CAAkB,CAE/C,MAAM,SAASC,EAA+B,CAC5C,MAAMC,EAAa,CACjB,KAAMD,CACR,EAWA,OATyB,MAAML,EAAM,QAAyB,CAC5D,OAAQ,OACR,IAAK,GAAG,KAAK,OAAO,QACpB,KAAMM,EACN,QAAS,CACP,0BAA2B,2BAA2BL,EAAQ,OAAO,EACvE,CACF,CAAC,GAEuB,KAAK,IAC/B,CAEA,MAAM,mBAAsC,CAC1C,GAAI,CACF,aAAMD,EAAM,QAA2B,CACrC,OAAQ,MACR,IAAK,GAAG,KAAK,OAAO,UACpB,QAAS,CACP,0BAA2B,2BAA2BC,EAAQ,OAAO,EACvE,EACA,QAASC,CACX,CAAC,EACM,EACT,MAAiB,CACf,MAAO,EACT,CACF,CACF",
6
+ "names": ["axios", "PACKAGE", "TIMEOUT", "HttpSpeculosDatasource", "baseUrl", "apdu", "requestDto"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import n from"axios";import r from"http";import i from"https";function c(e,t,o){return n.create({baseURL:e.replace(/\/+$/,""),timeout:t,proxy:!1,headers:{"X-Ledger-Client-Version":o,Connection:"close"},httpAgent:new r.Agent({keepAlive:!1,maxSockets:1/0}),httpsAgent:new i.Agent({keepAlive:!1,maxSockets:1/0}),transitional:{clarifyTimeoutError:!0}})}function l(e,t){return n.create({baseURL:e.replace(/\/+$/,""),timeout:0,proxy:!1,headers:{"X-Ledger-Client-Version":t,Connection:"keep-alive"},httpAgent:new r.Agent({keepAlive:!0,maxSockets:1,maxFreeSockets:1}),httpsAgent:new i.Agent({keepAlive:!0,maxSockets:1,maxFreeSockets:1}),transitional:{clarifyTimeoutError:!0}})}export{l as makeKeepAliveAxiosForSSE,c as makeNoKeepAliveAxios};
2
+ //# sourceMappingURL=axiosInstances.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../src/internal/utils/axiosInstances.ts"],
4
+ "sourcesContent": ["import axios, { type AxiosInstance } from \"axios\";\nimport http from \"http\";\nimport https from \"https\";\n\nexport function makeNoKeepAliveAxios(\n baseUrl: string,\n timeoutMs: number,\n clientHeader: string,\n): AxiosInstance {\n return axios.create({\n baseURL: baseUrl.replace(/\\/+$/, \"\"),\n timeout: timeoutMs,\n proxy: false,\n headers: {\n \"X-Ledger-Client-Version\": clientHeader,\n Connection: \"close\",\n },\n httpAgent: new http.Agent({ keepAlive: false, maxSockets: Infinity }),\n httpsAgent: new https.Agent({ keepAlive: false, maxSockets: Infinity }),\n transitional: { clarifyTimeoutError: true },\n });\n}\n\nexport function makeKeepAliveAxiosForSSE(\n baseUrl: string,\n clientHeader: string,\n): AxiosInstance {\n return axios.create({\n baseURL: baseUrl.replace(/\\/+$/, \"\"),\n timeout: 0,\n proxy: false,\n headers: {\n \"X-Ledger-Client-Version\": clientHeader,\n\n Connection: \"keep-alive\",\n },\n httpAgent: new http.Agent({\n keepAlive: true,\n maxSockets: 1,\n maxFreeSockets: 1,\n }),\n httpsAgent: new https.Agent({\n keepAlive: true,\n maxSockets: 1,\n maxFreeSockets: 1,\n }),\n transitional: { clarifyTimeoutError: true },\n });\n}\n"],
5
+ "mappings": "AAAA,OAAOA,MAAmC,QAC1C,OAAOC,MAAU,OACjB,OAAOC,MAAW,QAEX,SAASC,EACdC,EACAC,EACAC,EACe,CACf,OAAON,EAAM,OAAO,CAClB,QAASI,EAAQ,QAAQ,OAAQ,EAAE,EACnC,QAASC,EACT,MAAO,GACP,QAAS,CACP,0BAA2BC,EAC3B,WAAY,OACd,EACA,UAAW,IAAIL,EAAK,MAAM,CAAE,UAAW,GAAO,WAAY,GAAS,CAAC,EACpE,WAAY,IAAIC,EAAM,MAAM,CAAE,UAAW,GAAO,WAAY,GAAS,CAAC,EACtE,aAAc,CAAE,oBAAqB,EAAK,CAC5C,CAAC,CACH,CAEO,SAASK,EACdH,EACAE,EACe,CACf,OAAON,EAAM,OAAO,CAClB,QAASI,EAAQ,QAAQ,OAAQ,EAAE,EACnC,QAAS,EACT,MAAO,GACP,QAAS,CACP,0BAA2BE,EAE3B,WAAY,YACd,EACA,UAAW,IAAIL,EAAK,MAAM,CACxB,UAAW,GACX,WAAY,EACZ,eAAgB,CAClB,CAAC,EACD,WAAY,IAAIC,EAAM,MAAM,CAC1B,UAAW,GACX,WAAY,EACZ,eAAgB,CAClB,CAAC,EACD,aAAc,CAAE,oBAAqB,EAAK,CAC5C,CAAC,CACH",
6
+ "names": ["axios", "http", "https", "makeNoKeepAliveAxios", "baseUrl", "timeoutMs", "clientHeader", "makeKeepAliveAxiosForSSE"]
7
+ }
@@ -1,7 +1,7 @@
1
1
  import { type ApduResponse, type ConnectError, type DeviceId, type DisconnectHandler, type DmkConfig, type DmkError, type LoggerPublisherService, type Transport, type TransportConnectedDevice, type TransportDiscoveredDevice, type TransportFactory, type TransportIdentifier } from "@ledgerhq/device-management-kit";
2
2
  import { type Either } from "purify-ts";
3
3
  import { type Observable } from "rxjs";
4
- export declare class QuietSpeculosTransport implements Transport {
4
+ export declare class E2eSpeculosTransport implements Transport {
5
5
  private logger;
6
6
  private readonly identifier;
7
7
  private readonly _speculosDataSource;
@@ -24,5 +24,5 @@ export declare class QuietSpeculosTransport implements Transport {
24
24
  private createApduResponse;
25
25
  private fromHexString;
26
26
  }
27
- export declare const quietSpeculosTransportFactory: (speculosUrl?: string) => TransportFactory;
28
- //# sourceMappingURL=QuietSpeculosTransport.d.ts.map
27
+ export declare const e2eSpeculosTransportFactory: (speculosUrl?: string) => TransportFactory;
28
+ //# sourceMappingURL=E2eSpeculosTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"E2eSpeculosTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/E2eSpeculosTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,QAAQ,EAEb,KAAK,sBAAsB,EAE3B,KAAK,SAAS,EACd,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,WAAW,CAAC;AACrD,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAO7C,qBAAa,oBAAqB,YAAW,SAAS;IACpD,OAAO,CAAC,MAAM,CAAyB;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2C;IAEtE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAwB;IAE5D,OAAO,CAAC,eAAe,CAAyC;IAEhE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAgB7B;gBAGA,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB,EAC7D,OAAO,EAAE,SAAS,EAClB,WAAW,EAAE,MAAM;IAUrB,WAAW,IAAI,OAAO;IAItB,aAAa,IAAI,mBAAmB;IAIpC,wBAAwB,IAAI,UAAU,CAAC,yBAAyB,EAAE,CAAC;IAInE,gBAAgB,IAAI,UAAU,CAAC,yBAAyB,CAAC;IAKzD,eAAe,IAAI,IAAI;IAIjB,OAAO,CAAC,MAAM,EAAE;QACpB,QAAQ,EAAE,QAAQ,CAAC;QACnB,YAAY,EAAE,iBAAiB,CAAC;KACjC,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,wBAAwB,CAAC,CAAC;IAmCrD,UAAU,CAAC,OAAO,EAAE;QACxB,eAAe,EAAE,wBAAwB,CAAC;KAC3C,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAM7B,QAAQ,CACZ,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,iBAAiB,EAC/B,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAiB1C,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,aAAa;CAMtB;AAED,eAAO,MAAM,2BAA2B,EAAE,CACxC,WAAW,CAAC,EAAE,MAAM,KACjB,gBAGkE,CAAC"}
@@ -3,14 +3,13 @@ import { type Either } from "purify-ts";
3
3
  import { type Observable } from "rxjs";
4
4
  export declare const speculosIdentifier: TransportIdentifier;
5
5
  export declare class SpeculosTransport implements Transport {
6
- private readonly legacyE2ECompatibility;
7
6
  private logger;
8
7
  private readonly identifier;
9
8
  private readonly _speculosDataSource;
10
9
  private connectedDevice;
11
10
  private disconnectInterval;
12
11
  private readonly speculosDevice;
13
- constructor(loggerServiceFactory: (tag: string) => LoggerPublisherService, _config: DmkConfig, speculosUrl: string, legacyE2ECompatibility: boolean);
12
+ constructor(loggerServiceFactory: (tag: string) => LoggerPublisherService, _config: DmkConfig, speculosUrl: string);
14
13
  isSupported(): boolean;
15
14
  getIdentifier(): TransportIdentifier;
16
15
  listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]>;
@@ -28,5 +27,5 @@ export declare class SpeculosTransport implements Transport {
28
27
  private fromHexString;
29
28
  private listenForDisconnect;
30
29
  }
31
- export declare const speculosTransportFactory: (speculosUrl?: string, legacyE2ECompatibility?: boolean) => TransportFactory;
30
+ export declare const speculosTransportFactory: (speculosUrl?: string) => TransportFactory;
32
31
  //# sourceMappingURL=SpeculosTransport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SpeculosTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/SpeculosTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EAEjB,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,QAAQ,EAEb,KAAK,sBAAsB,EAE3B,KAAK,SAAS,EACd,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,WAAW,CAAC;AACrD,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAM7C,eAAO,MAAM,kBAAkB,EAAE,mBACN,CAAC;AAE5B,qBAAa,iBAAkB,YAAW,SAAS;IA4B/C,OAAO,CAAC,QAAQ,CAAC,sBAAsB;I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AC;IA8CrD,UAAU,CAAC,OAAO,EAAE;QACxB,eAAe,EAAE,wBAAwB,CAAC;KAC3C,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAM7B,QAAQ,CACZ,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,iBAAiB,EAC/B,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAwB1C,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,aAAa;IASrB,OAAO,CAAC,mBAAmB;CA0B5B;AAED,eAAO,MAAM,wBAAwB,EAAE,CACrC,WAAW,CAAC,EAAE,MAAM,KACjB,gBAG+D,CAAC"}
@@ -1,3 +1,3 @@
1
- export * from "./api/QuietSpeculosTransport";
1
+ export * from "./api/E2eSpeculosTransport";
2
2
  export * from "./api/SpeculosTransport";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,yBAAyB,CAAC"}