@ledgerhq/coin-bitcoin 0.29.0-nightly.20260115024415 → 0.29.0-nightly.20260116124336

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/CHANGELOG.md +12 -10
  2. package/lib/bridge/js.d.ts +1 -1
  3. package/lib/bridge/js.d.ts.map +1 -1
  4. package/lib/bridge/js.js +2 -3
  5. package/lib/bridge/js.js.map +1 -1
  6. package/lib/buildOptimisticOperation.d.ts +13 -0
  7. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  8. package/lib/buildOptimisticOperation.js +20 -0
  9. package/lib/buildOptimisticOperation.js.map +1 -0
  10. package/lib/explorer.d.ts.map +1 -1
  11. package/lib/explorer.js +0 -7
  12. package/lib/explorer.js.map +1 -1
  13. package/lib/observable.d.ts +4 -0
  14. package/lib/observable.d.ts.map +1 -0
  15. package/lib/observable.js +9 -0
  16. package/lib/observable.js.map +1 -0
  17. package/lib/psbtFees.d.ts +9 -0
  18. package/lib/psbtFees.d.ts.map +1 -0
  19. package/lib/psbtFees.js +73 -0
  20. package/lib/psbtFees.js.map +1 -0
  21. package/lib/signOperation.d.ts.map +1 -1
  22. package/lib/signOperation.js +94 -99
  23. package/lib/signOperation.js.map +1 -1
  24. package/lib/signRawOperation.d.ts +6 -0
  25. package/lib/signRawOperation.d.ts.map +1 -0
  26. package/lib/signRawOperation.js +70 -0
  27. package/lib/signRawOperation.js.map +1 -0
  28. package/lib/signer.d.ts +15 -0
  29. package/lib/signer.d.ts.map +1 -1
  30. package/lib/types.d.ts +2 -0
  31. package/lib/types.d.ts.map +1 -1
  32. package/lib-es/bridge/js.d.ts +1 -1
  33. package/lib-es/bridge/js.d.ts.map +1 -1
  34. package/lib-es/bridge/js.js +2 -3
  35. package/lib-es/bridge/js.js.map +1 -1
  36. package/lib-es/buildOptimisticOperation.d.ts +13 -0
  37. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  38. package/lib-es/buildOptimisticOperation.js +16 -0
  39. package/lib-es/buildOptimisticOperation.js.map +1 -0
  40. package/lib-es/explorer.d.ts.map +1 -1
  41. package/lib-es/explorer.js +0 -7
  42. package/lib-es/explorer.js.map +1 -1
  43. package/lib-es/observable.d.ts +4 -0
  44. package/lib-es/observable.d.ts.map +1 -0
  45. package/lib-es/observable.js +5 -0
  46. package/lib-es/observable.js.map +1 -0
  47. package/lib-es/psbtFees.d.ts +9 -0
  48. package/lib-es/psbtFees.d.ts.map +1 -0
  49. package/lib-es/psbtFees.js +69 -0
  50. package/lib-es/psbtFees.js.map +1 -0
  51. package/lib-es/signOperation.d.ts.map +1 -1
  52. package/lib-es/signOperation.js +94 -99
  53. package/lib-es/signOperation.js.map +1 -1
  54. package/lib-es/signRawOperation.d.ts +6 -0
  55. package/lib-es/signRawOperation.d.ts.map +1 -0
  56. package/lib-es/signRawOperation.js +66 -0
  57. package/lib-es/signRawOperation.js.map +1 -0
  58. package/lib-es/signer.d.ts +15 -0
  59. package/lib-es/signer.d.ts.map +1 -1
  60. package/lib-es/types.d.ts +2 -0
  61. package/lib-es/types.d.ts.map +1 -1
  62. package/package.json +13 -12
  63. package/src/__tests__/fixtures/common.fixtures.ts +6 -0
  64. package/src/__tests__/unit/psbtFees.fromFixture.unit.test.ts +31 -0
  65. package/src/__tests__/unit/signOperation.test.ts +226 -0
  66. package/src/__tests__/unit/signRawOperation.test.ts +188 -0
  67. package/src/bridge/js.test.ts +30 -0
  68. package/src/bridge/js.ts +2 -3
  69. package/src/buildOptimisticOperation.ts +34 -0
  70. package/src/explorer.ts +0 -8
  71. package/src/hw-signMessage.test.ts +1 -0
  72. package/src/observable.ts +12 -0
  73. package/src/observable.unit.test.ts +27 -0
  74. package/src/psbtFees.ts +77 -0
  75. package/src/signOperation.ts +140 -126
  76. package/src/signRawOperation.ts +104 -0
  77. package/src/signer.ts +13 -0
  78. package/src/types.ts +2 -0
  79. package/src/wallet-btc/__tests__/fixtures/common.fixtures.ts +64 -1
  80. package/src/wallet-btc/__tests__/wallet.integration.test.ts +1 -1
  81. package/src/wallet-btc/__tests__/xpub.txs.dogecoin.integration.test.ts +1 -1
  82. package/src/wallet-btc/__tests__/xpub.txs.zcash.integration.test.ts +1 -1
  83. package/tsconfig.json +3 -12
  84. package/lib/descriptor.d.ts +0 -19
  85. package/lib/descriptor.d.ts.map +0 -1
  86. package/lib/descriptor.js +0 -127
  87. package/lib/descriptor.js.map +0 -1
  88. package/lib/mockBtcSigner.d.ts +0 -20
  89. package/lib/mockBtcSigner.d.ts.map +0 -1
  90. package/lib/mockBtcSigner.js +0 -50
  91. package/lib/mockBtcSigner.js.map +0 -1
  92. package/lib-es/descriptor.d.ts +0 -19
  93. package/lib-es/descriptor.d.ts.map +0 -1
  94. package/lib-es/descriptor.js +0 -118
  95. package/lib-es/descriptor.js.map +0 -1
  96. package/lib-es/mockBtcSigner.d.ts +0 -20
  97. package/lib-es/mockBtcSigner.d.ts.map +0 -1
  98. package/lib-es/mockBtcSigner.js +0 -45
  99. package/lib-es/mockBtcSigner.js.map +0 -1
  100. package/src/descriptor.test.ts +0 -76
  101. package/src/descriptor.ts +0 -204
  102. package/src/mockBtcSigner.ts +0 -65
