@ledgerhq/device-management-kit 0.0.0-rn-ble-pairing-removed-while-reconnecting-20250731150808 → 0.0.0-rn-ble-perf-20251009143619

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 (106) hide show
  1. package/README.md +3 -3
  2. package/lib/cjs/package.json +1 -1
  3. package/lib/cjs/src/api/DeviceManagementKit.js +1 -1
  4. package/lib/cjs/src/api/DeviceManagementKit.js.map +3 -3
  5. package/lib/cjs/src/api/DeviceManagementKit.test.js +1 -1
  6. package/lib/cjs/src/api/DeviceManagementKit.test.js.map +3 -3
  7. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  8. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js.map +2 -2
  9. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  10. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  11. package/lib/cjs/src/api/apdu/utils/ByteArrayParser.js +1 -1
  12. package/lib/cjs/src/api/apdu/utils/ByteArrayParser.js.map +3 -3
  13. package/lib/cjs/src/api/command/os/__mocks__/GetOsVersionCommand.js +1 -1
  14. package/lib/cjs/src/api/command/os/__mocks__/GetOsVersionCommand.js.map +2 -2
  15. package/lib/cjs/src/api/device/DeviceModel.js +1 -1
  16. package/lib/cjs/src/api/device/DeviceModel.js.map +2 -2
  17. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  18. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
  19. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  20. package/lib/cjs/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
  21. package/lib/cjs/src/api/device-action/xstate-utils/XStateDeviceAction.js +1 -1
  22. package/lib/cjs/src/api/device-action/xstate-utils/XStateDeviceAction.js.map +2 -2
  23. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
  24. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.js.map +2 -2
  25. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
  26. package/lib/cjs/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +2 -2
  27. package/lib/cjs/src/api/device-model/model/DeviceModel.js +1 -1
  28. package/lib/cjs/src/api/device-model/model/DeviceModel.js.map +2 -2
  29. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  30. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  31. package/lib/cjs/src/api/transport/model/Errors.js +1 -1
  32. package/lib/cjs/src/api/transport/model/Errors.js.map +3 -3
  33. package/lib/cjs/src/api/utils/HexaString.js +1 -1
  34. package/lib/cjs/src/api/utils/HexaString.js.map +3 -3
  35. package/lib/cjs/src/api/utils/HexaString.test.js +1 -1
  36. package/lib/cjs/src/api/utils/HexaString.test.js.map +2 -2
  37. package/lib/cjs/src/internal/device-session/service/DefaultApduReceiverService.js +1 -1
  38. package/lib/cjs/src/internal/device-session/service/DefaultApduReceiverService.js.map +2 -2
  39. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  40. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  41. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.test.js +1 -1
  42. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.test.js.map +2 -2
  43. package/lib/esm/package.json +1 -1
  44. package/lib/esm/src/api/DeviceManagementKit.js +1 -1
  45. package/lib/esm/src/api/DeviceManagementKit.js.map +3 -3
  46. package/lib/esm/src/api/DeviceManagementKit.test.js +1 -1
  47. package/lib/esm/src/api/DeviceManagementKit.test.js.map +3 -3
  48. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  49. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js.map +3 -3
  50. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  51. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  52. package/lib/esm/src/api/apdu/utils/ByteArrayParser.js +1 -1
  53. package/lib/esm/src/api/apdu/utils/ByteArrayParser.js.map +3 -3
  54. package/lib/esm/src/api/command/os/__mocks__/GetOsVersionCommand.js +1 -1
  55. package/lib/esm/src/api/command/os/__mocks__/GetOsVersionCommand.js.map +2 -2
  56. package/lib/esm/src/api/device/DeviceModel.js +1 -1
  57. package/lib/esm/src/api/device/DeviceModel.js.map +2 -2
  58. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js +1 -1
  59. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.js.map +3 -3
  60. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js +1 -1
  61. package/lib/esm/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.test.js.map +2 -2
  62. package/lib/esm/src/api/device-action/xstate-utils/XStateDeviceAction.js +1 -1
  63. package/lib/esm/src/api/device-action/xstate-utils/XStateDeviceAction.js.map +2 -2
  64. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js +1 -1
  65. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.js.map +2 -2
  66. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js +1 -1
  67. package/lib/esm/src/api/device-model/data/StaticDeviceModelDataSource.test.js.map +2 -2
  68. package/lib/esm/src/api/device-model/model/DeviceModel.js +1 -1
  69. package/lib/esm/src/api/device-model/model/DeviceModel.js.map +2 -2
  70. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  71. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +3 -3
  72. package/lib/esm/src/api/transport/model/Errors.js +1 -1
  73. package/lib/esm/src/api/transport/model/Errors.js.map +3 -3
  74. package/lib/esm/src/api/utils/HexaString.js +1 -1
  75. package/lib/esm/src/api/utils/HexaString.js.map +3 -3
  76. package/lib/esm/src/api/utils/HexaString.test.js +1 -1
  77. package/lib/esm/src/api/utils/HexaString.test.js.map +2 -2
  78. package/lib/esm/src/internal/device-session/service/DefaultApduReceiverService.js +1 -1
  79. package/lib/esm/src/internal/device-session/service/DefaultApduReceiverService.js.map +2 -2
  80. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  81. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  82. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.test.js +1 -1
  83. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.test.js.map +2 -2
  84. package/lib/types/src/api/DeviceManagementKit.d.ts +4 -0
  85. package/lib/types/src/api/DeviceManagementKit.d.ts.map +1 -1
  86. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts +38 -0
  87. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts.map +1 -1
  88. package/lib/types/src/api/apdu/utils/ByteArrayParser.d.ts +1 -0
  89. package/lib/types/src/api/apdu/utils/ByteArrayParser.d.ts.map +1 -1
  90. package/lib/types/src/api/command/os/__mocks__/GetOsVersionCommand.d.ts.map +1 -1
  91. package/lib/types/src/api/device/DeviceModel.d.ts +2 -1
  92. package/lib/types/src/api/device/DeviceModel.d.ts.map +1 -1
  93. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts +1 -1
  94. package/lib/types/src/api/device-action/os/GetDeviceStatus/GetDeviceStatusDeviceAction.d.ts.map +1 -1
  95. package/lib/types/src/api/device-action/xstate-utils/XStateDeviceAction.d.ts +1 -0
  96. package/lib/types/src/api/device-action/xstate-utils/XStateDeviceAction.d.ts.map +1 -1
  97. package/lib/types/src/api/device-model/data/StaticDeviceModelDataSource.d.ts.map +1 -1
  98. package/lib/types/src/api/device-model/model/DeviceModel.d.ts.map +1 -1
  99. package/lib/types/src/api/secure-channel/task/ConnectToSecureChannelTask.d.ts.map +1 -1
  100. package/lib/types/src/api/transport/model/Errors.d.ts +5 -0
  101. package/lib/types/src/api/transport/model/Errors.d.ts.map +1 -1
  102. package/lib/types/src/api/utils/HexaString.d.ts +4 -3
  103. package/lib/types/src/api/utils/HexaString.d.ts.map +1 -1
  104. package/lib/types/src/internal/device-session/service/DefaultApduReceiverService.d.ts.map +1 -1
  105. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  106. package/package.json +5 -5
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var D=(o,e)=>{for(var r in e)p(o,r,{get:e[r],enumerable:!0})},G=(o,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of H(e))!C.call(o,n)&&n!==r&&p(o,n,{get:()=>e[n],enumerable:!(t=F(e,n))||t.enumerable});return o};var P=o=>G(p({},"__esModule",{value:!0}),o),_=(o,e,r,t)=>{for(var n=t>1?void 0:t?F(e,r):e,s=o.length-1,m;s>=0;s--)(m=o[s])&&(n=(t?m(e,r,n):m(n))||n);return t&&n&&p(e,r,n),n},f=(o,e)=>(r,t)=>e(r,t,o);var z={};D(z,{DefaultApduReceiverService:()=>g});module.exports=P(z);var d=require("inversify"),a=require("purify-ts"),A=require("uuid"),y=require("../../../api/device-session/ApduResponse"),i=require("../../../api/device-session/data/FramerConst"),h=require("../../../api/device-session/utils/FramerUtils"),l=require("../../device-session/data/ApduResponseConst"),u=require("../../device-session/model/Errors"),E=require("../../device-session/model/Frame"),b=require("../../device-session/model/FrameHeader"),v=require("../../logger-publisher/di/loggerTypes");let g=class{_channel;_logger;_pendingFrames;constructor({channel:e=a.Maybe.zero()},r){this._channel=e,this._logger=r("ApduReceiverService"),this._pendingFrames=[]}handleFrame(e){return this.getFrameFromBytes(e).map(t=>{if(this._logger.debug("handle frame",{data:{frame:t.getRawData()}}),this._pendingFrames.push(t),!this._pendingFrames[0])return a.Nothing;const n=this._pendingFrames[0].getHeader().getDataLength();return this.getCompleteFrame(n)})}getCompleteFrame(e){return e.chain(r=>{if(!this.isComplete(r))return this._logger.debug("frame is not complete, waiting for more"),a.Nothing;const t=h.FramerUtils.getFirstBytesFrom(this.concatFrames(this._pendingFrames),r),n=h.FramerUtils.getFirstBytesFrom(t,t.length-l.APDU_RESPONSE_STATUS_CODE_LENGTH),s=h.FramerUtils.getLastBytesFrom(t,l.APDU_RESPONSE_STATUS_CODE_LENGTH);return this._pendingFrames=[],(0,a.Just)(new y.ApduResponse({data:n,statusCode:s}))})}getFrameFromBytes(e){const r=this._channel.caseOf({Just:()=>i.CHANNEL_LENGTH,Nothing:()=>0}),t=e.slice(r,r+i.HEAD_TAG_LENGTH),n=e.slice(r+i.HEAD_TAG_LENGTH,r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH),s=n.reduce((T,U)=>T+U,0)===0;if(!s&&this._pendingFrames.length===0)return(0,a.Left)(new u.ReceiverApduError);const m=r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH,c=s?i.APDU_DATA_LENGTH_LENGTH:0;if(e.length<r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH+c)return(0,a.Left)(new u.ReceiverApduError("Unable to parse header from apdu"));const L=s?(0,a.Just)(e.slice(m,m+c)):a.Nothing,R=m+c,S=e.slice(R),N=new E.Frame({header:new b.FrameHeader({uuid:(0,A.v4)(),channel:this._channel,dataSize:L,headTag:t,index:n,length:r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH+c}),data:S});return(0,a.Right)(N)}isComplete(e){return this._pendingFrames.reduce((t,n)=>t+n.getData().length,0)>=e}concatFrames(e){return e.reduce((r,t)=>Uint8Array.from([...r,...t.getData()]),new Uint8Array(0))}};g=_([(0,d.injectable)(),f(1,(0,d.inject)(v.loggerTypes.LoggerPublisherServiceFactory))],g);0&&(module.exports={DefaultApduReceiverService});
1
+ "use strict";var p=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var C=Object.prototype.hasOwnProperty;var D=(o,e)=>{for(var r in e)p(o,r,{get:e[r],enumerable:!0})},G=(o,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of H(e))!C.call(o,t)&&t!==r&&p(o,t,{get:()=>e[t],enumerable:!(n=F(e,t))||n.enumerable});return o};var P=o=>G(p({},"__esModule",{value:!0}),o),_=(o,e,r,n)=>{for(var t=n>1?void 0:n?F(e,r):e,s=o.length-1,m;s>=0;s--)(m=o[s])&&(t=(n?m(e,r,t):m(t))||t);return n&&t&&p(e,r,t),t},A=(o,e)=>(r,n)=>e(r,n,o);var z={};D(z,{DefaultApduReceiverService:()=>c});module.exports=P(z);var d=require("inversify"),a=require("purify-ts"),f=require("uuid"),y=require("../../../api/device-session/ApduResponse"),i=require("../../../api/device-session/data/FramerConst"),h=require("../../../api/device-session/utils/FramerUtils"),l=require("../../device-session/data/ApduResponseConst"),u=require("../../device-session/model/Errors"),v=require("../../device-session/model/Frame"),E=require("../../device-session/model/FrameHeader"),L=require("../../logger-publisher/di/loggerTypes");let c=class{_channel;_logger;_pendingFrames;constructor({channel:e=a.Maybe.zero()},r){this._channel=e,this._logger=r("ApduReceiverService"),this._pendingFrames=[]}handleFrame(e){return this.getFrameFromBytes(e).map(n=>{if(this._pendingFrames.push(n),!this._pendingFrames[0])return a.Nothing;const t=this._pendingFrames[0].getHeader().getDataLength();return this.getCompleteFrame(t)})}getCompleteFrame(e){return e.chain(r=>{if(!this.isComplete(r))return this._logger.debug("frame is not complete, waiting for more"),a.Nothing;const n=h.FramerUtils.getFirstBytesFrom(this.concatFrames(this._pendingFrames),r),t=h.FramerUtils.getFirstBytesFrom(n,n.length-l.APDU_RESPONSE_STATUS_CODE_LENGTH),s=h.FramerUtils.getLastBytesFrom(n,l.APDU_RESPONSE_STATUS_CODE_LENGTH);return this._pendingFrames=[],(0,a.Just)(new y.ApduResponse({data:t,statusCode:s}))})}getFrameFromBytes(e){const r=this._channel.caseOf({Just:()=>i.CHANNEL_LENGTH,Nothing:()=>0}),n=e.slice(r,r+i.HEAD_TAG_LENGTH),t=e.slice(r+i.HEAD_TAG_LENGTH,r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH),s=t.reduce((T,U)=>T+U,0)===0;if(!s&&this._pendingFrames.length===0)return(0,a.Left)(new u.ReceiverApduError);const m=r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH,g=s?i.APDU_DATA_LENGTH_LENGTH:0;if(e.length<r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH+g)return(0,a.Left)(new u.ReceiverApduError("Unable to parse header from apdu"));const b=s?(0,a.Just)(e.slice(m,m+g)):a.Nothing,S=m+g,N=e.slice(S),R=new v.Frame({header:new E.FrameHeader({uuid:(0,f.v4)(),channel:this._channel,dataSize:b,headTag:n,index:t,length:r+i.HEAD_TAG_LENGTH+i.INDEX_LENGTH+g}),data:N});return(0,a.Right)(R)}isComplete(e){return this._pendingFrames.reduce((n,t)=>n+t.getData().length,0)>=e}concatFrames(e){return e.reduce((r,n)=>Uint8Array.from([...r,...n.getData()]),new Uint8Array(0))}};c=_([(0,d.injectable)(),A(1,(0,d.inject)(L.loggerTypes.LoggerPublisherServiceFactory))],c);0&&(module.exports={DefaultApduReceiverService});
2
2
  //# sourceMappingURL=DefaultApduReceiverService.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/service/DefaultApduReceiverService.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Either, Just, Left, Maybe, Nothing, Right } from \"purify-ts\";\nimport { v4 } from \"uuid\";\n\nimport { ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n APDU_DATA_LENGTH_LENGTH,\n CHANNEL_LENGTH,\n HEAD_TAG_LENGTH,\n INDEX_LENGTH,\n} from \"@api/device-session/data/FramerConst\";\nimport {\n type ApduReceiverConstructorArgs,\n ApduReceiverService,\n} from \"@api/device-session/service/ApduReceiverService\";\nimport { FramerUtils } from \"@api/device-session/utils/FramerUtils\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { APDU_RESPONSE_STATUS_CODE_LENGTH } from \"@internal/device-session/data/ApduResponseConst\";\nimport { ReceiverApduError } from \"@internal/device-session/model/Errors\";\nimport { Frame } from \"@internal/device-session/model/Frame\";\nimport { FrameHeader } from \"@internal/device-session/model/FrameHeader\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\n@injectable()\nexport class DefaultApduReceiverService implements ApduReceiverService {\n private readonly _channel: Maybe<Uint8Array>;\n private readonly _logger: LoggerPublisherService;\n private _pendingFrames: Frame[];\n\n constructor(\n { channel = Maybe.zero() }: ApduReceiverConstructorArgs,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._channel = channel;\n this._logger = loggerModuleFactory(\"ApduReceiverService\");\n this._pendingFrames = [];\n }\n\n /*\n * Return\n * - A complete ApduResponse\n * - Or a Nothing if not all the data has been received\n * - Or a ReceiverApduError if the apdu is not formatted correctly\n *\n * @param Uint8Array\n */\n public handleFrame(\n frameBytes: Uint8Array,\n ): Either<ReceiverApduError, Maybe<ApduResponse>> {\n const frame = this.getFrameFromBytes(frameBytes);\n\n return frame.map((value) => {\n this._logger.debug(\"handle frame\", {\n data: { frame: value.getRawData() },\n });\n this._pendingFrames.push(value);\n if (!this._pendingFrames[0]) {\n return Nothing;\n }\n const dataSize = this._pendingFrames[0].getHeader().getDataLength();\n return this.getCompleteFrame(dataSize);\n });\n }\n\n /*\n * Return\n * - A complete ApduResponse\n * - Or a Nothing if not all the data has been received\n *\n * @param Maybe<number>\n */\n private getCompleteFrame(dataSize: Maybe<number>): Maybe<ApduResponse> {\n return dataSize.chain((value) => {\n if (!this.isComplete(value)) {\n this._logger.debug(\"frame is not complete, waiting for more\");\n return Nothing;\n }\n\n const concatenatedFramesData = FramerUtils.getFirstBytesFrom(\n this.concatFrames(this._pendingFrames),\n value,\n );\n const data = FramerUtils.getFirstBytesFrom(\n concatenatedFramesData,\n concatenatedFramesData.length - APDU_RESPONSE_STATUS_CODE_LENGTH,\n );\n const statusCode = FramerUtils.getLastBytesFrom(\n concatenatedFramesData,\n APDU_RESPONSE_STATUS_CODE_LENGTH,\n );\n\n this._pendingFrames = [];\n\n return Just(\n new ApduResponse({\n data: data,\n statusCode,\n }),\n );\n });\n }\n\n /*\n * Parse an Uint8Array to a Frame\n * Return an error if the frame is not formatted correctly\n *\n * @param Uint8Array\n */\n private getFrameFromBytes(\n rawFrame: Uint8Array,\n ): Either<ReceiverApduError, Frame> {\n const channelSize = this._channel.caseOf({\n Just: () => CHANNEL_LENGTH,\n Nothing: () => 0,\n });\n\n const headTag = rawFrame.slice(channelSize, channelSize + HEAD_TAG_LENGTH);\n const index = rawFrame.slice(\n channelSize + HEAD_TAG_LENGTH,\n channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH,\n );\n\n const isFirstIndex = index.reduce((curr, val) => curr + val, 0) === 0;\n\n if (!isFirstIndex && this._pendingFrames.length === 0) {\n return Left(new ReceiverApduError());\n }\n\n const dataSizeIndex = channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH;\n const dataSizeLength = isFirstIndex ? APDU_DATA_LENGTH_LENGTH : 0;\n\n if (\n rawFrame.length <\n channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH + dataSizeLength\n ) {\n return Left(new ReceiverApduError(\"Unable to parse header from apdu\"));\n }\n\n const dataSize = isFirstIndex\n ? Just(rawFrame.slice(dataSizeIndex, dataSizeIndex + dataSizeLength))\n : Nothing;\n\n const dataIndex = dataSizeIndex + dataSizeLength;\n const data = rawFrame.slice(dataIndex);\n\n const frame = new Frame({\n header: new FrameHeader({\n uuid: v4(),\n channel: this._channel,\n dataSize,\n headTag,\n index,\n length: channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH + dataSizeLength,\n }),\n data,\n });\n\n return Right(frame);\n }\n\n /*\n * Return true if all the datas has been received\n *\n * @param number\n */\n private isComplete(dataSize: number): boolean {\n const totalReceiveLength = this._pendingFrames.reduce(\n (prev, curr) => prev + curr.getData().length,\n 0,\n );\n\n return totalReceiveLength >= dataSize;\n }\n\n private concatFrames(frames: Frame[]): Uint8Array {\n return frames.reduce(\n (prev: Uint8Array, curr: Frame) =>\n Uint8Array.from([...prev, ...curr.getData()]),\n new Uint8Array(0),\n );\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA0D,qBAC1DC,EAAmB,gBAEnBC,EAA6B,4CAC7BC,EAKO,gDAKPC,EAA4B,iDAE5BC,EAAiD,2DACjDC,EAAkC,iDAClCC,EAAsB,gDACtBC,EAA4B,sDAC5BC,EAA4B,qDAGrB,IAAMC,EAAN,KAAgE,CACpD,SACA,QACT,eAER,YACE,CAAE,QAAAC,EAAU,QAAM,KAAK,CAAE,EAEzBC,EACA,CACA,KAAK,SAAWD,EAChB,KAAK,QAAUC,EAAoB,qBAAqB,EACxD,KAAK,eAAiB,CAAC,CACzB,CAUO,YACLC,EACgD,CAGhD,OAFc,KAAK,kBAAkBA,CAAU,EAElC,IAAKC,GAAU,CAK1B,GAJA,KAAK,QAAQ,MAAM,eAAgB,CACjC,KAAM,CAAE,MAAOA,EAAM,WAAW,CAAE,CACpC,CAAC,EACD,KAAK,eAAe,KAAKA,CAAK,EAC1B,CAAC,KAAK,eAAe,CAAC,EACxB,OAAO,UAET,MAAMC,EAAW,KAAK,eAAe,CAAC,EAAE,UAAU,EAAE,cAAc,EAClE,OAAO,KAAK,iBAAiBA,CAAQ,CACvC,CAAC,CACH,CASQ,iBAAiBA,EAA8C,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,CAAC,EAED,SAAO,SAAMY,CAAK,CACpB,CAOQ,WAAWd,EAA2B,CAM5C,OAL2B,KAAK,eAAe,OAC7C,CAACe,EAAMN,IAASM,EAAON,EAAK,QAAQ,EAAE,OACtC,CACF,GAE6BT,CAC/B,CAEQ,aAAagB,EAA6B,CAChD,OAAOA,EAAO,OACZ,CAACD,EAAkBN,IACjB,WAAW,KAAK,CAAC,GAAGM,EAAM,GAAGN,EAAK,QAAQ,CAAC,CAAC,EAC9C,IAAI,WAAW,CAAC,CAClB,CACF,CACF,EA9Jad,EAANsB,EAAA,IADN,cAAW,EAQPC,EAAA,eAAO,cAAY,6BAA6B,IAPxCvB",
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Either, Just, Left, Maybe, Nothing, Right } from \"purify-ts\";\nimport { v4 } from \"uuid\";\n\nimport { ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n APDU_DATA_LENGTH_LENGTH,\n CHANNEL_LENGTH,\n HEAD_TAG_LENGTH,\n INDEX_LENGTH,\n} from \"@api/device-session/data/FramerConst\";\nimport {\n type ApduReceiverConstructorArgs,\n ApduReceiverService,\n} from \"@api/device-session/service/ApduReceiverService\";\nimport { FramerUtils } from \"@api/device-session/utils/FramerUtils\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport { APDU_RESPONSE_STATUS_CODE_LENGTH } from \"@internal/device-session/data/ApduResponseConst\";\nimport { ReceiverApduError } from \"@internal/device-session/model/Errors\";\nimport { Frame } from \"@internal/device-session/model/Frame\";\nimport { FrameHeader } from \"@internal/device-session/model/FrameHeader\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\n\n@injectable()\nexport class DefaultApduReceiverService implements ApduReceiverService {\n private readonly _channel: Maybe<Uint8Array>;\n private readonly _logger: LoggerPublisherService;\n private _pendingFrames: Frame[];\n\n constructor(\n { channel = Maybe.zero() }: ApduReceiverConstructorArgs,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerModuleFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._channel = channel;\n this._logger = loggerModuleFactory(\"ApduReceiverService\");\n this._pendingFrames = [];\n }\n\n /*\n * Return\n * - A complete ApduResponse\n * - Or a Nothing if not all the data has been received\n * - Or a ReceiverApduError if the apdu is not formatted correctly\n *\n * @param Uint8Array\n */\n public handleFrame(\n frameBytes: Uint8Array,\n ): Either<ReceiverApduError, Maybe<ApduResponse>> {\n const frame = this.getFrameFromBytes(frameBytes);\n\n return frame.map((value) => {\n this._pendingFrames.push(value);\n if (!this._pendingFrames[0]) {\n return Nothing;\n }\n const dataSize = this._pendingFrames[0].getHeader().getDataLength();\n return this.getCompleteFrame(dataSize);\n });\n }\n\n /*\n * Return\n * - A complete ApduResponse\n * - Or a Nothing if not all the data has been received\n *\n * @param Maybe<number>\n */\n private getCompleteFrame(dataSize: Maybe<number>): Maybe<ApduResponse> {\n return dataSize.chain((value) => {\n if (!this.isComplete(value)) {\n this._logger.debug(\"frame is not complete, waiting for more\");\n return Nothing;\n }\n\n const concatenatedFramesData = FramerUtils.getFirstBytesFrom(\n this.concatFrames(this._pendingFrames),\n value,\n );\n const data = FramerUtils.getFirstBytesFrom(\n concatenatedFramesData,\n concatenatedFramesData.length - APDU_RESPONSE_STATUS_CODE_LENGTH,\n );\n const statusCode = FramerUtils.getLastBytesFrom(\n concatenatedFramesData,\n APDU_RESPONSE_STATUS_CODE_LENGTH,\n );\n\n this._pendingFrames = [];\n\n return Just(\n new ApduResponse({\n data: data,\n statusCode,\n }),\n );\n });\n }\n\n /*\n * Parse an Uint8Array to a Frame\n * Return an error if the frame is not formatted correctly\n *\n * @param Uint8Array\n */\n private getFrameFromBytes(\n rawFrame: Uint8Array,\n ): Either<ReceiverApduError, Frame> {\n const channelSize = this._channel.caseOf({\n Just: () => CHANNEL_LENGTH,\n Nothing: () => 0,\n });\n\n const headTag = rawFrame.slice(channelSize, channelSize + HEAD_TAG_LENGTH);\n const index = rawFrame.slice(\n channelSize + HEAD_TAG_LENGTH,\n channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH,\n );\n\n const isFirstIndex = index.reduce((curr, val) => curr + val, 0) === 0;\n\n if (!isFirstIndex && this._pendingFrames.length === 0) {\n return Left(new ReceiverApduError());\n }\n\n const dataSizeIndex = channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH;\n const dataSizeLength = isFirstIndex ? APDU_DATA_LENGTH_LENGTH : 0;\n\n if (\n rawFrame.length <\n channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH + dataSizeLength\n ) {\n return Left(new ReceiverApduError(\"Unable to parse header from apdu\"));\n }\n\n const dataSize = isFirstIndex\n ? Just(rawFrame.slice(dataSizeIndex, dataSizeIndex + dataSizeLength))\n : Nothing;\n\n const dataIndex = dataSizeIndex + dataSizeLength;\n const data = rawFrame.slice(dataIndex);\n\n const frame = new Frame({\n header: new FrameHeader({\n uuid: v4(),\n channel: this._channel,\n dataSize,\n headTag,\n index,\n length: channelSize + HEAD_TAG_LENGTH + INDEX_LENGTH + dataSizeLength,\n }),\n data,\n });\n\n return Right(frame);\n }\n\n /*\n * Return true if all the datas has been received\n *\n * @param number\n */\n private isComplete(dataSize: number): boolean {\n const totalReceiveLength = this._pendingFrames.reduce(\n (prev, curr) => prev + curr.getData().length,\n 0,\n );\n\n return totalReceiveLength >= dataSize;\n }\n\n private concatFrames(frames: Frame[]): Uint8Array {\n return frames.reduce(\n (prev: Uint8Array, curr: Frame) =>\n Uint8Array.from([...prev, ...curr.getData()]),\n new Uint8Array(0),\n );\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA0D,qBAC1DC,EAAmB,gBAEnBC,EAA6B,4CAC7BC,EAKO,gDAKPC,EAA4B,iDAE5BC,EAAiD,2DACjDC,EAAkC,iDAClCC,EAAsB,gDACtBC,EAA4B,sDAC5BC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MAAMG,EAAgBN,EAAc,kBAAkB,eAChDO,EAAiBJ,EAAe,0BAA0B,EAEhE,GACEJ,EAAS,OACTC,EAAc,kBAAkB,eAAeO,EAE/C,SAAO,QAAK,IAAI,oBAAkB,kCAAkC,CAAC,EAGvE,MAAMZ,EAAWQ,KACb,QAAKJ,EAAS,MAAMO,EAAeA,EAAgBC,CAAc,CAAC,EAClE,UAEEC,EAAYF,EAAgBC,EAC5BV,EAAOE,EAAS,MAAMS,CAAS,EAE/BC,EAAQ,IAAI,QAAM,CACtB,OAAQ,IAAI,cAAY,CACtB,QAAM,MAAG,EACT,QAAS,KAAK,SACd,SAAAd,EACA,QAAAM,EACA,MAAAC,EACA,OAAQF,EAAc,kBAAkB,eAAeO,CACzD,CAAC,EACD,KAAAV,CACF,CAAC,EAED,SAAO,SAAMY,CAAK,CACpB,CAOQ,WAAWd,EAA2B,CAM5C,OAL2B,KAAK,eAAe,OAC7C,CAACe,EAAMN,IAASM,EAAON,EAAK,QAAQ,EAAE,OACtC,CACF,GAE6BT,CAC/B,CAEQ,aAAagB,EAA6B,CAChD,OAAOA,EAAO,OACZ,CAACD,EAAkBN,IACjB,WAAW,KAAK,CAAC,GAAGM,EAAM,GAAGN,EAAK,QAAQ,CAAC,CAAC,EAC9C,IAAI,WAAW,CAAC,CAClB,CACF,CACF,EA3Jad,EAANsB,EAAA,IADN,cAAW,EAQPC,EAAA,eAAO,cAAY,6BAA6B,IAPxCvB",
6
6
  "names": ["DefaultApduReceiverService_exports", "__export", "DefaultApduReceiverService", "__toCommonJS", "import_inversify", "import_purify_ts", "import_uuid", "import_ApduResponse", "import_FramerConst", "import_FramerUtils", "import_ApduResponseConst", "import_Errors", "import_Frame", "import_FrameHeader", "import_loggerTypes", "DefaultApduReceiverService", "channel", "loggerModuleFactory", "frameBytes", "value", "dataSize", "concatenatedFramesData", "data", "statusCode", "rawFrame", "channelSize", "headTag", "index", "isFirstIndex", "curr", "val", "dataSizeIndex", "dataSizeLength", "dataIndex", "frame", "prev", "frames", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var y=(a,e)=>{for(var t in e)c(a,t,{get:e[t],enumerable:!0})},E=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!v.call(a,i)&&i!==t&&c(a,i,{get:()=>e[i],enumerable:!(r=u(e,i))||r.enumerable});return a};var L=a=>E(c({},"__esModule",{value:!0}),a),f=(a,e,t,r)=>{for(var i=r>1?void 0:r?u(e,t):e,m=a.length-1,s;m>=0;m--)(s=a[m])&&(i=(r?s(e,t,i):s(i))||i);return r&&i&&c(e,t,i),i},F=(a,e)=>(t,r)=>e(t,r,a);var T={};y(T,{DefaultApduSenderService:()=>g});module.exports=L(T);var l=require("inversify"),o=require("purify-ts"),S=require("uuid"),n=require("../../../api/device-session/data/FramerConst"),d=require("../../../api/device-session/utils/FramerUtils"),h=require("../../device-session/model/Errors"),A=require("../../device-session/model/Frame"),_=require("../../device-session/model/FrameHeader"),b=require("../../logger-publisher/di/loggerTypes");let g=class{_frameSize;_channel;_padding;_logger;constructor({frameSize:e,channel:t=o.Maybe.zero(),padding:r=!1},i){this._frameSize=e,this._channel=t,this._padding=r,this._logger=i("DefaultApduSenderService")}getFrames(e){const t=[];let r=0,i=this.getFrameAtIndex(e,r);for(;i.isRight();)t.push(i.extract()),r+=1,i=this.getFrameAtIndex(e,r).mapLeft(m=>(m instanceof h.FramerOverflowError?this._logger.debug("Frames parsed",{data:{count:r}}):this._logger.error("Error while parsing frame",{data:{error:m}}),m));return t}getFrameAtIndex(e,t){const r=this.getFrameHeaderFrom(t,e.length),i=t*this._frameSize-this.getHeaderSizeSumFrom(t);if(i>e.length)return(0,o.Left)(new h.FramerOverflowError);if(r.getLength()>this._frameSize)return(0,o.Left)(new h.FramerApduError);const m=this._frameSize-r.getLength(),s=e.slice(t===0?0:i,t===0?m:i+this._frameSize-r.getLength()),p=this._padding?new Uint8Array(m).fill(0):new Uint8Array(s.length<m?s.length:m);p.set(s,0);const H=new A.Frame({header:r,data:p});return(0,o.Right)(H)}getFrameHeaderFrom(e,t){const r=new _.FrameHeader({uuid:(0,S.v4)(),channel:this._channel.map(i=>d.FramerUtils.getLastBytesFrom(i,n.CHANNEL_LENGTH)),headTag:new Uint8Array([n.HEAD_TAG]),index:d.FramerUtils.numberToByteArray(e,n.INDEX_LENGTH),length:this.getFrameHeaderSizeFromIndex(e),dataSize:o.Maybe.zero()});return e===0&&r.setDataSize(o.Maybe.of(d.FramerUtils.numberToByteArray(t,n.APDU_DATA_LENGTH_LENGTH))),r}getHeaderSizeSumFrom(e){let t=this.getFrameHeaderSizeFromIndex(0),r=1;for(;r<e;)t+=this.getFrameHeaderSizeFromIndex(r),r+=1;return t}getFrameHeaderSizeFromIndex(e){return this._channel.caseOf({Just:()=>n.CHANNEL_LENGTH,Nothing:()=>0})+n.INDEX_LENGTH+n.HEAD_TAG_LENGTH+(e===0?n.APDU_DATA_LENGTH_LENGTH:0)}};g=f([(0,l.injectable)(),F(1,(0,l.inject)(b.loggerTypes.LoggerPublisherServiceFactory))],g);0&&(module.exports={DefaultApduSenderService});
