@ledgerhq/device-trusted-app-kit-ledger-keyring-protocol 0.0.0-ledger-button-20250808091712 → 0.0.0-ledger-button-20250808181454
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/internal/app-binder/task/SignChallengeWithKeypairTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/SignChallengeWithKeypairTask.js.map +2 -2
- package/lib/esm/internal/app-binder/task/SignChallengeWithKeypairTask.js +1 -1
- package/lib/esm/internal/app-binder/task/SignChallengeWithKeypairTask.js.map +2 -2
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(a,
|
|
1
|
+
"use strict";var g=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(a,e)=>{for(var n in e)g(a,n,{get:e[n],enumerable:!0})},v=(a,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of x(e))!u.call(a,t)&&t!==n&&g(a,t,{get:()=>e[t],enumerable:!(i=m(e,t))||i.enumerable});return a};var E=a=>v(g({},"__esModule",{value:!0}),a);var C={};d(C,{SignChallengeWithKeypairTask:()=>A});module.exports=E(C);var p=require("@ledgerhq/device-management-kit"),s=require("purify-ts"),o=require("../../../api/app-binder/Errors"),h=require("../../utils/crypto"),y=require("../../utils/eitherSeqRecord"),l=require("../../utils/hex");class A{constructor(e,n){this.keypair=e;this.trustchainId=n}run(e){const n=this.getAttestation(),i=this.getCredential(this.keypair.pubKeyToHex());return s.EitherAsync.liftEither(this.getUnsignedChallengeTLV(e.tlv)).map(h.CryptoUtils.hash).map(t=>this.keypair.sign(t)).map(l.bytesToHex).map(t=>({challenge:e.json,signature:{attestation:n,credential:i,signature:t}})).mapLeft(t=>t instanceof o.LKRPMissingDataError?t:new o.LKRPUnknownError(String(t)))}getAttestation(){const e=(0,l.hexToBytes)(this.trustchainId),n=Uint8Array.from([2,e.length,...e]);return(0,l.bytesToHex)(n)}getCredential(e){return{version:0,curveId:33,signAlgorithm:1,publicKey:e}}getUnsignedChallengeTLV(e){const n=new p.ByteArrayParser((0,l.hexToBytes)(e)),i=new Map(function*(){for(;;){const r=n.extractFieldTLVEncoded();if(!r)break;yield[r.tag,r.value]}}());if(i.size>10)return(0,s.Left)(new o.LKRPMissingDataError("Challenge TLV contains unexpected data"));const t=(r,c)=>s.Maybe.fromNullable(i.get(r)).toEither(new o.LKRPMissingDataError(`Missing ${c} field`));return(0,y.eitherSeqRecord)({payloadType:()=>t(1,"Payload type"),version:()=>t(2,"Version"),challengeExpiry:()=>t(22,"Challenge expiry"),host:()=>t(32,"Host"),protocolVersion:()=>t(96,"Protocol version"),curveId:()=>t(50,"Curve ID"),publicKey:()=>t(51,"Public key"),challengeData:()=>t(18,"Challenge data"),signAlgorithm:()=>t(20,"Sign algorithm"),rpSignatureField:()=>t(21,"RP signature field")}).map(r=>Uint8Array.from([[1,r.payloadType.length,...r.payloadType],[2,r.version.length,...r.version],[18,r.challengeData.length,...r.challengeData],[22,r.challengeExpiry.length,...r.challengeExpiry],[32,r.host.length,...r.host],[96,r.protocolVersion.length,...r.protocolVersion]].flat()))}}0&&(module.exports={SignChallengeWithKeypairTask});
|
|
2
2
|
//# sourceMappingURL=SignChallengeWithKeypairTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/SignChallengeWithKeypairTask.ts"],
|
|
4
|
-
"sourcesContent": ["import { ByteArrayParser } from \"@ledgerhq/device-management-kit\";\nimport { type Either, EitherAsync, Left, Maybe } from \"purify-ts\";\n\nimport { LKRPMissingDataError, LKRPUnknownError } from \"@api/app-binder/Errors\";\nimport { type Keypair } from \"@api/app-binder/LKRPTypes\";\nimport {\n type AuthenticationPayload,\n type Challenge,\n} from \"@internal/lkrp-datasource/data/LKRPDataSource\";\nimport { CryptoUtils } from \"@internal/utils/crypto\";\nimport { eitherSeqRecord } from \"@internal/utils/eitherSeqRecord\";\nimport { bytesToHex, hexToBytes } from \"@internal/utils/hex\";\n\nexport class SignChallengeWithKeypairTask {\n constructor(\n private readonly keypair: Keypair,\n private readonly trustchainId: string,\n ) {}\n\n run(\n challenge: Challenge,\n ): EitherAsync<\n LKRPMissingDataError | LKRPUnknownError,\n AuthenticationPayload\n > {\n const attestation = this.getAttestation();\n const credential = this.getCredential(this.keypair.pubKeyToHex());\n\n return EitherAsync.liftEither(this.getUnsignedChallengeTLV(challenge.tlv))\n .map(CryptoUtils.hash)\n .map((hash) => this.keypair.sign(hash))\n .map(bytesToHex)\n .map((signature) => ({\n challenge: challenge.json,\n signature: { attestation, credential, signature },\n }))\n .mapLeft((error) =>\n error instanceof LKRPMissingDataError\n ? error\n : new LKRPUnknownError(String(error)),\n );\n }\n\n // Spec https://ledgerhq.atlassian.net/wiki/spaces/TA/pages/4335960138/ARCH+LedgerLive+Auth+specifications\n private getAttestation() {\n const bytes =
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,2CAChCC,EAAsD,qBAEtDC,EAAuD,kCAMvDC,EAA4B,kCAC5BC,EAAgC,2CAChCC,EAAuC,+BAEhC,MAAMP,CAA6B,CACxC,YACmBQ,EACAC,EACjB,CAFiB,aAAAD,EACA,kBAAAC,CAChB,CAEH,IACEC,EAIA,CACA,MAAMC,EAAc,KAAK,eAAe,EAClCC,EAAa,KAAK,cAAc,KAAK,QAAQ,YAAY,CAAC,EAEhE,OAAO,cAAY,WAAW,KAAK,wBAAwBF,EAAU,GAAG,CAAC,EACtE,IAAI,cAAY,IAAI,EACpB,IAAKG,GAAS,KAAK,QAAQ,KAAKA,CAAI,CAAC,EACrC,IAAI,YAAU,EACd,IAAKC,IAAe,CACnB,UAAWJ,EAAU,KACrB,UAAW,CAAE,YAAAC,EAAa,WAAAC,EAAY,UAAAE,CAAU,CAClD,EAAE,EACD,QAASC,GACRA,aAAiB,uBACbA,EACA,IAAI,mBAAiB,OAAOA,CAAK,CAAC,CACxC,CACJ,CAGQ,gBAAiB,CACvB,MAAMC,
|
|
4
|
+
"sourcesContent": ["import { ByteArrayParser } from \"@ledgerhq/device-management-kit\";\nimport { type Either, EitherAsync, Left, Maybe } from \"purify-ts\";\n\nimport { LKRPMissingDataError, LKRPUnknownError } from \"@api/app-binder/Errors\";\nimport { type Keypair } from \"@api/app-binder/LKRPTypes\";\nimport {\n type AuthenticationPayload,\n type Challenge,\n} from \"@internal/lkrp-datasource/data/LKRPDataSource\";\nimport { CryptoUtils } from \"@internal/utils/crypto\";\nimport { eitherSeqRecord } from \"@internal/utils/eitherSeqRecord\";\nimport { bytesToHex, hexToBytes } from \"@internal/utils/hex\";\n\nexport class SignChallengeWithKeypairTask {\n constructor(\n private readonly keypair: Keypair,\n private readonly trustchainId: string,\n ) {}\n\n run(\n challenge: Challenge,\n ): EitherAsync<\n LKRPMissingDataError | LKRPUnknownError,\n AuthenticationPayload\n > {\n const attestation = this.getAttestation();\n const credential = this.getCredential(this.keypair.pubKeyToHex());\n\n return EitherAsync.liftEither(this.getUnsignedChallengeTLV(challenge.tlv))\n .map(CryptoUtils.hash)\n .map((hash) => this.keypair.sign(hash))\n .map(bytesToHex)\n .map((signature) => ({\n challenge: challenge.json,\n signature: { attestation, credential, signature },\n }))\n .mapLeft((error) =>\n error instanceof LKRPMissingDataError\n ? error\n : new LKRPUnknownError(String(error)),\n );\n }\n\n // Spec https://ledgerhq.atlassian.net/wiki/spaces/TA/pages/4335960138/ARCH+LedgerLive+Auth+specifications\n private getAttestation() {\n const bytes = hexToBytes(this.trustchainId);\n const attestation = Uint8Array.from([0x02, bytes.length, ...bytes]);\n return bytesToHex(attestation);\n }\n\n private getCredential(publicKey: string) {\n return { version: 0, curveId: 33, signAlgorithm: 1, publicKey };\n }\n\n private getUnsignedChallengeTLV(\n tlv: string,\n ): Either<LKRPMissingDataError, Uint8Array> {\n const parser = new ByteArrayParser(hexToBytes(tlv));\n const parsed = new Map(\n (function* () {\n while (true) {\n const field = parser.extractFieldTLVEncoded();\n if (!field) break; // No more fields to extract\n yield [field.tag, field.value];\n }\n })(),\n );\n\n // We expect 10 fields in the TLV\n if (parsed.size > 10) {\n return Left(\n new LKRPMissingDataError(\"Challenge TLV contains unexpected data\"),\n );\n }\n\n const getField = (tag: number, fieldName: string) =>\n Maybe.fromNullable(parsed.get(tag)).toEither(\n new LKRPMissingDataError(`Missing ${fieldName} field`),\n );\n\n return eitherSeqRecord({\n // Unsigned fields\n payloadType: () => getField(0x01, \"Payload type\"),\n version: () => getField(0x02, \"Version\"),\n challengeExpiry: () => getField(0x16, \"Challenge expiry\"),\n host: () => getField(0x20, \"Host\"),\n protocolVersion: () => getField(0x60, \"Protocol version\"),\n\n // Signed fields\n curveId: () => getField(0x32, \"Curve ID\"),\n publicKey: () => getField(0x33, \"Public key\"),\n challengeData: () => getField(0x12, \"Challenge data\"),\n signAlgorithm: () => getField(0x14, \"Sign algorithm\"),\n rpSignatureField: () => getField(0x15, \"RP signature field\"),\n }).map((fields) =>\n Uint8Array.from(\n [\n [0x01, fields.payloadType.length, ...fields.payloadType],\n [0x02, fields.version.length, ...fields.version],\n [0x12, fields.challengeData.length, ...fields.challengeData],\n [0x16, fields.challengeExpiry.length, ...fields.challengeExpiry],\n [0x20, fields.host.length, ...fields.host],\n [0x60, fields.protocolVersion.length, ...fields.protocolVersion],\n ].flat(),\n ),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAgC,2CAChCC,EAAsD,qBAEtDC,EA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AClC,IAAI,uBAAqB,WAAWC,CAAS,QAAQ,CACvD,EAEF,SAAO,mBAAgB,CAErB,YAAa,IAAMF,EAAS,EAAM,cAAc,EAChD,QAAS,IAAMA,EAAS,EAAM,SAAS,EACvC,gBAAiB,IAAMA,EAAS,GAAM,kBAAkB,EACxD,KAAM,IAAMA,EAAS,GAAM,MAAM,EACjC,gBAAiB,IAAMA,EAAS,GAAM,kBAAkB,EAGxD,QAAS,IAAMA,EAAS,GAAM,UAAU,EACxC,UAAW,IAAMA,EAAS,GAAM,YAAY,EAC5C,cAAe,IAAMA,EAAS,GAAM,gBAAgB,EACpD,cAAe,IAAMA,EAAS,GAAM,gBAAgB,EACpD,iBAAkB,IAAMA,EAAS,GAAM,oBAAoB,CAC7D,CAAC,EAAE,IAAKG,GACN,WAAW,KACT,CACE,CAAC,EAAMA,EAAO,YAAY,OAAQ,GAAGA,EAAO,WAAW,EACvD,CAAC,EAAMA,EAAO,QAAQ,OAAQ,GAAGA,EAAO,OAAO,EAC/C,CAAC,GAAMA,EAAO,cAAc,OAAQ,GAAGA,EAAO,aAAa,EAC3D,CAAC,GAAMA,EAAO,gBAAgB,OAAQ,GAAGA,EAAO,eAAe,EAC/D,CAAC,GAAMA,EAAO,KAAK,OAAQ,GAAGA,EAAO,IAAI,EACzC,CAAC,GAAMA,EAAO,gBAAgB,OAAQ,GAAGA,EAAO,eAAe,CACjE,EAAE,KAAK,CACT,CACF,CACF,CACF",
|
|
6
6
|
"names": ["SignChallengeWithKeypairTask_exports", "__export", "SignChallengeWithKeypairTask", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_Errors", "import_crypto", "import_eitherSeqRecord", "import_hex", "keypair", "trustchainId", "challenge", "attestation", "credential", "hash", "signature", "error", "bytes", "publicKey", "tlv", "parser", "parsed", "field", "getField", "tag", "fieldName", "fields"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ByteArrayParser as
|
|
1
|
+
import{ByteArrayParser as g}from"@ledgerhq/device-management-kit";import{EitherAsync as p,Left as h,Maybe as y}from"purify-ts";import{LKRPMissingDataError as i,LKRPUnknownError as c}from"../../../api/app-binder/Errors";import{CryptoUtils as m}from"../../utils/crypto";import{eitherSeqRecord as x}from"../../utils/eitherSeqRecord";import{bytesToHex as o,hexToBytes as l}from"../../utils/hex";class f{constructor(r,n){this.keypair=r;this.trustchainId=n}run(r){const n=this.getAttestation(),a=this.getCredential(this.keypair.pubKeyToHex());return p.liftEither(this.getUnsignedChallengeTLV(r.tlv)).map(m.hash).map(t=>this.keypair.sign(t)).map(o).map(t=>({challenge:r.json,signature:{attestation:n,credential:a,signature:t}})).mapLeft(t=>t instanceof i?t:new c(String(t)))}getAttestation(){const r=l(this.trustchainId),n=Uint8Array.from([2,r.length,...r]);return o(n)}getCredential(r){return{version:0,curveId:33,signAlgorithm:1,publicKey:r}}getUnsignedChallengeTLV(r){const n=new g(l(r)),a=new Map(function*(){for(;;){const e=n.extractFieldTLVEncoded();if(!e)break;yield[e.tag,e.value]}}());if(a.size>10)return h(new i("Challenge TLV contains unexpected data"));const t=(e,s)=>y.fromNullable(a.get(e)).toEither(new i(`Missing ${s} field`));return x({payloadType:()=>t(1,"Payload type"),version:()=>t(2,"Version"),challengeExpiry:()=>t(22,"Challenge expiry"),host:()=>t(32,"Host"),protocolVersion:()=>t(96,"Protocol version"),curveId:()=>t(50,"Curve ID"),publicKey:()=>t(51,"Public key"),challengeData:()=>t(18,"Challenge data"),signAlgorithm:()=>t(20,"Sign algorithm"),rpSignatureField:()=>t(21,"RP signature field")}).map(e=>Uint8Array.from([[1,e.payloadType.length,...e.payloadType],[2,e.version.length,...e.version],[18,e.challengeData.length,...e.challengeData],[22,e.challengeExpiry.length,...e.challengeExpiry],[32,e.host.length,...e.host],[96,e.protocolVersion.length,...e.protocolVersion]].flat()))}}export{f as SignChallengeWithKeypairTask};
|
|
2
2
|
//# sourceMappingURL=SignChallengeWithKeypairTask.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/task/SignChallengeWithKeypairTask.ts"],
|
|
4
|
-
"sourcesContent": ["import { ByteArrayParser } from \"@ledgerhq/device-management-kit\";\nimport { type Either, EitherAsync, Left, Maybe } from \"purify-ts\";\n\nimport { LKRPMissingDataError, LKRPUnknownError } from \"@api/app-binder/Errors\";\nimport { type Keypair } from \"@api/app-binder/LKRPTypes\";\nimport {\n type AuthenticationPayload,\n type Challenge,\n} from \"@internal/lkrp-datasource/data/LKRPDataSource\";\nimport { CryptoUtils } from \"@internal/utils/crypto\";\nimport { eitherSeqRecord } from \"@internal/utils/eitherSeqRecord\";\nimport { bytesToHex, hexToBytes } from \"@internal/utils/hex\";\n\nexport class SignChallengeWithKeypairTask {\n constructor(\n private readonly keypair: Keypair,\n private readonly trustchainId: string,\n ) {}\n\n run(\n challenge: Challenge,\n ): EitherAsync<\n LKRPMissingDataError | LKRPUnknownError,\n AuthenticationPayload\n > {\n const attestation = this.getAttestation();\n const credential = this.getCredential(this.keypair.pubKeyToHex());\n\n return EitherAsync.liftEither(this.getUnsignedChallengeTLV(challenge.tlv))\n .map(CryptoUtils.hash)\n .map((hash) => this.keypair.sign(hash))\n .map(bytesToHex)\n .map((signature) => ({\n challenge: challenge.json,\n signature: { attestation, credential, signature },\n }))\n .mapLeft((error) =>\n error instanceof LKRPMissingDataError\n ? error\n : new LKRPUnknownError(String(error)),\n );\n }\n\n // Spec https://ledgerhq.atlassian.net/wiki/spaces/TA/pages/4335960138/ARCH+LedgerLive+Auth+specifications\n private getAttestation() {\n const bytes =
|
|
5
|
-
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,kCAChC,OAAsB,eAAAC,EAAa,QAAAC,EAAM,SAAAC,MAAa,YAEtD,OAAS,wBAAAC,EAAsB,oBAAAC,MAAwB,yBAMvD,OAAS,eAAAC,MAAmB,yBAC5B,OAAS,mBAAAC,MAAuB,kCAChC,OAAS,cAAAC,EAAY,cAAAC,MAAkB,sBAEhC,MAAMC,CAA6B,CACxC,YACmBC,EACAC,EACjB,CAFiB,aAAAD,EACA,kBAAAC,CAChB,CAEH,IACEC,EAIA,CACA,MAAMC,EAAc,KAAK,eAAe,EAClCC,EAAa,KAAK,cAAc,KAAK,QAAQ,YAAY,CAAC,EAEhE,OAAOd,EAAY,WAAW,KAAK,wBAAwBY,EAAU,GAAG,CAAC,EACtE,IAAIP,EAAY,IAAI,EACpB,IAAKU,GAAS,KAAK,QAAQ,KAAKA,CAAI,CAAC,EACrC,IAAIR,CAAU,EACd,IAAKS,IAAe,CACnB,UAAWJ,EAAU,KACrB,UAAW,CAAE,YAAAC,EAAa,WAAAC,EAAY,UAAAE,CAAU,CAClD,EAAE,EACD,QAASC,GACRA,aAAiBd,EACbc,EACA,IAAIb,EAAiB,OAAOa,CAAK,CAAC,CACxC,CACJ,CAGQ,gBAAiB,CACvB,MAAMC,
|
|
4
|
+
"sourcesContent": ["import { ByteArrayParser } from \"@ledgerhq/device-management-kit\";\nimport { type Either, EitherAsync, Left, Maybe } from \"purify-ts\";\n\nimport { LKRPMissingDataError, LKRPUnknownError } from \"@api/app-binder/Errors\";\nimport { type Keypair } from \"@api/app-binder/LKRPTypes\";\nimport {\n type AuthenticationPayload,\n type Challenge,\n} from \"@internal/lkrp-datasource/data/LKRPDataSource\";\nimport { CryptoUtils } from \"@internal/utils/crypto\";\nimport { eitherSeqRecord } from \"@internal/utils/eitherSeqRecord\";\nimport { bytesToHex, hexToBytes } from \"@internal/utils/hex\";\n\nexport class SignChallengeWithKeypairTask {\n constructor(\n private readonly keypair: Keypair,\n private readonly trustchainId: string,\n ) {}\n\n run(\n challenge: Challenge,\n ): EitherAsync<\n LKRPMissingDataError | LKRPUnknownError,\n AuthenticationPayload\n > {\n const attestation = this.getAttestation();\n const credential = this.getCredential(this.keypair.pubKeyToHex());\n\n return EitherAsync.liftEither(this.getUnsignedChallengeTLV(challenge.tlv))\n .map(CryptoUtils.hash)\n .map((hash) => this.keypair.sign(hash))\n .map(bytesToHex)\n .map((signature) => ({\n challenge: challenge.json,\n signature: { attestation, credential, signature },\n }))\n .mapLeft((error) =>\n error instanceof LKRPMissingDataError\n ? error\n : new LKRPUnknownError(String(error)),\n );\n }\n\n // Spec https://ledgerhq.atlassian.net/wiki/spaces/TA/pages/4335960138/ARCH+LedgerLive+Auth+specifications\n private getAttestation() {\n const bytes = hexToBytes(this.trustchainId);\n const attestation = Uint8Array.from([0x02, bytes.length, ...bytes]);\n return bytesToHex(attestation);\n }\n\n private getCredential(publicKey: string) {\n return { version: 0, curveId: 33, signAlgorithm: 1, publicKey };\n }\n\n private getUnsignedChallengeTLV(\n tlv: string,\n ): Either<LKRPMissingDataError, Uint8Array> {\n const parser = new ByteArrayParser(hexToBytes(tlv));\n const parsed = new Map(\n (function* () {\n while (true) {\n const field = parser.extractFieldTLVEncoded();\n if (!field) break; // No more fields to extract\n yield [field.tag, field.value];\n }\n })(),\n );\n\n // We expect 10 fields in the TLV\n if (parsed.size > 10) {\n return Left(\n new LKRPMissingDataError(\"Challenge TLV contains unexpected data\"),\n );\n }\n\n const getField = (tag: number, fieldName: string) =>\n Maybe.fromNullable(parsed.get(tag)).toEither(\n new LKRPMissingDataError(`Missing ${fieldName} field`),\n );\n\n return eitherSeqRecord({\n // Unsigned fields\n payloadType: () => getField(0x01, \"Payload type\"),\n version: () => getField(0x02, \"Version\"),\n challengeExpiry: () => getField(0x16, \"Challenge expiry\"),\n host: () => getField(0x20, \"Host\"),\n protocolVersion: () => getField(0x60, \"Protocol version\"),\n\n // Signed fields\n curveId: () => getField(0x32, \"Curve ID\"),\n publicKey: () => getField(0x33, \"Public key\"),\n challengeData: () => getField(0x12, \"Challenge data\"),\n signAlgorithm: () => getField(0x14, \"Sign algorithm\"),\n rpSignatureField: () => getField(0x15, \"RP signature field\"),\n }).map((fields) =>\n Uint8Array.from(\n [\n [0x01, fields.payloadType.length, ...fields.payloadType],\n [0x02, fields.version.length, ...fields.version],\n [0x12, fields.challengeData.length, ...fields.challengeData],\n [0x16, fields.challengeExpiry.length, ...fields.challengeExpiry],\n [0x20, fields.host.length, ...fields.host],\n [0x60, fields.protocolVersion.length, ...fields.protocolVersion],\n ].flat(),\n ),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,kCAChC,OAAsB,eAAAC,EAAa,QAAAC,EAAM,SAAAC,MAAa,YAEtD,OAAS,wBAAAC,EAAsB,oBAAAC,MAAwB,yBAMvD,OAAS,eAAAC,MAAmB,yBAC5B,OAAS,mBAAAC,MAAuB,kCAChC,OAAS,cAAAC,EAAY,cAAAC,MAAkB,sBAEhC,MAAMC,CAA6B,CACxC,YACmBC,EACAC,EACjB,CAFiB,aAAAD,EACA,kBAAAC,CAChB,CAEH,IACEC,EAIA,CACA,MAAMC,EAAc,KAAK,eAAe,EAClCC,EAAa,KAAK,cAAc,KAAK,QAAQ,YAAY,CAAC,EAEhE,OAAOd,EAAY,WAAW,KAAK,wBAAwBY,EAAU,GAAG,CAAC,EACtE,IAAIP,EAAY,IAAI,EACpB,IAAKU,GAAS,KAAK,QAAQ,KAAKA,CAAI,CAAC,EACrC,IAAIR,CAAU,EACd,IAAKS,IAAe,CACnB,UAAWJ,EAAU,KACrB,UAAW,CAAE,YAAAC,EAAa,WAAAC,EAAY,UAAAE,CAAU,CAClD,EAAE,EACD,QAASC,GACRA,aAAiBd,EACbc,EACA,IAAIb,EAAiB,OAAOa,CAAK,CAAC,CACxC,CACJ,CAGQ,gBAAiB,CACvB,MAAMC,EAAQV,EAAW,KAAK,YAAY,EACpCK,EAAc,WAAW,KAAK,CAAC,EAAMK,EAAM,OAAQ,GAAGA,CAAK,CAAC,EAClE,OAAOX,EAAWM,CAAW,CAC/B,CAEQ,cAAcM,EAAmB,CACvC,MAAO,CAAE,QAAS,EAAG,QAAS,GAAI,cAAe,EAAG,UAAAA,CAAU,CAChE,CAEQ,wBACNC,EAC0C,CAC1C,MA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,eAAe,CACjE,EAAE,KAAK,CACT,CACF,CACF,CACF",
|
|
6
6
|
"names": ["ByteArrayParser", "EitherAsync", "Left", "Maybe", "LKRPMissingDataError", "LKRPUnknownError", "CryptoUtils", "eitherSeqRecord", "bytesToHex", "hexToBytes", "SignChallengeWithKeypairTask", "keypair", "trustchainId", "challenge", "attestation", "credential", "hash", "signature", "error", "bytes", "publicKey", "tlv", "parser", "parsed", "field", "getField", "tag", "fieldName", "fields"]
|
|
7
7
|
}
|