@ledgerhq/device-trusted-app-kit-ledger-keyring-protocol 0.0.0-ledger-button-20250808181454 → 0.0.0-legacy-speculos-datasource-20250819074123
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/api/LedgerKeyringProtocol.js +1 -1
- package/lib/cjs/api/LedgerKeyringProtocol.js.map +1 -1
- package/lib/cjs/api/LedgerKeyringProtocolBuilder.js +1 -1
- package/lib/cjs/api/LedgerKeyringProtocolBuilder.js.map +3 -3
- package/lib/cjs/api/app-binder/AddToTrustchainDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/AddToTrustchainDeviceActionTypes.js.map +1 -1
- package/lib/cjs/api/app-binder/AuthenticateDeviceActionTypes.js +1 -1
- package/lib/cjs/api/app-binder/AuthenticateDeviceActionTypes.js.map +1 -1
- package/lib/cjs/api/app-binder/Errors.js +1 -1
- package/lib/cjs/api/app-binder/Errors.js.map +3 -3
- package/lib/cjs/api/app-binder/LKRPTypes.js +1 -1
- package/lib/cjs/api/app-binder/LKRPTypes.js.map +3 -3
- package/lib/cjs/api/app-binder/SignBlockHeaderCommandTypes.js +1 -1
- package/lib/cjs/api/app-binder/SignBlockHeaderCommandTypes.js.map +1 -1
- package/lib/cjs/internal/DefaultLedgerKeyringProtocol.js +1 -1
- package/lib/cjs/internal/DefaultLedgerKeyringProtocol.js.map +3 -3
- package/lib/cjs/internal/app-binder/LedgerKeyringProtocolBinder.js +1 -1
- package/lib/cjs/internal/app-binder/LedgerKeyringProtocolBinder.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/SetTrustedMemberCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/SetTrustedMemberCommand.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/SignBlockHeader.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignBlockHeader.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/SignBlockHeader.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignBlockHeader.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/AddToTrustchainDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/AddToTrustchainDeviceAction.js.map +3 -3
- package/lib/cjs/internal/app-binder/device-action/AuthenticateDeviceAction.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/AuthenticateDeviceAction.js.map +2 -2
- package/lib/cjs/internal/app-binder/task/ParseStreamToDeviceTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/ParseStreamToDeviceTask.js.map +3 -3
- package/lib/cjs/internal/app-binder/task/SignBlockTask.js +1 -1
- package/lib/cjs/internal/app-binder/task/SignBlockTask.js.map +3 -3
- 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/cjs/internal/app-binder/task/utils/TrustedProperties.js +1 -1
- package/lib/cjs/internal/app-binder/task/utils/TrustedProperties.js.map +3 -3
- package/lib/cjs/internal/di.js +1 -1
- package/lib/cjs/internal/di.js.map +3 -3
- package/lib/cjs/internal/externalTypes.js +1 -1
- package/lib/cjs/internal/externalTypes.js.map +2 -2
- package/lib/cjs/internal/lkrp-datasource/data/HttpLKRPDataSource.js +1 -1
- package/lib/cjs/internal/lkrp-datasource/data/HttpLKRPDataSource.js.map +3 -3
- package/lib/cjs/internal/lkrp-datasource/data/HttpLKRPDataSource.test.js +1 -1
- package/lib/cjs/internal/lkrp-datasource/data/HttpLKRPDataSource.test.js.map +2 -2
- package/lib/cjs/internal/lkrp-datasource/data/LKRPDataSource.js +1 -1
- package/lib/cjs/internal/lkrp-datasource/data/LKRPDataSource.js.map +1 -1
- package/lib/cjs/internal/use-cases/authentication/AuthenticateUseCase.js +1 -1
- package/lib/cjs/internal/use-cases/authentication/AuthenticateUseCase.js.map +3 -3
- package/lib/cjs/internal/utils/LKRPBlock.js.map +2 -2
- package/lib/cjs/internal/utils/LKRPBlock.test.js +1 -1
- package/lib/cjs/internal/utils/LKRPBlock.test.js.map +3 -3
- package/lib/cjs/internal/utils/LKRPBlockStream.js +2 -2
- package/lib/cjs/internal/utils/LKRPBlockStream.js.map +3 -3
- package/lib/cjs/internal/utils/LKRPBlockStream.test.js +3 -3
- package/lib/cjs/internal/utils/LKRPBlockStream.test.js.map +3 -3
- package/lib/cjs/internal/utils/LKRPCommand.js +2 -2
- package/lib/cjs/internal/utils/LKRPCommand.js.map +3 -3
- package/lib/cjs/internal/utils/LKRPCommand.test.js +1 -1
- package/lib/cjs/internal/utils/LKRPCommand.test.js.map +3 -3
- package/lib/cjs/internal/utils/TLVBuilder.js +1 -1
- package/lib/cjs/internal/utils/TLVBuilder.js.map +3 -3
- package/lib/cjs/internal/utils/TLVParser.js +1 -1
- package/lib/cjs/internal/utils/TLVParser.js.map +3 -3
- package/lib/cjs/internal/utils/TLVParser.test.js +1 -1
- package/lib/cjs/internal/utils/TLVParser.test.js.map +3 -3
- package/lib/cjs/internal/{models/Tags.js → utils/TLVTags.js} +1 -1
- package/lib/cjs/internal/{models/Tags.js.map → utils/TLVTags.js.map} +2 -2
- package/lib/cjs/internal/utils/hex.js +1 -1
- package/lib/cjs/internal/utils/hex.js.map +3 -3
- package/lib/cjs/internal/utils/types.js +2 -0
- package/lib/cjs/internal/utils/types.js.map +7 -0
- package/lib/esm/api/LedgerKeyringProtocolBuilder.js +1 -1
- package/lib/esm/api/LedgerKeyringProtocolBuilder.js.map +3 -3
- package/lib/esm/api/app-binder/Errors.js +1 -1
- package/lib/esm/api/app-binder/Errors.js.map +3 -3
- package/lib/esm/api/app-binder/LKRPTypes.js +1 -1
- package/lib/esm/api/app-binder/LKRPTypes.js.map +3 -3
- package/lib/esm/internal/DefaultLedgerKeyringProtocol.js +1 -1
- package/lib/esm/internal/DefaultLedgerKeyringProtocol.js.map +3 -3
- package/lib/esm/internal/app-binder/LedgerKeyringProtocolBinder.js +1 -1
- package/lib/esm/internal/app-binder/LedgerKeyringProtocolBinder.js.map +3 -3
- package/lib/esm/internal/app-binder/command/SetTrustedMemberCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/SetTrustedMemberCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SignBlockHeader.js +1 -1
- package/lib/esm/internal/app-binder/command/SignBlockHeader.js.map +3 -3
- package/lib/esm/internal/app-binder/command/SignBlockHeader.test.js +1 -1
- package/lib/esm/internal/app-binder/command/SignBlockHeader.test.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/AddToTrustchainDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/AddToTrustchainDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/device-action/AuthenticateDeviceAction.js +1 -1
- package/lib/esm/internal/app-binder/device-action/AuthenticateDeviceAction.js.map +3 -3
- package/lib/esm/internal/app-binder/task/ParseStreamToDeviceTask.js +1 -1
- package/lib/esm/internal/app-binder/task/ParseStreamToDeviceTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/SignBlockTask.js +1 -1
- package/lib/esm/internal/app-binder/task/SignBlockTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/SignChallengeWithKeypairTask.js +1 -1
- package/lib/esm/internal/app-binder/task/SignChallengeWithKeypairTask.js.map +3 -3
- package/lib/esm/internal/app-binder/task/utils/TrustedProperties.js +1 -1
- package/lib/esm/internal/app-binder/task/utils/TrustedProperties.js.map +3 -3
- package/lib/esm/internal/di.js +1 -1
- package/lib/esm/internal/di.js.map +3 -3
- package/lib/esm/internal/externalTypes.js +1 -1
- package/lib/esm/internal/externalTypes.js.map +2 -2
- package/lib/esm/internal/lkrp-datasource/data/HttpLKRPDataSource.js +1 -1
- package/lib/esm/internal/lkrp-datasource/data/HttpLKRPDataSource.js.map +3 -3
- package/lib/esm/internal/lkrp-datasource/data/HttpLKRPDataSource.test.js +1 -1
- package/lib/esm/internal/lkrp-datasource/data/HttpLKRPDataSource.test.js.map +3 -3
- package/lib/esm/internal/use-cases/authentication/AuthenticateUseCase.js +1 -1
- package/lib/esm/internal/use-cases/authentication/AuthenticateUseCase.js.map +3 -3
- package/lib/esm/internal/utils/LKRPBlock.js.map +2 -2
- package/lib/esm/internal/utils/LKRPBlock.test.js +1 -1
- package/lib/esm/internal/utils/LKRPBlock.test.js.map +3 -3
- package/lib/esm/internal/utils/LKRPBlockStream.js +2 -2
- package/lib/esm/internal/utils/LKRPBlockStream.js.map +3 -3
- package/lib/esm/internal/utils/LKRPBlockStream.test.js +3 -3
- package/lib/esm/internal/utils/LKRPBlockStream.test.js.map +3 -3
- package/lib/esm/internal/utils/LKRPCommand.js +2 -2
- package/lib/esm/internal/utils/LKRPCommand.js.map +3 -3
- package/lib/esm/internal/utils/LKRPCommand.test.js +1 -1
- package/lib/esm/internal/utils/LKRPCommand.test.js.map +3 -3
- package/lib/esm/internal/utils/TLVBuilder.js +1 -1
- package/lib/esm/internal/utils/TLVBuilder.js.map +2 -2
- package/lib/esm/internal/utils/TLVParser.js +1 -1
- package/lib/esm/internal/utils/TLVParser.js.map +3 -3
- package/lib/esm/internal/utils/TLVParser.test.js +1 -1
- package/lib/esm/internal/utils/TLVParser.test.js.map +3 -3
- package/lib/esm/internal/{models/Tags.js → utils/TLVTags.js} +1 -1
- package/lib/esm/internal/{models/Tags.js.map → utils/TLVTags.js.map} +1 -1
- package/lib/esm/internal/utils/hex.js +1 -1
- package/lib/esm/internal/utils/hex.js.map +3 -3
- package/lib/esm/internal/utils/types.js +1 -0
- package/lib/types/api/LedgerKeyringProtocol.d.ts +4 -3
- package/lib/types/api/LedgerKeyringProtocol.d.ts.map +1 -1
- package/lib/types/api/LedgerKeyringProtocolBuilder.d.ts +3 -8
- package/lib/types/api/LedgerKeyringProtocolBuilder.d.ts.map +1 -1
- package/lib/types/api/app-binder/AddToTrustchainDeviceActionTypes.d.ts +4 -4
- package/lib/types/api/app-binder/AddToTrustchainDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/AuthenticateDeviceActionTypes.d.ts +5 -5
- package/lib/types/api/app-binder/AuthenticateDeviceActionTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/Errors.d.ts +12 -38
- package/lib/types/api/app-binder/Errors.d.ts.map +1 -1
- package/lib/types/api/app-binder/LKRPTypes.d.ts +0 -4
- package/lib/types/api/app-binder/LKRPTypes.d.ts.map +1 -1
- package/lib/types/api/app-binder/SignBlockHeaderCommandTypes.d.ts +1 -2
- package/lib/types/api/app-binder/SignBlockHeaderCommandTypes.d.ts.map +1 -1
- package/lib/types/internal/DefaultLedgerKeyringProtocol.d.ts +6 -7
- package/lib/types/internal/DefaultLedgerKeyringProtocol.d.ts.map +1 -1
- package/lib/types/internal/app-binder/LedgerKeyringProtocolBinder.d.ts +4 -3
- package/lib/types/internal/app-binder/LedgerKeyringProtocolBinder.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/SignBlockHeader.d.ts +0 -1
- package/lib/types/internal/app-binder/command/SignBlockHeader.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/AddToTrustchainDeviceAction.d.ts +2 -2
- package/lib/types/internal/app-binder/device-action/AddToTrustchainDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/AuthenticateDeviceAction.d.ts +1 -1
- package/lib/types/internal/app-binder/device-action/AuthenticateDeviceAction.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/ParseStreamToDeviceTask.d.ts +3 -3
- package/lib/types/internal/app-binder/task/ParseStreamToDeviceTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/SignBlockTask.d.ts +7 -6
- package/lib/types/internal/app-binder/task/SignBlockTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/SignChallengeWithKeypairTask.d.ts +3 -2
- package/lib/types/internal/app-binder/task/SignChallengeWithKeypairTask.d.ts.map +1 -1
- package/lib/types/internal/app-binder/task/utils/TrustedProperties.d.ts +1 -1
- package/lib/types/internal/app-binder/task/utils/TrustedProperties.d.ts.map +1 -1
- package/lib/types/internal/di.d.ts +1 -4
- package/lib/types/internal/di.d.ts.map +1 -1
- package/lib/types/internal/externalTypes.d.ts +0 -1
- package/lib/types/internal/externalTypes.d.ts.map +1 -1
- package/lib/types/internal/lkrp-datasource/data/HttpLKRPDataSource.d.ts +6 -6
- package/lib/types/internal/lkrp-datasource/data/HttpLKRPDataSource.d.ts.map +1 -1
- package/lib/types/internal/lkrp-datasource/data/LKRPDataSource.d.ts +7 -7
- package/lib/types/internal/lkrp-datasource/data/LKRPDataSource.d.ts.map +1 -1
- package/lib/types/internal/use-cases/authentication/AuthenticateUseCase.d.ts +2 -2
- package/lib/types/internal/use-cases/authentication/AuthenticateUseCase.d.ts.map +1 -1
- package/lib/types/internal/utils/LKRPBlock.d.ts +1 -1
- package/lib/types/internal/utils/LKRPBlock.d.ts.map +1 -1
- package/lib/types/internal/utils/LKRPBlockStream.d.ts +3 -3
- package/lib/types/internal/utils/LKRPBlockStream.d.ts.map +1 -1
- package/lib/types/internal/utils/LKRPCommand.d.ts +2 -3
- package/lib/types/internal/utils/LKRPCommand.d.ts.map +1 -1
- package/lib/types/internal/utils/TLVParser.d.ts +2 -3
- package/lib/types/internal/utils/TLVParser.d.ts.map +1 -1
- package/lib/types/internal/{models/Tags.d.ts → utils/TLVTags.d.ts} +1 -1
- package/lib/types/internal/utils/TLVTags.d.ts.map +1 -0
- package/lib/types/internal/utils/hex.d.ts.map +1 -1
- package/lib/types/internal/{models/LKRPCommandTypes.d.ts → utils/types.d.ts} +29 -6
- package/lib/types/internal/utils/types.d.ts.map +1 -0
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/lib/cjs/internal/models/LKRPBlockTypes.js +0 -2
- package/lib/cjs/internal/models/LKRPBlockTypes.js.map +0 -7
- package/lib/cjs/internal/models/LKRPCommandTypes.js +0 -2
- package/lib/cjs/internal/models/LKRPCommandTypes.js.map +0 -7
- package/lib/cjs/internal/models/Types.js +0 -2
- package/lib/cjs/internal/models/Types.js.map +0 -7
- package/lib/esm/internal/models/LKRPBlockTypes.js +0 -1
- package/lib/esm/internal/models/LKRPCommandTypes.js +0 -1
- package/lib/esm/internal/models/LKRPCommandTypes.js.map +0 -7
- package/lib/esm/internal/models/Types.js +0 -1
- package/lib/esm/internal/models/Types.js.map +0 -7
- package/lib/types/internal/models/LKRPBlockTypes.d.ts +0 -11
- package/lib/types/internal/models/LKRPBlockTypes.d.ts.map +0 -1
- package/lib/types/internal/models/LKRPCommandTypes.d.ts.map +0 -1
- package/lib/types/internal/models/Tags.d.ts.map +0 -1
- package/lib/types/internal/models/Types.d.ts +0 -14
- package/lib/types/internal/models/Types.d.ts.map +0 -1
- /package/lib/esm/internal/{models/LKRPBlockTypes.js.map → utils/types.js.map} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ByteArrayParser as a}from"@ledgerhq/device-management-kit";import{Either as p,Left as o,Right as i}from"purify-ts";import{LKRPParsingError as P}from"../../../../api/app-binder/Errors";import{
|
|
1
|
+
import{ByteArrayParser as a}from"@ledgerhq/device-management-kit";import{Either as p,Left as o,Right as i}from"purify-ts";import{LKRPParsingError as P}from"../../../../api/app-binder/Errors";import{required as e}from"../../../utils/required";import{TPTags as t}from"../../../utils/TLVTags";class h{constructor(r){this.bytes=r;this.parser=new a(r)}parser;iv=null;encryptedProps=null;getIv(){if(!this.iv){const r=this.parser.extractFieldTLVEncoded();if(!r||r.tag!==0)return o(new P("Invalid trusted property: missing IV"));this.iv=r.value}return i(this.iv)}getIssuer(){return this.parseEncryptedProps().chain(r=>e(r.get(t.ISSUER)?.value,"Missing issuer in trusted properties"))}getXPriv(){return this.parseEncryptedProps().chain(r=>e(r.get(t.XPRIV)?.value,"Missing xpriv in trusted properties"))}getEphemeralPublicKey(){return this.parseEncryptedProps().chain(r=>e(r.get(t.EPHEMERAL_PUBLIC_KEY)?.value,"Missing ephemeral public key in trusted properties"))}getCommandIv(){return this.parseEncryptedProps().chain(r=>e(r.get(t.COMMAND_IV)?.value,"Missing command IV in trusted properties"))}getGroupKey(){return this.parseEncryptedProps().chain(r=>e(r.get(t.GROUPKEY)?.value,"Missing group key in trusted properties"))}getNewMember(){return this.parseEncryptedProps().chain(r=>e(r.get(t.NEW_MEMBER)?.tlv,"Missing new member in trusted properties"))}parseEncryptedProps(){return this.encryptedProps?i(this.encryptedProps):this.getIv().chain(()=>p.sequence(Array.from(E(this.parser)))).map(r=>new Map(r.map(n=>[n.tag,n]))).ifRight(r=>{this.encryptedProps=r})}}function*E(s){for(;;){const r=s.extractFieldTLVEncoded();if(!r)return;yield i(r)}}export{h as TrustedProperties};
|
|
2
2
|
//# sourceMappingURL=TrustedProperties.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/app-binder/task/utils/TrustedProperties.ts"],
|
|
4
|
-
"sourcesContent": ["import { ByteArrayParser } from \"@ledgerhq/device-management-kit\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport {\n type LKRPMissingDataError,\n LKRPParsingError,\n} from \"@api/app-binder/Errors\";\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,kCAChC,OAAS,UAAAC,EAAQ,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAEE,oBAAAC,MACK,yBACP,OAAS,
|
|
6
|
-
"names": ["ByteArrayParser", "Either", "Left", "Right", "LKRPParsingError", "
|
|
4
|
+
"sourcesContent": ["import { ByteArrayParser } from \"@ledgerhq/device-management-kit\";\nimport { Either, Left, Right } from \"purify-ts\";\n\nimport {\n type LKRPMissingDataError,\n LKRPParsingError,\n} from \"@api/app-binder/Errors\";\nimport { required } from \"@internal/utils/required\";\nimport { TPTags } from \"@internal/utils/TLVTags\";\n\ntype EncryptedTPTag = Exclude<TPTags, TPTags.IV>;\ntype EncryptedTP = { tag: EncryptedTPTag; value: Uint8Array; tlv: Uint8Array };\n\nexport class TrustedProperties {\n private readonly parser: ByteArrayParser;\n private iv: Uint8Array | null = null;\n private encryptedProps: Map<EncryptedTPTag, EncryptedTP> | null = null;\n\n constructor(public readonly bytes: Uint8Array) {\n this.parser = new ByteArrayParser(bytes);\n }\n\n getIv(): Either<LKRPParsingError, Uint8Array> {\n if (!this.iv) {\n const field = this.parser.extractFieldTLVEncoded();\n if (!field || field.tag !== 0x00) {\n return Left(\n new LKRPParsingError(\"Invalid trusted property: missing IV\"),\n );\n }\n\n this.iv = field.value;\n }\n return Right(this.iv);\n }\n\n getIssuer(): Either<LKRPParsingError | LKRPMissingDataError, Uint8Array> {\n return this.parseEncryptedProps().chain((props) =>\n required(\n props.get(TPTags.ISSUER)?.value,\n \"Missing issuer in trusted properties\",\n ),\n );\n }\n\n getXPriv(): Either<LKRPParsingError | LKRPMissingDataError, Uint8Array> {\n return this.parseEncryptedProps().chain((props) =>\n required(\n props.get(TPTags.XPRIV)?.value,\n \"Missing xpriv in trusted properties\",\n ),\n );\n }\n\n getEphemeralPublicKey(): Either<\n LKRPParsingError | LKRPMissingDataError,\n Uint8Array\n > {\n return this.parseEncryptedProps().chain((props) =>\n required(\n props.get(TPTags.EPHEMERAL_PUBLIC_KEY)?.value,\n \"Missing ephemeral public key in trusted properties\",\n ),\n );\n }\n\n getCommandIv(): Either<LKRPParsingError | LKRPMissingDataError, Uint8Array> {\n return this.parseEncryptedProps().chain((props) =>\n required(\n props.get(TPTags.COMMAND_IV)?.value,\n \"Missing command IV in trusted properties\",\n ),\n );\n }\n\n getGroupKey(): Either<LKRPParsingError | LKRPMissingDataError, Uint8Array> {\n return this.parseEncryptedProps().chain((props) =>\n required(\n props.get(TPTags.GROUPKEY)?.value,\n \"Missing group key in trusted properties\",\n ),\n );\n }\n\n getNewMember(): Either<LKRPParsingError | LKRPMissingDataError, Uint8Array> {\n return this.parseEncryptedProps().chain((props) =>\n required(\n props.get(TPTags.NEW_MEMBER)?.tlv,\n \"Missing new member in trusted properties\",\n ),\n );\n }\n\n parseEncryptedProps(): Either<\n LKRPParsingError,\n Map<EncryptedTPTag, EncryptedTP>\n > {\n return this.encryptedProps\n ? Right(this.encryptedProps)\n : this.getIv()\n .chain(() => Either.sequence(Array.from(parseTPs(this.parser))))\n .map((fields) => new Map(fields.map((field) => [field.tag, field])))\n .ifRight((props) => {\n this.encryptedProps = props;\n });\n }\n}\n\nfunction* parseTPs(\n parser: ByteArrayParser,\n): Generator<Either<LKRPParsingError, EncryptedTP>> {\n while (true) {\n const field = parser.extractFieldTLVEncoded();\n if (!field) return;\n yield Right(field);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,mBAAAA,MAAuB,kCAChC,OAAS,UAAAC,EAAQ,QAAAC,EAAM,SAAAC,MAAa,YAEpC,OAEE,oBAAAC,MACK,yBACP,OAAS,YAAAC,MAAgB,2BACzB,OAAS,UAAAC,MAAc,0BAKhB,MAAMC,CAAkB,CAK7B,YAA4BC,EAAmB,CAAnB,WAAAA,EAC1B,KAAK,OAAS,IAAIR,EAAgBQ,CAAK,CACzC,CANiB,OACT,GAAwB,KACxB,eAA0D,KAMlE,OAA8C,CAC5C,GAAI,CAAC,KAAK,GAAI,CACZ,MAAMC,EAAQ,KAAK,OAAO,uBAAuB,EACjD,GAAI,CAACA,GAASA,EAAM,MAAQ,EAC1B,OAAOP,EACL,IAAIE,EAAiB,sCAAsC,CAC7D,EAGF,KAAK,GAAKK,EAAM,KAClB,CACA,OAAON,EAAM,KAAK,EAAE,CACtB,CAEA,WAAyE,CACvE,OAAO,KAAK,oBAAoB,EAAE,MAAOO,GACvCL,EACEK,EAAM,IAAIJ,EAAO,MAAM,GAAG,MAC1B,sCACF,CACF,CACF,CAEA,UAAwE,CACtE,OAAO,KAAK,oBAAoB,EAAE,MAAOI,GACvCL,EACEK,EAAM,IAAIJ,EAAO,KAAK,GAAG,MACzB,qCACF,CACF,CACF,CAEA,uBAGE,CACA,OAAO,KAAK,oBAAoB,EAAE,MAAOI,GACvCL,EACEK,EAAM,IAAIJ,EAAO,oBAAoB,GAAG,MACxC,oDACF,CACF,CACF,CAEA,cAA4E,CAC1E,OAAO,KAAK,oBAAoB,EAAE,MAAOI,GACvCL,EACEK,EAAM,IAAIJ,EAAO,UAAU,GAAG,MAC9B,0CACF,CACF,CACF,CAEA,aAA2E,CACzE,OAAO,KAAK,oBAAoB,EAAE,MAAOI,GACvCL,EACEK,EAAM,IAAIJ,EAAO,QAAQ,GAAG,MAC5B,yCACF,CACF,CACF,CAEA,cAA4E,CAC1E,OAAO,KAAK,oBAAoB,EAAE,MAAOI,GACvCL,EACEK,EAAM,IAAIJ,EAAO,UAAU,GAAG,IAC9B,0CACF,CACF,CACF,CAEA,qBAGE,CACA,OAAO,KAAK,eACRH,EAAM,KAAK,cAAc,EACzB,KAAK,MAAM,EACR,MAAM,IAAMF,EAAO,SAAS,MAAM,KAAKU,EAAS,KAAK,MAAM,CAAC,CAAC,CAAC,EAC9D,IAAKC,GAAW,IAAI,IAAIA,EAAO,IAAKH,GAAU,CAACA,EAAM,IAAKA,CAAK,CAAC,CAAC,CAAC,EAClE,QAASC,GAAU,CAClB,KAAK,eAAiBA,CACxB,CAAC,CACT,CACF,CAEA,SAAUC,EACRE,EACkD,CAClD,OAAa,CACX,MAAMJ,EAAQI,EAAO,uBAAuB,EAC5C,GAAI,CAACJ,EAAO,OACZ,MAAMN,EAAMM,CAAK,CACnB,CACF",
|
|
6
|
+
"names": ["ByteArrayParser", "Either", "Left", "Right", "LKRPParsingError", "required", "TPTags", "TrustedProperties", "bytes", "field", "props", "parseTPs", "fields", "parser"]
|
|
7
7
|
}
|
package/lib/esm/internal/di.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Container as
|
|
1
|
+
import{Container as a}from"inversify";import{appBindingModuleFactory as s}from"./app-binder/di/appBinderModule";import{lkrpDatasourceModuleFactory as m}from"./lkrp-datasource/di/lkrpDatasourceModuleFactory";import{useCasesModuleFactory as p}from"./use-cases/di/useCasesModule";import{externalTypes as o}from"./externalTypes";const D=({dmk:t,sessionId:n,baseUrl:r,stub:i})=>{const e=new a;return e.bind(o.Dmk).toConstantValue(t),e.bind(o.SessionId).toConstantValue(n),e.loadSync(s(),m({baseUrl:r,stub:i}),p()),e};export{D as makeContainer};
|
|
2
2
|
//# sourceMappingURL=di.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/di.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type DeviceManagementKit,\n type DeviceSessionId,\n} from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport {
|
|
5
|
-
"mappings": "AAIA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,
|
|
6
|
-
"names": ["Container", "
|
|
4
|
+
"sourcesContent": ["import {\n type DeviceManagementKit,\n type DeviceSessionId,\n} from \"@ledgerhq/device-management-kit\";\nimport { Container } from \"inversify\";\n\nimport { appBindingModuleFactory } from \"@internal/app-binder/di/appBinderModule\";\n\nimport { lkrpDatasourceModuleFactory } from \"./lkrp-datasource/di/lkrpDatasourceModuleFactory\";\nimport { useCasesModuleFactory } from \"./use-cases/di/useCasesModule\";\nimport { externalTypes } from \"./externalTypes\";\n\nexport type MakeContainerProps = {\n dmk: DeviceManagementKit;\n sessionId: DeviceSessionId;\n baseUrl?: string; // Optional base URL for the LKRP network requests\n stub?: boolean;\n};\n\nexport const makeContainer = ({\n dmk,\n sessionId,\n baseUrl,\n stub,\n}: MakeContainerProps) => {\n const container = new Container();\n\n container.bind<DeviceManagementKit>(externalTypes.Dmk).toConstantValue(dmk);\n container\n .bind<DeviceSessionId>(externalTypes.SessionId)\n .toConstantValue(sessionId);\n\n container.loadSync(\n appBindingModuleFactory(),\n lkrpDatasourceModuleFactory({ baseUrl, stub }),\n useCasesModuleFactory(),\n );\n\n return container;\n};\n"],
|
|
5
|
+
"mappings": "AAIA,OAAS,aAAAA,MAAiB,YAE1B,OAAS,2BAAAC,MAA+B,0CAExC,OAAS,+BAAAC,MAAmC,mDAC5C,OAAS,yBAAAC,MAA6B,gCACtC,OAAS,iBAAAC,MAAqB,kBASvB,MAAMC,EAAgB,CAAC,CAC5B,IAAAC,EACA,UAAAC,EACA,QAAAC,EACA,KAAAC,CACF,IAA0B,CACxB,MAAMC,EAAY,IAAIV,EAEtB,OAAAU,EAAU,KAA0BN,EAAc,GAAG,EAAE,gBAAgBE,CAAG,EAC1EI,EACG,KAAsBN,EAAc,SAAS,EAC7C,gBAAgBG,CAAS,EAE5BG,EAAU,SACRT,EAAwB,EACxBC,EAA4B,CAAE,QAAAM,EAAS,KAAAC,CAAK,CAAC,EAC7CN,EAAsB,CACxB,EAEOO,CACT",
|
|
6
|
+
"names": ["Container", "appBindingModuleFactory", "lkrpDatasourceModuleFactory", "useCasesModuleFactory", "externalTypes", "makeContainer", "dmk", "sessionId", "baseUrl", "stub", "container"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const r={Dmk:Symbol.for("Dmk"),SessionId:Symbol.for("SessionId")
|
|
1
|
+
const r={Dmk:Symbol.for("Dmk"),SessionId:Symbol.for("SessionId")};export{r as externalTypes};
|
|
2
2
|
//# sourceMappingURL=externalTypes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/internal/externalTypes.ts"],
|
|
4
|
-
"sourcesContent": ["export const externalTypes = {\n Dmk: Symbol.for(\"Dmk\"),\n SessionId: Symbol.for(\"SessionId\"),\n
|
|
5
|
-
"mappings": "AAAO,MAAMA,EAAgB,CAC3B,IAAK,OAAO,IAAI,KAAK,EACrB,UAAW,OAAO,IAAI,WAAW,
|
|
4
|
+
"sourcesContent": ["export const externalTypes = {\n Dmk: Symbol.for(\"Dmk\"),\n SessionId: Symbol.for(\"SessionId\"),\n};\n\nexport type TrustedProperty = {\n iv: Uint8Array;\n issuer: Uint8Array;\n xpriv: Uint8Array;\n ephemeralPubKey: Uint8Array;\n commandIV: Uint8Array;\n groupKey: Uint8Array;\n newMember: Uint8Array;\n};\n"],
|
|
5
|
+
"mappings": "AAAO,MAAMA,EAAgB,CAC3B,IAAK,OAAO,IAAI,KAAK,EACrB,UAAW,OAAO,IAAI,WAAW,CACnC",
|
|
6
6
|
"names": ["externalTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var d=Object.defineProperty;var
|
|
1
|
+
var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=(n,t,e,r)=>{for(var i=r>1?void 0:r?f(t,e):t,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=(r?o(t,e,i):o(i))||i);return r&&i&&d(t,e,i),i},c=(n,t)=>(e,r)=>t(e,r,n);import{inject as g,injectable as y}from"inversify";import{EitherAsync as R,Just as u,Maybe as b,Nothing as l,Right as p}from"purify-ts";import{LKRPHttpRequestError as h,LKRPUnauthorizedError as T}from"../../../api/app-binder/Errors";import{lkrpDatasourceTypes as P}from"../../lkrp-datasource/di/lkrpDatasourceTypes";import{LKRPBlockStream as $}from"../../utils/LKRPBlockStream";let a=class{constructor(t){this.baseUrl=t}getChallenge(){return this.request("/challenge",l)}authenticate(t){return this.request("/authenticate",l,{method:"POST",body:JSON.stringify(t)}).map(e=>({jwt:e,trustchainId:b.fromNullable(Object.keys(e.permissions).find(r=>!!e.permissions[r]?.["m/"]))}))}getTrustchainById(t,e){return this.request(`/trustchain/${t}`,u(e)).map(r=>Object.fromEntries(Object.entries(r).map(([i,s])=>[i,$.fromHex(s)])))}postDerivation(t,e,r){return this.request(`/trustchain/${t}/derivation`,u(r),{method:"POST",body:JSON.stringify(e.toString())})}putCommands(t,e,r,i){return this.request(`/trustchain/${t}/commands`,u(i),{method:"PUT",body:JSON.stringify({path:e,blocks:[r.toString()]})})}request(t,e,r){const i=this.baseUrl+t;return R.fromPromise(async()=>{const s=await fetch(i,{...r,headers:{...r?.headers,"Content-Type":"application/json",...e.mapOrDefault(({access_token:o})=>({Authorization:`Bearer ${o}`}),{})}});switch(s.status){case 204:return p(void 0);case 401:throw new T(`Unauthorized request to ${i}: [${s.status}] ${s.statusText}`);default:if(!s.ok)throw new h(`Failed to fetch ${i}: [${s.status}] ${s.statusText}`);return p(await s.json())}}).mapLeft(s=>s instanceof h?s:new h(s))}};a=m([y(),c(0,g(P.BaseUrl))],a);export{a as HttpLKRPDataSource};
|
|
2
2
|
//# sourceMappingURL=HttpLKRPDataSource.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/lkrp-datasource/data/HttpLKRPDataSource.ts"],
|
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync, Just,
|
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YACnC,OAAS,eAAAC,EAAa,QAAAC,EAAM,
|
|
6
|
-
"names": ["inject", "injectable", "EitherAsync", "Just", "
|
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\nimport { EitherAsync, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport {\n LKRPHttpRequestError,\n LKRPUnauthorizedError,\n} from \"@api/app-binder/Errors\";\nimport { JWT } from \"@api/app-binder/LKRPTypes\";\nimport { lkrpDatasourceTypes } from \"@internal/lkrp-datasource/di/lkrpDatasourceTypes\";\nimport { LKRPBlock } from \"@internal/utils/LKRPBlock\";\nimport { LKRPBlockStream } from \"@internal/utils/LKRPBlockStream\";\n\nimport {\n AuthenticationPayload,\n Challenge,\n LKRPDataSource,\n} from \"./LKRPDataSource\";\n\n@injectable()\nexport class HttpLKRPDataSource implements LKRPDataSource {\n constructor(\n @inject(lkrpDatasourceTypes.BaseUrl) private readonly baseUrl: string,\n ) {}\n\n getChallenge() {\n return this.request<Challenge>(\"/challenge\", Nothing);\n }\n\n authenticate(payload: AuthenticationPayload) {\n return this.request<JWT>(\"/authenticate\", Nothing, {\n method: \"POST\",\n body: JSON.stringify(payload),\n }).map((jwt) => ({\n jwt,\n trustchainId: Maybe.fromNullable(\n Object.keys(jwt.permissions).find((id) =>\n Boolean(jwt.permissions[id]?.[\"m/\"]),\n ),\n ),\n }));\n }\n\n getTrustchainById(id: string, jwt: JWT) {\n return this.request<{ [path: string]: string }>(\n `/trustchain/${id}`,\n Just(jwt),\n ).map((serialized) =>\n Object.fromEntries(\n Object.entries(serialized).map(([path, stream]) => [\n path,\n LKRPBlockStream.fromHex(stream),\n ]),\n ),\n );\n }\n\n postDerivation(id: string, block: LKRPBlock, jwt: JWT) {\n return this.request<void>(`/trustchain/${id}/derivation`, Just(jwt), {\n method: \"POST\",\n body: JSON.stringify(block.toString()),\n });\n }\n\n putCommands(id: string, path: string, block: LKRPBlock, jwt: JWT) {\n return this.request<void>(`/trustchain/${id}/commands`, Just(jwt), {\n method: \"PUT\",\n body: JSON.stringify({ path, blocks: [block.toString()] }),\n });\n }\n\n private request<Res>(\n endpoint: `/${string}`,\n jwt: Maybe<{ access_token: string }>,\n init?: RequestInit,\n ): EitherAsync<LKRPHttpRequestError, Res> {\n const href = this.baseUrl + endpoint;\n\n return EitherAsync.fromPromise(async () => {\n const response = await fetch(href, {\n ...init,\n headers: {\n ...init?.headers,\n \"Content-Type\": \"application/json\",\n ...jwt.mapOrDefault<{ Authorization?: string }>(\n ({ access_token }) => ({ Authorization: `Bearer ${access_token}` }),\n {},\n ),\n },\n });\n switch (response.status) {\n case 204:\n return Right(undefined as Res);\n\n case 401:\n throw new LKRPUnauthorizedError(\n `Unauthorized request to ${href}: [${response.status}] ${response.statusText}`,\n );\n\n default:\n if (!response.ok) {\n throw new LKRPHttpRequestError(\n `Failed to fetch ${href}: [${response.status}] ${response.statusText}`,\n );\n }\n return Right((await response.json()) as Res);\n }\n }).mapLeft((error: unknown) =>\n error instanceof LKRPHttpRequestError\n ? error\n : new LKRPHttpRequestError(error),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "iO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,CAAC,CAC3D,CAAC,CACH,CAEQ,QACNC,EACAT,EACAU,EACwC,CACxC,MAAMC,EAAO,KAAK,QAAUF,EAE5B,OAAOG,EAAY,YAAY,SAAY,CACzC,MAAMC,EAAW,MAAM,MAAMF,EAAM,CACjC,GAAGD,EACH,QAAS,CACP,GAAGA,GAAM,QACT,eAAgB,mBAChB,GAAGV,EAAI,aACL,CAAC,CAAE,aAAAc,CAAa,KAAO,CAAE,cAAe,UAAUA,CAAY,EAAG,GACjE,CAAC,CACH,CACF,CACF,CAAC,EACD,OAAQD,EAAS,OAAQ,CACvB,IAAK,KACH,OAAOE,EAAM,MAAgB,EAE/B,IAAK,KACH,MAAM,IAAIC,EACR,2BAA2BL,CAAI,MAAME,EAAS,MAAM,KAAKA,EAAS,UAAU,EAC9E,EAEF,QACE,GAAI,CAACA,EAAS,GACZ,MAAM,IAAII,EACR,mBAAmBN,CAAI,MAAME,EAAS,MAAM,KAAKA,EAAS,UAAU,EACtE,EAEF,OAAOE,EAAO,MAAMF,EAAS,KAAK,CAAS,CAC/C,CACF,CAAC,EAAE,QAASK,GACVA,aAAiBD,EACbC,EACA,IAAID,EAAqBC,CAAK,CACpC,CACF,CACF,EA7FatB,EAANuB,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAoB,OAAO,IAF1B3B",
|
|
6
|
+
"names": ["inject", "injectable", "EitherAsync", "Just", "Maybe", "Nothing", "Right", "LKRPHttpRequestError", "LKRPUnauthorizedError", "lkrpDatasourceTypes", "LKRPBlockStream", "HttpLKRPDataSource", "baseUrl", "Nothing", "payload", "jwt", "Maybe", "id", "Just", "serialized", "path", "stream", "LKRPBlockStream", "block", "endpoint", "init", "href", "EitherAsync", "response", "access_token", "Right", "LKRPUnauthorizedError", "LKRPHttpRequestError", "error", "__decorateClass", "injectable", "__decorateParam", "inject", "lkrpDatasourceTypes"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Just as b,Left as d,Nothing as S,Right as r}from"purify-ts";import{
|
|
1
|
+
import{Just as b,Left as d,Nothing as S,Right as r}from"purify-ts";import{LKRPHttpRequestError as h,LKRPUnauthorizedError as T}from"../../../api/app-binder/Errors";import{LKRPBlock as m}from"../../utils/LKRPBlock";import{LKRPBlockStream as p}from"../../utils/LKRPBlockStream";import{HttpLKRPDataSource as c}from"./HttpLKRPDataSource";const n={access_token:"ACCESS TOKEN",permissions:{TRUSTCHAIN_ID:{"m/":["owner"]}}},i={version:0,challenge:{data:"1010101010010101010",expiry:"2025-06-30T10:00:00Z"},host:"example.com",rp:[{credential:{version:0,curveId:33,signAlgorithm:1,publicKey:"aaaaaaaaaaaaaaaaaaaaaaaaaa"},signature:"abababababababab"}],protocolVersion:{major:1,minor:0,patch:0}},u={credential:{version:0,curveId:33,signAlgorithm:1,publicKey:"bbbbbbbbbbbbbbbbbbbbbbbbbbb"},signature:"acacacacacacacac",attestation:"0000000000000000"};describe("HttpLKRPDataSource",()=>{const a=vi.spyOn(global,"fetch"),t="https://example.com";afterEach(()=>{a.mockClear()}),describe("getChallenge",()=>{it("should fetch challenge successfully",async()=>{const e={tlv:"0f1234567890",json:i};a.mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve(e)});const s=await new c(t).getChallenge();expect(a).toHaveBeenCalledWith(`${t}/challenge`,{headers:{"Content-Type":"application/json"}}),expect(s).toEqual(r(e))}),it("should handle fetch error",async()=>{const e=new Error("Random error");a.mockRejectedValueOnce(e);const s=await new c(t).getChallenge();expect(s).toEqual(d(new h(e)))})}),describe("authenticate",()=>{it("should fetch a JWT when the authentication is successful",async()=>{a.mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve(n)});const o=await new c(t).authenticate({challenge:i,signature:u});expect(a).toHaveBeenCalledWith(`${t}/authenticate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({challenge:i,signature:u})}),expect(o).toEqual(r({jwt:n,trustchainId:b("TRUSTCHAIN_ID")}))}),it("should return no trustchainId the returned JWT does not contain one",async()=>{const e={access_token:"ACCESS TOKEN",permissions:{}};a.mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve(e)});const s=await new c(t).authenticate({challenge:i,signature:u});expect(s).toEqual(r({jwt:e,trustchainId:S}))}),it("should handle authentication error",async()=>{a.mockResolvedValueOnce({ok:!1,status:401,statusText:"Unauthorized"});const o=await new c(t).authenticate({challenge:i,signature:u});expect(o).toEqual(d(new T(`Unauthorized request to ${t}/authenticate: [401] Unauthorized`)))})}),describe("getTrustchainById",()=>{it("should fetch trustchain by ID successfully",async()=>{const e={"m/":"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1d","m/16'":"1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b"};a.mockResolvedValueOnce({ok:!0,json:()=>Promise.resolve(e)});const s=await new c(t).getTrustchainById("TRUSTCHAIN_ID",n);expect(a).toHaveBeenCalledWith(`${t}/trustchain/TRUSTCHAIN_ID`,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.access_token}`}}),expect(s).toEqual(r({"m/":p.fromHex("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1d"),"m/16'":p.fromHex("1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b")}))}),it("should handle errors",async()=>{a.mockResolvedValueOnce({ok:!1,status:500,statusText:"Internal Server Error"});const o=await new c(t).getTrustchainById("TRUSTCHAIN_ID",n);expect(o).toEqual(d(new h(`Failed to fetch ${t}/trustchain/TRUSTCHAIN_ID: [500] Internal Server Error`)))})}),describe("postDerivation",()=>{it("should post derivation successfully",async()=>{const e="0102030405060708090a0b0c0d0e0f",o=m.fromHex(e);a.mockResolvedValueOnce({ok:!0,status:204});const l=await new c(t).postDerivation("TRUSTCHAIN_ID",o,n);expect(a).toHaveBeenCalledWith(`${t}/trustchain/TRUSTCHAIN_ID/derivation`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.access_token}`},body:JSON.stringify(e)}),expect(l).toEqual(r(void 0))})}),describe("putCommands",()=>{it("should put commands successfully",async()=>{const e="0102030405060708090a0b0c0d0e0f",o=m.fromHex(e);a.mockResolvedValueOnce({ok:!0,status:204});const l=await new c(t).putCommands("TRUSTCHAIN_ID","m/0'/16'/0'",o,n);expect(a).toHaveBeenCalledWith(`${t}/trustchain/TRUSTCHAIN_ID/commands`,{method:"PUT",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.access_token}`},body:JSON.stringify({path:"m/0'/16'/0'",blocks:[e]})}),expect(l).toEqual(r(void 0))})})});
|
|
2
2
|
//# sourceMappingURL=HttpLKRPDataSource.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/lkrp-datasource/data/HttpLKRPDataSource.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,YAE3C,
|
|
6
|
-
"names": ["Just", "Left", "Nothing", "Right", "
|
|
4
|
+
"sourcesContent": ["import { Just, Left, Nothing, Right } from \"purify-ts\";\n\nimport {\n LKRPHttpRequestError,\n LKRPUnauthorizedError,\n} from \"@api/app-binder/Errors\";\nimport { LKRPBlock } from \"@internal/utils/LKRPBlock\";\nimport { LKRPBlockStream } from \"@internal/utils/LKRPBlockStream\";\n\nimport { HttpLKRPDataSource } from \"./HttpLKRPDataSource\";\n\nconst mockJwt = {\n access_token: \"ACCESS TOKEN\",\n permissions: { TRUSTCHAIN_ID: { \"m/\": [\"owner\"] } },\n};\n\nconst mockChallengeJSON = {\n version: 0,\n challenge: {\n data: \"1010101010010101010\",\n expiry: \"2025-06-30T10:00:00Z\",\n },\n host: \"example.com\",\n rp: [\n {\n credential: {\n version: 0,\n curveId: 33,\n signAlgorithm: 1,\n publicKey: \"aaaaaaaaaaaaaaaaaaaaaaaaaa\",\n },\n signature: \"abababababababab\",\n },\n ],\n protocolVersion: { major: 1, minor: 0, patch: 0 },\n};\n\nconst mockSignature = {\n credential: {\n version: 0,\n curveId: 33,\n signAlgorithm: 1,\n publicKey: \"bbbbbbbbbbbbbbbbbbbbbbbbbbb\",\n },\n signature: \"acacacacacacacac\",\n attestation: \"0000000000000000\",\n};\n\ndescribe(\"HttpLKRPDataSource\", () => {\n const fetchSpy = vi.spyOn(global, \"fetch\");\n const baseUrl = \"https://example.com\";\n\n afterEach(() => {\n fetchSpy.mockClear();\n });\n\n describe(\"getChallenge\", () => {\n it(\"should fetch challenge successfully\", async () => {\n // GIVEN\n const mockChallenge = {\n tlv: \"0f1234567890\",\n json: mockChallengeJSON,\n };\n\n fetchSpy.mockResolvedValueOnce({\n ok: true,\n json: () => Promise.resolve(mockChallenge),\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.getChallenge();\n expect(fetchSpy).toHaveBeenCalledWith(`${baseUrl}/challenge`, {\n headers: {\n \"Content-Type\": \"application/json\",\n },\n });\n\n // THEN\n expect(result).toEqual(Right(mockChallenge));\n });\n\n it(\"should handle fetch error\", async () => {\n // GIVEN\n const error = new Error(\"Random error\");\n fetchSpy.mockRejectedValueOnce(error);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.getChallenge();\n\n // THEN\n expect(result).toEqual(Left(new LKRPHttpRequestError(error)));\n });\n });\n\n describe(\"authenticate\", () => {\n it(\"should fetch a JWT when the authentication is successful\", async () => {\n // GIVEN\n fetchSpy.mockResolvedValueOnce({\n ok: true,\n json: () => Promise.resolve(mockJwt),\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.authenticate({\n challenge: mockChallengeJSON,\n signature: mockSignature,\n });\n\n // THEN\n expect(fetchSpy).toHaveBeenCalledWith(`${baseUrl}/authenticate`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n challenge: mockChallengeJSON,\n signature: mockSignature,\n }),\n });\n expect(result).toEqual(\n Right({ jwt: mockJwt, trustchainId: Just(\"TRUSTCHAIN_ID\") }),\n );\n });\n\n it(\"should return no trustchainId the returned JWT does not contain one\", async () => {\n // GIVEN\n const jwtWithoutTrustchainId = {\n access_token: \"ACCESS TOKEN\",\n permissions: {},\n };\n fetchSpy.mockResolvedValueOnce({\n ok: true,\n json: () => Promise.resolve(jwtWithoutTrustchainId),\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.authenticate({\n challenge: mockChallengeJSON,\n signature: mockSignature,\n });\n\n // THEN\n expect(result).toEqual(\n Right({ jwt: jwtWithoutTrustchainId, trustchainId: Nothing }),\n );\n });\n\n it(\"should handle authentication error\", async () => {\n // GIVEN\n fetchSpy.mockResolvedValueOnce({\n ok: false,\n status: 401,\n statusText: \"Unauthorized\",\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.authenticate({\n challenge: mockChallengeJSON,\n signature: mockSignature,\n });\n\n // THEN\n expect(result).toEqual(\n Left(\n new LKRPUnauthorizedError(\n `Unauthorized request to ${baseUrl}/authenticate: [401] Unauthorized`,\n ),\n ),\n );\n });\n });\n\n describe(\"getTrustchainById\", () => {\n it(\"should fetch trustchain by ID successfully\", async () => {\n // GIVEN\n const mockTrustchain = {\n \"m/\": \"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1d\",\n \"m/16'\": \"1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b\",\n };\n fetchSpy.mockResolvedValueOnce({\n ok: true,\n json: () => Promise.resolve(mockTrustchain),\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.getTrustchainById(\n \"TRUSTCHAIN_ID\",\n mockJwt,\n );\n\n // THEN\n expect(fetchSpy).toHaveBeenCalledWith(\n `${baseUrl}/trustchain/TRUSTCHAIN_ID`,\n {\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${mockJwt.access_token}`,\n },\n },\n );\n expect(result).toEqual(\n Right({\n \"m/\": LKRPBlockStream.fromHex(\n \"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1e1d\",\n ),\n \"m/16'\": LKRPBlockStream.fromHex(\n \"1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b\",\n ),\n }),\n );\n });\n\n it(\"should handle errors\", async () => {\n // GIVEN\n fetchSpy.mockResolvedValueOnce({\n ok: false,\n status: 500,\n statusText: \"Internal Server Error\",\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.getTrustchainById(\n \"TRUSTCHAIN_ID\",\n mockJwt,\n );\n\n // THEN\n expect(result).toEqual(\n Left(\n new LKRPHttpRequestError(\n `Failed to fetch ${baseUrl}/trustchain/TRUSTCHAIN_ID: [500] Internal Server Error`,\n ),\n ),\n );\n });\n });\n\n describe(\"postDerivation\", () => {\n it(\"should post derivation successfully\", async () => {\n // GIVEN\n const hex = \"0102030405060708090a0b0c0d0e0f\";\n const mockBlock = LKRPBlock.fromHex(hex);\n fetchSpy.mockResolvedValueOnce({\n ok: true,\n status: 204,\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.postDerivation(\n \"TRUSTCHAIN_ID\",\n mockBlock,\n mockJwt,\n );\n\n // THEN\n expect(fetchSpy).toHaveBeenCalledWith(\n `${baseUrl}/trustchain/TRUSTCHAIN_ID/derivation`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${mockJwt.access_token}`,\n },\n body: JSON.stringify(hex),\n },\n );\n expect(result).toEqual(Right(undefined));\n });\n });\n\n describe(\"putCommands\", () => {\n it(\"should put commands successfully\", async () => {\n // GIVEN\n const hex = \"0102030405060708090a0b0c0d0e0f\";\n const mockBlock = LKRPBlock.fromHex(hex);\n fetchSpy.mockResolvedValueOnce({\n ok: true,\n status: 204,\n } as Response);\n\n // WHEN\n const dataSource = new HttpLKRPDataSource(baseUrl);\n const result = await dataSource.putCommands(\n \"TRUSTCHAIN_ID\",\n \"m/0'/16'/0'\",\n mockBlock,\n mockJwt,\n );\n\n // THEN\n expect(fetchSpy).toHaveBeenCalledWith(\n `${baseUrl}/trustchain/TRUSTCHAIN_ID/commands`,\n {\n method: \"PUT\",\n headers: {\n \"Content-Type\": \"application/json\",\n Authorization: `Bearer ${mockJwt.access_token}`,\n },\n body: JSON.stringify({ path: \"m/0'/16'/0'\", blocks: [hex] }),\n },\n );\n expect(result).toEqual(Right(undefined));\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,QAAAC,EAAM,WAAAC,EAAS,SAAAC,MAAa,YAE3C,OACE,wBAAAC,EACA,yBAAAC,MACK,yBACP,OAAS,aAAAC,MAAiB,4BAC1B,OAAS,mBAAAC,MAAuB,kCAEhC,OAAS,sBAAAC,MAA0B,uBAEnC,MAAMC,EAAU,CACd,aAAc,eACd,YAAa,CAAE,cAAe,CAAE,KAAM,CAAC,OAAO,CAAE,CAAE,CACpD,EAEMC,EAAoB,CACxB,QAAS,EACT,UAAW,CACT,KAAM,sBACN,OAAQ,sBACV,EACA,KAAM,cACN,GAAI,CACF,CACE,WAAY,CACV,QAAS,EACT,QAAS,GACT,cAAe,EACf,UAAW,4BACb,EACA,UAAW,kBACb,CACF,EACA,gBAAiB,CAAE,MAAO,EAAG,MAAO,EAAG,MAAO,CAAE,CAClD,EAEMC,EAAgB,CACpB,WAAY,CACV,QAAS,EACT,QAAS,GACT,cAAe,EACf,UAAW,6BACb,EACA,UAAW,mBACX,YAAa,kBACf,EAEA,SAAS,qBAAsB,IAAM,CACnC,MAAMC,EAAW,GAAG,MAAM,OAAQ,OAAO,EACnCC,EAAU,sBAEhB,UAAU,IAAM,CACdD,EAAS,UAAU,CACrB,CAAC,EAED,S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estError", "LKRPUnauthorizedError", "LKRPBlock", "LKRPBlockStream", "HttpLKRPDataSource", "mockJwt", "mockChallengeJSON", "mockSignature", "fetchSpy", "baseUrl", "mockChallenge", "result", "error", "jwtWithoutTrustchainId", "mockTrustchain", "hex", "mockBlock"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var g=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=(
|
|
1
|
+
var g=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var c=(n,r,o,e)=>{for(var i=e>1?void 0:e?s(r,o):r,p=n.length-1,t;p>=0;p--)(t=n[p])&&(i=(e?t(r,o,i):t(i))||i);return e&&i&&g(r,o,i),i},d=(n,r)=>(o,e)=>r(o,e,n);import{inject as y,injectable as a}from"inversify";import{appBinderTypes as u}from"../../app-binder/di/appBinderTypes";let m=class{constructor(r){this.appBinder=r}execute(r,o,e,i,p,t){return this.appBinder.authenticate({keypair:r,applicationId:o,clientName:e,permissions:i,trustchainId:p,jwt:t})}};m=c([a(),d(0,y(u.AppBinding))],m);export{m as AuthenticateUseCase};
|
|
2
2
|
//# sourceMappingURL=AuthenticateUseCase.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/use-cases/authentication/AuthenticateUseCase.ts"],
|
|
4
|
-
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { AuthenticateDAReturnType } from \"@api/app-binder/AuthenticateDeviceActionTypes\";\nimport { Keypair, Permissions } from \"@api/app-binder/LKRPTypes\";\nimport { appBinderTypes } from \"@internal/app-binder/di/appBinderTypes\";\nimport { LedgerKeyringProtocolBinder } from \"@internal/app-binder/LedgerKeyringProtocolBinder\";\n\n@injectable()\nexport class AuthenticateUseCase {\n constructor(\n @inject(appBinderTypes.AppBinding)\n private appBinder: LedgerKeyringProtocolBinder,\n ) {}\n\n execute(\n keypair: Keypair,\n clientName: string,\n permissions: Permissions,\n trustchainId?: string,\n ): AuthenticateDAReturnType {\n return this.appBinder.authenticate({\n keypair,\n clientName,\n permissions,\n trustchainId,\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAInC,OAAS,kBAAAC,MAAsB,yCAIxB,IAAMC,EAAN,KAA0B,CAC/B,YAEUC,EACR,CADQ,eAAAA,CACP,CAEH,QACEC,EACAC,EACAC,EACAC,EAC0B,CAC1B,OAAO,KAAK,UAAU,aAAa,CACjC,
|
|
6
|
-
"names": ["inject", "injectable", "appBinderTypes", "AuthenticateUseCase", "appBinder", "keypair", "clientName", "permissions", "trustchainId", "__decorateClass", "injectable", "__decorateParam", "inject", "appBinderTypes"]
|
|
4
|
+
"sourcesContent": ["import { inject, injectable } from \"inversify\";\n\nimport { AuthenticateDAReturnType } from \"@api/app-binder/AuthenticateDeviceActionTypes\";\nimport { JWT, Keypair, Permissions } from \"@api/app-binder/LKRPTypes\";\nimport { appBinderTypes } from \"@internal/app-binder/di/appBinderTypes\";\nimport { LedgerKeyringProtocolBinder } from \"@internal/app-binder/LedgerKeyringProtocolBinder\";\n\n@injectable()\nexport class AuthenticateUseCase {\n constructor(\n @inject(appBinderTypes.AppBinding)\n private appBinder: LedgerKeyringProtocolBinder,\n ) {}\n\n execute(\n keypair: Keypair,\n applicationId: number,\n clientName: string,\n permissions: Permissions,\n trustchainId?: string,\n jwt?: JWT,\n ): AuthenticateDAReturnType {\n return this.appBinder.authenticate({\n keypair,\n applicationId,\n clientName,\n permissions,\n trustchainId,\n jwt,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "iOAAA,OAAS,UAAAA,EAAQ,cAAAC,MAAkB,YAInC,OAAS,kBAAAC,MAAsB,yCAIxB,IAAMC,EAAN,KAA0B,CAC/B,YAEUC,EACR,CADQ,eAAAA,CACP,CAEH,QACEC,EACAC,EACAC,EACAC,EACAC,EACAC,EAC0B,CAC1B,OAAO,KAAK,UAAU,aAAa,CACjC,QAAAL,EACA,cAAAC,EACA,WAAAC,EACA,YAAAC,EACA,aAAAC,EACA,IAAAC,CACF,CAAC,CACH,CACF,EAvBaP,EAANQ,EAAA,CADNC,EAAW,EAGPC,EAAA,EAAAC,EAAOC,EAAe,UAAU,IAFxBZ",
|
|
6
|
+
"names": ["inject", "injectable", "appBinderTypes", "AuthenticateUseCase", "appBinder", "keypair", "applicationId", "clientName", "permissions", "trustchainId", "jwt", "__decorateClass", "injectable", "__decorateParam", "inject", "appBinderTypes"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPBlock.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n bufferToHexaString,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Either, Just, type Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/app-binder/Errors\";\nimport {
|
|
5
|
-
"mappings": "AAAA,OACE,sBAAAA,EACA,sBAAAC,MACK,kCACP,OAAS,UAAAC,EAAQ,QAAAC,EAAkB,WAAAC,EAAS,SAAAC,MAAa,
|
|
4
|
+
"sourcesContent": ["import {\n bufferToHexaString,\n hexaStringToBuffer,\n} from \"@ledgerhq/device-management-kit\";\nimport { Either, Just, type Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/app-binder/Errors\";\n\nimport { CryptoUtils } from \"./crypto\";\nimport { TLVBuilder } from \"./TLVBuilder\";\nimport { TLVParser } from \"./TLVParser\";\nimport { type LKRPBlockData, type LKRPBlockParsedData } from \"./types\";\n\nexport class LKRPBlock {\n private hashValue: Maybe<string> = Nothing; // Cache hash value for performance\n private data: Maybe<Either<LKRPParsingError, LKRPBlockParsedData>>;\n\n public constructor(\n private readonly bytes: Uint8Array,\n data?: LKRPBlockParsedData,\n ) {\n this.data = data ? Just(Right(data)) : Nothing;\n }\n\n static fromHex(hex: string): LKRPBlock {\n return new LKRPBlock(hexaStringToBuffer(hex) ?? new Uint8Array());\n }\n\n static fromData(data: LKRPBlockData): LKRPBlock {\n const builder = new TLVBuilder()\n .addInt(1, 1) // Version 1\n .addHash(hexaStringToBuffer(data.parent) ?? new Uint8Array())\n .addPublicKey(data.issuer)\n .addInt(data.commands.length, 1);\n\n const header = builder.build();\n\n data.commands.forEach((cmd) => builder.push(cmd.toU8A()));\n\n const sigStart = builder.build().length;\n const bytes = builder.addSignature(data.signature).build();\n const signature = bytes.slice(sigStart, bytes.length);\n\n return new LKRPBlock(bytes, { ...data, header, signature });\n }\n\n toString(): string {\n return bufferToHexaString(this.bytes).slice(2);\n }\n\n toU8A(): Uint8Array {\n return this.bytes;\n }\n\n parse(): Either<LKRPParsingError, LKRPBlockParsedData> {\n return this.data.orDefaultLazy(() => {\n const data = new TLVParser(this.bytes).parseBlockData();\n this.data = Just(data);\n return data;\n });\n }\n\n toHuman(): Either<LKRPParsingError, string> {\n return this.parse()\n .chain((data) =>\n Either.sequence(data.commands.map((cmd) => cmd.toHuman())).map(\n (commands) => ({ ...data, commands }),\n ),\n )\n .map((data) =>\n [\n `Parent: ${data.parent}`,\n `Issuer: ${bufferToHexaString(data.issuer).slice(2)}`,\n `Commands:${data.commands\n .flatMap((cmd) => cmd.split(\"\\n\").map((l) => `\\n ${l}`))\n .join(\"\")}`,\n `Signature: ${bufferToHexaString(data.signature.slice(2)).slice(2)}`,\n ].join(\"\\n\"),\n );\n }\n\n hash(): string {\n return this.hashValue.orDefaultLazy(() => {\n const hashValue = CryptoUtils.hash(this.bytes);\n return bufferToHexaString(hashValue).slice(2);\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,sBAAAA,EACA,sBAAAC,MACK,kCACP,OAAS,UAAAC,EAAQ,QAAAC,EAAkB,WAAAC,EAAS,SAAAC,MAAa,YAIzD,OAAS,eAAAC,MAAmB,WAC5B,OAAS,cAAAC,MAAkB,eAC3B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,EACrC,CACF,EACC,IAAKP,GACJ,CACE,WAAWA,EAAK,MAAM,GACtB,WAAWX,EAAmBW,EAAK,MAAM,EAAE,MAAM,CAAC,CAAC,GACnD,YAAYA,EAAK,SACd,QAASI,GAAQA,EAAI,MAAM;AAAA,CAAI,EAAE,IAAKI,GAAM;AAAA,IAAOA,CAAC,EAAE,CAAC,EACvD,KAAK,EAAE,CAAC,GACX,cAAcnB,EAAmBW,EAAK,UAAU,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,EACpE,EAAE,KAAK;AAAA,CAAI,CACb,CACJ,CAEA,MAAe,CACb,OAAO,KAAK,UAAU,cAAc,IAAM,CACxC,MAAMS,EAAYd,EAAY,KAAK,KAAK,KAAK,EAC7C,OAAON,EAAmBoB,CAAS,EAAE,MAAM,CAAC,CAC9C,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["bufferToHexaString", "hexaStringToBuffer", "Either", "Just", "Nothing", "Right", "CryptoUtils", "TLVBuilder", "TLVParser", "LKRPBlock", "bytes", "data", "hex", "builder", "header", "cmd", "sigStart", "signature", "commands", "l", "hashValue"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Left as n,Right as b}from"purify-ts";import{LKRPParsingError as s}from"../../api/app-binder/Errors";import{
|
|
1
|
+
import{Left as n,Right as b}from"purify-ts";import{LKRPParsingError as s}from"../../api/app-binder/Errors";import{hexToBytes as l}from"./hex";import{LKRPBlock as d}from"./LKRPBlock";import{LKRPCommand as t}from"./LKRPCommand";import{GeneralTags as m}from"./TLVTags";const f={parent:"0000",issuer:new Uint8Array([1,2,3]),commands:[t.fromHex("10020102"),t.fromHex("11020304")],signature:new Uint8Array([4,5,6])},r=["010101","02020000","0603010203","010102"].join(""),a=[...r,"10020102","11020304","0303040506"].join(""),o={...f,header:l(r),signature:Uint8Array.from([m.Signature,3,...f.signature])};describe("LKRPBlock",()=>{describe("fromData",()=>{it("should create a Block from data",()=>{const e=d.fromData(f);expect(e.parse()).toStrictEqual(b(o)),expect(e.toString()).toBe(a)})}),describe("toString",()=>{it("should return the hex representation of the block",()=>{const e=d.fromHex(a);expect(e.toString()).toBe(a)})}),describe("toU8A",()=>{it("should return the bytes of the block",()=>{const e=new Uint8Array([1,2,3,4,5,6,7,8]),c=new d(e);expect(c.toU8A()).toBe(e)})}),describe("parse",()=>{it("should parse the block data correctly",()=>{const c=d.fromHex(a).parse();expect(c).toStrictEqual(b(o))}),it("should fail if the block data is invalid",()=>{const e=d.fromHex("invalid");expect(e.parse()).toStrictEqual(n(new s("Unexpected end of TLV")))})}),describe("toHuman",()=>{it("should return a human-readable representation of the block",()=>{const e=`
|
|
2
2
|
01 01 01
|
|
3
3
|
02 20 1d bf 17 52 c5 4b 9f b5 4f b7 c3 63 c1 e6 15 f7 2f d9 61 b7 97 e6 f0 9e 6c 1d 1b 6e db 28 5a 6d
|
|
4
4
|
06 21 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPBlock.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { LKRPParsingError } from \"@api/app-binder/Errors\";\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,oBAAAC,MAAwB,
|
|
6
|
-
"names": ["Left", "Right", "LKRPParsingError", "
|
|
4
|
+
"sourcesContent": ["import { Left, Right } from \"purify-ts\";\n\nimport { LKRPParsingError } from \"@api/app-binder/Errors\";\n\nimport { hexToBytes } from \"./hex\";\nimport { LKRPBlock } from \"./LKRPBlock\";\nimport { LKRPCommand } from \"./LKRPCommand\";\nimport { GeneralTags } from \"./TLVTags\";\n\n// Mocked data for testing\nconst mockedBlockData = {\n parent: \"0000\",\n issuer: new Uint8Array([1, 2, 3]),\n commands: [LKRPCommand.fromHex(\"10020102\"), LKRPCommand.fromHex(\"11020304\")],\n signature: new Uint8Array([4, 5, 6]),\n};\nconst mockedHeaderHex = [\n \"010101\", // Version: 1\n \"02020000\", // Parent hash: 00 00 00\n \"0603010203\", // Issuer: 01 02 03\n \"010102\", // Command Count: 2\n].join(\"\");\nconst mockedBlockHex = [\n ...mockedHeaderHex, // Header\n \"10020102\", // Command 1\n \"11020304\", // Command 2\n \"0303040506\", // Signature: 04 05 06\n].join(\"\");\nconst parsedMockedBlockData = {\n ...mockedBlockData,\n header: hexToBytes(mockedHeaderHex),\n signature: Uint8Array.from([\n GeneralTags.Signature,\n 3,\n ...mockedBlockData.signature,\n ]),\n};\n\ndescribe(\"LKRPBlock\", () => {\n describe(\"fromData\", () => {\n it(\"should create a Block from data\", () => {\n // WHEN\n const block = LKRPBlock.fromData(mockedBlockData);\n // THEN\n expect(block.parse()).toStrictEqual(Right(parsedMockedBlockData));\n expect(block.toString()).toBe(mockedBlockHex);\n });\n });\n\n describe(\"toString\", () => {\n it(\"should return the hex representation of the block\", () => {\n // WHEN\n const block = LKRPBlock.fromHex(mockedBlockHex);\n // THEN\n expect(block.toString()).toBe(mockedBlockHex);\n });\n });\n\n describe(\"toU8A\", () => {\n it(\"should return the bytes of the block\", () => {\n // GIVEN\n const bytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);\n // WHEN\n const block = new LKRPBlock(bytes);\n // THEN\n expect(block.toU8A()).toBe(bytes);\n });\n });\n\n describe(\"parse\", () => {\n it(\"should parse the block data correctly\", () => {\n // GIVEN\n const block = LKRPBlock.fromHex(mockedBlockHex);\n // WHEN\n const parsedData = block.parse();\n // THEN\n expect(parsedData).toStrictEqual(Right(parsedMockedBlockData));\n });\n\n it(\"should fail if the block data is invalid\", () => {\n // WHEN\n const invalidBlock = LKRPBlock.fromHex(\"invalid\");\n // THEN\n expect(invalidBlock.parse()).toStrictEqual(\n Left(new LKRPParsingError(\"Unexpected end of TLV\")),\n );\n });\n });\n\n describe(\"toHuman\", () => {\n it(\"should return a human-readable representation of the block\", () => {\n // GIVEN\n const hex = `\n 01 01 01\n 02 20 1d bf 17 52 c5 4b 9f b5 4f b7 c3 63 c1 e6 15 f7 2f d9 61 b7 97 e6 f0 9e 6c 1d 1b 6e db 28 5a 6d\n 06 21 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21\n 01 01 03\n 15 b8\n 05 0c 80 00 00 00 80 00 00 10 80 00 00 01\n 06 21 03 4f 37 31 2d 9b ab d8 c0 32 e1 dd 2d e3 3d a3 69 fa 1c e3 0f 00 5b bb a6 00 d1 73 30 ba 39 2c b2\n 05 10 b6 da 2c 97 a3 ec 8b 07 4f 38 f1 50 8a ed 33 35\n 05 50 d2 1f 8f 30 77 02 33 3f 7a 59 3b eb d7 98 a6 b0 6e b5 90 42 77 26 8a 91 35 0a 3c 1b 1e e6 7c 24 b5 a4 7d 22 8c 60 d0 fb c1 52 4e ac 1b cf 12 3e 6e 26 b5 d7 17 08 29 1c c0 8d cf 49 de 0b b3 4b ac f2 00 93 52 4c a6 56 5d 87 c6 36 b2 44 75 b2\n 06 21 02 93 fe b6 64 12 53 6d 3d 71 d5 c7 af ac 96 a3 6e a8 c6 85 88 9e eb cf 6f 6f 82 68 57 12 fe f1 50\n 11 37\n 04 0c 64 65 62 75 67 2d 64 34 63 36 31 64\n 06 21 03 d4 c6 1d da 2a af 76 29 54 fc e9 73 96 d9 be 03 99 e1 dc 75 c3 b7 90 c7 a3 4d de 85 96 a1 18 12\n 01 04 ff ff ff ff\n 12 aa\n 05 10 e7 b7 36 c4 0b 14 a8 30 fb 23 aa de d8 ea e5 44\n 05 50 df 7e 80 8c 79 46 75 d0 a2 d4 66 d4 ef c8 ec d0 7d 52 36 80 16 10 0d 34 d6 fd b8 e6 da 86 e9 2f bb b7 11 0c b5 64 29 b8 3b 1c b9 74 ed 4b 70 51 43 f6 91 b5 b8 14 68 ab d2 c5 26 26 6a 6d ee 6d f4 fd f1 a9 d8 1f e7 4c da 4f 61 c9 89 60 b4 db\n 06 21 03 d4 c6 1d da 2a af 76 29 54 fc e9 73 96 d9 be 03 99 e1 dc 75 c3 b7 90 c7 a3 4d de 85 96 a1 18 12\n 06 21 02 45 f1 1d 7d 78 bd 22 76 45 11 8a bb 20 b4 07 ff 97 8d f8 7a 6b b3 c4 46 1d 63 37 66 85 8f 98 f5\n 03 47 30 45 02 21 00 a0 ea 9d ee 12 f3 83 13 2f 90 72 ad 47 85 a4 15 14 75 d5 70 4a a9 ff 7f 95 52 e9 03 47 b4 ce be 02 20 71 a3 e4 4c 1f 4f a6 4b c6 e2 f4 06 fa 00 fc b4 6f 70 1c 99 49 29 12 bf 33 c7 3e df b2 d5 d1 71\n `.replace(/\\s/g, \"\");\n\n // WHEN\n const block = LKRPBlock.fromHex(hex);\n const humanReadable = block.toHuman();\n\n // THEN\n expect(humanReadable).toStrictEqual(\n Right(\n [\n `Parent: 1dbf1752c54b9fb54fb7c363c1e615f72fd961b797e6f09e6c1d1b6edb285a6d`,\n `Issuer: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021`,\n `Commands:`,\n ` Derive(0x15):`,\n ` path: m/0'/16'/1'`,\n ` groupKey: 034f37312d9babd8c032e1dd2de33da369fa1ce30f005bbba600d17330ba392cb2`,\n ` initializationVector: b6da2c97a3ec8b074f38f1508aed3335`,\n ` encryptedXpriv: d21f8f307702333f7a593bebd798a6b06eb5904277268a91350a3c1b1ee67c24b5a47d228c60d0fbc1524eac1bcf123e6e26b5d71708291cc08dcf49de0bb34bacf20093524ca6565d87c636b24475b2`,\n ` ephemeralPublicKey: 0293feb66412536d3d71d5c7afac96a36ea8c685889eebcf6f6f82685712fef150`,\n ` AddMember(0x11):`,\n ` name: debug-d4c61d`,\n ` publicKey: 03d4c61dda2aaf762954fce97396d9be0399e1dc75c3b790c7a34dde8596a11812`,\n ` permissions: 4294967295`,\n ` PublishKey(0x12):`,\n ` initializationVector: e7b736c40b14a830fb23aaded8eae544`,\n ` encryptedXpriv: df7e808c794675d0a2d466d4efc8ecd07d52368016100d34d6fdb8e6da86e92fbbb7110cb56429b83b1cb974ed4b705143f691b5b81468abd2c526266a6dee6df4fdf1a9d81fe74cda4f61c98960b4db`,\n ` recipient: 03d4c61dda2aaf762954fce97396d9be0399e1dc75c3b790c7a34dde8596a11812`,\n ` ephemeralPublicKey: 0245f11d7d78bd227645118abb20b407ff978df87a6bb3c4461d633766858f98f5`,\n `Signature: 3045022100a0ea9dee12f383132f9072ad4785a4151475d5704aa9ff7f9552e90347b4cebe022071a3e44c1f4fa64bc6e2f406fa00fcb46f701c99492912bf33c73edfb2d5d171`,\n ].join(\"\\n\"),\n ),\n );\n });\n });\n\n describe(\"hash\", () => {\n it(\"should return the hash of the block\", () => {\n // GIVEN\n const block = LKRPBlock.fromHex(mockedBlockHex);\n // WHEN\n const hash = block.hash();\n // THEN\n expect(hash).toBe(\n \"7cf783bc15c062242ab92796237da3b192361da7645c488d5023698d4f9cc952\",\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,QAAAA,EAAM,SAAAC,MAAa,YAE5B,OAAS,oBAAAC,MAAwB,yBAEjC,OAAS,cAAAC,MAAkB,QAC3B,OAAS,aAAAC,MAAiB,cAC1B,OAAS,eAAAC,MAAmB,gBAC5B,OAAS,eAAAC,MAAmB,YAG5B,MAAMC,EAAkB,CACtB,OAAQ,OACR,OAAQ,IAAI,WAAW,CAAC,EAAG,EAAG,CAAC,CAAC,EAChC,SAAU,CAACF,EAAY,QAAQ,UAAU,EAAGA,EAAY,QAAQ,UAAU,CAAC,EAC3E,UAAW,IAAI,WAAW,CAAC,EAAG,EAAG,CAAC,CAAC,CACrC,EACMG,EAAkB,CACtB,SACA,WACA,aACA,QACF,EAAE,KAAK,EAAE,EACHC,EAAiB,CACrB,GA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G,6DAA8D,IAAM,CAErE,MAAMa,EAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAqBV,QAAQ,MAAO,EAAE,EAIbC,EADQZ,EAAU,QAAQW,CAAG,EACP,QAAQ,EAGpC,OAAOC,CAAa,EAAE,cACpBf,EACE,CACE,2EACA,6EACA,YACA,kBACA,wBACA,mFACA,6DACA,uLACA,6FACA,qBACA,yBACA,oFACA,8BACA,sBACA,6DACA,uLACA,oFACA,6FACA,2JACF,EAAE,KAAK;AAAA,CAAI,CACb,CACF,CACF,CAAC,CACH,CAAC,EAED,SAAS,OAAQ,IAAM,CACrB,GAAG,sCAAuC,IAAM,CAI9C,MAAMgB,EAFQb,EAAU,QAAQK,CAAc,EAE3B,KAAK,EAExB,OAAOQ,CAAI,EAAE,KACX,kEACF,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["Left", "Right", "LKRPParsingError", "hexToBytes", "LKRPBlock", "LKRPCommand", "GeneralTags", "mockedBlockData", "mockedHeaderHex", "mockedBlockHex", "parsedMockedBlockData", "block", "bytes", "parsedData", "invalidBlock", "hex", "humanReadable", "hash"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Either as l,Just as c,Maybe as p,Nothing as i,Right as f}from"purify-ts";import{
|
|
1
|
+
import{Either as l,Just as c,Maybe as p,Nothing as i,Right as f}from"purify-ts";import{CryptoUtils as b}from"../utils/crypto";import{bytesToHex as m,hexToBytes as P}from"./hex";import{LKRPBlock as y}from"./LKRPBlock";import{TLVParser as g}from"./TLVParser";import{CommandTags as u}from"./TLVTags";class h{constructor(t,r,e){this.bytes=t;this.blocks=r?c(f(r)):i,this.path=p.fromNullable(e)}validation=i;blocks=i;path=i;static fromHex(t){return new h(P(t))}static fromPath(t){return new h(new Uint8Array,[],t)}static async fromData(t,r){const e=[];let a=r??m(crypto.getRandomValues(new Uint8Array(32)));for(const s of t){const n=y.fromData({...s,parent:a});a=n.hash(),e.push(n)}const o=e.reduce((s,n)=>new Uint8Array([...s,...n.toU8A()]),new Uint8Array);return new h(o,e)}toU8A(){return this.bytes}toString(){return m(this.bytes)}parse(){return this.blocks.orDefaultLazy(()=>{const t=new g(this.bytes),r=[];for(;!t.state.isDone;){const a=t.state.offset,o=t.parseBlockData().map(s=>{const n=t.state.offset;return new y(this.bytes.slice(a,n),s)});if(r.push(o),o.isLeft())break}const e=l.sequence(r);return this.blocks=c(e),e})}toHuman(){return this.parse().map(t=>t.map(r=>r.toHuman())).chain(l.sequence).map(t=>t.join(`
|
|
2
2
|
|
|
3
|
-
`))}async validate(t){return this.validation.orDefaultLazy(async()=>this.parse().map(e=>e.map(a=>a.parse().map(({parent:o})=>({parent:o,hash:()=>a.hash()})))).chain(l.sequence).toMaybe().map(async e=>{if(t&&e[0]&&t!==e[0].parent)return!1;for await(const[a,o]of e.entries()){const s=e[a+1];if(s&&o.hash()!==s.parent)return!1}return!0}).orDefault(Promise.resolve(!1)))}getPath(){return this.path.ifNothing(()=>{this.path=this.parse().toMaybe().chain(t=>p.fromNullable(t[0])).chain(t=>t.parse().toMaybe()).chain(({commands:t})=>p.fromNullable(t[0])).chain(t=>t.parse().toMaybe()).chain(t=>{switch(t.type){case
|
|
3
|
+
`))}async validate(t){return this.validation.orDefaultLazy(async()=>this.parse().map(e=>e.map(a=>a.parse().map(({parent:o})=>({parent:o,hash:()=>a.hash()})))).chain(l.sequence).toMaybe().map(async e=>{if(t&&e[0]&&t!==e[0].parent)return!1;for await(const[a,o]of e.entries()){const s=e[a+1];if(s&&o.hash()!==s.parent)return!1}return!0}).orDefault(Promise.resolve(!1)))}getPath(){return this.path.ifNothing(()=>{this.path=this.parse().toMaybe().chain(t=>p.fromNullable(t[0])).chain(t=>t.parse().toMaybe()).chain(({commands:t})=>p.fromNullable(t[0])).chain(t=>t.parse().toMaybe()).chain(t=>{switch(t.type){case u.Derive:return c(t.path);case u.Seed:return c("m/0'");default:return i}})}),this.path}getMemberBlock(t){return this.parse().toMaybe().chain(r=>{for(const e of r){const a=e.parse();if(a.isRight()){const o=a.extract();for(const s of o.commands){const n=s.getPublicKey();if(n.isJust()&&n.extract()===t)return p.of(o)}}}return i})}hasMember(t){return this.getMemberBlock(t).isJust()}getPublishedKey(t){return this.getMemberBlock(t.pubKeyToHex()).chain(r=>{for(const e of r.commands){const a=e.getEncryptedPublichedKey();if(a.isJust())return a}return i}).map(r=>{const e=t.ecdh(r.ephemeralPublicKey).slice(1),a=b.decrypt(e,r.initializationVector,r.encryptedXpriv);return{privateKey:a.slice(0,32),chainCode:a.slice(32)}})}}export{h as LKRPBlockStream};
|
|
4
4
|
//# sourceMappingURL=LKRPBlockStream.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/utils/LKRPBlockStream.ts"],
|
|
4
|
-
"sourcesContent": ["import { Either, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/app-binder/Errors\";\nimport { type Keypair } from \"@api/app-binder/LKRPTypes\";\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAS,UAAAA,EAAQ,QAAAC,EAAM,SAAAC,EAAO,WAAAC,EAAS,SAAAC,MAAa,
|
|
6
|
-
"names": ["Either", "Just", "Maybe", "Nothing", "Right", "
|
|
4
|
+
"sourcesContent": ["import { Either, Just, Maybe, Nothing, Right } from \"purify-ts\";\n\nimport { type LKRPParsingError } from \"@api/app-binder/Errors\";\nimport { type Keypair } from \"@api/app-binder/LKRPTypes\";\nimport { CryptoUtils } from \"@internal/utils/crypto\";\n\nimport { bytesToHex, hexToBytes } from \"./hex\";\nimport { LKRPBlock } from \"./LKRPBlock\";\nimport { TLVParser } from \"./TLVParser\";\nimport { CommandTags } from \"./TLVTags\";\nimport { type LKRPBlockData } from \"./types\";\nimport { type EncryptedPublishedKey, type PublishedKey } from \"./types\";\n\nexport class LKRPBlockStream {\n private validation: Maybe<Promise<boolean>> = Nothing;\n private blocks: Maybe<Either<LKRPParsingError, LKRPBlock[]>> = Nothing;\n private path: Maybe<string> = Nothing;\n\n constructor(\n private readonly bytes: Uint8Array,\n blocks?: LKRPBlock[],\n path?: string,\n ) {\n this.blocks = blocks ? Just(Right(blocks)) : Nothing;\n this.path = Maybe.fromNullable(path);\n }\n\n static fromHex(hex: string): LKRPBlockStream {\n return new LKRPBlockStream(hexToBytes(hex));\n }\n\n static fromPath(path: string): LKRPBlockStream {\n return new LKRPBlockStream(new Uint8Array(), [], path);\n }\n\n static async fromData(\n blocksData: Omit<LKRPBlockData, \"parent\">[],\n parentHash?: string,\n ): Promise<LKRPBlockStream> {\n const blocks: LKRPBlock[] = [];\n let hash =\n parentHash ?? bytesToHex(crypto.getRandomValues(new Uint8Array(32)));\n\n for (const blockData of blocksData) {\n const block = LKRPBlock.fromData({\n ...blockData,\n parent: hash,\n });\n hash = block.hash();\n blocks.push(block);\n }\n const bytes = blocks.reduce(\n (acc, block) => new Uint8Array([...acc, ...block.toU8A()]),\n new Uint8Array(),\n );\n return new LKRPBlockStream(bytes, blocks);\n }\n\n toU8A(): Uint8Array {\n return this.bytes;\n }\n\n toString(): string {\n return bytesToHex(this.bytes);\n }\n\n parse(): Either<LKRPParsingError, LKRPBlock[]> {\n return this.blocks.orDefaultLazy(() => {\n const parser = new TLVParser(this.bytes);\n const parsed: Either<LKRPParsingError, LKRPBlock>[] = [];\n while (!parser.state.isDone) {\n const start = parser.state.offset;\n const block = parser.parseBlockData().map((data) => {\n const end = parser.state.offset;\n return new LKRPBlock(this.bytes.slice(start, end), data);\n });\n parsed.push(block);\n if (block.isLeft()) break;\n }\n const blocks = Either.sequence(parsed);\n this.blocks = Just(blocks);\n return blocks;\n });\n }\n\n toHuman(): Either<LKRPParsingError, string> {\n return this.parse()\n .map((blocks) => blocks.map((block) => block.toHuman()))\n .chain(Either.sequence)\n .map((blocks) => blocks.join(\"\\n\\n\"));\n }\n\n async validate(streamParentHash?: string): Promise<boolean> {\n return this.validation.orDefaultLazy(async () => {\n const validation = this.parse()\n .map((blocks) =>\n blocks.map((block) =>\n block\n .parse()\n .map(({ parent }) => ({ parent, hash: () => block.hash() })),\n ),\n )\n .chain(Either.sequence)\n .toMaybe()\n .map(async (blocks) => {\n if (\n streamParentHash &&\n blocks[0] &&\n streamParentHash !== blocks[0].parent\n ) {\n return false;\n }\n\n for await (const [index, block] of blocks.entries()) {\n const nextBlock = blocks[index + 1];\n if (nextBlock && block.hash() !== nextBlock.parent) {\n return false;\n }\n }\n return true;\n })\n .orDefault(Promise.resolve(false));\n\n return validation;\n });\n }\n\n getPath(): Maybe<string> {\n this.path.ifNothing(() => {\n this.path = this.parse()\n .toMaybe()\n .chain((blocks) => Maybe.fromNullable(blocks[0]))\n .chain((block) => block.parse().toMaybe())\n .chain(({ commands }) => Maybe.fromNullable(commands[0]))\n .chain((command) => command.parse().toMaybe())\n .chain((data) => {\n switch (data.type) {\n case CommandTags.Derive:\n return Just(data.path);\n case CommandTags.Seed:\n return Just(\"m/0'\");\n default:\n return Nothing;\n }\n });\n });\n return this.path;\n }\n\n getMemberBlock(member: string): Maybe<LKRPBlockData> {\n return this.parse()\n .toMaybe()\n .chain((blocks) => {\n for (const block of blocks) {\n const parsedBlock = block.parse();\n if (parsedBlock.isRight()) {\n const blockData = parsedBlock.extract();\n for (const command of blockData.commands) {\n const pubkey = command.getPublicKey();\n if (pubkey.isJust() && pubkey.extract() === member) {\n return Maybe.of(blockData);\n }\n }\n }\n }\n return Nothing;\n });\n }\n\n hasMember(member: string): boolean {\n return this.getMemberBlock(member).isJust();\n }\n\n getPublishedKey(keypair: Keypair): Maybe<PublishedKey> {\n return this.getMemberBlock(keypair.pubKeyToHex())\n .chain((block): Maybe<EncryptedPublishedKey> => {\n for (const command of block.commands) {\n const key = command.getEncryptedPublichedKey();\n if (key.isJust()) {\n return key;\n }\n }\n return Nothing;\n })\n .map((published) => {\n const secret = keypair.ecdh(published.ephemeralPublicKey).slice(1);\n const xpriv = CryptoUtils.decrypt(\n secret,\n published.initializationVector,\n published.encryptedXpriv,\n );\n return { privateKey: xpriv.slice(0, 32), chainCode: xpriv.slice(32) };\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,UAAAA,EAAQ,QAAAC,EAAM,SAAAC,EAAO,WAAAC,EAAS,SAAAC,MAAa,YAIpD,OAAS,eAAAC,MAAmB,yBAE5B,OAAS,cAAAC,EAAY,cAAAC,MAAkB,QACvC,OAAS,aAAAC,MAAiB,cAC1B,OAAS,aAAAC,MAAiB,cAC1B,OAAS,eAAAC,MAAmB,YAIrB,MAAMC,CAAgB,CAK3B,YACmBC,EACjBC,EACAC,EACA,CAHiB,WAAAF,EAIjB,KAAK,OAASC,EAASZ,EAAKG,EAAMS,CAAM,CAAC,EAAIV,EAC7C,KAAK,KAAOD,EAAM,aAAaY,CAAI,CACrC,CAXQ,WAAsCX,EACtC,OAAuDA,EACvD,KAAsBA,EAW9B,OAAO,QAAQY,EAA8B,CAC3C,OAAO,IAAIJ,EAAgBJ,EAAWQ,CAAG,CAAC,CAC5C,CAEA,OAAO,SAASD,EAA+B,CAC7C,OAAO,IAAIH,EAAgB,IAAI,WAAc,CAAC,EAAGG,CAAI,CACvD,CAEA,aAAa,SACXE,EACAC,EAC0B,CAC1B,MAAMJ,EAAsB,CAAC,EAC7B,IAAIK,EACFD,GAAcX,EAAW,OAAO,gBAAgB,IAAI,WAAW,EAAE,CAAC,CAAC,EAErE,UAAWa,KAAaH,EAAY,CAClC,MAAMI,EAAQZ,EAAU,SAAS,CAC/B,GAAGW,EACH,OAAQD,CACV,CAAC,EACDA,EAAOE,EAAM,KAAK,EAClBP,EAAO,KAAKO,CAAK,CACnB,CACA,MAAMR,EAAQC,EAAO,OACnB,CAACQ,EAAKD,IAAU,IAAI,WAAW,CAAC,GAAGC,EAAK,GA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AO,KAAK,eAAeA,CAAM,EAAE,OAAO,CAC5C,CAEA,gBAAgBG,EAAuC,CACrD,OAAO,KAAK,eAAeA,EAAQ,YAAY,CAAC,EAC7C,MAAOhB,GAAwC,CAC9C,UAAWY,KAAWZ,EAAM,SAAU,CACpC,MAAMiB,EAAML,EAAQ,yBAAyB,EAC7C,GAAIK,EAAI,OAAO,EACb,OAAOA,CAEX,CACA,OAAOlC,CACT,CAAC,EACA,IAAKmC,GAAc,CAClB,MAAMC,EAASH,EAAQ,KAAKE,EAAU,kBAAkB,EAAE,MAAM,CAAC,EAC3DE,EAAQnC,EAAY,QACxBkC,EACAD,EAAU,qBACVA,EAAU,cACZ,EACA,MAAO,CAAE,WAAYE,EAAM,MAAM,EAAG,EAAE,EAAG,UAAWA,EAAM,MAAM,EAAE,CAAE,CACtE,CAAC,CACL,CACF",
|
|
6
|
+
"names": ["Either", "Just", "Maybe", "Nothing", "Right", "CryptoUtils", "bytesToHex", "hexToBytes", "LKRPBlock", "TLVParser", "CommandTags", "LKRPBlockStream", "bytes", "blocks", "path", "hex", "blocksData", "parentHash", "hash", "blockData", "block", "acc", "parser", "parsed", "start", "data", "end", "streamParentHash", "parent", "index", "nextBlock", "commands", "command", "member", "parsedBlock", "pubkey", "keypair", "key", "published", "secret", "xpriv"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{Just as p,Left as l,Right as s}from"purify-ts";import{LKRPParsingError as u}from"../../api/app-binder/Errors";import{
|
|
2
|
-
`)))})}),describe("parse",()=>{it("should parse the block stream correctly",()=>{const e=d.fromHex(t),a=e.parse();e.toHuman(),expect(a).toStrictEqual(s([m.fromData(f),m.fromData(i)]))}),it("should fail if the block stream data is invalid",()=>{const a=d.fromHex("00").parse();expect(a).toStrictEqual(l(new u("Invalid end of TLV, expected length")))})}),describe("fromData",()=>{it("should create a BlockStream from data",()=>{const e=[{...f,parent:void 0},{...i,parent:void 0}],a=d.fromData(e,f.parent);expect(a.toString()).toBe(t)}),it("should assign a random parent hash if not provided",()=>{const e=[{...f,parent:void 0},{...i,parent:void 0}],b=d.fromData(e).parse().map(n=>n[0]?.hash()).caseOf({Left:()=>{},Right:n=>n});expect(typeof b).toBe("string"),expect(b?.length).toBe(64),expect(b).not.toBe(f.parent)})}),describe("validate",()=>{it("should validate the block stream",async()=>{const e=d.fromHex(t),a=await e.validate(f.parent),b=await e.validate(f.parent);expect(a).toBe(!0),expect(b).toBe(!0)}),it("should fail validation if the parent hash does not match",async()=>{const e=d.fromHex(t.replace(i.parent,f.parent)),a=await e.validate("0123455678"),b=await e.validate();expect(a).toBe(!1),expect(b).toBe(!1)})}),describe("getPath",()=>{it("should return the path of the block stream",()=>{const a=d.fromHex(t).getPath();expect(a).toEqual(p("m/0'/16'/0'"))})})});const t=`
|
|
1
|
+
import{Just as p,Left as l,Right as s}from"purify-ts";import{LKRPParsingError as u}from"../../api/app-binder/Errors";import{hexToBytes as c}from"./hex";import{LKRPBlock as m}from"./LKRPBlock";import{LKRPBlockStream as d}from"./LKRPBlockStream";import{LKRPCommand as r}from"./LKRPCommand";import{CommandTags as o}from"./TLVTags";describe("LKRPBlockStream",()=>{describe("toString",()=>{it("should return the hex representation of the block stream",()=>{const e="0102030405060708",a=d.fromHex(e);expect(a.toString()).toBe(e)})}),describe("toU8A",()=>{it("should return the bytes of the block stream",()=>{const e=new Uint8Array([1,2,3,4,5,6,7,8]),a=new d(e);expect(a.toU8A()).toBe(e)})}),describe("toHuman",()=>{it("should return a human-readable representation of the block stream",()=>{const a=d.fromHex(t).toHuman();expect(a).toStrictEqual(s(["Parent: 7ba5eefac6605547fc50188ba7880311d3d1240a7ae32e6eaac7499434091c45","Issuer: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021","Commands:"," Derive(0x15):"," path: m/0'/16'/0'"," groupKey: 02839a288f6a76090b64312281d2e7d6b02c4ddf64ed5e7693471b1b445f819508"," initializationVector: a66c5a4486e870287caa53bbd609af00"," encryptedXpriv: 0f43341d6f9099a5180fb304a2889b3b0468f05fb0b931d22211753b3411567abb21981b64261e95bcd44a3512af7c87bbb5a4b6b680c03b5f09e8d9c56a9cb1c0788993a3d9d5c140a2462cb1930d19"," ephemeralPublicKey: 02fbe26c32ab991c1b107156e22fc158c335e0aeedc171381c9d77743c66f41171"," AddMember(0x11):"," name: debug-d4c61d"," publicKey: 03d4c61dda2aaf762954fce97396d9be0399e1dc75c3b790c7a34dde8596a11812"," permissions: 4294967295"," PublishKey(0x12):"," initializationVector: 4d305eae5b70b69cf657f3b9f7db5863"," encryptedXpriv: 898de535f87f7ac775b09c80827d14efddeeaa9a2b106bfd7fcc91942dc36d6a1751793ba7ec0792ba936f5f1d858bc1fc54ca1a70e8d28a5b0bf33b5e926f3add372c802b3b9da64bc06e26b9349db5"," recipient: 03d4c61dda2aaf762954fce97396d9be0399e1dc75c3b790c7a34dde8596a11812"," ephemeralPublicKey: 023db66b974b871c6caafdf486c6895518303b140d389e787d2c3b5527c2df50f4","Signature: 3044022056ab426bd75696cbe9538cb42271e8796ba1576dfe3e2634f0a6f1a636821e5002205e41ae68ebd8fbff404340a4f0124af25e948aa52500de192d15ff4f8ee92c02","","Parent: 154d99eb867cfeef249d573fc2e1f3d307c1e49ec1f66e9af1c9dbd219143211","Issuer: 0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021","Commands:"," AddMember(0x11):"," name: debug-80a289"," publicKey: 0280a28918369e12c86feb321cd100fe6d958e55a0bb570576ef718e7a379204db"," permissions: 4294967295"," PublishKey(0x12):"," initializationVector: 27bdb34fb6028128bfc919f4db7d1378"," encryptedXpriv: e792b83f26fac0de46ee8f1a07e53b0e508d9373aa2e8047f0a764204ab0f06a2fffa9c29599f5d3fe42fefabd9827867157bd14ec7e2bd8ef83c6f9371d7b48d28d9a4499f8ed626ce75fcec0a0b33f"," recipient: 0280a28918369e12c86feb321cd100fe6d958e55a0bb570576ef718e7a379204db"," ephemeralPublicKey: 027d40157737671bb04eaca2756b8ec58020ff5c893b10cbfb25b48014c5252dc4","Signature: 30440220718d20c9996893639da807b8a9675d944abdc8fded97f73159beba5004fa17f102203338b74a9e6a2e696ea3658d3af4fce95ffa0f74c11b2c3d37b0ca1b577657e8"].join(`
|
|
2
|
+
`)))})}),describe("parse",()=>{it("should parse the block stream correctly",()=>{const e=d.fromHex(t),a=e.parse();e.toHuman(),expect(a).toStrictEqual(s([m.fromData(f),m.fromData(i)]))}),it("should fail if the block stream data is invalid",()=>{const a=d.fromHex("00").parse();expect(a).toStrictEqual(l(new u("Invalid end of TLV, expected length")))})}),describe("fromData",()=>{it("should create a BlockStream from data",async()=>{const e=[{...f,parent:void 0},{...i,parent:void 0}],a=await d.fromData(e,f.parent);expect(a.toString()).toBe(t)}),it("should assign a random parent hash if not provided",async()=>{const e=[{...f,parent:void 0},{...i,parent:void 0}],b=await(await d.fromData(e)).parse().map(n=>n[0]?.hash()).caseOf({Left:()=>{},Right:n=>n});expect(typeof b).toBe("string"),expect(b?.length).toBe(64),expect(b).not.toBe(f.parent)})}),describe("validate",()=>{it("should validate the block stream",async()=>{const e=d.fromHex(t),a=await e.validate(f.parent),b=await e.validate(f.parent);expect(a).toBe(!0),expect(b).toBe(!0)}),it("should fail validation if the parent hash does not match",async()=>{const e=d.fromHex(t.replace(i.parent,f.parent)),a=await e.validate("0123455678"),b=await e.validate();expect(a).toBe(!1),expect(b).toBe(!1)})}),describe("getPath",()=>{it("should return the path of the block stream",()=>{const a=d.fromHex(t).getPath();expect(a).toEqual(p("m/0'/16'/0'"))})})});const t=`
|
|
3
3
|
01 01 01
|
|
4
4
|
02 20 7b a5 ee fa c6 60 55 47 fc 50 18 8b a7 88 03 11 d3 d1 24 0a 7a e3 2e 6e aa c7 49 94 34 09 1c 45
|
|
5
5
|
06 21 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21
|
|
@@ -35,5 +35,5 @@ import{Just as p,Left as l,Right as s}from"purify-ts";import{LKRPParsingError as
|
|
|
35
35
|
06 21 02 80 a2 89 18 36 9e 12 c8 6f eb 32 1c d1 00 fe 6d 95 8e 55 a0 bb 57 05 76 ef 71 8e 7a 37 92 04 db
|
|
36
36
|
06 21 02 7d 40 15 77 37 67 1b b0 4e ac a2 75 6b 8e c5 80 20 ff 5c 89 3b 10 cb fb 25 b4 80 14 c5 25 2d c4
|
|
37
37
|
03 46 30 44 02 20 71 8d 20 c9 99 68 93 63 9d a8 07 b8 a9 67 5d 94 4a bd c8 fd ed 97 f7 31 59 be ba 50 04 fa 17 f1 02 20 33 38 b7 4a 9e 6a 2e 69 6e a3 65 8d 3a f4 fc e9 5f fa 0f 74 c1 1b 2c 3d 37 b0 ca 1b 57 76 57 e8
|
|
38
|
-
`.replace(/\s/g,""),f={parent:"7ba5eefac6605547fc50188ba7880311d3d1240a7ae32e6eaac7499434091c45",issuer:c("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021"),commands:[
|
|
38
|
+
`.replace(/\s/g,""),f={parent:"7ba5eefac6605547fc50188ba7880311d3d1240a7ae32e6eaac7499434091c45",issuer:c("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021"),commands:[r.fromData({type:o.Derive,path:"m/0'/16'/0'",groupKey:c("02839a288f6a76090b64312281d2e7d6b02c4ddf64ed5e7693471b1b445f819508"),initializationVector:c("a66c5a4486e870287caa53bbd609af00"),encryptedXpriv:c("0f43341d6f9099a5180fb304a2889b3b0468f05fb0b931d22211753b3411567abb21981b64261e95bcd44a3512af7c87bbb5a4b6b680c03b5f09e8d9c56a9cb1c0788993a3d9d5c140a2462cb1930d19"),ephemeralPublicKey:c("02fbe26c32ab991c1b107156e22fc158c335e0aeedc171381c9d77743c66f41171")}),r.fromData({type:o.AddMember,name:"debug-d4c61d",publicKey:c("03d4c61dda2aaf762954fce97396d9be0399e1dc75c3b790c7a34dde8596a11812"),permissions:4294967295}),r.fromData({type:o.PublishKey,initializationVector:c("4d305eae5b70b69cf657f3b9f7db5863"),encryptedXpriv:c("898de535f87f7ac775b09c80827d14efddeeaa9a2b106bfd7fcc91942dc36d6a1751793ba7ec0792ba936f5f1d858bc1fc54ca1a70e8d28a5b0bf33b5e926f3add372c802b3b9da64bc06e26b9349db5"),recipient:c("03d4c61dda2aaf762954fce97396d9be0399e1dc75c3b790c7a34dde8596a11812"),ephemeralPublicKey:c("023db66b974b871c6caafdf486c6895518303b140d389e787d2c3b5527c2df50f4")})],signature:c("3044022056ab426bd75696cbe9538cb42271e8796ba1576dfe3e2634f0a6f1a636821e5002205e41ae68ebd8fbff404340a4f0124af25e948aa52500de192d15ff4f8ee92c02")},i={parent:"154d99eb867cfeef249d573fc2e1f3d307c1e49ec1f66e9af1c9dbd219143211",issuer:c("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021"),commands:[r.fromData({type:o.AddMember,name:"debug-80a289",publicKey:c("0280a28918369e12c86feb321cd100fe6d958e55a0bb570576ef718e7a379204db"),permissions:4294967295}),r.fromData({type:o.PublishKey,initializationVector:c("27bdb34fb6028128bfc919f4db7d1378"),encryptedXpriv:c("e792b83f26fac0de46ee8f1a07e53b0e508d9373aa2e8047f0a764204ab0f06a2fffa9c29599f5d3fe42fefabd9827867157bd14ec7e2bd8ef83c6f9371d7b48d28d9a4499f8ed626ce75fcec0a0b33f"),recipient:c("0280a28918369e12c86feb321cd100fe6d958e55a0bb570576ef718e7a379204db"),ephemeralPublicKey:c("027d40157737671bb04eaca2756b8ec58020ff5c893b10cbfb25b48014c5252dc4")})],signature:c("30440220718d20c9996893639da807b8a9675d944abdc8fded97f73159beba5004fa17f102203338b74a9e6a2e696ea3658d3af4fce95ffa0f74c11b2c3d37b0ca1b577657e8")};
|
|
39
39
|
//# sourceMappingURL=LKRPBlockStream.test.js.map
|