1
+ "use strict";var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var y=(a,e)=>{for(var t in e)c(a,t,{get:e[t],enumerable:!0})},E=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of z(e))!v.call(a,i)&&i!==t&&c(a,i,{get:()=>e[i],enumerable:!(r=u(e,i))||r.enumerable});return a};var L=a=>E(c({},"__esModule",{value:!0}),a),f=(a,e,t,r)=>{for(var i=r>1?void 0:r?u(e,t):e,m=a.length-1,s;m>=0;m--)(s=a[m])&&(i=(r?s(e,t,i):s(i))||i);return r&&i&&c(e,t,i),i},F=(a,e)=>(t,r)=>e(t,r,a);var T={};y(T,{DefaultApduSenderService:()=>g});module.exports=L(T);var l=require("inversify"),o=require("purify-ts"),S=require("uuid"),n=require("../../../api/device-session/data/FramerConst"),d=require("../../../api/device-session/utils/FramerUtils"),h=require("../../device-session/model/Errors"),A=require("../../device-session/model/Frame"),_=require("../../device-session/model/FrameHeader"),b=require("../../logger-publisher/di/loggerTypes");let g=class{_frameSize;_channel;_padding;_logger;constructor({frameSize:e,channel:t=o.Maybe.zero(),padding:r=!1},i){this._frameSize=e,this._channel=t,this._padding=r,this._logger=i("DefaultApduSenderService")}getFrames(e){const t=[];let r=0,i=this.getFrameAtIndex(e,r);for(;i.isRight();)t.push(i.extract()),r+=1,i=this.getFrameAtIndex(e,r).mapLeft(m=>(m instanceof h.FramerOverflowError||this._logger.error("Error while parsing frame",{data:{error:m}}),m));return t}getFrameAtIndex(e,t){const r=this.getFrameHeaderFrom(t,e.length),i=t===0?0:t*this._frameSize-this.getHeaderSizeSumFrom(t);if(i>=e.length)return(0,o.Left)(new h.FramerOverflowError);if(r.getLength()>this._frameSize)return(0,o.Left)(new h.FramerApduError);const m=this._frameSize-r.getLength(),s=e.slice(i,i+this._frameSize-r.getLength()),p=this._padding?new Uint8Array(m).fill(0):new Uint8Array(s.length<m?s.length:m);p.set(s,0);const H=new A.Frame({header:r,data:p});return(0,o.Right)(H)}getFrameHeaderFrom(e,t){const r=new _.FrameHeader({uuid:(0,S.v4)(),channel:this._channel.map(i=>d.FramerUtils.getLastBytesFrom(i,n.CHANNEL_LENGTH)),headTag:new Uint8Array([n.HEAD_TAG]),index:d.FramerUtils.numberToByteArray(e,n.INDEX_LENGTH),length:this.getFrameHeaderSizeFromIndex(e),dataSize:o.Maybe.zero()});return e===0&&r.setDataSize(o.Maybe.of(d.FramerUtils.numberToByteArray(t,n.APDU_DATA_LENGTH_LENGTH))),r}getHeaderSizeSumFrom(e){let t=this.getFrameHeaderSizeFromIndex(0),r=1;for(;r<e;)t+=this.getFrameHeaderSizeFromIndex(r),r+=1;return t}getFrameHeaderSizeFromIndex(e){return this._channel.caseOf({Just:()=>n.CHANNEL_LENGTH,Nothing:()=>0})+n.INDEX_LENGTH+n.HEAD_TAG_LENGTH+(e===0?n.APDU_DATA_LENGTH_LENGTH:0)}};g=f([(0,l.injectable)(),F(1,(0,l.inject)(b.loggerTypes.LoggerPublisherServiceFactory))],g);0&&(module.exports={DefaultApduSenderService});
2
2
  //# sourceMappingURL=DefaultApduSenderService.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/service/DefaultApduSenderService.ts"],
