@ledgerhq/hw-app-btc 6.10.0 → 6.12.0

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 (114) hide show
  1. package/README.md +384 -60
  2. package/lib/Btc.d.ts +9 -6
  3. package/lib/Btc.d.ts.map +1 -1
  4. package/lib/Btc.js +73 -8
  5. package/lib/Btc.js.map +1 -1
  6. package/lib/BtcNew.d.ts +79 -32
  7. package/lib/BtcNew.d.ts.map +1 -1
  8. package/lib/BtcNew.js +168 -207
  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 +73 -8
  53. package/lib-es/Btc.js.map +1 -1
  54. package/lib-es/BtcNew.d.ts +79 -32
  55. package/lib-es/BtcNew.d.ts.map +1 -1
  56. package/lib-es/BtcNew.js +170 -209
  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 +3 -3
  99. package/src/Btc.ts +111 -9
  100. package/src/BtcNew.ts +204 -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.test.ts +89 -0
  112. package/tests/newops/BtcNew.test.ts +48 -21
  113. package/tests/newops/integrationtools.ts +47 -36
  114. 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,26 +35,68 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
35
  }
47
36
  };
48
37
  import { crypto } from "bitcoinjs-lib";
49
- import { pointCompress, pointAddScalar } from "tiny-secp256k1";
50
38
  import semver from "semver";
39
+ import { pointCompress } from "tiny-secp256k1";
51
40
  import { getXpubComponents, hardenedPathOf, pathArrayToString, pathStringToArray, pubkeyFromXpub, } from "./bip32";
52
- import { BufferReader, BufferWriter } from "./buffertools";
53
- import { hashPublicKey } from "./hashPublicKey";
54
- 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";
55
44
  import { extract } from "./newops/psbtExtractor";
56
45
  import { finalize } from "./newops/psbtFinalizer";
57
46
  import { psbtIn, PsbtV2 } from "./newops/psbtv2";
58
47
  import { serializeTransaction } from "./serializeTransaction";
59
- import { HASH_SIZE, OP_CHECKSIG, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH160, } from "./constants";
60
48
  var newSupportedApps = ["Bitcoin", "Bitcoin Test"];
