@ledgerhq/device-management-kit 0.0.0-develop-20260218001447 → 0.0.0-develop-20260221001335
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.
- package/lib/cjs/package.json +1 -1
- package/lib/cjs/src/api/apdu/utils/ApduBuilder.js +1 -1
- package/lib/cjs/src/api/apdu/utils/ApduBuilder.js.map +3 -3
- package/lib/esm/package.json +1 -1
- package/lib/esm/src/api/apdu/utils/ApduBuilder.js +1 -1
- package/lib/esm/src/api/apdu/utils/ApduBuilder.js.map +3 -3
- package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts +7 -0
- package/lib/types/src/api/apdu/utils/ApduBuilder.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +2 -2
package/lib/cjs/package.json
CHANGED
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
65
65
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
66
66
|
},
|
|
67
|
-
"version": "0.0.0-develop-
|
|
67
|
+
"version": "0.0.0-develop-20260221001335"
|
|
68
68
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var A=(r,t)=>{for(var
|
|
1
|
+
"use strict";var i=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var A=(r,t)=>{for(var a in t)i(r,a,{get:t[a],enumerable:!0})},h=(r,t,a,d)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of p(t))!l.call(r,e)&&e!==a&&i(r,e,{get:()=>t[e],enumerable:!(d=s(t,e))||d.enumerable});return r};var B=r=>h(i({},"__esModule",{value:!0}),r);var f={};A(f,{APDU_MAX_PAYLOAD:()=>n,APDU_MAX_SIZE:()=>c,ApduBuilder:()=>b,HEADER_LENGTH:()=>m});module.exports=B(f);var u=require("../../apdu/model/Apdu"),o=require("./ByteArrayBuilder");const m=5,n=255,c=n+5;class b{_ins;_cla;_p1;p2;data=new o.ByteArrayBuilder(n);constructor({ins:t,cla:a,p1:d,p2:e}){this._cla=a&255,this._ins=t&255,this._p1=d&255,this.p2=e&255}build=()=>new u.Apdu(this._cla,this._ins,this._p1,this.p2,this.data.build());add8BitUIntToData=t=>(this.data.add8BitUIntToData(t),this);add16BitUIntToData=t=>(this.data.add16BitUIntToData(t),this);add32BitUIntToData=t=>(this.data.add32BitUIntToData(t),this);add64BitUIntToData=(t,a=!0)=>(this.data.add64BitUIntToData(t,a),this);addBufferToData=t=>(this.data.addBufferToData(t),this);addHexaStringToData=t=>(this.data.addHexaStringToData(t),this);addAsciiStringToData=t=>(this.data.addAsciiStringToData(t),this);encodeInLVFromHexa=t=>(this.data.encodeInLVFromHexa(t),this);encodeInLVFromBuffer=t=>(this.data.encodeInLVFromBuffer(t),this);encodeInLVFromAscii=t=>(this.data.encodeInLVFromAscii(t),this);getAvailablePayloadLength=()=>this.data.getAvailablePayloadLength();getErrors=()=>this.data.getErrors()}0&&(module.exports={APDU_MAX_PAYLOAD,APDU_MAX_SIZE,ApduBuilder,HEADER_LENGTH});
|
|
2
2
|
//# sourceMappingURL=ApduBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/apdu/utils/ApduBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import { Apdu } from \"@api/apdu/model/Apdu\";\n\nimport { type AppBuilderError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nexport const HEADER_LENGTH = 5;\nexport const APDU_MAX_PAYLOAD = 255;\nexport const APDU_MAX_SIZE = APDU_MAX_PAYLOAD + 5;\n\nexport type ApduBuilderArgs = {\n readonly ins: number;\n readonly cla: number;\n readonly p1: number;\n readonly p2: number;\n};\n\n/**\n * ApduBuilder is a utility class to help build APDU commands.\n * It allows to easily add data to the data field of the APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const apduBuilder = new ApduBuilder({ ins: 0x01, cla: 0x02, p1: 0x03, p2: 0x04 })\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const apdu = apduBuilder.build();\n * const builderErrors = apduBuilder.getErrors();\n * ```\n */\nexport class ApduBuilder {\n private readonly _ins: number;\n private readonly _cla: number;\n private readonly _p1: number;\n private readonly p2: number;\n private data: ByteArrayBuilder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n\n constructor({ ins, cla, p1, p2 }: ApduBuilderArgs) {\n this._cla = cla & 0xff;\n this._ins = ins & 0xff;\n this._p1 = p1 & 0xff;\n this.p2 = p2 & 0xff;\n }\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new Apdu instance with the current state of the builder\n * @returns {Apdu} - Returns a new Apdu instance\n */\n build = (): Apdu =>\n new Apdu(this._cla, this._ins, this._p1, this.p2, this.data.build());\n\n /**\n * Add a 8-bit unsigned integer to the data field (max value 0xff = 255)\n * @param value?: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add8BitUIntToData = (value: number): ApduBuilder => {\n this.data.add8BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 16-bit unsigned integer to the data field (max value 0xffff = 65535)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add16BitUIntToData = (value: number): ApduBuilder => {\n this.data.add16BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 32-bit unsigned integer to the data field (max value 0xffffffff = 4294967295)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add32BitUIntToData = (value: number): ApduBuilder => {\n this.data.add32BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a Uint8Array to the data field if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addBufferToData = (value: Uint8Array): ApduBuilder => {\n this.data.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a string to the data field 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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addHexaStringToData = (value: string): ApduBuilder => {\n this.data.addHexaStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addAsciiStringToData = (value: string): ApduBuilder => {\n this.data.addAsciiStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromHexa = (value: string): ApduBuilder => {\n this.data.encodeInLVFromHexa(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ApduBuilder => {\n this.data.encodeInLVFromBuffer(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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromAscii = (value: string): ApduBuilder => {\n this.data.encodeInLVFromAscii(value);\n return this;\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number =>\n this.data.getAvailablePayloadLength();\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.data.getErrors();\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,kBAAAC,EAAA,gBAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,gCAGrBC,EAAiC,8BAE1B,MAAMH,EAAgB,EAChBH,EAAmB,IACnBC,EAAgBD,EAAmB,EA0BzC,MAAME,CAAY,CACN,KACA,KACA,IACA,GACT,KAAyB,IAAI,mBAAiBF,CAAgB,EAEtE,YAAY,CAAE,IAAAO,EAAK,IAAAC,EAAK,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,KAAK,KAAOF,EAAM,IAClB,KAAK,KAAOD,EAAM,IAClB,KAAK,IAAME,EAAK,IAChB,KAAK,GAAKC,EAAK,GACjB,CAUA,MAAQ,IACN,IAAI,OAAK,KAAK,KAAM,KAAK,KAAM,KAAK,IAAK,KAAK,GAAI,KAAK,KAAK,MAAM,CAAC,EAOrE,kBAAqBC,IACnB,KAAK,KAAK,kBAAkBA,CAAK,EAC1B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,
|
|
6
|
-
"names": ["ApduBuilder_exports", "__export", "APDU_MAX_PAYLOAD", "APDU_MAX_SIZE", "ApduBuilder", "HEADER_LENGTH", "__toCommonJS", "import_Apdu", "import_ByteArrayBuilder", "ins", "cla", "p1", "p2", "value"]
|
|
4
|
+
"sourcesContent": ["import { Apdu } from \"@api/apdu/model/Apdu\";\n\nimport { type AppBuilderError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nexport const HEADER_LENGTH = 5;\nexport const APDU_MAX_PAYLOAD = 255;\nexport const APDU_MAX_SIZE = APDU_MAX_PAYLOAD + 5;\n\nexport type ApduBuilderArgs = {\n readonly ins: number;\n readonly cla: number;\n readonly p1: number;\n readonly p2: number;\n};\n\n/**\n * ApduBuilder is a utility class to help build APDU commands.\n * It allows to easily add data to the data field of the APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const apduBuilder = new ApduBuilder({ ins: 0x01, cla: 0x02, p1: 0x03, p2: 0x04 })\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const apdu = apduBuilder.build();\n * const builderErrors = apduBuilder.getErrors();\n * ```\n */\nexport class ApduBuilder {\n private readonly _ins: number;\n private readonly _cla: number;\n private readonly _p1: number;\n private readonly p2: number;\n private data: ByteArrayBuilder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n\n constructor({ ins, cla, p1, p2 }: ApduBuilderArgs) {\n this._cla = cla & 0xff;\n this._ins = ins & 0xff;\n this._p1 = p1 & 0xff;\n this.p2 = p2 & 0xff;\n }\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new Apdu instance with the current state of the builder\n * @returns {Apdu} - Returns a new Apdu instance\n */\n build = (): Apdu =>\n new Apdu(this._cla, this._ins, this._p1, this.p2, this.data.build());\n\n /**\n * Add a 8-bit unsigned integer to the data field (max value 0xff = 255)\n * @param value?: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add8BitUIntToData = (value: number): ApduBuilder => {\n this.data.add8BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 16-bit unsigned integer to the data field (max value 0xffff = 65535)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add16BitUIntToData = (value: number): ApduBuilder => {\n this.data.add16BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 32-bit unsigned integer to the data field (max value 0xffffffff = 4294967295)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add32BitUIntToData = (value: number): ApduBuilder => {\n this.data.add32BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 64-bit unsigned integer to the data field in big-endian (max value 0xffffffffffffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True for big-endian (default), false for little-endian\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add64BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ApduBuilder => {\n this.data.add64BitUIntToData(value, bigEndian);\n return this;\n };\n\n /**\n * Add a Uint8Array to the data field if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addBufferToData = (value: Uint8Array): ApduBuilder => {\n this.data.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a string to the data field 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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addHexaStringToData = (value: string): ApduBuilder => {\n this.data.addHexaStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addAsciiStringToData = (value: string): ApduBuilder => {\n this.data.addAsciiStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromHexa = (value: string): ApduBuilder => {\n this.data.encodeInLVFromHexa(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ApduBuilder => {\n this.data.encodeInLVFromBuffer(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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromAscii = (value: string): ApduBuilder => {\n this.data.encodeInLVFromAscii(value);\n return this;\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number =>\n this.data.getAvailablePayloadLength();\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.data.getErrors();\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,sBAAAE,EAAA,kBAAAC,EAAA,gBAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAN,GAAA,IAAAO,EAAqB,gCAGrBC,EAAiC,8BAE1B,MAAMH,EAAgB,EAChBH,EAAmB,IACnBC,EAAgBD,EAAmB,EA0BzC,MAAME,CAAY,CACN,KACA,KACA,IACA,GACT,KAAyB,IAAI,mBAAiBF,CAAgB,EAEtE,YAAY,CAAE,IAAAO,EAAK,IAAAC,EAAK,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,KAAK,KAAOF,EAAM,IAClB,KAAK,KAAOD,EAAM,IAClB,KAAK,IAAME,EAAK,IAChB,KAAK,GAAKC,EAAK,GACjB,CAUA,MAAQ,IACN,IAAI,OAAK,KAAK,KAAM,KAAK,KAAM,KAAK,IAAK,KAAK,GAAI,KAAK,KAAK,MAAM,CAAC,EAOrE,kBAAqBC,IACnB,KAAK,KAAK,kBAAkBA,CAAK,EAC1B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAST,mBAAqB,CACnBA,EACAC,EAAqB,MAErB,KAAK,KAAK,mBAAmBD,EAAOC,CAAS,EACtC,MAQT,gBAAmBD,IACjB,KAAK,KAAK,gBAAgBA,CAAK,EACxB,MAST,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAQT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAUT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAOT,0BAA4B,IAC1B,KAAK,KAAK,0BAA0B,EAMtC,UAAY,IAAyB,KAAK,KAAK,UAAU,CAC3D",
|
|
6
|
+
"names": ["ApduBuilder_exports", "__export", "APDU_MAX_PAYLOAD", "APDU_MAX_SIZE", "ApduBuilder", "HEADER_LENGTH", "__toCommonJS", "import_Apdu", "import_ByteArrayBuilder", "ins", "cla", "p1", "p2", "value", "bigEndian"]
|
|
7
7
|
}
|
package/lib/esm/package.json
CHANGED
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"watch:builds": "pnpm ldmk-tool watch --entryPoints index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
65
65
|
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
66
66
|
},
|
|
67
|
-
"version": "0.0.0-develop-
|
|
67
|
+
"version": "0.0.0-develop-20260221001335"
|
|
68
68
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Apdu as i}from"../../apdu/model/Apdu";import{ByteArrayBuilder as n}from"./ByteArrayBuilder";const p=5,
|
|
1
|
+
import{Apdu as i}from"../../apdu/model/Apdu";import{ByteArrayBuilder as n}from"./ByteArrayBuilder";const p=5,a=255,l=a+5;class A{_ins;_cla;_p1;p2;data=new n(a);constructor({ins:t,cla:r,p1:e,p2:d}){this._cla=r&255,this._ins=t&255,this._p1=e&255,this.p2=d&255}build=()=>new i(this._cla,this._ins,this._p1,this.p2,this.data.build());add8BitUIntToData=t=>(this.data.add8BitUIntToData(t),this);add16BitUIntToData=t=>(this.data.add16BitUIntToData(t),this);add32BitUIntToData=t=>(this.data.add32BitUIntToData(t),this);add64BitUIntToData=(t,r=!0)=>(this.data.add64BitUIntToData(t,r),this);addBufferToData=t=>(this.data.addBufferToData(t),this);addHexaStringToData=t=>(this.data.addHexaStringToData(t),this);addAsciiStringToData=t=>(this.data.addAsciiStringToData(t),this);encodeInLVFromHexa=t=>(this.data.encodeInLVFromHexa(t),this);encodeInLVFromBuffer=t=>(this.data.encodeInLVFromBuffer(t),this);encodeInLVFromAscii=t=>(this.data.encodeInLVFromAscii(t),this);getAvailablePayloadLength=()=>this.data.getAvailablePayloadLength();getErrors=()=>this.data.getErrors()}export{a as APDU_MAX_PAYLOAD,l as APDU_MAX_SIZE,A as ApduBuilder,p as HEADER_LENGTH};
|
|
2
2
|
//# sourceMappingURL=ApduBuilder.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/api/apdu/utils/ApduBuilder.ts"],
|
|
4
|
-
"sourcesContent": ["import { Apdu } from \"@api/apdu/model/Apdu\";\n\nimport { type AppBuilderError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nexport const HEADER_LENGTH = 5;\nexport const APDU_MAX_PAYLOAD = 255;\nexport const APDU_MAX_SIZE = APDU_MAX_PAYLOAD + 5;\n\nexport type ApduBuilderArgs = {\n readonly ins: number;\n readonly cla: number;\n readonly p1: number;\n readonly p2: number;\n};\n\n/**\n * ApduBuilder is a utility class to help build APDU commands.\n * It allows to easily add data to the data field of the APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const apduBuilder = new ApduBuilder({ ins: 0x01, cla: 0x02, p1: 0x03, p2: 0x04 })\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const apdu = apduBuilder.build();\n * const builderErrors = apduBuilder.getErrors();\n * ```\n */\nexport class ApduBuilder {\n private readonly _ins: number;\n private readonly _cla: number;\n private readonly _p1: number;\n private readonly p2: number;\n private data: ByteArrayBuilder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n\n constructor({ ins, cla, p1, p2 }: ApduBuilderArgs) {\n this._cla = cla & 0xff;\n this._ins = ins & 0xff;\n this._p1 = p1 & 0xff;\n this.p2 = p2 & 0xff;\n }\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new Apdu instance with the current state of the builder\n * @returns {Apdu} - Returns a new Apdu instance\n */\n build = (): Apdu =>\n new Apdu(this._cla, this._ins, this._p1, this.p2, this.data.build());\n\n /**\n * Add a 8-bit unsigned integer to the data field (max value 0xff = 255)\n * @param value?: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add8BitUIntToData = (value: number): ApduBuilder => {\n this.data.add8BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 16-bit unsigned integer to the data field (max value 0xffff = 65535)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add16BitUIntToData = (value: number): ApduBuilder => {\n this.data.add16BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 32-bit unsigned integer to the data field (max value 0xffffffff = 4294967295)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add32BitUIntToData = (value: number): ApduBuilder => {\n this.data.add32BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a Uint8Array to the data field if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addBufferToData = (value: Uint8Array): ApduBuilder => {\n this.data.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a string to the data field 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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addHexaStringToData = (value: string): ApduBuilder => {\n this.data.addHexaStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addAsciiStringToData = (value: string): ApduBuilder => {\n this.data.addAsciiStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromHexa = (value: string): ApduBuilder => {\n this.data.encodeInLVFromHexa(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ApduBuilder => {\n this.data.encodeInLVFromBuffer(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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromAscii = (value: string): ApduBuilder => {\n this.data.encodeInLVFromAscii(value);\n return this;\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number =>\n this.data.getAvailablePayloadLength();\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.data.getErrors();\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,MAAY,uBAGrB,OAAS,oBAAAC,MAAwB,qBAE1B,MAAMC,EAAgB,EAChBC,EAAmB,IACnBC,EAAgBD,EAAmB,EA0BzC,MAAME,CAAY,CACN,KACA,KACA,IACA,GACT,KAAyB,IAAIJ,EAAiBE,CAAgB,EAEtE,YAAY,CAAE,IAAAG,EAAK,IAAAC,EAAK,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,KAAK,KAAOF,EAAM,IAClB,KAAK,KAAOD,EAAM,IAClB,KAAK,IAAME,EAAK,IAChB,KAAK,GAAKC,EAAK,GACjB,CAUA,MAAQ,IACN,IAAIT,EAAK,KAAK,KAAM,KAAK,KAAM,KAAK,IAAK,KAAK,GAAI,KAAK,KAAK,MAAM,CAAC,EAOrE,kBAAqBU,IACnB,KAAK,KAAK,kBAAkBA,CAAK,EAC1B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,
|
|
6
|
-
"names": ["Apdu", "ByteArrayBuilder", "HEADER_LENGTH", "APDU_MAX_PAYLOAD", "APDU_MAX_SIZE", "ApduBuilder", "ins", "cla", "p1", "p2", "value"]
|
|
4
|
+
"sourcesContent": ["import { Apdu } from \"@api/apdu/model/Apdu\";\n\nimport { type AppBuilderError } from \"./AppBuilderError\";\nimport { ByteArrayBuilder } from \"./ByteArrayBuilder\";\n\nexport const HEADER_LENGTH = 5;\nexport const APDU_MAX_PAYLOAD = 255;\nexport const APDU_MAX_SIZE = APDU_MAX_PAYLOAD + 5;\n\nexport type ApduBuilderArgs = {\n readonly ins: number;\n readonly cla: number;\n readonly p1: number;\n readonly p2: number;\n};\n\n/**\n * ApduBuilder is a utility class to help build APDU commands.\n * It allows to easily add data to the data field of the APDU command\n * and to encode this data in different formats.\n *\n * @example\n * ```\n * const apduBuilder = new ApduBuilder({ ins: 0x01, cla: 0x02, p1: 0x03, p2: 0x04 })\n * .add8BitUIntToData(0x05)\n * .add16BitUIntToData(0x0607)\n * .addHexaStringToData(\"0x0809\")\n * .addAsciiStringToData(\"hello\")\n *\n * const apdu = apduBuilder.build();\n * const builderErrors = apduBuilder.getErrors();\n * ```\n */\nexport class ApduBuilder {\n private readonly _ins: number;\n private readonly _cla: number;\n private readonly _p1: number;\n private readonly p2: number;\n private data: ByteArrayBuilder = new ByteArrayBuilder(APDU_MAX_PAYLOAD);\n\n constructor({ ins, cla, p1, p2 }: ApduBuilderArgs) {\n this._cla = cla & 0xff;\n this._ins = ins & 0xff;\n this._p1 = p1 & 0xff;\n this.p2 = p2 & 0xff;\n }\n\n // ==========\n // Public API\n // ==========\n\n /**\n * Build a new Apdu instance with the current state of the builder\n * @returns {Apdu} - Returns a new Apdu instance\n */\n build = (): Apdu =>\n new Apdu(this._cla, this._ins, this._p1, this.p2, this.data.build());\n\n /**\n * Add a 8-bit unsigned integer to the data field (max value 0xff = 255)\n * @param value?: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add8BitUIntToData = (value: number): ApduBuilder => {\n this.data.add8BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 16-bit unsigned integer to the data field (max value 0xffff = 65535)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add16BitUIntToData = (value: number): ApduBuilder => {\n this.data.add16BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 32-bit unsigned integer to the data field (max value 0xffffffff = 4294967295)\n * @param value: number - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add32BitUIntToData = (value: number): ApduBuilder => {\n this.data.add32BitUIntToData(value);\n return this;\n };\n\n /**\n * Add a 64-bit unsigned integer to the data field in big-endian (max value 0xffffffffffffffff)\n * @param value: number | bigint - The value to add to the data\n * @param bigEndian: boolean - True for big-endian (default), false for little-endian\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n add64BitUIntToData = (\n value: number | bigint,\n bigEndian: boolean = true,\n ): ApduBuilder => {\n this.data.add64BitUIntToData(value, bigEndian);\n return this;\n };\n\n /**\n * Add a Uint8Array to the data field if it has enough remaining space\n * @param value: Uint8Array - The value to add to the data\n * @returns {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addBufferToData = (value: Uint8Array): ApduBuilder => {\n this.data.addBufferToData(value);\n return this;\n };\n\n /**\n * Add a string to the data field 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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addHexaStringToData = (value: string): ApduBuilder => {\n this.data.addHexaStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n addAsciiStringToData = (value: string): ApduBuilder => {\n this.data.addAsciiStringToData(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromHexa = (value: string): ApduBuilder => {\n this.data.encodeInLVFromHexa(value);\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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromBuffer = (value: Uint8Array): ApduBuilder => {\n this.data.encodeInLVFromBuffer(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 {ApduBuilder} - Returns the current instance of ApduBuilder\n */\n encodeInLVFromAscii = (value: string): ApduBuilder => {\n this.data.encodeInLVFromAscii(value);\n return this;\n };\n\n /**\n * Returns the remaining payload length\n * @returns {number}\n */\n getAvailablePayloadLength = (): number =>\n this.data.getAvailablePayloadLength();\n\n /**\n * Returns the current errors\n * @returns {AppBuilderError[]} - Returns an array of errors\n */\n getErrors = (): AppBuilderError[] => this.data.getErrors();\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,MAAY,uBAGrB,OAAS,oBAAAC,MAAwB,qBAE1B,MAAMC,EAAgB,EAChBC,EAAmB,IACnBC,EAAgBD,EAAmB,EA0BzC,MAAME,CAAY,CACN,KACA,KACA,IACA,GACT,KAAyB,IAAIJ,EAAiBE,CAAgB,EAEtE,YAAY,CAAE,IAAAG,EAAK,IAAAC,EAAK,GAAAC,EAAI,GAAAC,CAAG,EAAoB,CACjD,KAAK,KAAOF,EAAM,IAClB,KAAK,KAAOD,EAAM,IAClB,KAAK,IAAME,EAAK,IAChB,KAAK,GAAKC,EAAK,GACjB,CAUA,MAAQ,IACN,IAAIT,EAAK,KAAK,KAAM,KAAK,KAAM,KAAK,IAAK,KAAK,GAAI,KAAK,KAAK,MAAM,CAAC,EAOrE,kBAAqBU,IACnB,KAAK,KAAK,kBAAkBA,CAAK,EAC1B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAQT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAST,mBAAqB,CACnBA,EACAC,EAAqB,MAErB,KAAK,KAAK,mBAAmBD,EAAOC,CAAS,EACtC,MAQT,gBAAmBD,IACjB,KAAK,KAAK,gBAAgBA,CAAK,EACxB,MAST,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAQT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,mBAAsBA,IACpB,KAAK,KAAK,mBAAmBA,CAAK,EAC3B,MAUT,qBAAwBA,IACtB,KAAK,KAAK,qBAAqBA,CAAK,EAC7B,MAUT,oBAAuBA,IACrB,KAAK,KAAK,oBAAoBA,CAAK,EAC5B,MAOT,0BAA4B,IAC1B,KAAK,KAAK,0BAA0B,EAMtC,UAAY,IAAyB,KAAK,KAAK,UAAU,CAC3D",
|
|
6
|
+
"names": ["Apdu", "ByteArrayBuilder", "HEADER_LENGTH", "APDU_MAX_PAYLOAD", "APDU_MAX_SIZE", "ApduBuilder", "ins", "cla", "p1", "p2", "value", "bigEndian"]
|
|
7
7
|
}
|
|
@@ -56,6 +56,13 @@ export declare class ApduBuilder {
|
|
|
56
56
|
* @returns {ApduBuilder} - Returns the current instance of ApduBuilder
|
|
57
57
|
*/
|
|
58
58
|
add32BitUIntToData: (value: number) => ApduBuilder;
|
|
59
|
+
/**
|
|
60
|
+
* Add a 64-bit unsigned integer to the data field in big-endian (max value 0xffffffffffffffff)
|
|
61
|
+
* @param value: number | bigint - The value to add to the data
|
|
62
|
+
* @param bigEndian: boolean - True for big-endian (default), false for little-endian
|
|
63
|
+
* @returns {ApduBuilder} - Returns the current instance of ApduBuilder
|
|
64
|
+
*/
|
|
65
|
+
add64BitUIntToData: (value: number | bigint, bigEndian?: boolean) => ApduBuilder;
|
|
59
66
|
/**
|
|
60
67
|
* Add a Uint8Array to the data field if it has enough remaining space
|
|
61
68
|
* @param value: Uint8Array - The value to add to the data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApduBuilder.d.ts","sourceRoot":"","sources":["../../../../../../src/api/apdu/utils/ApduBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,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