@@ -5,7 +5,7 @@ import BitcoinLikeExplorer from "../explorer";
5
5
  import BitcoinLikeStorage from "../storage";
6
6
  import { Merge } from "../pickingstrategies/Merge";
7
7
  import BitcoinLikeWallet from "../wallet";
8
- import MockBtcSigner from "../../mockBtcSigner";
8
+ import { MockBtcSigner } from "./fixtures/common.fixtures";
9
9
  import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets";
10
10
  import ZCash from "../crypto/zec";
11
11
 
package/tsconfig.json CHANGED
@@ -4,19 +4,10 @@
4
4
  "declaration": true,
5
5
  "declarationMap": true,
6
6
  "downlevelIteration": true,
7
- "lib": [
8
- "es2020",
9
- "dom"
10
- ],
7
+ "lib": ["es2021", "dom"],
11
8
  "outDir": "lib",
12
9
  "exactOptionalPropertyTypes": true,
13
- "typeRoots": [
14
- "./types",
15
- "./node_modules/@types"
16
- ]
10
+ "typeRoots": ["./types", "./node_modules/@types"]
17
11
  },
18
- "include": [
19
- "src/**/*",
20
- "types.d.ts"
21
- ]
12
+ "include": ["src/**/*", "types.d.ts"]
22
13
  }
