@ledgerhq/device-management-kit 0.0.0-develop-20250819001259 → 0.0.0-develop-20250822001217

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 (37) hide show
  1. package/lib/cjs/package.json +1 -1
  2. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  3. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.js.map +2 -2
  4. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  5. package/lib/cjs/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  6. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  7. package/lib/cjs/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +2 -2
  8. package/lib/cjs/src/api/utils/HexaString.js +1 -1
  9. package/lib/cjs/src/api/utils/HexaString.js.map +3 -3
  10. package/lib/cjs/src/api/utils/HexaString.test.js +1 -1
  11. package/lib/cjs/src/api/utils/HexaString.test.js.map +2 -2
  12. package/lib/cjs/src/internal/device-session/service/DefaultApduReceiverService.js +1 -1
  13. package/lib/cjs/src/internal/device-session/service/DefaultApduReceiverService.js.map +2 -2
  14. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  15. package/lib/cjs/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  16. package/lib/esm/package.json +1 -1
  17. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js +1 -1
  18. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.js.map +3 -3
  19. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js +1 -1
  20. package/lib/esm/src/api/apdu/utils/ByteArrayBuilder.test.js.map +2 -2
  21. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js +1 -1
  22. package/lib/esm/src/api/secure-channel/task/ConnectToSecureChannelTask.js.map +2 -2
  23. package/lib/esm/src/api/utils/HexaString.js +1 -1
  24. package/lib/esm/src/api/utils/HexaString.js.map +3 -3
  25. package/lib/esm/src/api/utils/HexaString.test.js +1 -1
  26. package/lib/esm/src/api/utils/HexaString.test.js.map +2 -2
  27. package/lib/esm/src/internal/device-session/service/DefaultApduReceiverService.js +1 -1
  28. package/lib/esm/src/internal/device-session/service/DefaultApduReceiverService.js.map +2 -2
  29. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js +1 -1
  30. package/lib/esm/src/internal/device-session/service/DefaultApduSenderService.js.map +2 -2
  31. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts +38 -0
  32. package/lib/types/src/api/apdu/utils/ByteArrayBuilder.d.ts.map +1 -1
  33. package/lib/types/src/api/utils/HexaString.d.ts +4 -3
  34. package/lib/types/src/api/utils/HexaString.d.ts.map +1 -1
  35. package/lib/types/src/internal/device-session/service/DefaultApduReceiverService.d.ts.map +1 -1
  36. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  37. package/package.json +3 -3
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/device-management-kit",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "private": false,
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -1,2 +1,2 @@
1
- "use strict";var h=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var g=(i,r)=>{for(var t in r)h(i,t,{get:r[t],enumerable:!0})},m=(i,r,t,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of f(r))!y.call(i,e)&&e!==t&&h(i,e,{get:()=>r[e],enumerable:!(a=b(r,e))||a.enumerable});return i};var l=i=>m(h({},"__esModule",{value:!0}),i);var D={};g(D,{ByteArrayBuilder:()=>A});module.exports=l(D);var B=require("../../utils/HexaString"),n=require("./AppBuilderError");const T=4294967295;class A{constructor(r=T){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 n.DataOverflowError(r.toString())),this);addHexaStringToData=r=>{const t=(0,B.hexaStringToBuffer)(r);return t===null||t.length===0?(this.errors.push(new n.HexaStringEncodeError(r)),this):(this.addBufferToData(t),this)};addAsciiStringToData=r=>{const t=new TextEncoder().encode(r);return this.addBufferToData(t),this};encodeInLVFromHexa=r=>{const t=(0,B.hexaStringToBuffer)(r);return t===null||t.length===0?(this.errors.push(new n.HexaStringEncodeError(r)),this):this.hasEnoughLengthRemaining(t,!0)?(this.add8BitUIntToData(t.length),this.addBufferToData(t),this):(this.errors.push(new n.DataOverflowError(r)),this)};encodeInLVFromBuffer=r=>this.hasEnoughLengthRemaining(r,!0)?(this.add8BitUIntToData(r.length),this.addBufferToData(r),this):(this.errors.push(new n.DataOverflowError(r.toString())),this);encodeInLVFromAscii=r=>this.hasEnoughLengthRemaining(r,!0)?(this.add8BitUIntToData(r.length),this.addAsciiStringToData(r),this):(this.errors.push(new n.DataOverflowError(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 o=this.checkBoundsAndConvert(r,t,a);if(o===void 0)return this;const s=Number(t)/8,u=new Uint8Array(s);if(e)for(let d=s-1;d>=0;d--)u[d]=Number(o&0xffn),o>>=8n;else for(let d=0;d<s;d++)u[d]=Number(o&0xffn),o>>=8n;return this.addBufferToData(u)}checkBoundsAndConvert(r,t,a){if(typeof r=="number"){if(!Number.isInteger(r)||r>Number.MAX_SAFE_INTEGER){this.errors.push(new n.ValueOverflowError(r.toString()));return}r=BigInt(r)}if(a){const e=1n<<t-1n;if(r>=e||r<-e){this.errors.push(new n.ValueOverflowError(r.toString(),e-1n));return}if(r<0n){const o=(1n<<t)-1n;r=-r,r=(~r&o)+1n}}else{const e=1n<<t;if(r<0||r>=e){this.errors.push(new n.ValueOverflowError(r.toString(),e-1n));return}}return r}}0&&(module.exports={ByteArrayBuilder});
1
+ "use strict";var h=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var f=(a,t)=>{for(var r in t)h(a,r,{get:t[r],enumerable:!0})},g=(a,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of m(t))!y.call(a,e)&&e!==r&&h(a,e,{get:()=>t[e],enumerable:!(n=b(t,e))||n.enumerable});return a};var l=a=>g(h({},"__esModule",{value:!0}),a);var A={};f(A,{ByteArrayBuilder:()=>D});module.exports=l(A);var B=require("../../utils/HexaString"),i=require("./AppBuilderError");const T=4294967295;class D{constructor(t=T){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 i.DataOverflowError(t.toString())),this);addHexaStringToData=t=>{const r=(0,B.hexaStringToBuffer)(t);return r===null||r.length===0?(this.errors.push(new i.HexaStringEncodeError(t)),this):(this.addBufferToData(r),this)};addAsciiStringToData=t=>{const r=new TextEncoder().encode(t);return this.addBufferToData(r),this};encodeInLVFromHexa=t=>{const r=(0,B.hexaStringToBuffer)(t);return r===null||r.length===0?(this.errors.push(new i.HexaStringEncodeError(t)),this):this.hasEnoughLengthRemaining(r,!0)?(this.add8BitUIntToData(r.length),this.addBufferToData(r),this):(this.errors.push(new i.DataOverflowError(t)),this)};encodeInLVFromBuffer=t=>this.hasEnoughLengthRemaining(t,!0)?(this.add8BitUIntToData(t.length),this.addBufferToData(t),this):(this.errors.push(new i.DataOverflowError(t.toString())),this);encodeInLVFromAscii=t=>this.hasEnoughLengthRemaining(t,!0)?(this.add8BitUIntToData(t.length),this.addAsciiStringToData(t),this):(this.errors.push(new i.DataOverflowError(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,n=!0)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(2),this.add16BitUIntToData(r,n));encodeInTLVFromUInt32=(t,r,n=!0)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(4),this.add32BitUIntToData(r,n));encodeInTLVFromUInt64=(t,r,n=!0)=>(this.add8BitUIntToData(t),this.add8BitUIntToData(8),this.add64BitUIntToData(r,n));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,n,e){let o=this.checkBoundsAndConvert(t,r,n);if(o===void 0)return this;const u=Number(r)/8,s=new Uint8Array(u);if(e)for(let d=u-1;d>=0;d--)s[d]=Number(o&0xffn),o>>=8n;else for(let d=0;d<u;d++)s[d]=Number(o&0xffn),o>>=8n;return this.addBufferToData(s)}checkBoundsAndConvert(t,r,n){if(typeof t=="number"){if(!Number.isInteger(t)||t>Number.MAX_SAFE_INTEGER){this.errors.push(new i.ValueOverflowError(t.toString()));return}t=BigInt(t)}if(n){const e=1n<<r-1n;if(t>=e||t<-e){this.errors.push(new i.ValueOverflowError(t.toString(),e-1n));return}if(t<0n){const o=(1n<<r)-1n;t=-t,t=(~t&o)+1n}}else{const e=1n<<r;if(t<0||t>=e){this.errors.push(new i.ValueOverflowError(t.toString(),e-1n));return}}return t}}0&&(module.exports={ByteArrayBuilder});
2
2
  //# sourceMappingURL=ByteArrayBuilder.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/apdu/utils/ByteArrayBuilder.ts"],
