@ledgerhq/device-signer-kit-bitcoin 0.0.0-wrong-error-when-in-experimental-provider-20251021161219 → 0.0.0-z-intent-queue-7-20251204111630
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/command/ContinueCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/ContinueCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/ContinueCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/ContinueCommand.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/GetExtendedPublicKeyCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetExtendedPublicKeyCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetExtendedPublicKeyCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetExtendedPublicKeyCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetMasterFingerprintCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetMasterFingerprintCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetMasterFingerprintCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetMasterFingerprintCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetWalletAddressCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetWalletAddressCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/GetWalletAddressCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/GetWalletAddressCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/RegisterWalletAddressCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/RegisterWalletAddressCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/RegisterWalletAddressCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/RegisterWalletAddressCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/SignMessageCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignMessageCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/SignMessageCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignMessageCommand.test.js.map +3 -3
- package/lib/cjs/internal/app-binder/command/SignPsbtCommand.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignPsbtCommand.js.map +2 -2
- package/lib/cjs/internal/app-binder/command/SignPsbtCommand.test.js +1 -1
- package/lib/cjs/internal/app-binder/command/SignPsbtCommand.test.js.map +2 -2
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/cjs/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/cjs/internal/psbt/service/key-pair/DefaultKeyPairSerializer.test.js +1 -1
- package/lib/cjs/internal/psbt/service/key-pair/DefaultKeyPairSerializer.test.js.map +1 -1
- package/lib/cjs/internal/psbt/service/psbt/DefaultPsbtSerializer.js.map +1 -1
- package/lib/cjs/package.json +43 -39
- package/lib/esm/internal/app-binder/command/ContinueCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/ContinueCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/ContinueCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/ContinueCommand.test.js.map +3 -3
- package/lib/esm/internal/app-binder/command/GetExtendedPublicKeyCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/GetExtendedPublicKeyCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetExtendedPublicKeyCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/GetExtendedPublicKeyCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetMasterFingerprintCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/GetMasterFingerprintCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetMasterFingerprintCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/GetMasterFingerprintCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetWalletAddressCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/GetWalletAddressCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/GetWalletAddressCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/GetWalletAddressCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/RegisterWalletAddressCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/RegisterWalletAddressCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/RegisterWalletAddressCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/RegisterWalletAddressCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SignMessageCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/SignMessageCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SignMessageCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/SignMessageCommand.test.js.map +3 -3
- package/lib/esm/internal/app-binder/command/SignPsbtCommand.js +1 -1
- package/lib/esm/internal/app-binder/command/SignPsbtCommand.js.map +2 -2
- package/lib/esm/internal/app-binder/command/SignPsbtCommand.test.js +1 -1
- package/lib/esm/internal/app-binder/command/SignPsbtCommand.test.js.map +2 -2
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js +1 -1
- package/lib/esm/internal/app-binder/device-action/__test-utils__/makeInternalApi.js.map +3 -3
- package/lib/esm/internal/psbt/service/key-pair/DefaultKeyPairSerializer.test.js +1 -1
- package/lib/esm/internal/psbt/service/key-pair/DefaultKeyPairSerializer.test.js.map +1 -1
- package/lib/esm/internal/psbt/service/psbt/DefaultPsbtSerializer.js.map +1 -1
- package/lib/esm/package.json +43 -39
- package/lib/types/internal/app-binder/command/ContinueCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/ContinueCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/GetExtendedPublicKeyCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/GetExtendedPublicKeyCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/GetMasterFingerprintCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/GetMasterFingerprintCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/GetWalletAddressCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/GetWalletAddressCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/RegisterWalletAddressCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/RegisterWalletAddressCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/SignMessageCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/SignMessageCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/command/SignPsbtCommand.d.ts +1 -0
- package/lib/types/internal/app-binder/command/SignPsbtCommand.d.ts.map +1 -1
- package/lib/types/internal/app-binder/device-action/__test-utils__/makeInternalApi.d.ts.map +1 -1
- package/lib/types/internal/psbt/service/psbt/DefaultPsbtSerializer.d.ts +2 -2
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +38 -34
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/SignPsbtCommand.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { PROTOCOL_VERSION } from \"@internal/app-binder/command/utils/constants\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nexport type SignPsbtCommandArgs = {\n globalCommitment: Uint8Array;\n inputsCount: number;\n inputsRoot: Uint8Array;\n outputsCount: number;\n outputsRoot: Uint8Array;\n walletId: Uint8Array;\n walletHmac: Uint8Array;\n};\n\ntype SignPsbtCommandResponse = ApduResponse;\n\nexport class SignPsbtCommand\n implements\n Command<SignPsbtCommandResponse, SignPsbtCommandArgs, BtcErrorCodes>\n{\n constructor(\n private readonly _args: SignPsbtCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n SignPsbtCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n const builder = new ApduBuilder({\n cla: 0xe1,\n ins: 0x04,\n p1: 0x00,\n p2: PROTOCOL_VERSION,\n });\n const {\n globalCommitment,\n inputsCount,\n inputsRoot,\n outputsCount,\n outputsRoot,\n walletHmac,\n walletId,\n } = this._args;\n\n return builder\n .addBufferToData(globalCommitment)\n .add8BitUIntToData(inputsCount)\n .addBufferToData(inputsRoot)\n .add8BitUIntToData(outputsCount)\n .addBufferToData(outputsRoot)\n .addBufferToData(walletId)\n .addBufferToData(walletHmac)\n .build();\n }\n parseResponse(\n response: ApduResponse,\n ): CommandResult<SignPsbtCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(this._errorHelper.getError(response)).orDefault(\n CommandResultFactory({ data: response }),\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,2CACPC,EAAmC,kCACnCC,EAAsB,qBAEtBC,EAIO,+DACPC,EAAiC,wDACjCC,EAAgC,2CAczB,MAAMP,CAGb,
|
|
4
|
+
"sourcesContent": ["import {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { PROTOCOL_VERSION } from \"@internal/app-binder/command/utils/constants\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nexport type SignPsbtCommandArgs = {\n globalCommitment: Uint8Array;\n inputsCount: number;\n inputsRoot: Uint8Array;\n outputsCount: number;\n outputsRoot: Uint8Array;\n walletId: Uint8Array;\n walletHmac: Uint8Array;\n};\n\ntype SignPsbtCommandResponse = ApduResponse;\n\nexport class SignPsbtCommand\n implements\n Command<SignPsbtCommandResponse, SignPsbtCommandArgs, BtcErrorCodes>\n{\n readonly name = \"signPsbt\";\n constructor(\n private readonly _args: SignPsbtCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n SignPsbtCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n const builder = new ApduBuilder({\n cla: 0xe1,\n ins: 0x04,\n p1: 0x00,\n p2: PROTOCOL_VERSION,\n });\n const {\n globalCommitment,\n inputsCount,\n inputsRoot,\n outputsCount,\n outputsRoot,\n walletHmac,\n walletId,\n } = this._args;\n\n return builder\n .addBufferToData(globalCommitment)\n .add8BitUIntToData(inputsCount)\n .addBufferToData(inputsRoot)\n .add8BitUIntToData(outputsCount)\n .addBufferToData(outputsRoot)\n .addBufferToData(walletId)\n .addBufferToData(walletHmac)\n .build();\n }\n parseResponse(\n response: ApduResponse,\n ): CommandResult<SignPsbtCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(this._errorHelper.getError(response)).orDefault(\n CommandResultFactory({ data: response }),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAOO,2CACPC,EAAmC,kCACnCC,EAAsB,qBAEtBC,EAIO,+DACPC,EAAiC,wDACjCC,EAAgC,2CAczB,MAAMP,CAGb,CAEE,YACmBQ,EACAC,EAAe,IAAI,qBAIlC,iBACA,4BACA,kBAAgB,iBAClB,EACA,CATiB,WAAAD,EACA,kBAAAC,CAQhB,CAXM,KAAO,WAahB,SAAgB,CACd,MAAMC,EAAU,IAAI,cAAY,CAC9B,IAAK,IACL,IAAK,EACL,GAAI,EACJ,GAAI,kBACN,CAAC,EACK,CACJ,iBAAAC,EACA,YAAAC,EACA,WAAAC,EACA,aAAAC,EACA,YAAAC,EACA,WAAAC,EACA,SAAAC,CACF,EAAI,KAAK,MAET,OAAOP,EACJ,gBAAgBC,CAAgB,EAChC,kBAAkBC,CAAW,EAC7B,gBAAgBC,CAAU,EAC1B,kBAAkBC,CAAY,EAC9B,gBAAgBC,CAAW,EAC3B,gBAAgBE,CAAQ,EACxB,gBAAgBD,CAAU,EAC1B,MAAM,CACX,CACA,cACEE,EACuD,CACvD,OAAO,QAAM,aAAa,KAAK,aAAa,SAASA,CAAQ,CAAC,EAAE,aAC9D,wBAAqB,CAAE,KAAMA,CAAS,CAAC,CACzC,CACF,CACF",
|
|
6
6
|
"names": ["SignPsbtCommand_exports", "__export", "SignPsbtCommand", "__toCommonJS", "import_device_management_kit", "import_signer_utils", "import_purify_ts", "import_bitcoinAppErrors", "import_constants", "import_BtcCommandUtils", "_args", "_errorHelper", "builder", "globalCommitment", "inputsCount", "inputsRoot", "outputsCount", "outputsRoot", "walletHmac", "walletId", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("@ledgerhq/device-management-kit"),t=require("../../app-binder/command/SignPsbtCommand");const n=Uint8Array.from([5,81,155,56,218,231,68,71,183,33,81,243,84,203,19,140,163,89,26,95,248,172,129,50,137,177,138,0,78,49,50,22,32,58,34,31,75,185,94,30,99,129,67,20,166,147,179,89,53,61,70,96,163,67,81,101,211,223,183,53,206,45,245,245,143]),r=Uint8Array.from([1,42,200,205,188,111,214,67,112,5,86,99,249,80,47,227,102,237,248,73,112,204,125,126,232,246,186,71,89,159,17,5,194]),c=Uint8Array.from([1,217,53,20,212,41,104,141,118,87,201,175,10,8,134,172,116,75,208,136,28,74,25,16,181,55,250,186,40,205,202,46,17]),d=Uint8Array.from([65,172,65,166,22,180,162,250,212,152,38,143,233,200,166,59,136,84,135,56,57,6,93,230,251,47,171,241,251,232,146,86]),m=Uint8Array.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),f=Uint8Array.from([225,4,0,1,197,...n,1,...r,1,...c,...d,...m]);describe("SignPsbtCommand",()=>{const s={globalCommitment:n,inputsCount:1,inputsRoot:r,outputsCount:1,outputsRoot:c,walletId:d,walletHmac:m};describe("name",()=>{it("should be 'signPsbt'",()=>{const x=new t.SignPsbtCommand(s);expect(x.name).toBe("signPsbt")})}),describe("getApdu",()=>{it("should return a correct apdu",()=>{const x=new t.SignPsbtCommand(s);expect(x.getApdu().getRawApdu()).toEqual(f)})}),describe("parseResponse",()=>{it("should return success",()=>{const x=new t.SignPsbtCommand(s),a=new e.ApduResponse({statusCode:Uint8Array.from([144,0]),data:Uint8Array.from([])}),o=x.parseResponse(a);expect((0,e.isSuccessCommandResult)(o)).toBe(!0)}),it("should return failure",()=>{const x=new t.SignPsbtCommand(s),a=new e.ApduResponse({statusCode:Uint8Array.from([109,0]),data:new Uint8Array(0)}),o=x.parseResponse(a);expect((0,e.isSuccessCommandResult)(o)).toBe(!1)})})});
|
|
2
2
|
//# sourceMappingURL=SignPsbtCommand.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/SignPsbtCommand.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport {\n SignPsbtCommand,\n type SignPsbtCommandArgs,\n} from \"@internal/app-binder/command/SignPsbtCommand\";\n\nconst GLOBAL_COMMITMENT = Uint8Array.from([\n 0x05, 0x51, 0x9b, 0x38, 0xda, 0xe7, 0x44, 0x47, 0xb7, 0x21, 0x51, 0xf3, 0x54,\n 0xcb, 0x13, 0x8c, 0xa3, 0x59, 0x1a, 0x5f, 0xf8, 0xac, 0x81, 0x32, 0x89, 0xb1,\n 0x8a, 0x00, 0x4e, 0x31, 0x32, 0x16, 0x20, 0x3a, 0x22, 0x1f, 0x4b, 0xb9, 0x5e,\n 0x1e, 0x63, 0x81, 0x43, 0x14, 0xa6, 0x93, 0xb3, 0x59, 0x35, 0x3d, 0x46, 0x60,\n 0xa3, 0x43, 0x51, 0x65, 0xd3, 0xdf, 0xb7, 0x35, 0xce, 0x2d, 0xf5, 0xf5, 0x8f,\n]);\n\nconst INPUTS_ROOT = Uint8Array.from([\n 0x01, 0x2a, 0xc8, 0xcd, 0xbc, 0x6f, 0xd6, 0x43, 0x70, 0x05, 0x56, 0x63, 0xf9,\n 0x50, 0x2f, 0xe3, 0x66, 0xed, 0xf8, 0x49, 0x70, 0xcc, 0x7d, 0x7e, 0xe8, 0xf6,\n 0xba, 0x47, 0x59, 0x9f, 0x11, 0x05, 0xc2,\n]);\n\nconst OUTPUTS_ROOT = Uint8Array.from([\n 0x01, 0xd9, 0x35, 0x14, 0xd4, 0x29, 0x68, 0x8d, 0x76, 0x57, 0xc9, 0xaf, 0x0a,\n 0x08, 0x86, 0xac, 0x74, 0x4b, 0xd0, 0x88, 0x1c, 0x4a, 0x19, 0x10, 0xb5, 0x37,\n 0xfa, 0xba, 0x28, 0xcd, 0xca, 0x2e, 0x11,\n]);\nconst WALLET_ID = Uint8Array.from([\n 0x41, 0xac, 0x41, 0xa6, 0x16, 0xb4, 0xa2, 0xfa, 0xd4, 0x98, 0x26, 0x8f, 0xe9,\n 0xc8, 0xa6, 0x3b, 0x88, 0x54, 0x87, 0x38, 0x39, 0x06, 0x5d, 0xe6, 0xfb, 0x2f,\n 0xab, 0xf1, 0xfb, 0xe8, 0x92, 0x56,\n]);\nconst WALLET_HMAC = Uint8Array.from([\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n]);\nconst SIGN_PSBT_APDU = Uint8Array.from([\n 0xe1,\n 0x04,\n 0x00,\n 0x01,\n 0xc5,\n ...GLOBAL_COMMITMENT,\n 0x01,\n ...INPUTS_ROOT,\n 0x01,\n ...OUTPUTS_ROOT,\n ...WALLET_ID,\n ...WALLET_HMAC,\n]);\n\ndescribe(\"SignPsbtCommand\", () => {\n const args: SignPsbtCommandArgs = {\n globalCommitment: GLOBAL_COMMITMENT,\n inputsCount: 1,\n inputsRoot: INPUTS_ROOT,\n outputsCount: 1,\n outputsRoot: OUTPUTS_ROOT,\n walletId: WALLET_ID,\n walletHmac: WALLET_HMAC,\n };\n describe(\"getApdu\", () => {\n it(\"should return a correct apdu\", () => {\n const command = new SignPsbtCommand(args);\n\n expect(command.getApdu().getRawApdu()).toEqual(SIGN_PSBT_APDU);\n });\n });\n describe(\"parseResponse\", () => {\n it(\"should return success\", () => {\n // given\n const command = new SignPsbtCommand(args);\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: Uint8Array.from([]),\n });\n\n // when\n const result = command.parseResponse(response);\n\n // then\n expect(isSuccessCommandResult(result)).toBe(true);\n });\n it(\"should return failure\", () => {\n // given\n const command = new SignPsbtCommand(args);\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x6d, 0x00]),\n data: new Uint8Array(0),\n });\n\n // when\n const result = command.parseResponse(response);\n\n // then\n expect(isSuccessCommandResult(result)).toBe(false);\n });\n });\n});\n"],
|
|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AM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EACxE,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EACxE,EAAM,EAAM,EAAM,EAAM,EAAM,CAChC,CAAC,EACKC,EAAiB,WAAW,KAAK,CACrC,IACA,EACA,EACA,EACA,IACA,GAAGL,EACH,EACA,GAAGC,EACH,EACA,GAAGC,EACH,GAAGC,EACH,GAAGC,CACL,CAAC,EAED,SAAS,kBAAmB,IAAM,CAChC,MAAME,EAA4B,CAChC,iBAAkBN,EAClB,YAAa,EACb,WAAYC,EACZ,aAAc,EACd,YAAaC,EACb,SAAUC,EACV,WAAYC,CACd,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\n\nimport {\n SignPsbtCommand,\n type SignPsbtCommandArgs,\n} from \"@internal/app-binder/command/SignPsbtCommand\";\n\nconst GLOBAL_COMMITMENT = Uint8Array.from([\n 0x05, 0x51, 0x9b, 0x38, 0xda, 0xe7, 0x44, 0x47, 0xb7, 0x21, 0x51, 0xf3, 0x54,\n 0xcb, 0x13, 0x8c, 0xa3, 0x59, 0x1a, 0x5f, 0xf8, 0xac, 0x81, 0x32, 0x89, 0xb1,\n 0x8a, 0x00, 0x4e, 0x31, 0x32, 0x16, 0x20, 0x3a, 0x22, 0x1f, 0x4b, 0xb9, 0x5e,\n 0x1e, 0x63, 0x81, 0x43, 0x14, 0xa6, 0x93, 0xb3, 0x59, 0x35, 0x3d, 0x46, 0x60,\n 0xa3, 0x43, 0x51, 0x65, 0xd3, 0xdf, 0xb7, 0x35, 0xce, 0x2d, 0xf5, 0xf5, 0x8f,\n]);\n\nconst INPUTS_ROOT = Uint8Array.from([\n 0x01, 0x2a, 0xc8, 0xcd, 0xbc, 0x6f, 0xd6, 0x43, 0x70, 0x05, 0x56, 0x63, 0xf9,\n 0x50, 0x2f, 0xe3, 0x66, 0xed, 0xf8, 0x49, 0x70, 0xcc, 0x7d, 0x7e, 0xe8, 0xf6,\n 0xba, 0x47, 0x59, 0x9f, 0x11, 0x05, 0xc2,\n]);\n\nconst OUTPUTS_ROOT = Uint8Array.from([\n 0x01, 0xd9, 0x35, 0x14, 0xd4, 0x29, 0x68, 0x8d, 0x76, 0x57, 0xc9, 0xaf, 0x0a,\n 0x08, 0x86, 0xac, 0x74, 0x4b, 0xd0, 0x88, 0x1c, 0x4a, 0x19, 0x10, 0xb5, 0x37,\n 0xfa, 0xba, 0x28, 0xcd, 0xca, 0x2e, 0x11,\n]);\nconst WALLET_ID = Uint8Array.from([\n 0x41, 0xac, 0x41, 0xa6, 0x16, 0xb4, 0xa2, 0xfa, 0xd4, 0x98, 0x26, 0x8f, 0xe9,\n 0xc8, 0xa6, 0x3b, 0x88, 0x54, 0x87, 0x38, 0x39, 0x06, 0x5d, 0xe6, 0xfb, 0x2f,\n 0xab, 0xf1, 0xfb, 0xe8, 0x92, 0x56,\n]);\nconst WALLET_HMAC = Uint8Array.from([\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n]);\nconst SIGN_PSBT_APDU = Uint8Array.from([\n 0xe1,\n 0x04,\n 0x00,\n 0x01,\n 0xc5,\n ...GLOBAL_COMMITMENT,\n 0x01,\n ...INPUTS_ROOT,\n 0x01,\n ...OUTPUTS_ROOT,\n ...WALLET_ID,\n ...WALLET_HMAC,\n]);\n\ndescribe(\"SignPsbtCommand\", () => {\n const args: SignPsbtCommandArgs = {\n globalCommitment: GLOBAL_COMMITMENT,\n inputsCount: 1,\n inputsRoot: INPUTS_ROOT,\n outputsCount: 1,\n outputsRoot: OUTPUTS_ROOT,\n walletId: WALLET_ID,\n walletHmac: WALLET_HMAC,\n };\n\n describe(\"name\", () => {\n it(\"should be 'signPsbt'\", () => {\n const command = new SignPsbtCommand(args);\n expect(command.name).toBe(\"signPsbt\");\n });\n });\n\n describe(\"getApdu\", () => {\n it(\"should return a correct apdu\", () => {\n const command = new SignPsbtCommand(args);\n\n expect(command.getApdu().getRawApdu()).toEqual(SIGN_PSBT_APDU);\n });\n });\n describe(\"parseResponse\", () => {\n it(\"should return success\", () => {\n // given\n const command = new SignPsbtCommand(args);\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x90, 0x00]),\n data: Uint8Array.from([]),\n });\n\n // when\n const result = command.parseResponse(response);\n\n // then\n expect(isSuccessCommandResult(result)).toBe(true);\n });\n it(\"should return failure\", () => {\n // given\n const command = new SignPsbtCommand(args);\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x6d, 0x00]),\n data: new Uint8Array(0),\n });\n\n // when\n const result = command.parseResponse(response);\n\n // then\n expect(isSuccessCommandResult(result)).toBe(false);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "aAAA,IAAAA,EAGO,2CAEPC,EAGO,wDAEP,MAAMC,EAAoB,WAAW,KAAK,CACxC,EAAM,GAAM,IAAM,GAAM,IAAM,IAAM,GAAM,GAAM,IAAM,GAAM,GAAM,IAAM,GACxE,IAAM,GAAM,IAAM,IAAM,GAAM,GAAM,GAAM,IAAM,IAAM,IAAM,GAAM,IAAM,IACxE,IAAM,EAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,IAAM,GACxE,GAAM,GAAM,IAAM,GAAM,GAAM,IAAM,IAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GACxE,IAAM,GAAM,GAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,GAAM,IAAM,IAAM,GAC1E,CAAC,EAEKC,EAAc,WAAW,KAAK,CAClC,EAAM,GAAM,IAAM,IAAM,IAAM,IAAM,IAAM,GAAM,IAAM,EAAM,GAAM,GAAM,IAC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tC,CAAC,CACH,CAAC,EAED,SAAS,UAAW,IAAM,CACxB,GAAG,+BAAgC,IAAM,CACvC,MAAMA,EAAU,IAAI,kBAAgBD,CAAI,EAExC,OAAOC,EAAQ,QAAQ,EAAE,WAAW,CAAC,EAAE,QAAQF,CAAc,CAC/D,CAAC,CACH,CAAC,EACD,SAAS,gBAAiB,IAAM,CAC9B,GAAG,wBAAyB,IAAM,CAEhC,MAAME,EAAU,IAAI,kBAAgBD,CAAI,EAClCE,EAAW,IAAI,eAAa,CAChC,WAAY,WAAW,KAAK,CAAC,IAAM,CAAI,CAAC,EACxC,KAAM,WAAW,KAAK,CAAC,CAAC,CAC1B,CAAC,EAGKC,EAASF,EAAQ,cAAcC,CAAQ,EAG7C,UAAO,0BAAuBC,CAAM,CAAC,EAAE,KAAK,EAAI,CAClD,CAAC,EACD,GAAG,wBAAyB,IAAM,CAEhC,MAAMF,EAAU,IAAI,kBAAgBD,CAAI,EAClCE,EAAW,IAAI,eAAa,CAChC,WAAY,WAAW,KAAK,CAAC,IAAM,CAAI,CAAC,EACxC,KAAM,IAAI,WAAW,CAAC,CACxB,CAAC,EAGKC,EAASF,EAAQ,cAAcC,CAAQ,EAG7C,UAAO,0BAAuBC,CAAM,CAAC,EAAE,KAAK,EAAK,CACnD,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_device_management_kit", "import_SignPsbtCommand", "GLOBAL_COMMITMENT", "INPUTS_ROOT", "OUTPUTS_ROOT", "WALLET_ID", "WALLET_HMAC", "SIGN_PSBT_APDU", "args", "command", "response", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var v=Object.prototype.hasOwnProperty;var r=(n,e)=>{for(var i in e)c(n,i,{get:e[i],enumerable:!0})},S=(n,e,i,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of a(e))!v.call(n,t)&&t!==i&&c(n,t,{get:()=>e[t],enumerable:!(o=s(e,t))||o.enumerable});return n};var p=n=>S(c({},"__esModule",{value:!0}),n);var u={};r(u,{makeDeviceActionInternalApiMock:()=>A});module.exports=p(u);const M=vi.fn(),d=vi.fn(),k=vi.fn(),f=vi.fn(),g=vi.fn(),l=vi.fn(),m=vi.fn(),D=vi.fn();function A(){return{sendApdu:M,sendCommand:d,getDeviceModel:k,getDeviceSessionState:f,getDeviceSessionStateObservable:g,setDeviceSessionState:l,getManagerApiService:m,getSecureChannelService:D}}0&&(module.exports={makeDeviceActionInternalApiMock});
|
|
2
2
|
//# sourceMappingURL=makeInternalApi.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/app-binder/device-action/__test-utils__/makeInternalApi.ts"],
|
|
4
|
-
"sourcesContent": ["import { type InternalApi } from \"@ledgerhq/device-management-kit\";\nimport { type Mocked } from \"vitest\";\n\nconst sendApduMock = vi.fn();\nconst sendCommandMock = vi.fn();\nconst apiGetDeviceModelMock = vi.fn();\nconst apiGetDeviceSessionStateMock = vi.fn();\nconst apiGetDeviceSessionStateObservableMock = vi.fn();\nconst setDeviceSessionStateMock = vi.fn();\nconst getManagerApiServiceMock = vi.fn();\nconst getSecureChannelServiceMock = vi.fn();\
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAGA,MAAMI,EAAe,GAAG,GAAG,EACrBC,EAAkB,GAAG,GAAG,EACxBC,EAAwB,GAAG,GAAG,EAC9BC,EAA+B,GAAG,GAAG,EACrCC,EAAyC,GAAG,GAAG,EAC/CC,EAA4B,GAAG,GAAG,EAClCC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,
|
|
6
|
-
"names": ["makeInternalApi_exports", "__export", "makeDeviceActionInternalApiMock", "__toCommonJS", "sendApduMock", "sendCommandMock", "apiGetDeviceModelMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "setDeviceSessionStateMock", "getManagerApiServiceMock", "getSecureChannelServiceMock"
|
|
4
|
+
"sourcesContent": ["import { type InternalApi } from \"@ledgerhq/device-management-kit\";\nimport { type Mocked } from \"vitest\";\n\nconst sendApduMock = vi.fn();\nconst sendCommandMock = vi.fn();\nconst apiGetDeviceModelMock = vi.fn();\nconst apiGetDeviceSessionStateMock = vi.fn();\nconst apiGetDeviceSessionStateObservableMock = vi.fn();\nconst setDeviceSessionStateMock = vi.fn();\nconst getManagerApiServiceMock = vi.fn();\nconst getSecureChannelServiceMock = vi.fn();\n\nexport function makeDeviceActionInternalApiMock(): Mocked<InternalApi> {\n return {\n sendApdu: sendApduMock,\n sendCommand: sendCommandMock,\n getDeviceModel: apiGetDeviceModelMock,\n getDeviceSessionState: apiGetDeviceSessionStateMock,\n getDeviceSessionStateObservable: apiGetDeviceSessionStateObservableMock,\n setDeviceSessionState: setDeviceSessionStateMock,\n getManagerApiService: getManagerApiServiceMock,\n getSecureChannelService: getSecureChannelServiceMock,\n };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qCAAAE,IAAA,eAAAC,EAAAH,GAGA,MAAMI,EAAe,GAAG,GAAG,EACrBC,EAAkB,GAAG,GAAG,EACxBC,EAAwB,GAAG,GAAG,EAC9BC,EAA+B,GAAG,GAAG,EACrCC,EAAyC,GAAG,GAAG,EAC/CC,EAA4B,GAAG,GAAG,EAClCC,EAA2B,GAAG,GAAG,EACjCC,EAA8B,GAAG,GAAG,EAEnC,SAAST,GAAuD,CACrE,MAAO,CACL,SAAUE,EACV,YAAaC,EACb,eAAgBC,EAChB,sBAAuBC,EACvB,gCAAiCC,EACjC,sBAAuBC,EACvB,qBAAsBC,EACtB,wBAAyBC,CAC3B,CACF",
|
|
6
|
+
"names": ["makeInternalApi_exports", "__export", "makeDeviceActionInternalApiMock", "__toCommonJS", "sendApduMock", "sendCommandMock", "apiGetDeviceModelMock", "apiGetDeviceSessionStateMock", "apiGetDeviceSessionStateObservableMock", "setDeviceSessionStateMock", "getManagerApiServiceMock", "getSecureChannelServiceMock"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var t=require("@ledgerhq/device-management-kit"),i=require("purify-ts"),s=require("../../../psbt/service/key/DefaultKeySerializer"),n=require("../../../psbt/service/value/DefaultValueParser"),u=require("./DefaultKeyPairSerializer");describe("DefaultKeyPairSerializer",()=>{let r;const l=new n.DefaultValueParser;beforeEach(()=>{const e=new s.DefaultKeySerializer;r=new u.DefaultKeyPairSerializer(e)}),it("Invalid key",()=>{const e=r.deserialize(new t.ByteArrayParser(Uint8Array.from([])));expect(e.isJust()).toStrictEqual(!1)}),it("Invalid valueLen",()=>{const e=r.deserialize(new t.ByteArrayParser(Uint8Array.from([7,42,0,1,2,3,4,5])));expect(e.isJust()).toStrictEqual(!1)}),it("Invalid value",()=>{const e=r.deserialize(new t.ByteArrayParser(Uint8Array.from([7,42,0,1,2,3,4,5,2,7])));expect(e.isJust()).toStrictEqual(!1)}),it("Serialize and deserialize a
|
|
1
|
+
"use strict";var t=require("@ledgerhq/device-management-kit"),i=require("purify-ts"),s=require("../../../psbt/service/key/DefaultKeySerializer"),n=require("../../../psbt/service/value/DefaultValueParser"),u=require("./DefaultKeyPairSerializer");describe("DefaultKeyPairSerializer",()=>{let r;const l=new n.DefaultValueParser;beforeEach(()=>{const e=new s.DefaultKeySerializer;r=new u.DefaultKeyPairSerializer(e)}),it("Invalid key",()=>{const e=r.deserialize(new t.ByteArrayParser(Uint8Array.from([])));expect(e.isJust()).toStrictEqual(!1)}),it("Invalid valueLen",()=>{const e=r.deserialize(new t.ByteArrayParser(Uint8Array.from([7,42,0,1,2,3,4,5])));expect(e.isJust()).toStrictEqual(!1)}),it("Invalid value",()=>{const e=r.deserialize(new t.ByteArrayParser(Uint8Array.from([7,42,0,1,2,3,4,5,2,7])));expect(e.isJust()).toStrictEqual(!1)}),it("Serialize and deserialize a keyPair",()=>{const e=new t.ByteArrayParser(Uint8Array.from([7,42,0,1,2,3,4,5,5,254,145,69,220,0,42])),c=r.deserialize(e);expect(c.isJust()).toStrictEqual(!0);const a=c.unsafeCoerce();expect(a.key.keyType).toStrictEqual(42),expect(a.key.keyData).toStrictEqual(Uint8Array.from([0,1,2,3,4,5])),expect(a.value.data).toStrictEqual(Uint8Array.from([254,145,69,220,0])),expect(l.getInt32LE(a.value.data)).toStrictEqual((0,i.Just)(-599420418)),expect(l.getVarint(a.value.data)).toStrictEqual((0,i.Just)(14435729)),expect(e.extract8BitUInt()).toStrictEqual(42);const o=new t.ByteArrayBuilder;r.serialize(o,a),expect(o.build()).toStrictEqual(Uint8Array.from([7,42,0,1,2,3,4,5,5,254,145,69,220,0]))})});
|
|
2
2
|
//# sourceMappingURL=DefaultKeyPairSerializer.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/psbt/service/key-pair/DefaultKeyPairSerializer.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ByteArrayBuilder,\n ByteArrayParser,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just } from \"purify-ts\";\n\nimport { DefaultKeySerializer } from \"@internal/psbt/service/key/DefaultKeySerializer\";\nimport { DefaultValueParser } from \"@internal/psbt/service/value/DefaultValueParser\";\n\nimport { DefaultKeyPairSerializer } from \"./DefaultKeyPairSerializer\";\n\ndescribe(\"DefaultKeyPairSerializer\", () => {\n let service: DefaultKeyPairSerializer;\n const valueParser = new DefaultValueParser();\n\n beforeEach(() => {\n const keySerializerService = new DefaultKeySerializer();\n service = new DefaultKeyPairSerializer(keySerializerService);\n });\n\n it(\"Invalid key\", () => {\n const keyPair = service.deserialize(\n new ByteArrayParser(Uint8Array.from([])),\n );\n expect(keyPair.isJust()).toStrictEqual(false);\n });\n\n it(\"Invalid valueLen\", () => {\n const keyPair = service.deserialize(\n new ByteArrayParser(Uint8Array.from([7, 42, 0, 1, 2, 3, 4, 5])),\n );\n expect(keyPair.isJust()).toStrictEqual(false);\n });\n\n it(\"Invalid value\", () => {\n const keyPair = service.deserialize(\n new ByteArrayParser(Uint8Array.from([7, 42, 0, 1, 2, 3, 4, 5, 2, 7])),\n );\n expect(keyPair.isJust()).toStrictEqual(false);\n });\n\n it(\"Serialize and deserialize a
|
|
4
|
+
"sourcesContent": ["import {\n ByteArrayBuilder,\n ByteArrayParser,\n} from \"@ledgerhq/device-management-kit\";\nimport { Just } from \"purify-ts\";\n\nimport { DefaultKeySerializer } from \"@internal/psbt/service/key/DefaultKeySerializer\";\nimport { DefaultValueParser } from \"@internal/psbt/service/value/DefaultValueParser\";\n\nimport { DefaultKeyPairSerializer } from \"./DefaultKeyPairSerializer\";\n\ndescribe(\"DefaultKeyPairSerializer\", () => {\n let service: DefaultKeyPairSerializer;\n const valueParser = new DefaultValueParser();\n\n beforeEach(() => {\n const keySerializerService = new DefaultKeySerializer();\n service = new DefaultKeyPairSerializer(keySerializerService);\n });\n\n it(\"Invalid key\", () => {\n const keyPair = service.deserialize(\n new ByteArrayParser(Uint8Array.from([])),\n );\n expect(keyPair.isJust()).toStrictEqual(false);\n });\n\n it(\"Invalid valueLen\", () => {\n const keyPair = service.deserialize(\n new ByteArrayParser(Uint8Array.from([7, 42, 0, 1, 2, 3, 4, 5])),\n );\n expect(keyPair.isJust()).toStrictEqual(false);\n });\n\n it(\"Invalid value\", () => {\n const keyPair = service.deserialize(\n new ByteArrayParser(Uint8Array.from([7, 42, 0, 1, 2, 3, 4, 5, 2, 7])),\n );\n expect(keyPair.isJust()).toStrictEqual(false);\n });\n\n it(\"Serialize and deserialize a keyPair\", () => {\n // Deserialize a valid keyPair\n const parser = new ByteArrayParser(\n Uint8Array.from([\n 7, 42, 0, 1, 2, 3, 4, 5, 5, 0xfe, 0x91, 0x45, 0xdc, 0x00, 42,\n ]),\n );\n\n const maybeKeyPair = service.deserialize(parser);\n expect(maybeKeyPair.isJust()).toStrictEqual(true);\n const keyPair = maybeKeyPair.unsafeCoerce();\n expect(keyPair.key.keyType).toStrictEqual(42);\n expect(keyPair.key.keyData).toStrictEqual(\n Uint8Array.from([0, 1, 2, 3, 4, 5]),\n );\n expect(keyPair.value.data).toStrictEqual(\n Uint8Array.from([0xfe, 0x91, 0x45, 0xdc, 0x00]),\n );\n expect(valueParser.getInt32LE(keyPair.value.data)).toStrictEqual(\n Just(-599420418),\n );\n expect(valueParser.getVarint(keyPair.value.data)).toStrictEqual(\n Just(0xdc4591),\n );\n expect(parser.extract8BitUInt()).toStrictEqual(42);\n\n // Re-serialize\n const builder = new ByteArrayBuilder();\n service.serialize(builder, keyPair);\n expect(builder.build()).toStrictEqual(\n Uint8Array.from([\n 7, 42, 0, 1, 2, 3, 4, 5, 5, 0xfe, 0x91, 0x45, 0xdc, 0x00,\n ]),\n );\n });\n});\n"],
|
|
5
5
|
"mappings": "aAAA,IAAAA,EAGO,2CACPC,EAAqB,qBAErBC,EAAqC,2DACrCC,EAAmC,2DAEnCC,EAAyC,sCAEzC,SAAS,2BAA4B,IAAM,CACzC,IAAIC,EACJ,MAAMC,EAAc,IAAI,qBAExB,WAAW,IAAM,CACf,MAAMC,EAAuB,IAAI,uBACjCF,EAAU,IAAI,2BAAyBE,CAAoB,CAC7D,CAAC,EAED,GAAG,cAAe,IAAM,CACtB,MAAMC,EAAUH,EAAQ,YACtB,IAAI,kBAAgB,WAAW,KAAK,CAAC,CAAC,CAAC,CACzC,EACA,OAAOG,EAAQ,OAAO,CAAC,EAAE,cAAc,EAAK,CAC9C,CAAC,EAED,GAAG,mBAAoB,IAAM,CAC3B,MAAMA,EAAUH,EAAQ,YACtB,IAAI,kBAAgB,WAAW,KAAK,CAAC,EAAG,GAAI,E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AAW,KAAK,CACd,EAAG,GAAI,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,IAAM,IAAM,GAAM,IAAM,CACtD,CAAC,CACH,CACF,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["import_device_management_kit", "import_purify_ts", "import_DefaultKeySerializer", "import_DefaultValueParser", "import_DefaultKeyPairSerializer", "service", "valueParser", "keySerializerService", "keyPair", "parser", "maybeKeyPair", "builder"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/internal/psbt/service/psbt/DefaultPsbtSerializer.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n ByteArrayParser,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"bitcoinjs-lib\";\nimport { inject } from \"inversify\";\nimport { Either, Left, Maybe, Right } from \"purify-ts\";\n\nimport { psbtTypes } from \"@internal/psbt/di/psbtTypes\";\nimport { Key } from \"@internal/psbt/model/Key\";\nimport { Psbt } from \"@internal/psbt/model/Psbt\";\nimport { PsbtGlobal } from \"@internal/psbt/model/Psbt\";\nimport { Value } from \"@internal/psbt/model/Value\";\nimport { type KeyPairSerializer } from \"@internal/psbt/service/key-pair/KeyPairSerializer\";\nimport { type ValueParser } from \"@internal/psbt/service/value/ValueParser\";\n\nimport { type PsbtSerializer } from \"./PsbtSerializer\";\n\n// PSBT magic bytes\nconst PSBT_MAGIC_BYTES = Uint8Array.from([0x70, 0x73, 0x62, 0x74, 0xff]);\n\n/**\n * According to specification, psbt is formatted as:\n * <magic> <global-map> <input-map>* <output-map>*\n * with:\n * <magic>: 0x70 0x73 0x62 0x74 0xFF\n * <map>: <
|
|
4
|
+
"sourcesContent": ["import {\n bufferToHexaString,\n ByteArrayBuilder,\n ByteArrayParser,\n} from \"@ledgerhq/device-management-kit\";\nimport { Transaction } from \"bitcoinjs-lib\";\nimport { inject } from \"inversify\";\nimport { Either, Left, Maybe, Right } from \"purify-ts\";\n\nimport { psbtTypes } from \"@internal/psbt/di/psbtTypes\";\nimport { Key } from \"@internal/psbt/model/Key\";\nimport { Psbt } from \"@internal/psbt/model/Psbt\";\nimport { PsbtGlobal } from \"@internal/psbt/model/Psbt\";\nimport { Value } from \"@internal/psbt/model/Value\";\nimport { type KeyPairSerializer } from \"@internal/psbt/service/key-pair/KeyPairSerializer\";\nimport { type ValueParser } from \"@internal/psbt/service/value/ValueParser\";\n\nimport { type PsbtSerializer } from \"./PsbtSerializer\";\n\n// PSBT magic bytes\nconst PSBT_MAGIC_BYTES = Uint8Array.from([0x70, 0x73, 0x62, 0x74, 0xff]);\n\n/**\n * According to specification, psbt is formatted as:\n * <magic> <global-map> <input-map>* <output-map>*\n * with:\n * <magic>: 0x70 0x73 0x62 0x74 0xFF\n * <map>: <keyPair>* 0x00\n * For <keyPair> serialization, it's done in KeyPair class.\n * For more informations:\n * https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#specification\n */\nexport class DefaultPsbtSerializer implements PsbtSerializer {\n constructor(\n @inject(psbtTypes.ValueParser)\n private readonly valueParser: ValueParser,\n @inject(psbtTypes.KeyPairSerializer)\n private readonly keyPairSerializer: KeyPairSerializer,\n ) {}\n\n private getValue(map: Map<string, Value>, keyType: number): Maybe<Value> {\n return Maybe.fromNullable(map.get(new Key(keyType).toHexaString()));\n }\n\n private sortMap(map: Map<string, Value>): Map<string, Value> {\n return new Map(\n Array.from(map.entries()).sort((a, b) => a[0].localeCompare(b[0])),\n );\n }\n\n deserialize(buffer: Uint8Array): Either<Error, Psbt> {\n const parser = new ByteArrayParser(buffer);\n\n // Read PSBT magic\n for (const magicByte of PSBT_MAGIC_BYTES) {\n if (parser.extract8BitUInt() !== magicByte) {\n return Left(new Error(\"PSBT deserializer: Invalid magic bytes\"));\n }\n }\n\n // Read all the maps available in that PSBT\n const maps: Map<string, Value>[] = [];\n while (parser.getUnparsedRemainingLength()) {\n maps.push(this.keyPairSerializer.deserializeMap(parser));\n }\n if (maps.length === 0) {\n return Left(new Error(\"PSBT deserializer: No map found\"));\n }\n\n // Get global map\n const globalMap = maps[0]!;\n\n // Get inputs and outpus count, either from the global map, or within the tx\n const transaction = this.getValue(globalMap, PsbtGlobal.UNSIGNED_TX).chain(\n (value) =>\n Either.encase(() =>\n Transaction.fromHex(bufferToHexaString(value.data, false)),\n ).toMaybe(),\n );\n const inputCount = this.getValue(globalMap, PsbtGlobal.INPUT_COUNT)\n .chain((value) => this.valueParser.getVarint(value.data))\n .alt(transaction.map((tx) => tx.ins.length));\n const outputCount = this.getValue(globalMap, PsbtGlobal.OUTPUT_COUNT)\n .chain((value) => this.valueParser.getVarint(value.data))\n .alt(transaction.map((tx) => tx.outs.length));\n\n // Get inputs map and outputs map\n if (inputCount.isJust() && outputCount.isJust()) {\n if (maps.length === 1 + inputCount.extract() + outputCount.extract()) {\n const inputMaps = maps.slice(1, 1 + inputCount.extract());\n const outputMaps = maps.slice(1 + inputCount.extract());\n return Right(new Psbt(globalMap, inputMaps, outputMaps));\n }\n return Left(\n new Error(\n \"PSBT deserializer: map count don't match input and output count\",\n ),\n );\n }\n return Left(\n new Error(\n \"PSBT deserializer: input or output count not found in global map or transaction\",\n ),\n );\n }\n\n serialize(psbt: Psbt): Uint8Array {\n const builder = new ByteArrayBuilder();\n\n // Start by ordering all the maps, in case some values were added\n psbt.globalMap = this.sortMap(psbt.globalMap);\n psbt.inputMaps = psbt.inputMaps.map((input) => this.sortMap(input));\n psbt.outputMaps = psbt.outputMaps.map((output) => this.sortMap(output));\n\n // Serialize PSBT magic\n builder.addBufferToData(PSBT_MAGIC_BYTES);\n\n // Serialize all the maps\n this.keyPairSerializer.serializeMap(builder, psbt.globalMap);\n psbt.inputMaps.forEach((input) =>\n this.keyPairSerializer.serializeMap(builder, input),\n );\n psbt.outputMaps.forEach((output) =>\n this.keyPairSerializer.serializeMap(builder, output),\n );\n\n return builder.build();\n }\n}\n"],
|
|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,eAAO,YAAU,iBAAiB,IAJ1BvB",
|
|
6
6
|
"names": ["DefaultPsbtSerializer_exports", "__export", "DefaultPsbtSerializer", "__toCommonJS", "import_device_management_kit", "import_bitcoinjs_lib", "import_inversify", "import_purify_ts", "import_psbtTypes", "import_Key", "import_Psbt", "PSBT_MAGIC_BYTES", "DefaultPsbtSerializer", "valueParser", "keyPairSerializer", "map", "keyType", "b", "buffer", "parser", "magicByte", "maps", "globalMap", "transaction", "value", "inputCount", "tx", "outputCount", "inputMaps", "outputMaps", "psbt", "builder", "input", "output", "__decorateClass", "__decorateParam"]
|
|
7
7
|
}
|
package/lib/cjs/package.json
CHANGED
|
@@ -1,63 +1,67 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
"dependencies": {
|
|
3
|
+
"@types/crypto-js": "catalog:",
|
|
4
|
+
"crypto-js": "catalog:",
|
|
5
|
+
"inversify": "catalog:",
|
|
6
|
+
"purify-ts": "catalog:",
|
|
7
|
+
"reflect-metadata": "catalog:",
|
|
8
|
+
"xstate": "catalog:"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@ledgerhq/device-management-kit": "workspace:^",
|
|
12
|
+
"@ledgerhq/eslint-config-dsdk": "workspace:^",
|
|
13
|
+
"@ledgerhq/ldmk-tool": "workspace:^",
|
|
14
|
+
"@ledgerhq/prettier-config-dsdk": "workspace:^",
|
|
15
|
+
"@ledgerhq/signer-utils": "workspace:^",
|
|
16
|
+
"@ledgerhq/tsconfig-dsdk": "workspace:^",
|
|
17
|
+
"@ledgerhq/vitest-config-dmk": "workspace:^",
|
|
18
|
+
"bitcoinjs-lib": "catalog:",
|
|
19
|
+
"rxjs": "catalog:",
|
|
20
|
+
"ts-node": "catalog:"
|
|
21
|
+
},
|
|
8
22
|
"exports": {
|
|
9
23
|
".": {
|
|
10
|
-
"types": "./lib/types/index.d.ts",
|
|
11
24
|
"import": "./lib/esm/index.js",
|
|
12
|
-
"require": "./lib/cjs/index.js"
|
|
25
|
+
"require": "./lib/cjs/index.js",
|
|
26
|
+
"types": "./lib/types/index.d.ts"
|
|
13
27
|
},
|
|
14
28
|
"./*": {
|
|
15
|
-
"types": "./lib/types/*",
|
|
16
29
|
"import": "./lib/esm/*",
|
|
17
|
-
"require": "./lib/cjs/*"
|
|
30
|
+
"require": "./lib/cjs/*",
|
|
31
|
+
"types": "./lib/types/*"
|
|
18
32
|
}
|
|
19
33
|
},
|
|
20
34
|
"files": [
|
|
21
35
|
"./lib"
|
|
22
36
|
],
|
|
37
|
+
"license": "Apache-2.0",
|
|
38
|
+
"main": "lib/cjs/index.js",
|
|
39
|
+
"name": "@ledgerhq/device-signer-kit-bitcoin",
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@ledgerhq/device-management-kit": "workspace:^",
|
|
42
|
+
"bitcoinjs-lib": "^6.1.6"
|
|
43
|
+
},
|
|
44
|
+
"private": false,
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/LedgerHQ/device-sdk-ts.git"
|
|
48
|
+
},
|
|
23
49
|
"scripts": {
|
|
24
|
-
"prebuild": "rimraf lib",
|
|
25
50
|
"build": "pnpm ldmk-tool build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
26
51
|
"dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
|
|
27
|
-
"watch:builds": "pnpm ldmk-tool watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
28
|
-
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
|
|
29
52
|
"lint": "eslint",
|
|
30
53
|
"lint:fix": "pnpm lint --fix",
|
|
31
54
|
"postpack": "find . -name '*.tgz' -exec cp {} ../../../dist/ \\; ",
|
|
55
|
+
"prebuild": "rimraf lib",
|
|
32
56
|
"prettier": "prettier . --check",
|
|
33
57
|
"prettier:fix": "prettier . --write",
|
|
34
|
-
"typecheck": "tsc --noEmit",
|
|
35
58
|
"test": "vitest run",
|
|
59
|
+
"test:coverage": "vitest run --coverage",
|
|
36
60
|
"test:watch": "vitest",
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"@types/crypto-js": "catalog:",
|
|
41
|
-
"crypto-js": "catalog:",
|
|
42
|
-
"inversify": "catalog:",
|
|
43
|
-
"purify-ts": "catalog:",
|
|
44
|
-
"reflect-metadata": "catalog:",
|
|
45
|
-
"xstate": "catalog:"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@ledgerhq/device-management-kit": "workspace:*",
|
|
49
|
-
"@ledgerhq/ldmk-tool": "workspace:*",
|
|
50
|
-
"@ledgerhq/eslint-config-dsdk": "workspace:*",
|
|
51
|
-
"@ledgerhq/prettier-config-dsdk": "workspace:*",
|
|
52
|
-
"@ledgerhq/signer-utils": "workspace:*",
|
|
53
|
-
"@ledgerhq/tsconfig-dsdk": "workspace:*",
|
|
54
|
-
"@ledgerhq/vitest-config-dmk": "workspace:*",
|
|
55
|
-
"bitcoinjs-lib": "catalog:",
|
|
56
|
-
"rxjs": "catalog:",
|
|
57
|
-
"ts-node": "catalog:"
|
|
61
|
+
"typecheck": "tsc --noEmit",
|
|
62
|
+
"watch:builds": "pnpm ldmk-tool watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
|
|
63
|
+
"watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\""
|
|
58
64
|
},
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
"bitcoinjs-lib": "^6.1.6"
|
|
62
|
-
}
|
|
65
|
+
"types": "lib/cjs/index.d.ts",
|
|
66
|
+
"version": "0.0.0-z-intent-queue-7-20251204111630"
|
|
63
67
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduBuilder as
|
|
1
|
+
import{ApduBuilder as o,CommandResultFactory as r}from"@ledgerhq/device-management-kit";import{CommandErrorHelper as n}from"@ledgerhq/signer-utils";import{Maybe as t}from"purify-ts";import{BTC_APP_ERRORS as m,BtcAppCommandErrorFactory as p}from"../../app-binder/command/utils/bitcoinAppErrors";import{BtcCommandUtils as a}from"../../utils/BtcCommandUtils";class c{constructor(e,d=new n(m,p,a.isSuccessResponse)){this._args=e;this._errorHelper=d}name="continue";getApdu(){return new o({cla:248,ins:1,p1:0,p2:0}).addBufferToData(this._args.payload).build()}parseResponse(e){return t.fromNullable(this._errorHelper.getError(e)).orDefault(r({data:e}))}}export{c as ContinueCommand};
|
|
2
2
|
//# sourceMappingURL=ContinueCommand.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/ContinueCommand.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nexport type ContinueCommandArgs = {\n payload: Uint8Array;\n};\n\nexport type ContinueCommandResponse = ApduResponse;\n\nexport class ContinueCommand\n implements\n Command<ContinueCommandResponse, ContinueCommandArgs, BtcErrorCodes>\n{\n constructor(\n private readonly _args: ContinueCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n ContinueCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n return new ApduBuilder({\n cla: 0xf8,\n ins: 0x01,\n p1: 0x00,\n p2: 0x00,\n })\n .addBufferToData(this._args.payload)\n .build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<ContinueCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(this._errorHelper.getError(response)).orDefault(\n CommandResultFactory({\n data: response,\n }),\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAEE,eAAAA,EAIA,wBAAAC,MACK,kCACP,OAAS,sBAAAC,MAA0B,yBACnC,OAAS,SAAAC,MAAa,YAEtB,OACE,kBAAAC,EACA,6BAAAC,MAEK,sDACP,OAAS,mBAAAC,MAAuB,kCAQzB,MAAMC,CAGb,
|
|
4
|
+
"sourcesContent": ["import {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nexport type ContinueCommandArgs = {\n payload: Uint8Array;\n};\n\nexport type ContinueCommandResponse = ApduResponse;\n\nexport class ContinueCommand\n implements\n Command<ContinueCommandResponse, ContinueCommandArgs, BtcErrorCodes>\n{\n readonly name = \"continue\";\n constructor(\n private readonly _args: ContinueCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n ContinueCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n return new ApduBuilder({\n cla: 0xf8,\n ins: 0x01,\n p1: 0x00,\n p2: 0x00,\n })\n .addBufferToData(this._args.payload)\n .build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<ContinueCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(this._errorHelper.getError(response)).orDefault(\n CommandResultFactory({\n data: response,\n }),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,eAAAA,EAIA,wBAAAC,MACK,kCACP,OAAS,sBAAAC,MAA0B,yBACnC,OAAS,SAAAC,MAAa,YAEtB,OACE,kBAAAC,EACA,6BAAAC,MAEK,sDACP,OAAS,mBAAAC,MAAuB,kCAQzB,MAAMC,CAGb,CAEE,YACmBC,EACAC,EAAe,IAAIP,EAIlCE,EACAC,EACAC,EAAgB,iBAClB,EACA,CATiB,WAAAE,EACA,kBAAAC,CAQhB,CAXM,KAAO,WAahB,SAAgB,CACd,OAAO,IAAIT,EAAY,CACrB,IAAK,IACL,IAAK,EACL,GAAI,EACJ,GAAI,CACN,CAAC,EACE,gBAAgB,KAAK,MAAM,OAAO,EAClC,MAAM,CACX,CAEA,cACEU,EACuD,CACvD,OAAOP,EAAM,aAAa,KAAK,aAAa,SAASO,CAAQ,CAAC,EAAE,UAC9DT,EAAqB,CACnB,KAAMS,CACR,CAAC,CACH,CACF,CACF",
|
|
6
6
|
"names": ["ApduBuilder", "CommandResultFactory", "CommandErrorHelper", "Maybe", "BTC_APP_ERRORS", "BtcAppCommandErrorFactory", "BtcCommandUtils", "ContinueCommand", "_args", "_errorHelper", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduResponse as d,CommandResultFactory as c}from"@ledgerhq/device-management-kit";import{SW_INTERRUPTED_EXECUTION as
|
|
1
|
+
import{ApduResponse as d,CommandResultFactory as c}from"@ledgerhq/device-management-kit";import{SW_INTERRUPTED_EXECUTION as i}from"../../app-binder/command/utils/constants";import{ContinueCommand as o}from"./ContinueCommand";describe("ContinueCommand",()=>{const n={payload:new Uint8Array([222,173,190,239])},a=new Uint8Array([248,1,0,0,4,222,173,190,239]);describe("name",()=>{it("should be 'continue'",()=>{const e=new o(n);expect(e.name).toBe("continue")})}),describe("getApdu",()=>{it("should return correct APDU for given payload",()=>{const t=new o(n).getApdu();expect(t.getRawApdu()).toStrictEqual(a)})}),describe("parseResponse",()=>{it("should return the APDU response if it's a continue response",()=>{const e=new o(n),t=new Uint8Array([1,2,3,4]),s=new d({statusCode:i,data:t}),r=e.parseResponse(s);expect(r).toStrictEqual(c({data:s}))})})});
|
|
2
2
|
//# sourceMappingURL=ContinueCommand.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/ContinueCommand.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { SW_INTERRUPTED_EXECUTION } from \"@internal/app-binder/command/utils/constants\";\n\nimport { ContinueCommand } from \"./ContinueCommand\";\n\ndescribe(\"ContinueCommand\", (): void => {\n const defaultArgs = {\n payload: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),\n };\n\n const EXPECTED_APDU = new Uint8Array([\n 0xf8, // CLA\n 0x01, // INS\n 0x00, // P1\n 0x00, // P2\n 0x04, // Lc\n 0xde,\n 0xad,\n 0xbe,\n 0xef, // Payload data\n ]);\n\n describe(\"getApdu\", () => {\n it(\"should return correct APDU for given payload\", () => {\n // given\n const command = new ContinueCommand(defaultArgs);\n // when\n const apdu = command.getApdu();\n // then\n expect(apdu.getRawApdu()).toStrictEqual(EXPECTED_APDU);\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"should return the APDU response if it's a continue response\", () => {\n // given\n const command = new ContinueCommand(defaultArgs);\n const continueResponseData = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const apduResponse = new ApduResponse({\n statusCode: SW_INTERRUPTED_EXECUTION,\n data: continueResponseData,\n });\n\n // when\n const response = command.parseResponse(apduResponse);\n\n // then\n expect(response).toStrictEqual(\n CommandResultFactory({\n data: apduResponse,\n }),\n );\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OACE,gBAAAA,EACA,wBAAAC,MACK,kCAEP,OAAS,4BAAAC,MAAgC,+CAEzC,OAAS,mBAAAC,MAAuB,oBAEhC,SAAS,kBAAmB,IAAY,CACtC,MAAMC,EAAc,CAClB,QAAS,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,GAAI,CAAC,CAClD,EAEMC,EAAgB,IAAI,WAAW,CACnC,IACA,EACA,EACA,EACA,EACA,IACA,IACA,IACA,GACF,CAAC,EAED,SAAS,UAAW,IAAM,CACxB,GAAG,+CAAgD,IAAM,CAIvD,MAAMC,EAFU,
|
|
6
|
-
"names": ["ApduResponse", "CommandResultFactory", "SW_INTERRUPTED_EXECUTION", "ContinueCommand", "defaultArgs", "EXPECTED_APDU", "
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\n\nimport { SW_INTERRUPTED_EXECUTION } from \"@internal/app-binder/command/utils/constants\";\n\nimport { ContinueCommand } from \"./ContinueCommand\";\n\ndescribe(\"ContinueCommand\", (): void => {\n const defaultArgs = {\n payload: new Uint8Array([0xde, 0xad, 0xbe, 0xef]),\n };\n\n const EXPECTED_APDU = new Uint8Array([\n 0xf8, // CLA\n 0x01, // INS\n 0x00, // P1\n 0x00, // P2\n 0x04, // Lc\n 0xde,\n 0xad,\n 0xbe,\n 0xef, // Payload data\n ]);\n\n describe(\"name\", () => {\n it(\"should be 'continue'\", () => {\n const command = new ContinueCommand(defaultArgs);\n expect(command.name).toBe(\"continue\");\n });\n });\n\n describe(\"getApdu\", () => {\n it(\"should return correct APDU for given payload\", () => {\n // given\n const command = new ContinueCommand(defaultArgs);\n // when\n const apdu = command.getApdu();\n // then\n expect(apdu.getRawApdu()).toStrictEqual(EXPECTED_APDU);\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"should return the APDU response if it's a continue response\", () => {\n // given\n const command = new ContinueCommand(defaultArgs);\n const continueResponseData = new Uint8Array([0x01, 0x02, 0x03, 0x04]);\n const apduResponse = new ApduResponse({\n statusCode: SW_INTERRUPTED_EXECUTION,\n data: continueResponseData,\n });\n\n // when\n const response = command.parseResponse(apduResponse);\n\n // then\n expect(response).toStrictEqual(\n CommandResultFactory({\n data: apduResponse,\n }),\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,gBAAAA,EACA,wBAAAC,MACK,kCAEP,OAAS,4BAAAC,MAAgC,+CAEzC,OAAS,mBAAAC,MAAuB,oBAEhC,SAAS,kBAAmB,IAAY,CACtC,MAAMC,EAAc,CAClB,QAAS,IAAI,WAAW,CAAC,IAAM,IAAM,IAAM,GAAI,CAAC,CAClD,EAEMC,EAAgB,IAAI,WAAW,CACnC,IACA,EACA,EACA,EACA,EACA,IACA,IACA,IACA,GACF,CAAC,EAED,SAAS,OAAQ,IAAM,CACrB,GAAG,uBAAwB,IAAM,CAC/B,MAAMC,EAAU,IAAIH,EAAgBC,CAAW,EAC/C,OAAOE,EAAQ,IAAI,EAAE,KAAK,UAAU,CACtC,CAAC,CACH,CAAC,EAED,SAAS,UAAW,IAAM,CACxB,GAAG,+CAAgD,IAAM,CAIvD,MAAMC,EAFU,IAAIJ,EAAgBC,CAAW,EAE1B,QAAQ,EAE7B,OAAOG,EAAK,WAAW,CAAC,EAAE,cAAcF,CAAa,CACvD,CAAC,CACH,CAAC,EAED,SAAS,gBAAiB,IAAM,CAC9B,GAAG,8DAA+D,IAAM,CAEtE,MAAMC,EAAU,IAAIH,EAAgBC,CAAW,EACzCI,EAAuB,IAAI,WAAW,CAAC,EAAM,EAAM,EAAM,CAAI,CAAC,EAC9DC,EAAe,IAAIT,EAAa,CACpC,WAAYE,EACZ,KAAMM,CACR,CAAC,EAGKE,EAAWJ,EAAQ,cAAcG,CAAY,EAGnD,OAAOC,CAAQ,EAAE,cACfT,EAAqB,CACnB,KAAMQ,CACR,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["ApduResponse", "CommandResultFactory", "SW_INTERRUPTED_EXECUTION", "ContinueCommand", "defaultArgs", "EXPECTED_APDU", "command", "apdu", "continueResponseData", "apduResponse", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduBuilder as s,ApduParser as i,CommandResultFactory as d,InvalidStatusWordError as p}from"@ledgerhq/device-management-kit";import{CommandErrorHelper as m,DerivationPathUtils as
|
|
1
|
+
import{ApduBuilder as s,ApduParser as i,CommandResultFactory as d,InvalidStatusWordError as p}from"@ledgerhq/device-management-kit";import{CommandErrorHelper as m,DerivationPathUtils as l}from"@ledgerhq/signer-utils";import{Maybe as c}from"purify-ts";import{BTC_APP_ERRORS as u,BtcAppCommandErrorFactory as y}from"../../app-binder/command/utils/bitcoinAppErrors";import{BtcCommandUtils as g}from"../../utils/BtcCommandUtils";class h{constructor(t,e=new m(u,y,g.isSuccessResponse)){this._args=t;this._errorHelper=e}name="getExtendedPublicKey";getApdu(){const{checkOnDevice:t,derivationPath:e}=this._args,n={cla:225,ins:0,p1:0,p2:0},r=new s(n).add8BitUIntToData(t?1:0),o=l.splitPath(e);return r.add8BitUIntToData(o.length),o.forEach(a=>{r.add32BitUIntToData(a)}),r.build()}parseResponse(t){return c.fromNullable(this._errorHelper.getError(t)).orDefaultLazy(()=>{const e=new i(t),n=e.getUnparsedRemainingLength();if(n<=0)return d({error:new p("Invalid response length")});const r=e.encodeToString(e.extractFieldByLength(n));return d({data:{extendedPublicKey:r}})})}}export{h as GetExtendedPublicKeyCommand};
|
|
2
2
|
//# sourceMappingURL=GetExtendedPublicKeyCommand.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/GetExtendedPublicKeyCommand.ts"],
|
|
4
|
-
"sourcesContent": ["// https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey\nimport {\n type Apdu,\n ApduBuilder,\n type ApduBuilderArgs,\n ApduParser,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n CommandErrorHelper,\n DerivationPathUtils,\n} from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nexport type GetExtendedPublicKeyCommandArgs = {\n checkOnDevice: boolean;\n derivationPath: string;\n};\n\nexport type GetExtendedPublicKeyCommandResponse = {\n extendedPublicKey: string;\n};\n\nexport class GetExtendedPublicKeyCommand\n implements\n Command<\n GetExtendedPublicKeyCommandResponse,\n GetExtendedPublicKeyCommandArgs,\n BtcErrorCodes\n >\n{\n constructor(\n private readonly _args: GetExtendedPublicKeyCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n GetExtendedPublicKeyCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n const { checkOnDevice, derivationPath } = this._args;\n\n const getExtendedPublicKeyArgs: ApduBuilderArgs = {\n cla: 0xe1,\n ins: 0x00,\n p1: 0x00,\n p2: 0x00,\n };\n const builder = new ApduBuilder(getExtendedPublicKeyArgs).add8BitUIntToData(\n checkOnDevice ? 0x01 : 0x00,\n );\n\n const path = DerivationPathUtils.splitPath(derivationPath);\n builder.add8BitUIntToData(path.length);\n path.forEach((element) => {\n builder.add32BitUIntToData(element);\n });\n\n return builder.build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<GetExtendedPublicKeyCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(\n this._errorHelper.getError(response),\n ).orDefaultLazy(() => {\n const parser = new ApduParser(response);\n const length = parser.getUnparsedRemainingLength();\n\n if (length <= 0) {\n return CommandResultFactory({\n error: new InvalidStatusWordError(\"Invalid response length\"),\n });\n }\n\n const extendedPublicKey = parser.encodeToString(\n parser.extractFieldByLength(length),\n );\n\n return CommandResultFactory({\n data: {\n extendedPublicKey,\n },\n });\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,OAEE,eAAAA,EAEA,cAAAC,EAIA,wBAAAC,EACA,0BAAAC,MACK,kCACP,OACE,sBAAAC,EACA,uBAAAC,MACK,yBACP,OAAS,SAAAC,MAAa,YAEtB,OACE,kBAAAC,EACA,6BAAAC,MAEK,sDACP,OAAS,mBAAAC,MAAuB,kCAWzB,MAAMC,CAOb,
|
|
4
|
+
"sourcesContent": ["// https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey\nimport {\n type Apdu,\n ApduBuilder,\n type ApduBuilderArgs,\n ApduParser,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport {\n CommandErrorHelper,\n DerivationPathUtils,\n} from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nexport type GetExtendedPublicKeyCommandArgs = {\n checkOnDevice: boolean;\n derivationPath: string;\n};\n\nexport type GetExtendedPublicKeyCommandResponse = {\n extendedPublicKey: string;\n};\n\nexport class GetExtendedPublicKeyCommand\n implements\n Command<\n GetExtendedPublicKeyCommandResponse,\n GetExtendedPublicKeyCommandArgs,\n BtcErrorCodes\n >\n{\n readonly name = \"getExtendedPublicKey\";\n constructor(\n private readonly _args: GetExtendedPublicKeyCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n GetExtendedPublicKeyCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n const { checkOnDevice, derivationPath } = this._args;\n\n const getExtendedPublicKeyArgs: ApduBuilderArgs = {\n cla: 0xe1,\n ins: 0x00,\n p1: 0x00,\n p2: 0x00,\n };\n const builder = new ApduBuilder(getExtendedPublicKeyArgs).add8BitUIntToData(\n checkOnDevice ? 0x01 : 0x00,\n );\n\n const path = DerivationPathUtils.splitPath(derivationPath);\n builder.add8BitUIntToData(path.length);\n path.forEach((element) => {\n builder.add32BitUIntToData(element);\n });\n\n return builder.build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<GetExtendedPublicKeyCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(\n this._errorHelper.getError(response),\n ).orDefaultLazy(() => {\n const parser = new ApduParser(response);\n const length = parser.getUnparsedRemainingLength();\n\n if (length <= 0) {\n return CommandResultFactory({\n error: new InvalidStatusWordError(\"Invalid response length\"),\n });\n }\n\n const extendedPublicKey = parser.encodeToString(\n parser.extractFieldByLength(length),\n );\n\n return CommandResultFactory({\n data: {\n extendedPublicKey,\n },\n });\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAEE,eAAAA,EAEA,cAAAC,EAIA,wBAAAC,EACA,0BAAAC,MACK,kCACP,OACE,sBAAAC,EACA,uBAAAC,MACK,yBACP,OAAS,SAAAC,MAAa,YAEtB,OACE,kBAAAC,EACA,6BAAAC,MAEK,sDACP,OAAS,mBAAAC,MAAuB,kCAWzB,MAAMC,CAOb,CAEE,YACmBC,EACAC,EAAe,IAAIR,EAIlCG,EACAC,EACAC,EAAgB,iBAClB,EACA,CATiB,WAAAE,EACA,kBAAAC,CAQhB,CAXM,KAAO,uBAahB,SAAgB,CACd,KAAM,CAAE,cAAAC,EAAe,eAAAC,CAAe,EAAI,KAAK,MAEzCC,EAA4C,CAChD,IAAK,IACL,IAAK,EACL,GAAI,EACJ,GAAI,CACN,EACMC,EAAU,IAAIhB,EAAYe,CAAwB,EAAE,kBACxDF,EAAgB,EAAO,CACzB,EAEMI,EAAOZ,EAAoB,UAAUS,CAAc,EACzD,OAAAE,EAAQ,kBAAkBC,EAAK,MAAM,EACrCA,EAAK,QAASC,GAAY,CACxBF,EAAQ,mBAAmBE,CAAO,CACpC,CAAC,EAEMF,EAAQ,MAAM,CACvB,CAEA,cACEG,EACmE,CACnE,OAAOb,EAAM,aACX,KAAK,aAAa,SAASa,CAAQ,CACrC,EAAE,cAAc,IAAM,CACpB,MAAMC,EAAS,IAAInB,EAAWkB,CAAQ,EAChCE,EAASD,EAAO,2BAA2B,EAEjD,GAAIC,GAAU,EACZ,OAAOnB,EAAqB,CAC1B,MAAO,IAAIC,EAAuB,yBAAyB,CAC7D,CAAC,EAGH,MAAMmB,EAAoBF,EAAO,eAC/BA,EAAO,qBAAqBC,CAAM,CACpC,EAEA,OAAOnB,EAAqB,CAC1B,KAAM,CACJ,kBAAAoB,CACF,CACF,CAAC,CACH,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["ApduBuilder", "ApduParser", "CommandResultFactory", "InvalidStatusWordError", "CommandErrorHelper", "DerivationPathUtils", "Maybe", "BTC_APP_ERRORS", "BtcAppCommandErrorFactory", "BtcCommandUtils", "GetExtendedPublicKeyCommand", "_args", "_errorHelper", "checkOnDevice", "derivationPath", "getExtendedPublicKeyArgs", "builder", "path", "element", "response", "parser", "length", "extendedPublicKey"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduResponse as o,CommandResultFactory as a,InvalidStatusWordError as s}from"@ledgerhq/device-management-kit";import{BTC_APP_ERRORS as d,BtcAppCommandErrorFactory as c}from"../../app-binder/command/utils/bitcoinAppErrors";import{GetExtendedPublicKeyCommand as r}from"./GetExtendedPublicKeyCommand";const u=new Uint8Array([225,0,0,0,14,1,3,128,0,0,84,128,0,0,0,128,0,0,0]),i=new Uint8Array([225,0,0,0,14,0,3,128,0,0,84,128,0,0,0,128,0,0,0]),p=new Uint8Array([225,0,0,0,18,1,4,128,0,0,49,128,0,0,0,128,0,0,0,0,0,0,0]),E=new Uint8Array([120,112,117,98,54,68,57,80,112,52,114,70,118,119,84,71,120,56,56,89,68,52,67,68,97,49,110,66,69,112,99,75,69,90,84,67,78,70,122,67,70,55,103,86,80,122,54,84,104,57,66,97,86,104,104,80,74,68,117,103,57,89,89,70,80,89,109,107,83,72,76,102,82,49,86,81,89,106,53,106,97,121,113,119,83,89,65,82,110,117,66,74,105,80,83,68,97,98,121,121,84,105,67,68,55,66,51,99,106,80,113]);describe("GetExtendedPublicKeyCommand",()=>{let x;const t={checkOnDevice:!0,derivationPath:"84'/0'/0'"};beforeEach(()=>{}),describe("getApdu",()=>{it("should return the correct APDU",()=>{x=new r(t);const e=x.getApdu();expect(e.getRawApdu()).toEqual(u)}),it("should return the correct APDU without checkOnDevice",()=>{x=new r({...t,checkOnDevice:!1});const e=x.getApdu();expect(e.getRawApdu()).toEqual(i)}),it("should return the correct APDU with different derivation path",()=>{x=new r({...t,derivationPath:"49'/0'/0'/0"});const e=x.getApdu();expect(e.getRawApdu()).toEqual(p)})}),describe("parseResponse",()=>{it("should return the extended public key",()=>{x=new r(t);const e=new o({data:E,statusCode:new Uint8Array([144,0])}),n=x.parseResponse(e);expect(n).toEqual(a({data:{extendedPublicKey:"xpub6D9Pp4rFvwTGx88YD4CDa1nBEpcKEZTCNFzCF7gVPz6Th9BaVhhPJDug9YYFPYmkSHLfR1VQYj5jayqwSYARnuBJiPSDabyyTiCD7B3cjPq"}}))}),it("should return an error if the response is not successful",()=>{x=new r(t);const e=new o({statusCode:Uint8Array.from([109,0]),data:new Uint8Array(0)}),n=x.parseResponse(e);expect(n).toStrictEqual(a({error:c({...d["6d00"],errorCode:"6d00"})}))}),it("should return an error if the response is too short",()=>{x=new r(t);const e=new o({data:Uint8Array.from([]),statusCode:new Uint8Array([144,0])}),n=x.parseResponse(e);expect(n).toStrictEqual(a({error:new s("Invalid response length")}))})})});
|
|
1
|
+
import{ApduResponse as o,CommandResultFactory as a,InvalidStatusWordError as s}from"@ledgerhq/device-management-kit";import{BTC_APP_ERRORS as d,BtcAppCommandErrorFactory as c}from"../../app-binder/command/utils/bitcoinAppErrors";import{GetExtendedPublicKeyCommand as r}from"./GetExtendedPublicKeyCommand";const u=new Uint8Array([225,0,0,0,14,1,3,128,0,0,84,128,0,0,0,128,0,0,0]),i=new Uint8Array([225,0,0,0,14,0,3,128,0,0,84,128,0,0,0,128,0,0,0]),p=new Uint8Array([225,0,0,0,18,1,4,128,0,0,49,128,0,0,0,128,0,0,0,0,0,0,0]),E=new Uint8Array([120,112,117,98,54,68,57,80,112,52,114,70,118,119,84,71,120,56,56,89,68,52,67,68,97,49,110,66,69,112,99,75,69,90,84,67,78,70,122,67,70,55,103,86,80,122,54,84,104,57,66,97,86,104,104,80,74,68,117,103,57,89,89,70,80,89,109,107,83,72,76,102,82,49,86,81,89,106,53,106,97,121,113,119,83,89,65,82,110,117,66,74,105,80,83,68,97,98,121,121,84,105,67,68,55,66,51,99,106,80,113]);describe("GetExtendedPublicKeyCommand",()=>{let x;const t={checkOnDevice:!0,derivationPath:"84'/0'/0'"};beforeEach(()=>{}),describe("name",()=>{it("should be 'getExtendedPublicKey'",()=>{x=new r(t),expect(x.name).toBe("getExtendedPublicKey")})}),describe("getApdu",()=>{it("should return the correct APDU",()=>{x=new r(t);const e=x.getApdu();expect(e.getRawApdu()).toEqual(u)}),it("should return the correct APDU without checkOnDevice",()=>{x=new r({...t,checkOnDevice:!1});const e=x.getApdu();expect(e.getRawApdu()).toEqual(i)}),it("should return the correct APDU with different derivation path",()=>{x=new r({...t,derivationPath:"49'/0'/0'/0"});const e=x.getApdu();expect(e.getRawApdu()).toEqual(p)})}),describe("parseResponse",()=>{it("should return the extended public key",()=>{x=new r(t);const e=new o({data:E,statusCode:new Uint8Array([144,0])}),n=x.parseResponse(e);expect(n).toEqual(a({data:{extendedPublicKey:"xpub6D9Pp4rFvwTGx88YD4CDa1nBEpcKEZTCNFzCF7gVPz6Th9BaVhhPJDug9YYFPYmkSHLfR1VQYj5jayqwSYARnuBJiPSDabyyTiCD7B3cjPq"}}))}),it("should return an error if the response is not successful",()=>{x=new r(t);const e=new o({statusCode:Uint8Array.from([109,0]),data:new Uint8Array(0)}),n=x.parseResponse(e);expect(n).toStrictEqual(a({error:c({...d["6d00"],errorCode:"6d00"})}))}),it("should return an error if the response is too short",()=>{x=new r(t);const e=new o({data:Uint8Array.from([]),statusCode:new Uint8Array([144,0])}),n=x.parseResponse(e);expect(n).toStrictEqual(a({error:new s("Invalid response length")}))})})});
|
|
2
2
|
//# sourceMappingURL=GetExtendedPublicKeyCommand.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/GetExtendedPublicKeyCommand.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n CommandResultFactory,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\n\nimport {\n GetExtendedPublicKeyCommand,\n type GetExtendedPublicKeyCommandArgs,\n} from \"./GetExtendedPublicKeyCommand\";\n\nconst GET_EXTENDED_PUBLIC_KEY_APDU_WITH_DISPLAY = new Uint8Array([\n 0xe1, 0x00, 0x00, 0x00, 0x0e, 0x01, 0x03, 0x80, 0x00, 0x00, 0x54, 0x80, 0x00,\n 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,\n]);\n\nconst GET_EXTENDED_PUBLIC_KEY_APDU_WITHOUT_DISPLAY = new Uint8Array([\n 0xe1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x80, 0x00, 0x00, 0x54, 0x80, 0x00,\n 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,\n]);\n\nconst GET_EXTENDED_PUBLIC_KEY_APDU_WITH_OTHER_DERIVATION_PATH = new Uint8Array([\n 0xe1, 0x00, 0x00, 0x00, 0x12, 0x01, 0x04, 0x80, 0x00, 0x00, 0x31, 0x80, 0x00,\n 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n]);\n\nconst GET_EXTENDED_PUBLIC_KEY_VALID_RESPONSE = new Uint8Array([\n 0x78, 0x70, 0x75, 0x62, 0x36, 0x44, 0x39, 0x50, 0x70, 0x34, 0x72, 0x46, 0x76,\n 0x77, 0x54, 0x47, 0x78, 0x38, 0x38, 0x59, 0x44, 0x34, 0x43, 0x44, 0x61, 0x31,\n 0x6e, 0x42, 0x45, 0x70, 0x63, 0x4b, 0x45, 0x5a, 0x54, 0x43, 0x4e, 0x46, 0x7a,\n 0x43, 0x46, 0x37, 0x67, 0x56, 0x50, 0x7a, 0x36, 0x54, 0x68, 0x39, 0x42, 0x61,\n 0x56, 0x68, 0x68, 0x50, 0x4a, 0x44, 0x75, 0x67, 0x39, 0x59, 0x59, 0x46, 0x50,\n 0x59, 0x6d, 0x6b, 0x53, 0x48, 0x4c, 0x66, 0x52, 0x31, 0x56, 0x51, 0x59, 0x6a,\n 0x35, 0x6a, 0x61, 0x79, 0x71, 0x77, 0x53, 0x59, 0x41, 0x52, 0x6e, 0x75, 0x42,\n 0x4a, 0x69, 0x50, 0x53, 0x44, 0x61, 0x62, 0x79, 0x79, 0x54, 0x69, 0x43, 0x44,\n 0x37, 0x42, 0x33, 0x63, 0x6a, 0x50, 0x71,\n]);\n\ndescribe(\"GetExtendedPublicKeyCommand\", () => {\n let command: GetExtendedPublicKeyCommand;\n const defaultArgs: GetExtendedPublicKeyCommandArgs = {\n checkOnDevice: true,\n derivationPath: \"84'/0'/0'\",\n };\n\n beforeEach(() => {});\n\n describe(\"getApdu\", () => {\n it(\"should return the correct APDU\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n\n // WHEN\n const apdu = command.getApdu();\n\n //THEN\n expect(apdu.getRawApdu()).toEqual(\n GET_EXTENDED_PUBLIC_KEY_APDU_WITH_DISPLAY,\n );\n });\n\n it(\"should return the correct APDU without checkOnDevice\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand({\n ...defaultArgs,\n checkOnDevice: false,\n });\n\n // WHEN\n const apdu = command.getApdu();\n\n //THEN\n expect(apdu.getRawApdu()).toEqual(\n GET_EXTENDED_PUBLIC_KEY_APDU_WITHOUT_DISPLAY,\n );\n });\n\n it(\"should return the correct APDU with different derivation path\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand({\n ...defaultArgs,\n derivationPath: \"49'/0'/0'/0\",\n });\n\n // WHEN\n const apdu = command.getApdu();\n\n //THEN\n expect(apdu.getRawApdu()).toEqual(\n GET_EXTENDED_PUBLIC_KEY_APDU_WITH_OTHER_DERIVATION_PATH,\n );\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"should return the extended public key\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n const response = new ApduResponse({\n data: GET_EXTENDED_PUBLIC_KEY_VALID_RESPONSE,\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toEqual(\n CommandResultFactory({\n data: {\n extendedPublicKey:\n \"xpub6D9Pp4rFvwTGx88YD4CDa1nBEpcKEZTCNFzCF7gVPz6Th9BaVhhPJDug9YYFPYmkSHLfR1VQYj5jayqwSYARnuBJiPSDabyyTiCD7B3cjPq\",\n },\n }),\n );\n });\n\n it(\"should return an error if the response is not successful\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x6d, 0x00]),\n data: new Uint8Array(0),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toStrictEqual(\n CommandResultFactory({\n error: BtcAppCommandErrorFactory({\n ...BTC_APP_ERRORS[\"6d00\"],\n errorCode: \"6d00\",\n }),\n }),\n );\n });\n\n it(\"should return an error if the response is too short\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n const response = new ApduResponse({\n data: Uint8Array.from([]),\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toStrictEqual(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Invalid response length\"),\n }),\n );\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OACE,gBAAAA,EACA,wBAAAC,EACA,0BAAAC,MACK,kCAEP,OACE,kBAAAC,EACA,6BAAAC,MACK,sDAEP,OACE,+BAAAC,MAEK,gCAEP,MAAMC,EAA4C,IAAI,WAAW,CAC/D,IAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,IAAM,EAAM,EAAM,GAAM,IAAM,EACxE,EAAM,EAAM,IAAM,EAAM,EAAM,CAChC,CAAC,EAEKC,EAA+C,IAAI,WAAW,CAClE,IAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,IAAM,EAAM,EAAM,GAAM,IAAM,EACxE,EAAM,EAAM,IAAM,EAAM,EAAM,CAChC,CAAC,EAEKC,EAA0D,IAAI,WAAW,CAC7E,IAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,IAAM,EAAM,EAAM,GAAM,IAAM,EACxE,EAAM,EAAM,IAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,EAEKC,EAAyC,IAAI,WAAW,CAC5D,IAAM,IAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GAAM,IAAM,GAAM,IAAM,GAAM,IACxE,IAAM,GAAM,GAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GACxE,IAAM,GAAM,GAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,GAAM,IACxE,GAAM,GAAM,GAAM,IAAM,GAAM,GAAM,IAAM,GAAM,GAAM,IAAM,GAAM,GAAM,GACxE,GAAM,IAAM,IAAM,GAAM,GAAM,GAAM,IAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GACxE,GAAM,IAAM,IAAM,GAAM,GAAM,GAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GAAM,IACxE,GAAM,IAAM,GAAM,IAAM,IAAM,IAAM,GAAM,GAAM,GAAM,GAAM,IAAM,IAAM,GACxE,GAAM,IAAM,GAAM,GAAM,GAAM,GAAM,GAAM,IAAM,IAAM,GAAM,IAAM,GAAM,GACxE,GAAM,GAAM,GAAM,GAAM,IAAM,GAAM,GACtC,CAAC,EAED,SAAS,8BAA+B,IAAM,CAC5C,IAAIC,EACJ,MAAMC,EAA+C,CACnD,cAAe,GACf,eAAgB,WAClB,EAEA,WAAW,IAAM,CAAC,CAAC,EAEnB,SAAS,UAAW,IAAM,CACxB,GAAG,iCAAkC,IAAM,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n CommandResultFactory,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\n\nimport {\n GetExtendedPublicKeyCommand,\n type GetExtendedPublicKeyCommandArgs,\n} from \"./GetExtendedPublicKeyCommand\";\n\nconst GET_EXTENDED_PUBLIC_KEY_APDU_WITH_DISPLAY = new Uint8Array([\n 0xe1, 0x00, 0x00, 0x00, 0x0e, 0x01, 0x03, 0x80, 0x00, 0x00, 0x54, 0x80, 0x00,\n 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,\n]);\n\nconst GET_EXTENDED_PUBLIC_KEY_APDU_WITHOUT_DISPLAY = new Uint8Array([\n 0xe1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x80, 0x00, 0x00, 0x54, 0x80, 0x00,\n 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,\n]);\n\nconst GET_EXTENDED_PUBLIC_KEY_APDU_WITH_OTHER_DERIVATION_PATH = new Uint8Array([\n 0xe1, 0x00, 0x00, 0x00, 0x12, 0x01, 0x04, 0x80, 0x00, 0x00, 0x31, 0x80, 0x00,\n 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\n]);\n\nconst GET_EXTENDED_PUBLIC_KEY_VALID_RESPONSE = new Uint8Array([\n 0x78, 0x70, 0x75, 0x62, 0x36, 0x44, 0x39, 0x50, 0x70, 0x34, 0x72, 0x46, 0x76,\n 0x77, 0x54, 0x47, 0x78, 0x38, 0x38, 0x59, 0x44, 0x34, 0x43, 0x44, 0x61, 0x31,\n 0x6e, 0x42, 0x45, 0x70, 0x63, 0x4b, 0x45, 0x5a, 0x54, 0x43, 0x4e, 0x46, 0x7a,\n 0x43, 0x46, 0x37, 0x67, 0x56, 0x50, 0x7a, 0x36, 0x54, 0x68, 0x39, 0x42, 0x61,\n 0x56, 0x68, 0x68, 0x50, 0x4a, 0x44, 0x75, 0x67, 0x39, 0x59, 0x59, 0x46, 0x50,\n 0x59, 0x6d, 0x6b, 0x53, 0x48, 0x4c, 0x66, 0x52, 0x31, 0x56, 0x51, 0x59, 0x6a,\n 0x35, 0x6a, 0x61, 0x79, 0x71, 0x77, 0x53, 0x59, 0x41, 0x52, 0x6e, 0x75, 0x42,\n 0x4a, 0x69, 0x50, 0x53, 0x44, 0x61, 0x62, 0x79, 0x79, 0x54, 0x69, 0x43, 0x44,\n 0x37, 0x42, 0x33, 0x63, 0x6a, 0x50, 0x71,\n]);\n\ndescribe(\"GetExtendedPublicKeyCommand\", () => {\n let command: GetExtendedPublicKeyCommand;\n const defaultArgs: GetExtendedPublicKeyCommandArgs = {\n checkOnDevice: true,\n derivationPath: \"84'/0'/0'\",\n };\n\n beforeEach(() => {});\n\n describe(\"name\", () => {\n it(\"should be 'getExtendedPublicKey'\", () => {\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n expect(command.name).toBe(\"getExtendedPublicKey\");\n });\n });\n\n describe(\"getApdu\", () => {\n it(\"should return the correct APDU\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n\n // WHEN\n const apdu = command.getApdu();\n\n //THEN\n expect(apdu.getRawApdu()).toEqual(\n GET_EXTENDED_PUBLIC_KEY_APDU_WITH_DISPLAY,\n );\n });\n\n it(\"should return the correct APDU without checkOnDevice\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand({\n ...defaultArgs,\n checkOnDevice: false,\n });\n\n // WHEN\n const apdu = command.getApdu();\n\n //THEN\n expect(apdu.getRawApdu()).toEqual(\n GET_EXTENDED_PUBLIC_KEY_APDU_WITHOUT_DISPLAY,\n );\n });\n\n it(\"should return the correct APDU with different derivation path\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand({\n ...defaultArgs,\n derivationPath: \"49'/0'/0'/0\",\n });\n\n // WHEN\n const apdu = command.getApdu();\n\n //THEN\n expect(apdu.getRawApdu()).toEqual(\n GET_EXTENDED_PUBLIC_KEY_APDU_WITH_OTHER_DERIVATION_PATH,\n );\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"should return the extended public key\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n const response = new ApduResponse({\n data: GET_EXTENDED_PUBLIC_KEY_VALID_RESPONSE,\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toEqual(\n CommandResultFactory({\n data: {\n extendedPublicKey:\n \"xpub6D9Pp4rFvwTGx88YD4CDa1nBEpcKEZTCNFzCF7gVPz6Th9BaVhhPJDug9YYFPYmkSHLfR1VQYj5jayqwSYARnuBJiPSDabyyTiCD7B3cjPq\",\n },\n }),\n );\n });\n\n it(\"should return an error if the response is not successful\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x6d, 0x00]),\n data: new Uint8Array(0),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toStrictEqual(\n CommandResultFactory({\n error: BtcAppCommandErrorFactory({\n ...BTC_APP_ERRORS[\"6d00\"],\n errorCode: \"6d00\",\n }),\n }),\n );\n });\n\n it(\"should return an error if the response is too short\", () => {\n // GIVEN\n command = new GetExtendedPublicKeyCommand(defaultArgs);\n const response = new ApduResponse({\n data: Uint8Array.from([]),\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toStrictEqual(\n CommandResultFactory({\n error: new InvalidStatusWordError(\"Invalid response length\"),\n }),\n );\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,gBAAAA,EACA,wBAAAC,EACA,0BAAAC,MACK,kCAEP,OACE,kBAAAC,EACA,6BAAAC,MACK,sDAEP,OACE,+BAAAC,MAEK,gCAEP,MAAMC,EAA4C,IAAI,WAAW,CAC/D,IAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,IAAM,EAAM,EAAM,GAAM,IAAM,EACxE,EAAM,EAAM,IAAM,EAAM,EAAM,CAChC,CAAC,EAEKC,EAA+C,IAAI,WAAW,CAClE,IAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,IAAM,EAAM,EAAM,GAAM,IAAM,EACxE,EAAM,EAAM,IAAM,EAAM,EAAM,CAChC,CAAC,EAEKC,EAA0D,IAAI,WAAW,CAC7E,IAAM,EAAM,EAAM,EAAM,GAAM,EAAM,EAAM,IAAM,EAAM,EAAM,GAAM,IAAM,EACxE,EAAM,EAAM,IAAM,EAAM,EAAM,EAAM,EAAM,EAAM,EAAM,CACxD,CAAC,EAEKC,EAAyC,IAAI,WAAW,CAC5D,IAAM,IAAM,IAAM,GAAM,GAAM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BAAyB,CAC7D,CAAC,CACH,CACF,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["ApduResponse", "CommandResultFactory", "InvalidStatusWordError", "BTC_APP_ERRORS", "BtcAppCommandErrorFactory", "GetExtendedPublicKeyCommand", "GET_EXTENDED_PUBLIC_KEY_APDU_WITH_DISPLAY", "GET_EXTENDED_PUBLIC_KEY_APDU_WITHOUT_DISPLAY", "GET_EXTENDED_PUBLIC_KEY_APDU_WITH_OTHER_DERIVATION_PATH", "GET_EXTENDED_PUBLIC_KEY_VALID_RESPONSE", "command", "defaultArgs", "apdu", "response", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduBuilder as
|
|
1
|
+
import{ApduBuilder as n,ApduParser as o,CommandResultFactory as t,InvalidStatusWordError as s}from"@ledgerhq/device-management-kit";import{CommandErrorHelper as p}from"@ledgerhq/signer-utils";import{Maybe as a}from"purify-ts";import{BTC_APP_ERRORS as i,BtcAppCommandErrorFactory as m}from"../../app-binder/command/utils/bitcoinAppErrors";import{BtcCommandUtils as d}from"../../utils/BtcCommandUtils";const u=4;class F{constructor(r=new p(i,m,d.isSuccessResponse)){this._errorHelper=r}name="getMasterFingerprint";getApdu(){const r={cla:225,ins:5,p1:0,p2:0};return new n(r).build()}parseResponse(r){return a.fromNullable(this._errorHelper.getError(r)).orDefaultLazy(()=>{const e=new o(r).extractFieldByLength(u);return e?t({data:{masterFingerprint:e}}):t({error:new s("Master fingerprint is missing")})})}}export{F as GetMasterFingerprintCommand};
|
|
2
2
|
//# sourceMappingURL=GetMasterFingerprintCommand.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/GetMasterFingerprintCommand.ts"],
|
|
4
|
-
"sourcesContent": ["// https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_master_fingerprint\nimport {\n type Apdu,\n ApduBuilder,\n type ApduBuilderArgs,\n ApduParser,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nconst MASTER_FINGERPRINT_LENGTH = 4;\n\ntype GetMasterFingerprintCommandResponse = {\n masterFingerprint: Uint8Array;\n};\n\nexport class GetMasterFingerprintCommand\n implements Command<GetMasterFingerprintCommandResponse, void, BtcErrorCodes>\n{\n constructor(\n private readonly _errorHelper = new CommandErrorHelper<\n GetMasterFingerprintCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n getApdu(): Apdu {\n const getMasterFingerprintArgs: ApduBuilderArgs = {\n cla: 0xe1,\n ins: 0x05,\n p1: 0x00,\n p2: 0x00,\n };\n return new ApduBuilder(getMasterFingerprintArgs).build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<GetMasterFingerprintCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(\n this._errorHelper.getError(response),\n ).orDefaultLazy(() => {\n const parser = new ApduParser(response);\n\n const masterFingerprint = parser.extractFieldByLength(\n MASTER_FINGERPRINT_LENGTH,\n );\n if (!masterFingerprint) {\n return CommandResultFactory({\n error: new InvalidStatusWordError(\"Master fingerprint is missing\"),\n });\n }\n\n return CommandResultFactory({\n data: {\n masterFingerprint,\n },\n });\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,OAEE,eAAAA,EAEA,cAAAC,EAIA,wBAAAC,EACA,0BAAAC,MACK,kCACP,OAAS,sBAAAC,MAA0B,yBACnC,OAAS,SAAAC,MAAa,YAEtB,OACE,kBAAAC,EACA,6BAAAC,MAEK,sDACP,OAAS,mBAAAC,MAAuB,kCAEhC,MAAMC,EAA4B,EAM3B,MAAMC,CAEb,
|
|
4
|
+
"sourcesContent": ["// https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_master_fingerprint\nimport {\n type Apdu,\n ApduBuilder,\n type ApduBuilderArgs,\n ApduParser,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n InvalidStatusWordError,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"@internal/app-binder/command/utils/bitcoinAppErrors\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nconst MASTER_FINGERPRINT_LENGTH = 4;\n\ntype GetMasterFingerprintCommandResponse = {\n masterFingerprint: Uint8Array;\n};\n\nexport class GetMasterFingerprintCommand\n implements Command<GetMasterFingerprintCommandResponse, void, BtcErrorCodes>\n{\n readonly name = \"getMasterFingerprint\";\n constructor(\n private readonly _errorHelper = new CommandErrorHelper<\n GetMasterFingerprintCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n getApdu(): Apdu {\n const getMasterFingerprintArgs: ApduBuilderArgs = {\n cla: 0xe1,\n ins: 0x05,\n p1: 0x00,\n p2: 0x00,\n };\n return new ApduBuilder(getMasterFingerprintArgs).build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<GetMasterFingerprintCommandResponse, BtcErrorCodes> {\n return Maybe.fromNullable(\n this._errorHelper.getError(response),\n ).orDefaultLazy(() => {\n const parser = new ApduParser(response);\n\n const masterFingerprint = parser.extractFieldByLength(\n MASTER_FINGERPRINT_LENGTH,\n );\n if (!masterFingerprint) {\n return CommandResultFactory({\n error: new InvalidStatusWordError(\"Master fingerprint is missing\"),\n });\n }\n\n return CommandResultFactory({\n data: {\n masterFingerprint,\n },\n });\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAEE,eAAAA,EAEA,cAAAC,EAIA,wBAAAC,EACA,0BAAAC,MACK,kCACP,OAAS,sBAAAC,MAA0B,yBACnC,OAAS,SAAAC,MAAa,YAEtB,OACE,kBAAAC,EACA,6BAAAC,MAEK,sDACP,OAAS,mBAAAC,MAAuB,kCAEhC,MAAMC,EAA4B,EAM3B,MAAMC,CAEb,CAEE,YACmBC,EAAe,IAAIP,EAIlCE,EACAC,EACAC,EAAgB,iBAClB,EACA,CARiB,kBAAAG,CAQhB,CAVM,KAAO,uBAWhB,SAAgB,CACd,MAAMC,EAA4C,CAChD,IAAK,IACL,IAAK,EACL,GAAI,EACJ,GAAI,CACN,EACA,OAAO,IAAIZ,EAAYY,CAAwB,EAAE,MAAM,CACzD,CAEA,cACEC,EACmE,CACnE,OAAOR,EAAM,aACX,KAAK,aAAa,SAASQ,CAAQ,CACrC,EAAE,cAAc,IAAM,CAGpB,MAAMC,EAFS,IAAIb,EAAWY,CAAQ,EAEL,qBAC/BJ,CACF,EACA,OAAKK,EAMEZ,EAAqB,CAC1B,KAAM,CACJ,kBAAAY,CACF,CACF,CAAC,EATQZ,EAAqB,CAC1B,MAAO,IAAIC,EAAuB,+BAA+B,CACnE,CAAC,CAQL,CAAC,CACH,CACF",
|
|
6
6
|
"names": ["ApduBuilder", "ApduParser", "CommandResultFactory", "InvalidStatusWordError", "CommandErrorHelper", "Maybe", "BTC_APP_ERRORS", "BtcAppCommandErrorFactory", "BtcCommandUtils", "MASTER_FINGERPRINT_LENGTH", "GetMasterFingerprintCommand", "_errorHelper", "getMasterFingerprintArgs", "response", "masterFingerprint"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduResponse as s,CommandResultFactory as a,isSuccessCommandResult as n}from"@ledgerhq/device-management-kit";import{InvalidStatusWordError as i}from"@ledgerhq/device-management-kit";import{GetMasterFingerprintCommand as p}from"./GetMasterFingerprintCommand";const c=new Uint8Array([225,5,0,0,0]),o=new Uint8Array([130,141,194,243]);describe("GetMasterFingerprintCommand",()=>{let t;beforeEach(()=>{t=new p}),describe("getApdu",()=>{it("returns the correct APDU",()=>{const e=t.getApdu();expect(e.getRawApdu()).toEqual(c)})}),describe("parseResponse",()=>{it("should return the master fingerprint",()=>{const e=new s({data:o,statusCode:new Uint8Array([144,0])}),r=t.parseResponse(e);expect(r).toEqual(a({data:{masterFingerprint:Uint8Array.from([130,141,194,243])}}))}),it("should return an error if the response is not successful",()=>{const e=new s({statusCode:Uint8Array.from([109,0]),data:new Uint8Array(0)}),r=t.parseResponse(e);expect(n(r)).toBe(!1)}),it("should return an error if the response is too short",()=>{const e=new s({data:o.slice(0,2),statusCode:new Uint8Array([144,0])}),r=t.parseResponse(e);n(r)?assert.fail("Expected an error, but the result was successful"):expect(r.error).toEqual(new i("Master fingerprint is missing"))})})});
|
|
1
|
+
import{ApduResponse as s,CommandResultFactory as a,isSuccessCommandResult as n}from"@ledgerhq/device-management-kit";import{InvalidStatusWordError as i}from"@ledgerhq/device-management-kit";import{GetMasterFingerprintCommand as p}from"./GetMasterFingerprintCommand";const c=new Uint8Array([225,5,0,0,0]),o=new Uint8Array([130,141,194,243]);describe("GetMasterFingerprintCommand",()=>{let t;beforeEach(()=>{t=new p}),describe("name",()=>{it("should be 'getMasterFingerprint'",()=>{expect(t.name).toBe("getMasterFingerprint")})}),describe("getApdu",()=>{it("returns the correct APDU",()=>{const e=t.getApdu();expect(e.getRawApdu()).toEqual(c)})}),describe("parseResponse",()=>{it("should return the master fingerprint",()=>{const e=new s({data:o,statusCode:new Uint8Array([144,0])}),r=t.parseResponse(e);expect(r).toEqual(a({data:{masterFingerprint:Uint8Array.from([130,141,194,243])}}))}),it("should return an error if the response is not successful",()=>{const e=new s({statusCode:Uint8Array.from([109,0]),data:new Uint8Array(0)}),r=t.parseResponse(e);expect(n(r)).toBe(!1)}),it("should return an error if the response is too short",()=>{const e=new s({data:o.slice(0,2),statusCode:new Uint8Array([144,0])}),r=t.parseResponse(e);n(r)?assert.fail("Expected an error, but the result was successful"):expect(r.error).toEqual(new i("Master fingerprint is missing"))})})});
|
|
2
2
|
//# sourceMappingURL=GetMasterFingerprintCommand.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/GetMasterFingerprintCommand.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n CommandResultFactory,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { InvalidStatusWordError } from \"@ledgerhq/device-management-kit\";\n\nimport { GetMasterFingerprintCommand } from \"./GetMasterFingerprintCommand\";\n\nconst GET_MASTER_FINGERPRINT_APDU = new Uint8Array([\n 0xe1, 0x05, 0x00, 0x00, 0x00,\n]);\n\nconst GET_MASTER_FINGERPRINT_RESPONSE = new Uint8Array([\n 0x82, 0x8d, 0xc2, 0xf3,\n]);\n\ndescribe(\"GetMasterFingerprintCommand\", () => {\n let command: GetMasterFingerprintCommand;\n\n beforeEach(() => {\n command = new GetMasterFingerprintCommand();\n });\n\n describe(\"getApdu\", () => {\n it(\"returns the correct APDU\", () => {\n // WHEN\n const apdu = command.getApdu();\n\n // THEN\n expect(apdu.getRawApdu()).toEqual(GET_MASTER_FINGERPRINT_APDU);\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"should return the master fingerprint\", () => {\n // GIVEN\n const response = new ApduResponse({\n data: GET_MASTER_FINGERPRINT_RESPONSE,\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toEqual(\n CommandResultFactory({\n data: {\n masterFingerprint: Uint8Array.from([0x82, 0x8d, 0xc2, 0xf3]),\n },\n }),\n );\n });\n\n it(\"should return an error if the response is not successful\", () => {\n // GIVEN\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x6d, 0x00]),\n data: new Uint8Array(0),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(isSuccessCommandResult(result)).toBe(false);\n });\n\n it(\"should return an error if the response is too short\", () => {\n // GIVEN\n const response = new ApduResponse({\n data: GET_MASTER_FINGERPRINT_RESPONSE.slice(0, 2),\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n if (!isSuccessCommandResult(result)) {\n expect(result.error).toEqual(\n new InvalidStatusWordError(\"Master fingerprint is missing\"),\n );\n } else {\n assert.fail(\"Expected an error, but the result was successful\");\n }\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "AAAA,OACE,gBAAAA,EACA,wBAAAC,EACA,0BAAAC,MACK,kCACP,OAAS,0BAAAC,MAA8B,kCAEvC,OAAS,+BAAAC,MAAmC,gCAE5C,MAAMC,EAA8B,IAAI,WAAW,CACjD,IAAM,EAAM,EAAM,EAAM,CAC1B,CAAC,EAEKC,EAAkC,IAAI,WAAW,CACrD,IAAM,IAAM,IAAM,GACpB,CAAC,EAED,SAAS,8BAA+B,IAAM,CAC5C,IAAIC,EAEJ,WAAW,IAAM,CACfA,EAAU,IAAIH,CAChB,CAAC,EAED,SAAS,UAAW,IAAM,CACxB,GAAG,2BAA4B,IAAM,CAEnC,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n CommandResultFactory,\n isSuccessCommandResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { InvalidStatusWordError } from \"@ledgerhq/device-management-kit\";\n\nimport { GetMasterFingerprintCommand } from \"./GetMasterFingerprintCommand\";\n\nconst GET_MASTER_FINGERPRINT_APDU = new Uint8Array([\n 0xe1, 0x05, 0x00, 0x00, 0x00,\n]);\n\nconst GET_MASTER_FINGERPRINT_RESPONSE = new Uint8Array([\n 0x82, 0x8d, 0xc2, 0xf3,\n]);\n\ndescribe(\"GetMasterFingerprintCommand\", () => {\n let command: GetMasterFingerprintCommand;\n\n beforeEach(() => {\n command = new GetMasterFingerprintCommand();\n });\n\n describe(\"name\", () => {\n it(\"should be 'getMasterFingerprint'\", () => {\n expect(command.name).toBe(\"getMasterFingerprint\");\n });\n });\n\n describe(\"getApdu\", () => {\n it(\"returns the correct APDU\", () => {\n // WHEN\n const apdu = command.getApdu();\n\n // THEN\n expect(apdu.getRawApdu()).toEqual(GET_MASTER_FINGERPRINT_APDU);\n });\n });\n\n describe(\"parseResponse\", () => {\n it(\"should return the master fingerprint\", () => {\n // GIVEN\n const response = new ApduResponse({\n data: GET_MASTER_FINGERPRINT_RESPONSE,\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(result).toEqual(\n CommandResultFactory({\n data: {\n masterFingerprint: Uint8Array.from([0x82, 0x8d, 0xc2, 0xf3]),\n },\n }),\n );\n });\n\n it(\"should return an error if the response is not successful\", () => {\n // GIVEN\n const response = new ApduResponse({\n statusCode: Uint8Array.from([0x6d, 0x00]),\n data: new Uint8Array(0),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n expect(isSuccessCommandResult(result)).toBe(false);\n });\n\n it(\"should return an error if the response is too short\", () => {\n // GIVEN\n const response = new ApduResponse({\n data: GET_MASTER_FINGERPRINT_RESPONSE.slice(0, 2),\n statusCode: new Uint8Array([0x90, 0x00]),\n });\n\n // WHEN\n const result = command.parseResponse(response);\n\n // THEN\n if (!isSuccessCommandResult(result)) {\n expect(result.error).toEqual(\n new InvalidStatusWordError(\"Master fingerprint is missing\"),\n );\n } else {\n assert.fail(\"Expected an error, but the result was successful\");\n }\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OACE,gBAAAA,EACA,wBAAAC,EACA,0BAAAC,MACK,kCACP,OAAS,0BAAAC,MAA8B,k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C,EAChD,WAAY,IAAI,WAAW,CAAC,IAAM,CAAI,CAAC,CACzC,CAAC,EAGKI,EAASH,EAAQ,cAAcE,CAAQ,EAGxCP,EAAuBQ,CAAM,EAKhC,OAAO,KAAK,kDAAkD,EAJ9D,OAAOA,EAAO,KAAK,EAAE,QACnB,IAAIP,EAAuB,+BAA+B,CAC5D,CAIJ,CAAC,CACH,CAAC,CACH,CAAC",
|
|
6
6
|
"names": ["ApduResponse", "CommandResultFactory", "isSuccessCommandResult", "InvalidStatusWordError", "GetMasterFingerprintCommand", "GET_MASTER_FINGERPRINT_APDU", "GET_MASTER_FINGERPRINT_RESPONSE", "command", "apdu", "response", "result"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduBuilder as r,CommandResultFactory as a}from"@ledgerhq/device-management-kit";import{CommandErrorHelper as o}from"@ledgerhq/signer-utils";import{Maybe as t}from"purify-ts";import{PROTOCOL_VERSION as d}from"../../app-binder/command/utils/constants";import{BtcCommandUtils as s}from"../../utils/BtcCommandUtils";import{BTC_APP_ERRORS as n,BtcAppCommandErrorFactory as m}from"./utils/bitcoinAppErrors";class f{constructor(e,p=new o(n,m,s.isSuccessResponse)){this.args=e;this._errorHelper=p}getApdu(){return new r({cla:225,ins:3,p1:0,p2:d}).addBufferToData(Uint8Array.from([this.args.checkOnDevice?1:0])).addBufferToData(this.args.walletId).addBufferToData(this.args.walletHmac).addBufferToData(Uint8Array.from([this.args.change?1:0])).add32BitUIntToData(this.args.addressIndex).build()}parseResponse(e){return t.fromNullable(this._errorHelper.getError(e)).orDefault(a({data:e}))}}export{f as GetWalletAddressCommand};
|
|
1
|
+
import{ApduBuilder as r,CommandResultFactory as a}from"@ledgerhq/device-management-kit";import{CommandErrorHelper as o}from"@ledgerhq/signer-utils";import{Maybe as t}from"purify-ts";import{PROTOCOL_VERSION as d}from"../../app-binder/command/utils/constants";import{BtcCommandUtils as s}from"../../utils/BtcCommandUtils";import{BTC_APP_ERRORS as n,BtcAppCommandErrorFactory as m}from"./utils/bitcoinAppErrors";class f{constructor(e,p=new o(n,m,s.isSuccessResponse)){this.args=e;this._errorHelper=p}name="getWalletAddress";getApdu(){return new r({cla:225,ins:3,p1:0,p2:d}).addBufferToData(Uint8Array.from([this.args.checkOnDevice?1:0])).addBufferToData(this.args.walletId).addBufferToData(this.args.walletHmac).addBufferToData(Uint8Array.from([this.args.change?1:0])).add32BitUIntToData(this.args.addressIndex).build()}parseResponse(e){return t.fromNullable(this._errorHelper.getError(e)).orDefault(a({data:e}))}}export{f as GetWalletAddressCommand};
|
|
2
2
|
//# sourceMappingURL=GetWalletAddressCommand.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/internal/app-binder/command/GetWalletAddressCommand.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport { PROTOCOL_VERSION } from \"@internal/app-binder/command/utils/constants\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"./utils/bitcoinAppErrors\";\n\nexport type GetWalletAddressCommandResponse = ApduResponse;\n\nexport type GetWalletAddressCommandArgs = {\n readonly checkOnDevice: boolean;\n readonly walletId: Uint8Array;\n readonly walletHmac: Uint8Array;\n readonly change: boolean;\n readonly addressIndex: number;\n};\n\nexport class GetWalletAddressCommand\n implements\n Command<\n GetWalletAddressCommandResponse,\n GetWalletAddressCommandArgs,\n BtcErrorCodes\n >\n{\n constructor(\n private readonly args: GetWalletAddressCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n GetWalletAddressCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n return new ApduBuilder({\n cla: 0xe1,\n ins: 0x03,\n p1: 0x00,\n p2: PROTOCOL_VERSION,\n })\n .addBufferToData(Uint8Array.from([this.args.checkOnDevice ? 1 : 0]))\n .addBufferToData(this.args.walletId)\n .addBufferToData(this.args.walletHmac)\n .addBufferToData(Uint8Array.from([this.args.change ? 1 : 0]))\n .add32BitUIntToData(this.args.addressIndex)\n .build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<ApduResponse, BtcErrorCodes> {\n return Maybe.fromNullable(this._errorHelper.getError(response)).orDefault(\n CommandResultFactory({ data: response }),\n );\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAEE,eAAAA,EAIA,wBAAAC,MACK,kCACP,OAAS,sBAAAC,MAA0B,yBACnC,OAAS,SAAAC,MAAa,YAEtB,OAAS,oBAAAC,MAAwB,+CACjC,OAAS,mBAAAC,MAAuB,kCAEhC,OACE,kBAAAC,EACA,6BAAAC,MAEK,2BAYA,MAAMC,CAOb,
|
|
4
|
+
"sourcesContent": ["import {\n type Apdu,\n ApduBuilder,\n type ApduResponse,\n type Command,\n type CommandResult,\n CommandResultFactory,\n} from \"@ledgerhq/device-management-kit\";\nimport { CommandErrorHelper } from \"@ledgerhq/signer-utils\";\nimport { Maybe } from \"purify-ts\";\n\nimport { PROTOCOL_VERSION } from \"@internal/app-binder/command/utils/constants\";\nimport { BtcCommandUtils } from \"@internal/utils/BtcCommandUtils\";\n\nimport {\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n type BtcErrorCodes,\n} from \"./utils/bitcoinAppErrors\";\n\nexport type GetWalletAddressCommandResponse = ApduResponse;\n\nexport type GetWalletAddressCommandArgs = {\n readonly checkOnDevice: boolean;\n readonly walletId: Uint8Array;\n readonly walletHmac: Uint8Array;\n readonly change: boolean;\n readonly addressIndex: number;\n};\n\nexport class GetWalletAddressCommand\n implements\n Command<\n GetWalletAddressCommandResponse,\n GetWalletAddressCommandArgs,\n BtcErrorCodes\n >\n{\n readonly name = \"getWalletAddress\";\n constructor(\n private readonly args: GetWalletAddressCommandArgs,\n private readonly _errorHelper = new CommandErrorHelper<\n GetWalletAddressCommandResponse,\n BtcErrorCodes\n >(\n BTC_APP_ERRORS,\n BtcAppCommandErrorFactory,\n BtcCommandUtils.isSuccessResponse,\n ),\n ) {}\n\n getApdu(): Apdu {\n return new ApduBuilder({\n cla: 0xe1,\n ins: 0x03,\n p1: 0x00,\n p2: PROTOCOL_VERSION,\n })\n .addBufferToData(Uint8Array.from([this.args.checkOnDevice ? 1 : 0]))\n .addBufferToData(this.args.walletId)\n .addBufferToData(this.args.walletHmac)\n .addBufferToData(Uint8Array.from([this.args.change ? 1 : 0]))\n .add32BitUIntToData(this.args.addressIndex)\n .build();\n }\n\n parseResponse(\n response: ApduResponse,\n ): CommandResult<ApduResponse, BtcErrorCodes> {\n return Maybe.fromNullable(this._errorHelper.getError(response)).orDefault(\n CommandResultFactory({ data: response }),\n );\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAEE,eAAAA,EAIA,wBAAAC,MACK,kCACP,OAAS,sBAAAC,MAA0B,yBACnC,OAAS,SAAAC,MAAa,YAEtB,OAAS,oBAAAC,MAAwB,+CACjC,OAAS,mBAAAC,MAAuB,kCAEhC,OACE,kBAAAC,EACA,6BAAAC,MAEK,2BAYA,MAAMC,CAOb,CAEE,YACmBC,EACAC,EAAe,IAAIR,EAIlCI,EACAC,EACAF,EAAgB,iBAClB,EACA,CATiB,UAAAI,EACA,kBAAAC,CAQhB,CAXM,KAAO,mBAahB,SAAgB,CACd,OAAO,IAAIV,EAAY,CACrB,IAAK,IACL,IAAK,EACL,GAAI,EACJ,GAAII,CACN,CAAC,EACE,gBAAgB,WAAW,KAAK,CAAC,KAAK,KAAK,cAAgB,EAAI,CAAC,CAAC,CAAC,EAClE,gBAAgB,KAAK,KAAK,QAAQ,EAClC,gBAAgB,KAAK,KAAK,UAAU,EACpC,gBAAgB,WAAW,KAAK,CAAC,KAAK,KAAK,OAAS,EAAI,CAAC,CAAC,CAAC,EAC3D,mBAAmB,KAAK,KAAK,YAAY,EACzC,MAAM,CACX,CAEA,cACEO,EAC4C,CAC5C,OAAOR,EAAM,aAAa,KAAK,aAAa,SAASQ,CAAQ,CAAC,EAAE,UAC9DV,EAAqB,CAAE,KAAMU,CAAS,CAAC,CACzC,CACF,CACF",
|
|
6
6
|
"names": ["ApduBuilder", "CommandResultFactory", "CommandErrorHelper", "Maybe", "PROTOCOL_VERSION", "BtcCommandUtils", "BTC_APP_ERRORS", "BtcAppCommandErrorFactory", "GetWalletAddressCommand", "args", "_errorHelper", "response"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{ApduResponse as o,CommandResultFactory as n,isSuccessCommandResult as d}from"@ledgerhq/device-management-kit";import{SW_INTERRUPTED_EXECUTION as A}from"./utils/constants";import{GetWalletAddressCommand as c}from"./GetWalletAddressCommand";const
|
|
1
|
+
import{ApduResponse as o,CommandResultFactory as n,isSuccessCommandResult as d}from"@ledgerhq/device-management-kit";import{SW_INTERRUPTED_EXECUTION as A}from"./utils/constants";import{GetWalletAddressCommand as c}from"./GetWalletAddressCommand";const i=new Uint8Array([144,0]),m=new Uint8Array([105,133]);describe("GetWalletAddressCommand",()=>{let s;const l={checkOnDevice:!0,walletId:Uint8Array.from("walletIdBuffer",e=>e.charCodeAt(0)),walletHmac:Uint8Array.from("walletHmacBuffer",e=>e.charCodeAt(0)),change:!1,addressIndex:0};beforeEach(()=>{s=new c(l),vi.clearAllMocks(),vi.importActual("@ledgerhq/device-management-kit")}),describe("name",()=>{it("should be 'getWalletAddress'",()=>{expect(s.name).toBe("getWalletAddress")})}),describe("getApdu",()=>{it("should return correct APDU for default arguments",()=>{const e=s.getApdu(),t=Uint8Array.from([225,3,0,1,36,1,...Uint8Array.from("walletIdBuffer",r=>r.charCodeAt(0)),...Uint8Array.from("walletHmacBuffer",r=>r.charCodeAt(0)),0,0,0,0,0]);expect(e.getRawApdu()).toEqual(t)}),it("should return correct APDU for different arguments",()=>{const e={checkOnDevice:!1,walletId:Uint8Array.from("anotherWalletId",a=>a.charCodeAt(0)),walletHmac:Uint8Array.from("anotherWalletHmac",a=>a.charCodeAt(0)),change:!0,addressIndex:5};s=new c(e);const t=s.getApdu(),r=Uint8Array.from([225,3,0,1,38,0,...Uint8Array.from("anotherWalletId",a=>a.charCodeAt(0)),...Uint8Array.from("anotherWalletHmac",a=>a.charCodeAt(0)),1,0,0,0,5]);expect(t.getRawApdu()).toEqual(r)})}),describe("parseResponse",()=>{it("should return the APDU response if it's a continue response",()=>{const e=new Uint8Array([1,2,3,4]),t=new o({statusCode:A,data:e}),r=s.parseResponse(t);expect(r).toStrictEqual(n({data:t}))}),it("should return an error if user denied the operation",()=>{const e=new o({statusCode:m,data:new Uint8Array([])}),t=s.parseResponse(e);expect(d(t)).toBe(!1),d(t)||expect(t.error).toBeDefined()}),it("should return correct data when response is not empty",()=>{const e=Uint8Array.from("addressData",a=>a.charCodeAt(0)),t=new o({statusCode:i,data:e}),r=s.parseResponse(t);expect(r).toStrictEqual(n({data:t}))})})});
|
|
2
2
|
//# sourceMappingURL=GetWalletAddressCommand.test.js.map
|