61
49
  export function canSupportApp(appAndVersion) {
62
50
  return (newSupportedApps.includes(appAndVersion.name) &&
63
51
  semver.major(appAndVersion.version) >= 2);
64
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
+ */
65
66
  var BtcNew = /** @class */ (function () {
66
67
  function BtcNew(client) {
67
68
  this.client = client;
68
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
+ */
69
100
  BtcNew.prototype.getWalletXpub = function (_a) {
70
101
  var path = _a.path, xpubVersion = _a.xpubVersion;
71
102
  return __awaiter(this, void 0, void 0, function () {
@@ -74,7 +105,7 @@ var BtcNew = /** @class */ (function () {
74
105
  switch (_b.label) {
75
106
  case 0:
76
107
  pathElements = pathStringToArray(path);
77
- return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
108
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
78
109
  case 1:
79
110
  xpub = _b.sent();
80
111
  xpubComponents = getXpubComponents(xpub);
@@ -86,6 +117,13 @@ var BtcNew = /** @class */ (function () {
86
117
  });
87
118
  });
88
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
+ */
89
127
  BtcNew.prototype.getWalletPublicKey = function (path, opts) {
90
128
  var _a, _b;
91
129
  return __awaiter(this, void 0, void 0, function () {
@@ -94,11 +132,11 @@ var BtcNew = /** @class */ (function () {
94
132
  switch (_c.label) {
95
133
  case 0:
96
134
  pathElements = pathStringToArray(path);
97
- return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
135
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
98
136
  case 1:
99
137
  xpub = _c.sent();
100
138
  display = (_a = opts === null || opts === void 0 ? void 0 : opts.verify) !== null && _a !== void 0 ? _a : false;
101
- 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)];
102
140
  case 2:
103
141
  address = _c.sent();
104
142
  components = getXpubComponents(xpub);
@@ -121,13 +159,13 @@ var BtcNew = /** @class */ (function () {
121
159
  *
122
160
  * If display is false we *could* generate the address ourselves, but chose to
123
161
  * get it from the device to save development time. However, it shouldn't take
124
- * more than a few hours to implement local address generation.
162
+ * too much time to implement local address generation.
125
163
  *
126
164
  * Moreover, if the path is not for a leaf, ie accountPath+/X/Y, there is no
127
165
  * way to get the address from the device. In this case we have to create it
128
166
  * ourselves, but we don't at this time, and instead return an empty ("") address.
129
167
  */
130
- BtcNew.prototype.getWalletAddress = function (pathElements, accountType, display) {
168
+ BtcNew.prototype.getWalletAddress = function (pathElements, descrTempl, display) {
131
169
  return __awaiter(this, void 0, void 0, function () {
132
170
  var accountPath, accountXpub, masterFingerprint, policy, changeAndIndex;
133
171
  return __generator(this, function (_a) {
@@ -137,13 +175,13 @@ var BtcNew = /** @class */ (function () {
137
175
  if (accountPath.length + 2 != pathElements.length) {
138
176
  return [2 /*return*/, ""];
139
177
  }
140
- return [4 /*yield*/, this.client.getPubkey(false, accountPath)];
178
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, accountPath)];
141
179
  case 1:
142
180
  accountXpub = _a.sent();
143
181
  return [4 /*yield*/, this.client.getMasterFingerprint()];
144
182
  case 2:
145
183
  masterFingerprint = _a.sent();
146
- policy = new WalletPolicy(accountType, createKey(masterFingerprint, accountPath, accountXpub));
184
+ policy = new WalletPolicy(descrTempl, createKey(masterFingerprint, accountPath, accountXpub));
147
185
  changeAndIndex = pathElements.slice(-2, pathElements.length);
148
186
  return [2 /*return*/, this.client.getWalletAddress(policy, Buffer.alloc(32, 0), changeAndIndex[0], changeAndIndex[1], display)];
149
187
  }
@@ -151,75 +189,62 @@ var BtcNew = /** @class */ (function () {
151
189
  });
152
190
  };
153
191
  /**
154
- * To sign a transaction involving standard (P2PKH) inputs, call createTransaction with the following parameters
155
- * @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.
156
194
  *
157
- * * transaction is the previously computed transaction object for this UTXO
158
- * * output_index is the output in the transaction used as input for this UTXO (counting from 0)
159
- * * redeem script is the optional redeem script to use when consuming a Segregated Witness input
160
- * * sequence is the sequence number to use for this input (when using RBF), or non present
161
- * @param associatedKeysets is an array of BIP 32 paths pointing to the path to the private key used for each UTXO
162
- * @param changePath is an optional BIP 32 path pointing to the path to the public key used to compute the change address
163
- * @param outputScriptHex is the hexadecimal serialized outputs of the transaction to sign, including leading vararg voutCount
164
- * @param lockTime is the optional lockTime of the transaction to sign, or default (0)
165
- * @param sigHashType is the hash type of the transaction to sign, or default (all)
166
- * @param segwit is an optional boolean indicating wether to use segwit or not. This includes wrapped segwit.
167
- * @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)
168
- * @param additionals list of additionnal options
169
- *
170
- * - "bech32" for spending native segwit outputs
171
- * - "bech32m" for spending segwit v1+ outptus
172
- * - "abc" for bch
173
- * - "gold" for btg
174
- * - "bipxxx" for using BIPxxx
175
- * - "sapling" to indicate a zec transaction is supporting sapling (to be set over block 419200)
176
- * @param expiryHeight is an optional Buffer for zec overwinter / sapling Txs
177
- * @param useTrustedInputForSegwit trust inputs for segwit transactions. If app version >= 1.4.0 this should be true.
178
- * @return the signed transaction ready to be broadcast
179
- * @example
180
- btc.createTransaction({
181
- inputs: [ [tx1, 1] ],
182
- associatedKeysets: ["0'/0/0"],
183
- outputScriptHex: "01905f0100000000001976a91472a5d75c8d2d0565b656a5232703b167d50d5a2b88ac"
184
- }).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.
185
198
  */
186
199
  BtcNew.prototype.createPaymentTransactionNew = function (arg) {
187
200
  return __awaiter(this, void 0, void 0, function () {
188
- 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;
189
202
  return __generator(this, function (_a) {
190
203
  switch (_a.label) {
191
204
  case 0:
192
- if (arg.inputs.length == 0) {
205
+ inputCount = arg.inputs.length;
206
+ if (inputCount == 0) {
193
207
  throw Error("No inputs");
194
208
  }
195
209
  psbt = new PsbtV2();
196
- accountType = accountTypeFromArg(arg);
197
- psbt.setGlobalTxVersion(2);
210
+ return [4 /*yield*/, this.client.getMasterFingerprint()];
211
+ case 1:
212
+ masterFp = _a.sent();
213
+ accountType = accountTypeFromArg(arg, psbt, masterFp);
198
214
  if (arg.lockTime) {
215
+ // The signer will assume locktime 0 if unset
199
216
  psbt.setGlobalFallbackLocktime(arg.lockTime);
200
217
  }
201
- psbt.setGlobalInputCount(arg.inputs.length);
218
+ psbt.setGlobalInputCount(inputCount);
202
219
  psbt.setGlobalPsbtVersion(2);
203
220
  psbt.setGlobalTxVersion(2);
204
- return [4 /*yield*/, this.client.getMasterFingerprint()];
205
- case 1:
206
- 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
+ };
207
231
  accountXpub = "";
208
232
  accountPath = [];
209
233
  i = 0;
210
234
  _a.label = 2;
211
235
  case 2:
212
- if (!(i < arg.inputs.length)) return [3 /*break*/, 7];
236
+ if (!(i < inputCount)) return [3 /*break*/, 7];
237
+ progress();
213
238
  pathElems = pathStringToArray(arg.associatedKeysets[i]);
214
239
  if (!(accountXpub == "")) return [3 /*break*/, 4];
215
240
  // We assume all inputs belong to the same account so we set
216
241
  // the account xpub and path based on the first input.
217
242
  accountPath = pathElems.slice(0, -2);
218
- return [4 /*yield*/, this.client.getPubkey(false, accountPath)];
243
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, accountPath)];
219
244
  case 3:
220
245
  accountXpub = _a.sent();
221
246
  _a.label = 4;
222
- 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)];
223
248
  case 5:
224
249
  _a.sent();
225
250
  _a.label = 6;
@@ -230,52 +255,63 @@ var BtcNew = /** @class */ (function () {
230
255
  outputsConcat = Buffer.from(arg.outputScriptHex, "hex");
231
256
  outputsBufferReader = new BufferReader(outputsConcat);
232
257
  outputCount = outputsBufferReader.readVarInt();
258
+ psbt.setGlobalOutputCount(outputCount);
233
259
  return [4 /*yield*/, this.outputScriptAt(accountPath, accountType, arg.changePath)];
234
260
  case 8:
235
261
  changeData = _a.sent();
236
- psbt.setGlobalOutputCount(outputCount);
237
262
  changeFound = !changeData;
238
263
  for (i = 0; i < outputCount; i++) {
239
264
  amount = Number(outputsBufferReader.readUInt64());
240
265
  outputScript = outputsBufferReader.readVarSlice();
241
- 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);
242
269
  if (isChange) {
243
270
  changeFound = true;
244
271
  changePath = pathStringToArray(arg.changePath);
245
272
  pubkey = changeData.pubkey;
246
- if (accountType == AccountType.p2pkh) {
247
- psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
248
- }
249
- else if (accountType == AccountType.p2wpkh) {
250
- psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
251
- }
252
- else if (accountType == AccountType.p2wpkhWrapped) {
253
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
254
- psbt.setOutputRedeemScript(i, changeData.redeemScript);
255
- psbt.setOutputBip32Derivation(i, pubkey, masterFp, changePath);
256
- }
257
- else if (accountType == AccountType.p2tr) {
258
- psbt.setOutputTapBip32Derivation(i, pubkey, [], masterFp, changePath);
259
- }
273
+ accountType.setOwnOutput(i, changeData.cond, [pubkey], [changePath]);
260
274
  }
261
- psbt.setOutputAmount(i, amount);
262
- psbt.setOutputScript(i, outputScript);
263
275
  }
264
276
  if (!changeFound) {
265
277
  throw new Error("Change script not found among outputs! " +
266
- (changeData === null || changeData === void 0 ? void 0 : changeData.script.toString("hex")));
278
+ (changeData === null || changeData === void 0 ? void 0 : changeData.cond.scriptPubKey.toString("hex")));
267
279
  }
268
280
  key = createKey(masterFp, accountPath, accountXpub);
269
- p = new WalletPolicy(accountType, key);
270
- return [4 /*yield*/, this.signPsbt(psbt, p)];
271
- 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")];
272
300
  }
273
301
  });
274
302
  });
275
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
+ */
276
312
  BtcNew.prototype.outputScriptAt = function (accountPath, accountType, path) {
277
313
  return __awaiter(this, void 0, void 0, function () {
278
- var pathElems, i, xpub, pubkey, script;
314
+ var pathElems, i, xpub, pubkey, cond;
279
315
  return __generator(this, function (_a) {
280
316
  switch (_a.label) {
281
317
  case 0:
@@ -289,68 +325,52 @@ var BtcNew = /** @class */ (function () {
289
325
  throw new Error("Path " + path + " not in account " + pathArrayToString(accountPath));
290
326
  }
291
327
  }
292
- return [4 /*yield*/, this.client.getPubkey(false, pathElems)];
328
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElems)];
293
329
  case 1:
294
330
  xpub = _a.sent();
295
331
  pubkey = pubkeyFromXpub(xpub);
296
- if (accountType == AccountType.p2tr) {
297
- pubkey = pubkey.slice(1);
298
- }
299
- script = outputScriptOf(pubkey, accountType);
300
- return [2 /*return*/, __assign(__assign({}, script), { pubkey: pubkey })];
332
+ cond = accountType.spendingCondition([pubkey]);
333
+ return [2 /*return*/, { cond: cond, pubkey: pubkey }];
301
334
  }
302
335
  });
303
336
  });
304
337
  };
305
- 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) {
306
344
  return __awaiter(this, void 0, void 0, function () {
307
- 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;
308
346
  return __generator(this, function (_a) {
309
347
  switch (_a.label) {
310
348
  case 0:
311
349
  inputTx = input[0];
312
350
  spentOutputIndex = input[1];
313
- redeemScript = input[2];
351
+ redeemScript = input[2] ? Buffer.from(input[2], "hex") : undefined;
314
352
  sequence = input[3];
315
353
  if (sequence) {
316
354
  psbt.setInputSequence(i, sequence);
317
355
  }
356
+ if (sigHashType) {
357
+ psbt.setInputSighashType(i, sigHashType);
358
+ }
318
359
  inputTxBuffer = serializeTransaction(inputTx, true);
319
360
  inputTxid = crypto.hash256(inputTxBuffer);
320
- return [4 /*yield*/, this.client.getPubkey(false, pathElements)];
361
+ return [4 /*yield*/, this.client.getExtendedPubkey(false, pathElements)];
321
362
  case 1:
322
363
  xpubBase58 = _a.sent();
323
364
  pubkey = pubkeyFromXpub(xpubBase58);
324
365
  if (!inputTx.outputs)
325
366
  throw Error("Missing outputs array in transaction to sign");
326
- spentOutput = inputTx.outputs[spentOutputIndex];
327
- if (accountType == AccountType.p2pkh) {
328
- psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
329
- psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
330
- }
331
- else if (accountType == AccountType.p2wpkh) {
332
- psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
333
- psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
334
- psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
335
- }
336
- else if (accountType == AccountType.p2wpkhWrapped) {
337
- psbt.setInputNonWitnessUtxo(i, inputTxBuffer);
338
- psbt.setInputBip32Derivation(i, pubkey, masterFP, pathElements);
339
- if (!redeemScript) {
340
- throw new Error("Missing redeemScript for p2wpkhWrapped input");
341
- }
342
- expectedRedeemScript = createRedeemScript(pubkey);
343
- if (redeemScript != expectedRedeemScript.toString("hex")) {
344
- throw new Error("Unexpected redeemScript");
345
- }
346
- psbt.setInputRedeemScript(i, expectedRedeemScript);
347
- psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
348
- }
349
- else if (accountType == AccountType.p2tr) {
350
- xonly = pubkey.slice(1);
351
- psbt.setInputTapBip32Derivation(i, xonly, [], masterFP, pathElements);
352
- psbt.setInputWitnessUtxo(i, spentOutput.amount, spentOutput.script);
353
- }
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]);
354
374
  psbt.setInputPreviousTxId(i, inputTxid);
355
375
  psbt.setInputOutputIndex(i, spentOutputIndex);
356
376
  return [2 /*return*/];
@@ -358,17 +378,26 @@ var BtcNew = /** @class */ (function () {
358
378
  });
359
379
  });
360
380
  };
361
- 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) {
362
391
  return __awaiter(this, void 0, void 0, function () {
363
- var sigs, serializedTx;
392
+ var sigs;
364
393
  return __generator(this, function (_a) {
365
394
  switch (_a.label) {
366
- 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)];
367
396
  case 1:
368
397
  sigs = _a.sent();
369
398
  sigs.forEach(function (v, k) {
370
- // Note: Looking at BIP32 derivation does not work in the generic case.
371
- // 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.
372
401
  var pubkeys = psbt.getInputKeyDatas(k, psbtIn.BIP32_DERIVATION);
373
402
  var pubkey;
374
403
  if (pubkeys.length != 1) {
@@ -384,9 +413,7 @@ var BtcNew = /** @class */ (function () {
384
413
  psbt.setInputPartialSig(k, pubkey, v);
385
414
  }
386
415
  });
387
- finalize(psbt);
388
- serializedTx = extract(psbt);
389
- return [2 /*return*/, serializedTx.toString("hex")];
416
+ return [2 /*return*/];
390
417
  }
391
418
  });
392
419
  });
@@ -394,90 +421,24 @@ var BtcNew = /** @class */ (function () {
394
421
  return BtcNew;
395
422
  }());
396
423
  export default BtcNew;
397
- var AccountType;
398
- (function (AccountType) {
399
- AccountType["p2pkh"] = "pkh(@0)";
400
- AccountType["p2wpkh"] = "wpkh(@0)";
401
- AccountType["p2wpkhWrapped"] = "sh(wpkh(@0))";
402
- AccountType["p2tr"] = "tr(@0)";
403
- })(AccountType || (AccountType = {}));
404
- function createRedeemScript(pubkey) {
405
- var pubkeyHash = hashPublicKey(pubkey);
406
- return Buffer.concat([Buffer.from("0014", "hex"), pubkeyHash]);
407
- }
408
- function outputScriptOf(pubkey, accountType) {
409
- var buf = new BufferWriter();
410
- var pubkeyHash = hashPublicKey(pubkey);
411
- var redeemScript;
412
- if (accountType == AccountType.p2pkh) {
413
- buf.writeSlice(Buffer.of(OP_DUP, OP_HASH160, HASH_SIZE));
414
- buf.writeSlice(pubkeyHash);
415
- buf.writeSlice(Buffer.of(OP_EQUALVERIFY, OP_CHECKSIG));
416
- }
417
- else if (accountType == AccountType.p2wpkhWrapped) {
418
- redeemScript = createRedeemScript(pubkey);
419
- var scriptHash = hashPublicKey(redeemScript);
420
- buf.writeSlice(Buffer.of(OP_HASH160, HASH_SIZE));
421
- buf.writeSlice(scriptHash);
422
- buf.writeUInt8(OP_EQUAL);
423
- }
424
- else if (accountType == AccountType.p2wpkh) {
425
- buf.writeSlice(Buffer.of(0, HASH_SIZE));
426
- buf.writeSlice(pubkeyHash);
427
- }
428
- else if (accountType == AccountType.p2tr) {
429
- console.log("Internal key: " + pubkey.toString("hex"));
430
- var outputKey = getTaprootOutputKey(pubkey);
431
- buf.writeSlice(Buffer.of(0x51, 32)); // push1, pubkeylen
432
- buf.writeSlice(outputKey);
433
- }
434
- return { script: buf.buffer(), redeemScript: redeemScript };
435
- }
436
- function accountTypeFrom(addressFormat) {
424
+ function descrTemplFrom(addressFormat) {
437
425
  if (addressFormat == "legacy")
438
- return AccountType.p2pkh;
426
+ return "pkh(@0)";
439
427
  if (addressFormat == "p2sh")
440
- return AccountType.p2wpkhWrapped;
428
+ return "sh(wpkh(@0))";
441
429
  if (addressFormat == "bech32")
442
- return AccountType.p2wpkh;
430
+ return "wpkh(@0)";
443
431
  if (addressFormat == "bech32m")
444
- return AccountType.p2tr;
432
+ return "tr(@0)";
445
433
  throw new Error("Unsupported address format " + addressFormat);
446
434
  }
447
- function accountTypeFromArg(arg) {
435
+ function accountTypeFromArg(arg, psbt, masterFp) {
448
436
  if (arg.additionals.includes("bech32m"))
449
- return AccountType.p2tr;
437
+ return new p2tr(psbt, masterFp);
450
438
  if (arg.additionals.includes("bech32"))
451
- return AccountType.p2wpkh;
439
+ return new p2wpkh(psbt, masterFp);
452
440
  if (arg.segwit)
453
- return AccountType.p2wpkhWrapped;
454
- return AccountType.p2pkh;
455
- }
456
- /*
457
- The following two functions are copied from wallet-btc and adapte.
458
- They should be moved to a library to avoid code reuse.
459
- */
460
- function hashTapTweak(x) {
461
- // hash_tag(x) = SHA256(SHA256(tag) || SHA256(tag) || x), see BIP340
462
- // See https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#specification
463
- var h = crypto.sha256(Buffer.from("TapTweak", "utf-8"));
464
- return crypto.sha256(Buffer.concat([h, h, x]));
465
- }
466
- function getTaprootOutputKey(internalPubkey) {
467
- if (internalPubkey.length != 32) {
468
- throw new Error("Expected 32 byte pubkey. Got " + internalPubkey.length);
469
- }
470
- // A BIP32 derived key can be converted to a schnorr pubkey by dropping
471
- // the first byte, which represent the oddness/evenness. In schnorr all
472
- // pubkeys are even.
473
- // https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki#public-key-conversion
474
- var evenEcdsaPubkey = Buffer.concat([Buffer.of(0x02), internalPubkey]);
475
- var tweak = hashTapTweak(internalPubkey);
476
- // Q = P + int(hash_TapTweak(bytes(P)))G
477
- var outputEcdsaKey = Buffer.from(pointAddScalar(evenEcdsaPubkey, tweak));
478
- // Convert to schnorr.
479
- var outputSchnorrKey = outputEcdsaKey.slice(1);
480
- // Create address
481
- return outputSchnorrKey;
441
+ return new p2wpkhWrapped(psbt, masterFp);
442
+ return new p2pkh(psbt, masterFp);
482
443
  }
483
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,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,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,EACL,SAAS,EACT,WAAW,EACX,MAAM,EACN,QAAQ,EACR,cAAc,EACd,UAAU,GACX,MAAM,aAAa,CAAC;AAGrB,IAAM,gBAAgB,GAAG,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAErD,MAAM,UAAU,aAAa,CAAC,aAA4B;IACxD,OAAO,CACL,gBAAgB,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CA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