4
- "sourcesContent": ["import { hexaStringToBuffer } from \"@api/utils/HexaString\";\n\nimport {\n type AppBuilderError,\n DataOverflowError,\n HexaStringEncodeError,\n ValueOverflowError,\n} from \"./AppBuilderError\";\n\nconst MAX_32_BIT_UINT = 0xffffffff;\n\n/**\n * ByteArrayBuilder is a utility class to help build APDU payloads.\n * It allows to easily add data to the payload of an APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const builder = new ByteArrayBuilder(255)\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const payload = builder.build();\n * const builderErrors = builder.getErrors();\n * ```\n */\nexport class ByteArrayBuilder {\n private data: Uint8Array = new Uint8Array();\n private readonly errors: AppBuilderError[] = []; // Custom Error\n\n constructor(private maxPayloadSize: number = MAX_32_BIT_UINT) {}\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new payload instance with the current state of the builder\n * @returns {payload} - Returns a new payload instance\n */\n build = (): Uint8Array => this.data;\n\n /**\n * Try to build a new payload instance with the current state of the builder\n * if the builder don't contain any error.\n * @returns {payload | undefined} - Returns a new payload instance or undefined\n */\n tryBuild = (): Uint8Array | undefined => {\n return this.hasErrors() ? undefined : this.data;\n };\n\n /**\n * Add a 8-bit unsigned integer to the payload (max value 0xff = 255)\n * @param value: number | bigint - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add8BitUIntToData = (value: number | bigint): ByteArrayBuilder => {\n return this.addNumberToData(value, 8n, false, false);\n };\n\n /**\n * Add a 16-bit unsigned integer to the payload (max value 0xffff = 65535)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add16BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 16n, false, bigEndian);\n };\n\n /**\n * Add a 32-bit unsigned integer to the payload (max value 0xffffffff = 4294967295)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add32BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 32n, false, bigEndian);\n };\n\n /**\n * Add a 64-bit unsigned integer to the payload (max value 0xffffffffffffffff = 18446744073709551615)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add64BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 64n, false, bigEndian);\n };\n\n /**\n * Add a 128-bit unsigned integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add128BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 128n, false, bigEndian);\n };\n\n /**\n * Add a 256-bit unsigned integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add256BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 256n, false, bigEndian);\n };\n\n /**\n * Add a 16-bit signed integer to the payload (value between -0x8000 to 0x7fff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add16BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 16n, true, bigEndian);\n };\n\n /**\n * Add a 32-bit signed integer to the payload (value between -0x80000000 to 0x7fffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add32BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 32n, true, bigEndian);\n };\n\n /**\n * Add a 64-bit signed integer to the payload (value between -0x8000000000000000 to 0x7fffffffffffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add64BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 64n, true, bigEndian);\n };\n\n /**\n * Add a 128-bit signed integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add128BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 128n, true, bigEndian);\n };\n\n /**\n * Add a 256-bit signed integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add256BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 256n, true, bigEndian);\n };\n\n /**\n * Add a Uint8Array to the payload if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n addBufferToData = (value: Uint8Array): ByteArrayBuilder => {\n if (!this.hasEnoughLengthRemaining(value)) {\n this.errors.push(new DataOverflowError(value.toString()));\n return this;\n }\n\n this.data = Uint8Array.from([...this.data, ...value]);\n return this;\n };\n\n /**\n * Add a string to the payload if it has enough remaining space\n * and it can be formatted as a hexadecimal string\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n addHexaStringToData = (value: string): ByteArrayBuilder => {\n const result = hexaStringToBuffer(value);\n if (result === null || result.length === 0) {\n this.errors.push(new HexaStringEncodeError(value));\n return this;\n }\n this.addBufferToData(result);\n return this;\n };\n\n /**\n * Add an ascii string to the data field if it has enough remaining space\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n addAsciiStringToData = (value: string): ByteArrayBuilder => {\n const bytes = new TextEncoder().encode(value);\n this.addBufferToData(bytes);\n return this;\n };\n\n /**\n * Add a Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInLVFromHexa = (value: string): ByteArrayBuilder => {\n const result = hexaStringToBuffer(value);\n if (result === null || result.length === 0) {\n this.errors.push(new HexaStringEncodeError(value));\n return this;\n }\n\n if (!this.hasEnoughLengthRemaining(result, true)) {\n this.errors.push(new DataOverflowError(value));\n return this;\n }\n // values are always being well formatted at this point\n // therefore no status test is needed\n this.add8BitUIntToData(result.length);\n this.addBufferToData(result);\n return this;\n };\n\n /**\n * Add a Length-Value encoded buffer to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: Uint8Array - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ByteArrayBuilder => {\n if (!this.hasEnoughLengthRemaining(value, true)) {\n this.errors.push(new DataOverflowError(value.toString()));\n return this;\n }\n\n this.add8BitUIntToData(value.length);\n this.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded ascii string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInLVFromAscii = (value: string): ByteArrayBuilder => {\n if (!this.hasEnoughLengthRemaining(value, true)) {\n this.errors.push(new DataOverflowError(value));\n return this;\n }\n\n this.add8BitUIntToData(value.length);\n this.addAsciiStringToData(value);\n return this;\n };\n\n /**\n * Add a Tag-Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromHexa = (tag: number, value: string): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n return this.encodeInLVFromHexa(value);\n };\n\n /**\n * Add a Tag-Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: Uint8Array - The buffer to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromBuffer = (\n tag: number,\n value: Uint8Array,\n ): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n return this.encodeInLVFromBuffer(value);\n };\n\n /**\n * Add a Tag-Length-Value encoded uint64 to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: number | bigint - The number to add\n * @param bigEndian: boolean - Endianness used to encode the number\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromUInt64 = (\n tag: number,\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n this.add8BitUIntToData(8);\n return this.add64BitUIntToData(value, bigEndian);\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number => {\n return this.maxPayloadSize - this.data.length;\n };\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.errors;\n\n /**\n * Verifies if the builder contains errors\n * @returns {boolean} - Returns wether the builder contains errors or not\n */\n hasErrors = (): boolean => this.errors.length !== 0;\n\n // ===========\n // Private API\n // ===========\n\n /**\n * Check if there is enough space to add a value to the data field\n * @param value {string | Uint8Array | number[]} - Value to add to the data\n * @param hasLv {boolean} - Length-Value encoding flag\n * @returns {boolean} - Returns true if there is enough space to add the value\n */\n private hasEnoughLengthRemaining = (\n value: string | Uint8Array | number[],\n hasLv: boolean = false,\n ): boolean => {\n return (\n this.data.length + value.length + (hasLv ? 1 : 0) <= this.maxPayloadSize\n );\n };\n\n /**\n * Add a number to the payload\n * @param value: number | bigint - The value to add to the data\n * @param sizeInBits: bigint - The number size in bits, for example 16 for a uint16\n * @param signed: boolean - Whether the value is signed or unsigned.\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n private addNumberToData(\n value: number | bigint,\n sizeInBits: bigint,\n signed: boolean,\n bigEndian: boolean,\n ): ByteArrayBuilder {\n // Convert the number to two's complement and check its bounds\n let converted = this.checkBoundsAndConvert(value, sizeInBits, signed);\n if (converted === undefined) {\n return this;\n }\n\n // Compute the buffer\n const sizeInBytes = Number(sizeInBits) / 8;\n const buffer = new Uint8Array(sizeInBytes);\n if (bigEndian) {\n for (let i = sizeInBytes - 1; i >= 0; i--) {\n buffer[i] = Number(converted & 0xffn);\n converted >>= 8n;\n }\n } else {\n for (let i = 0; i < sizeInBytes; i++) {\n buffer[i] = Number(converted & 0xffn);\n converted >>= 8n;\n }\n }\n return this.addBufferToData(buffer);\n }\n\n /**\n * Checks the bounds of a signed or unsigned integer value and converts it to two's complement if it is signed and negative.\n * @param value The value to check and convert.\n * @param sizeInBits The size of the value in bits.\n * @param signed Whether the value is signed or unsigned.\n * @returns The converted value, or null if the value is out of bounds.\n */\n private checkBoundsAndConvert(\n value: number | bigint,\n sizeInBits: bigint,\n signed: boolean,\n ): bigint | undefined {\n // Normalize the value to a bigint\n if (typeof value === \"number\") {\n if (!Number.isInteger(value) || value > Number.MAX_SAFE_INTEGER) {\n this.errors.push(new ValueOverflowError(value.toString()));\n return;\n }\n value = BigInt(value);\n }\n\n if (!signed) {\n // Check if the value is within the bounds of an unsigned integer\n const limit = 1n << sizeInBits;\n if (value < 0 || value >= limit) {\n this.errors.push(new ValueOverflowError(value.toString(), limit - 1n));\n return;\n }\n } else {\n // Check if the value is within the bounds of a signed integer\n const limit = 1n << (sizeInBits - 1n);\n if (value >= limit || value < -limit) {\n this.errors.push(new ValueOverflowError(value.toString(), limit - 1n));\n return;\n }\n\n // Convert the value to two's complement if it is negative\n // https://en.wikipedia.org/wiki/Two%27s_complement\n if (value < 0n) {\n const mask = (1n << sizeInBits) - 1n;\n value = -value;\n value = (~value & mask) + 1n;\n }\n }\n return value;\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,iCAEnCC,EAKO,6BAEP,MAAMC,EAAkB,WAmBjB,MAAMJ,CAAiB,CAI5B,YAAoBK,EAAyBD,EAAiB,CAA1C,oBAAAC,CAA2C,CAHvD,KAAmB,IAAI,WACd,OAA4B,CAAC,EAY9C,MAAQ,IAAkB,KAAK,KAO/B,SAAW,IACF,KAA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O,CAC/B,KAAK,OAAO,KAAK,IAAI,qBAAmBZ,EAAM,SAAS,EAAGY,EAAQ,EAAE,CAAC,EACrE,MACF,CACF,CAgBA,OAAOZ,CACT,CACF",
4
+ "sourcesContent": ["import { hexaStringToBuffer } from \"@api/utils/HexaString\";\n\nimport {\n type AppBuilderError,\n DataOverflowError,\n HexaStringEncodeError,\n ValueOverflowError,\n} from \"./AppBuilderError\";\n\nconst MAX_32_BIT_UINT = 0xffffffff;\n\n/**\n * ByteArrayBuilder is a utility class to help build APDU payloads.\n * It allows to easily add data to the payload of an APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const builder = new ByteArrayBuilder(255)\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const payload = builder.build();\n * const builderErrors = builder.getErrors();\n * ```\n */\nexport class ByteArrayBuilder {\n private data: Uint8Array = new Uint8Array();\n private readonly errors: AppBuilderError[] = []; // Custom Error\n\n constructor(private maxPayloadSize: number = MAX_32_BIT_UINT) {}\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new payload instance with the current state of the builder\n * @returns {payload} - Returns a new payload instance\n */\n build = (): Uint8Array => this.data;\n\n /**\n * Try to build a new payload instance with the current state of the builder\n * if the builder don't contain any error.\n * @returns {payload | undefined} - Returns a new payload instance or undefined\n */\n tryBuild = (): Uint8Array | undefined => {\n return this.hasErrors() ? undefined : this.data;\n };\n\n /**\n * Add a 8-bit unsigned integer to the payload (max value 0xff = 255)\n * @param value: number | bigint - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add8BitUIntToData = (value: number | bigint): ByteArrayBuilder => {\n return this.addNumberToData(value, 8n, false, false);\n };\n\n /**\n * Add a 16-bit unsigned integer to the payload (max value 0xffff = 65535)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add16BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 16n, false, bigEndian);\n };\n\n /**\n * Add a 32-bit unsigned integer to the payload (max value 0xffffffff = 4294967295)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add32BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 32n, false, bigEndian);\n };\n\n /**\n * Add a 64-bit unsigned integer to the payload (max value 0xffffffffffffffff = 18446744073709551615)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add64BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 64n, false, bigEndian);\n };\n\n /**\n * Add a 128-bit unsigned integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add128BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 128n, false, bigEndian);\n };\n\n /**\n * Add a 256-bit unsigned integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add256BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 256n, false, bigEndian);\n };\n\n /**\n * Add a 16-bit signed integer to the payload (value between -0x8000 to 0x7fff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add16BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 16n, true, bigEndian);\n };\n\n /**\n * Add a 32-bit signed integer to the payload (value between -0x80000000 to 0x7fffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add32BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 32n, true, bigEndian);\n };\n\n /**\n * Add a 64-bit signed integer to the payload (value between -0x8000000000000000 to 0x7fffffffffffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add64BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 64n, true, bigEndian);\n };\n\n /**\n * Add a 128-bit signed integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add128BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 128n, true, bigEndian);\n };\n\n /**\n * Add a 256-bit signed integer to the payload\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n add256BitIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n return this.addNumberToData(value, 256n, true, bigEndian);\n };\n\n /**\n * Add a Uint8Array to the payload if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n addBufferToData = (value: Uint8Array): ByteArrayBuilder => {\n if (!this.hasEnoughLengthRemaining(value)) {\n this.errors.push(new DataOverflowError(value.toString()));\n return this;\n }\n\n this.data = Uint8Array.from([...this.data, ...value]);\n return this;\n };\n\n /**\n * Add a string to the payload if it has enough remaining space\n * and it can be formatted as a hexadecimal string\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n addHexaStringToData = (value: string): ByteArrayBuilder => {\n const result = hexaStringToBuffer(value);\n if (result === null || result.length === 0) {\n this.errors.push(new HexaStringEncodeError(value));\n return this;\n }\n this.addBufferToData(result);\n return this;\n };\n\n /**\n * Add an ascii string to the data field if it has enough remaining space\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n addAsciiStringToData = (value: string): ByteArrayBuilder => {\n const bytes = new TextEncoder().encode(value);\n this.addBufferToData(bytes);\n return this;\n };\n\n /**\n * Add a Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInLVFromHexa = (value: string): ByteArrayBuilder => {\n const result = hexaStringToBuffer(value);\n if (result === null || result.length === 0) {\n this.errors.push(new HexaStringEncodeError(value));\n return this;\n }\n\n if (!this.hasEnoughLengthRemaining(result, true)) {\n this.errors.push(new DataOverflowError(value));\n return this;\n }\n // values are always being well formatted at this point\n // therefore no status test is needed\n this.add8BitUIntToData(result.length);\n this.addBufferToData(result);\n return this;\n };\n\n /**\n * Add a Length-Value encoded buffer to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: Uint8Array - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ByteArrayBuilder => {\n if (!this.hasEnoughLengthRemaining(value, true)) {\n this.errors.push(new DataOverflowError(value.toString()));\n return this;\n }\n\n this.add8BitUIntToData(value.length);\n this.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a Length-Value encoded ascii string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInLVFromAscii = (value: string): ByteArrayBuilder => {\n if (!this.hasEnoughLengthRemaining(value, true)) {\n this.errors.push(new DataOverflowError(value));\n return this;\n }\n\n this.add8BitUIntToData(value.length);\n this.addAsciiStringToData(value);\n return this;\n };\n\n /**\n * Add a Tag-Length-Value encoded ascii string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromAscii = (tag: number, value: string): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n return this.encodeInLVFromAscii(value);\n };\n\n /**\n * Add a Tag-Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: string - The value to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromHexa = (tag: number, value: string): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n return this.encodeInLVFromHexa(value);\n };\n\n /**\n * Add a Tag-Length-Value encoded hexadecimal string to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: Uint8Array - The buffer to add to the data\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromBuffer = (\n tag: number,\n value: Uint8Array,\n ): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n return this.encodeInLVFromBuffer(value);\n };\n\n /**\n * Add a Tag-Length-Value encoded uint8 to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: number - The number to add\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromUInt8 = (tag: number, value: number): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n this.add8BitUIntToData(1);\n return this.add8BitUIntToData(value);\n };\n\n /**\n * Add a Tag-Length-Value encoded uint16 to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: number | bigint - The number to add\n * @param bigEndian: boolean - Endianness used to encode the number\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromUInt16 = (\n tag: number,\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n this.add8BitUIntToData(2);\n return this.add16BitUIntToData(value, bigEndian);\n };\n\n /**\n * Add a Tag-Length-Value encoded uint32 to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: number | bigint - The number to add\n * @param bigEndian: boolean - Endianness used to encode the number\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromUInt32 = (\n tag: number,\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n this.add8BitUIntToData(4);\n return this.add32BitUIntToData(value, bigEndian);\n };\n\n /**\n * Add a Tag-Length-Value encoded uint64 to the data field if it has enough remaining space\n * Length-Value encoding is a way to encode data in a binary format with the first byte\n * being the length of the data and the following bytes being the data itself\n * @param tag: number - The tag to add to the data\n * @param value: number | bigint - The number to add\n * @param bigEndian: boolean - Endianness used to encode the number\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n encodeInTLVFromUInt64 = (\n tag: number,\n value: number | bigint,\n bigEndian: boolean = true,\n ): ByteArrayBuilder => {\n this.add8BitUIntToData(tag);\n this.add8BitUIntToData(8);\n return this.add64BitUIntToData(value, bigEndian);\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number => {\n return this.maxPayloadSize - this.data.length;\n };\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.errors;\n\n /**\n * Verifies if the builder contains errors\n * @returns {boolean} - Returns wether the builder contains errors or not\n */\n hasErrors = (): boolean => this.errors.length !== 0;\n\n // ===========\n // Private API\n // ===========\n\n /**\n * Check if there is enough space to add a value to the data field\n * @param value {string | Uint8Array | number[]} - Value to add to the data\n * @param hasLv {boolean} - Length-Value encoding flag\n * @returns {boolean} - Returns true if there is enough space to add the value\n */\n private hasEnoughLengthRemaining = (\n value: string | Uint8Array | number[],\n hasLv: boolean = false,\n ): boolean => {\n return (\n this.data.length + value.length + (hasLv ? 1 : 0) <= this.maxPayloadSize\n );\n };\n\n /**\n * Add a number to the payload\n * @param value: number | bigint - The value to add to the data\n * @param sizeInBits: bigint - The number size in bits, for example 16 for a uint16\n * @param signed: boolean - Whether the value is signed or unsigned.\n * @param bigEndian: boolean - True to encode in big endian, false for little endian\n * @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder\n */\n private addNumberToData(\n value: number | bigint,\n sizeInBits: bigint,\n signed: boolean,\n bigEndian: boolean,\n ): ByteArrayBuilder {\n // Convert the number to two's complement and check its bounds\n let converted = this.checkBoundsAndConvert(value, sizeInBits, signed);\n if (converted === undefined) {\n return this;\n }\n\n // Compute the buffer\n const sizeInBytes = Number(sizeInBits) / 8;\n const buffer = new Uint8Array(sizeInBytes);\n if (bigEndian) {\n for (let i = sizeInBytes - 1; i >= 0; i--) {\n buffer[i] = Number(converted & 0xffn);\n converted >>= 8n;\n }\n } else {\n for (let i = 0; i < sizeInBytes; i++) {\n buffer[i] = Number(converted & 0xffn);\n converted >>= 8n;\n }\n }\n return this.addBufferToData(buffer);\n }\n\n /**\n * Checks the bounds of a signed or unsigned integer value and converts it to two's complement if it is signed and negative.\n * @param value The value to check and convert.\n * @param sizeInBits The size of the value in bits.\n * @param signed Whether the value is signed or unsigned.\n * @returns The converted value, or null if the value is out of bounds.\n */\n private checkBoundsAndConvert(\n value: number | bigint,\n sizeInBits: bigint,\n signed: boolean,\n ): bigint | undefined {\n // Normalize the value to a bigint\n if (typeof value === \"number\") {\n if (!Number.isInteger(value) || value > Number.MAX_SAFE_INTEGER) {\n this.errors.push(new ValueOverflowError(value.toString()));\n return;\n }\n value = BigInt(value);\n }\n\n if (!signed) {\n // Check if the value is within the bounds of an unsigned integer\n const limit = 1n << sizeInBits;\n if (value < 0 || value >= limit) {\n this.errors.push(new ValueOverflowError(value.toString(), limit - 1n));\n return;\n }\n } else {\n // Check if the value is within the bounds of a signed integer\n const limit = 1n << (sizeInBits - 1n);\n if (value >= limit || value < -limit) {\n this.errors.push(new ValueOverflowError(value.toString(), limit - 1n));\n return;\n }\n\n // Convert the value to two's complement if it is negative\n // https://en.wikipedia.org/wiki/Two%27s_complement\n if (value < 0n) {\n const mask = (1n << sizeInBits) - 1n;\n value = -value;\n value = (~value & mask) + 1n;\n }\n }\n return value;\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,iCAEnCC,EAKO,6BAEP,MAAMC,EAAkB,WAmBjB,MAAMJ,CAAiB,CAI5B,YA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AC,EACoB,CAEpB,GAAI,OAAOP,GAAU,SAAU,CAC7B,GAAI,CAAC,OAAO,UAAUA,CAAK,GAAKA,EAAQ,OAAO,iBAAkB,CAC/D,KAAK,OAAO,KAAK,IAAI,qBAAmBA,EAAM,SAAS,CAAC,CAAC,EACzD,MACF,CACAA,EAAQ,OAAOA,CAAK,CACtB,CAEA,GAAKO,EAOE,CAEL,MAAMK,EAAQ,IAAON,EAAa,GAClC,GAAIN,GAASY,GAASZ,EAAQ,CAACY,EAAO,CACpC,KAAK,OAAO,KAAK,IAAI,qBAAmBZ,EAAM,SAAS,EAAGY,EAAQ,EAAE,CAAC,EACrE,MACF,CAIA,GAAIZ,EAAQ,GAAI,CACd,MAAMa,GAAQ,IAAMP,GAAc,GAClCN,EAAQ,CAACA,EACTA,GAAS,CAACA,EAAQa,GAAQ,EAC5B,CACF,KAtBa,CAEX,MAAMD,EAAQ,IAAMN,EACpB,GAAIN,EAAQ,GAAKA,GAASY,EAAO,CAC/B,KAAK,OAAO,KAAK,IAAI,qBAAmBZ,EAAM,SAAS,EAAGY,EAAQ,EAAE,CAAC,EACrE,MACF,CACF,CAgBA,OAAOZ,CACT,CACF",
6
6
  "names": ["ByteArrayBuilder_exports", "__export", "ByteArrayBuilder", "__toCommonJS", "import_HexaString", "import_AppBuilderError", "MAX_32_BIT_UINT", "maxPayloadSize", "value", "bigEndian", "result", "bytes", "tag", "hasLv", "sizeInBits", "signed", "converted", "sizeInBytes", "buffer", "i", "limit", "mask"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var c=require("../../utils/HexaString"),a=require("./ApduBuilder"),r=require("./AppBuilderError"),l=require("./ByteArrayBuilder");const d=new Uint8Array([]),g=new Uint8Array([1]),y=new Uint8Array([128,129,130,131,132]),A=new Uint8Array([133,134,135,136]),p=new Uint8Array([3,161,162,163]),E=new Uint8Array([5,109,97,109,97,110]),b=new Uint8Array([2,240,241]),h=new Uint8Array([1,51,2,1,35,69,103,128,129,130,131,132,133,134,135,136,3,161,162,163,5,109,97,109,97,110,2,240,241]),x=new Uint8Array([...Array(255).fill(170)]),s=new Uint8Array([...Array(254).fill(170)]);let e;describe("ByteArrayBuilder",()=>{const i=(f,t,o,n)=>{if(n)switch(o){case 2:e.add16BitIntToData(f,t);break;case 4:e.add32BitIntToData(f,t);break;case 8:e.add64BitIntToData(f,t);break;case 16:e.add128BitIntToData(f,t);break;case 32:e.add256BitIntToData(f,t);break}else switch(o){case 2:e.add16BitUIntToData(f,t);break;case 4:e.add32BitUIntToData(f,t);break;case 8:e.add64BitUIntToData(f,t);break;case 16:e.add128BitUIntToData(f,t);break;case 32:e.add256BitUIntToData(f,t);break}};describe("clean",()=>{beforeEach(()=>{e=new l.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it("should create an instance",()=>{expect(e).toBeDefined(),expect(e).toBeInstanceOf(l.ByteArrayBuilder)})}),describe("simple",()=>{beforeEach(()=>{e=new l.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it("should serialize with an empty body",()=>{expect(e.build()).toEqual(d)}),it("should serialize with an single byte body",()=>{e=new l.ByteArrayBuilder(1),e.add8BitUIntToData(1),expect(e.build()).toEqual(g),expect(e.getErrors()).toEqual([])}),it.each([[2,!1,!0,13058,"3302"],[2,!1,!1,0x3302n,"0233"],[2,!0,!0,4200n,"1068"],[2,!0,!0,-4200n,"ef98"],[2,!0,!1,4200,"6810"],[2,!0,!1,-4200,"98ef"],[4,!1,!0,0x01234567n,"01234567"],[4,!1,!1,0x01234567n,"67452301"],[4,!0,!0,123456789,"075bcd15"],[4,!0,!0,-123456789,"f8a432eb"],[4,!0,!1,123456789,"15cd5b07"],[4,!0,!1,-123456789,"eb32a4f8"],[8,!1,!0,14147778004927559n,"0032435442584447"],[8,!1,!1,14147778004927559n,"4744584254433200"],[8,!0,!0,14147778004927559n,"0032435442584447"],[8,!0,!0,-14147778004927559n,"ffcdbcabbda7bbb9"],[8,!0,!1,14147778004927559n,"4744584254433200"],[8,!0,!1,-14147778004927559n,"b9bba7bdabbccdff"],[16,!1,!0,0x00324354425844470032435442584447n,"00324354425844470032435442584447"],[16,!1,!1,0x00324354425844470032435442584447n,"47445842544332004744584254433200"],[16,!0,!0,0x00324354425844470032435442584447n,"00324354425844470032435442584447"],[16,!0,!0,-0x00324354425844470032435442584447n,"ffcdbcabbda7bbb8ffcdbcabbda7bbb9"],[16,!0,!1,0x00324354425844470032435442584447n,"47445842544332004744584254433200"],[16,!0,!1,-0x00324354425844470032435442584447n,"b9bba7bdabbccdffb8bba7bdabbccdff"],[32,!1,!0,0x0032435442584447003243544258444700324354425844470032435442584447n,"0032435442584447003243544258444700324354425844470032435442584447"],[32,!1,!1,0x0032435442584447003243544258444700324354425844470032435442584447n,"4744584254433200474458425443320047445842544332004744584254433200"],[32,!0,!0,0x0032435442584447003243544258444700324354425844470032435442584447n,"0032435442584447003243544258444700324354425844470032435442584447"],[32,!0,!0,-0x0032435442584447003243544258444700324354425844470032435442584447n,"ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb9"],[32,!0,!1,0x0032435442584447003243544258444700324354425844470032435442584447n,"4744584254433200474458425443320047445842544332004744584254433200"],[32,!0,!1,-0x0032435442584447003243544258444700324354425844470032435442584447n,"b9bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdff"]])("serialize the following number: size %i, signed %s, bigEndian %s, value %i, expected %s",(f,t,o,n,u)=>{e=new l.ByteArrayBuilder(f),i(n,o,f,t),expect(e.build()).toEqual((0,c.hexaStringToBuffer)(u)),expect(e.getErrors()).toEqual([]),e=new l.ByteArrayBuilder(f-1),i(n,o,f,t),expect(e.getErrors().length).toEqual(1),expect(e.build()).toEqual(Uint8Array.from([]))}),it.each([[2,!1,!0,0xffffn,"ffff"],[2,!0,!0,0x7fffn,"7fff"],[2,!0,!0,-0x8000n,"8000"],[4,!1,!0,0xffffffffn,"ffffffff"],[4,!0,!0,0x7fffffffn,"7fffffff"],[4,!0,!0,-0x80000000n,"80000000"],[8,!1,!0,0xffffffffffffffffn,"ffffffffffffffff"],[8,!0,!0,0x7fffffffffffffffn,"7fffffffffffffff"],[8,!0,!0,-0x8000000000000000n,"8000000000000000"],[16,!1,!0,0xffffffffffffffffffffffffffffffffn,"ffffffffffffffffffffffffffffffff"],[16,!0,!0,0x7fffffffffffffffffffffffffffffffn,"7fffffffffffffffffffffffffffffff"],[16,!0,!0,-0x80000000000000000000000000000000n,"80000000000000000000000000000000"],[32,!1,!0,0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],[32,!0,!0,0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],[32,!0,!0,-0x8000000000000000000000000000000000000000000000000000000000000000n,"8000000000000000000000000000000000000000000000000000000000000000"]])("serialize the number to the limit: size %i, signed %s, bigEndian %s, value %i, expected %s",(f,t,o,n,u)=>{e=new l.ByteArrayBuilder(f),i(n,o,f,t),expect(e.build()).toEqual((0,c.hexaStringToBuffer)(u)),expect(e.getErrors()).toEqual([])}),it("Serialize from float to bigint",()=>{e=new l.ByteArrayBuilder(4),e.add32BitIntToData(1234567893e-1,!1),expect(e.getErrors().length).toEqual(1),expect(e.build()).toEqual(Uint8Array.from([]))}),it("should serialize with an 5 byte body from an hexastring",()=>{e.addHexaStringToData("0x8081828384"),expect(e.build()).toEqual(y),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body from an hexastring without '0x'",()=>{e.addHexaStringToData("85868788"),expect(e.build()).toEqual(A),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from an hexastring",()=>{e.encodeInLVFromHexa("0xA1A2A3"),expect(e.build()).toEqual(p),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from an ascci string",()=>{e.encodeInLVFromAscii("maman"),expect(e.build()).toEqual(E),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from a buffer",()=>{const f=new Uint8Array([240,241]);e.encodeInLVFromBuffer(f),expect(e.build()).toEqual(b),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from a buffer",()=>{const f=new Uint8Array([240,241]);e.encodeInLVFromBuffer(f),expect(e.build()).toEqual(b),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an hexastring",()=>{e.encodeInTLVFromHexa(5,"0xA1A2A3"),expect(e.build()).toEqual(Uint8Array.from([5,3,161,162,163])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from a buffer",()=>{e.encodeInTLVFromBuffer(6,Uint8Array.from([161,162,163,164])),expect(e.build()).toEqual(Uint8Array.from([6,4,161,162,163,164])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an uint64",()=>{e.encodeInTLVFromUInt64(6,95075813176406),expect(e.build()).toEqual(Uint8Array.from([6,8,0,0,86,120,144,18,52,86])),expect(e.getErrors()).toEqual([])}),it("should serialize with an complete body of 0xAA",()=>{const f=new Uint8Array(255).fill(170,0,255);e.addBufferToData(f),expect(e.build()).toEqual(x),expect(e.getErrors()).toEqual([])})}),describe("mixed",()=>{beforeEach(()=>{e=new l.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it("should serialize with all previous field",()=>{let f=a.APDU_MAX_PAYLOAD;e.add8BitUIntToData(1),f--,expect(e.getAvailablePayloadLength()).toBe(f),e.add16BitUIntToData(13058),f-=2,expect(e.getAvailablePayloadLength()).toBe(f),e.add32BitUIntToData(19088743),f-=4,expect(e.getAvailablePayloadLength()).toBe(f),e.addHexaStringToData("0x8081828384"),f-=5,expect(e.getAvailablePayloadLength()).toBe(f),e.addHexaStringToData("85868788"),f-=4,expect(e.getAvailablePayloadLength()).toBe(f),e.encodeInLVFromHexa("0xA1A2A3"),f-=4,expect(e.getAvailablePayloadLength()).toBe(f),e.encodeInLVFromAscii("maman"),f-=6,expect(e.getAvailablePayloadLength()).toBe(f);const t=new Uint8Array([240,241]);e.encodeInLVFromBuffer(t),f-=3,expect(e.getAvailablePayloadLength()).toBe(f),expect(e.build()).toEqual(h)})}),describe("error",()=>{beforeEach(()=>{e=new l.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it.each([[2,!1,!0,0x10000n],[2,!0,!0,0x8000n],[2,!0,!0,-0x8001n],[4,!1,!0,0x100000000n],[4,!0,!0,0x80000000n],[4,!0,!0,-0x80000001n],[8,!1,!0,0x10000000000000000n],[8,!0,!0,0x8000000000000000n],[8,!0,!0,-0x8000000000000001n]])("serialize the number overflowed: size %i, signed %s, bigEndian %s, value %i",(f,t,o,n)=>{e=new l.ByteArrayBuilder(f),i(n,o,f,t),expect(e.getErrors().length).toEqual(1),expect(e.build()).toEqual(Uint8Array.from([]))}),it("error due to a string not well coded",()=>{e.addHexaStringToData(":08081828384").addHexaStringToData("80818n8384").addHexaStringToData("808182838z"),expect(e.build()).toEqual(d),expect(e.getAvailablePayloadLength()).toBe(a.APDU_MAX_PAYLOAD),expect(e.getErrors()).toEqual([new r.HexaStringEncodeError(":08081828384"),new r.HexaStringEncodeError("80818n8384"),new r.HexaStringEncodeError("808182838z")])}),it("error due direct overflow",()=>{const f=new Uint8Array(256).fill(170,0,256);e.addBufferToData(f),expect(e.build()).toEqual(d),expect(e.getAvailablePayloadLength()).toBe(a.APDU_MAX_PAYLOAD),expect(e.getErrors()).toEqual([new r.DataOverflowError(f.toString())])}),it("error due to subsequent overflow with 1-byte array",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD).fill(170,0,a.APDU_MAX_PAYLOAD);e.addBufferToData(f),expect(e.build()).toEqual(x),expect(e.getAvailablePayloadLength()).toBe(0);const t=new Uint8Array(1);t.set([255],0),e.addBufferToData(t),expect(e.build()).toEqual(x),expect(e.getAvailablePayloadLength()).toBe(0),expect(e.getErrors()).toEqual([new r.DataOverflowError(t.toString())])}),it("error due to subsequent overflow with 1-char ascii",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD).fill(170,0,a.APDU_MAX_PAYLOAD);e.addBufferToData(f),expect(e.build()).toEqual(x),expect(e.getAvailablePayloadLength()).toBe(0);const t="a";e.addAsciiStringToData(t),expect(e.build()).toEqual(x),expect(e.getAvailablePayloadLength()).toBe(0),expect(e.getErrors()).toEqual([new r.DataOverflowError(new TextEncoder().encode(t).toString())])}),it("error due to subsequent overflow with 1-char hexastring",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD).fill(170,0,a.APDU_MAX_PAYLOAD);e.addBufferToData(f),expect(e.build()).toEqual(x),expect(e.getAvailablePayloadLength()).toBe(0),e.addHexaStringToData("0xB4").addHexaStringToData("e1"),expect(e.build()).toEqual(x),expect(e.getAvailablePayloadLength()).toBe(0),expect(e.getErrors()).toEqual([new r.DataOverflowError("180"),new r.DataOverflowError("225")])}),it("error due to empty values",()=>{const f="";e.addHexaStringToData(f).encodeInLVFromHexa(f),expect(e.build()).toEqual(d),expect(e.getAvailablePayloadLength()).toBe(a.APDU_MAX_PAYLOAD),expect(e.getErrors()).toEqual([new r.HexaStringEncodeError(f),new r.HexaStringEncodeError(f)])}),it("error due to subsequent overflow with 1-char LV",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD-1).fill(170,0,a.APDU_MAX_PAYLOAD-1);e.addBufferToData(f),expect(e.build()).toEqual(s),expect(e.getAvailablePayloadLength()).toBe(1);const t="n",o="e1",n=new Uint8Array(1);n.set([255],0),e.encodeInLVFromAscii(t).encodeInLVFromHexa(o).encodeInLVFromBuffer(n),expect(e.build()).toEqual(s),expect(e.getAvailablePayloadLength()).toBe(1),expect(e.getErrors()).toEqual([new r.DataOverflowError(t),new r.DataOverflowError(o),new r.DataOverflowError(n.toString())])})})});
1
+ "use strict";var c=require("../../utils/HexaString"),a=require("./ApduBuilder"),r=require("./AppBuilderError"),x=require("./ByteArrayBuilder");const d=new Uint8Array([]),g=new Uint8Array([1]),y=new Uint8Array([128,129,130,131,132]),A=new Uint8Array([133,134,135,136]),E=new Uint8Array([3,161,162,163]),p=new Uint8Array([5,109,97,109,97,110]),b=new Uint8Array([2,240,241]),h=new Uint8Array([1,51,2,1,35,69,103,128,129,130,131,132,133,134,135,136,3,161,162,163,5,109,97,109,97,110,2,240,241]),l=new Uint8Array([...Array(255).fill(170)]),s=new Uint8Array([...Array(254).fill(170)]);let e;describe("ByteArrayBuilder",()=>{const i=(f,t,o,n)=>{if(n)switch(o){case 2:e.add16BitIntToData(f,t);break;case 4:e.add32BitIntToData(f,t);break;case 8:e.add64BitIntToData(f,t);break;case 16:e.add128BitIntToData(f,t);break;case 32:e.add256BitIntToData(f,t);break}else switch(o){case 2:e.add16BitUIntToData(f,t);break;case 4:e.add32BitUIntToData(f,t);break;case 8:e.add64BitUIntToData(f,t);break;case 16:e.add128BitUIntToData(f,t);break;case 32:e.add256BitUIntToData(f,t);break}};describe("clean",()=>{beforeEach(()=>{e=new x.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it("should create an instance",()=>{expect(e).toBeDefined(),expect(e).toBeInstanceOf(x.ByteArrayBuilder)})}),describe("simple",()=>{beforeEach(()=>{e=new x.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it("should serialize with an empty body",()=>{expect(e.build()).toEqual(d)}),it("should serialize with an single byte body",()=>{e=new x.ByteArrayBuilder(1),e.add8BitUIntToData(1),expect(e.build()).toEqual(g),expect(e.getErrors()).toEqual([])}),it.each([[2,!1,!0,13058,"3302"],[2,!1,!1,0x3302n,"0233"],[2,!0,!0,4200n,"1068"],[2,!0,!0,-4200n,"ef98"],[2,!0,!1,4200,"6810"],[2,!0,!1,-4200,"98ef"],[4,!1,!0,0x01234567n,"01234567"],[4,!1,!1,0x01234567n,"67452301"],[4,!0,!0,123456789,"075bcd15"],[4,!0,!0,-123456789,"f8a432eb"],[4,!0,!1,123456789,"15cd5b07"],[4,!0,!1,-123456789,"eb32a4f8"],[8,!1,!0,14147778004927559n,"0032435442584447"],[8,!1,!1,14147778004927559n,"4744584254433200"],[8,!0,!0,14147778004927559n,"0032435442584447"],[8,!0,!0,-14147778004927559n,"ffcdbcabbda7bbb9"],[8,!0,!1,14147778004927559n,"4744584254433200"],[8,!0,!1,-14147778004927559n,"b9bba7bdabbccdff"],[16,!1,!0,0x00324354425844470032435442584447n,"00324354425844470032435442584447"],[16,!1,!1,0x00324354425844470032435442584447n,"47445842544332004744584254433200"],[16,!0,!0,0x00324354425844470032435442584447n,"00324354425844470032435442584447"],[16,!0,!0,-0x00324354425844470032435442584447n,"ffcdbcabbda7bbb8ffcdbcabbda7bbb9"],[16,!0,!1,0x00324354425844470032435442584447n,"47445842544332004744584254433200"],[16,!0,!1,-0x00324354425844470032435442584447n,"b9bba7bdabbccdffb8bba7bdabbccdff"],[32,!1,!0,0x0032435442584447003243544258444700324354425844470032435442584447n,"0032435442584447003243544258444700324354425844470032435442584447"],[32,!1,!1,0x0032435442584447003243544258444700324354425844470032435442584447n,"4744584254433200474458425443320047445842544332004744584254433200"],[32,!0,!0,0x0032435442584447003243544258444700324354425844470032435442584447n,"0032435442584447003243544258444700324354425844470032435442584447"],[32,!0,!0,-0x0032435442584447003243544258444700324354425844470032435442584447n,"ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb9"],[32,!0,!1,0x0032435442584447003243544258444700324354425844470032435442584447n,"4744584254433200474458425443320047445842544332004744584254433200"],[32,!0,!1,-0x0032435442584447003243544258444700324354425844470032435442584447n,"b9bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdff"]])("serialize the following number: size %i, signed %s, bigEndian %s, value %i, expected %s",(f,t,o,n,u)=>{e=new x.ByteArrayBuilder(f),i(n,o,f,t),expect(e.build()).toEqual((0,c.hexaStringToBuffer)(u)),expect(e.getErrors()).toEqual([]),e=new x.ByteArrayBuilder(f-1),i(n,o,f,t),expect(e.getErrors().length).toEqual(1),expect(e.build()).toEqual(Uint8Array.from([]))}),it.each([[2,!1,!0,0xffffn,"ffff"],[2,!0,!0,0x7fffn,"7fff"],[2,!0,!0,-0x8000n,"8000"],[4,!1,!0,0xffffffffn,"ffffffff"],[4,!0,!0,0x7fffffffn,"7fffffff"],[4,!0,!0,-0x80000000n,"80000000"],[8,!1,!0,0xffffffffffffffffn,"ffffffffffffffff"],[8,!0,!0,0x7fffffffffffffffn,"7fffffffffffffff"],[8,!0,!0,-0x8000000000000000n,"8000000000000000"],[16,!1,!0,0xffffffffffffffffffffffffffffffffn,"ffffffffffffffffffffffffffffffff"],[16,!0,!0,0x7fffffffffffffffffffffffffffffffn,"7fffffffffffffffffffffffffffffff"],[16,!0,!0,-0x80000000000000000000000000000000n,"80000000000000000000000000000000"],[32,!1,!0,0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],[32,!0,!0,0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"],[32,!0,!0,-0x8000000000000000000000000000000000000000000000000000000000000000n,"8000000000000000000000000000000000000000000000000000000000000000"]])("serialize the number to the limit: size %i, signed %s, bigEndian %s, value %i, expected %s",(f,t,o,n,u)=>{e=new x.ByteArrayBuilder(f),i(n,o,f,t),expect(e.build()).toEqual((0,c.hexaStringToBuffer)(u)),expect(e.getErrors()).toEqual([])}),it("Serialize from float to bigint",()=>{e=new x.ByteArrayBuilder(4),e.add32BitIntToData(1234567893e-1,!1),expect(e.getErrors().length).toEqual(1),expect(e.build()).toEqual(Uint8Array.from([]))}),it("should serialize with an 5 byte body from an hexastring",()=>{e.addHexaStringToData("0x8081828384"),expect(e.build()).toEqual(y),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body from an hexastring without '0x'",()=>{e.addHexaStringToData("85868788"),expect(e.build()).toEqual(A),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from an hexastring",()=>{e.encodeInLVFromHexa("0xA1A2A3"),expect(e.build()).toEqual(E),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from an ascci string",()=>{e.encodeInLVFromAscii("maman"),expect(e.build()).toEqual(p),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from a buffer",()=>{const f=new Uint8Array([240,241]);e.encodeInLVFromBuffer(f),expect(e.build()).toEqual(b),expect(e.getErrors()).toEqual([])}),it("should serialize with an 4 byte body LV encoded from a buffer",()=>{const f=new Uint8Array([240,241]);e.encodeInLVFromBuffer(f),expect(e.build()).toEqual(b),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an ascii string",()=>{e.encodeInTLVFromAscii(5,"coucou"),expect(e.build()).toEqual(Uint8Array.from([5,6,99,111,117,99,111,117])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an hexastring",()=>{e.encodeInTLVFromHexa(5,"0xA1A2A3"),expect(e.build()).toEqual(Uint8Array.from([5,3,161,162,163])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from a buffer",()=>{e.encodeInTLVFromBuffer(6,Uint8Array.from([161,162,163,164])),expect(e.build()).toEqual(Uint8Array.from([6,4,161,162,163,164])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an uint8",()=>{e.encodeInTLVFromUInt8(6,86),expect(e.build()).toEqual(Uint8Array.from([6,1,86])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an uint16",()=>{e.encodeInTLVFromUInt16(6,13398),expect(e.build()).toEqual(Uint8Array.from([6,2,52,86])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an uint32",()=>{e.encodeInTLVFromUInt32(6,2417112150),expect(e.build()).toEqual(Uint8Array.from([6,4,144,18,52,86])),expect(e.getErrors()).toEqual([])}),it("should serialize with an TLV encoded from an uint64",()=>{e.encodeInTLVFromUInt64(6,95075813176406),expect(e.build()).toEqual(Uint8Array.from([6,8,0,0,86,120,144,18,52,86])),expect(e.getErrors()).toEqual([])}),it("should serialize with an complete body of 0xAA",()=>{const f=new Uint8Array(255).fill(170,0,255);e.addBufferToData(f),expect(e.build()).toEqual(l),expect(e.getErrors()).toEqual([])})}),describe("mixed",()=>{beforeEach(()=>{e=new x.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it("should serialize with all previous field",()=>{let f=a.APDU_MAX_PAYLOAD;e.add8BitUIntToData(1),f--,expect(e.getAvailablePayloadLength()).toBe(f),e.add16BitUIntToData(13058),f-=2,expect(e.getAvailablePayloadLength()).toBe(f),e.add32BitUIntToData(19088743),f-=4,expect(e.getAvailablePayloadLength()).toBe(f),e.addHexaStringToData("0x8081828384"),f-=5,expect(e.getAvailablePayloadLength()).toBe(f),e.addHexaStringToData("85868788"),f-=4,expect(e.getAvailablePayloadLength()).toBe(f),e.encodeInLVFromHexa("0xA1A2A3"),f-=4,expect(e.getAvailablePayloadLength()).toBe(f),e.encodeInLVFromAscii("maman"),f-=6,expect(e.getAvailablePayloadLength()).toBe(f);const t=new Uint8Array([240,241]);e.encodeInLVFromBuffer(t),f-=3,expect(e.getAvailablePayloadLength()).toBe(f),expect(e.build()).toEqual(h)})}),describe("error",()=>{beforeEach(()=>{e=new x.ByteArrayBuilder(a.APDU_MAX_PAYLOAD)}),it.each([[2,!1,!0,0x10000n],[2,!0,!0,0x8000n],[2,!0,!0,-0x8001n],[4,!1,!0,0x100000000n],[4,!0,!0,0x80000000n],[4,!0,!0,-0x80000001n],[8,!1,!0,0x10000000000000000n],[8,!0,!0,0x8000000000000000n],[8,!0,!0,-0x8000000000000001n]])("serialize the number overflowed: size %i, signed %s, bigEndian %s, value %i",(f,t,o,n)=>{e=new x.ByteArrayBuilder(f),i(n,o,f,t),expect(e.getErrors().length).toEqual(1),expect(e.build()).toEqual(Uint8Array.from([]))}),it("error due to a string not well coded",()=>{e.addHexaStringToData(":08081828384").addHexaStringToData("80818n8384").addHexaStringToData("808182838z"),expect(e.build()).toEqual(d),expect(e.getAvailablePayloadLength()).toBe(a.APDU_MAX_PAYLOAD),expect(e.getErrors()).toEqual([new r.HexaStringEncodeError(":08081828384"),new r.HexaStringEncodeError("80818n8384"),new r.HexaStringEncodeError("808182838z")])}),it("error due direct overflow",()=>{const f=new Uint8Array(256).fill(170,0,256);e.addBufferToData(f),expect(e.build()).toEqual(d),expect(e.getAvailablePayloadLength()).toBe(a.APDU_MAX_PAYLOAD),expect(e.getErrors()).toEqual([new r.DataOverflowError(f.toString())])}),it("error due to subsequent overflow with 1-byte array",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD).fill(170,0,a.APDU_MAX_PAYLOAD);e.addBufferToData(f),expect(e.build()).toEqual(l),expect(e.getAvailablePayloadLength()).toBe(0);const t=new Uint8Array(1);t.set([255],0),e.addBufferToData(t),expect(e.build()).toEqual(l),expect(e.getAvailablePayloadLength()).toBe(0),expect(e.getErrors()).toEqual([new r.DataOverflowError(t.toString())])}),it("error due to subsequent overflow with 1-char ascii",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD).fill(170,0,a.APDU_MAX_PAYLOAD);e.addBufferToData(f),expect(e.build()).toEqual(l),expect(e.getAvailablePayloadLength()).toBe(0);const t="a";e.addAsciiStringToData(t),expect(e.build()).toEqual(l),expect(e.getAvailablePayloadLength()).toBe(0),expect(e.getErrors()).toEqual([new r.DataOverflowError(new TextEncoder().encode(t).toString())])}),it("error due to subsequent overflow with 1-char hexastring",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD).fill(170,0,a.APDU_MAX_PAYLOAD);e.addBufferToData(f),expect(e.build()).toEqual(l),expect(e.getAvailablePayloadLength()).toBe(0),e.addHexaStringToData("0xB4").addHexaStringToData("e1"),expect(e.build()).toEqual(l),expect(e.getAvailablePayloadLength()).toBe(0),expect(e.getErrors()).toEqual([new r.DataOverflowError("180"),new r.DataOverflowError("225")])}),it("error due to empty values",()=>{const f="";e.addHexaStringToData(f).encodeInLVFromHexa(f),expect(e.build()).toEqual(d),expect(e.getAvailablePayloadLength()).toBe(a.APDU_MAX_PAYLOAD),expect(e.getErrors()).toEqual([new r.HexaStringEncodeError(f),new r.HexaStringEncodeError(f)])}),it("error due to subsequent overflow with 1-char LV",()=>{const f=new Uint8Array(a.APDU_MAX_PAYLOAD-1).fill(170,0,a.APDU_MAX_PAYLOAD-1);e.addBufferToData(f),expect(e.build()).toEqual(s),expect(e.getAvailablePayloadLength()).toBe(1);const t="n",o="e1",n=new Uint8Array(1);n.set([255],0),e.encodeInLVFromAscii(t).encodeInLVFromHexa(o).encodeInLVFromBuffer(n),expect(e.build()).toEqual(s),expect(e.getAvailablePayloadLength()).toBe(1),expect(e.getErrors()).toEqual([new r.DataOverflowError(t),new r.DataOverflowError(o),new r.DataOverflowError(n.toString())])})})});
2
2
  //# sourceMappingURL=ByteArrayBuilder.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/apdu/utils/ByteArrayBuilder.test.ts"],
4
- "sourcesContent": ["import { hexaStringToBuffer } from \"@api/utils/HexaString\";\n\nimport { APDU_MAX_PAYLOAD } from \"./ApduBuilder\";\nimport { DataOverflowError, HexaStringEncodeError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nconst COMMAND_NO_BODY = new Uint8Array([]);\n\nconst COMMAND_BODY_SINGLE = new Uint8Array([0x01]);\n\nconst COMMAND_BODY_HEXA1 = new Uint8Array([0x80, 0x81, 0x82, 0x83, 0x84]);\n\nconst COMMAND_BODY_HEXA2 = new Uint8Array([0x85, 0x86, 0x87, 0x88]);\n\nconst COMMAND_BODY_LV_HEXA = new Uint8Array([0x03, 0xa1, 0xa2, 0xa3]);\n\nconst COMMAND_BODY_LV_ASCII = new Uint8Array([\n 0x05, 0x6d, 0x61, 0x6d, 0x61, 0x6e,\n]);\n\nconst COMMAND_BODY_LV_ARRAY = new Uint8Array([0x02, 0xf0, 0xf1]);\n\nconst COMMAND_BODY_COMBINED = new Uint8Array([\n 0x01, 0x33, 0x02, 0x01, 0x23, 0x45, 0x67, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,\n 0x86, 0x87, 0x88, 0x03, 0xa1, 0xa2, 0xa3, 0x05, 0x6d, 0x61, 0x6d, 0x61, 0x6e,\n 0x02, 0xf0, 0xf1,\n]);\n\nconst COMMAND_BODY_MAX = new Uint8Array([...Array<number>(255).fill(0xaa)]);\n\nconst COMMAND_BODY_NEARLY = new Uint8Array([...Array<number>(254).fill(0xaa)]);\n\nlet builder: ByteArrayBuilder;\n\ndescribe(\"ByteArrayBuilder\", () => {\n const builderAddNumber = (\n num: number | bigint,\n bigEndian: boolean,\n sizeInBits: number,\n signed: boolean,\n ) => {\n if (signed) {\n switch (sizeInBits) {\n case 2:\n builder.add16BitIntToData(num, bigEndian);\n break;\n case 4:\n builder.add32BitIntToData(num, bigEndian);\n break;\n case 8:\n builder.add64BitIntToData(num, bigEndian);\n break;\n case 16:\n builder.add128BitIntToData(num, bigEndian);\n break;\n case 32:\n builder.add256BitIntToData(num, bigEndian);\n break;\n }\n } else {\n switch (sizeInBits) {\n case 2:\n builder.add16BitUIntToData(num, bigEndian);\n break;\n case 4:\n builder.add32BitUIntToData(num, bigEndian);\n break;\n case 8:\n builder.add64BitUIntToData(num, bigEndian);\n break;\n case 16:\n builder.add128BitUIntToData(num, bigEndian);\n break;\n case 32:\n builder.add256BitUIntToData(num, bigEndian);\n break;\n }\n }\n };\n\n describe(\"clean\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it(\"should create an instance\", () => {\n expect(builder).toBeDefined();\n expect(builder).toBeInstanceOf(ByteArrayBuilder);\n });\n });\n\n describe(\"simple\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it(\"should serialize with an empty body\", () => {\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n });\n\n it(\"should serialize with an single byte body\", () => {\n builder = new ByteArrayBuilder(1);\n builder.add8BitUIntToData(0x01);\n expect(builder.build()).toEqual(COMMAND_BODY_SINGLE);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it.each([\n [2, false, true, 0x3302, \"3302\"],\n [2, false, false, 0x3302n, \"0233\"],\n [2, true, true, 4200n, \"1068\"],\n [2, true, true, -4200n, \"ef98\"],\n [2, true, false, 4200, \"6810\"],\n [2, true, false, -4200, \"98ef\"],\n [4, false, true, 0x01234567n, \"01234567\"],\n [4, false, false, 0x01234567n, \"67452301\"],\n [4, true, true, 123456789, \"075bcd15\"],\n [4, true, true, -123456789, \"f8a432eb\"],\n [4, true, false, 123456789, \"15cd5b07\"],\n [4, true, false, -123456789, \"eb32a4f8\"],\n [8, false, true, 14147778004927559n, \"0032435442584447\"],\n [8, false, false, 14147778004927559n, \"4744584254433200\"],\n [8, true, true, 14147778004927559n, \"0032435442584447\"],\n [8, true, true, -14147778004927559n, \"ffcdbcabbda7bbb9\"],\n [8, true, false, 14147778004927559n, \"4744584254433200\"],\n [8, true, false, -14147778004927559n, \"b9bba7bdabbccdff\"],\n [\n 16,\n false,\n true,\n 0x00324354425844470032435442584447n,\n \"00324354425844470032435442584447\",\n ],\n [\n 16,\n false,\n false,\n 0x00324354425844470032435442584447n,\n \"47445842544332004744584254433200\",\n ],\n [\n 16,\n true,\n true,\n 0x00324354425844470032435442584447n,\n \"00324354425844470032435442584447\",\n ],\n [\n 16,\n true,\n true,\n -0x00324354425844470032435442584447n,\n \"ffcdbcabbda7bbb8ffcdbcabbda7bbb9\",\n ],\n [\n 16,\n true,\n false,\n 0x00324354425844470032435442584447n,\n \"47445842544332004744584254433200\",\n ],\n [\n 16,\n true,\n false,\n -0x00324354425844470032435442584447n,\n \"b9bba7bdabbccdffb8bba7bdabbccdff\",\n ],\n [\n 32,\n false,\n true,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"0032435442584447003243544258444700324354425844470032435442584447\",\n ],\n [\n 32,\n false,\n false,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"4744584254433200474458425443320047445842544332004744584254433200\",\n ],\n [\n 32,\n true,\n true,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"0032435442584447003243544258444700324354425844470032435442584447\",\n ],\n [\n 32,\n true,\n true,\n -0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb9\",\n ],\n [\n 32,\n true,\n false,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"4744584254433200474458425443320047445842544332004744584254433200\",\n ],\n [\n 32,\n true,\n false,\n -0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"b9bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdff\",\n ],\n ])(\n \"serialize the following number: size %i, signed %s, bigEndian %s, value %i, expected %s\",\n (sizeInBits, signed, bigEndian, input, output) => {\n builder = new ByteArrayBuilder(sizeInBits);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.build()).toEqual(hexaStringToBuffer(output));\n expect(builder.getErrors()).toEqual([]);\n\n // Retry with a buffer too small\n builder = new ByteArrayBuilder(sizeInBits - 1);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.getErrors().length).toEqual(1);\n expect(builder.build()).toEqual(Uint8Array.from([]));\n },\n );\n\n it.each([\n [2, false, true, 0xffffn, \"ffff\"],\n [2, true, true, 0x7fffn, \"7fff\"],\n [2, true, true, -0x8000n, \"8000\"],\n [4, false, true, 0xffffffffn, \"ffffffff\"],\n [4, true, true, 0x7fffffffn, \"7fffffff\"],\n [4, true, true, -0x80000000n, \"80000000\"],\n [8, false, true, 0xffffffffffffffffn, \"ffffffffffffffff\"],\n [8, true, true, 0x7fffffffffffffffn, \"7fffffffffffffff\"],\n [8, true, true, -0x8000000000000000n, \"8000000000000000\"],\n [\n 16,\n false,\n true,\n 0xffffffffffffffffffffffffffffffffn,\n \"ffffffffffffffffffffffffffffffff\",\n ],\n [\n 16,\n true,\n true,\n 0x7fffffffffffffffffffffffffffffffn,\n \"7fffffffffffffffffffffffffffffff\",\n ],\n [\n 16,\n true,\n true,\n -0x80000000000000000000000000000000n,\n \"80000000000000000000000000000000\",\n ],\n [\n 32,\n false,\n true,\n 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,\n \"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\",\n ],\n [\n 32,\n true,\n true,\n 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,\n \"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\",\n ],\n [\n 32,\n true,\n true,\n -0x8000000000000000000000000000000000000000000000000000000000000000n,\n \"8000000000000000000000000000000000000000000000000000000000000000\",\n ],\n ])(\n \"serialize the number to the limit: size %i, signed %s, bigEndian %s, value %i, expected %s\",\n (sizeInBits, signed, bigEndian, input, output) => {\n builder = new ByteArrayBuilder(sizeInBits);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.build()).toEqual(hexaStringToBuffer(output));\n expect(builder.getErrors()).toEqual([]);\n },\n );\n\n it(\"Serialize from float to bigint\", () => {\n builder = new ByteArrayBuilder(4);\n builder.add32BitIntToData(123456789.3, false);\n expect(builder.getErrors().length).toEqual(1);\n expect(builder.build()).toEqual(Uint8Array.from([]));\n });\n\n it(\"should serialize with an 5 byte body from an hexastring\", () => {\n builder.addHexaStringToData(\"0x8081828384\");\n expect(builder.build()).toEqual(COMMAND_BODY_HEXA1);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body from an hexastring without '0x'\", () => {\n builder.addHexaStringToData(\"85868788\");\n expect(builder.build()).toEqual(COMMAND_BODY_HEXA2);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from an hexastring\", () => {\n builder.encodeInLVFromHexa(\"0xA1A2A3\");\n expect(builder.build()).toEqual(COMMAND_BODY_LV_HEXA);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from an ascci string\", () => {\n builder.encodeInLVFromAscii(\"maman\");\n expect(builder.build()).toEqual(COMMAND_BODY_LV_ASCII);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from a buffer\", () => {\n const myarray = new Uint8Array([0xf0, 0xf1]);\n builder.encodeInLVFromBuffer(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_LV_ARRAY);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from a buffer\", () => {\n const myarray = new Uint8Array([0xf0, 0xf1]);\n builder.encodeInLVFromBuffer(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_LV_ARRAY);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an hexastring\", () => {\n builder.encodeInTLVFromHexa(0x05, \"0xA1A2A3\");\n expect(builder.build()).toEqual(\n Uint8Array.from([0x05, 0x03, 0xa1, 0xa2, 0xa3]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from a buffer\", () => {\n builder.encodeInTLVFromBuffer(\n 0x06,\n Uint8Array.from([0xa1, 0xa2, 0xa3, 0xa4]),\n );\n expect(builder.build()).toEqual(\n Uint8Array.from([0x06, 0x04, 0xa1, 0xa2, 0xa3, 0xa4]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an uint64\", () => {\n builder.encodeInTLVFromUInt64(0x06, 0x567890123456);\n expect(builder.build()).toEqual(\n Uint8Array.from([\n 0x06, 0x08, 0x00, 0x00, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,\n ]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an complete body of 0xAA\", () => {\n const myarray = new Uint8Array(255).fill(0xaa, 0, 255);\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getErrors()).toEqual([]);\n });\n });\n\n describe(\"mixed\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it(\"should serialize with all previous field\", () => {\n let available = APDU_MAX_PAYLOAD;\n builder.add8BitUIntToData(0x01);\n available--;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.add16BitUIntToData(0x3302);\n available -= 2;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.add32BitUIntToData(0x01234567);\n available -= 4;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.addHexaStringToData(\"0x8081828384\");\n available -= 5;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.addHexaStringToData(\"85868788\");\n available -= 4;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.encodeInLVFromHexa(\"0xA1A2A3\");\n available -= 4;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.encodeInLVFromAscii(\"maman\");\n available -= 6;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n const myarray = new Uint8Array([0xf0, 0xf1]);\n builder.encodeInLVFromBuffer(myarray);\n available -= 3;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n expect(builder.build()).toEqual(COMMAND_BODY_COMBINED);\n });\n });\n\n describe(\"error\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it.each([\n [2, false, true, 0x10000n],\n [2, true, true, 0x8000n],\n [2, true, true, -0x8001n],\n [4, false, true, 0x100000000n],\n [4, true, true, 0x80000000n],\n [4, true, true, -0x80000001n],\n [8, false, true, 0x10000000000000000n],\n [8, true, true, 0x8000000000000000n],\n [8, true, true, -0x8000000000000001n],\n ])(\n \"serialize the number overflowed: size %i, signed %s, bigEndian %s, value %i\",\n (sizeInBits, signed, bigEndian, input) => {\n builder = new ByteArrayBuilder(sizeInBits);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.getErrors().length).toEqual(1);\n expect(builder.build()).toEqual(Uint8Array.from([]));\n },\n );\n\n it(\"error due to a string not well coded\", () => {\n builder\n .addHexaStringToData(\":08081828384\")\n .addHexaStringToData(\"80818n8384\")\n .addHexaStringToData(\"808182838z\");\n\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n expect(builder.getAvailablePayloadLength()).toBe(APDU_MAX_PAYLOAD);\n expect(builder.getErrors()).toEqual([\n new HexaStringEncodeError(\":08081828384\"),\n new HexaStringEncodeError(\"80818n8384\"),\n new HexaStringEncodeError(\"808182838z\"),\n ]);\n });\n\n it(\"error due direct overflow\", () => {\n const myarray = new Uint8Array(256).fill(0xaa, 0, 256);\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n expect(builder.getAvailablePayloadLength()).toBe(APDU_MAX_PAYLOAD);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(myarray.toString()),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-byte array\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n\n const mybuffer = new Uint8Array(1);\n mybuffer.set([0xff], 0);\n\n builder.addBufferToData(mybuffer);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(mybuffer.toString()),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-char ascii\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n\n const mystring = \"a\";\n\n builder.addAsciiStringToData(mystring);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(new TextEncoder().encode(mystring).toString()),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-char hexastring\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n\n const firstString = \"0xB4\";\n const secondString = \"e1\";\n\n builder\n .addHexaStringToData(firstString)\n .addHexaStringToData(secondString);\n\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError((0xb4).toString()),\n new DataOverflowError((0xe1).toString()),\n ]);\n });\n\n it(\"error due to empty values\", () => {\n const mystring = \"\";\n\n builder.addHexaStringToData(mystring).encodeInLVFromHexa(mystring);\n\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n expect(builder.getAvailablePayloadLength()).toBe(APDU_MAX_PAYLOAD);\n expect(builder.getErrors()).toEqual([\n new HexaStringEncodeError(mystring),\n new HexaStringEncodeError(mystring),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-char LV\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD - 1).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD - 1,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_NEARLY);\n expect(builder.getAvailablePayloadLength()).toBe(1);\n\n const firstString = \"n\";\n const secondString = \"e1\";\n const mybuffer = new Uint8Array(1);\n mybuffer.set([0xff], 0);\n\n builder\n .encodeInLVFromAscii(firstString)\n .encodeInLVFromHexa(secondString)\n .encodeInLVFromBuffer(mybuffer);\n\n expect(builder.build()).toEqual(COMMAND_BODY_NEARLY);\n expect(builder.getAvailablePayloadLength()).toBe(1);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(firstString),\n new DataOverflowError(secondString),\n new DataOverflowError(mybuffer.toString()),\n ]);\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAAmC,iCAEnCC,EAAiC,yBACjCC,EAAyD,6BACzDC,EAAiC,8BAEjC,MAAMC,EAAkB,IAAI,WAAW,CAAC,CAAC,EAEnCC,EAAsB,IAAI,WAAW,CAAC,CAAI,CAAC,EAE3CC,EAAqB,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,IAAM,GAAI,CAAC,EAElEC,EAAqB,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,GAAI,CAAC,EAE5DC,EAAuB,IAAI,WAAW,CAAC,EAAM,IAAM,IAAM,GAAI,CAAC,EAE9DC,EAAwB,IAAI,WAAW,CAC3C,EAAM,IAAM,GAAM,IAAM,GAAM,GAChC,CAAC,EAEKC,EAAwB,IAAI,WAAW,CAAC,EAAM,IAAM,GAAI,CAAC,EAEzDC,EAAwB,IAAI,WAAW,CAC3C,EAAM,GAAM,EAAM,EAAM,GAAM,GAAM,IAAM,IAAM,IAAM,IAAM,IAAM,IAAM,IACxE,IAAM,IAAM,IAAM,EAAM,IAAM,IAAM,IAAM,EAAM,IAAM,GAAM,IAAM,GAAM,IACxE,EAAM,IAAM,GACd,CAAC,EAEKC,EAAmB,IAAI,WAAW,CAAC,GAAG,MAAc,GAAG,EAAE,KAAK,GAAI,CAAC,CAAC,EAEpEC,EAAsB,IAAI,WAAW,CAAC,GAAG,MAAc,GAAG,EAAE,KAAK,GAAI,CAAC,CAAC,EAE7E,IAAIC,EAEJ,SAAS,mBAAoB,IAAM,CACjC,MAAMC,EAAmB,CACvBC,EACAC,EACAC,EACAC,IACG,CACH,GAAIA,EACF,OAAQD,EAAY,CAClB,IAAK,GACHJ,EAAQ,kBAAkBE,EA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AAC,EAEtBV,EACG,oBAAoBY,CAAW,EAC/B,mBAAmBC,CAAY,EAC/B,qBAAqBH,CAAQ,EAEhC,OAAOV,EAAQ,MAAM,CAAC,EAAE,QAAQD,CAAmB,EACnD,OAAOC,EAAQ,0BAA0B,CAAC,EAAE,KAAK,CAAC,EAClD,OAAOA,EAAQ,UAAU,CAAC,EAAE,QAAQ,CAClC,IAAI,oBAAkBY,CAAW,EACjC,IAAI,oBAAkBC,CAAY,EAClC,IAAI,oBAAkBH,EAAS,SAAS,CAAC,CAC3C,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import { hexaStringToBuffer } from \"@api/utils/HexaString\";\n\nimport { APDU_MAX_PAYLOAD } from \"./ApduBuilder\";\nimport { DataOverflowError, HexaStringEncodeError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nconst COMMAND_NO_BODY = new Uint8Array([]);\n\nconst COMMAND_BODY_SINGLE = new Uint8Array([0x01]);\n\nconst COMMAND_BODY_HEXA1 = new Uint8Array([0x80, 0x81, 0x82, 0x83, 0x84]);\n\nconst COMMAND_BODY_HEXA2 = new Uint8Array([0x85, 0x86, 0x87, 0x88]);\n\nconst COMMAND_BODY_LV_HEXA = new Uint8Array([0x03, 0xa1, 0xa2, 0xa3]);\n\nconst COMMAND_BODY_LV_ASCII = new Uint8Array([\n 0x05, 0x6d, 0x61, 0x6d, 0x61, 0x6e,\n]);\n\nconst COMMAND_BODY_LV_ARRAY = new Uint8Array([0x02, 0xf0, 0xf1]);\n\nconst COMMAND_BODY_COMBINED = new Uint8Array([\n 0x01, 0x33, 0x02, 0x01, 0x23, 0x45, 0x67, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,\n 0x86, 0x87, 0x88, 0x03, 0xa1, 0xa2, 0xa3, 0x05, 0x6d, 0x61, 0x6d, 0x61, 0x6e,\n 0x02, 0xf0, 0xf1,\n]);\n\nconst COMMAND_BODY_MAX = new Uint8Array([...Array<number>(255).fill(0xaa)]);\n\nconst COMMAND_BODY_NEARLY = new Uint8Array([...Array<number>(254).fill(0xaa)]);\n\nlet builder: ByteArrayBuilder;\n\ndescribe(\"ByteArrayBuilder\", () => {\n const builderAddNumber = (\n num: number | bigint,\n bigEndian: boolean,\n sizeInBits: number,\n signed: boolean,\n ) => {\n if (signed) {\n switch (sizeInBits) {\n case 2:\n builder.add16BitIntToData(num, bigEndian);\n break;\n case 4:\n builder.add32BitIntToData(num, bigEndian);\n break;\n case 8:\n builder.add64BitIntToData(num, bigEndian);\n break;\n case 16:\n builder.add128BitIntToData(num, bigEndian);\n break;\n case 32:\n builder.add256BitIntToData(num, bigEndian);\n break;\n }\n } else {\n switch (sizeInBits) {\n case 2:\n builder.add16BitUIntToData(num, bigEndian);\n break;\n case 4:\n builder.add32BitUIntToData(num, bigEndian);\n break;\n case 8:\n builder.add64BitUIntToData(num, bigEndian);\n break;\n case 16:\n builder.add128BitUIntToData(num, bigEndian);\n break;\n case 32:\n builder.add256BitUIntToData(num, bigEndian);\n break;\n }\n }\n };\n\n describe(\"clean\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it(\"should create an instance\", () => {\n expect(builder).toBeDefined();\n expect(builder).toBeInstanceOf(ByteArrayBuilder);\n });\n });\n\n describe(\"simple\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it(\"should serialize with an empty body\", () => {\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n });\n\n it(\"should serialize with an single byte body\", () => {\n builder = new ByteArrayBuilder(1);\n builder.add8BitUIntToData(0x01);\n expect(builder.build()).toEqual(COMMAND_BODY_SINGLE);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it.each([\n [2, false, true, 0x3302, \"3302\"],\n [2, false, false, 0x3302n, \"0233\"],\n [2, true, true, 4200n, \"1068\"],\n [2, true, true, -4200n, \"ef98\"],\n [2, true, false, 4200, \"6810\"],\n [2, true, false, -4200, \"98ef\"],\n [4, false, true, 0x01234567n, \"01234567\"],\n [4, false, false, 0x01234567n, \"67452301\"],\n [4, true, true, 123456789, \"075bcd15\"],\n [4, true, true, -123456789, \"f8a432eb\"],\n [4, true, false, 123456789, \"15cd5b07\"],\n [4, true, false, -123456789, \"eb32a4f8\"],\n [8, false, true, 14147778004927559n, \"0032435442584447\"],\n [8, false, false, 14147778004927559n, \"4744584254433200\"],\n [8, true, true, 14147778004927559n, \"0032435442584447\"],\n [8, true, true, -14147778004927559n, \"ffcdbcabbda7bbb9\"],\n [8, true, false, 14147778004927559n, \"4744584254433200\"],\n [8, true, false, -14147778004927559n, \"b9bba7bdabbccdff\"],\n [\n 16,\n false,\n true,\n 0x00324354425844470032435442584447n,\n \"00324354425844470032435442584447\",\n ],\n [\n 16,\n false,\n false,\n 0x00324354425844470032435442584447n,\n \"47445842544332004744584254433200\",\n ],\n [\n 16,\n true,\n true,\n 0x00324354425844470032435442584447n,\n \"00324354425844470032435442584447\",\n ],\n [\n 16,\n true,\n true,\n -0x00324354425844470032435442584447n,\n \"ffcdbcabbda7bbb8ffcdbcabbda7bbb9\",\n ],\n [\n 16,\n true,\n false,\n 0x00324354425844470032435442584447n,\n \"47445842544332004744584254433200\",\n ],\n [\n 16,\n true,\n false,\n -0x00324354425844470032435442584447n,\n \"b9bba7bdabbccdffb8bba7bdabbccdff\",\n ],\n [\n 32,\n false,\n true,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"0032435442584447003243544258444700324354425844470032435442584447\",\n ],\n [\n 32,\n false,\n false,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"4744584254433200474458425443320047445842544332004744584254433200\",\n ],\n [\n 32,\n true,\n true,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"0032435442584447003243544258444700324354425844470032435442584447\",\n ],\n [\n 32,\n true,\n true,\n -0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb8ffcdbcabbda7bbb9\",\n ],\n [\n 32,\n true,\n false,\n 0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"4744584254433200474458425443320047445842544332004744584254433200\",\n ],\n [\n 32,\n true,\n false,\n -0x0032435442584447003243544258444700324354425844470032435442584447n,\n \"b9bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdffb8bba7bdabbccdff\",\n ],\n ])(\n \"serialize the following number: size %i, signed %s, bigEndian %s, value %i, expected %s\",\n (sizeInBits, signed, bigEndian, input, output) => {\n builder = new ByteArrayBuilder(sizeInBits);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.build()).toEqual(hexaStringToBuffer(output));\n expect(builder.getErrors()).toEqual([]);\n\n // Retry with a buffer too small\n builder = new ByteArrayBuilder(sizeInBits - 1);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.getErrors().length).toEqual(1);\n expect(builder.build()).toEqual(Uint8Array.from([]));\n },\n );\n\n it.each([\n [2, false, true, 0xffffn, \"ffff\"],\n [2, true, true, 0x7fffn, \"7fff\"],\n [2, true, true, -0x8000n, \"8000\"],\n [4, false, true, 0xffffffffn, \"ffffffff\"],\n [4, true, true, 0x7fffffffn, \"7fffffff\"],\n [4, true, true, -0x80000000n, \"80000000\"],\n [8, false, true, 0xffffffffffffffffn, \"ffffffffffffffff\"],\n [8, true, true, 0x7fffffffffffffffn, \"7fffffffffffffff\"],\n [8, true, true, -0x8000000000000000n, \"8000000000000000\"],\n [\n 16,\n false,\n true,\n 0xffffffffffffffffffffffffffffffffn,\n \"ffffffffffffffffffffffffffffffff\",\n ],\n [\n 16,\n true,\n true,\n 0x7fffffffffffffffffffffffffffffffn,\n \"7fffffffffffffffffffffffffffffff\",\n ],\n [\n 16,\n true,\n true,\n -0x80000000000000000000000000000000n,\n \"80000000000000000000000000000000\",\n ],\n [\n 32,\n false,\n true,\n 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,\n \"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\",\n ],\n [\n 32,\n true,\n true,\n 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn,\n \"7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\",\n ],\n [\n 32,\n true,\n true,\n -0x8000000000000000000000000000000000000000000000000000000000000000n,\n \"8000000000000000000000000000000000000000000000000000000000000000\",\n ],\n ])(\n \"serialize the number to the limit: size %i, signed %s, bigEndian %s, value %i, expected %s\",\n (sizeInBits, signed, bigEndian, input, output) => {\n builder = new ByteArrayBuilder(sizeInBits);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.build()).toEqual(hexaStringToBuffer(output));\n expect(builder.getErrors()).toEqual([]);\n },\n );\n\n it(\"Serialize from float to bigint\", () => {\n builder = new ByteArrayBuilder(4);\n builder.add32BitIntToData(123456789.3, false);\n expect(builder.getErrors().length).toEqual(1);\n expect(builder.build()).toEqual(Uint8Array.from([]));\n });\n\n it(\"should serialize with an 5 byte body from an hexastring\", () => {\n builder.addHexaStringToData(\"0x8081828384\");\n expect(builder.build()).toEqual(COMMAND_BODY_HEXA1);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body from an hexastring without '0x'\", () => {\n builder.addHexaStringToData(\"85868788\");\n expect(builder.build()).toEqual(COMMAND_BODY_HEXA2);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from an hexastring\", () => {\n builder.encodeInLVFromHexa(\"0xA1A2A3\");\n expect(builder.build()).toEqual(COMMAND_BODY_LV_HEXA);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from an ascci string\", () => {\n builder.encodeInLVFromAscii(\"maman\");\n expect(builder.build()).toEqual(COMMAND_BODY_LV_ASCII);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from a buffer\", () => {\n const myarray = new Uint8Array([0xf0, 0xf1]);\n builder.encodeInLVFromBuffer(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_LV_ARRAY);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an 4 byte body LV encoded from a buffer\", () => {\n const myarray = new Uint8Array([0xf0, 0xf1]);\n builder.encodeInLVFromBuffer(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_LV_ARRAY);\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an ascii string\", () => {\n builder.encodeInTLVFromAscii(0x05, \"coucou\");\n expect(builder.build()).toEqual(\n Uint8Array.from([0x05, 0x06, 0x63, 0x6f, 0x75, 0x63, 0x6f, 0x75]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an hexastring\", () => {\n builder.encodeInTLVFromHexa(0x05, \"0xA1A2A3\");\n expect(builder.build()).toEqual(\n Uint8Array.from([0x05, 0x03, 0xa1, 0xa2, 0xa3]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from a buffer\", () => {\n builder.encodeInTLVFromBuffer(\n 0x06,\n Uint8Array.from([0xa1, 0xa2, 0xa3, 0xa4]),\n );\n expect(builder.build()).toEqual(\n Uint8Array.from([0x06, 0x04, 0xa1, 0xa2, 0xa3, 0xa4]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an uint8\", () => {\n builder.encodeInTLVFromUInt8(0x06, 0x56);\n expect(builder.build()).toEqual(Uint8Array.from([0x06, 0x01, 0x56]));\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an uint16\", () => {\n builder.encodeInTLVFromUInt16(0x06, 0x3456);\n expect(builder.build()).toEqual(\n Uint8Array.from([0x06, 0x02, 0x34, 0x56]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an uint32\", () => {\n builder.encodeInTLVFromUInt32(0x06, 0x90123456);\n expect(builder.build()).toEqual(\n Uint8Array.from([0x06, 0x04, 0x90, 0x12, 0x34, 0x56]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an TLV encoded from an uint64\", () => {\n builder.encodeInTLVFromUInt64(0x06, 0x567890123456);\n expect(builder.build()).toEqual(\n Uint8Array.from([\n 0x06, 0x08, 0x00, 0x00, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,\n ]),\n );\n expect(builder.getErrors()).toEqual([]);\n });\n\n it(\"should serialize with an complete body of 0xAA\", () => {\n const myarray = new Uint8Array(255).fill(0xaa, 0, 255);\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getErrors()).toEqual([]);\n });\n });\n\n describe(\"mixed\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it(\"should serialize with all previous field\", () => {\n let available = APDU_MAX_PAYLOAD;\n builder.add8BitUIntToData(0x01);\n available--;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.add16BitUIntToData(0x3302);\n available -= 2;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.add32BitUIntToData(0x01234567);\n available -= 4;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.addHexaStringToData(\"0x8081828384\");\n available -= 5;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.addHexaStringToData(\"85868788\");\n available -= 4;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.encodeInLVFromHexa(\"0xA1A2A3\");\n available -= 4;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n builder.encodeInLVFromAscii(\"maman\");\n available -= 6;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n const myarray = new Uint8Array([0xf0, 0xf1]);\n builder.encodeInLVFromBuffer(myarray);\n available -= 3;\n expect(builder.getAvailablePayloadLength()).toBe(available);\n\n expect(builder.build()).toEqual(COMMAND_BODY_COMBINED);\n });\n });\n\n describe(\"error\", () => {\n beforeEach(() => {\n builder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n });\n\n it.each([\n [2, false, true, 0x10000n],\n [2, true, true, 0x8000n],\n [2, true, true, -0x8001n],\n [4, false, true, 0x100000000n],\n [4, true, true, 0x80000000n],\n [4, true, true, -0x80000001n],\n [8, false, true, 0x10000000000000000n],\n [8, true, true, 0x8000000000000000n],\n [8, true, true, -0x8000000000000001n],\n ])(\n \"serialize the number overflowed: size %i, signed %s, bigEndian %s, value %i\",\n (sizeInBits, signed, bigEndian, input) => {\n builder = new ByteArrayBuilder(sizeInBits);\n builderAddNumber(input, bigEndian, sizeInBits, signed);\n expect(builder.getErrors().length).toEqual(1);\n expect(builder.build()).toEqual(Uint8Array.from([]));\n },\n );\n\n it(\"error due to a string not well coded\", () => {\n builder\n .addHexaStringToData(\":08081828384\")\n .addHexaStringToData(\"80818n8384\")\n .addHexaStringToData(\"808182838z\");\n\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n expect(builder.getAvailablePayloadLength()).toBe(APDU_MAX_PAYLOAD);\n expect(builder.getErrors()).toEqual([\n new HexaStringEncodeError(\":08081828384\"),\n new HexaStringEncodeError(\"80818n8384\"),\n new HexaStringEncodeError(\"808182838z\"),\n ]);\n });\n\n it(\"error due direct overflow\", () => {\n const myarray = new Uint8Array(256).fill(0xaa, 0, 256);\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n expect(builder.getAvailablePayloadLength()).toBe(APDU_MAX_PAYLOAD);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(myarray.toString()),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-byte array\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n\n const mybuffer = new Uint8Array(1);\n mybuffer.set([0xff], 0);\n\n builder.addBufferToData(mybuffer);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(mybuffer.toString()),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-char ascii\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n\n const mystring = \"a\";\n\n builder.addAsciiStringToData(mystring);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(new TextEncoder().encode(mystring).toString()),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-char hexastring\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n\n const firstString = \"0xB4\";\n const secondString = \"e1\";\n\n builder\n .addHexaStringToData(firstString)\n .addHexaStringToData(secondString);\n\n expect(builder.build()).toEqual(COMMAND_BODY_MAX);\n expect(builder.getAvailablePayloadLength()).toBe(0);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError((0xb4).toString()),\n new DataOverflowError((0xe1).toString()),\n ]);\n });\n\n it(\"error due to empty values\", () => {\n const mystring = \"\";\n\n builder.addHexaStringToData(mystring).encodeInLVFromHexa(mystring);\n\n expect(builder.build()).toEqual(COMMAND_NO_BODY);\n expect(builder.getAvailablePayloadLength()).toBe(APDU_MAX_PAYLOAD);\n expect(builder.getErrors()).toEqual([\n new HexaStringEncodeError(mystring),\n new HexaStringEncodeError(mystring),\n ]);\n });\n\n it(\"error due to subsequent overflow with 1-char LV\", () => {\n const myarray = new Uint8Array(APDU_MAX_PAYLOAD - 1).fill(\n 0xaa,\n 0,\n APDU_MAX_PAYLOAD - 1,\n );\n builder.addBufferToData(myarray);\n expect(builder.build()).toEqual(COMMAND_BODY_NEARLY);\n expect(builder.getAvailablePayloadLength()).toBe(1);\n\n const firstString = \"n\";\n const secondString = \"e1\";\n const mybuffer = new Uint8Array(1);\n mybuffer.set([0xff], 0);\n\n builder\n .encodeInLVFromAscii(firstString)\n .encodeInLVFromHexa(secondString)\n .encodeInLVFromBuffer(mybuffer);\n\n expect(builder.build()).toEqual(COMMAND_BODY_NEARLY);\n expect(builder.getAvailablePayloadLength()).toBe(1);\n expect(builder.getErrors()).toEqual([\n new DataOverflowError(firstString),\n new DataOverflowError(secondString),\n new DataOverflowError(mybuffer.toString()),\n ]);\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAAmC,iCAEnCC,EAAiC,yBACjCC,EAAyD,6BACzDC,EAAiC,8BAEjC,MAAMC,EAAkB,IAAI,WAAW,CAAC,CAAC,EAEnCC,EAAsB,IAAI,WAAW,CAAC,CAAI,CAAC,EAE3CC,EAAqB,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,IAAM,GAAI,CAAC,EAElEC,EAAqB,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,GAAI,CAAC,EAE5DC,EAAuB,IAAI,WAAW,CAAC,EAAM,IAAM,IAAM,GAAI,CAAC,EAE9DC,EAAwB,IAAI,WAAW,CAC3C,EAAM,IAAM,GAAM,IAAM,GAAM,GAChC,CAAC,EAEKC,EAAwB,IAAI,WAAW,CAAC,EAAM,IAAM,GAAI,CAAC,EAEzDC,EAAwB,IAAI,WAAW,CAC3C,EAAM,GAAM,EAAM,EAAM,GAAM,GAAM,IAAM,IAAM,IAAM,IAAM,IAAM,IAAM,IACxE,IAAM,IAAM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,0BAA0B,CAAC,EAAE,KAAK,CAAC,EAElD,MAAMY,EAAc,IACdC,EAAe,KACfH,EAAW,IAAI,WAAW,CAAC,EACjCA,EAAS,IAAI,CAAC,GAAI,EAAG,CAAC,EAEtBV,EACG,oBAAoBY,CAAW,EAC/B,mBAAmBC,CAAY,EAC/B,qBAAqBH,CAAQ,EAEhC,OAAOV,EAAQ,MAAM,CAAC,EAAE,QAAQD,CAAmB,EACnD,OAAOC,EAAQ,0BAA0B,CAAC,EAAE,KAAK,CAAC,EAClD,OAAOA,EAAQ,UAAU,CAAC,EAAE,QAAQ,CAClC,IAAI,oBAAkBY,CAAW,EACjC,IAAI,oBAAkBC,CAAY,EAClC,IAAI,oBAAkBH,EAAS,SAAS,CAAC,CAC3C,CAAC,CACH,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_HexaString", "import_ApduBuilder", "import_AppBuilderError", "import_ByteArrayBuilder", "COMMAND_NO_BODY", "COMMAND_BODY_SINGLE", "COMMAND_BODY_HEXA1", "COMMAND_BODY_HEXA2", "COMMAND_BODY_LV_HEXA", "COMMAND_BODY_LV_ASCII", "COMMAND_BODY_LV_ARRAY", "COMMAND_BODY_COMBINED", "COMMAND_BODY_MAX", "COMMAND_BODY_NEARLY", "builder", "builderAddNumber", "num", "bigEndian", "sizeInBits", "signed", "input", "output", "myarray", "available", "mybuffer", "mystring", "firstString", "secondString"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var R=Object.create;var E=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var U=(i,e)=>{for(var s in e)E(i,s,{get:e[s],enumerable:!0})},_=(i,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of O(e))!D.call(i,c)&&c!==s&&E(i,c,{get:()=>e[c],enumerable:!(r=T(e,c))||r.enumerable});return i};var N=(i,e,s)=>(s=i!=null?R(I(i)):{},_(e||!i||!i.__esModule?E(s,"default",{value:i,enumerable:!0}):s,i)),P=i=>_(E({},"__esModule",{value:!0}),i);var q={};U(q,{ConnectToSecureChannelTask:()=>W});module.exports=P(q);var A=N(require("isomorphic-ws")),x=require("rxjs"),g=require("../../command/utils/CommandUtils"),n=require("../../secure-channel/task/types"),M=require("../../secure-channel/utils"),m=require("../../utils/HexaString"),t=require("../../../internal/secure-channel/model/Errors");class W{constructor(e,s){this._api=e;this._args=s;if(this._args.connection.isRight())this._connection=this._args.connection.extract();else throw new t.SecureChannelError(`Invalid WebSocket connection: ${String(this._args.connection.extract())}`)}_connection;run(){const e=this._api.disableRefresher("connectToSecureChannel");return new x.Observable(r=>{let c=!1,p=!1,v=!1;const l=y=>{r.next({type:n.SecureChannelEventType.Error,error:y}),r.complete(),p=!0};return this._connection.onopen=()=>{r.next({type:n.SecureChannelEventType.Opened})},this._connection.onerror=y=>{p||(r.next({type:n.SecureChannelEventType.Error,error:new t.SecureChannelError({url:this._connection.url,errorMessage:y.message})}),r.complete())},this._connection.onclose=()=>{p||(v?r.next({type:n.SecureChannelEventType.Closed}):r.next({type:n.SecureChannelEventType.Error,error:new t.SecureChannelError({url:this._connection.url,errorMessage:"Connection closed unexpectedly"})}),r.complete())},this._connection.onmessage=async y=>{if(c)return;let a;try{const o=JSON.parse(String(y.data));if(this.isInMessageType(o))a=o;else throw new Error("Data does not match InMessageType")}catch{l(new t.SecureChannelError({url:this._connection.url,errorMessage:`Invalid message received: ${String(y.data)}`}));return}switch(a.query){case n.InMessageQueryEnum.EXCHANGE:{const{nonce:o,data:d}=a;if(typeof d!="string"){l(new t.SecureChannelError(`${n.InMessageQueryEnum.EXCHANGE} data type should be an APDU`));return}const u=(0,m.hexaStringToBuffer)(d);if(u===null||u.length<5){l(new t.SecureChannelError(`Received invalid APDU data: ${d}`));return}r.next({type:n.SecureChannelEventType.PreExchange,payload:{nonce:o,apdu:u}});let f=!1;(0,M.willRequestPermission)(u)&&!this.isSecureConnectionAllowed()&&(f=!0,r.next({type:n.SecureChannelEventType.PermissionRequested}));const S=await this._api.sendApdu(u);if(c)return;S.caseOf({Left:h=>{l(new t.SecureChannelError(h))},Right:h=>{let C;const w=this.mapDeviceError(h);w===null?(C=n.OutMessageResponseEnum.SUCCESS,r.next({type:n.SecureChannelEventType.Exchange,payload:{nonce:o,apdu:u,data:h.data,status:h.statusCode}}),f&&r.next({type:n.SecureChannelEventType.PermissionGranted})):(C=n.OutMessageResponseEnum.ERROR,l(w));const k={nonce:o,response:C,data:(0,m.bufferToHexaString)(h.data).slice(2)};this._connection.send(JSON.stringify(k))}});break}case n.InMessageQueryEnum.BULK:{if(p=!0,this._connection.close(),!Array.isArray(a.data)||a.data.length===0||!a.data.every(o=>typeof o=="string")){l(new t.SecureChannelError("Invalid bulk data received"));return}for(let o=0,d=a.data.length;o<d;o++){const u=(0,m.hexaStringToBuffer)(a.data[o]);if(u===null||u.length<5){l(new t.SecureChannelError(`Received invalid APDU bulk data: ${a.data[o]}`));return}const f=await this._api.sendApdu(u);if(c)return;if(f.isLeft()){l(new t.SecureChannelError(f.extract()));return}else if(f.isRight()){const S=this.mapDeviceError(f.extract());if(S===null)r.next({type:n.SecureChannelEventType.Progress,payload:{progress:+Number((o+1)/d).toFixed(2),index:o,total:d}});else{l(S);return}}}v=!0,r.complete();break}case n.InMessageQueryEnum.SUCCESS:{if(p)break;const o=a.result??a.data;o&&r.next({type:n.SecureChannelEventType.Result,payload:o??""}),v=!0,r.complete();break}case n.InMessageQueryEnum.WARNING:{if(p)break;r.next({type:n.SecureChannelEventType.Warning,payload:{message:String(a.data)}});break}case n.InMessageQueryEnum.ERROR:{if(p)break;l(new t.SecureChannelError({url:this._connection.url,errorMessage:String(a.data)}))}}},()=>{e(),c=!0,this._connection.readyState===A.default.OPEN&&this._connection.close()}})}isSecureConnectionAllowed(){const e=this._api.getDeviceSessionState();return"isSecureConnectionAllowed"in e&&e.isSecureConnectionAllowed}isInMessageType(e){if(typeof e!="object"||!e)return!1;const s=e;return typeof s.uuid=="string"&&typeof s.session=="string"&&typeof s.query=="string"&&Object.values(n.InMessageQueryEnum).includes(s.query)&&typeof s.nonce=="number"}mapDeviceError(e){return g.CommandUtils.isSuccessResponse(e)?null:g.CommandUtils.isLockedDeviceResponse(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"Device is locked"},t.SecureChannelErrorType.DeviceLocked):g.CommandUtils.isRefusedByUser(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"User refused on the device"},t.SecureChannelErrorType.RefusedByUser):g.CommandUtils.isAppAlreadyInstalled(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"App already installed"},t.SecureChannelErrorType.AppAlreadyInstalled):g.CommandUtils.isOutOfMemory(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"Out of memory"},t.SecureChannelErrorType.OutOfMemory):new t.SecureChannelError({url:this._connection.url,errorMessage:`Invalid status code: ${(0,m.bufferToHexaString)(e.statusCode)}`})}}0&&(module.exports={ConnectToSecureChannelTask});
1
+ "use strict";var R=Object.create;var E=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var U=(i,e)=>{for(var s in e)E(i,s,{get:e[s],enumerable:!0})},_=(i,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let c of O(e))!D.call(i,c)&&c!==s&&E(i,c,{get:()=>e[c],enumerable:!(r=T(e,c))||r.enumerable});return i};var N=(i,e,s)=>(s=i!=null?R(I(i)):{},_(e||!i||!i.__esModule?E(s,"default",{value:i,enumerable:!0}):s,i)),P=i=>_(E({},"__esModule",{value:!0}),i);var q={};U(q,{ConnectToSecureChannelTask:()=>W});module.exports=P(q);var A=N(require("isomorphic-ws")),x=require("rxjs"),g=require("../../command/utils/CommandUtils"),n=require("../../secure-channel/task/types"),M=require("../../secure-channel/utils"),m=require("../../utils/HexaString"),t=require("../../../internal/secure-channel/model/Errors");class W{constructor(e,s){this._api=e;this._args=s;if(this._args.connection.isRight())this._connection=this._args.connection.extract();else throw new t.SecureChannelError(`Invalid WebSocket connection: ${String(this._args.connection.extract())}`)}_connection;run(){const e=this._api.disableRefresher("connectToSecureChannel");return new x.Observable(r=>{let c=!1,p=!1,v=!1;const l=y=>{r.next({type:n.SecureChannelEventType.Error,error:y}),r.complete(),p=!0};return this._connection.onopen=()=>{r.next({type:n.SecureChannelEventType.Opened})},this._connection.onerror=y=>{p||(r.next({type:n.SecureChannelEventType.Error,error:new t.SecureChannelError({url:this._connection.url,errorMessage:y.message})}),r.complete())},this._connection.onclose=()=>{p||(v?r.next({type:n.SecureChannelEventType.Closed}):r.next({type:n.SecureChannelEventType.Error,error:new t.SecureChannelError({url:this._connection.url,errorMessage:"Connection closed unexpectedly"})}),r.complete())},this._connection.onmessage=async y=>{if(c)return;let a;try{const o=JSON.parse(String(y.data));if(this.isInMessageType(o))a=o;else throw new Error("Data does not match InMessageType")}catch{l(new t.SecureChannelError({url:this._connection.url,errorMessage:`Invalid message received: ${String(y.data)}`}));return}switch(a.query){case n.InMessageQueryEnum.EXCHANGE:{const{nonce:o,data:d}=a;if(typeof d!="string"){l(new t.SecureChannelError(`${n.InMessageQueryEnum.EXCHANGE} data type should be an APDU`));return}const u=(0,m.hexaStringToBuffer)(d);if(u===null||u.length<5){l(new t.SecureChannelError(`Received invalid APDU data: ${d}`));return}r.next({type:n.SecureChannelEventType.PreExchange,payload:{nonce:o,apdu:u}});let f=!1;(0,M.willRequestPermission)(u)&&!this.isSecureConnectionAllowed()&&(f=!0,r.next({type:n.SecureChannelEventType.PermissionRequested}));const S=await this._api.sendApdu(u);if(c)return;S.caseOf({Left:h=>{l(new t.SecureChannelError(h))},Right:h=>{let C;const w=this.mapDeviceError(h);w===null?(C=n.OutMessageResponseEnum.SUCCESS,r.next({type:n.SecureChannelEventType.Exchange,payload:{nonce:o,apdu:u,data:h.data,status:h.statusCode}}),f&&r.next({type:n.SecureChannelEventType.PermissionGranted})):(C=n.OutMessageResponseEnum.ERROR,l(w));const k={nonce:o,response:C,data:(0,m.bufferToHexaString)(h.data,!1)};this._connection.send(JSON.stringify(k))}});break}case n.InMessageQueryEnum.BULK:{if(p=!0,this._connection.close(),!Array.isArray(a.data)||a.data.length===0||!a.data.every(o=>typeof o=="string")){l(new t.SecureChannelError("Invalid bulk data received"));return}for(let o=0,d=a.data.length;o<d;o++){const u=(0,m.hexaStringToBuffer)(a.data[o]);if(u===null||u.length<5){l(new t.SecureChannelError(`Received invalid APDU bulk data: ${a.data[o]}`));return}const f=await this._api.sendApdu(u);if(c)return;if(f.isLeft()){l(new t.SecureChannelError(f.extract()));return}else if(f.isRight()){const S=this.mapDeviceError(f.extract());if(S===null)r.next({type:n.SecureChannelEventType.Progress,payload:{progress:+Number((o+1)/d).toFixed(2),index:o,total:d}});else{l(S);return}}}v=!0,r.complete();break}case n.InMessageQueryEnum.SUCCESS:{if(p)break;const o=a.result??a.data;o&&r.next({type:n.SecureChannelEventType.Result,payload:o??""}),v=!0,r.complete();break}case n.InMessageQueryEnum.WARNING:{if(p)break;r.next({type:n.SecureChannelEventType.Warning,payload:{message:String(a.data)}});break}case n.InMessageQueryEnum.ERROR:{if(p)break;l(new t.SecureChannelError({url:this._connection.url,errorMessage:String(a.data)}))}}},()=>{e(),c=!0,this._connection.readyState===A.default.OPEN&&this._connection.close()}})}isSecureConnectionAllowed(){const e=this._api.getDeviceSessionState();return"isSecureConnectionAllowed"in e&&e.isSecureConnectionAllowed}isInMessageType(e){if(typeof e!="object"||!e)return!1;const s=e;return typeof s.uuid=="string"&&typeof s.session=="string"&&typeof s.query=="string"&&Object.values(n.InMessageQueryEnum).includes(s.query)&&typeof s.nonce=="number"}mapDeviceError(e){return g.CommandUtils.isSuccessResponse(e)?null:g.CommandUtils.isLockedDeviceResponse(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"Device is locked"},t.SecureChannelErrorType.DeviceLocked):g.CommandUtils.isRefusedByUser(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"User refused on the device"},t.SecureChannelErrorType.RefusedByUser):g.CommandUtils.isAppAlreadyInstalled(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"App already installed"},t.SecureChannelErrorType.AppAlreadyInstalled):g.CommandUtils.isOutOfMemory(e)?new t.SecureChannelError({url:this._connection.url,errorMessage:"Out of memory"},t.SecureChannelErrorType.OutOfMemory):new t.SecureChannelError({url:this._connection.url,errorMessage:`Invalid status code: ${(0,m.bufferToHexaString)(e.statusCode)}`})}}0&&(module.exports={ConnectToSecureChannelTask});
2
2
  //# sourceMappingURL=ConnectToSecureChannelTask.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/api/secure-channel/task/ConnectToSecureChannelTask.ts"],
4
- "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport { willRequestPermission } from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n SecureChannelErrorType,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let ignoreNetworkEvents = false;\n let communicationFinished = false;\n\n const notifyError = (error: SecureChannelError) => {\n subscriber.next({\n type: SecureChannelEventType.Error,\n error,\n });\n subscriber.complete();\n\n // Netowrks events can be ignored once the obervable has been completed\n ignoreNetworkEvents = true;\n };\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n if (ignoreNetworkEvents) {\n return;\n }\n\n subscriber.next({\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n });\n subscriber.complete();\n };\n\n this._connection.onclose = () => {\n if (ignoreNetworkEvents) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n } else {\n subscriber.next({\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n }),\n });\n }\n subscriber.complete();\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n\n // Parse input message\n let input: InMessageType;\n try {\n const jsonData = JSON.parse(String(event.data));\n if (this.isInMessageType(jsonData)) {\n input = jsonData;\n } else {\n throw new Error(\"Data does not match InMessageType\");\n }\n } catch (_) {\n notifyError(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid message received: ${String(event.data)}`,\n }),\n );\n return;\n }\n\n // Execute message query\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce, data } = input;\n\n // Exchange query should contain a single APDU\n if (typeof data !== \"string\") {\n notifyError(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should be an APDU`,\n ),\n );\n return;\n }\n\n // APDU should be a valid hex string\n const apdu = hexaStringToBuffer(data);\n if (apdu === null || apdu.length < 5) {\n notifyError(\n new SecureChannelError(`Received invalid APDU data: ${data}`),\n );\n return;\n }\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n // Notify permission requested\n let permissionRequested = false;\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n permissionRequested = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n // Send APDU to the device\n const response = await this._api.sendApdu(apdu);\n if (unsubscribed) {\n return;\n }\n\n // Map device response\n response.caseOf({\n Left: (error) => {\n notifyError(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n const deviceError = this.mapDeviceError(apduResponse);\n if (deviceError === null) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n\n // If manager consent was requested, notify the \"granted\" event\n if (permissionRequested) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n }\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n notifyError(deviceError);\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data).slice(2),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n // Network not needed anymore during bulk APDUs sending\n ignoreNetworkEvents = true;\n this._connection.close();\n\n // A valid array of APDUs is required in a bulk query\n if (\n !Array.isArray(input.data) ||\n input.data.length === 0 ||\n !input.data.every((data) => typeof data === \"string\")\n ) {\n notifyError(new SecureChannelError(\"Invalid bulk data received\"));\n return;\n }\n\n for (let i = 0, len = input.data.length; i < len; i++) {\n // APDU should be a valid hex string\n const apdu = hexaStringToBuffer(input.data[i]!);\n if (apdu === null || apdu.length < 5) {\n notifyError(\n new SecureChannelError(\n `Received invalid APDU bulk data: ${input.data[i]}`,\n ),\n );\n return;\n }\n\n // Send APDU to the device\n const response = await this._api.sendApdu(apdu);\n if (unsubscribed) {\n return;\n }\n\n // Map device response\n if (response.isLeft()) {\n notifyError(new SecureChannelError(response.extract()));\n return;\n } else if (response.isRight()) {\n const deviceError = this.mapDeviceError(response.extract());\n if (deviceError === null) {\n // Notify the progress\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n } else {\n notifyError(deviceError);\n return;\n }\n }\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n if (ignoreNetworkEvents) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: payload ?? \"\",\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n if (ignoreNetworkEvents) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (ignoreNetworkEvents) {\n break;\n }\n notifyError(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n\n isInMessageType(data: unknown): data is InMessageType {\n if (typeof data !== \"object\" || !data) {\n return false;\n }\n\n const message = data as InMessageType;\n return (\n typeof message.uuid === \"string\" &&\n typeof message.session === \"string\" &&\n typeof message.query === \"string\" &&\n Object.values(InMessageQueryEnum).includes(message.query) &&\n typeof message.nonce === \"number\"\n );\n }\n\n mapDeviceError(apduResponse: ApduResponse): SecureChannelError | null {\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n return null;\n }\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: `Device is locked`,\n },\n SecureChannelErrorType.DeviceLocked,\n );\n }\n\n // User refused the permission\n if (CommandUtils.isRefusedByUser(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n },\n SecureChannelErrorType.RefusedByUser,\n );\n }\n\n // App already installed\n if (CommandUtils.isAppAlreadyInstalled(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"App already installed\",\n },\n SecureChannelErrorType.AppAlreadyInstalled,\n );\n }\n\n // Out of memory\n if (CommandUtils.isOutOfMemory(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"Out of memory\",\n },\n SecureChannelErrorType.OutOfMemory,\n );\n }\n\n return new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n }\n}\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsB,4BAEtBC,EAA2B,gBAE3BC,EAA6B,2CAG7BC,EAOO,0CACPC,EAAsC,qCACtCC,EAAuD,iCACvDC,EAIO,iDAMA,MAAMR,CAA2B,CAEtC,YACmBS,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,EAEjB,GAAI,KAAK,MAAM,WAAW,QAAQ,EAChC,KA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KAAK,YAAY,IACtB,aAAc,uBAChB,EACA,yBAAuB,mBACzB,EAIE,eAAa,cAAcA,CAAY,EAClC,IAAI,qBACT,CACE,IAAK,KAAK,YAAY,IACtB,aAAc,eAChB,EACA,yBAAuB,WACzB,EAGK,IAAI,qBAAmB,CAC5B,IAAK,KAAK,YAAY,IACtB,aAAc,2BAAwB,sBACpCA,EAAa,UACf,CAAC,EACH,CAAC,CACH,CACF",
4
+ "sourcesContent": ["import WebSocket from \"isomorphic-ws\";\nimport { type Either } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { CommandUtils } from \"@api/command/utils/CommandUtils\";\nimport { type InternalApi } from \"@api/device-action/DeviceAction\";\nimport { type ApduResponse } from \"@api/device-session/ApduResponse\";\nimport {\n InMessageQueryEnum,\n type InMessageType,\n OutMessageResponseEnum,\n type OutMessageType,\n type SecureChannelEvent,\n SecureChannelEventType,\n} from \"@api/secure-channel/task/types\";\nimport { willRequestPermission } from \"@api/secure-channel/utils\";\nimport { bufferToHexaString, hexaStringToBuffer } from \"@api/utils/HexaString\";\nimport {\n SecureChannelError,\n SecureChannelErrorType,\n type WebSocketConnectionError,\n} from \"@internal/secure-channel/model/Errors\";\n\nexport type ConnectToSecureChannelTaskArgs = {\n connection: Either<WebSocketConnectionError, WebSocket>;\n};\n\nexport class ConnectToSecureChannelTask {\n private readonly _connection: WebSocket;\n constructor(\n private readonly _api: InternalApi,\n private readonly _args: ConnectToSecureChannelTaskArgs,\n ) {\n if (this._args.connection.isRight()) {\n this._connection = this._args.connection.extract();\n } else {\n throw new SecureChannelError(\n `Invalid WebSocket connection: ${String(this._args.connection.extract())}`,\n );\n }\n }\n\n run(): Observable<SecureChannelEvent> {\n const reenableRefresher = this._api.disableRefresher(\n \"connectToSecureChannel\",\n );\n\n const obs = new Observable<SecureChannelEvent>((subscriber) => {\n let unsubscribed: boolean = false;\n let ignoreNetworkEvents = false;\n let communicationFinished = false;\n\n const notifyError = (error: SecureChannelError) => {\n subscriber.next({\n type: SecureChannelEventType.Error,\n error,\n });\n subscriber.complete();\n\n // Netowrks events can be ignored once the obervable has been completed\n ignoreNetworkEvents = true;\n };\n\n this._connection.onopen = () => {\n subscriber.next({\n type: SecureChannelEventType.Opened,\n });\n };\n\n this._connection.onerror = (error) => {\n if (ignoreNetworkEvents) {\n return;\n }\n\n subscriber.next({\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: this._connection.url,\n errorMessage: error.message,\n }),\n });\n subscriber.complete();\n };\n\n this._connection.onclose = () => {\n if (ignoreNetworkEvents) {\n return;\n }\n\n if (communicationFinished) {\n subscriber.next({\n type: SecureChannelEventType.Closed,\n });\n } else {\n subscriber.next({\n type: SecureChannelEventType.Error,\n error: new SecureChannelError({\n url: this._connection.url,\n errorMessage: \"Connection closed unexpectedly\",\n }),\n });\n }\n subscriber.complete();\n };\n\n this._connection.onmessage = async (event) => {\n // When unsubscribed, ignore the message\n if (unsubscribed) {\n return;\n }\n\n // Parse input message\n let input: InMessageType;\n try {\n const jsonData = JSON.parse(String(event.data));\n if (this.isInMessageType(jsonData)) {\n input = jsonData;\n } else {\n throw new Error(\"Data does not match InMessageType\");\n }\n } catch (_) {\n notifyError(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid message received: ${String(event.data)}`,\n }),\n );\n return;\n }\n\n // Execute message query\n switch (input.query) {\n case InMessageQueryEnum.EXCHANGE: {\n const { nonce, data } = input;\n\n // Exchange query should contain a single APDU\n if (typeof data !== \"string\") {\n notifyError(\n new SecureChannelError(\n `${InMessageQueryEnum.EXCHANGE} data type should be an APDU`,\n ),\n );\n return;\n }\n\n // APDU should be a valid hex string\n const apdu = hexaStringToBuffer(data);\n if (apdu === null || apdu.length < 5) {\n notifyError(\n new SecureChannelError(`Received invalid APDU data: ${data}`),\n );\n return;\n }\n subscriber.next({\n type: SecureChannelEventType.PreExchange,\n payload: { nonce, apdu },\n });\n\n // Notify permission requested\n let permissionRequested = false;\n if (\n willRequestPermission(apdu) &&\n !this.isSecureConnectionAllowed()\n ) {\n permissionRequested = true;\n subscriber.next({\n type: SecureChannelEventType.PermissionRequested,\n });\n }\n\n // Send APDU to the device\n const response = await this._api.sendApdu(apdu);\n if (unsubscribed) {\n return;\n }\n\n // Map device response\n response.caseOf({\n Left: (error) => {\n notifyError(new SecureChannelError(error));\n },\n Right: (apduResponse: ApduResponse) => {\n let outMessageResponse: OutMessageResponseEnum;\n const deviceError = this.mapDeviceError(apduResponse);\n if (deviceError === null) {\n outMessageResponse = OutMessageResponseEnum.SUCCESS;\n\n // Emit event for the exchange\n subscriber.next({\n type: SecureChannelEventType.Exchange,\n payload: {\n nonce,\n apdu,\n data: apduResponse.data,\n status: apduResponse.statusCode,\n },\n });\n\n // If manager consent was requested, notify the \"granted\" event\n if (permissionRequested) {\n subscriber.next({\n type: SecureChannelEventType.PermissionGranted,\n });\n }\n } else {\n outMessageResponse = OutMessageResponseEnum.ERROR;\n notifyError(deviceError);\n }\n\n // Send the message back to the server\n const message: OutMessageType = {\n nonce,\n response: outMessageResponse,\n data: bufferToHexaString(apduResponse.data, false),\n };\n this._connection.send(JSON.stringify(message));\n },\n });\n break;\n }\n case InMessageQueryEnum.BULK: {\n // Network not needed anymore during bulk APDUs sending\n ignoreNetworkEvents = true;\n this._connection.close();\n\n // A valid array of APDUs is required in a bulk query\n if (\n !Array.isArray(input.data) ||\n input.data.length === 0 ||\n !input.data.every((data) => typeof data === \"string\")\n ) {\n notifyError(new SecureChannelError(\"Invalid bulk data received\"));\n return;\n }\n\n for (let i = 0, len = input.data.length; i < len; i++) {\n // APDU should be a valid hex string\n const apdu = hexaStringToBuffer(input.data[i]!);\n if (apdu === null || apdu.length < 5) {\n notifyError(\n new SecureChannelError(\n `Received invalid APDU bulk data: ${input.data[i]}`,\n ),\n );\n return;\n }\n\n // Send APDU to the device\n const response = await this._api.sendApdu(apdu);\n if (unsubscribed) {\n return;\n }\n\n // Map device response\n if (response.isLeft()) {\n notifyError(new SecureChannelError(response.extract()));\n return;\n } else if (response.isRight()) {\n const deviceError = this.mapDeviceError(response.extract());\n if (deviceError === null) {\n // Notify the progress\n subscriber.next({\n type: SecureChannelEventType.Progress,\n payload: {\n progress: +Number((i + 1) / len).toFixed(2),\n index: i,\n total: len,\n },\n });\n } else {\n notifyError(deviceError);\n return;\n }\n }\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.SUCCESS: {\n if (ignoreNetworkEvents) {\n break;\n }\n // Emit the result if there is any\n const payload = input.result ?? input.data;\n if (payload) {\n subscriber.next({\n type: SecureChannelEventType.Result,\n payload: payload ?? \"\",\n });\n }\n communicationFinished = true;\n subscriber.complete();\n break;\n }\n case InMessageQueryEnum.WARNING: {\n if (ignoreNetworkEvents) {\n break;\n }\n subscriber.next({\n type: SecureChannelEventType.Warning,\n payload: { message: String(input.data) },\n });\n break;\n }\n case InMessageQueryEnum.ERROR: {\n if (ignoreNetworkEvents) {\n break;\n }\n notifyError(\n new SecureChannelError({\n url: this._connection.url,\n errorMessage: String(input.data),\n }),\n );\n }\n }\n };\n\n return () => {\n reenableRefresher();\n unsubscribed = true;\n // Close the connection if it is open when unsubscribing\n if (this._connection.readyState === WebSocket.OPEN) {\n this._connection.close();\n }\n };\n });\n\n return obs;\n }\n\n /**\n * Determines if a secure connection is already allowed based on the current device session state.\n *\n * @returns {boolean} `true` if a secure connection is allowed, otherwise `false`.\n */\n isSecureConnectionAllowed(): boolean {\n const deviceSessionState = this._api.getDeviceSessionState();\n return (\n \"isSecureConnectionAllowed\" in deviceSessionState &&\n deviceSessionState.isSecureConnectionAllowed\n );\n }\n\n isInMessageType(data: unknown): data is InMessageType {\n if (typeof data !== \"object\" || !data) {\n return false;\n }\n\n const message = data as InMessageType;\n return (\n typeof message.uuid === \"string\" &&\n typeof message.session === \"string\" &&\n typeof message.query === \"string\" &&\n Object.values(InMessageQueryEnum).includes(message.query) &&\n typeof message.nonce === \"number\"\n );\n }\n\n mapDeviceError(apduResponse: ApduResponse): SecureChannelError | null {\n if (CommandUtils.isSuccessResponse(apduResponse)) {\n return null;\n }\n\n // Device is locked\n if (CommandUtils.isLockedDeviceResponse(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: `Device is locked`,\n },\n SecureChannelErrorType.DeviceLocked,\n );\n }\n\n // User refused the permission\n if (CommandUtils.isRefusedByUser(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"User refused on the device\",\n },\n SecureChannelErrorType.RefusedByUser,\n );\n }\n\n // App already installed\n if (CommandUtils.isAppAlreadyInstalled(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"App already installed\",\n },\n SecureChannelErrorType.AppAlreadyInstalled,\n );\n }\n\n // Out of memory\n if (CommandUtils.isOutOfMemory(apduResponse)) {\n return new SecureChannelError(\n {\n url: this._connection.url,\n errorMessage: \"Out of memory\",\n },\n SecureChannelErrorType.OutOfMemory,\n );\n }\n\n return new SecureChannelError({\n url: this._connection.url,\n errorMessage: `Invalid status code: ${bufferToHexaString(\n apduResponse.statusCode,\n )}`,\n });\n }\n}\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAsB,4BAEtBC,EAA2B,gBAE3BC,EAA6B,2CAG7BC,EAOO,0CACPC,EAAsC,qCACtCC,EAAuD,iCACvDC,EAIO,iDAMA,MAAMR,CAA2B,CAEtC,YACmBS,EACAC,EACjB,CAFiB,UAAAD,EACA,WAAAC,EAEjB,GAAI,KAAK,MAAM,WAAW,QAAQ,EAChC,KAAK,YAAc,KAAK,MAAM,WAAW,QAAQ,MAEjD,OAAM,IAAI,qBACR,iCAAiC,OAAO,KAAK,MAAM,WAAW,QAAQ,CAAC,CAAC,EAC1E,CAEJ,CAZiB,YAcjB,KAAsC,CACpC,MAAMC,EAAoB,KAAK,KAAK,iBAClC,wBACF,EA4RA,OA1RY,IAA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ACpCA,EAAa,UACf,CAAC,EACH,CAAC,CACH,CACF",
6
6
  "names": ["ConnectToSecureChannelTask_exports", "__export", "ConnectToSecureChannelTask", "__toCommonJS", "import_isomorphic_ws", "import_rxjs", "import_CommandUtils", "import_types", "import_utils", "import_HexaString", "import_Errors", "_api", "_args", "reenableRefresher", "subscriber", "unsubscribed", "ignoreNetworkEvents", "communicationFinished", "notifyError", "error", "event", "input", "jsonData", "nonce", "data", "apdu", "permissionRequested", "response", "apduResponse", "outMessageResponse", "deviceError", "message", "i", "len", "payload", "WebSocket", "deviceSessionState"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var a=(t,r)=>{for(var n in r)e(t,n,{get:r[n],enumerable:!0})},g=(t,r,n,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of f(r))!x.call(t,i)&&i!==n&&e(t,i,{get:()=>r[i],enumerable:!(s=o(r,i))||s.enumerable});return t};var p=t=>g(e({},"__esModule",{value:!0}),t);var c={};a(c,{bufferToHexaString:()=>A,hexaStringToBuffer:()=>S,isHexaString:()=>y});module.exports=p(c);const y=t=>typeof t=="string"&&/^0x[0-9a-fA-F]*$/.test(t),S=t=>{if(t.startsWith("0x")&&(t=t.slice(2)),t.length===0)return new Uint8Array;if(t.length%2!==0&&(t="0"+t),/^[0-9a-fA-F]*$/.test(t)===!1)return null;const r=t.match(/.{1,2}/g)?.map(n=>parseInt(n,16));return!r||r.some(isNaN)?null:new Uint8Array(r)},A=t=>`0x${Array.from(t,r=>r.toString(16).padStart(2,"0")).join("")}`;0&&(module.exports={bufferToHexaString,hexaStringToBuffer,isHexaString});
1
+ "use strict";var f=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var s=(r,t)=>{for(var n in t)f(r,n,{get:t[n],enumerable:!0})},g=(r,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of x(t))!a.call(r,i)&&i!==n&&f(r,i,{get:()=>t[i],enumerable:!(e=o(t,i))||e.enumerable});return r};var u=r=>g(f({},"__esModule",{value:!0}),r);var c={};s(c,{bufferToHexaString:()=>y,hexaStringToBuffer:()=>S,isHexaString:()=>p});module.exports=u(c);function p(r){return typeof r=="string"&&/^0x[0-9a-fA-F]*$/.test(r)}function S(r){if(r.startsWith("0x")&&(r=r.slice(2)),r.length===0)return new Uint8Array;if(r.length%2!==0&&(r="0"+r),/^[0-9a-fA-F]*$/.test(r)===!1)return null;const t=r.match(/.{1,2}/g)?.map(n=>parseInt(n,16));return!t||t.some(isNaN)?null:new Uint8Array(t)}function y(r,t=!0){return`${t?"0x":""}${Array.from(r,e=>e.toString(16).padStart(2,"0")).join("")}`}0&&(module.exports={bufferToHexaString,hexaStringToBuffer,isHexaString});
2
2
  //# sourceMappingURL=HexaString.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/api/utils/HexaString.ts"],
4
- "sourcesContent": ["export type HexaString = `0x${string}`;\n\nexport const isHexaString = (value: unknown): value is HexaString => {\n return typeof value === \"string\" && /^0x[0-9a-fA-F]*$/.test(value);\n};\n\nexport const hexaStringToBuffer = (value: string): Uint8Array | null => {\n if (value.startsWith(\"0x\")) {\n value = value.slice(2);\n }\n if (value.length === 0) {\n return new Uint8Array();\n }\n if (value.length % 2 !== 0) {\n value = \"0\" + value;\n }\n if (/^[0-9a-fA-F]*$/.test(value) === false) {\n return null;\n }\n const bytes = value.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16));\n if (!bytes || bytes.some(isNaN)) {\n return null;\n }\n return new Uint8Array(bytes);\n};\n\nexport const bufferToHexaString = (value: Uint8Array): HexaString => {\n return `0x${Array.from(value, (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\")}`;\n};\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,uBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAL,GAEO,MAAMI,EAAgBE,GACpB,OAAOA,GAAU,UAAY,mBAAmB,KAAKA,CAAK,EAGtDH,EAAsBG,GAAqC,CAItE,GAHIA,EAAM,WAAW,IAAI,IACvBA,EAAQA,EAAM,MAAM,CAAC,GAEnBA,EAAM,SAAW,EACnB,OAAO,IAAI,WAKb,GAHIA,EAAM,OAAS,IAAM,IACvBA,EAAQ,IAAMA,GAEZ,iBAAiB,KAAKA,CAAK,IAAM,GACnC,OAAO,KAET,MAAMC,EAAQD,EAAM,MAAM,SAAS,GAAG,IAAKE,GAAS,SAASA,EAAM,EAAE,CAAC,EACtE,MAAI,CAACD,GAASA,EAAM,KAAK,KAAK,EACrB,KAEF,IAAI,WAAWA,CAAK,CAC7B,EAEaL,EAAsBI,GAC1B,KAAK,MAAM,KAAKA,EAAQE,GAC7BA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CACnC,EAAE,KAAK,EAAE,CAAC",
6
- "names": ["HexaString_exports", "__export", "bufferToHexaString", "hexaStringToBuffer", "isHexaString", "__toCommonJS", "value", "bytes", "byte"]
4
+ "sourcesContent": ["export type HexaString = `0x${string}`;\n\nexport function isHexaString(value: unknown): value is HexaString {\n return typeof value === \"string\" && /^0x[0-9a-fA-F]*$/.test(value);\n}\n\nexport function hexaStringToBuffer(value: string): Uint8Array | null {\n if (value.startsWith(\"0x\")) {\n value = value.slice(2);\n }\n if (value.length === 0) {\n return new Uint8Array();\n }\n if (value.length % 2 !== 0) {\n value = \"0\" + value;\n }\n if (/^[0-9a-fA-F]*$/.test(value) === false) {\n return null;\n }\n const bytes = value.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16));\n if (!bytes || bytes.some(isNaN)) {\n return null;\n }\n return new Uint8Array(bytes);\n}\n\nexport function bufferToHexaString(\n value: Uint8Array,\n withPrefix?: true,\n): HexaString;\nexport function bufferToHexaString(\n value: Uint8Array,\n withPrefix?: false,\n): string;\nexport function bufferToHexaString(\n value: Uint8Array,\n withPrefix: boolean = true,\n): HexaString | string {\n const prefix = withPrefix ? \"0x\" : \"\";\n return `${prefix}${Array.from(value, (byte) =>\n byte.toString(16).padStart(2, \"0\"),\n ).join(\"\")}`;\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,uBAAAC,EAAA,iBAAAC,IAAA,eAAAC,EAAAL,GAEO,SAASI,EAAaE,EAAqC,CAChE,OAAO,OAAOA,GAAU,UAAY,mBAAmB,KAAKA,CAAK,CACnE,CAEO,SAASH,EAAmBG,EAAkC,CAInE,GAHIA,EAAM,WAAW,IAAI,IACvBA,EAAQA,EAAM,MAAM,CAAC,GAEnBA,EAAM,SAAW,EACnB,OAAO,IAAI,WAKb,GAHIA,EAAM,OAAS,IAAM,IACvBA,EAAQ,IAAMA,GAEZ,iBAAiB,KAAKA,CAAK,IAAM,GACnC,OAAO,KAET,MAAMC,EAAQD,EAAM,MAAM,SAAS,GAAG,IAAKE,GAAS,SAASA,EAAM,EAAE,CAAC,EACtE,MAAI,CAACD,GAASA,EAAM,KAAK,KAAK,EACrB,KAEF,IAAI,WAAWA,CAAK,CAC7B,CAUO,SAASL,EACdI,EACAG,EAAsB,GACD,CAErB,MAAO,GADQA,EAAa,KAAO,EACnB,GAAG,MAAM,KAAKH,EAAQE,GACpCA,EAAK,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,CACnC,EAAE,KAAK,EAAE,CAAC,EACZ",
6
+ "names": ["HexaString_exports", "__export", "bufferToHexaString", "hexaStringToBuffer", "isHexaString", "__toCommonJS", "value", "bytes", "byte", "withPrefix"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("./HexaString");describe("HexaString",()=>{describe("isHexaString function",()=>{it("should return true if the value is a valid hex string",()=>{const t=(0,e.isHexaString)("0x1234abc");expect(t).toBeTruthy()}),it("should return true if no data",()=>{const t=(0,e.isHexaString)("0x");expect(t).toBeTruthy()}),it("should return false if the value contain an invalid letter",()=>{const t=(0,e.isHexaString)("0x1234z");expect(t).toBeFalsy()}),it("should return false if the value does not start with 0x",()=>{const t=(0,e.isHexaString)("1234abc");expect(t).toBeFalsy()}),it("should return false for an epmty string",()=>{const t=(0,e.isHexaString)("");expect(t).toBeFalsy()}),it.each([123,[],{},null,void 0,!0])("should return false for invalid input %p",u=>{const t=(0,e.isHexaString)(u);expect(t).toBeFalsy()})}),describe("hexaStringToBuffer function",()=>{it("should convert empty input to empty buffer",()=>{const t=(0,e.hexaStringToBuffer)("");expect(t).toStrictEqual(new Uint8Array)}),it("should fail on invalid string",()=>{const t=(0,e.hexaStringToBuffer)("bonjour");expect(t).toStrictEqual(null)}),it("should fail on invalid string with valid numbers",()=>{const t=(0,e.hexaStringToBuffer)("0x012n34");expect(t).toStrictEqual(null)}),it("should convert correct hexadecimal string",()=>{const t=(0,e.hexaStringToBuffer)("1a35669f0100");expect(t).toStrictEqual(new Uint8Array([26,53,102,159,1,0]))}),it("should support 0x prefix",()=>{const t=(0,e.hexaStringToBuffer)("0x1a35");expect(t).toStrictEqual(new Uint8Array([26,53]))}),it("should be case insensitive",()=>{const t=(0,e.hexaStringToBuffer)("0xcCDd");expect(t).toStrictEqual(new Uint8Array([204,221]))}),it("should pad with 0",()=>{const t=(0,e.hexaStringToBuffer)("0xa35");expect(t).toStrictEqual(new Uint8Array([10,53]))})}),describe("bufferToHexaString function",()=>{it("should convert a buffer into a hexa string",()=>{const u=Uint8Array.from([0,1,2,255,254]),t=(0,e.bufferToHexaString)(u);expect(t).toStrictEqual("0x000102fffe")})})});
1
+ "use strict";var e=require("./HexaString");describe("HexaString",()=>{describe("isHexaString function",()=>{it("should return true if the value is a valid hex string",()=>{const t=(0,e.isHexaString)("0x1234abc");expect(t).toBeTruthy()}),it("should return true if no data",()=>{const t=(0,e.isHexaString)("0x");expect(t).toBeTruthy()}),it("should return false if the value contain an invalid letter",()=>{const t=(0,e.isHexaString)("0x1234z");expect(t).toBeFalsy()}),it("should return false if the value does not start with 0x",()=>{const t=(0,e.isHexaString)("1234abc");expect(t).toBeFalsy()}),it("should return false for an epmty string",()=>{const t=(0,e.isHexaString)("");expect(t).toBeFalsy()}),it.each([123,[],{},null,void 0,!0])("should return false for invalid input %p",r=>{const t=(0,e.isHexaString)(r);expect(t).toBeFalsy()})}),describe("hexaStringToBuffer function",()=>{it("should convert empty input to empty buffer",()=>{const t=(0,e.hexaStringToBuffer)("");expect(t).toStrictEqual(new Uint8Array)}),it("should fail on invalid string",()=>{const t=(0,e.hexaStringToBuffer)("bonjour");expect(t).toStrictEqual(null)}),it("should fail on invalid string with valid numbers",()=>{const t=(0,e.hexaStringToBuffer)("0x012n34");expect(t).toStrictEqual(null)}),it("should convert correct hexadecimal string",()=>{const t=(0,e.hexaStringToBuffer)("1a35669f0100");expect(t).toStrictEqual(new Uint8Array([26,53,102,159,1,0]))}),it("should support 0x prefix",()=>{const t=(0,e.hexaStringToBuffer)("0x1a35");expect(t).toStrictEqual(new Uint8Array([26,53]))}),it("should be case insensitive",()=>{const t=(0,e.hexaStringToBuffer)("0xcCDd");expect(t).toStrictEqual(new Uint8Array([204,221]))}),it("should pad with 0",()=>{const t=(0,e.hexaStringToBuffer)("0xa35");expect(t).toStrictEqual(new Uint8Array([10,53]))})}),describe("bufferToHexaString function",()=>{it("should convert a buffer into a hexa string",()=>{const r=Uint8Array.from([0,1,2,255,254]),t=(0,e.bufferToHexaString)(r);expect(t).toStrictEqual("0x000102fffe")}),it("should convert a buffer into a hexa string without prefix",()=>{const r=Uint8Array.from([0,1,2,255,254]),t=(0,e.bufferToHexaString)(r,!1);expect(t).toStrictEqual("000102fffe")})})});
2
2
  //# sourceMappingURL=HexaString.test.js.map