4
- "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Either, Left, Maybe, Right } from \"purify-ts\";\nimport { v4 } from \"uuid\";\n\nimport {\n APDU_DATA_LENGTH_LENGTH,\n CHANNEL_LENGTH,\n HEAD_TAG,\n HEAD_TAG_LENGTH,\n INDEX_LENGTH,\n} from \"@api/device-session/data/FramerConst\";\nimport type {\n ApduSenderService,\n ApduSenderServiceConstructorArgs,\n} from \"@api/device-session/service/ApduSenderService\";\nimport { FramerUtils } from \"@api/device-session/utils/FramerUtils\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport {\n FramerApduError,\n FramerOverflowError,\n} from \"@internal/device-session/model/Errors\";\nimport { Frame } from \"@internal/device-session/model/Frame\";\nimport { FrameHeader } from \"@internal/device-session/model/FrameHeader\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { DmkError } from \"@root/src/api/Error\";\n/**\n * Default implementation of ApduSenderService\n *\n * Split APDU in an array of frames readies to send to a TransportConnectedDevice\n */\n@injectable()\nexport class DefaultApduSenderService implements ApduSenderService {\n protected _frameSize: number;\n protected _channel: Maybe<Uint8Array>;\n protected _padding: boolean;\n private _logger: LoggerPublisherService;\n\n /**\n * Constructor\n *\n * @param frameSize\n * @param channel\n * @param padding\n * @param loggerServiceFactory\n */\n constructor(\n {\n frameSize,\n channel = Maybe.zero(),\n padding = false,\n }: ApduSenderServiceConstructorArgs,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._frameSize = frameSize;\n this._channel = channel;\n this._padding = padding;\n this._logger = loggerServiceFactory(\"DefaultApduSenderService\");\n }\n\n /**\n * Get frames from apdu\n *\n * @param apdu\n */\n public getFrames(apdu: Uint8Array): Frame[] {\n const frames: Frame[] = [];\n let count = 0;\n let frame = this.getFrameAtIndex(apdu, count);\n\n while (frame.isRight()) {\n frames.push(frame.extract());\n count += 1;\n frame = this.getFrameAtIndex(apdu, count).mapLeft((error) => {\n if (error instanceof FramerOverflowError) {\n this._logger.debug(\"Frames parsed\", { data: { count } });\n } else {\n this._logger.error(\"Error while parsing frame\", { data: { error } });\n }\n return error;\n });\n }\n return frames;\n }\n\n /**\n * Get apdu frame at index\n * Split every {{PACKET_SIZE - HEADER_SIZE}} bytes of apdu\n * @param apdu\n * @param frameIndex\n * @private\n */\n private getFrameAtIndex(\n apdu: Uint8Array,\n frameIndex: number,\n ): Either<DmkError, Frame> {\n const header = this.getFrameHeaderFrom(frameIndex, apdu.length);\n const frameOffset =\n frameIndex * this._frameSize - this.getHeaderSizeSumFrom(frameIndex);\n\n if (frameOffset > apdu.length) {\n return Left(new FramerOverflowError());\n }\n if (header.getLength() > this._frameSize) {\n return Left(new FramerApduError());\n }\n const dataMaxSize = this._frameSize - header.getLength();\n const data = apdu.slice(\n frameIndex === 0 ? 0 : frameOffset,\n frameIndex === 0\n ? dataMaxSize\n : frameOffset + this._frameSize - header.getLength(),\n );\n const frameData = this._padding\n ? new Uint8Array(dataMaxSize).fill(0)\n : new Uint8Array(data.length < dataMaxSize ? data.length : dataMaxSize);\n frameData.set(data, 0);\n const frame = new Frame({\n header,\n data: frameData,\n });\n return Right(frame);\n }\n\n /**\n * Get frame header\n * @param frameIndex\n * @param apduSize\n * @private\n */\n private getFrameHeaderFrom(\n frameIndex: number,\n apduSize: number,\n ): FrameHeader {\n const header = new FrameHeader({\n uuid: v4(),\n channel: this._channel.map((channel) =>\n FramerUtils.getLastBytesFrom(channel, CHANNEL_LENGTH),\n ),\n headTag: new Uint8Array([HEAD_TAG]),\n index: FramerUtils.numberToByteArray(frameIndex, INDEX_LENGTH),\n length: this.getFrameHeaderSizeFromIndex(frameIndex),\n dataSize: Maybe.zero(),\n });\n if (frameIndex === 0) {\n header.setDataSize(\n Maybe.of(\n FramerUtils.numberToByteArray(apduSize, APDU_DATA_LENGTH_LENGTH),\n ),\n );\n }\n return header;\n }\n\n /**\n * Get frame offset\n * First frame has more bytes of header\n * Padding append means a 0 bytes is added at the end of each frame\n * @private\n * @param frameIndex\n */\n private getHeaderSizeSumFrom(frameIndex: number): number {\n let sum = this.getFrameHeaderSizeFromIndex(0);\n let i = 1;\n while (i < frameIndex) {\n sum += this.getFrameHeaderSizeFromIndex(i);\n i += 1;\n }\n return sum;\n }\n\n /**\n * Get frame header size\n * @private\n * @param frameIndex\n */\n private getFrameHeaderSizeFromIndex(frameIndex: number): number {\n return (\n this._channel.caseOf({\n Just: () => CHANNEL_LENGTH,\n Nothing: () => 0,\n }) +\n INDEX_LENGTH +\n HEAD_TAG_LENGTH +\n (frameIndex === 0 ? APDU_DATA_LENGTH_LENGTH : 0)\n );\n }\n}\n"],
5
- "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA2C,qBAC3CC,EAAmB,gBAEnBC,EAMO,gDAKPC,EAA4B,iDAE5BC,EAGO,iDACPC,EAAsB,gDACtBC,EAA4B,sDAC5BC,EAA4B,qDAQrB,IAAMC,EAAN,KAA4D,CACvD,WACA,SACA,SACF,QAUR,YACE,CACE,UAAAC,EACA,QAAAC,EAAU,QAAM,KAAK,EACrB,QAAAC,EAAU,EACZ,EAEAC,EACA,CACA,KAAK,WAAaH,EAClB,KAAK,SAAWC,EAChB,KAA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AG,EACT,QAAS,KAAK,SAAS,IAAKT,GAC1B,cAAY,iBAAiBA,EAAS,gBAAc,CACtD,EACA,QAAS,IAAI,WAAW,CAAC,UAAQ,CAAC,EAClC,MAAO,cAAY,kBAAkBQ,EAAY,cAAY,EAC7D,OAAQ,KAAK,4BAA4BA,CAAU,EACnD,SAAU,QAAM,KAAK,CACvB,CAAC,EACD,OAAIA,IAAe,GACjBC,EAAO,YACL,QAAM,GACJ,cAAY,kBAAkBK,EAAU,yBAAuB,CACjE,CACF,EAEKL,CACT,CASQ,qBAAqBD,EAA4B,CACvD,IAAIO,EAAM,KAAK,4BAA4B,CAAC,EACxCC,EAAI,EACR,KAAOA,EAAIR,GACTO,GAAO,KAAK,4BAA4BC,CAAC,EACzCA,GAAK,EAEP,OAAOD,CACT,CAOQ,4BAA4BP,EAA4B,CAC9D,OACE,KAAK,SAAS,OAAO,CACnB,KAAM,IAAM,iBACZ,QAAS,IAAM,CACjB,CAAC,EACD,eACA,mBACCA,IAAe,EAAI,0BAA0B,EAElD,CACF,EA5JaV,EAANmB,EAAA,IADN,cAAW,EAqBPC,EAAA,eAAO,cAAY,6BAA6B,IApBxCpB",
4
+ "sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { Either, Left, Maybe, Right } from \"purify-ts\";\nimport { v4 } from \"uuid\";\n\nimport {\n APDU_DATA_LENGTH_LENGTH,\n CHANNEL_LENGTH,\n HEAD_TAG,\n HEAD_TAG_LENGTH,\n INDEX_LENGTH,\n} from \"@api/device-session/data/FramerConst\";\nimport type {\n ApduSenderService,\n ApduSenderServiceConstructorArgs,\n} from \"@api/device-session/service/ApduSenderService\";\nimport { FramerUtils } from \"@api/device-session/utils/FramerUtils\";\nimport { LoggerPublisherService } from \"@api/logger-publisher/service/LoggerPublisherService\";\nimport {\n FramerApduError,\n FramerOverflowError,\n} from \"@internal/device-session/model/Errors\";\nimport { Frame } from \"@internal/device-session/model/Frame\";\nimport { FrameHeader } from \"@internal/device-session/model/FrameHeader\";\nimport { loggerTypes } from \"@internal/logger-publisher/di/loggerTypes\";\nimport { DmkError } from \"@root/src/api/Error\";\n/**\n * Default implementation of ApduSenderService\n *\n * Split APDU in an array of frames readies to send to a TransportConnectedDevice\n */\n@injectable()\nexport class DefaultApduSenderService implements ApduSenderService {\n protected _frameSize: number;\n protected _channel: Maybe<Uint8Array>;\n protected _padding: boolean;\n private _logger: LoggerPublisherService;\n\n /**\n * Constructor\n *\n * @param frameSize\n * @param channel\n * @param padding\n * @param loggerServiceFactory\n */\n constructor(\n {\n frameSize,\n channel = Maybe.zero(),\n padding = false,\n }: ApduSenderServiceConstructorArgs,\n @inject(loggerTypes.LoggerPublisherServiceFactory)\n loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._frameSize = frameSize;\n this._channel = channel;\n this._padding = padding;\n this._logger = loggerServiceFactory(\"DefaultApduSenderService\");\n }\n\n /**\n * Get frames from apdu\n *\n * @param apdu\n */\n public getFrames(apdu: Uint8Array): Frame[] {\n const frames: Frame[] = [];\n let count = 0;\n let frame = this.getFrameAtIndex(apdu, count);\n\n while (frame.isRight()) {\n frames.push(frame.extract());\n count += 1;\n frame = this.getFrameAtIndex(apdu, count).mapLeft((error) => {\n if (error instanceof FramerOverflowError) {\n // do nothing\n } else {\n this._logger.error(\"Error while parsing frame\", { data: { error } });\n }\n return error;\n });\n }\n return frames;\n }\n\n /**\n * Get apdu frame at index\n * Split every {{PACKET_SIZE - HEADER_SIZE}} bytes of apdu\n * @param apdu\n * @param frameIndex\n * @private\n */\n private getFrameAtIndex(\n apdu: Uint8Array,\n frameIndex: number,\n ): Either<DmkError, Frame> {\n const header = this.getFrameHeaderFrom(frameIndex, apdu.length);\n const frameOffset =\n frameIndex === 0\n ? 0\n : frameIndex * this._frameSize - this.getHeaderSizeSumFrom(frameIndex);\n\n if (frameOffset >= apdu.length) {\n return Left(new FramerOverflowError());\n }\n if (header.getLength() > this._frameSize) {\n return Left(new FramerApduError());\n }\n const dataMaxSize = this._frameSize - header.getLength();\n const data = apdu.slice(\n frameOffset,\n frameOffset + this._frameSize - header.getLength(),\n );\n const frameData = this._padding\n ? new Uint8Array(dataMaxSize).fill(0)\n : new Uint8Array(data.length < dataMaxSize ? data.length : dataMaxSize);\n frameData.set(data, 0);\n const frame = new Frame({\n header,\n data: frameData,\n });\n return Right(frame);\n }\n\n /**\n * Get frame header\n * @param frameIndex\n * @param apduSize\n * @private\n */\n private getFrameHeaderFrom(\n frameIndex: number,\n apduSize: number,\n ): FrameHeader {\n const header = new FrameHeader({\n uuid: v4(),\n channel: this._channel.map((channel) =>\n FramerUtils.getLastBytesFrom(channel, CHANNEL_LENGTH),\n ),\n headTag: new Uint8Array([HEAD_TAG]),\n index: FramerUtils.numberToByteArray(frameIndex, INDEX_LENGTH),\n length: this.getFrameHeaderSizeFromIndex(frameIndex),\n dataSize: Maybe.zero(),\n });\n if (frameIndex === 0) {\n header.setDataSize(\n Maybe.of(\n FramerUtils.numberToByteArray(apduSize, APDU_DATA_LENGTH_LENGTH),\n ),\n );\n }\n return header;\n }\n\n /**\n * Get frame offset\n * First frame has more bytes of header\n * Padding append means a 0 bytes is added at the end of each frame\n * @private\n * @param frameIndex\n */\n private getHeaderSizeSumFrom(frameIndex: number): number {\n let sum = this.getFrameHeaderSizeFromIndex(0);\n let i = 1;\n while (i < frameIndex) {\n sum += this.getFrameHeaderSizeFromIndex(i);\n i += 1;\n }\n return sum;\n }\n\n /**\n * Get frame header size\n * @private\n * @param frameIndex\n */\n private getFrameHeaderSizeFromIndex(frameIndex: number): number {\n return (\n this._channel.caseOf({\n Just: () => CHANNEL_LENGTH,\n Nothing: () => 0,\n }) +\n INDEX_LENGTH +\n HEAD_TAG_LENGTH +\n (frameIndex === 0 ? APDU_DATA_LENGTH_LENGTH : 0)\n );\n }\n}\n"],
5
+ "mappings": "okBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,8BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,qBACnCC,EAA2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W,EACxEE,EAAU,IAAID,EAAM,CAAC,EACrB,MAAMN,EAAQ,IAAI,QAAM,CACtB,OAAAG,EACA,KAAMI,CACR,CAAC,EACD,SAAO,SAAMP,CAAK,CACpB,CAQQ,mBACNE,EACAM,EACa,CACb,MAAML,EAAS,IAAI,cAAY,CAC7B,QAAM,MAAG,EACT,QAAS,KAAK,SAAS,IAAKT,GAC1B,cAAY,iBAAiBA,EAAS,gBAAc,CACtD,EACA,QAAS,IAAI,WAAW,CAAC,UAAQ,CAAC,EAClC,MAAO,cAAY,kBAAkBQ,EAAY,cAAY,EAC7D,OAAQ,KAAK,4BAA4BA,CAAU,EACnD,SAAU,QAAM,KAAK,CACvB,CAAC,EACD,OAAIA,IAAe,GACjBC,EAAO,YACL,QAAM,GACJ,cAAY,kBAAkBK,EAAU,yBAAuB,CACjE,CACF,EAEKL,CACT,CASQ,qBAAqBD,EAA4B,CACvD,IAAIO,EAAM,KAAK,4BAA4B,CAAC,EACxCC,EAAI,EACR,KAAOA,EAAIR,GACTO,GAAO,KAAK,4BAA4BC,CAAC,EACzCA,GAAK,EAEP,OAAOD,CACT,CAOQ,4BAA4BP,EAA4B,CAC9D,OACE,KAAK,SAAS,OAAO,CACnB,KAAM,IAAM,iBACZ,QAAS,IAAM,CACjB,CAAC,EACD,eACA,mBACCA,IAAe,EAAI,0BAA0B,EAElD,CACF,EA5JaV,EAANmB,EAAA,IADN,cAAW,EAqBPC,EAAA,eAAO,cAAY,6BAA6B,IApBxCpB",
6
6
  "names": ["DefaultApduSenderService_exports", "__export", "DefaultApduSenderService", "__toCommonJS", "import_inversify", "import_purify_ts", "import_uuid", "import_FramerConst", "import_FramerUtils", "import_Errors", "import_Frame", "import_FrameHeader", "import_loggerTypes", "DefaultApduSenderService", "frameSize", "channel", "padding", "loggerServiceFactory", "apdu", "frames", "count", "frame", "error", "frameIndex", "header", "frameOffset", "dataMaxSize", "data", "frameData", "apduSize", "sum", "i", "__decorateClass", "__decorateParam"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var x=require("purify-ts"),t=require("../../device-session/model/Frame"),i=require("../../device-session/model/FrameHeader"),w=require("../../logger-publisher/service/DefaultLoggerPublisherService"),d=require("./DefaultApduSenderService");vi.mock("uuid",()=>({v4:vi.fn().mockReturnValue("42")}));const o=new w.DefaultLoggerPublisherService([],"frame");describe("DefaultApduSenderService",()=>{describe("[USB] With padding and channel",()=>{it("should return 1 frame",()=>{const n=x.Maybe.of(new Uint8Array([18,52])),a=new d.DefaultApduSenderService({frameSize:64,padding:!0,channel:n},()=>o),e=new Uint8Array([224,1,0,0,0]),r=a.getFrames(e);expect(r).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,5])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])})]),expect(r.map(c=>c.getRawData())).toEqual([new Uint8Array([18,52,5,0,0,0,5,224,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])])}),it("should return 2 frames",()=>{const n=x.Maybe.of(new Uint8Array([18,52])),a=new d.DefaultApduSenderService({frameSize:64,padding:!0,channel:n},()=>o),e=new Uint8Array([224,212,0,0,64,84,111,102,117,73,115,78,117,116,114,105,116,105,111,117,115,65,110,100,66,114,105,110,103,115,74,111,121,68,101,108,105,103,104,116,72,101,97,108,116,104,105,110,101,115,115,72,97,114,109,111,110,121,73,110,69,118,101,114,121,66,105,116,101]),r=a.getFrames(e);expect(r).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,69])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,212,0,0,64,84,111,102,117,73,115,78,117,116,114,105,116,105,111,117,115,65,110,100,66,114,105,110,103,115,74,111,121,68,101,108,105,103,104,116,72,101,97,108,116,104,105,110,101,115,115,72,97,114,109,111,110])}),new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),index:new Uint8Array([0,1]),length:5,dataSize:x.Maybe.zero()}),data:new Uint8Array([121,73,110,69,118,101,114,121,66,105,116,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])})]),expect(r.map(c=>c.getRawData())).toEqual([new Uint8Array([18,52,5,0,0,0,69,224,212,0,0,64,84,111,102,117,73,115,78,117,116,114,105,116,105,111,117,115,65,110,100,66,114,105,110,103,115,74,111,121,68,101,108,105,103,104,116,72,101,97,108,116,104,105,110,101,115,115,72,97,114,109,111,110]),new Uint8Array([18,52,5,0,1,121,73,110,69,118,101,114,121,66,105,116,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])])})}),describe("[BLE] Without padding nor channel",()=>{it("should return 1 frame",()=>{const n=new d.DefaultApduSenderService({frameSize:123},()=>o),a=new Uint8Array([224,1,0,0,0]),e=n.getFrames(a);expect(e).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,5])),index:new Uint8Array([0,0]),length:5}),data:new Uint8Array([224,1,0,0,0])})]),expect(e.map(r=>r.getRawData())).toEqual([new Uint8Array([5,0,0,0,5,224,1,0,0,0])])}),it("should return 3 frames",()=>{const n=new d.DefaultApduSenderService({frameSize:10},()=>o),a=new Uint8Array([1,5,79,76,79,83,0,7,46,50,46,52,45,50,0,144,0]),e=n.getFrames(a);expect(e).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),index:new Uint8Array([0,0]),dataSize:x.Maybe.of(new Uint8Array([0,17])),length:5}),data:new Uint8Array([1,5,79,76,79])}),new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),dataSize:x.Maybe.zero(),index:new Uint8Array([0,1]),length:3}),data:new Uint8Array([83,0,7,46,50,46,52])}),new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),dataSize:x.Maybe.zero(),index:new Uint8Array([0,2]),length:3}),data:new Uint8Array([45,50,0,144,0])})]),expect(e.map(r=>r.getRawData())).toEqual([new Uint8Array([5,0,0,0,17,1,5,79,76,79]),new Uint8Array([5,0,1,83,0,7,46,50,46,52]),new Uint8Array([5,0,2,45,50,0,144,0])])})}),describe("Errors",()=>{it("should return a well formatted header with very big channel",()=>{const n=new d.DefaultApduSenderService({frameSize:64,channel:x.Maybe.of(new Uint8Array([1193012,214084,353364,30788,590916]))},()=>o),a=new Uint8Array([224,1,0,0,0]),e=n.getFrames(a);expect(e).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([68,68])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,5])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,1,0,0,0])})]),expect(e.map(r=>r.getRawData())).toEqual([new Uint8Array([68,68,5,0,0,0,5,224,1,0,0,0])])}),it("should return empty if packet size smaller than header size",()=>{const n=new d.DefaultApduSenderService({frameSize:Math.random()&4,channel:x.Maybe.of(new Uint8Array([18,52]))},()=>o),a=new Uint8Array([224,1,0,0,0]),e=n.getFrames(a);expect(e.length).toEqual(0)}),it("should return empty if no apdu length",()=>{const n=new d.DefaultApduSenderService({frameSize:Math.random()&255,padding:Math.random()>.5,channel:x.Maybe.of(new Uint8Array([18,52]))},()=>o),a=new Uint8Array([]),e=n.getFrames(a);expect(e.length).toEqual(0)})})});
