@ledgerhq/hw-app-btc 6.9.1-taproot.0 → 6.11.1

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 (133) hide show
  1. package/README.md +602 -107
  2. package/lib/Btc.d.ts +11 -7
  3. package/lib/Btc.d.ts.map +1 -1
  4. package/lib/Btc.js +113 -31
  5. package/lib/Btc.js.map +1 -1
  6. package/lib/BtcNew.d.ts +81 -32
  7. package/lib/BtcNew.d.ts.map +1 -1
  8. package/lib/BtcNew.js +296 -99
  9. package/lib/BtcNew.js.map +1 -1
  10. package/lib/BtcOld.d.ts +3 -1
  11. package/lib/BtcOld.d.ts.map +1 -1
  12. package/lib/BtcOld.js +22 -6
  13. package/lib/BtcOld.js.map +1 -1
  14. package/lib/constants.d.ts +1 -0
  15. package/lib/constants.d.ts.map +1 -1
  16. package/lib/constants.js +2 -1
  17. package/lib/constants.js.map +1 -1
  18. package/lib/getAppAndVersion.d.ts +3 -2
  19. package/lib/getAppAndVersion.d.ts.map +1 -1
  20. package/lib/getAppAndVersion.js.map +1 -1
  21. package/lib/newops/appClient.d.ts +6 -2
  22. package/lib/newops/appClient.d.ts.map +1 -1
  23. package/lib/newops/appClient.js +9 -5
  24. package/lib/newops/appClient.js.map +1 -1
  25. package/lib/newops/clientCommands.d.ts +18 -2
  26. package/lib/newops/clientCommands.d.ts.map +1 -1
  27. package/lib/newops/clientCommands.js +20 -3
  28. package/lib/newops/clientCommands.js.map +1 -1
  29. package/lib/newops/merkelizedPsbt.d.ts +11 -0
  30. package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
  31. package/lib/newops/merkelizedPsbt.js +11 -0
  32. package/lib/newops/merkelizedPsbt.js.map +1 -1
  33. package/lib/newops/merkle.d.ts +5 -0
  34. package/lib/newops/merkle.d.ts.map +1 -1
  35. package/lib/newops/merkle.js +5 -0
  36. package/lib/newops/merkle.js.map +1 -1
  37. package/lib/newops/merkleMap.d.ts +10 -0
  38. package/lib/newops/merkleMap.d.ts.map +1 -1
  39. package/lib/newops/merkleMap.js +10 -0
  40. package/lib/newops/merkleMap.js.map +1 -1
  41. package/lib/newops/policy.d.ts +8 -0
  42. package/lib/newops/policy.d.ts.map +1 -1
  43. package/lib/newops/policy.js +9 -1
  44. package/lib/newops/policy.js.map +1 -1
  45. package/lib/newops/psbtExtractor.d.ts +6 -0
  46. package/lib/newops/psbtExtractor.d.ts.map +1 -1
  47. package/lib/newops/psbtExtractor.js +6 -0
  48. package/lib/newops/psbtExtractor.js.map +1 -1
  49. package/lib/newops/psbtFinalizer.d.ts +11 -1
  50. package/lib/newops/psbtFinalizer.d.ts.map +1 -1
  51. package/lib/newops/psbtFinalizer.js +28 -4
  52. package/lib/newops/psbtFinalizer.js.map +1 -1
  53. package/lib/newops/psbtv2.d.ts +22 -2
  54. package/lib/newops/psbtv2.d.ts.map +1 -1
  55. package/lib/newops/psbtv2.js +37 -8
  56. package/lib/newops/psbtv2.js.map +1 -1
  57. package/lib-es/Btc.d.ts +11 -7
  58. package/lib-es/Btc.d.ts.map +1 -1
  59. package/lib-es/Btc.js +94 -31
  60. package/lib-es/Btc.js.map +1 -1
  61. package/lib-es/BtcNew.d.ts +81 -32
  62. package/lib-es/BtcNew.d.ts.map +1 -1
  63. package/lib-es/BtcNew.js +293 -101
  64. package/lib-es/BtcNew.js.map +1 -1
  65. package/lib-es/BtcOld.d.ts +3 -1
  66. package/lib-es/BtcOld.d.ts.map +1 -1
  67. package/lib-es/BtcOld.js +22 -6
  68. package/lib-es/BtcOld.js.map +1 -1
  69. package/lib-es/constants.d.ts +1 -0
  70. package/lib-es/constants.d.ts.map +1 -1
  71. package/lib-es/constants.js +1 -0
  72. package/lib-es/constants.js.map +1 -1
  73. package/lib-es/getAppAndVersion.d.ts +3 -2
  74. package/lib-es/getAppAndVersion.d.ts.map +1 -1
  75. package/lib-es/getAppAndVersion.js.map +1 -1
  76. package/lib-es/newops/appClient.d.ts +6 -2
  77. package/lib-es/newops/appClient.d.ts.map +1 -1
  78. package/lib-es/newops/appClient.js +9 -5
  79. package/lib-es/newops/appClient.js.map +1 -1
  80. package/lib-es/newops/clientCommands.d.ts +18 -2
  81. package/lib-es/newops/clientCommands.d.ts.map +1 -1
  82. package/lib-es/newops/clientCommands.js +20 -3
  83. package/lib-es/newops/clientCommands.js.map +1 -1
  84. package/lib-es/newops/merkelizedPsbt.d.ts +11 -0
  85. package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
  86. package/lib-es/newops/merkelizedPsbt.js +11 -0
  87. package/lib-es/newops/merkelizedPsbt.js.map +1 -1
  88. package/lib-es/newops/merkle.d.ts +5 -0
  89. package/lib-es/newops/merkle.d.ts.map +1 -1
  90. package/lib-es/newops/merkle.js +5 -0
  91. package/lib-es/newops/merkle.js.map +1 -1
  92. package/lib-es/newops/merkleMap.d.ts +10 -0
  93. package/lib-es/newops/merkleMap.d.ts.map +1 -1
  94. package/lib-es/newops/merkleMap.js +10 -0
  95. package/lib-es/newops/merkleMap.js.map +1 -1
  96. package/lib-es/newops/policy.d.ts +8 -0
  97. package/lib-es/newops/policy.d.ts.map +1 -1
  98. package/lib-es/newops/policy.js +10 -2
  99. package/lib-es/newops/policy.js.map +1 -1
  100. package/lib-es/newops/psbtExtractor.d.ts +6 -0
  101. package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
  102. package/lib-es/newops/psbtExtractor.js +6 -0
  103. package/lib-es/newops/psbtExtractor.js.map +1 -1
  104. package/lib-es/newops/psbtFinalizer.d.ts +11 -1
  105. package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
  106. package/lib-es/newops/psbtFinalizer.js +28 -4
  107. package/lib-es/newops/psbtFinalizer.js.map +1 -1
  108. package/lib-es/newops/psbtv2.d.ts +22 -2
  109. package/lib-es/newops/psbtv2.d.ts.map +1 -1
  110. package/lib-es/newops/psbtv2.js +37 -8
  111. package/lib-es/newops/psbtv2.js.map +1 -1
  112. package/package.json +4 -4
  113. package/src/Btc.ts +92 -21
  114. package/src/BtcNew.ts +295 -77
  115. package/src/BtcOld.ts +13 -9
  116. package/src/bip32.ts +1 -1
  117. package/src/constants.ts +1 -0
  118. package/src/getAppAndVersion.ts +7 -4
  119. package/src/newops/appClient.ts +13 -5
  120. package/src/newops/clientCommands.ts +19 -3
  121. package/src/newops/merkelizedPsbt.ts +11 -0
  122. package/src/newops/merkle.ts +5 -0
  123. package/src/newops/merkleMap.ts +10 -0
  124. package/src/newops/policy.ts +10 -2
  125. package/src/newops/psbtExtractor.ts +6 -0
  126. package/src/newops/psbtFinalizer.ts +28 -4
  127. package/src/newops/psbtv2.ts +38 -14
  128. package/tests/Btc.integration.test.ts +125 -15
  129. package/tests/Btc.test.ts +83 -0
  130. package/tests/newops/BtcNew.test.ts +75 -508
  131. package/tests/newops/integrationtools.ts +174 -0
  132. package/tests/newops/testtx.ts +676 -0
  133. package/tests/speculosclient.ts +47 -0
