@ledgerhq/hw-app-btc 6.10.0-taproot.0 → 6.11.2

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 (115) hide show
  1. package/README.md +660 -107
  2. package/lib/Btc.d.ts +9 -6
  3. package/lib/Btc.d.ts.map +1 -1
  4. package/lib/Btc.js +74 -11
  5. package/lib/Btc.js.map +1 -1
  6. package/lib/BtcNew.d.ts +80 -32
  7. package/lib/BtcNew.d.ts.map +1 -1
  8. package/lib/BtcNew.js +179 -209
  9. package/lib/BtcNew.js.map +1 -1
  10. package/lib/newops/accounttype.d.ts +110 -0
  11. package/lib/newops/accounttype.d.ts.map +1 -0
  12. package/lib/newops/accounttype.js +233 -0
  13. package/lib/newops/accounttype.js.map +1 -0
  14. package/lib/newops/appClient.d.ts +6 -2
  15. package/lib/newops/appClient.d.ts.map +1 -1
  16. package/lib/newops/appClient.js +8 -4
  17. package/lib/newops/appClient.js.map +1 -1
  18. package/lib/newops/clientCommands.d.ts +18 -2
  19. package/lib/newops/clientCommands.d.ts.map +1 -1
  20. package/lib/newops/clientCommands.js +34 -12
  21. package/lib/newops/clientCommands.js.map +1 -1
  22. package/lib/newops/merkelizedPsbt.d.ts +11 -0
  23. package/lib/newops/merkelizedPsbt.d.ts.map +1 -1
  24. package/lib/newops/merkelizedPsbt.js +11 -0
  25. package/lib/newops/merkelizedPsbt.js.map +1 -1
  26. package/lib/newops/merkle.d.ts +5 -0
  27. package/lib/newops/merkle.d.ts.map +1 -1
  28. package/lib/newops/merkle.js +5 -0
  29. package/lib/newops/merkle.js.map +1 -1
  30. package/lib/newops/merkleMap.d.ts +10 -0
  31. package/lib/newops/merkleMap.d.ts.map +1 -1
  32. package/lib/newops/merkleMap.js +10 -0
  33. package/lib/newops/merkleMap.js.map +1 -1
  34. package/lib/newops/policy.d.ts +8 -0
  35. package/lib/newops/policy.d.ts.map +1 -1
  36. package/lib/newops/policy.js +9 -1
  37. package/lib/newops/policy.js.map +1 -1
  38. package/lib/newops/psbtExtractor.d.ts +6 -0
  39. package/lib/newops/psbtExtractor.d.ts.map +1 -1
  40. package/lib/newops/psbtExtractor.js +6 -0
  41. package/lib/newops/psbtExtractor.js.map +1 -1
  42. package/lib/newops/psbtFinalizer.d.ts +11 -1
  43. package/lib/newops/psbtFinalizer.d.ts.map +1 -1
  44. package/lib/newops/psbtFinalizer.js +26 -1
  45. package/lib/newops/psbtFinalizer.js.map +1 -1
  46. package/lib/newops/psbtv2.d.ts +22 -2
  47. package/lib/newops/psbtv2.d.ts.map +1 -1
  48. package/lib/newops/psbtv2.js +33 -8
  49. package/lib/newops/psbtv2.js.map +1 -1
  50. package/lib-es/Btc.d.ts +9 -6
  51. package/lib-es/Btc.d.ts.map +1 -1
  52. package/lib-es/Btc.js +75 -12
  53. package/lib-es/Btc.js.map +1 -1
  54. package/lib-es/BtcNew.d.ts +80 -32
  55. package/lib-es/BtcNew.d.ts.map +1 -1
  56. package/lib-es/BtcNew.js +176 -210
  57. package/lib-es/BtcNew.js.map +1 -1
  58. package/lib-es/newops/accounttype.d.ts +110 -0
  59. package/lib-es/newops/accounttype.d.ts.map +1 -0
  60. package/lib-es/newops/accounttype.js +230 -0
  61. package/lib-es/newops/accounttype.js.map +1 -0
  62. package/lib-es/newops/appClient.d.ts +6 -2
  63. package/lib-es/newops/appClient.d.ts.map +1 -1
  64. package/lib-es/newops/appClient.js +8 -4
  65. package/lib-es/newops/appClient.js.map +1 -1
  66. package/lib-es/newops/clientCommands.d.ts +18 -2
  67. package/lib-es/newops/clientCommands.d.ts.map +1 -1
  68. package/lib-es/newops/clientCommands.js +34 -12
  69. package/lib-es/newops/clientCommands.js.map +1 -1
  70. package/lib-es/newops/merkelizedPsbt.d.ts +11 -0
  71. package/lib-es/newops/merkelizedPsbt.d.ts.map +1 -1
  72. package/lib-es/newops/merkelizedPsbt.js +11 -0
  73. package/lib-es/newops/merkelizedPsbt.js.map +1 -1
  74. package/lib-es/newops/merkle.d.ts +5 -0
  75. package/lib-es/newops/merkle.d.ts.map +1 -1
  76. package/lib-es/newops/merkle.js +5 -0
  77. package/lib-es/newops/merkle.js.map +1 -1
  78. package/lib-es/newops/merkleMap.d.ts +10 -0
  79. package/lib-es/newops/merkleMap.d.ts.map +1 -1
  80. package/lib-es/newops/merkleMap.js +10 -0
  81. package/lib-es/newops/merkleMap.js.map +1 -1
  82. package/lib-es/newops/policy.d.ts +8 -0
  83. package/lib-es/newops/policy.d.ts.map +1 -1
  84. package/lib-es/newops/policy.js +10 -2
  85. package/lib-es/newops/policy.js.map +1 -1
  86. package/lib-es/newops/psbtExtractor.d.ts +6 -0
  87. package/lib-es/newops/psbtExtractor.d.ts.map +1 -1
  88. package/lib-es/newops/psbtExtractor.js +6 -0
  89. package/lib-es/newops/psbtExtractor.js.map +1 -1
  90. package/lib-es/newops/psbtFinalizer.d.ts +11 -1
  91. package/lib-es/newops/psbtFinalizer.d.ts.map +1 -1
  92. package/lib-es/newops/psbtFinalizer.js +26 -1
  93. package/lib-es/newops/psbtFinalizer.js.map +1 -1
  94. package/lib-es/newops/psbtv2.d.ts +22 -2
  95. package/lib-es/newops/psbtv2.d.ts.map +1 -1
  96. package/lib-es/newops/psbtv2.js +33 -8
  97. package/lib-es/newops/psbtv2.js.map +1 -1
  98. package/package.json +4 -4
  99. package/src/Btc.ts +113 -15
  100. package/src/BtcNew.ts +213 -209
  101. package/src/newops/accounttype.ts +370 -0
  102. package/src/newops/appClient.ts +12 -4
  103. package/src/newops/clientCommands.ts +34 -12
  104. package/src/newops/merkelizedPsbt.ts +11 -0
  105. package/src/newops/merkle.ts +5 -0
  106. package/src/newops/merkleMap.ts +10 -0
  107. package/src/newops/policy.ts +10 -2
  108. package/src/newops/psbtExtractor.ts +6 -0
  109. package/src/newops/psbtFinalizer.ts +26 -1
  110. package/src/newops/psbtv2.ts +34 -14
  111. package/tests/Btc.integration.test.ts +7 -1
  112. package/tests/Btc.test.ts +88 -0
  113. package/tests/newops/BtcNew.test.ts +54 -20
  114. package/tests/newops/integrationtools.ts +49 -39
  115. package/tests/newops/testtx.ts +0 -55
