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