1
+ "use strict";var x=require("purify-ts"),t=require("../../device-session/model/Frame"),i=require("../../device-session/model/FrameHeader"),w=require("../../logger-publisher/service/DefaultLoggerPublisherService"),d=require("./DefaultApduSenderService");vi.mock("uuid",()=>({v4:vi.fn().mockReturnValue("42")}));const o=new w.DefaultLoggerPublisherService([],"frame");describe("DefaultApduSenderService",()=>{describe("[USB] With padding and channel",()=>{it("should return 1 frame",()=>{const n=x.Maybe.of(new Uint8Array([18,52])),a=new d.DefaultApduSenderService({frameSize:64,padding:!0,channel:n},()=>o),e=new Uint8Array([224,1,0,0,0]),r=a.getFrames(e);expect(r).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,5])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])})]),expect(r.map(c=>c.getRawData())).toEqual([new Uint8Array([18,52,5,0,0,0,5,224,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])])}),it("should return 2 frames",()=>{const n=x.Maybe.of(new Uint8Array([18,52])),a=new d.DefaultApduSenderService({frameSize:64,padding:!0,channel:n},()=>o),e=new Uint8Array([224,212,0,0,64,84,111,102,117,73,115,78,117,116,114,105,116,105,111,117,115,65,110,100,66,114,105,110,103,115,74,111,121,68,101,108,105,103,104,116,72,101,97,108,116,104,105,110,101,115,115,72,97,114,109,111,110,121,73,110,69,118,101,114,121,66,105,116,101]),r=a.getFrames(e);expect(r).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,69])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,212,0,0,64,84,111,102,117,73,115,78,117,116,114,105,116,105,111,117,115,65,110,100,66,114,105,110,103,115,74,111,121,68,101,108,105,103,104,116,72,101,97,108,116,104,105,110,101,115,115,72,97,114,109,111,110])}),new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),index:new Uint8Array([0,1]),length:5,dataSize:x.Maybe.zero()}),data:new Uint8Array([121,73,110,69,118,101,114,121,66,105,116,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])})]),expect(r.map(c=>c.getRawData())).toEqual([new Uint8Array([18,52,5,0,0,0,69,224,212,0,0,64,84,111,102,117,73,115,78,117,116,114,105,116,105,111,117,115,65,110,100,66,114,105,110,103,115,74,111,121,68,101,108,105,103,104,116,72,101,97,108,116,104,105,110,101,115,115,72,97,114,109,111,110]),new Uint8Array([18,52,5,0,1,121,73,110,69,118,101,114,121,66,105,116,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])])}),it("should return exactly 0 frame",()=>{const n=x.Maybe.of(new Uint8Array([18,52])),a=new d.DefaultApduSenderService({frameSize:64,padding:!0,channel:n},()=>o),e=new Uint8Array([]),r=a.getFrames(e);expect(r).toEqual([])}),it("should return exactly 1 frame",()=>{const n=x.Maybe.of(new Uint8Array([18,52])),a=new d.DefaultApduSenderService({frameSize:64,padding:!0,channel:n},()=>o),e=new Uint8Array([224,6,0,19,52,71,50,73,103,115,81,104,104,88,83,105,77,113,56,107,85,80,121,78,110,70,99,99,49,69,105,65,103,119,53,78,120,109,45,104,105,111,121,86,103,106,57,119,72,86,101,77,4,9,146,192,254]),r=a.getFrames(e);expect(r).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([18,52])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,57])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,6,0,19,52,71,50,73,103,115,81,104,104,88,83,105,77,113,56,107,85,80,121,78,110,70,99,99,49,69,105,65,103,119,53,78,120,109,45,104,105,111,121,86,103,106,57,119,72,86,101,77,4,9,146,192,254])})]),expect(r.map(c=>c.getRawData())).toEqual([new Uint8Array([18,52,5,0,0,0,57,224,6,0,19,52,71,50,73,103,115,81,104,104,88,83,105,77,113,56,107,85,80,121,78,110,70,99,99,49,69,105,65,103,119,53,78,120,109,45,104,105,111,121,86,103,106,57,119,72,86,101,77,4,9,146,192,254])])})}),describe("[BLE] Without padding nor channel",()=>{it("should return 1 frame",()=>{const n=new d.DefaultApduSenderService({frameSize:123},()=>o),a=new Uint8Array([224,1,0,0,0]),e=n.getFrames(a);expect(e).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,5])),index:new Uint8Array([0,0]),length:5}),data:new Uint8Array([224,1,0,0,0])})]),expect(e.map(r=>r.getRawData())).toEqual([new Uint8Array([5,0,0,0,5,224,1,0,0,0])])}),it("should return 3 frames",()=>{const n=new d.DefaultApduSenderService({frameSize:10},()=>o),a=new Uint8Array([1,5,79,76,79,83,0,7,46,50,46,52,45,50,0,144,0]),e=n.getFrames(a);expect(e).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),index:new Uint8Array([0,0]),dataSize:x.Maybe.of(new Uint8Array([0,17])),length:5}),data:new Uint8Array([1,5,79,76,79])}),new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),dataSize:x.Maybe.zero(),index:new Uint8Array([0,1]),length:3}),data:new Uint8Array([83,0,7,46,50,46,52])}),new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.zero(),headTag:new Uint8Array([5]),dataSize:x.Maybe.zero(),index:new Uint8Array([0,2]),length:3}),data:new Uint8Array([45,50,0,144,0])})]),expect(e.map(r=>r.getRawData())).toEqual([new Uint8Array([5,0,0,0,17,1,5,79,76,79]),new Uint8Array([5,0,1,83,0,7,46,50,46,52]),new Uint8Array([5,0,2,45,50,0,144,0])])})}),describe("Errors",()=>{it("should return a well formatted header with very big channel",()=>{const n=new d.DefaultApduSenderService({frameSize:64,channel:x.Maybe.of(new Uint8Array([1193012,214084,353364,30788,590916]))},()=>o),a=new Uint8Array([224,1,0,0,0]),e=n.getFrames(a);expect(e).toEqual([new t.Frame({header:new i.FrameHeader({uuid:"42",channel:x.Maybe.of(new Uint8Array([68,68])),headTag:new Uint8Array([5]),dataSize:x.Maybe.of(new Uint8Array([0,5])),index:new Uint8Array([0,0]),length:7}),data:new Uint8Array([224,1,0,0,0])})]),expect(e.map(r=>r.getRawData())).toEqual([new Uint8Array([68,68,5,0,0,0,5,224,1,0,0,0])])}),it("should return empty if packet size smaller than header size",()=>{const n=new d.DefaultApduSenderService({frameSize:Math.random()&4,channel:x.Maybe.of(new Uint8Array([18,52]))},()=>o),a=new Uint8Array([224,1,0,0,0]),e=n.getFrames(a);expect(e.length).toEqual(0)}),it("should return empty if no apdu length",()=>{const n=new d.DefaultApduSenderService({frameSize:Math.random()&255,padding:Math.random()>.5,channel:x.Maybe.of(new Uint8Array([18,52]))},()=>o),a=new Uint8Array([]),e=n.getFrames(a);expect(e.length).toEqual(0)})})});
2
2
  //# sourceMappingURL=DefaultApduSenderService.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/internal/device-session/service/DefaultApduSenderService.test.ts"],