package/lib/BtcNew.js CHANGED
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -46,24 +35,75 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
36
  }
48
37
  };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
49
41
  exports.__esModule = true;
50
- exports.newSupportedApps = void 0;
42
+ exports.canSupportApp = void 0;
51
43
  var bitcoinjs_lib_1 = require("bitcoinjs-lib");
44
+ var semver_1 = __importDefault(require("semver"));
45
+ var tiny_secp256k1_1 = require("tiny-secp256k1");
52
46
  var bip32_1 = require("./bip32");
53
47
  var buffertools_1 = require("./buffertools");
54
- var hashPublicKey_1 = require("./hashPublicKey");
48
+ var accounttype_1 = require("./newops/accounttype");
55
49
  var policy_1 = require("./newops/policy");
56
50
  var psbtExtractor_1 = require("./newops/psbtExtractor");
57
51
  var psbtFinalizer_1 = require("./newops/psbtFinalizer");
58
52
  var psbtv2_1 = require("./newops/psbtv2");
59
53
  var serializeTransaction_1 = require("./serializeTransaction");
60
- var tiny_secp256k1_1 = require("tiny-secp256k1");
61
- var constants_1 = require("./constants");
62
- exports.newSupportedApps = ["Bitcoin", "Bitcoin Test"];
54
+ var newSupportedApps = ["Bitcoin", "Bitcoin Test"];
55
+ function canSupportApp(appAndVersion) {
56
+ return (newSupportedApps.includes(appAndVersion.name) &&
57
+ semver_1["default"].major(appAndVersion.version) >= 2);
58
+ }
59
+ exports.canSupportApp = canSupportApp;
60
+ /**
61
+ * This class implements the same interface as BtcOld (formerly
62
+ * named Btc), but interacts with Bitcoin hardware app version 2+
63
+ * which uses a totally new APDU protocol. This new
64
+ * protocol is documented at
65
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md
66
+ *
67
+ * Since the interface must remain compatible with BtcOld, the methods
68
+ * of this class are quite clunky, because it needs to adapt legacy
69
+ * input data into the PSBT process. In the future, a new interface should
70
+ * be developed that exposes PSBT to the outer world, which would render
71
+ * a much cleaner implementation.
72
+ */
63
73
  var BtcNew = /** @class */ (function () {
64
74
  function BtcNew(client) {
65
75
  this.client = client;
66
76
  }
77
+ /**
78
+ * This is a new method that allow users to get an xpub at a standard path.
79
+ * Standard paths are described at
80
+ * https://github.com/LedgerHQ/app-bitcoin-new/blob/master/doc/bitcoin.md#description
81
+ *
82
+ * This boils down to paths (N=0 for Bitcoin, N=1 for Testnet):
83
+ * M/44'/N'/x'/**
84
+ * M/48'/N'/x'/y'/**
85
+ * M/49'/N'/x'/**
86
+ * M/84'/N'/x'/**
87
+ * M/86'/N'/x'/**
88
+ *
89
+ * The method was added because of added security in the hardware app v2+. The
90
+ * new hardware app will allow export of any xpub up to and including the
91
+ * deepest hardened key of standard derivation paths, whereas the old app
92
+ * would allow export of any key.
93
+ *
94
+ * This caused an issue for callers of this class, who only had
95
+ * getWalletPublicKey() to call which means they have to constuct xpub
96
+ * themselves:
97
+ *
98
+ * Suppose a user of this class wants to create an account xpub on a standard
99
+ * path, M/44'/0'/Z'. The user must get the parent key fingerprint (see BIP32)
100
+ * by requesting the parent key M/44'/0'. The new app won't allow that, because
101
+ * it only allows exporting deepest level hardened path. So the options are to
102
+ * allow requesting M/44'/0' from the app, or to add a new function
103
+ * "getWalletXpub".
104
+ *
105
+ * We opted for adding a new function, which can greatly simplify client code.
106
+ */
67
107
  BtcNew.prototype.getWalletXpub = function (_a) {
68
108
  var path = _a.path, xpubVersion = _a.xpubVersion;
69
109
  return __awaiter(this, void 0, void 0, function () {
@@ -72,7 +112,7 @@ var BtcNew = /** @class */ (function () {
72
112
  switch (_b.label) {
73
113
  case 0:
74
114
  pathElements = (0, bip32_1.pathStringToArray)(path);
75
- return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
115
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
76
116
  case 1:
77
117
  xpub = _b.sent();
78
118
  xpubComponents = (0, bip32_1.getXpubComponents)(xpub);
@@ -84,6 +124,13 @@ var BtcNew = /** @class */ (function () {
84
124
  });
85
125
  });
86
126
  };
127
+ /**
128
+ * This method returns a public key, a bitcoin address, and and a chaincode
129
+ * for a specific derivation path.
130
+ *
131
+ * Limitation: If the path is not a leaf node of a standard path, the address
132
+ * will be the empty string "", see this.getWalletAddress() for details.
133
+ */
87
134
  BtcNew.prototype.getWalletPublicKey = function (path, opts) {
88
135
  var _a, _b;
89
136
  return __awaiter(this, void 0, void 0, function () {
@@ -92,11 +139,11 @@ var BtcNew = /** @class */ (function () {
92
139
  switch (_c.label) {
93
140
  case 0:
94
141
  pathElements = (0, bip32_1.pathStringToArray)(path);
95
- return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
142
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
96
143
  case 1:
97
144
  xpub = _c.sent();
98
145
  display = (_a = opts === null || opts === void 0 ? void 0 : opts.verify) !== null && _a !== void 0 ? _a : false;
99
- return [4 /*yield*/, this.getWalletAddress(pathElements, accountTypeFrom((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : "legacy"), display)];
146
+ return [4 /*yield*/, this.getWalletAddress(pathElements, descrTemplFrom((_b = opts === null || opts === void 0 ? void 0 : opts.format) !== null && _b !== void 0 ? _b : "legacy"), display)];
100
147
  case 2:
101
148
  address = _c.sent();
102
149
  components = (0, bip32_1.getXpubComponents)(xpub);
@@ -119,13 +166,13 @@ var BtcNew = /** @class */ (function () {
119
166
  *
120
167
  * If display is false we *could* generate the address ourselves, but chose to
121
168
  * get it from the device to save development time. However, it shouldn't take
122
- * more than a few hours to implement local address generation.
169
+ * too much time to implement local address generation.
123
170
  *
124
171
  * Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
125
172
  * way to get the address from the device. In this case we have to create it
126
173
  * ourselves, but we don't at this time, and instead return an empty ("") address.
127
174
  */
128
- BtcNew.prototype.getWalletAddress = function (pathElements, accountType, display) {
175
+ BtcNew.prototype.getWalletAddress = function (pathElements, descrTempl, display) {
129
176
  return __awaiter(this, void 0, void 0, function () {
130
177
  var accountPath, accountXpub, masterFingerprint, policy, changeAndIndex;
131
178
  return __generator(this, function (_a) {
@@ -135,13 +182,13 @@ var BtcNew = /** @class */ (function () {
135
182
  if (accountPath.length + 2 != pathElements.length) {
136
183
  return [2 /*return*/, ""];
137
184
  }
138
- return [4 /*yield*/, this.client.getPubkey(false, accountPath)];
185
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, accountPath)];
139
186
  case 1:
140
187
  accountXpub = _a.sent();
141
188
  return [4 /*yield*/, this.client.getMasterFingerprint()];
142
189
  case 2:
143
190
  masterFingerprint = _a.sent();
144
- policy = new policy_1.WalletPolicy(accountType, (0, policy_1.createKey)(masterFingerprint, accountPath, accountXpub));
191
+ policy = new policy_1.WalletPolicy(descrTempl, (0, policy_1.createKey)(masterFingerprint, accountPath, accountXpub));
145
192
  changeAndIndex = pathElements.slice(-2, pathElements.length);
146
193
  return [2 /*return*/, this.client.getWalletAddress(policy, Buffer.alloc(32, 0), changeAndIndex[0], changeAndIndex[1], display)];
147
194
  }
@@ -149,75 +196,62 @@ var BtcNew = /** @class */ (function () {
149
196
  });
150
197
  };
151
198
  /**
152
- * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
153
- * @param inputs is an array of [ transaction, output_index, optional redeem script, optional sequence ] where
154
- *
155
- * * transaction is the previously computed transaction object for this UTXO
156
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
157
- * * redeem script is the optional redeem script to use when consuming a Segregated Witness input
158
- * * sequence is the sequence number to use for this input (when using RBF), or non present
159
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
160
- * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
161
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
162
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
163
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
164
- * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
165
- * @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)
166
- * @param additionals list of additionnal options
199
+ * Build and sign a transaction. See Btc.createPaymentTransactionNew for
200
+ * details on how to use this method.
167
201
  *
168
- * - "bech32" for spending native segwit outputs
169
- * - "bech32m" for spending segwit v1+ outptus
170
- * - "abc" for bch
171
- * - "gold" for btg
172
- * - "bipxxx" for using BIPxxx
173
- * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
174
- * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
175
- * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
176
- * @return the signed transaction ready to be broadcast
177
- * @example
178
- btc.createTransaction({
179
- inputs: [ [tx1, 1] ],
180
- associatedKeysets: ["0'/0/0"],
181
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
182
- }).then(res => ...);
202
+ * This method will convert the legacy arguments, CreateTransactionArg, into
203
+ * a psbt which is finally signed and finalized, and the extracted fully signed
204
+ * transaction is returned.
183
205
  */
184
206
  BtcNew.prototype.createPaymentTransactionNew = function (arg) {
185
207
  return __awaiter(this, void 0, void 0, function () {
186
- var psbt, accountType, masterFp, accountXpub, accountPath, i, pathElems, outputsConcat, outputsBufferReader, outputCount, changeData, changeFound, i, amount, outputScript, isChange, changePath, pubkey, key, p;
208
+ var inputCount, psbt, masterFp, accountType, notifyCount, progress, accountXpub, accountPath, i, pathElems, outputsConcat, outputsBufferReader, outputCount, changeData, changeFound, i, amount, outputScript, isChange, changePath, pubkey, key, p, firstSigned, progressCallback, serializedTx;
187
209
  return __generator(this, function (_a) {
188
210
  switch (_a.label) {
189
211
  case 0:
190
- if (arg.inputs.length == 0) {
212
+ inputCount = arg.inputs.length;
213
+ if (inputCount == 0) {
191
214
  throw Error("No inputs");
192
215
  }
193
216
  psbt = new psbtv2_1.PsbtV2();
194
- accountType = accountTypeFromArg(arg);
195
- psbt.setGlobalTxVersion(2);
217
+ return [4 /*yield*/, this.client.getMasterFingerprint()];
218
+ case 1:
219
+ masterFp = _a.sent();
220
+ accountType = accountTypeFromArg(arg, psbt, masterFp);
196
221
  if (arg.lockTime) {
222
+ // The signer will assume locktime 0 if unset
197
223
  psbt.setGlobalFallbackLocktime(arg.lockTime);
198
224
  }
199
- psbt.setGlobalInputCount(arg.inputs.length);
225
+ psbt.setGlobalInputCount(inputCount);
200
226
  psbt.setGlobalPsbtVersion(2);
201
227
  psbt.setGlobalTxVersion(2);
202
- return [4 /*yield*/, this.client.getMasterFingerprint()];
203
- case 1:
204
- masterFp = _a.sent();
228
+ notifyCount = 0;
229
+ progress = function () {
230
+ if (!arg.onDeviceStreaming)
231
+ return;
232
+ arg.onDeviceStreaming({
233
+ total: 2 * inputCount,
234
+ index: notifyCount,
235
+ progress: ++notifyCount / (2 * inputCount)
236
+ });
237
+ };
205
238
  accountXpub = "";
206
239
  accountPath = [];
207
240
  i = 0;
208
241
  _a.label = 2;
209
242
  case 2:
210
- if (!(i < arg.inputs.length)) return [3 /*break*/, 7];
243
+ if (!(i < inputCount)) return [3 /*break*/, 7];
244
+ progress();
211
245
  pathElems = (0, bip32_1.pathStringToArray)(arg.associatedKeysets[i]);
212
246
  if (!(accountXpub == "")) return [3 /*break*/, 4];
213
247
  // We assume all inputs belong to the same account so we set
214
248
  // the account xpub and path based on the first input.
215
249
  accountPath = pathElems.slice(0, -2);
216
- return [4 /*yield*/, this.client.getPubkey(false, accountPath)];
250
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, accountPath)];
217
251
  case 3:
218
252
  accountXpub = _a.sent();
219
253
  _a.label = 4;
220
- case 4: return [4 /*yield*/, this.setInput(psbt, i, arg.inputs[i], pathElems, accountType, masterFp)];
254
+ case 4: return [4 /*yield*/, this.setInput(psbt, i, arg.inputs[i], pathElems, accountType, masterFp, arg.sigHashType)];
221
255
  case 5:
222
256
  _a.sent();
223
257
  _a.label = 6;
@@ -228,52 +262,63 @@ var BtcNew = /** @class */ (function () {
228
262
  outputsConcat = Buffer.from(arg.outputScriptHex, "hex");
229
263
  outputsBufferReader = new buffertools_1.BufferReader(outputsConcat);
230
264
  outputCount = outputsBufferReader.readVarInt();
265
+ psbt.setGlobalOutputCount(outputCount);
231
266
  return [4 /*yield*/, this.outputScriptAt(accountPath, accountType, arg.changePath)];
232
267
  case 8:
233
268
  changeData = _a.sent();
234
- psbt.setGlobalOutputCount(outputCount);
235
269
  changeFound = !changeData;
236
270
  for (i = 0; i < outputCount; i++) {
237
271
  amount = Number(outputsBufferReader.readUInt64());
238
272
  outputScript = outputsBufferReader.readVarSlice();
239
- isChange = changeData && outputScript.equals(changeData === null || changeData === void 0 ? void 0 : changeData.script);
273
+ psbt.setOutputAmount(i, amount);
274
+ psbt.setOutputScript(i, outputScript);
275
+ isChange = changeData && outputScript.equals(changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey);
240
276
  if (isChange) {
241
277
  changeFound = true;
242
278
  changePath = (0, bip32_1.pathStringToArray)(arg.changePath);
243
279
  pubkey = changeData.pubkey;
244
- if (accountType == AccountType.p2pkh) {
245
- psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
246
- }
247
- else if (accountType == AccountType.p2wpkh) {
248
- psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
249
- }
250
- else if (accountType == AccountType.p2wpkhWrapped) {
251
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
252
- psbt.setOutputRedeemScript(i, changeData.redeemScript);
253
- psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
254
- }
255
- else if (accountType == AccountType.p2tr) {
256
- psbt.setOutputTapBip32Derivation(i, pubkey, [], masterFp, changePath);
257
- }
280
+ accountType.setOwnOutput(i, changeData.cond, [pubkey], [changePath]);
258
281
  }
259
- psbt.setOutputAmount(i, amount);
260
- psbt.setOutputScript(i, outputScript);
261
282
  }
262
283
  if (!changeFound) {
263
284
  throw new Error("Change script not found among outputs! " +
264
- (changeData === null || changeData === void 0 ? void 0 : changeData.script.toString("hex")));
285
+ (changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey.toString("hex")));
265
286
  }
266
287
  key = (0, policy_1.createKey)(masterFp, accountPath, accountXpub);
267
- p = new policy_1.WalletPolicy(accountType, key);
268
- return [4 /*yield*/, this.signPsbt(psbt, p)];
269
- case 9: return [2 /*return*/, _a.sent()];
288
+ p = new policy_1.WalletPolicy(accountType.getDescriptorTemplate(), key);
289
+ // This is cheating, because it's not actually requested on the
290
+ // device yet, but it will be, soonish.
291
+ if (arg.onDeviceSignatureRequested)
292
+ arg.onDeviceSignatureRequested();
293
+ firstSigned = false;
294
+ progressCallback = function () {
295
+ if (!firstSigned) {
296
+ firstSigned = true;
297
+ arg.onDeviceSignatureGranted && arg.onDeviceSignatureGranted();
298
+ }
299
+ progress();
300
+ };
301
+ return [4 /*yield*/, this.signPsbt(psbt, p, progressCallback)];
302
+ case 9:
303
+ _a.sent();
304
+ (0, psbtFinalizer_1.finalize)(psbt);
305
+ serializedTx = (0, psbtExtractor_1.extract)(psbt);
306
+ return [2 /*return*/, serializedTx.toString("hex")];
270
307
  }
271
308
  });
272
309
  });
273
310
  };
311
+ /**
312
+ * Calculates an output script along with public key and possible redeemScript
313
+ * from a path and accountType. The accountPath must be a prefix of path.
314
+ *
315
+ * @returns an object with output script (property "script"), redeemScript (if
316
+ * wrapped p2wpkh), and pubkey at provided path. The values of these three
317
+ * properties depend on the accountType used.
318
+ */
274
319
  BtcNew.prototype.outputScriptAt = function (accountPath, accountType, path) {
275
320
  return __awaiter(this, void 0, void 0, function () {
276
- var pathElems, i, xpub, pubkey, script;
321
+ var pathElems, i, xpub, pubkey, cond;
277
322
  return __generator(this, function (_a) {
278
323
  switch (_a.label) {
279
324
  case 0:
@@ -287,68 +332,52 @@ var BtcNew = /** @class */ (function () {
287
332
  throw new Error("Path " + path + " not in account " + (0, bip32_1.pathArrayToString)(accountPath));
288
333
  }
289
334
  }
290
- return [4 /*yield*/, this.client.getPubkey(false, pathElems)];
335
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElems)];
291
336
  case 1:
292
337
  xpub = _a.sent();
293
338
  pubkey = (0, bip32_1.pubkeyFromXpub)(xpub);
294
- if (accountType == AccountType.p2tr) {
295
- pubkey = pubkey.slice(1);
296
- }
297
- script = outputScriptOf(pubkey, accountType);
298
- return [2 /*return*/, __assign(__assign({}, script), { pubkey: pubkey })];
339
+ cond = accountType.spendingCondition([pubkey]);
340
+ return [2 /*return*/, { cond: cond, pubkey: pubkey }];
299
341
  }
300
342
  });
301
343
  });
302
344
  };
303
- BtcNew.prototype.setInput = function (psbt, i, input, pathElements, accountType, masterFP) {
345
+ /**
346
+ * Adds relevant data about an input to the psbt. This includes sequence,
347
+ * previous txid, output index, spent UTXO, redeem script for wrapped p2wpkh,
348
+ * public key and its derivation path.
349
+ */
350
+ BtcNew.prototype.setInput = function (psbt, i, input, pathElements, accountType, masterFP, sigHashType) {
304
351
  return __awaiter(this, void 0, void 0, function () {
305
- var inputTx, spentOutputIndex, redeemScript, sequence, inputTxBuffer, inputTxid, xpubBase58, pubkey, spentOutput, expectedRedeemScript, xonly;
352
+ var inputTx, spentOutputIndex, redeemScript, sequence, inputTxBuffer, inputTxid, xpubBase58, pubkey, spentTxOutput, spendCondition, spentOutput;
306
353
  return __generator(this, function (_a) {
307
354
  switch (_a.label) {
308
355
  case 0:
309
356
  inputTx = input[0];
310
357
  spentOutputIndex = input[1];
311
- redeemScript = input[2];
358
+ redeemScript = input[2] ? Buffer.from(input[2], "hex") : undefined;
312
359
  sequence = input[3];
313
360
  if (sequence) {
314
361
  psbt.setInputSequence(i, sequence);
315
362
  }
363
+ if (sigHashType) {
364
+ psbt.setInputSighashType(i, sigHashType);
365
+ }
316
366
  inputTxBuffer = (0, serializeTransaction_1.serializeTransaction)(inputTx, true);
317
367
  inputTxid = bitcoinjs_lib_1.crypto.hash256(inputTxBuffer);
318
- return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
368
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
319
369
  case 1:
320
370
  xpubBase58 = _a.sent();
321
371
  pubkey = (0, bip32_1.pubkeyFromXpub)(xpubBase58);
322
372
  if (!inputTx.outputs)
323
373
  throw Error("Missing outputs array in transaction to sign");
324
- spentOutput = inputTx.outputs[spentOutputIndex];
325
- if (accountType == AccountType.p2pkh) {
326
- psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
327
- psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
328
- }
329
- else if (accountType == AccountType.p2wpkh) {
330
- psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
331
- psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
332
- psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
333
- }
334
- else if (accountType == AccountType.p2wpkhWrapped) {
335
- psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
336
- psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
337
- if (!redeemScript) {
338
- throw new Error("Missing redeemScript for p2wpkhWrapped input");
339
- }
340
- expectedRedeemScript = createRedeemScript(pubkey);
341
- if (redeemScript != expectedRedeemScript.toString("hex")) {
342
- throw new Error("Unexpected redeemScript");
343
- }
344
- psbt.setInputRedeemScript(i, expectedRedeemScript);
345
- psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
346
- }
347
- else if (accountType == AccountType.p2tr) {
348
- xonly = pubkey.slice(1);
349
- psbt.setInputTapBip32Derivation(i, xonly, [], masterFP, pathElements);
350
- psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
351
- }
374
+ spentTxOutput = inputTx.outputs[spentOutputIndex];
375
+ spendCondition = {
376
+ scriptPubKey: spentTxOutput.script,
377
+ redeemScript: redeemScript
378
+ };
379
+ spentOutput = { cond: spendCondition, amount: spentTxOutput.amount };
380
+ accountType.setInput(i, inputTxBuffer, spentOutput, [pubkey], [pathElements]);
352
381
  psbt.setInputPreviousTxId(i, inputTxid);
353
382
  psbt.setInputOutputIndex(i, spentOutputIndex);
354
383
  return [2 /*return*/];
@@ -356,17 +385,26 @@ var BtcNew = /** @class */ (function () {
356
385
  });
357
386
  });
358
387
  };
359
- BtcNew.prototype.signPsbt = function (psbt, walletPolicy) {
388
+ /**
389
+ * This implements the "Signer" role of the BIP370 transaction signing
390
+ * process.
391
+ *
392
+ * It ssks the hardware device to sign the a psbt using the specified wallet
393
+ * policy. This method assumes BIP32 derived keys are used for all inputs, see
394
+ * comment in-line. The signatures returned from the hardware device is added
395
+ * to the appropriate input fields of the PSBT.
396
+ */
397
+ BtcNew.prototype.signPsbt = function (psbt, walletPolicy, progressCallback) {
360
398
  return __awaiter(this, void 0, void 0, function () {
361
- var sigs, serializedTx;
399
+ var sigs;
362
400
  return __generator(this, function (_a) {
363
401
  switch (_a.label) {
364
- case 0: return [4 /*yield*/, this.client.signPsbt(psbt, walletPolicy, Buffer.alloc(32, 0))];
402
+ case 0: return [4 /*yield*/, this.client.signPsbt(psbt, walletPolicy, Buffer.alloc(32, 0), progressCallback)];
365
403
  case 1:
366
404
  sigs = _a.sent();
367
405
  sigs.forEach(function (v, k) {
368
- // Note: Looking at BIP32 derivation does not work in the generic case.
369
- // some inputs might not have a BIP32-derived pubkey.
406
+ // Note: Looking at BIP32 derivation does not work in the generic case,
407
+ // since some inputs might not have a BIP32-derived pubkey.
370
408
  var pubkeys = psbt.getInputKeyDatas(k, psbtv2_1.psbtIn.BIP32_DERIVATION);
371
409
  var pubkey;
372
410
  if (pubkeys.length != 1) {
@@ -382,9 +420,7 @@ var BtcNew = /** @class */ (function () {
382
420
  psbt.setInputPartialSig(k, pubkey, v);
383
421
  }
384
422
  });
385
- (0, psbtFinalizer_1.finalize)(psbt);
386
- serializedTx = (0, psbtExtractor_1.extract)(psbt);
387
- return [2 /*return*/, serializedTx.toString("hex")];
423
+ return [2 /*return*/];
388
424
  }
389
425
  });
390
426
  });
@@ -392,90 +428,24 @@ var BtcNew = /** @class */ (function () {
392
428
  return BtcNew;
393
429
  }());
394
430
  exports["default"] = BtcNew;
395
- var AccountType;
396
- (function (AccountType) {
397
- AccountType["p2pkh"] = "pkh(@0)";
398
- AccountType["p2wpkh"] = "wpkh(@0)";
399
- AccountType["p2wpkhWrapped"] = "sh(wpkh(@0))";
400
- AccountType["p2tr"] = "tr(@0)";
401
- })(AccountType || (AccountType = {}));
402
- function createRedeemScript(pubkey) {
403
- var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
404
- return Buffer.concat([Buffer.from("0014", "hex"), pubkeyHash]);
405
- }
406
- function outputScriptOf(pubkey, accountType) {
407
- var buf = new buffertools_1.BufferWriter();
408
- var pubkeyHash = (0, hashPublicKey_1.hashPublicKey)(pubkey);
409
- var redeemScript;
410
- if (accountType == AccountType.p2pkh) {
411
- buf.writeSlice(Buffer.of(constants_1.OP_DUP, constants_1.OP_HASH160, constants_1.HASH_SIZE));
412
- buf.writeSlice(pubkeyHash);
413
- buf.writeSlice(Buffer.of(constants_1.OP_EQUALVERIFY, constants_1.OP_CHECKSIG));
414
- }
415
- else if (accountType == AccountType.p2wpkhWrapped) {
416
- redeemScript = createRedeemScript(pubkey);
417
- var scriptHash = (0, hashPublicKey_1.hashPublicKey)(redeemScript);
418
- buf.writeSlice(Buffer.of(constants_1.OP_HASH160, constants_1.HASH_SIZE));
419
- buf.writeSlice(scriptHash);
420
- buf.writeUInt8(constants_1.OP_EQUAL);
421
- }
422
- else if (accountType == AccountType.p2wpkh) {
423
- buf.writeSlice(Buffer.of(0, constants_1.HASH_SIZE));
424
- buf.writeSlice(pubkeyHash);
425
- }
426
- else if (accountType == AccountType.p2tr) {
427
- console.log("Internal key: " + pubkey.toString("hex"));
428
- var outputKey = getTaprootOutputKey(pubkey);
429
- buf.writeSlice(Buffer.of(0x51, 32)); // push1, pubkeylen
430
- buf.writeSlice(outputKey);
431
- }
432
- return { script: buf.buffer(), redeemScript: redeemScript };
433
- }
434
- function accountTypeFrom(addressFormat) {
431
+ function descrTemplFrom(addressFormat) {
435
432
  if (addressFormat == "legacy")
436
- return AccountType.p2pkh;
433
+ return "pkh(@0)";
437
434
  if (addressFormat == "p2sh")
438
- return AccountType.p2wpkhWrapped;
435
+ return "sh(wpkh(@0))";
439
436
  if (addressFormat == "bech32")
440
- return AccountType.p2wpkh;
437
+ return "wpkh(@0)";
441
438
  if (addressFormat == "bech32m")
442
- return AccountType.p2tr;
439
+ return "tr(@0)";
443
440
  throw new Error("Unsupported address format " + addressFormat);
444
441
  }
445
- function accountTypeFromArg(arg) {
442
+ function accountTypeFromArg(arg, psbt, masterFp) {
446
443
  if (arg.additionals.includes("bech32m"))
447
- return AccountType.p2tr;
444
+ return new accounttype_1.p2tr(psbt, masterFp);
448
445
  if (arg.additionals.includes("bech32"))
449
- return AccountType.p2wpkh;
446
+ return new accounttype_1.p2wpkh(psbt, masterFp);
450
447
  if (arg.segwit)
451
- return AccountType.p2wpkhWrapped;
452
- return AccountType.p2pkh;
453
- }
454
- /*
455
- The following two functions are copied from wallet-btc and adapte.
456
- They should be moved to a library to avoid code reuse.
457
- */
458
- function hashTapTweak(x) {
459
- // hash_tag(x) = SHA256(SHA256(tag) || SHA256(tag) || x), see BIP340
460
- // See https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification
461
- var h = bitcoinjs_lib_1.crypto.sha256(Buffer.from("TapTweak", "utf-8"));
462
- return bitcoinjs_lib_1.crypto.sha256(Buffer.concat([h, h, x]));
463
- }
464
- function getTaprootOutputKey(internalPubkey) {
465
- if (internalPubkey.length != 32) {
466
- throw new Error("Expected 32 byte pubkey. Got " + internalPubkey.length);
467
- }
468
- // A BIP32 derived key can be converted to a schnorr pubkey by dropping
469
- // the first byte, which represent the oddness/evenness. In schnorr all
470
- // pubkeys are even.
471
- // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-conversion
472
- var evenEcdsaPubkey = Buffer.concat([Buffer.of(0x02), internalPubkey]);
473
- var tweak = hashTapTweak(internalPubkey);
474
- // Q = P + int(hash_TapTweak(bytes(P)))G
475
- var outputEcdsaKey = Buffer.from((0, tiny_secp256k1_1.pointAddScalar)(evenEcdsaPubkey, tweak));
476
- // Convert to schnorr.
477
- var outputSchnorrKey = outputEcdsaKey.slice(1);
478
- // Create address
479
- return outputSchnorrKey;
448
+ return new accounttype_1.p2wpkhWrapped(psbt, masterFp);
449
+ return new accounttype_1.p2pkh(psbt, masterFp);
480
450
  }
481
451
  //# sourceMappingURL=BtcNew.js.map
package/lib/BtcNew.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"BtcNew.js","sourceRoot":"","sources":["../src/BtcNew.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAuC;AACvC,iCAMiB;AACjB,6CAA2D;AAG3D,iDAAgD;AAEhD,0CAA0D;AAC1D,wDAAiD;AACjD,wDAAkD;AAClD,0CAAiD;AACjD,+DAA8D;AAE9D,iDAA+D;AAC/D,yCAOqB;AAER,QAAA,gBAAgB,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAE5D;IACE,gB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