package/lib/Btc.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type Transport from "@ledgerhq/hw-transport";
3
+ import BtcNew from "./BtcNew";
4
+ import BtcOld from "./BtcOld";
3
5
  import type { CreateTransactionArg } from "./createTransaction";
4
6
  import type { AddressFormat } from "./getWalletPublicKey";
5
7
  import type { SignP2SHTransactionArg } from "./signP2SHTransaction";
@@ -40,7 +42,7 @@ export default class Btc {
40
42
  *
41
43
  * - p2sh format with 49' paths
42
44
  *
43
- * - bech32 format with 173' paths
45
+ * - bech32 format with 84' paths
44
46
  *
45
47
  * - cashaddr in case of Bitcoin Cash
46
48
  *
@@ -80,20 +82,21 @@ export default class Btc {
80
82
  * * sequence is the sequence number to use for this input (when using RBF), or non present
81
83
  * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
82
84
  * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
83
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
85
+ * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
84
86
  * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
85
87
  * @param sigHashType is the hash type of the transaction to sign, or default (all)
86
- * @param segwit is an optional boolean indicating wether to use segwit or not
88
+ * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
87
89
  * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
88
90
  * @param additionals list of additionnal options
89
91
  *
90
92
  * - "bech32" for spending native segwit outputs
93
+ * - "bech32m" for spending segwit v1+ outputs
91
94
  * - "abc" for bch
92
95
  * - "gold" for btg
93
96
  * - "bipxxx" for using BIPxxx
94
97
  * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
95
98
  * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
96
- * @param useTrustedInputForSegwit trust inputs for segwit transactions
99
+ * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
97
100
  * @return the signed transaction ready to be broadcast
98
101
  * @example
99
102
  btc.createTransaction({
@@ -137,9 +140,10 @@ export default class Btc {
137
140
  serializeTransactionOutputs(t: Transaction): Buffer;
138
141
  getTrustedInput(indexLookup: number, transaction: Transaction, additionals?: Array<string>): Promise<string>;
139
142
  getTrustedInputBIP143(indexLookup: number, transaction: Transaction, additionals?: Array<string>): string;
143
+ private _lazyImpl;
140
144
  private getCorrectImpl;
141
- private old;
142
- private new;
143
- private useNewApp;
145
+ private inferCorrectImpl;
146
+ protected old(): BtcOld;
147
+ protected new(): BtcNew;
144
148
  }
145
149
  //# sourceMappingURL=Btc.d.ts.map
package/lib/Btc.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Btc.d.ts","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC;AAIpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAIhE,OAAO,KAAK,EAAE,aAA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W,GAAE,KAAK,CAAC,MAAM,CAAM,GAC9B,MAAM;IAUT,OAAO,CAAC,SAAS,CAAgC;YACnC,cAAc;YAQd,gBAAgB;IAU9B,SAAS,CAAC,GAAG,IAAI,MAAM;IAIvB,SAAS,CAAC,GAAG,IAAI,MAAM;CAGxB"}
package/lib/Btc.js CHANGED
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -39,8 +58,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
58
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
59
  };
41
60
  exports.__esModule = true;
42
- var semver_1 = __importDefault(require("semver"));
43
- var BtcNew_1 = __importDefault(require("./BtcNew"));
61
+ var bip32_1 = require("./bip32");
62
+ var BtcNew_1 = __importStar(require("./BtcNew"));
44
63
  var BtcOld_1 = __importDefault(require("./BtcOld"));
45
64
  var getAppAndVersion_1 = require("./getAppAndVersion");
46
65
  var getTrustedInput_1 = require("./getTrustedInput");
@@ -58,6 +77,8 @@ var splitTransaction_1 = require("./splitTransaction");
58
77
  var Btc = /** @class */ (function () {
59
78
  function Btc(transport, scrambleKey) {
60
79
  if (scrambleKey === void 0) { scrambleKey = "BTC"; }
80
+ // cache the underlying implementation (only once)
81
+ this._lazyImpl = null;
61
82
  this.transport = transport;
62
83
  transport.decorateAppAPIMethods(this, [
63
84
  "getWalletXpub",
@@ -93,7 +114,7 @@ var Btc = /** @class */ (function () {
93
114
  *
94
115
  * - p2sh format with 49' paths
95
116
  *
96
- * - bech32 format with 173' paths
117
+ * - bech32 format with 84' paths
97
118
  *
98
119
  * - cashaddr in case of Bitcoin Cash
99
120
  *
@@ -102,6 +123,7 @@ var Btc = /** @class */ (function () {
102
123
  * btc.getWalletPublicKey("49'/0'/0'/0/0", { format: "p2sh" }).then(o => o.bitcoinAddress)
103
124
  */
104
125
  Btc.prototype.getWalletPublicKey = function (path, opts) {
126
+ var _this = this;
105
127
  var options;
106
128
  if (arguments.length > 2 || typeof opts === "boolean") {
107
129
  console.warn("btc.getWalletPublicKey deprecated signature used. Please switch to getWalletPublicKey(path, { format, verify })");
@@ -115,7 +137,38 @@ var Btc = /** @class */ (function () {
115
137
  options = opts || {};
116
138
  }
117
139
  return this.getCorrectImpl().then(function (impl) {
118
- return impl.getWalletPublicKey(path, options);
140
+ /**
141
+ * Definition: A "normal path" is a prefix of a standard path where all
142
+ * the hardened steps of the standard path are included. For example, the
143
+ * paths m/44'/1'/17' and m/44'/1'/17'/1 are normal paths, but m/44'/1'
144
+ * is not. m/'199/1'/17'/0/1 is not a normal path either.
145
+ *
146
+ * There's a compatiblity issue between old and new app: When exporting
147
+ * the key of a non-normal path with verify=false, the new app would
148
+ * return an error, whereas the old app would return the key.
149
+ *
150
+ * See
151
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#get_extended_pubkey
152
+ *
153
+ * If format bech32m is used, we'll not use old, because it doesn't
154
+ * support it.
155
+ *
156
+ * When to use new (given the app supports it)
157
+ * * format is bech32m or
158
+ * * path is normal or
159
+ * * verify is true
160
+ *
161
+ * Otherwise use old.
162
+ */
163
+ if (impl instanceof BtcNew_1["default"] &&
164
+ options.format != "bech32m" &&
165
+ (!options.verify || options.verify == false) &&
166
+ !isPathNormal(path)) {
167
+ return _this.old().getWalletPublicKey(path, options);
168
+ }
169
+ else {
170
+ return impl.getWalletPublicKey(path, options);
171
+ }
119
172
  });
120
173
  };
121
174
  /**
@@ -140,20 +193,21 @@ var Btc = /** @class */ (function () {
140
193
  * * sequence is the sequence number to use for this input (when using RBF), or non present
141
194
  * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
142
195
  * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
143
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign
196
+ * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
144
197
  * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
145
198
  * @param sigHashType is the hash type of the transaction to sign, or default (all)
146
- * @param segwit is an optional boolean indicating wether to use segwit or not
199
+ * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
147
200
  * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
148
201
  * @param additionals list of additionnal options
149
202
  *
150
203
  * - "bech32" for spending native segwit outputs
204
+ * - "bech32m" for spending segwit v1+ outputs
151
205
  * - "abc" for bch
152
206
  * - "gold" for btg
153
207
  * - "bipxxx" for using BIPxxx
154
208
  * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
155
209
  * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
156
- * @param useTrustedInputForSegwit trust inputs for segwit transactions
210
+ * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
157
211
  * @return the signed transaction ready to be broadcast
158
212
  * @example
159
213
  btc.createTransaction({
@@ -220,50 +274,78 @@ var Btc = /** @class */ (function () {
220
274
  if (additionals === void 0) { additionals = []; }
221
275
  return (0, getTrustedInputBIP143_1.getTrustedInputBIP143)(this.transport, indexLookup, transaction, additionals);
222
276
  };
223
- // TODO: we should save in a field what was the latest app and not ask each time in the lifecycle of a new Btc()
224
277
  Btc.prototype.getCorrectImpl = function () {
225
278
  return __awaiter(this, void 0, void 0, function () {
226
- var isNewApp;
279
+ var _lazyImpl, impl;
227
280
  return __generator(this, function (_a) {
228
281
  switch (_a.label) {
229
- case 0: return [4 /*yield*/, this.useNewApp()];
282
+ case 0:
283
+ _lazyImpl = this._lazyImpl;
284
+ if (_lazyImpl)
285
+ return [2 /*return*/, _lazyImpl];
286
+ return [4 /*yield*/, this.inferCorrectImpl()];
230
287
  case 1:
231
- isNewApp = _a.sent();
232
- if (isNewApp) {
233
- return [2 /*return*/, this["new"]()];
234
- }
235
- else {
236
- return [2 /*return*/, this.old()];
237
- }
238
- return [2 /*return*/];
288
+ impl = _a.sent();
289
+ this._lazyImpl = impl;
290
+ return [2 /*return*/, impl];
239
291
  }
240
292
  });
241
293
  });
242
294
  };
243
- Btc.prototype.old = function () {
244
- return new BtcOld_1["default"](this.transport);
245
- };
246
- Btc.prototype["new"] = function () {
247
- return new BtcNew_1["default"](new appClient_1.AppClient(this.transport));
248
- };
249
- Btc.prototype.useNewApp = function () {
295
+ Btc.prototype.inferCorrectImpl = function () {
250
296
  return __awaiter(this, void 0, void 0, function () {
251
- var a, isNewApp;
297
+ var appAndVersion, canUseNewImplementation;
252
298
  return __generator(this, function (_a) {
253
299
  switch (_a.label) {
254
300
  case 0: return [4 /*yield*/, (0, getAppAndVersion_1.getAppAndVersion)(this.transport)];
255
301
  case 1:
256
- a = _a.sent();
257
- isNewApp = semver_1["default"].major(a.version) >= 2;
258
- if ((a.name == "Bitcoin" || a.name == "Bitcoin Test") && isNewApp) {
259
- return [2 /*return*/, true];
302
+ appAndVersion = _a.sent();
303
+ canUseNewImplementation = (0, BtcNew_1.canSupportApp)(appAndVersion);
304
+ if (!canUseNewImplementation) {
305
+ return [2 /*return*/, this.old()];
260
306
  }
261
- return [2 /*return*/, false];
307
+ else {
308
+ return [2 /*return*/, this["new"]()];
309
+ }
310
+ return [2 /*return*/];
262
311
  }
263
312
  });
264
313
  });
265
314
  };
315
+ Btc.prototype.old = function () {
316
+ return new BtcOld_1["default"](this.transport);
317
+ };
318
+ Btc.prototype["new"] = function () {
319
+ return new BtcNew_1["default"](new appClient_1.AppClient(this.transport));
320
+ };
266
321
  return Btc;
267
322
  }());
268
323
  exports["default"] = Btc;
324
+ function isPathNormal(path) {
325
+ //path is not deepest hardened node of a standard path or deeper, use BtcOld
326
+ var h = 0x80000000;
327
+ var pathElems = (0, bip32_1.pathStringToArray)(path);
328
+ var hard = function (n) { return n > h; };
329
+ var soft = function (n) { return !n || n < h; };
330
+ if (pathElems.length >= 3 &&
331
+ pathElems.length <= 5 &&
332
+ [44 + h, 49 + h, 84 + h, 86 + h].some(function (v) { return v == pathElems[0]; }) &&
333
+ [0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
334
+ hard(pathElems[2]) &&
335
+ soft(pathElems[3]) &&
336
+ soft(pathElems[4])) {
337
+ return true;
338
+ }
339
+ if (pathElems.length >= 4 &&
340
+ pathElems.length <= 6 &&
341
+ 48 + h == pathElems[0] &&
342
+ [0 + h, 1 + h].some(function (v) { return v == pathElems[1]; }) &&
343
+ hard(pathElems[2]) &&
344
+ hard(pathElems[3]) &&
345
+ soft(pathElems[4]) &&
346
+ soft(pathElems[5])) {
347
+ return true;
348
+ }
349
+ return false;
350
+ }
269
351
  //# sourceMappingURL=Btc.js.map
package/lib/Btc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Btc.js","sourceRoot":"","sources":["../src/Btc.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAA4B;AAC5B,oDAA8B;AAC9B,oDAA8B;AAE9B,uDA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AS,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IACD,IACE,SAAS,CAAC,MAAM,IAAI,CAAC;QACrB,SAAS,CAAC,MAAM,IAAI,CAAC;QACrB,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC;QACtB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,EAAjB,CAAiB,CAAC;QAC7C,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAClB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAClB;QACA,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/lib/BtcNew.d.ts CHANGED
@@ -1,13 +1,65 @@
1
1
  import type { CreateTransactionArg } from "./createTransaction";
2
+ import { AppAndVersion } from "./getAppAndVersion";
2
3
  import type { AddressFormat } from "./getWalletPublicKey";
3
4
  import { AppClient as Client } from "./newops/appClient";
5
+ export declare function canSupportApp(appAndVersion: AppAndVersion): boolean;
6
+ /**
7
+ * This class implements the same interface as BtcOld (formerly
8
+ * named Btc), but interacts with Bitcoin hardware app version 2+
9
+ * which uses a totally new APDU protocol. This new
10
+ * protocol is documented at
11
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
12
+ *
13
+ * Since the interface must remain compatible with BtcOld, the methods
14
+ * of this class are quite clunky, because it needs to adapt legacy
15
+ * input data into the PSBT process. In the future, a new interface should
16
+ * be developed that exposes PSBT to the outer world, which would render
17
+ * a much cleaner implementation.
18
+ */
4
19
  export default class BtcNew {
5
20
  private client;
6
21
  constructor(client: Client);
22
+ /**
23
+ * This is a new method that allow users to get an xpub at a standard path.
24
+ * Standard paths are described at
25
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description
26
+ *
27
+ * This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
28
+ * M/44'/N'/x'/**
29
+ * M/48'/N'/x'/y'/**
30
+ * M/49'/N'/x'/**
31
+ * M/84'/N'/x'/**
32
+ * M/86'/N'/x'/**
33
+ *
34
+ * The method was added because of added security in the hardware app v2+. The
35
+ * new hardware app will allow export of any xpub up to and including the
36
+ * deepest hardened key of standard derivation paths, whereas the old app
37
+ * would allow export of any key.
38
+ *
39
+ * This caused an issue for callers of this class, who only had
40
+ * getWalletPublicKey() to call which means they have to constuct xpub
41
+ * themselves:
42
+ *
43
+ * Suppose a user of this class wants to create an account xpub on a standard
44
+ * path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
45
+ * by requesting the parent key M/44'/0'. The new app won't allow that, because
46
+ * it only allows exporting deepest level hardened path. So the options are to
47
+ * allow requesting M/44'/0' from the app, or to add a new function
48
+ * "getWalletXpub".
49
+ *
50
+ * We opted for adding a new function, which can greatly simplify client code.
51
+ */
7
52
  getWalletXpub({ path, xpubVersion, }: {
8
53
  path: string;
9
54
  xpubVersion: number;
10
55
  }): Promise<string>;
56
+ /**
57
+ * This method returns a public key, a bitcoin address, and and a chaincode
58
+ * for a specific derivation path.
59
+ *
60
+ * Limitation: If the path is not a leaf node of a standard path, the address
61
+ * will be the empty string "", see this.getWalletAddress() for details.
62
+ */
11
63
  getWalletPublicKey(path: string, opts?: {
12
64
  verify?: boolean;
13
65
  format?: AddressFormat;
@@ -25,7 +77,7 @@ export default class BtcNew {
25
77
  *
26
78
  * If display is false we *could* generate the address ourselves, but chose to
27
79
  * get it from the device to save development time. However, it shouldn't take
28
- * more than a few hours to implement local address generation.
80
+ * too much time to implement local address generation.
29
81
  *
30
82
  * Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
31
83
  * way to get the address from the device. In this case we have to create it
@@ -33,41 +85,38 @@ export default class BtcNew {
33
85
  */
34
86
  private getWalletAddress;
35
87
  /**
36
- * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
37
- * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
88
+ * Build and sign a transaction. See Btc.createPaymentTransactionNew for
89
+ * details on how to use this method.
38
90
  *
39
- * * transaction is the previously computed transaction object for this UTXO
40
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
41
- * * redeem script is the optional redeem script to use when consuming a Segregated Witness input
42
- * * sequence is the sequence number to use for this input (when using RBF), or non present
43
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
44
- * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
45
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
46
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
47
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
48
- * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
49
- * @param initialTimestamp is an optional timestamp of the function call to use for coins that necessitate timestamps only, (not the one that the tx will include)
50
- * @param additionals list of additionnal options
51
- *
52
- * - "bech32" for spending native segwit outputs
53
- * - "bech32m" for spending segwit v1+ outptus
54
- * - "abc" for bch
55
- * - "gold" for btg
56
- * - "bipxxx" for using BIPxxx
57
- * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
58
- * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
59
- * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
60
- * @return the signed transaction ready to be broadcast
61
- * @example
62
- btc.createTransaction({
63
- inputs: [ [tx1, 1] ],
64
- associatedKeysets: ["0'/0/0"],
65
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
66
- }).then(res => ...);
91
+ * This method will convert the legacy arguments, CreateTransactionArg, into
92
+ * a psbt which is finally signed and finalized, and the extracted fully signed
93
+ * transaction is returned.
67
94
  */
68
95
  createPaymentTransactionNew(arg: CreateTransactionArg): Promise<string>;
96
+ /**
97
+ * Calculates an output script along with public key and possible redeemScript
98
+ * from a path and accountType. The accountPath must be a prefix of path.
99
+ *
100
+ * @returns an object with output script (property "script"), redeemScript (if
101
+ * wrapped p2wpkh), and pubkey at provided path. The values of these three
102
+ * properties depend on the accountType used.
103
+ */
104
+ private outputScriptAt;
105
+ /**
106
+ * Adds relevant data about an input to the psbt. This includes sequence,
107
+ * previous txid, output index, spent UTXO, redeem script for wrapped p2wpkh,
108
+ * public key and its derivation path.
109
+ */
69
110
  private setInput;
111
+ /**
112
+ * This implements the "Signer" role of the BIP370 transaction signing
113
+ * process.
114
+ *
115
+ * It ssks the hardware device to sign the a psbt using the specified wallet
116
+ * policy. This method assumes BIP32 derived keys are used for all inputs, see
117
+ * comment in-line. The signatures returned from the hardware device is added
118
+ * to the appropriate input fields of the PSBT.
119
+ */
70
120
  private signPsbt;
71
- private createRedeemScript;
72
121
  }
73
122
  //# sourceMappingURL=BtcNew.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BtcNew.d.ts","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AASzD,MAAM,CAAC,OAAO,OAAO,MAAM;IACb,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAE5B,aAAa,CAAC,EAClB,IAAI,EACJ,WAAW,GACZ,EAAE;QACD,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;KACrB,GAAG,OAAO,CAAC,MAAM,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