4
- "sourcesContent": ["import { Maybe } from \"purify-ts\";\n\nimport { Frame } from \"@internal/device-session/model/Frame\";\nimport { FrameHeader } from \"@internal/device-session/model/FrameHeader\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\n\nimport { DefaultApduSenderService } from \"./DefaultApduSenderService\";\n\nvi.mock(\"uuid\", () => ({\n v4: vi.fn().mockReturnValue(\"42\"),\n}));\n\nconst loggerService = new DefaultLoggerPublisherService([], \"frame\");\n\ndescribe(\"DefaultApduSenderService\", () => {\n describe(\"[USB] With padding and channel\", () => {\n it(\"should return 1 frame\", () => {\n // given\n const channel = Maybe.of(new Uint8Array([0x12, 0x34]));\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n padding: true,\n channel,\n },\n () => loggerService,\n );\n // getVersion APDU\n const apdu = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(apdu);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0, 0x05])),\n index: new Uint8Array([0, 0]),\n length: 7,\n }),\n data: new Uint8Array([\n 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00,\n ]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x00, 0x00, 0x05, 0xe0, 0x01, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n ]),\n ]);\n });\n\n it(\"should return 2 frames\", () => {\n // given\n const channel = Maybe.of(new Uint8Array([0x12, 0x34]));\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n padding: true,\n channel,\n },\n () => loggerService,\n );\n const apdu = new Uint8Array([\n // editDeviceName APDU\n 0xe0, 0xd4, 0x00, 0x00, 0x40,\n // editDeviceNameData\n 0x54, 0x6f, 0x66, 0x75, 0x49, 0x73, 0x4e, 0x75, 0x74, 0x72, 0x69, 0x74,\n 0x69, 0x6f, 0x75, 0x73, 0x41, 0x6e, 0x64, 0x42, 0x72, 0x69, 0x6e, 0x67,\n 0x73, 0x4a, 0x6f, 0x79, 0x44, 0x65, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x48,\n 0x65, 0x61, 0x6c, 0x74, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x48, 0x61,\n 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x49, 0x6e, 0x45, 0x76, 0x65, 0x72, 0x79,\n 0x42, 0x69, 0x74, 0x65,\n ]);\n\n // when\n const frames = apduSenderService.getFrames(apdu);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0x00, 0x45])),\n index: new Uint8Array([0x00, 0x00]),\n length: 7,\n }),\n data: new Uint8Array([\n 0xe0, 0xd4, 0x00, 0x00, 0x40, 0x54, 0x6f, 0x66, 0x75, 0x49, 0x73,\n 0x4e, 0x75, 0x74, 0x72, 0x69, 0x74, 0x69, 0x6f, 0x75, 0x73, 0x41,\n 0x6e, 0x64, 0x42, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x4a, 0x6f, 0x79,\n 0x44, 0x65, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x48, 0x65, 0x61, 0x6c,\n 0x74, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x48, 0x61, 0x72, 0x6d,\n 0x6f, 0x6e,\n ]),\n }),\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n index: new Uint8Array([0x00, 0x01]),\n length: 5,\n dataSize: Maybe.zero(),\n }),\n data: new Uint8Array([\n 0x79, 0x49, 0x6e, 0x45, 0x76, 0x65, 0x72, 0x79, 0x42, 0x69, 0x74,\n 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00,\n ]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x00, 0x00, 0x45, 0xe0, 0xd4, 0x00, 0x00,\n 0x40, 0x54, 0x6f, 0x66, 0x75, 0x49, 0x73, 0x4e, 0x75, 0x74, 0x72,\n 0x69, 0x74, 0x69, 0x6f, 0x75, 0x73, 0x41, 0x6e, 0x64, 0x42, 0x72,\n 0x69, 0x6e, 0x67, 0x73, 0x4a, 0x6f, 0x79, 0x44, 0x65, 0x6c, 0x69,\n 0x67, 0x68, 0x74, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x69, 0x6e,\n 0x65, 0x73, 0x73, 0x48, 0x61, 0x72, 0x6d, 0x6f, 0x6e,\n ]),\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x01, 0x79, 0x49, 0x6e, 0x45, 0x76, 0x65,\n 0x72, 0x79, 0x42, 0x69, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n ]),\n ]);\n });\n });\n\n describe(\"[BLE] Without padding nor channel\", () => {\n it(\"should return 1 frame\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 123,\n },\n () => loggerService,\n );\n const command = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0, 5])),\n index: new Uint8Array([0, 0]),\n length: 5,\n }),\n data: new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x05, 0x00, 0x00, 0x00, 0x05, 0xe0, 0x01, 0x00, 0x00, 0x00,\n ]),\n ]);\n });\n\n it(\"should return 3 frames\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 10,\n },\n () => loggerService,\n );\n const command = new Uint8Array([\n 0x01, 0x05, 0x4f, 0x4c, 0x4f, 0x53, 0x00, 0x07, 0x2e, 0x32, 0x2e, 0x34,\n 0x2d, 0x32, 0x00, 0x90, 0x00,\n ]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n index: new Uint8Array([0, 0]),\n dataSize: Maybe.of(new Uint8Array([0, 0x11])),\n length: 5,\n }),\n data: new Uint8Array([0x01, 0x05, 0x4f, 0x4c, 0x4f]),\n }),\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.zero(),\n index: new Uint8Array([0, 0x01]),\n length: 3,\n }),\n data: new Uint8Array([0x53, 0x00, 0x07, 0x2e, 0x32, 0x2e, 0x34]),\n }),\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.zero(),\n index: new Uint8Array([0, 0x02]),\n length: 3,\n }),\n data: new Uint8Array([0x2d, 0x32, 0x00, 0x90, 0x00]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x05, 0x00, 0x00, 0x00, 0x11, 0x01, 0x05, 0x4f, 0x4c, 0x4f,\n ]),\n new Uint8Array([\n 0x05, 0x00, 0x01, 0x53, 0x00, 0x07, 0x2e, 0x32, 0x2e, 0x34,\n ]),\n new Uint8Array([0x05, 0x00, 0x02, 0x2d, 0x32, 0x00, 0x90, 0x00]),\n ]);\n });\n });\n\n describe(\"Errors\", () => {\n it(\"should return a well formatted header with very big channel\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n channel: Maybe.of(\n new Uint8Array([0x123434, 0x34444, 0x56454, 0x7844, 0x90444]),\n ),\n },\n () => loggerService,\n );\n const command = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x44, 0x44])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0, 0x05])),\n index: new Uint8Array([0, 0]),\n length: 7,\n }),\n data: new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x44, 0x44, 0x05, 0x00, 0x00, 0x00, 0x05, 0xe0, 0x01, 0x00, 0x00,\n 0x00,\n ]),\n ]);\n });\n it(\"should return empty if packet size smaller than header size\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: Math.random() & 4,\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n },\n () => loggerService,\n );\n const command = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames.length).toEqual(0);\n });\n\n it(\"should return empty if no apdu length\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n // random frameSize < 0xff\n frameSize: Math.random() & 0xff,\n // random padding boolean\n padding: Math.random() > 0.5,\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n },\n () => loggerService,\n );\n const command = new Uint8Array([]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames.length).toEqual(0);\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAAsB,qBAEtBC,EAAsB,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C,GAAM,EAAI,CAAC,CAAC,CAChD,EACA,IAAMF,CACR,EACMM,EAAU,IAAI,WAAW,CAAC,CAAC,EAG3BF,EAASF,EAAkB,UAAUI,CAAO,EAGlD,OAAOF,EAAO,MAAM,EAAE,QAAQ,CAAC,CACjC,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { Maybe } from \"purify-ts\";\n\nimport { Frame } from \"@internal/device-session/model/Frame\";\nimport { FrameHeader } from \"@internal/device-session/model/FrameHeader\";\nimport { DefaultLoggerPublisherService } from \"@internal/logger-publisher/service/DefaultLoggerPublisherService\";\n\nimport { DefaultApduSenderService } from \"./DefaultApduSenderService\";\n\nvi.mock(\"uuid\", () => ({\n v4: vi.fn().mockReturnValue(\"42\"),\n}));\n\nconst loggerService = new DefaultLoggerPublisherService([], \"frame\");\n\ndescribe(\"DefaultApduSenderService\", () => {\n describe(\"[USB] With padding and channel\", () => {\n it(\"should return 1 frame\", () => {\n // given\n const channel = Maybe.of(new Uint8Array([0x12, 0x34]));\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n padding: true,\n channel,\n },\n () => loggerService,\n );\n // getVersion APDU\n const apdu = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(apdu);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0, 0x05])),\n index: new Uint8Array([0, 0]),\n length: 7,\n }),\n data: new Uint8Array([\n 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00,\n ]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x00, 0x00, 0x05, 0xe0, 0x01, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n ]),\n ]);\n });\n\n it(\"should return 2 frames\", () => {\n // given\n const channel = Maybe.of(new Uint8Array([0x12, 0x34]));\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n padding: true,\n channel,\n },\n () => loggerService,\n );\n const apdu = new Uint8Array([\n // editDeviceName APDU\n 0xe0, 0xd4, 0x00, 0x00, 0x40,\n // editDeviceNameData\n 0x54, 0x6f, 0x66, 0x75, 0x49, 0x73, 0x4e, 0x75, 0x74, 0x72, 0x69, 0x74,\n 0x69, 0x6f, 0x75, 0x73, 0x41, 0x6e, 0x64, 0x42, 0x72, 0x69, 0x6e, 0x67,\n 0x73, 0x4a, 0x6f, 0x79, 0x44, 0x65, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x48,\n 0x65, 0x61, 0x6c, 0x74, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x48, 0x61,\n 0x72, 0x6d, 0x6f, 0x6e, 0x79, 0x49, 0x6e, 0x45, 0x76, 0x65, 0x72, 0x79,\n 0x42, 0x69, 0x74, 0x65,\n ]);\n\n // when\n const frames = apduSenderService.getFrames(apdu);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0x00, 0x45])),\n index: new Uint8Array([0x00, 0x00]),\n length: 7,\n }),\n data: new Uint8Array([\n 0xe0, 0xd4, 0x00, 0x00, 0x40, 0x54, 0x6f, 0x66, 0x75, 0x49, 0x73,\n 0x4e, 0x75, 0x74, 0x72, 0x69, 0x74, 0x69, 0x6f, 0x75, 0x73, 0x41,\n 0x6e, 0x64, 0x42, 0x72, 0x69, 0x6e, 0x67, 0x73, 0x4a, 0x6f, 0x79,\n 0x44, 0x65, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x48, 0x65, 0x61, 0x6c,\n 0x74, 0x68, 0x69, 0x6e, 0x65, 0x73, 0x73, 0x48, 0x61, 0x72, 0x6d,\n 0x6f, 0x6e,\n ]),\n }),\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n index: new Uint8Array([0x00, 0x01]),\n length: 5,\n dataSize: Maybe.zero(),\n }),\n data: new Uint8Array([\n 0x79, 0x49, 0x6e, 0x45, 0x76, 0x65, 0x72, 0x79, 0x42, 0x69, 0x74,\n 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00,\n ]),\n }),\n ]);\n\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x00, 0x00, 0x45, 0xe0, 0xd4, 0x00, 0x00,\n 0x40, 0x54, 0x6f, 0x66, 0x75, 0x49, 0x73, 0x4e, 0x75, 0x74, 0x72,\n 0x69, 0x74, 0x69, 0x6f, 0x75, 0x73, 0x41, 0x6e, 0x64, 0x42, 0x72,\n 0x69, 0x6e, 0x67, 0x73, 0x4a, 0x6f, 0x79, 0x44, 0x65, 0x6c, 0x69,\n 0x67, 0x68, 0x74, 0x48, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x69, 0x6e,\n 0x65, 0x73, 0x73, 0x48, 0x61, 0x72, 0x6d, 0x6f, 0x6e,\n ]),\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x01, 0x79, 0x49, 0x6e, 0x45, 0x76, 0x65,\n 0x72, 0x79, 0x42, 0x69, 0x74, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n ]),\n ]);\n });\n\n it(\"should return exactly 0 frame\", () => {\n // given\n const channel = Maybe.of(new Uint8Array([0x12, 0x34]));\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n padding: true,\n channel,\n },\n () => loggerService,\n );\n const apdu = new Uint8Array([]);\n\n // when\n const frames = apduSenderService.getFrames(apdu);\n expect(frames).toEqual([]);\n });\n\n it(\"should return exactly 1 frame\", () => {\n // given\n const channel = Maybe.of(new Uint8Array([0x12, 0x34]));\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n padding: true,\n channel,\n },\n () => loggerService,\n );\n const apdu = new Uint8Array([\n 0xe0, 0x06, 0x00, 0x13, 0x34, 0x47, 0x32, 0x49, 0x67, 0x73, 0x51, 0x68,\n 0x68, 0x58, 0x53, 0x69, 0x4d, 0x71, 0x38, 0x6b, 0x55, 0x50, 0x79, 0x4e,\n 0x6e, 0x46, 0x63, 0x63, 0x31, 0x45, 0x69, 0x41, 0x67, 0x77, 0x35, 0x4e,\n 0x78, 0x6d, 0x2d, 0x68, 0x69, 0x6f, 0x79, 0x56, 0x67, 0x6a, 0x39, 0x77,\n 0x48, 0x56, 0x65, 0x4d, 0x04, 0x09, 0x92, 0xc0, 0xfe,\n ]);\n\n // when\n const frames = apduSenderService.getFrames(apdu);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0x00, 0x39])),\n index: new Uint8Array([0x00, 0x00]),\n length: 7,\n }),\n data: new Uint8Array([\n 0xe0, 0x06, 0x00, 0x13, 0x34, 0x47, 0x32, 0x49, 0x67, 0x73, 0x51,\n 0x68, 0x68, 0x58, 0x53, 0x69, 0x4d, 0x71, 0x38, 0x6b, 0x55, 0x50,\n 0x79, 0x4e, 0x6e, 0x46, 0x63, 0x63, 0x31, 0x45, 0x69, 0x41, 0x67,\n 0x77, 0x35, 0x4e, 0x78, 0x6d, 0x2d, 0x68, 0x69, 0x6f, 0x79, 0x56,\n 0x67, 0x6a, 0x39, 0x77, 0x48, 0x56, 0x65, 0x4d, 0x04, 0x09, 0x92,\n 0xc0, 0xfe,\n ]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x12, 0x34, 0x05, 0x00, 0x00, 0x00, 0x39, 0xe0, 0x06, 0x00, 0x13,\n 0x34, 0x47, 0x32, 0x49, 0x67, 0x73, 0x51, 0x68, 0x68, 0x58, 0x53,\n 0x69, 0x4d, 0x71, 0x38, 0x6b, 0x55, 0x50, 0x79, 0x4e, 0x6e, 0x46,\n 0x63, 0x63, 0x31, 0x45, 0x69, 0x41, 0x67, 0x77, 0x35, 0x4e, 0x78,\n 0x6d, 0x2d, 0x68, 0x69, 0x6f, 0x79, 0x56, 0x67, 0x6a, 0x39, 0x77,\n 0x48, 0x56, 0x65, 0x4d, 0x04, 0x09, 0x92, 0xc0, 0xfe,\n ]),\n ]);\n });\n });\n\n describe(\"[BLE] Without padding nor channel\", () => {\n it(\"should return 1 frame\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 123,\n },\n () => loggerService,\n );\n const command = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0, 5])),\n index: new Uint8Array([0, 0]),\n length: 5,\n }),\n data: new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x05, 0x00, 0x00, 0x00, 0x05, 0xe0, 0x01, 0x00, 0x00, 0x00,\n ]),\n ]);\n });\n\n it(\"should return 3 frames\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 10,\n },\n () => loggerService,\n );\n const command = new Uint8Array([\n 0x01, 0x05, 0x4f, 0x4c, 0x4f, 0x53, 0x00, 0x07, 0x2e, 0x32, 0x2e, 0x34,\n 0x2d, 0x32, 0x00, 0x90, 0x00,\n ]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n index: new Uint8Array([0, 0]),\n dataSize: Maybe.of(new Uint8Array([0, 0x11])),\n length: 5,\n }),\n data: new Uint8Array([0x01, 0x05, 0x4f, 0x4c, 0x4f]),\n }),\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.zero(),\n index: new Uint8Array([0, 0x01]),\n length: 3,\n }),\n data: new Uint8Array([0x53, 0x00, 0x07, 0x2e, 0x32, 0x2e, 0x34]),\n }),\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.zero(),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.zero(),\n index: new Uint8Array([0, 0x02]),\n length: 3,\n }),\n data: new Uint8Array([0x2d, 0x32, 0x00, 0x90, 0x00]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x05, 0x00, 0x00, 0x00, 0x11, 0x01, 0x05, 0x4f, 0x4c, 0x4f,\n ]),\n new Uint8Array([\n 0x05, 0x00, 0x01, 0x53, 0x00, 0x07, 0x2e, 0x32, 0x2e, 0x34,\n ]),\n new Uint8Array([0x05, 0x00, 0x02, 0x2d, 0x32, 0x00, 0x90, 0x00]),\n ]);\n });\n });\n\n describe(\"Errors\", () => {\n it(\"should return a well formatted header with very big channel\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: 64,\n channel: Maybe.of(\n new Uint8Array([0x123434, 0x34444, 0x56454, 0x7844, 0x90444]),\n ),\n },\n () => loggerService,\n );\n const command = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames).toEqual([\n new Frame({\n header: new FrameHeader({\n uuid: \"42\",\n channel: Maybe.of(new Uint8Array([0x44, 0x44])),\n headTag: new Uint8Array([0x05]),\n dataSize: Maybe.of(new Uint8Array([0, 0x05])),\n index: new Uint8Array([0, 0]),\n length: 7,\n }),\n data: new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]),\n }),\n ]);\n expect(frames.map((fr) => fr.getRawData())).toEqual([\n new Uint8Array([\n 0x44, 0x44, 0x05, 0x00, 0x00, 0x00, 0x05, 0xe0, 0x01, 0x00, 0x00,\n 0x00,\n ]),\n ]);\n });\n it(\"should return empty if packet size smaller than header size\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n frameSize: Math.random() & 4,\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n },\n () => loggerService,\n );\n const command = new Uint8Array([0xe0, 0x01, 0x00, 0x00, 0x00]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames.length).toEqual(0);\n });\n\n it(\"should return empty if no apdu length\", () => {\n // given\n const apduSenderService = new DefaultApduSenderService(\n {\n // random frameSize < 0xff\n frameSize: Math.random() & 0xff,\n // random padding boolean\n padding: Math.random() > 0.5,\n channel: Maybe.of(new Uint8Array([0x12, 0x34])),\n },\n () => loggerService,\n );\n const command = new Uint8Array([]);\n\n // when\n const frames = apduSenderService.getFrames(command);\n\n // then\n expect(frames.length).toEqual(0);\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAAsB,qBAEtBC,EAAsB,gDACtBC,EAA4B,sDAC5BC,EAA8C,4EAE9CC,EAAyC,sCAEzC,GAAG,KAAK,OAAQ,KAAO,CACrB,GAAI,GAAG,GAAG,EAAE,gBAAgB,IAAI,CAClC,EAAE,EAEF,MAAMC,EAAgB,IAAI,gCAA8B,CAAC,EAAG,OAAO,EAEnE,SAAS,2BAA4B,IAAM,CACzC,SAAS,iCAAkC,IAAM,CAC/C,GAAG,wBAAyB,IAAM,CAEhC,MAAMC,EAAU,QAAM,GAAG,IAAI,WAAW,CAAC,GAAM,EAAI,CAAC,CAAC,EAC/CC,EAAoB,IAAI,2BAC5B,CACE,UAAW,GACX,QAAS,GACT,QAAAD,CACF,EACA,IAAMD,CACR,EAEMG,EAAO,IAAI,WAAW,CAAC,IAAM,EAAM,EAAM,EAAM,CAAI,CAAC,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W,KAAK,OAAO,EAAI,EAC3B,QAAS,QAAM,GAAG,IAAI,WAAW,CAAC,GAAM,EAAI,CAAC,CAAC,CAChD,EACA,IAAMF,CACR,EACMM,EAAU,IAAI,WAAW,CAAC,IAAM,EAAM,EAAM,EAAM,CAAI,CAAC,EAGvDF,EAASF,EAAkB,UAAUI,CAAO,EAGlD,OAAOF,EAAO,MAAM,EAAE,QAAQ,CAAC,CACjC,CAAC,EAED,GAAG,wCAAyC,IAAM,CAEhD,MAAMF,EAAoB,IAAI,2BAC5B,CAEE,UAAW,KAAK,OAAO,EAAI,IAE3B,QAAS,KAAK,OAAO,EAAI,GACzB,QAAS,QAAM,GAAG,IAAI,WAAW,CAAC,GAAM,EAAI,CAAC,CAAC,CAChD,EACA,IAAMF,CACR,EACMM,EAAU,IAAI,WAAW,CAAC,CAAC,EAG3BF,EAASF,EAAkB,UAAUI,CAAO,EAGlD,OAAOF,EAAO,MAAM,EAAE,QAAQ,CAAC,CACjC,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_purify_ts", "import_Frame", "import_FrameHeader", "import_DefaultLoggerPublisherService", "import_DefaultApduSenderService", "loggerService", "channel", "apduSenderService", "apdu", "frames", "fr", "command"]
7
7
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/device-management-kit",
3
- "version": "0.7.0",
3
+ "version": "0.9.1",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -1,2 +1,2 @@
1
- import{commandTypes as c}from"./command/di/commandTypes";import{configTypes as a}from"../internal/config/di/configTypes";import{deviceSessionTypes as t}from"../internal/device-session/di/deviceSessionTypes";import{discoveryTypes as s}from"../internal/discovery/di/discoveryTypes";import{managerApiTypes as r}from"../internal/manager-api/di/managerApiTypes";import{sendTypes as p}from"../internal/send/di/sendTypes";import{makeContainer as m}from"../../src/di";import{deviceActionTypes as C}from"./device-action/di/deviceActionTypes";class l{container;constructor({stub:e,transports:i,loggers:o,config:n}={}){this.container=m({stub:e,transports:i,loggers:o,config:n})}getVersion(){return this.container.get(a.GetDmkVersionUseCase).getDmkVersion()}startDiscovering(e){return this.container.get(s.StartDiscoveringUseCase).execute(e)}stopDiscovering(){return this.container.get(s.StopDiscoveringUseCase).execute()}listenToAvailableDevices(e){return this.container.get(s.ListenToAvailableDevicesUseCase).execute(e)}connect(e){return this.container.get(s.ConnectUseCase).execute(e)}disconnect(e){return this.container.get(s.DisconnectUseCase).execute(e)}sendApdu(e){return this.container.get(p.SendApduUseCase).execute(e)}sendCommand(e){return this.container.get(c.SendCommandUseCase).execute(e)}executeDeviceAction(e){return this.container.get(C.ExecuteDeviceActionUseCase).execute(e)}getConnectedDevice(e){return this.container.get(s.GetConnectedDeviceUseCase).execute(e)}getDeviceSessionState(e){return this.container.get(t.GetDeviceSessionStateUseCase).execute(e)}close(){return this.container.get(t.CloseSessionsUseCase).execute()}listConnectedDevices(){return this.container.get(s.ListConnectedDevicesUseCase).execute()}listenToConnectedDevice(){return this.container.get(s.ListenToConnectedDeviceUseCase).execute()}disableDeviceSessionRefresher(e){return this.container.get(t.DisableDeviceSessionRefresherUseCase).execute(e)}setProvider(e){return this.container.get(r.SetProviderUseCase).execute(e)}getProvider(){return this.container.get(r.ManagerApiDataSource).getProvider()}}export{l as DeviceManagementKit};
1
+ import{commandTypes as c}from"./command/di/commandTypes";import{configTypes as a}from"../internal/config/di/configTypes";import{deviceSessionTypes as t}from"../internal/device-session/di/deviceSessionTypes";import{discoveryTypes as s}from"../internal/discovery/di/discoveryTypes";import{managerApiTypes as r}from"../internal/manager-api/di/managerApiTypes";import{sendTypes as p}from"../internal/send/di/sendTypes";import{transportDiTypes as m}from"../internal/transport/di/transportDiTypes";import{makeContainer as C}from"../../src/di";import{deviceActionTypes as v}from"./device-action/di/deviceActionTypes";class x{container;constructor({stub:e,transports:i,loggers:o,config:n}={}){this.container=C({stub:e,transports:i,loggers:o,config:n})}getVersion(){return this.container.get(a.GetDmkVersionUseCase).getDmkVersion()}startDiscovering(e){return this.container.get(s.StartDiscoveringUseCase).execute(e)}stopDiscovering(){return this.container.get(s.StopDiscoveringUseCase).execute()}listenToAvailableDevices(e){return this.container.get(s.ListenToAvailableDevicesUseCase).execute(e)}connect(e){return this.container.get(s.ConnectUseCase).execute(e)}disconnect(e){return this.container.get(s.DisconnectUseCase).execute(e)}sendApdu(e){return this.container.get(p.SendApduUseCase).execute(e)}sendCommand(e){return this.container.get(c.SendCommandUseCase).execute(e)}executeDeviceAction(e){return this.container.get(v.ExecuteDeviceActionUseCase).execute(e)}getConnectedDevice(e){return this.container.get(s.GetConnectedDeviceUseCase).execute(e)}getDeviceSessionState(e){return this.container.get(t.GetDeviceSessionStateUseCase).execute(e)}close(){return this.container.get(t.CloseSessionsUseCase).execute()}listConnectedDevices(){return this.container.get(s.ListConnectedDevicesUseCase).execute()}listenToConnectedDevice(){return this.container.get(s.ListenToConnectedDeviceUseCase).execute()}disableDeviceSessionRefresher(e){return this.container.get(t.DisableDeviceSessionRefresherUseCase).execute(e)}setProvider(e){return this.container.get(r.SetProviderUseCase).execute(e)}getProvider(){return this.container.get(r.ManagerApiDataSource).getProvider()}isEnvironmentSupported(){return this.container.get(m.TransportService).getAllTransports().some(e=>e.isSupported())}}export{x as DeviceManagementKit};
2
2
  //# sourceMappingURL=DeviceManagementKit.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/DeviceManagementKit.ts"],