@@ -1,19 +0,0 @@
1
- import { Observable } from "rxjs";
2
- import type { Result } from "@ledgerhq/coin-framework/derivation";
3
- import type { Account, DerivationMode } from "@ledgerhq/types-live";
4
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
5
- import { SignerContext } from "./signer";
6
- export type AccountDescriptor = {
7
- internal: string;
8
- external: string;
9
- };
10
- export declare function inferDescriptorFromAccount(account: Account): AccountDescriptor | null | undefined;
11
- export declare function inferDescriptorFromDeviceInfo({ derivationMode, currency, index, parentDerivation, accountDerivation, }: {
12
- derivationMode: DerivationMode;
13
- currency: CryptoCurrency;
14
- index: number;
15
- parentDerivation: Result;
16
- accountDerivation: Result;
17
- }): AccountDescriptor | null | undefined;
18
- export declare function scanDescriptors(deviceId: string, currency: CryptoCurrency, signerContext: SignerContext, limit?: number): Observable<AccountDescriptor>;
19
- //# sourceMappingURL=descriptor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../src/descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,MAAM,CAAC;AAInD,OAAO,KAAK,EAGV,MAAM,EACP,MAAM,qCAAqC,CAAC;AAS7C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA2CF,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAYjG;AAwCD,wBAAgB,6BAA6B,CAAC,EAC5C,cAAc,EACd,QAAQ,EACR,KAAK,EACL,gBAAgB,EAChB,iBAAiB,GAClB,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,GAAG,iBAAiB,GAAG,IAAI,GAAG,SAAS,CA6BvC;AACD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,cAAc,EACxB,aAAa,EAAE,aAAa,EAC5B,KAAK,SAAK,GACT,UAAU,CAAC,iBAAiB,CAAC,CAoC/B"}
package/lib/descriptor.js DELETED
@@ -1,127 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.scanDescriptors = exports.inferDescriptorFromDeviceInfo = exports.inferDescriptorFromAccount = void 0;
7
- const rxjs_1 = require("rxjs");
8
- const operators_1 = require("rxjs/operators");
9
- const invariant_1 = __importDefault(require("invariant"));
10
- const bs58_1 = __importDefault(require("bs58"));
11
- const crypto_util_1 = require("./crypto-util");
12
- const derivation_1 = require("@ledgerhq/coin-framework/derivation");
13
- const hw_getAddress_1 = __importDefault(require("./hw-getAddress"));
14
- const index_1 = require("@ledgerhq/coin-framework/account/index");
15
- const perDerivation = {
16
- "": fragment => `pkh(${fragment})`,
17
- segwit: fragment => `sh(wpkh(${fragment}))`,
18
- native_segwit: fragment => `wpkh(${fragment})`,
19
- taproot: fragment => `tr(${fragment})`,
20
- };
21
- function makeFingerprint(compressedPubKey) {
22
- return (0, crypto_util_1.hash160)(compressedPubKey).slice(0, 4);
23
- }
24
- function makeDescriptor({ currency, index, derivationMode, fingerprint, xpub, }) {
25
- const tmpl = perDerivation[derivationMode];
26
- if (!tmpl || !xpub)
27
- return;
28
- const keyOrigin = fingerprint.toString("hex");
29
- const scheme = (0, derivation_1.getDerivationScheme)({
30
- currency,
31
- derivationMode,
32
- });
33
- const accountPath = (0, derivation_1.runAccountDerivationScheme)(scheme, currency, {
34
- account: index,
35
- });
36
- return {
37
- external: tmpl(`[${keyOrigin}/${accountPath}]${xpub}/0/*`),
38
- internal: tmpl(`[${keyOrigin}/${accountPath}]${xpub}/1/*`),
39
- };
40
- }
41
- function inferDescriptorFromAccount(account) {
42
- if (account.currency.family !== "bitcoin")
43
- return;
44
- const { id, derivationMode, seedIdentifier, currency, index } = account;
45
- const xpub = (0, index_1.decodeAccountId)(id).xpubOrAddress;
46
- const fingerprint = makeFingerprint(compressPublicKeySECP256(Buffer.from(seedIdentifier, "hex")));
47
- return makeDescriptor({
48
- derivationMode,
49
- currency,
50
- fingerprint,
51
- xpub,
52
- index,
53
- });
54
- }
55
- exports.inferDescriptorFromAccount = inferDescriptorFromAccount;
56
- function asBufferUInt32BE(n) {
57
- const buf = Buffer.allocUnsafe(4);
58
- buf.writeUInt32BE(n, 0);
59
- return buf;
60
- }
61
- const compressPublicKeySECP256 = (publicKey) => Buffer.concat([Buffer.from([0x02 + (publicKey[64] & 0x01)]), publicKey.slice(1, 33)]);
62
- function makeXpub({ version, depth, parentFingerprint, index, chainCode, pubKey, }) {
63
- const indexBuffer = asBufferUInt32BE(index);
64
- indexBuffer[0] |= 0x80;
65
- const extendedKeyBytes = Buffer.concat([
66
- asBufferUInt32BE(version),
67
- Buffer.from([depth]),
68
- parentFingerprint,
69
- indexBuffer,
70
- chainCode,
71
- pubKey,
72
- ]);
73
- const checksum = (0, crypto_util_1.hash256)(extendedKeyBytes).slice(0, 4);
74
- return bs58_1.default.encode(Buffer.concat([extendedKeyBytes, checksum]));
75
- }
76
- function inferDescriptorFromDeviceInfo({ derivationMode, currency, index, parentDerivation, accountDerivation, }) {
77
- (0, invariant_1.default)(currency.bitcoinLikeInfo, "bitcoin currency expected");
78
- const { bitcoinLikeInfo } = currency;
79
- const { XPUBVersion } = bitcoinLikeInfo;
80
- (0, invariant_1.default)(XPUBVersion, "unsupported bitcoin fork %s", currency.id);
81
- const { chainCode } = accountDerivation;
82
- (0, invariant_1.default)(chainCode, "chainCode is required");
83
- const fingerprint = makeFingerprint(compressPublicKeySECP256(Buffer.from(parentDerivation.publicKey, "hex")));
84
- const xpub = makeXpub({
85
- version: XPUBVersion,
86
- depth: 3,
87
- parentFingerprint: fingerprint,
88
- index,
89
- chainCode: Buffer.from(chainCode, "hex"),
90
- pubKey: compressPublicKeySECP256(Buffer.from(accountDerivation.publicKey, "hex")),
91
- });
92
- return makeDescriptor({
93
- derivationMode,
94
- currency,
95
- fingerprint,
96
- xpub,
97
- index,
98
- });
99
- }
100
- exports.inferDescriptorFromDeviceInfo = inferDescriptorFromDeviceInfo;
101
- function scanDescriptors(deviceId, currency, signerContext, limit = 10) {
102
- const derivateAddress = (opts) => (0, rxjs_1.from)((0, hw_getAddress_1.default)(signerContext)(deviceId, opts));
103
- function stepAddress({ index, accountDerivation, parentDerivation, derivationMode, }) {
104
- const result = inferDescriptorFromDeviceInfo({
105
- derivationMode,
106
- currency,
107
- index,
108
- parentDerivation,
109
- accountDerivation,
110
- });
111
- return !result
112
- ? rxjs_1.EMPTY
113
- : (0, rxjs_1.of)({
114
- result,
115
- complete: index >= limit,
116
- });
117
- }
118
- return (0, rxjs_1.from)((0, derivation_1.getDerivationModesForCurrency)(currency)).pipe((0, operators_1.concatMap)(derivationMode => (0, derivation_1.walletDerivation)({
119
- currency,
120
- derivationMode,
121
- derivateAddress,
122
- stepAddress,
123
- shouldDerivesOnAccount: true,
124
- })));
125
- }
126
- exports.scanDescriptors = scanDescriptors;
127
- //# sourceMappingURL=descriptor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../src/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AE,KAAK,CAAC,CAAC;KAClF,CAAC,CAAC;IACH,OAAO,cAAc,CAAC;QACpB,cAAc;QACd,QAAQ;QACR,WAAW;QACX,IAAI;QACJ,KAAK;KACN,CAAC,CAAC;AACL,CAAC;AAzCD,sEAyCC;AACD,SAAgB,eAAe,CAC7B,QAAgB,EAChB,QAAwB,EACxB,aAA4B,EAC5B,KAAK,GAAG,EAAE;IAEV,MAAM,eAAe,GAAG,CAAC,IAAuB,EAAE,EAAE,CAClD,IAAA,WAAI,EAAC,IAAA,uBAAU,EAAC,aAAa,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC;IAElD,SAAS,WAAW,CAAC,EACnB,KAAK,EACL,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACG;QACjB,MAAM,MAAM,GAAG,6BAA6B,CAAC;YAC3C,cAAc;YACd,QAAQ;YACR,KAAK;YACL,gBAAgB;YAChB,iBAAiB;SAClB,CAAC,CAAC;QACH,OAAO,CAAC,MAAM;YACZ,CAAC,CAAC,YAAK;YACP,CAAC,CAAC,IAAA,SAAE,EAAC;gBACD,MAAM;gBACN,QAAQ,EAAE,KAAK,IAAI,KAAK;aACzB,CAAC,CAAC;IACT,CAAC;IAED,OAAO,IAAA,WAAI,EAAC,IAAA,0CAA6B,EAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CACvD,IAAA,qBAAS,EAAC,cAAc,CAAC,EAAE,CACzB,IAAA,6BAAgB,EAAC;QACf,QAAQ;QACR,cAAc;QACd,eAAe;QACf,WAAW;QACX,sBAAsB,EAAE,IAAI;KAC7B,CAAC,CACH,CACF,CAAC;AACJ,CAAC;AAzCD,0CAyCC"}
@@ -1,20 +0,0 @@
1
- import type { AddressFormat, BitcoinSignature, BitcoinSigner, BitcoinXPub, CreateTransaction, SignerTransaction } from "./signer";
2
- declare class MockBtcSigner implements BitcoinSigner {
3
- getWalletPublicKey(path: string, _opts: {
4
- verify?: boolean;
5
- format?: AddressFormat;
6
- }): Promise<{
7
- publicKey: string;
8
- chainCode: string;
9
- bitcoinAddress: string;
10
- }>;
11
- createPaymentTransaction(arg: CreateTransaction): Promise<string>;
12
- getWalletXpub(_arg: {
13
- path: string;
14
- xpubVersion: number;
15
- }): Promise<BitcoinXPub>;
16
- signMessage(_path: string, _messageHex: string): Promise<BitcoinSignature>;
17
- splitTransaction(_transactionHex: string, _isSegwitSupported: boolean | null | undefined, _hasExtraData: boolean | null | undefined, _additionals: Array<string> | null | undefined): SignerTransaction;
18
- }
19
- export default MockBtcSigner;
20
- //# sourceMappingURL=mockBtcSigner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockBtcSigner.d.ts","sourceRoot":"","sources":["../src/mockBtcSigner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,cAAM,aAAc,YAAW,aAAa;IAEpC,kBAAkB,CACtB,IAAI,EAAE,MAAM,EAEZ,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,aAAa,CAAA;KAAE;;;;;IAwB/C,wBAAwB,CAAC,GAAG,EAAE,iBAAiB;IAIrD,aAAa,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAGhF,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAG1E,gBAAgB,CACd,eAAe,EAAE,MAAM,EACvB,kBAAkB,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EAC9C,aAAa,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACzC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GAC7C,iBAAiB;CAQrB;AAED,eAAe,aAAa,CAAC"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const object_hash_1 = __importDefault(require("object-hash"));
7
- class MockBtcSigner {
8
- // eslint-disable-next-line class-methods-use-this
9
- async getWalletPublicKey(path,
10
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
- _opts) {
12
- switch (path) {
13
- case "44'/0'":
14
- return {
15
- publicKey: "04c621f37493d99f39ca12fb02ba7fe1687b1650b875dcb6733f386a98958e6556fc95dcecb6ac41af0a5296965751b1598aa475a537474bab5b316fcdc1196568",
16
- chainCode: "a45d311c31a80bf06cc38d8ed7934bd1e8a7b2d48b2868a70258a86e094bacfb",
17
- bitcoinAddress: "1BKWjmA9swxRKMH9NgXpSz8YZfVMnWWU9D",
18
- };
19
- break;
20
- case "44'/0'/0'":
21
- return {
22
- publicKey: "04d52d1ad9311c5a3d542fa652fbd7d7b0be70109e329d359704d9f2946f8eb52a829c23f8b980c5f7b6c51bf446b21f3dc80c865095243c9215dbf9f3cb6403b8",
23
- chainCode: "0bd3e45edca4d8a466f523a2c4094c412d25c36d5298b2d3a29938151a8d37fe",
24
- bitcoinAddress: "1FHa4cuKdea21ByTngP9vz3KYDqqQe9SsA",
25
- };
26
- break;
27
- default:
28
- throw new Error("not supported");
29
- }
30
- }
31
- async createPaymentTransaction(arg) {
32
- return (0, object_hash_1.default)(arg);
33
- }
34
- getWalletXpub(_arg) {
35
- return Promise.reject();
36
- }
37
- signMessage(_path, _messageHex) {
38
- return Promise.reject();
39
- }
40
- splitTransaction(_transactionHex, _isSegwitSupported, _hasExtraData, _additionals) {
41
- // Stub
42
- return {
43
- version: Buffer.from(""),
44
- inputs: [],
45
- outputs: [],
46
- };
47
- }
48
- }
49
- exports.default = MockBtcSigner;
50
- //# sourceMappingURL=mockBtcSigner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockBtcSigner.js","sourceRoot":"","sources":["../src/mockBtcSigner.ts"],"names":[],"mappings":";;;;;AAAA,8DAA+B;AAU/B,MAAM,aAAa;IACjB,kDAAkD;IAClD,KAAK,CAAC,kBAAkB,CACtB,IAAY;IACZ,6DAA6D;IAC7D,KAAmD;QAEnD,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,QAAQ;gBACX,OAAO;oBACL,SAAS,EACP,oIAAoI;oBACtI,SAAS,EAAE,kEAAkE;oBAC7E,cAAc,EAAE,oCAAoC;iBACrD,CAAC;gBACF,MAAM;YACR,KAAK,WAAW;gBACd,OAAO;oBACL,SAAS,EACP,oIAAoI;oBACtI,SAAS,EAAE,kEAAkE;oBAC7E,cAAc,EAAE,oCAAoC;iBACrD,CAAC;gBACF,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,wBAAwB,CAAC,GAAsB;QACnD,OAAO,IAAA,qBAAI,EAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,aAAa,CAAC,IAA2C;QACvD,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,WAAW,CAAC,KAAa,EAAE,WAAmB;QAC5C,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,gBAAgB,CACd,eAAuB,EACvB,kBAA8C,EAC9C,aAAyC,EACzC,YAA8C;QAE9C,OAAO;QACP,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;CACF;AAED,kBAAe,aAAa,CAAC"}
@@ -1,19 +0,0 @@
1
- import { Observable } from "rxjs";
2
- import type { Result } from "@ledgerhq/coin-framework/derivation";
3
- import type { Account, DerivationMode } from "@ledgerhq/types-live";
4
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
5
- import { SignerContext } from "./signer";
6
- export type AccountDescriptor = {
7
- internal: string;
8
- external: string;
9
- };
10
- export declare function inferDescriptorFromAccount(account: Account): AccountDescriptor | null | undefined;
11
- export declare function inferDescriptorFromDeviceInfo({ derivationMode, currency, index, parentDerivation, accountDerivation, }: {
12
- derivationMode: DerivationMode;
13
- currency: CryptoCurrency;
14
- index: number;
15
- parentDerivation: Result;
16
- accountDerivation: Result;
17
- }): AccountDescriptor | null | undefined;
18
- export declare function scanDescriptors(deviceId: string, currency: CryptoCurrency, signerContext: SignerContext, limit?: number): Observable<AccountDescriptor>;
19
- //# sourceMappingURL=descriptor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor.d.ts","sourceRoot":"","sources":["../src/descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,MAAM,CAAC;AAInD,OAAO,KAAK,EAGV,MAAM,EACP,MAAM,qCAAqC,CAAC;AAS7C,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AA2CF,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAYjG;AAwCD,wBAAgB,6BAA6B,CAAC,EAC5C,cAAc,EACd,QAAQ,EACR,KAAK,EACL,gBAAgB,EAChB,iBAAiB,GAClB,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;CAC3B,GAAG,iBAAiB,GAAG,IAAI,GAAG,SAAS,CA6BvC;AACD,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,cAAc,EACxB,aAAa,EAAE,aAAa,EAC5B,KAAK,SAAK,GACT,UAAU,CAAC,iBAAiB,CAAC,CAoC/B"}
@@ -1,118 +0,0 @@
1
- import { from, of, EMPTY } from "rxjs";
2
- import { concatMap } from "rxjs/operators";
3
- import invariant from "invariant";
4
- import bs58 from "bs58";
5
- import { hash256, hash160 } from "./crypto-util";
6
- import { walletDerivation, getDerivationModesForCurrency, runAccountDerivationScheme, getDerivationScheme, } from "@ledgerhq/coin-framework/derivation";
7
- import getAddress from "./hw-getAddress";
8
- import { decodeAccountId } from "@ledgerhq/coin-framework/account/index";
9
- const perDerivation = {
10
- "": fragment => `pkh(${fragment})`,
11
- segwit: fragment => `sh(wpkh(${fragment}))`,
12
- native_segwit: fragment => `wpkh(${fragment})`,
13
- taproot: fragment => `tr(${fragment})`,
14
- };
15
- function makeFingerprint(compressedPubKey) {
16
- return hash160(compressedPubKey).slice(0, 4);
17
- }
18
- function makeDescriptor({ currency, index, derivationMode, fingerprint, xpub, }) {
19
- const tmpl = perDerivation[derivationMode];
20
- if (!tmpl || !xpub)
21
- return;
22
- const keyOrigin = fingerprint.toString("hex");
23
- const scheme = getDerivationScheme({
24
- currency,
25
- derivationMode,
26
- });
27
- const accountPath = runAccountDerivationScheme(scheme, currency, {
28
- account: index,
29
- });
30
- return {
31
- external: tmpl(`[${keyOrigin}/${accountPath}]${xpub}/0/*`),
32
- internal: tmpl(`[${keyOrigin}/${accountPath}]${xpub}/1/*`),
33
- };
34
- }
35
- export function inferDescriptorFromAccount(account) {
36
- if (account.currency.family !== "bitcoin")
37
- return;
38
- const { id, derivationMode, seedIdentifier, currency, index } = account;
39
- const xpub = decodeAccountId(id).xpubOrAddress;
40
- const fingerprint = makeFingerprint(compressPublicKeySECP256(Buffer.from(seedIdentifier, "hex")));
41
- return makeDescriptor({
42
- derivationMode,
43
- currency,
44
- fingerprint,
45
- xpub,
46
- index,
47
- });
48
- }
49
- function asBufferUInt32BE(n) {
50
- const buf = Buffer.allocUnsafe(4);
51
- buf.writeUInt32BE(n, 0);
52
- return buf;
53
- }
54
- const compressPublicKeySECP256 = (publicKey) => Buffer.concat([Buffer.from([0x02 + (publicKey[64] & 0x01)]), publicKey.slice(1, 33)]);
55
- function makeXpub({ version, depth, parentFingerprint, index, chainCode, pubKey, }) {
56
- const indexBuffer = asBufferUInt32BE(index);
57
- indexBuffer[0] |= 0x80;
58
- const extendedKeyBytes = Buffer.concat([
59
- asBufferUInt32BE(version),
60
- Buffer.from([depth]),
61
- parentFingerprint,
62
- indexBuffer,
63
- chainCode,
64
- pubKey,
65
- ]);
66
- const checksum = hash256(extendedKeyBytes).slice(0, 4);
67
- return bs58.encode(Buffer.concat([extendedKeyBytes, checksum]));
68
- }
69
- export function inferDescriptorFromDeviceInfo({ derivationMode, currency, index, parentDerivation, accountDerivation, }) {
70
- invariant(currency.bitcoinLikeInfo, "bitcoin currency expected");
71
- const { bitcoinLikeInfo } = currency;
72
- const { XPUBVersion } = bitcoinLikeInfo;
73
- invariant(XPUBVersion, "unsupported bitcoin fork %s", currency.id);
74
- const { chainCode } = accountDerivation;
75
- invariant(chainCode, "chainCode is required");
76
- const fingerprint = makeFingerprint(compressPublicKeySECP256(Buffer.from(parentDerivation.publicKey, "hex")));
77
- const xpub = makeXpub({
78
- version: XPUBVersion,
79
- depth: 3,
80
- parentFingerprint: fingerprint,
81
- index,
82
- chainCode: Buffer.from(chainCode, "hex"),
83
- pubKey: compressPublicKeySECP256(Buffer.from(accountDerivation.publicKey, "hex")),
84
- });
85
- return makeDescriptor({
86
- derivationMode,
87
- currency,
88
- fingerprint,
89
- xpub,
90
- index,
91
- });
92
- }
93
- export function scanDescriptors(deviceId, currency, signerContext, limit = 10) {
94
- const derivateAddress = (opts) => from(getAddress(signerContext)(deviceId, opts));
95
- function stepAddress({ index, accountDerivation, parentDerivation, derivationMode, }) {
96
- const result = inferDescriptorFromDeviceInfo({
97
- derivationMode,
98
- currency,
99
- index,
100
- parentDerivation,
101
- accountDerivation,
102
- });
103
- return !result
104
- ? EMPTY
105
- : of({
106
- result,
107
- complete: index >= limit,
108
- });
109
- }
110
- return from(getDerivationModesForCurrency(currency)).pipe(concatMap(derivationMode => walletDerivation({
111
- currency,
112
- derivationMode,
113
- derivateAddress,
114
- stepAddress,
115
- shouldDerivesOnAccount: true,
116
- })));
117
- }
118
- //# sourceMappingURL=descriptor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descriptor.js","sourceRoot":"","sources":["../src/descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,SAAS,MAAM,WAAW,CAAC;AAClC,OAAO,IAAI,MAAM,MAAM,CAAC;AAMxB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,0BAA0B,EAC1B,mBAAmB,GACpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAGzC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAOzE,MAAM,aAAa,GAEf;IACF,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,OAAO,QAAQ,GAAG;IAClC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,WAAW,QAAQ,IAAI;IAC3C,aAAa,EAAE,QAAQ,CAAC,EAAE,CAAC,QAAQ,QAAQ,GAAG;IAC9C,OAAO,EAAE,QAAQ,CAAC,EAAE,CAAC,MAAM,QAAQ,GAAG;CACvC,CAAC;AAEF,SAAS,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AQ;YACR,KAAK;YACL,gBAAgB;YAChB,iBAAiB;SAClB,CAAC,CAAC;QACH,OAAO,CAAC,MAAM;YACZ,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,EAAE,CAAC;gBACD,MAAM;gBACN,QAAQ,EAAE,KAAK,IAAI,KAAK;aACzB,CAAC,CAAC;IACT,CAAC;IAED,OAAO,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CACvD,SAAS,CAAC,cAAc,CAAC,EAAE,CACzB,gBAAgB,CAAC;QACf,QAAQ;QACR,cAAc;QACd,eAAe;QACf,WAAW;QACX,sBAAsB,EAAE,IAAI;KAC7B,CAAC,CACH,CACF,CAAC;AACJ,CAAC"}
@@ -1,20 +0,0 @@
1
- import type { AddressFormat, BitcoinSignature, BitcoinSigner, BitcoinXPub, CreateTransaction, SignerTransaction } from "./signer";
2
- declare class MockBtcSigner implements BitcoinSigner {
3
- getWalletPublicKey(path: string, _opts: {
4
- verify?: boolean;
5
- format?: AddressFormat;
6
- }): Promise<{
7
- publicKey: string;
8
- chainCode: string;
9
- bitcoinAddress: string;
10
- }>;
11
- createPaymentTransaction(arg: CreateTransaction): Promise<string>;
12
- getWalletXpub(_arg: {
13
- path: string;
14
- xpubVersion: number;
15
- }): Promise<BitcoinXPub>;
16
- signMessage(_path: string, _messageHex: string): Promise<BitcoinSignature>;
17
- splitTransaction(_transactionHex: string, _isSegwitSupported: boolean | null | undefined, _hasExtraData: boolean | null | undefined, _additionals: Array<string> | null | undefined): SignerTransaction;
18
- }
19
- export default MockBtcSigner;
20
- //# sourceMappingURL=mockBtcSigner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockBtcSigner.d.ts","sourceRoot":"","sources":["../src/mockBtcSigner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,cAAM,aAAc,YAAW,aAAa;IAEpC,kBAAkB,CACtB,IAAI,EAAE,MAAM,EAEZ,KAAK,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,aAAa,CAAA;KAAE;;;;;IAwB/C,wBAAwB,CAAC,GAAG,EAAE,iBAAiB;IAIrD,aAAa,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;IAGhF,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAG1E,gBAAgB,CACd,eAAe,EAAE,MAAM,EACvB,kBAAkB,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EAC9C,aAAa,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,EACzC,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GAC7C,iBAAiB;CAQrB;AAED,eAAe,aAAa,CAAC"}
@@ -1,45 +0,0 @@
1
- import hash from "object-hash";
2
- class MockBtcSigner {
3
- // eslint-disable-next-line class-methods-use-this
4
- async getWalletPublicKey(path,
5
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6
- _opts) {
7
- switch (path) {
8
- case "44'/0'":
9
- return {
10
- publicKey: "04c621f37493d99f39ca12fb02ba7fe1687b1650b875dcb6733f386a98958e6556fc95dcecb6ac41af0a5296965751b1598aa475a537474bab5b316fcdc1196568",
11
- chainCode: "a45d311c31a80bf06cc38d8ed7934bd1e8a7b2d48b2868a70258a86e094bacfb",
12
- bitcoinAddress: "1BKWjmA9swxRKMH9NgXpSz8YZfVMnWWU9D",
13
- };
14
- break;
15
- case "44'/0'/0'":
16
- return {
17
- publicKey: "04d52d1ad9311c5a3d542fa652fbd7d7b0be70109e329d359704d9f2946f8eb52a829c23f8b980c5f7b6c51bf446b21f3dc80c865095243c9215dbf9f3cb6403b8",
18
- chainCode: "0bd3e45edca4d8a466f523a2c4094c412d25c36d5298b2d3a29938151a8d37fe",
19
- bitcoinAddress: "1FHa4cuKdea21ByTngP9vz3KYDqqQe9SsA",
20
- };
21
- break;
22
- default:
23
- throw new Error("not supported");
24
- }
25
- }
26
- async createPaymentTransaction(arg) {
27
- return hash(arg);
28
- }
29
- getWalletXpub(_arg) {
30
- return Promise.reject();
31
- }
32
- signMessage(_path, _messageHex) {
33
- return Promise.reject();
34
- }
35
- splitTransaction(_transactionHex, _isSegwitSupported, _hasExtraData, _additionals) {
36
- // Stub
37
- return {
38
- version: Buffer.from(""),
39
- inputs: [],
40
- outputs: [],
41
- };
42
- }
43
- }
44
- export default MockBtcSigner;
45
- //# sourceMappingURL=mockBtcSigner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockBtcSigner.js","sourceRoot":"","sources":["../src/mockBtcSigner.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,aAAa,CAAC;AAU/B,MAAM,aAAa;IACjB,kDAAkD;IAClD,KAAK,CAAC,kBAAkB,CACtB,IAAY;IACZ,6DAA6D;IAC7D,KAAmD;QAEnD,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,QAAQ;gBACX,OAAO;oBACL,SAAS,EACP,oIAAoI;oBACtI,SAAS,EAAE,kEAAkE;oBAC7E,cAAc,EAAE,oCAAoC;iBACrD,CAAC;gBACF,MAAM;YACR,KAAK,WAAW;gBACd,OAAO;oBACL,SAAS,EACP,oIAAoI;oBACtI,SAAS,EAAE,kEAAkE;oBAC7E,cAAc,EAAE,oCAAoC;iBACrD,CAAC;gBACF,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,wBAAwB,CAAC,GAAsB;QACnD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,aAAa,CAAC,IAA2C;QACvD,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,WAAW,CAAC,KAAa,EAAE,WAAmB;QAC5C,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,gBAAgB,CACd,eAAuB,EACvB,kBAA8C,EAC9C,aAAyC,EACzC,YAA8C;QAE9C,OAAO;QACP,OAAO;YACL,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,EAAE;SACZ,CAAC;IACJ,CAAC;CACF;AAED,eAAe,aAAa,CAAC"}
@@ -1,76 +0,0 @@
1
- import invariant from "invariant";
2
- import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/index";
3
- import { setSupportedCurrencies } from "@ledgerhq/coin-framework/currencies/index";
4
- import { fromAccountRaw } from "@ledgerhq/coin-framework/serialization/index";
5
- import { inferDescriptorFromDeviceInfo, inferDescriptorFromAccount } from "./descriptor";
6
- import bitcoinDatasets from "./datasets/bitcoin";
7
- import { assignFromAccountRaw } from "./serialization";
8
- import type { CryptoAssetsStore } from "@ledgerhq/types-live";
9
- import { setCryptoAssetsStore } from "@ledgerhq/cryptoassets/state";
10
-
11
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
12
- setCryptoAssetsStore({
13
- findTokenById: () => Promise.resolve(undefined),
14
- findTokenByAddressInCurrency: () => Promise.resolve(undefined),
15
- getTokensSyncHash: () => Promise.resolve("0"),
16
- } as CryptoAssetsStore);
17
-
18
- setSupportedCurrencies(["bitcoin"]);
19
- describe("inferDescriptorFromAccount", () => {
20
- invariant(bitcoinDatasets.accounts, "bitcoin datasets have accounts");
21
-
22
- let bitcoin1: any, bitcoin2: any;
23
-
24
- beforeAll(async () => {
25
- invariant(bitcoinDatasets.accounts, "bitcoin datasets have accounts in beforeAll");
26
- [bitcoin1, bitcoin2] = await Promise.all(
27
- bitcoinDatasets.accounts.map(a => fromAccountRaw(a.raw, { assignFromAccountRaw })),
28
- );
29
- });
30
-
31
- it("should work on bitcoin account 1", () => {
32
- expect(inferDescriptorFromAccount(bitcoin1)).toEqual({
33
- external:
34
- "pkh([224b6226/44'/0'/0']xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn/0/*)",
35
- internal:
36
- "pkh([224b6226/44'/0'/0']xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn/1/*)",
37
- });
38
- });
39
- it("should work on bitcoin account 2", () => {
40
- expect(inferDescriptorFromAccount(bitcoin2)).toEqual({
41
- external:
42
- "wpkh([d6a9e45e/84'/0'/1']xpub6DEHKg8fgKcb9at2u9Xhjtx4tXGyWqUPQAx2zNCzr41gQRyCqpCn7onSoJU4VS96GXyCtAhhFxErnG2pGVvVexaqF7DEfqGGnGk7Havn7C2/0/*)",
43
- internal:
44
- "wpkh([d6a9e45e/84'/0'/1']xpub6DEHKg8fgKcb9at2u9Xhjtx4tXGyWqUPQAx2zNCzr41gQRyCqpCn7onSoJU4VS96GXyCtAhhFxErnG2pGVvVexaqF7DEfqGGnGk7Havn7C2/1/*)",
45
- });
46
- });
47
- });
48
- describe("inferDescriptorFromDeviceInfo", () => {
49
- it("should work on a first Bitcoin legacy derivation", () => {
50
- const descriptor = inferDescriptorFromDeviceInfo({
51
- derivationMode: "",
52
- currency: getCryptoCurrencyById("bitcoin"),
53
- index: 0,
54
- parentDerivation: {
55
- address: "148LHFgQkoPKHUFeVzFNmUjKT7ZwB47fTR",
56
- path: "44'/0'",
57
- publicKey:
58
- "041caa3a42db5bdd125b2530c47cfbe829539b5a20a5562ec839d241c67d1862f2980d26ebffee25e4f924410c3316b397f34bd572543e72c59a7569ef9032f498",
59
- chainCode: "9f819c7d45eb9eb1e9bd5fa695158cca9e493182f95068b22c8c440ae6eb0720",
60
- },
61
- accountDerivation: {
62
- address: "15o6uBtRzKojbxqBe4Kni66BSvXfKYT2GY",
63
- path: "44'/0'/0'",
64
- publicKey:
65
- "04238878d371ce61cdd04d22ccab50c542e94ffa7a27d02d6bcefaa22e4fcee6db4c2029fd4de0b595e98002c0be01fc1fbd3568671e394c97a6d52c3d4c113fb5",
66
- chainCode: "44728146118df8d18d38c2615154eaffcdd53829957f4e26863344f35653364e",
67
- },
68
- });
69
- expect(descriptor).toEqual({
70
- external:
71
- "pkh([224b6226/44'/0'/0']xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn/0/*)",
72
- internal:
73
- "pkh([224b6226/44'/0'/0']xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn/1/*)",
74
- });
75
- });
76
- });