4
- "sourcesContent": ["import { type Container } from \"inversify\";\nimport { type Observable } from \"rxjs\";\n\nimport { commandTypes } from \"@api/command/di/commandTypes\";\nimport { type CommandResult } from \"@api/command/model/CommandResult\";\nimport {\n type SendCommandUseCase,\n type SendCommandUseCaseArgs,\n} from \"@api/command/use-case/SendCommandUseCase\";\nimport {\n type ExecuteDeviceActionUseCase,\n type ExecuteDeviceActionUseCaseArgs,\n} from \"@api/device-action/use-case/ExecuteDeviceActionUseCase\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport {\n type ConnectUseCaseArgs,\n type DisconnectUseCaseArgs,\n type DiscoveredDevice,\n type GetConnectedDeviceUseCaseArgs,\n type SendApduUseCaseArgs,\n type StartDiscoveringUseCaseArgs,\n} from \"@api/types\";\nimport { configTypes } from \"@internal/config/di/configTypes\";\nimport { type GetDmkVersionUseCase } from \"@internal/config/use-case/GetDmkVersionUseCase\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport { type CloseSessionsUseCase } from \"@internal/device-session/use-case/CloseSessionsUseCase\";\nimport { type GetDeviceSessionStateUseCase } from \"@internal/device-session/use-case/GetDeviceSessionStateUseCase\";\nimport { discoveryTypes } from \"@internal/discovery/di/discoveryTypes\";\nimport { type ConnectUseCase } from \"@internal/discovery/use-case/ConnectUseCase\";\nimport { type DisconnectUseCase } from \"@internal/discovery/use-case/DisconnectUseCase\";\nimport { type GetConnectedDeviceUseCase } from \"@internal/discovery/use-case/GetConnectedDeviceUseCase\";\nimport { type ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport {\n type ListenToAvailableDevicesUseCase,\n type ListenToAvailableDevicesUseCaseArgs,\n} from \"@internal/discovery/use-case/ListenToAvailableDevicesUseCase\";\nimport { type ListenToConnectedDeviceUseCase } from \"@internal/discovery/use-case/ListenToConnectedDeviceUseCase\";\nimport type { StartDiscoveringUseCase } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nimport type { StopDiscoveringUseCase } from \"@internal/discovery/use-case/StopDiscoveringUseCase\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport { type SetProviderUseCase } from \"@internal/manager-api/use-case/SetProviderUseCase\";\nimport { sendTypes } from \"@internal/send/di/sendTypes\";\nimport { type SendApduUseCase } from \"@internal/send/use-case/SendApduUseCase\";\nimport { makeContainer, type MakeContainerProps } from \"@root/src/di\";\n\nimport {\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"./device-action/DeviceAction\";\nimport { deviceActionTypes } from \"./device-action/di/deviceActionTypes\";\nimport { type DisableDeviceSessionRefresherUseCase } from \"./device-session/use-case/DisableDeviceSessionRefresher\";\nimport { type DmkError } from \"./Error\";\n\n/**\n * The main class to interact with the Device Management Kit.\n *\n * NB: do not instantiate this class directly, instead, use `LedgerDMKBuilder`.\n */\nexport class DeviceManagementKit {\n readonly container: Container;\n /** @internal */\n constructor({\n stub,\n transports,\n loggers,\n config,\n }: Partial<MakeContainerProps> = {}) {\n // NOTE: MakeContainerProps might not be the exact type here\n // For the init of the project this is sufficient, but we might need to\n // update the constructor arguments as we go (we might have more than just the container config)\n this.container = makeContainer({\n stub,\n transports,\n loggers,\n config,\n });\n }\n\n /**\n * Returns a promise resolving to the version of the SDK.\n */\n getVersion(): Promise<string> {\n return this.container\n .get<GetDmkVersionUseCase>(configTypes.GetDmkVersionUseCase)\n .getDmkVersion();\n }\n\n /**\n * Starts discovering devices connected.\n *\n * For the WeHID implementation, this use-case needs to be called as a result\n * of an user interaction (button \"click\" event for ex).\n *\n * @param {StartDiscoveringUseCaseArgs} args - The transport to use for discover, or undefined to discover from all transports.\n * @returns {Observable<DiscoveredDevice>} An observable of discovered devices.\n */\n startDiscovering(\n args: StartDiscoveringUseCaseArgs,\n ): Observable<DiscoveredDevice> {\n return this.container\n .get<StartDiscoveringUseCase>(discoveryTypes.StartDiscoveringUseCase)\n .execute(args);\n }\n\n /**\n * Stops discovering devices connected.\n */\n stopDiscovering() {\n return this.container\n .get<StopDiscoveringUseCase>(discoveryTypes.StopDiscoveringUseCase)\n .execute();\n }\n\n /**\n * Listen to list of known discovered devices (and later BLE).\n * @param {ListenToAvailableDevicesUseCaseArgs} args - The transport to use for discover, or undefined to discover from all transports.\n * @returns {Observable<DiscoveredDevice[]>} An observable of known discovered devices.\n */\n listenToAvailableDevices(\n args: ListenToAvailableDevicesUseCaseArgs,\n ): Observable<DiscoveredDevice[]> {\n return this.container\n .get<ListenToAvailableDevicesUseCase>(\n discoveryTypes.ListenToAvailableDevicesUseCase,\n )\n .execute(args);\n }\n\n /**\n * Connects to a device previously discovered with `DeviceManagementKit.startDiscovering`.\n * Creates a new device session which:\n * - Represents the connection to the device.\n * - Is terminated upon disconnection of the device.\n * - Exposes the device state through an observable (see `DeviceManagementKit.getDeviceSessionState`)\n * - Should be used for all subsequent communication with the device.\n *\n * @param {ConnectUseCaseArgs} args - The arguments for connecting to the device.\n * - `device`: The discovered device obtained from `StartDiscoveringUseCase`.\n * - `sessionRefresherOptions` (optional): Configuration for session refreshing.\n * - `isRefresherDisabled`: Whether the refresher is disabled.\n * - `pollingInterval`: The refresh interval in milliseconds\n * @returns The session ID to use for further communication with the device.\n */\n connect(args: ConnectUseCaseArgs): Promise<DeviceSessionId> {\n return this.container\n .get<ConnectUseCase>(discoveryTypes.ConnectUseCase)\n .execute(args);\n }\n\n /**\n * Disconnects to a discovered device.\n *\n * @param {DisconnectUseCaseArgs} args - The session ID to disconnect.\n */\n disconnect(args: DisconnectUseCaseArgs): Promise<void> {\n return this.container\n .get<DisconnectUseCase>(discoveryTypes.DisconnectUseCase)\n .execute(args);\n }\n\n /**\n * Sends an APDU command to a device through a device session.\n *\n * @param {SendApduUseCaseArgs} args - The device session ID and APDU command to send.\n */\n sendApdu(args: SendApduUseCaseArgs): Promise<ApduResponse> {\n return this.container\n .get<SendApduUseCase>(sendTypes.SendApduUseCase)\n .execute(args);\n }\n\n /**\n * Sends a command to a device through a device session.\n *\n * @param {SendCommandUseCaseArgs<Response, Args, ErrorCodes>} args - The device session ID, command, command error codes and command parameters to send.\n * @returns A promise resolving with the response from the command.\n */\n sendCommand<Response, Args, ErrorCodes>(\n args: SendCommandUseCaseArgs<Response, Args, ErrorCodes>,\n ): Promise<CommandResult<Response, ErrorCodes>> {\n return this.container\n .get<SendCommandUseCase>(commandTypes.SendCommandUseCase)\n .execute(args);\n }\n\n executeDeviceAction<\n Output,\n Input,\n Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n args: ExecuteDeviceActionUseCaseArgs<\n Output,\n Input,\n Error,\n IntermediateValue\n >,\n ): ExecuteDeviceActionReturnType<Output, Error, IntermediateValue> {\n return this.container\n .get<ExecuteDeviceActionUseCase>(\n deviceActionTypes.ExecuteDeviceActionUseCase,\n )\n .execute(args);\n }\n\n /**\n * Gets the connected from its device session ID.\n *\n * @param {GetConnectedDeviceUseCaseArgs} args - The device session ID.\n * @returns {ConnectedDevice} The connected device.\n */\n getConnectedDevice(args: GetConnectedDeviceUseCaseArgs): ConnectedDevice {\n return this.container\n .get<GetConnectedDeviceUseCase>(discoveryTypes.GetConnectedDeviceUseCase)\n .execute(args);\n }\n\n /**\n * Gets the device state of a session.\n *\n * @param {{ sessionId: DeviceSessionId }} args - The device session ID.\n * @returns {Observable<DeviceSessionState>} An observable of the session device state.\n */\n getDeviceSessionState(args: {\n sessionId: DeviceSessionId;\n }): Observable<DeviceSessionState> {\n return this.container\n .get<GetDeviceSessionStateUseCase>(\n deviceSessionTypes.GetDeviceSessionStateUseCase,\n )\n .execute(args);\n }\n\n /**\n * Close the Device Management kit.\n *\n */\n close() {\n return this.container\n .get<CloseSessionsUseCase>(deviceSessionTypes.CloseSessionsUseCase)\n .execute();\n }\n\n /**\n * Lists all connected devices.\n *\n * @returns {ConnectedDevice[]} The list of device sessions.\n */\n listConnectedDevices(): ConnectedDevice[] {\n return this.container\n .get<ListConnectedDevicesUseCase>(\n discoveryTypes.ListConnectedDevicesUseCase,\n )\n .execute();\n }\n\n /**\n * Listen to connected device.\n *\n * @returns {Observable<ConnectedDevice>} An observable of connected device.\n */\n listenToConnectedDevice(): Observable<ConnectedDevice> {\n return this.container\n .get<ListenToConnectedDeviceUseCase>(\n discoveryTypes.ListenToConnectedDeviceUseCase,\n )\n .execute();\n }\n\n /**\n * Disable the device session refresher.\n *\n * @param {DisableDeviceSessionRefresherUseCaseArgs} args - The device session ID and a string to identify the blocker.\n * @returns {() => void} A function to reenable the device session refresher.\n */\n disableDeviceSessionRefresher(args: {\n sessionId: DeviceSessionId;\n blockerId: string;\n }): () => void {\n return this.container\n .get<DisableDeviceSessionRefresherUseCase>(\n deviceSessionTypes.DisableDeviceSessionRefresherUseCase,\n )\n .execute(args);\n }\n /**\n * Sets the provider for the manager API.\n *\n * @param {number} provider - The provider to set.\n */\n setProvider(provider: number): void {\n return this.container\n .get<SetProviderUseCase>(managerApiTypes.SetProviderUseCase)\n .execute(provider);\n }\n\n /**\n * Returns the current provider value from the manager API data source.\n */\n getProvider(): number {\n return this.container\n .get<ManagerApiDataSource>(managerApiTypes.ManagerApiDataSource)\n .getProvider();\n }\n}\n"],
5
- "mappings": "AAGA,OAAS,gBAAAA,MAAoB,+BAsB7B,OAAS,eAAAC,MAAmB,kCAE5B,OAAS,sBAAAC,MAA0B,iDAGnC,OAAS,kBAAAC,MAAsB,wCAa/B,OAAS,mBAAAC,MAAuB,2CAEhC,OAAS,aAAAC,MAAiB,8BAE1B,OAAS,iBAAAC,MAA8C,eAMvD,OAAS,qBAAAC,MAAyB,uCAS3B,MAAMC,CAAoB,CACtB,UAET,YAAY,CACV,KAAAC,EACA,WAAAC,EACA,QAAAC,EACA,OAAAC,CACF,EAAiC,CAAC,EAAG,CAInC,KAAK,UAAYN,EAAc,CAC7B,KAAAG,EACA,WAAAC,EACA,QAAAC,EACA,OAAAC,CACF,CAAC,CACH,CAKA,YAA8B,CAC5B,OAAO,KAAK,UACT,IAA0BX,EAAY,oBAAoB,EAC1D,cAAc,CACnB,CAWA,iBACEY,EAC8B,CAC9B,OAAO,KAAK,UACT,IAA6BV,EAAe,uBAAuB,EACnE,QAAQU,CAAI,CACjB,CAKA,iBAAkB,CAChB,OAAO,KAAK,UACT,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C9D,YAAY,CACjB,CACF",
6
- "names": ["commandTypes", "configTypes", "deviceSessionTypes", "discoveryTypes", "managerApiTypes", "sendTypes", "makeContainer", "deviceActionTypes", "DeviceManagementKit", "stub", "transports", "loggers", "config", "args", "provider"]
4
+ "sourcesContent": ["import { type Container } from \"inversify\";\nimport { type Observable } from \"rxjs\";\n\nimport { commandTypes } from \"@api/command/di/commandTypes\";\nimport { type CommandResult } from \"@api/command/model/CommandResult\";\nimport {\n type SendCommandUseCase,\n type SendCommandUseCaseArgs,\n} from \"@api/command/use-case/SendCommandUseCase\";\nimport {\n type ExecuteDeviceActionUseCase,\n type ExecuteDeviceActionUseCaseArgs,\n} from \"@api/device-action/use-case/ExecuteDeviceActionUseCase\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport { type DeviceSessionState } from \"@api/device-session/DeviceSessionState\";\nimport { type DeviceSessionId } from \"@api/device-session/types\";\nimport { type ConnectedDevice } from \"@api/transport/model/ConnectedDevice\";\nimport {\n type ConnectUseCaseArgs,\n type DisconnectUseCaseArgs,\n type DiscoveredDevice,\n type GetConnectedDeviceUseCaseArgs,\n type SendApduUseCaseArgs,\n type StartDiscoveringUseCaseArgs,\n} from \"@api/types\";\nimport { configTypes } from \"@internal/config/di/configTypes\";\nimport { type GetDmkVersionUseCase } from \"@internal/config/use-case/GetDmkVersionUseCase\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport { type CloseSessionsUseCase } from \"@internal/device-session/use-case/CloseSessionsUseCase\";\nimport { type GetDeviceSessionStateUseCase } from \"@internal/device-session/use-case/GetDeviceSessionStateUseCase\";\nimport { discoveryTypes } from \"@internal/discovery/di/discoveryTypes\";\nimport { type ConnectUseCase } from \"@internal/discovery/use-case/ConnectUseCase\";\nimport { type DisconnectUseCase } from \"@internal/discovery/use-case/DisconnectUseCase\";\nimport { type GetConnectedDeviceUseCase } from \"@internal/discovery/use-case/GetConnectedDeviceUseCase\";\nimport { type ListConnectedDevicesUseCase } from \"@internal/discovery/use-case/ListConnectedDevicesUseCase\";\nimport {\n type ListenToAvailableDevicesUseCase,\n type ListenToAvailableDevicesUseCaseArgs,\n} from \"@internal/discovery/use-case/ListenToAvailableDevicesUseCase\";\nimport { type ListenToConnectedDeviceUseCase } from \"@internal/discovery/use-case/ListenToConnectedDeviceUseCase\";\nimport type { StartDiscoveringUseCase } from \"@internal/discovery/use-case/StartDiscoveringUseCase\";\nimport type { StopDiscoveringUseCase } from \"@internal/discovery/use-case/StopDiscoveringUseCase\";\nimport { type ManagerApiDataSource } from \"@internal/manager-api/data/ManagerApiDataSource\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport { type SetProviderUseCase } from \"@internal/manager-api/use-case/SetProviderUseCase\";\nimport { sendTypes } from \"@internal/send/di/sendTypes\";\nimport { type SendApduUseCase } from \"@internal/send/use-case/SendApduUseCase\";\nimport { transportDiTypes } from \"@internal/transport/di/transportDiTypes\";\nimport { type TransportService } from \"@internal/transport/service/TransportService\";\nimport { makeContainer, type MakeContainerProps } from \"@root/src/di\";\n\nimport {\n type DeviceActionIntermediateValue,\n type ExecuteDeviceActionReturnType,\n} from \"./device-action/DeviceAction\";\nimport { deviceActionTypes } from \"./device-action/di/deviceActionTypes\";\nimport { type DisableDeviceSessionRefresherUseCase } from \"./device-session/use-case/DisableDeviceSessionRefresher\";\nimport { type DmkError } from \"./Error\";\n\n/**\n * The main class to interact with the Device Management Kit.\n *\n * NB: do not instantiate this class directly, instead, use `LedgerDMKBuilder`.\n */\nexport class DeviceManagementKit {\n readonly container: Container;\n /** @internal */\n constructor({\n stub,\n transports,\n loggers,\n config,\n }: Partial<MakeContainerProps> = {}) {\n // NOTE: MakeContainerProps might not be the exact type here\n // For the init of the project this is sufficient, but we might need to\n // update the constructor arguments as we go (we might have more than just the container config)\n this.container = makeContainer({\n stub,\n transports,\n loggers,\n config,\n });\n }\n\n /**\n * Returns a promise resolving to the version of the SDK.\n */\n getVersion(): Promise<string> {\n return this.container\n .get<GetDmkVersionUseCase>(configTypes.GetDmkVersionUseCase)\n .getDmkVersion();\n }\n\n /**\n * Starts discovering devices connected.\n *\n * For the WeHID implementation, this use-case needs to be called as a result\n * of an user interaction (button \"click\" event for ex).\n *\n * @param {StartDiscoveringUseCaseArgs} args - The transport to use for discover, or undefined to discover from all transports.\n * @returns {Observable<DiscoveredDevice>} An observable of discovered devices.\n */\n startDiscovering(\n args: StartDiscoveringUseCaseArgs,\n ): Observable<DiscoveredDevice> {\n return this.container\n .get<StartDiscoveringUseCase>(discoveryTypes.StartDiscoveringUseCase)\n .execute(args);\n }\n\n /**\n * Stops discovering devices connected.\n */\n stopDiscovering() {\n return this.container\n .get<StopDiscoveringUseCase>(discoveryTypes.StopDiscoveringUseCase)\n .execute();\n }\n\n /**\n * Listen to list of known discovered devices (and later BLE).\n * @param {ListenToAvailableDevicesUseCaseArgs} args - The transport to use for discover, or undefined to discover from all transports.\n * @returns {Observable<DiscoveredDevice[]>} An observable of known discovered devices.\n */\n listenToAvailableDevices(\n args: ListenToAvailableDevicesUseCaseArgs,\n ): Observable<DiscoveredDevice[]> {\n return this.container\n .get<ListenToAvailableDevicesUseCase>(\n discoveryTypes.ListenToAvailableDevicesUseCase,\n )\n .execute(args);\n }\n\n /**\n * Connects to a device previously discovered with `DeviceManagementKit.startDiscovering`.\n * Creates a new device session which:\n * - Represents the connection to the device.\n * - Is terminated upon disconnection of the device.\n * - Exposes the device state through an observable (see `DeviceManagementKit.getDeviceSessionState`)\n * - Should be used for all subsequent communication with the device.\n *\n * @param {ConnectUseCaseArgs} args - The arguments for connecting to the device.\n * - `device`: The discovered device obtained from `StartDiscoveringUseCase`.\n * - `sessionRefresherOptions` (optional): Configuration for session refreshing.\n * - `isRefresherDisabled`: Whether the refresher is disabled.\n * - `pollingInterval`: The refresh interval in milliseconds\n * @returns The session ID to use for further communication with the device.\n */\n connect(args: ConnectUseCaseArgs): Promise<DeviceSessionId> {\n return this.container\n .get<ConnectUseCase>(discoveryTypes.ConnectUseCase)\n .execute(args);\n }\n\n /**\n * Disconnects to a discovered device.\n *\n * @param {DisconnectUseCaseArgs} args - The session ID to disconnect.\n */\n disconnect(args: DisconnectUseCaseArgs): Promise<void> {\n return this.container\n .get<DisconnectUseCase>(discoveryTypes.DisconnectUseCase)\n .execute(args);\n }\n\n /**\n * Sends an APDU command to a device through a device session.\n *\n * @param {SendApduUseCaseArgs} args - The device session ID and APDU command to send.\n */\n sendApdu(args: SendApduUseCaseArgs): Promise<ApduResponse> {\n return this.container\n .get<SendApduUseCase>(sendTypes.SendApduUseCase)\n .execute(args);\n }\n\n /**\n * Sends a command to a device through a device session.\n *\n * @param {SendCommandUseCaseArgs<Response, Args, ErrorCodes>} args - The device session ID, command, command error codes and command parameters to send.\n * @returns A promise resolving with the response from the command.\n */\n sendCommand<Response, Args, ErrorCodes>(\n args: SendCommandUseCaseArgs<Response, Args, ErrorCodes>,\n ): Promise<CommandResult<Response, ErrorCodes>> {\n return this.container\n .get<SendCommandUseCase>(commandTypes.SendCommandUseCase)\n .execute(args);\n }\n\n executeDeviceAction<\n Output,\n Input,\n Error extends DmkError,\n IntermediateValue extends DeviceActionIntermediateValue,\n >(\n args: ExecuteDeviceActionUseCaseArgs<\n Output,\n Input,\n Error,\n IntermediateValue\n >,\n ): ExecuteDeviceActionReturnType<Output, Error, IntermediateValue> {\n return this.container\n .get<ExecuteDeviceActionUseCase>(\n deviceActionTypes.ExecuteDeviceActionUseCase,\n )\n .execute(args);\n }\n\n /**\n * Gets the connected from its device session ID.\n *\n * @param {GetConnectedDeviceUseCaseArgs} args - The device session ID.\n * @returns {ConnectedDevice} The connected device.\n */\n getConnectedDevice(args: GetConnectedDeviceUseCaseArgs): ConnectedDevice {\n return this.container\n .get<GetConnectedDeviceUseCase>(discoveryTypes.GetConnectedDeviceUseCase)\n .execute(args);\n }\n\n /**\n * Gets the device state of a session.\n *\n * @param {{ sessionId: DeviceSessionId }} args - The device session ID.\n * @returns {Observable<DeviceSessionState>} An observable of the session device state.\n */\n getDeviceSessionState(args: {\n sessionId: DeviceSessionId;\n }): Observable<DeviceSessionState> {\n return this.container\n .get<GetDeviceSessionStateUseCase>(\n deviceSessionTypes.GetDeviceSessionStateUseCase,\n )\n .execute(args);\n }\n\n /**\n * Close the Device Management kit.\n *\n */\n close() {\n return this.container\n .get<CloseSessionsUseCase>(deviceSessionTypes.CloseSessionsUseCase)\n .execute();\n }\n\n /**\n * Lists all connected devices.\n *\n * @returns {ConnectedDevice[]} The list of device sessions.\n */\n listConnectedDevices(): ConnectedDevice[] {\n return this.container\n .get<ListConnectedDevicesUseCase>(\n discoveryTypes.ListConnectedDevicesUseCase,\n )\n .execute();\n }\n\n /**\n * Listen to connected device.\n *\n * @returns {Observable<ConnectedDevice>} An observable of connected device.\n */\n listenToConnectedDevice(): Observable<ConnectedDevice> {\n return this.container\n .get<ListenToConnectedDeviceUseCase>(\n discoveryTypes.ListenToConnectedDeviceUseCase,\n )\n .execute();\n }\n\n /**\n * Disable the device session refresher.\n *\n * @param {DisableDeviceSessionRefresherUseCaseArgs} args - The device session ID and a string to identify the blocker.\n * @returns {() => void} A function to reenable the device session refresher.\n */\n disableDeviceSessionRefresher(args: {\n sessionId: DeviceSessionId;\n blockerId: string;\n }): () => void {\n return this.container\n .get<DisableDeviceSessionRefresherUseCase>(\n deviceSessionTypes.DisableDeviceSessionRefresherUseCase,\n )\n .execute(args);\n }\n /**\n * Sets the provider for the manager API.\n *\n * @param {number} provider - The provider to set.\n */\n setProvider(provider: number): void {\n return this.container\n .get<SetProviderUseCase>(managerApiTypes.SetProviderUseCase)\n .execute(provider);\n }\n\n /**\n * Returns the current provider value from the manager API data source.\n */\n getProvider(): number {\n return this.container\n .get<ManagerApiDataSource>(managerApiTypes.ManagerApiDataSource)\n .getProvider();\n }\n\n /**\n * Check if the current environment is supported by any transport.\n */\n isEnvironmentSupported(): boolean {\n return this.container\n .get<TransportService>(transportDiTypes.TransportService)\n .getAllTransports()\n .some((transport) => trans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AAO,KAAK,UACT,IACCN,EAAkB,0BACpB,EACC,QAAQM,CAAI,CACjB,CAQA,mBAAmBA,EAAsD,CACvE,OAAO,KAAK,UACT,IAA+BX,EAAe,yBAAyB,EACvE,QAAQW,CAAI,CACjB,CAQA,sBAAsBA,EAEa,CACjC,OAAO,KAAK,UACT,IACCZ,EAAmB,4BACrB,EACC,QAAQY,CAAI,CACjB,CAMA,OAAQ,CACN,OAAO,KAAK,UACT,IAA0BZ,EAAmB,oBAAoB,EACjE,QAAQ,CACb,CAOA,sBAA0C,CACxC,OAAO,KAAK,UACT,IACCC,EAAe,2BACjB,EACC,QAAQ,CACb,CAOA,yBAAuD,CACrD,OAAO,KAAK,UACT,IACCA,EAAe,8BACjB,EACC,QAAQ,CACb,CAQA,8BAA8BW,EAGf,CACb,OAAO,KAAK,UACT,IACCZ,EAAmB,oCACrB,EACC,QAAQY,CAAI,CACjB,CAMA,YAAYC,EAAwB,CAClC,OAAO,KAAK,UACT,IAAwBX,EAAgB,kBAAkB,EAC1D,QAAQW,CAAQ,CACrB,CAKA,aAAsB,CACpB,OAAO,KAAK,UACT,IAA0BX,EAAgB,oBAAoB,EAC9D,YAAY,CACjB,CAKA,wBAAkC,CAChC,OAAO,KAAK,UACT,IAAsBE,EAAiB,gBAAgB,EACvD,iBAAiB,EACjB,KAAMU,GAAcA,EAAU,YAAY,CAAC,CAChD,CACF",
6
+ "names": ["commandTypes", "configTypes", "deviceSessionTypes", "discoveryTypes", "managerApiTypes", "sendTypes", "transportDiTypes", "makeContainer", "deviceActionTypes", "DeviceManagementKit", "stub", "transports", "loggers", "config", "args", "provider", "transport"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{StubLocalConfigDataSource as r}from"../internal/config/data/LocalConfigDataSource.stub";import{configTypes as c}from"../internal/config/di/configTypes";import{deviceSessionTypes as a}from"../internal/device-session/di/deviceSessionTypes";import{discoveryTypes as t}from"../internal/discovery/di/discoveryTypes";import{managerApiTypes as d}from"../internal/manager-api/di/managerApiTypes";import{sendTypes as m}from"../internal/send/di/sendTypes";import p from"../../package.json";import{StubUseCase as f}from"../../src/di.stub";import{commandTypes as l}from"./command/di/commandTypes";import{ConsoleLogger as u}from"./logger-subscriber/service/ConsoleLogger";import{DeviceManagementKit as o}from"./DeviceManagementKit";vi.mock("./logger-subscriber/service/ConsoleLogger");let e,i;describe("DeviceManagementKit",()=>{describe("clean",()=>{beforeEach(()=>{i=new u,e=new o({stub:!1,loggers:[i],config:{managerApiUrl:"http://fake.url",mockUrl:"http://fake-mock.url",webSocketUrl:"http://fake-websocket.url",firmwareDistributionSalt:"salt"}})}),it("should create an instance",()=>{expect(e).toBeDefined(),expect(e).toBeInstanceOf(o)}),it("should return a clean `version`",async()=>{expect(await e.getVersion()).toBe(p.version)}),it("should have startDiscovery method",()=>{expect(e.startDiscovering).toBeDefined()}),it("should have stopDiscovery method",()=>{expect(e.stopDiscovering).toBeDefined()}),it("should have connect method",()=>{expect(e.connect).toBeDefined()}),it("should have sendApdu method",()=>{expect(e.sendApdu).toBeDefined()}),it("should have getConnectedDevice method",()=>{expect(e.getConnectedDevice).toBeDefined()}),it("should have sendCommand method",()=>{expect(e.sendCommand).toBeDefined()}),it("should have listConnectedDevices method",()=>{expect(e.listConnectedDevices).toBeDefined()}),it("should have listenToConnectedDevice method",()=>{expect(e.listenToConnectedDevice).toBeDefined()}),it("should have disableDeviceSessionRefresher method",()=>{expect(e.disableDeviceSessionRefresher).toBeDefined()}),it("should have setProvider method",()=>{expect(e.setProvider).toBeDefined()})}),describe("stubbed",()=>{beforeEach(()=>{e=new o({stub:!0,loggers:[],config:{managerApiUrl:"http://fake.url",mockUrl:"http://fake-mock.url",webSocketUrl:"http://fake-websocket.url",firmwareDistributionSalt:"salt"}})}),it("should create a stubbed dmk",()=>{expect(e).toBeDefined(),expect(e).toBeInstanceOf(o)}),it("should return a stubbed config",()=>{expect(e.container.get(c.LocalConfigDataSource)).toBeInstanceOf(r)}),it("should return a stubbed version",async()=>{expect(await e.getVersion()).toBe("0.0.0-stub.1")}),it.each([[t.StartDiscoveringUseCase],[t.StopDiscoveringUseCase],[t.ConnectUseCase],[m.SendApduUseCase],[l.SendCommandUseCase],[t.GetConnectedDeviceUseCase],[t.DisconnectUseCase],[a.GetDeviceSessionStateUseCase],[t.ListConnectedDevicesUseCase],[t.ListenToConnectedDeviceUseCase],[d.SetProviderUseCase]])("should have %s use case",n=>{const s=e.container.get(n);expect(s).toBeInstanceOf(f),expect(s.execute()).toBe("stub")})})});
1
+ import{StubLocalConfigDataSource as c}from"../internal/config/data/LocalConfigDataSource.stub";import{configTypes as p}from"../internal/config/di/configTypes";import{deviceSessionTypes as d}from"../internal/device-session/di/deviceSessionTypes";import{discoveryTypes as n}from"../internal/discovery/di/discoveryTypes";import{managerApiTypes as l}from"../internal/manager-api/di/managerApiTypes";import{sendTypes as u}from"../internal/send/di/sendTypes";import m from"../../package.json";import{StubUseCase as v}from"../../src/di.stub";import{commandTypes as f}from"./command/di/commandTypes";import{ConsoleLogger as h}from"./logger-subscriber/service/ConsoleLogger";import{DeviceManagementKit as r}from"./DeviceManagementKit";vi.mock("./logger-subscriber/service/ConsoleLogger");let e,a;describe("DeviceManagementKit",()=>{describe("clean",()=>{beforeEach(()=>{a=new h,e=new r({stub:!1,loggers:[a],config:{managerApiUrl:"http://fake.url",mockUrl:"http://fake-mock.url",webSocketUrl:"http://fake-websocket.url",firmwareDistributionSalt:"salt"}})}),it("should create an instance",()=>{expect(e).toBeDefined(),expect(e).toBeInstanceOf(r)}),it("should return a clean `version`",async()=>{expect(await e.getVersion()).toBe(m.version)}),it("should have startDiscovery method",()=>{expect(e.startDiscovering).toBeDefined()}),it("should have stopDiscovery method",()=>{expect(e.stopDiscovering).toBeDefined()}),it("should have connect method",()=>{expect(e.connect).toBeDefined()}),it("should have sendApdu method",()=>{expect(e.sendApdu).toBeDefined()}),it("should have getConnectedDevice method",()=>{expect(e.getConnectedDevice).toBeDefined()}),it("should have sendCommand method",()=>{expect(e.sendCommand).toBeDefined()}),it("should have listConnectedDevices method",()=>{expect(e.listConnectedDevices).toBeDefined()}),it("should have listenToConnectedDevice method",()=>{expect(e.listenToConnectedDevice).toBeDefined()}),it("should have disableDeviceSessionRefresher method",()=>{expect(e.disableDeviceSessionRefresher).toBeDefined()}),it("should have setProvider method",()=>{expect(e.setProvider).toBeDefined()}),it("should have isEnvironmentSupported method",()=>{expect(e.isEnvironmentSupported).toBeDefined()}),describe("isEnvironmentSupported",()=>{it("should return true when at least one transport is supported",()=>{const t={isSupported:vi.fn().mockReturnValue(!1)},o={isSupported:vi.fn().mockReturnValue(!0)},s={getAllTransports:vi.fn().mockReturnValue([t,o])};vi.spyOn(e.container,"get").mockReturnValue(s);const i=e.isEnvironmentSupported();expect(i).toBe(!0),expect(s.getAllTransports).toHaveBeenCalled(),expect(t.isSupported).toHaveBeenCalled(),expect(o.isSupported).toHaveBeenCalled()}),it("should return false when no transports are supported",()=>{const t={isSupported:vi.fn().mockReturnValue(!1)},o={isSupported:vi.fn().mockReturnValue(!1)},s={getAllTransports:vi.fn().mockReturnValue([t,o])};vi.spyOn(e.container,"get").mockReturnValue(s);const i=e.isEnvironmentSupported();expect(i).toBe(!1),expect(s.getAllTransports).toHaveBeenCalled(),expect(t.isSupported).toHaveBeenCalled(),expect(o.isSupported).toHaveBeenCalled()}),it("should return false when no transports are available",()=>{const t={getAllTransports:vi.fn().mockReturnValue([])};vi.spyOn(e.container,"get").mockReturnValue(t);const o=e.isEnvironmentSupported();expect(o).toBe(!1),expect(t.getAllTransports).toHaveBeenCalled()})})}),describe("stubbed",()=>{beforeEach(()=>{e=new r({stub:!0,loggers:[],config:{managerApiUrl:"http://fake.url",mockUrl:"http://fake-mock.url",webSocketUrl:"http://fake-websocket.url",firmwareDistributionSalt:"salt"}})}),it("should create a stubbed dmk",()=>{expect(e).toBeDefined(),expect(e).toBeInstanceOf(r)}),it("should return a stubbed config",()=>{expect(e.container.get(p.LocalConfigDataSource)).toBeInstanceOf(c)}),it("should return a stubbed version",async()=>{expect(await e.getVersion()).toBe("0.0.0-stub.1")}),it.each([[n.StartDiscoveringUseCase],[n.StopDiscoveringUseCase],[n.ConnectUseCase],[u.SendApduUseCase],[f.SendCommandUseCase],[n.GetConnectedDeviceUseCase],[n.DisconnectUseCase],[d.GetDeviceSessionStateUseCase],[n.ListConnectedDevicesUseCase],[n.ListenToConnectedDeviceUseCase],[l.SetProviderUseCase]])("should have %s use case",t=>{const o=e.container.get(t);expect(o).toBeInstanceOf(v),expect(o.execute()).toBe("stub")})})});
2
2
  //# sourceMappingURL=DeviceManagementKit.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/DeviceManagementKit.test.ts"],
4
- "sourcesContent": ["import { type ServiceIdentifier } from \"inversify\";\n\nimport { type LocalConfigDataSource } from \"@internal/config/data/ConfigDataSource\";\nimport { StubLocalConfigDataSource } from \"@internal/config/data/LocalConfigDataSource.stub\";\nimport { configTypes } from \"@internal/config/di/configTypes\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport { discoveryTypes } from \"@internal/discovery/di/discoveryTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport { sendTypes } from \"@internal/send/di/sendTypes\";\nimport pkg from \"@root/package.json\";\nimport { StubUseCase } from \"@root/src/di.stub\";\n\nimport { commandTypes } from \"./command/di/commandTypes\";\nimport { ConsoleLogger } from \"./logger-subscriber/service/ConsoleLogger\";\nimport { DeviceManagementKit } from \"./DeviceManagementKit\";\nimport { type DmkConfig } from \"./DmkConfig\";\n\nvi.mock(\"./logger-subscriber/service/ConsoleLogger\");\n\nlet dmk: DeviceManagementKit;\nlet logger: ConsoleLogger;\ndescribe(\"DeviceManagementKit\", () => {\n describe(\"clean\", () => {\n beforeEach(() => {\n logger = new ConsoleLogger();\n dmk = new DeviceManagementKit({\n stub: false,\n loggers: [logger],\n config: {\n managerApiUrl: \"http://fake.url\",\n mockUrl: \"http://fake-mock.url\",\n webSocketUrl: \"http://fake-websocket.url\",\n firmwareDistributionSalt: \"salt\",\n } as DmkConfig,\n });\n });\n\n it(\"should create an instance\", () => {\n expect(dmk).toBeDefined();\n expect(dmk).toBeInstanceOf(DeviceManagementKit);\n });\n\n it(\"should return a clean `version`\", async () => {\n expect(await dmk.getVersion()).toBe(pkg.version);\n });\n\n it(\"should have startDiscovery method\", () => {\n expect(dmk.startDiscovering).toBeDefined();\n });\n\n it(\"should have stopDiscovery method\", () => {\n expect(dmk.stopDiscovering).toBeDefined();\n });\n\n it(\"should have connect method\", () => {\n expect(dmk.connect).toBeDefined();\n });\n\n it(\"should have sendApdu method\", () => {\n expect(dmk.sendApdu).toBeDefined();\n });\n\n it(\"should have getConnectedDevice method\", () => {\n expect(dmk.getConnectedDevice).toBeDefined();\n });\n\n it(\"should have sendCommand method\", () => {\n expect(dmk.sendCommand).toBeDefined();\n });\n\n it(\"should have listConnectedDevices method\", () => {\n expect(dmk.listConnectedDevices).toBeDefined();\n });\n\n it(\"should have listenToConnectedDevice method\", () => {\n expect(dmk.listenToConnectedDevice).toBeDefined();\n });\n\n it(\"should have disableDeviceSessionRefresher method\", () => {\n expect(dmk.disableDeviceSessionRefresher).toBeDefined();\n });\n\n it(\"should have setProvider method\", () => {\n expect(dmk.setProvider).toBeDefined();\n });\n });\n\n describe(\"stubbed\", () => {\n beforeEach(() => {\n dmk = new DeviceManagementKit({\n stub: true,\n loggers: [],\n config: {\n managerApiUrl: \"http://fake.url\",\n mockUrl: \"http://fake-mock.url\",\n webSocketUrl: \"http://fake-websocket.url\",\n firmwareDistributionSalt: \"salt\",\n } as DmkConfig,\n });\n });\n\n it(\"should create a stubbed dmk\", () => {\n expect(dmk).toBeDefined();\n expect(dmk).toBeInstanceOf(DeviceManagementKit);\n });\n\n it(\"should return a stubbed config\", () => {\n expect(\n dmk.container.get<LocalConfigDataSource>(\n configTypes.LocalConfigDataSource,\n ),\n ).toBeInstanceOf(StubLocalConfigDataSource);\n });\n\n it(\"should return a stubbed version\", async () => {\n expect(await dmk.getVersion()).toBe(\"0.0.0-stub.1\");\n });\n\n it.each([\n [discoveryTypes.StartDiscoveringUseCase],\n [discoveryTypes.StopDiscoveringUseCase],\n [discoveryTypes.ConnectUseCase],\n [sendTypes.SendApduUseCase],\n [commandTypes.SendCommandUseCase],\n [discoveryTypes.GetConnectedDeviceUseCase],\n [discoveryTypes.DisconnectUseCase],\n [deviceSessionTypes.GetDeviceSessionStateUseCase],\n [discoveryTypes.ListConnectedDevicesUseCase],\n [discoveryTypes.ListenToConnectedDeviceUseCase],\n [managerApiTypes.SetProviderUseCase],\n ])(\n \"should have %s use case\",\n (diSymbol: ServiceIdentifier<StubUseCase>) => {\n const uc = dmk.container.get<StubUseCase>(diSymbol);\n expect(uc).toBeInstanceOf(StubUseCase);\n expect(uc.execute()).toBe(\"stub\");\n },\n );\n });\n});\n"],
5
- "mappings": "AAGA,OAAS,6BAAAA,MAAiC,mDAC1C,OAAS,eAAAC,MAAmB,kCAC5B,OAAS,sBAAAC,MAA0B,iDACnC,OAAS,kBAAAC,MAAsB,wCAC/B,OAAS,mBAAAC,MAAuB,2CAChC,OAAS,aAAAC,MAAiB,8BAC1B,OAAOC,MAAS,qBAChB,OAAS,eAAAC,MAAmB,oBAE5B,OAAS,gBAAAC,MAAoB,4BAC7B,OAAS,iBAAAC,MAAqB,4CAC9B,OAAS,uBAAAC,MAA2B,wBAGpC,GAAG,KAAK,2CAA2C,EAEnD,IAAIC,EACAC,EACJ,SAAS,sBAAuB,IAAM,CACpC,SAAS,QAAS,IAAM,CACtB,WAAW,IAAM,CACfA,EAAS,IAAIH,EACbE,EAAM,IAAID,EAAoB,CAC5B,KAAM,GACN,QAAS,CAACE,CAAM,EAChB,OAAQ,CACN,cAAe,kBACf,QAAS,uBACT,aAAc,4BACd,yBAA0B,MAC5B,CACF,CAAC,CACH,CAAC,EAED,GAAG,4BAA6B,IAAM,CACpC,OAAOD,CAAG,EAAE,YAAY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AAG,iCAAkC,IAAM,CACzC,OACEC,EAAI,UAAU,IACZV,EAAY,qBACd,CACF,EAAE,eAAeD,CAAyB,CAC5C,CAAC,EAED,GAAG,kCAAmC,SAAY,CAChD,OAAO,MAAMW,EAAI,WAAW,CAAC,EAAE,KAAK,cAAc,CACpD,CAAC,EAED,GAAG,KAAK,CACN,CAACR,EAAe,uBAAuB,EACvC,CAACA,EAAe,sBAAsB,EACtC,CAACA,EAAe,cAAc,EAC9B,CAACE,EAAU,eAAe,EAC1B,CAACG,EAAa,kBAAkB,EAChC,CAACL,EAAe,yBAAyB,EACzC,CAACA,EAAe,iBAAiB,EACjC,CAACD,EAAmB,4BAA4B,EAChD,CAACC,EAAe,2BAA2B,EAC3C,CAACA,EAAe,8BAA8B,EAC9C,CAACC,EAAgB,kBAAkB,CACrC,CAAC,EACC,0BACCS,GAA6C,CAC5C,MAAMC,EAAKH,EAAI,UAAU,IAAiBE,CAAQ,EAClD,OAAOC,CAAE,EAAE,eAAeP,CAAW,EACrC,OAAOO,EAAG,QAAQ,CAAC,EAAE,KAAK,MAAM,CAClC,CACF,CACF,CAAC,CACH,CAAC",
6
- "names": ["StubLocalConfigDataSource", "configTypes", "deviceSessionTypes", "discoveryTypes", "managerApiTypes", "sendTypes", "pkg", "StubUseCase", "commandTypes", "ConsoleLogger", "DeviceManagementKit", "dmk", "logger", "diSymbol", "uc"]
4
+ "sourcesContent": ["import { type ServiceIdentifier } from \"inversify\";\n\nimport { type LocalConfigDataSource } from \"@internal/config/data/ConfigDataSource\";\nimport { StubLocalConfigDataSource } from \"@internal/config/data/LocalConfigDataSource.stub\";\nimport { configTypes } from \"@internal/config/di/configTypes\";\nimport { deviceSessionTypes } from \"@internal/device-session/di/deviceSessionTypes\";\nimport { discoveryTypes } from \"@internal/discovery/di/discoveryTypes\";\nimport { managerApiTypes } from \"@internal/manager-api/di/managerApiTypes\";\nimport { sendTypes } from \"@internal/send/di/sendTypes\";\nimport pkg from \"@root/package.json\";\nimport { StubUseCase } from \"@root/src/di.stub\";\n\nimport { commandTypes } from \"./command/di/commandTypes\";\nimport { ConsoleLogger } from \"./logger-subscriber/service/ConsoleLogger\";\nimport { DeviceManagementKit } from \"./DeviceManagementKit\";\nimport { type DmkConfig } from \"./DmkConfig\";\n\nvi.mock(\"./logger-subscriber/service/ConsoleLogger\");\n\nlet dmk: DeviceManagementKit;\nlet logger: ConsoleLogger;\ndescribe(\"DeviceManagementKit\", () => {\n describe(\"clean\", () => {\n beforeEach(() => {\n logger = new ConsoleLogger();\n dmk = new DeviceManagementKit({\n stub: false,\n loggers: [logger],\n config: {\n managerApiUrl: \"http://fake.url\",\n mockUrl: \"http://fake-mock.url\",\n webSocketUrl: \"http://fake-websocket.url\",\n firmwareDistributionSalt: \"salt\",\n } as DmkConfig,\n });\n });\n\n it(\"should create an instance\", () => {\n expect(dmk).toBeDefined();\n expect(dmk).toBeInstanceOf(DeviceManagementKit);\n });\n\n it(\"should return a clean `version`\", async () => {\n expect(await dmk.getVersion()).toBe(pkg.version);\n });\n\n it(\"should have startDiscovery method\", () => {\n expect(dmk.startDiscovering).toBeDefined();\n });\n\n it(\"should have stopDiscovery method\", () => {\n expect(dmk.stopDiscovering).toBeDefined();\n });\n\n it(\"should have connect method\", () => {\n expect(dmk.connect).toBeDefined();\n });\n\n it(\"should have sendApdu method\", () => {\n expect(dmk.sendApdu).toBeDefined();\n });\n\n it(\"should have getConnectedDevice method\", () => {\n expect(dmk.getConnectedDevice).toBeDefined();\n });\n\n it(\"should have sendCommand method\", () => {\n expect(dmk.sendCommand).toBeDefined();\n });\n\n it(\"should have listConnectedDevices method\", () => {\n expect(dmk.listConnectedDevices).toBeDefined();\n });\n\n it(\"should have listenToConnectedDevice method\", () => {\n expect(dmk.listenToConnectedDevice).toBeDefined();\n });\n\n it(\"should have disableDeviceSessionRefresher method\", () => {\n expect(dmk.disableDeviceSessionRefresher).toBeDefined();\n });\n\n it(\"should have setProvider method\", () => {\n expect(dmk.setProvider).toBeDefined();\n });\n\n it(\"should have isEnvironmentSupported method\", () => {\n expect(dmk.isEnvironmentSupported).toBeDefined();\n });\n\n describe(\"isEnvironmentSupported\", () => {\n it(\"should return true when at least one transport is supported\", () => {\n // Mock the TransportService to return transports where at least one is supported\n const mockTransport1 = {\n isSupported: vi.fn().mockReturnValue(false),\n };\n const mockTransport2 = {\n isSupported: vi.fn().mockReturnValue(true),\n };\n const mockTransportService = {\n getAllTransports: vi\n .fn()\n .mockReturnValue([mockTransport1, mockTransport2]),\n };\n\n // Mock the container to return our mock TransportService\n vi.spyOn(dmk.container, \"get\").mockReturnValue(mockTransportService);\n\n const result = dmk.isEnvironmentSupported();\n\n expect(result).toBe(true);\n expect(mockTransportService.getAllTransports).toHaveBeenCalled();\n expect(mockTransport1.isSupported).toHaveBeenCalled();\n expect(mockTransport2.isSupported).toHaveBeenCalled();\n });\n\n it(\"should return false when no transports are supported\", () => {\n // Mock the TransportService to return transports where none are supported\n const mockTransport1 = {\n isSupported: vi.fn().mockReturnValue(false),\n };\n const mockTransport2 = {\n isSupported: vi.fn().mockReturnValue(false),\n };\n const mockTransportService = {\n getAllTransports: vi\n .fn()\n .mockReturnValue([mockTransport1, mockTransport2]),\n };\n\n // Mock the container to return our mock TransportService\n vi.spyOn(dmk.container, \"get\").mockReturnValue(mockTransportService);\n\n const result = dmk.isEnvironmentSupported();\n\n expect(result).toBe(false);\n expect(mockTransportService.getAllTransports).toHaveBeenCalled();\n expect(mockTransport1.isSupported).toHaveBeenCalled();\n expect(mockTransport2.isSupported).toHaveBeenCalled();\n });\n\n it(\"should return false when no transports are available\", () => {\n // Mock the TransportService to return an empty array\n const mockTransportService = {\n getAllTransports: vi.fn().mockReturnValue([]),\n };\n\n // Mock the container to return our mock TransportService\n vi.spyOn(dmk.container, \"get\").mockReturnValue(mockTransportService);\n\n const result = dmk.isEnvironmentSupported();\n\n expect(result).toBe(false);\n expect(mockTransportService.getAllTransports).toHaveBeenCalled();\n });\n });\n });\n\n describe(\"stubbed\", () => {\n beforeEach(() => {\n dmk = new DeviceManagementKit({\n stub: true,\n loggers: [],\n config: {\n managerApiUrl: \"http://fake.url\",\n mockUrl: \"http://fake-mock.url\",\n webSocketUrl: \"http://fake-websocket.url\",\n firmwareDistributionSalt: \"salt\",\n } as DmkConfig,\n });\n });\n\n it(\"should create a stubbed dmk\", () => {\n expect(dmk).toBeDefined();\n expect(dmk).toBeInstanceOf(DeviceManagementKit);\n });\n\n it(\"should return a stubbed config\", () => {\n expect(\n dmk.container.get<LocalConfigDataSource>(\n configTypes.LocalConfigDataSource,\n ),\n ).toBeInstanceOf(StubLocalConfigDataSource);\n });\n\n it(\"should return a stubbed version\", async () => {\n expect(await dmk.getVersion()).toBe(\"0.0.0-stub.1\");\n });\n\n it.each([\n [discoveryTypes.StartDiscoveringUseCase],\n [discoveryTypes.StopDiscoveringUseCase],\n [discoveryTypes.ConnectUseCase],\n [sendTypes.SendApduUseCase],\n [commandTypes.SendCommandUseCase],\n [discoveryTypes.GetConnectedDeviceUseCase],\n [discoveryTypes.DisconnectUseCase],\n [deviceSessionTypes.GetDeviceSessionStateUseCase],\n [discoveryTypes.ListConnectedDevicesUseCase],\n [discoveryTypes.ListenToConnectedDeviceUseCase],\n [managerApiTypes.SetProviderUseCase],\n ])(\n \"should have %s use case\",\n (diSymbol: ServiceIdentifier<StubUseCase>) => {\n const uc = dmk.container.get<StubUseCase>(diSymbol);\n expect(uc).toBeInstanceOf(StubUseCase);\n expect(uc.execute()).toBe(\"stub\");\n },\n );\n });\n});\n"],
5
+ "mappings": "AAGA,OAAS,6BAAAA,MAAiC,mDAC1C,OAAS,eAAAC,MAAmB,kCAC5B,OAAS,sBAAAC,MAA0B,iDACnC,OAAS,kBAAAC,MAAsB,wCAC/B,OAAS,mBAAAC,MAAuB,2CAChC,OAAS,aAAAC,MAAiB,8BAC1B,OAAOC,MAAS,qBAChB,OAAS,eAAAC,MAAmB,oBAE5B,OAAS,gBAAAC,MAAoB,4BAC7B,OAAS,iBAAAC,MAAq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AG,QAAQ,CAAC,EAAE,KAAK,MAAM,CAClC,CACF,CACF,CAAC,CACH,CAAC",
6
+ "names": ["StubLocalConfigDataSource", "configTypes", "deviceSessionTypes", "discoveryTypes", "managerApiTypes", "sendTypes", "pkg", "StubUseCase", "commandTypes", "ConsoleLogger", "DeviceManagementKit", "dmk", "logger", "mockTransport1", "mockTransport2", "mockTransportService", "result", "diSymbol", "uc"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{hexaStringToBuffer as h}from"../../utils/HexaString";import{DataOverflowError as o,HexaStringEncodeError as B,ValueOverflowError as u}from"./AppBuilderError";const b=4294967295;class m{constructor(r=b){this.maxPayloadSize=r}data=new Uint8Array;errors=[];build=()=>this.data;tryBuild=()=>this.hasErrors()?void 0:this.data;add8BitUIntToData=r=>this.addNumberToData(r,8n,!1,!1);add16BitUIntToData=(r,t=!0)=>this.addNumberToData(r,16n,!1,t);add32BitUIntToData=(r,t=!0)=>this.addNumberToData(r,32n,!1,t);add64BitUIntToData=(r,t=!0)=>this.addNumberToData(r,64n,!1,t);add128BitUIntToData=(r,t=!0)=>this.addNumberToData(r,128n,!1,t);add256BitUIntToData=(r,t=!0)=>this.addNumberToData(r,256n,!1,t);add16BitIntToData=(r,t=!0)=>this.addNumberToData(r,16n,!0,t);add32BitIntToData=(r,t=!0)=>this.addNumberToData(r,32n,!0,t);add64BitIntToData=(r,t=!0)=>this.addNumberToData(r,64n,!0,t);add128BitIntToData=(r,t=!0)=>this.addNumberToData(r,128n,!0,t);add256BitIntToData=(r,t=!0)=>this.addNumberToData(r,256n,!0,t);addBufferToData=r=>this.hasEnoughLengthRemaining(r)?(this.data=Uint8Array.from([...this.data,...r]),this):(this.errors.push(new o(r.toString())),this);addHexaStringToData=r=>{const t=h(r);return t===null||t.length===0?(this.errors.push(new B(r)),this):(this.addBufferToData(t),this)};addAsciiStringToData=r=>{const t=new TextEncoder().encode(r);return this.addBufferToData(t),this};encodeInLVFromHexa=r=>{const t=h(r);return t===null||t.length===0?(this.errors.push(new B(r)),this):this.hasEnoughLengthRemaining(t,!0)?(this.add8BitUIntToData(t.length),this.addBufferToData(t),this):(this.errors.push(new o(r)),this)};encodeInLVFromBuffer=r=>this.hasEnoughLengthRemaining(r,!0)?(this.add8BitUIntToData(r.length),this.addBufferToData(r),this):(this.errors.push(new o(r.toString())),this);encodeInLVFromAscii=r=>this.hasEnoughLengthRemaining(r,!0)?(this.add8BitUIntToData(r.length),this.addAsciiStringToData(r),this):(this.errors.push(new o(r)),this);encodeInTLVFromHexa=(r,t)=>(this.add8BitUIntToData(r),this.encodeInLVFromHexa(t));encodeInTLVFromBuffer=(r,t)=>(this.add8BitUIntToData(r),this.encodeInLVFromBuffer(t));encodeInTLVFromUInt64=(r,t,a=!0)=>(this.add8BitUIntToData(r),this.add8BitUIntToData(8),this.add64BitUIntToData(t,a));getAvailablePayloadLength=()=>this.maxPayloadSize-this.data.length;getErrors=()=>this.errors;hasErrors=()=>this.errors.length!==0;hasEnoughLengthRemaining=(r,t=!1)=>this.data.length+r.length+(t?1:0)<=this.maxPayloadSize;addNumberToData(r,t,a,e){let n=this.checkBoundsAndConvert(r,t,a);if(n===void 0)return this;const d=Number(t)/8,s=new Uint8Array(d);if(e)for(let i=d-1;i>=0;i--)s[i]=Number(n&0xffn),n>>=8n;else for(let i=0;i<d;i++)s[i]=Number(n&0xffn),n>>=8n;return this.addBufferToData(s)}checkBoundsAndConvert(r,t,a){if(typeof r=="number"){if(!Number.isInteger(r)||r>Number.MAX_SAFE_INTEGER){this.errors.push(new u(r.toString()));return}r=BigInt(r)}if(a){const e=1n<<t-1n;if(r>=e||r<-e){this.errors.push(new u(r.toString(),e-1n));return}if(r<0n){const n=(1n<<t)-1n;r=-r,r=(~r&n)+1n}}else{const e=1n<<t;if(r<0||r>=e){this.errors.push(new u(r.toString(),e-1n));return}}return r}}export{m as ByteArrayBuilder};
1
+ import{hexaStringToBuffer as h}from"../../utils/HexaString";import{DataOverflowError as o,HexaStringEncodeError as B,ValueOverflowError as s}from"./AppBuilderError";const b=4294967295;class g{constructor(t=b){this.maxPayloadSize=t}data=new Uint8Array;errors=[];build=()=>this.data;tryBuild=()=>this.hasErrors()?void 0:this.data;add8BitUIntToData=t=>this.addNumberToData(t,8n,!1,!1);add16BitUIntToData=(t,r=!0)=>this.addNumberToData(t,16n,!1,r);add32BitUIntToData=(t,r=!0)=>this.addNumberToData(t,32n,!1,r);add64BitUIntToData=(t,r=!0)=>this.addNumberToData(t,64n,!1,r);add128BitUIntToData=(t,r=!0)=>this.addNumberToData(t,128n,!1,r);add256BitUIntToData=(t,r=!0)=>this.addNumberToData(t,256n,!1,r);add16BitIntToData=(t,r=!0)=>this.addNumberToData(t,16n,!0,r);add32BitIntToData=(t,r=!0)=>this.addNumberToData(t,32n,!0,r);add64BitIntToData=(t,r=!0)=>this.addNumberToData(t,64n,!0,r);add128BitIntToData=(t,r=!0)=>this.addNumberToData(t,128n,!0,r);add256BitIntToData=(t,r=!0)=>this.addNumberToData(t,256n,!0,r);addBufferToData=t=>this.hasEnoughLengthRemaining(t)?(this.data=Uint8Array.from([...this.data,...t]),this):(this.errors.push(new o(t.toString())),this);addHexaStringToData=t=>{const r=h(t);return r===null||r.length===0?(this.errors.push(new B(t)),this):(this.addBufferToData(r),this)};addAsciiStringToData=t=>{const r=new TextEncoder().encode(t);return this.addBufferToData(r),this};encodeInLVFromHexa=t=>{const r=h(t);return r===null||r.length===0?(this.errors.push(new B(t)),this):this.hasEnoughLengthRemaining(r,!0)?(this.add8BitUIntToData(r.length),this.addBufferToData(r),this):(this.errors.push(new o(t)),this)};encodeInLVFromBuffer=t=>this.hasEnoughLengthRemaining(t,!0)?(this.add8BitUIntToData(t.length),this.addBufferToData(t),this):(this.errors.push(new o(t.toString())),this);encodeInLVFromAscii=t=>this.hasEnoughLengthRemaining(t,!0)?(this.add8BitUIntToData(t.length),this.addAsciiStringToData(t),this):(this.errors.push(new o(t)),this);encodeInTLVFromAscii=(t,r)=>(this.add8BitUIntToData(t),this.encodeInLVFromAscii(r));encodeInTLVFromHexa=(t,r)=>(this.add8BitUIntToData(t),this.encodeInLVFromHexa(r));encodeInTLVFromBuffer=(t,r)=>(this.add8BitUIntToData(t),this.encodeInLVFromBuffer(r));encodeInTLVFromUInt8=(t,r)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(1),this.add8BitUIntToData(r));encodeInTLVFromUInt16=(t,r,e=!0)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(2),this.add16BitUIntToData(r,e));encodeInTLVFromUInt32=(t,r,e=!0)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(4),this.add32BitUIntToData(r,e));encodeInTLVFromUInt64=(t,r,e=!0)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(8),this.add64BitUIntToData(r,e));getAvailablePayloadLength=()=>this.maxPayloadSize-this.data.length;getErrors=()=>this.errors;hasErrors=()=>this.errors.length!==0;hasEnoughLengthRemaining=(t,r=!1)=>this.data.length+t.length+(r?1:0)<=this.maxPayloadSize;addNumberToData(t,r,e,n){let i=this.checkBoundsAndConvert(t,r,e);if(i===void 0)return this;const d=Number(r)/8,u=new Uint8Array(d);if(n)for(let a=d-1;a>=0;a--)u[a]=Number(i&0xffn),i>>=8n;else for(let a=0;a<d;a++)u[a]=Number(i&0xffn),i>>=8n;return this.addBufferToData(u)}checkBoundsAndConvert(t,r,e){if(typeof t=="number"){if(!Number.isInteger(t)||t>Number.MAX_SAFE_INTEGER){this.errors.push(new s(t.toString()));return}t=BigInt(t)}if(e){const n=1n<<r-1n;if(t>=n||t<-n){this.errors.push(new s(t.toString(),n-1n));return}if(t<0n){const i=(1n<<r)-1n;t=-t,t=(~t&i)+1n}}else{const n=1n<<r;if(t<0||t>=n){this.errors.push(new s(t.toString(),n-1n));return}}return t}}export{g as ByteArrayBuilder};
2
2
  //# sourceMappingURL=ByteArrayBuilder.js.map