@ledgerhq/hw-app-btc 10.0.1 → 10.0.2-next.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 (165) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/lib/Btc.d.ts.map +1 -1
  3. package/lib/Btc.js +72 -97
  4. package/lib/Btc.js.map +1 -1
  5. package/lib/BtcNew.js +217 -313
  6. package/lib/BtcNew.js.map +1 -1
  7. package/lib/BtcOld.js +46 -106
  8. package/lib/BtcOld.js.map +1 -1
  9. package/lib/bip32.js +12 -12
  10. package/lib/bip32.js.map +1 -1
  11. package/lib/buffertools.js +66 -69
  12. package/lib/buffertools.js.map +1 -1
  13. package/lib/compressPublicKey.js +3 -3
  14. package/lib/compressPublicKey.js.map +1 -1
  15. package/lib/constants.js +1 -1
  16. package/lib/createTransaction.d.ts +1 -1
  17. package/lib/createTransaction.d.ts.map +1 -1
  18. package/lib/createTransaction.js +285 -398
  19. package/lib/createTransaction.js.map +1 -1
  20. package/lib/debug.js +11 -13
  21. package/lib/debug.js.map +1 -1
  22. package/lib/finalizeInput.js +23 -62
  23. package/lib/finalizeInput.js.map +1 -1
  24. package/lib/getAppAndVersion.d.ts +1 -1
  25. package/lib/getAppAndVersion.d.ts.map +1 -1
  26. package/lib/getAppAndVersion.js +29 -72
  27. package/lib/getAppAndVersion.js.map +1 -1
  28. package/lib/getTrustedInput.js +108 -251
  29. package/lib/getTrustedInput.js.map +1 -1
  30. package/lib/getTrustedInputBIP143.js +9 -10
  31. package/lib/getTrustedInputBIP143.js.map +1 -1
  32. package/lib/getWalletPublicKey.d.ts +1 -1
  33. package/lib/getWalletPublicKey.d.ts.map +1 -1
  34. package/lib/getWalletPublicKey.js +27 -73
  35. package/lib/getWalletPublicKey.js.map +1 -1
  36. package/lib/hashPublicKey.js +4 -4
  37. package/lib/hashPublicKey.js.map +1 -1
  38. package/lib/index.js +3 -3
  39. package/lib/index.js.map +1 -1
  40. package/lib/newops/accounttype.d.ts +2 -2
  41. package/lib/newops/accounttype.d.ts.map +1 -1
  42. package/lib/newops/accounttype.js +85 -125
  43. package/lib/newops/accounttype.js.map +1 -1
  44. package/lib/newops/appClient.js +98 -205
  45. package/lib/newops/appClient.js.map +1 -1
  46. package/lib/newops/clientCommands.js +122 -213
  47. package/lib/newops/clientCommands.js.map +1 -1
  48. package/lib/newops/merkelizedPsbt.js +28 -75
  49. package/lib/newops/merkelizedPsbt.js.map +1 -1
  50. package/lib/newops/merkle.js +38 -67
  51. package/lib/newops/merkle.js.map +1 -1
  52. package/lib/newops/merkleMap.js +11 -12
  53. package/lib/newops/merkleMap.js.map +1 -1
  54. package/lib/newops/policy.d.ts +1 -1
  55. package/lib/newops/policy.d.ts.map +1 -1
  56. package/lib/newops/policy.js +17 -18
  57. package/lib/newops/policy.js.map +1 -1
  58. package/lib/newops/psbtExtractor.js +9 -9
  59. package/lib/newops/psbtExtractor.js.map +1 -1
  60. package/lib/newops/psbtFinalizer.js +22 -22
  61. package/lib/newops/psbtFinalizer.js.map +1 -1
  62. package/lib/newops/psbtv2.d.ts +1 -1
  63. package/lib/newops/psbtv2.d.ts.map +1 -1
  64. package/lib/newops/psbtv2.js +227 -286
  65. package/lib/newops/psbtv2.js.map +1 -1
  66. package/lib/serializeTransaction.js +13 -15
  67. package/lib/serializeTransaction.js.map +1 -1
  68. package/lib/shouldUseTrustedInputForSegwit.js +4 -5
  69. package/lib/shouldUseTrustedInputForSegwit.js.map +1 -1
  70. package/lib/signMessage.js +47 -99
  71. package/lib/signMessage.js.map +1 -1
  72. package/lib/signP2SHTransaction.d.ts +1 -1
  73. package/lib/signP2SHTransaction.d.ts.map +1 -1
  74. package/lib/signP2SHTransaction.js +91 -187
  75. package/lib/signP2SHTransaction.js.map +1 -1
  76. package/lib/signTransaction.js +8 -9
  77. package/lib/signTransaction.js.map +1 -1
  78. package/lib/splitTransaction.js +50 -54
  79. package/lib/splitTransaction.js.map +1 -1
  80. package/lib/startUntrustedHashTransactionInput.js +65 -167
  81. package/lib/startUntrustedHashTransactionInput.js.map +1 -1
  82. package/lib/types.js +1 -1
  83. package/lib/varint.js +10 -10
  84. package/lib/varint.js.map +1 -1
  85. package/lib-es/Btc.d.ts.map +1 -1
  86. package/lib-es/Btc.js +58 -84
  87. package/lib-es/Btc.js.map +1 -1
  88. package/lib-es/BtcNew.js +205 -302
  89. package/lib-es/BtcNew.js.map +1 -1
  90. package/lib-es/BtcOld.js +35 -96
  91. package/lib-es/BtcOld.js.map +1 -1
  92. package/lib-es/bip32.js +7 -7
  93. package/lib-es/bip32.js.map +1 -1
  94. package/lib-es/buffertools.js +62 -67
  95. package/lib-es/buffertools.js.map +1 -1
  96. package/lib-es/compressPublicKey.js +2 -2
  97. package/lib-es/compressPublicKey.js.map +1 -1
  98. package/lib-es/constants.js +12 -12
  99. package/lib-es/constants.js.map +1 -1
  100. package/lib-es/createTransaction.d.ts +1 -1
  101. package/lib-es/createTransaction.d.ts.map +1 -1
  102. package/lib-es/createTransaction.js +271 -384
  103. package/lib-es/createTransaction.js.map +1 -1
  104. package/lib-es/debug.js +10 -12
  105. package/lib-es/debug.js.map +1 -1
  106. package/lib-es/finalizeInput.js +20 -59
  107. package/lib-es/finalizeInput.js.map +1 -1
  108. package/lib-es/getAppAndVersion.d.ts +1 -1
  109. package/lib-es/getAppAndVersion.d.ts.map +1 -1
  110. package/lib-es/getAppAndVersion.js +27 -70
  111. package/lib-es/getAppAndVersion.js.map +1 -1
  112. package/lib-es/getTrustedInput.js +104 -247
  113. package/lib-es/getTrustedInput.js.map +1 -1
  114. package/lib-es/getTrustedInputBIP143.js +5 -6
  115. package/lib-es/getTrustedInputBIP143.js.map +1 -1
  116. package/lib-es/getWalletPublicKey.d.ts +1 -1
  117. package/lib-es/getWalletPublicKey.d.ts.map +1 -1
  118. package/lib-es/getWalletPublicKey.js +25 -71
  119. package/lib-es/getWalletPublicKey.js.map +1 -1
  120. package/lib-es/newops/accounttype.d.ts +2 -2
  121. package/lib-es/newops/accounttype.d.ts.map +1 -1
  122. package/lib-es/newops/accounttype.js +79 -123
  123. package/lib-es/newops/accounttype.js.map +1 -1
  124. package/lib-es/newops/appClient.js +92 -200
  125. package/lib-es/newops/appClient.js.map +1 -1
  126. package/lib-es/newops/clientCommands.js +117 -214
  127. package/lib-es/newops/clientCommands.js.map +1 -1
  128. package/lib-es/newops/merkelizedPsbt.js +25 -73
  129. package/lib-es/newops/merkelizedPsbt.js.map +1 -1
  130. package/lib-es/newops/merkle.js +36 -66
  131. package/lib-es/newops/merkle.js.map +1 -1
  132. package/lib-es/newops/merkleMap.js +8 -10
  133. package/lib-es/newops/merkleMap.js.map +1 -1
  134. package/lib-es/newops/policy.d.ts +1 -1
  135. package/lib-es/newops/policy.d.ts.map +1 -1
  136. package/lib-es/newops/policy.js +12 -14
  137. package/lib-es/newops/policy.js.map +1 -1
  138. package/lib-es/newops/psbtExtractor.js +7 -7
  139. package/lib-es/newops/psbtExtractor.js.map +1 -1
  140. package/lib-es/newops/psbtFinalizer.js +19 -19
  141. package/lib-es/newops/psbtFinalizer.js.map +1 -1
  142. package/lib-es/newops/psbtv2.d.ts +1 -1
  143. package/lib-es/newops/psbtv2.d.ts.map +1 -1
  144. package/lib-es/newops/psbtv2.js +225 -286
  145. package/lib-es/newops/psbtv2.js.map +1 -1
  146. package/lib-es/serializeTransaction.js +11 -13
  147. package/lib-es/serializeTransaction.js.map +1 -1
  148. package/lib-es/shouldUseTrustedInputForSegwit.js +1 -2
  149. package/lib-es/shouldUseTrustedInputForSegwit.js.map +1 -1
  150. package/lib-es/signMessage.js +44 -96
  151. package/lib-es/signMessage.js.map +1 -1
  152. package/lib-es/signP2SHTransaction.d.ts +1 -1
  153. package/lib-es/signP2SHTransaction.d.ts.map +1 -1
  154. package/lib-es/signP2SHTransaction.js +84 -180
  155. package/lib-es/signP2SHTransaction.js.map +1 -1
  156. package/lib-es/signTransaction.js +6 -7
  157. package/lib-es/signTransaction.js.map +1 -1
  158. package/lib-es/splitTransaction.js +46 -50
  159. package/lib-es/splitTransaction.js.map +1 -1
  160. package/lib-es/startUntrustedHashTransactionInput.js +62 -164
  161. package/lib-es/startUntrustedHashTransactionInput.js.map +1 -1
  162. package/lib-es/varint.js +9 -9
  163. package/lib-es/varint.js.map +1 -1
  164. package/package.json +5 -6
  165. package/src/Btc.ts +28 -5
@@ -1,46 +1,9 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __values = (this && this.__values) || function(o) {
29
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
30
- if (m) return m.call(o);
31
- if (o && typeof o.length === "number") return {
32
- next: function () {
33
- if (o && i >= o.length) o = void 0;
34
- return { value: o && o[i++], done: !o };
35
- }
36
- };
37
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
38
- };
39
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
40
3
  exports.PsbtV2 = exports.NoSuchEntry = exports.psbtOut = exports.psbtIn = exports.psbtGlobal = void 0;
41
4
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
42
5
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
43
- var buffertools_1 = require("../buffertools");
6
+ const buffertools_1 = require("../buffertools");
44
7
  var psbtGlobal;
45
8
  (function (psbtGlobal) {
46
9
  psbtGlobal[psbtGlobal["TX_VERSION"] = 2] = "TX_VERSION";
@@ -74,14 +37,9 @@ var psbtOut;
74
37
  psbtOut[psbtOut["SCRIPT"] = 4] = "SCRIPT";
75
38
  psbtOut[psbtOut["TAP_BIP32_DERIVATION"] = 7] = "TAP_BIP32_DERIVATION";
76
39
  })(psbtOut = exports.psbtOut || (exports.psbtOut = {}));
77
- var PSBT_MAGIC_BYTES = Buffer.from([0x70, 0x73, 0x62, 0x74, 0xff]);
78
- var NoSuchEntry = /** @class */ (function (_super) {
79
- __extends(NoSuchEntry, _super);
80
- function NoSuchEntry() {
81
- return _super !== null && _super.apply(this, arguments) || this;
82
- }
83
- return NoSuchEntry;
84
- }(Error));
40
+ const PSBT_MAGIC_BYTES = Buffer.from([0x70, 0x73, 0x62, 0x74, 0xff]);
41
+ class NoSuchEntry extends Error {
42
+ }
85
43
  exports.NoSuchEntry = NoSuchEntry;
86
44
  /**
87
45
  * Implements Partially Signed Bitcoin Transaction version 2, BIP370, as
@@ -101,345 +59,341 @@ exports.NoSuchEntry = NoSuchEntry;
101
59
  * This class is made purposefully dumb, so it's easy to add support for
102
60
  * complemantary fields as needed in the future.
103
61
  */
104
- var PsbtV2 = /** @class */ (function () {
105
- function PsbtV2() {
62
+ class PsbtV2 {
63
+ constructor() {
106
64
  this.globalMap = new Map();
107
65
  this.inputMaps = [];
108
66
  this.outputMaps = [];
109
67
  }
110
- PsbtV2.prototype.setGlobalTxVersion = function (version) {
68
+ setGlobalTxVersion(version) {
111
69
  this.setGlobal(psbtGlobal.TX_VERSION, uint32LE(version));
112
- };
113
- PsbtV2.prototype.getGlobalTxVersion = function () {
70
+ }
71
+ getGlobalTxVersion() {
114
72
  return this.getGlobal(psbtGlobal.TX_VERSION).readUInt32LE(0);
115
- };
116
- PsbtV2.prototype.setGlobalFallbackLocktime = function (locktime) {
73
+ }
74
+ setGlobalFallbackLocktime(locktime) {
117
75
  this.setGlobal(psbtGlobal.FALLBACK_LOCKTIME, uint32LE(locktime));
118
- };
119
- PsbtV2.prototype.getGlobalFallbackLocktime = function () {
76
+ }
77
+ getGlobalFallbackLocktime() {
120
78
  var _a;
121
79
  return (_a = this.getGlobalOptional(psbtGlobal.FALLBACK_LOCKTIME)) === null || _a === void 0 ? void 0 : _a.readUInt32LE(0);
122
- };
123
- PsbtV2.prototype.setGlobalInputCount = function (inputCount) {
80
+ }
81
+ setGlobalInputCount(inputCount) {
124
82
  this.setGlobal(psbtGlobal.INPUT_COUNT, varint(inputCount));
125
- };
126
- PsbtV2.prototype.getGlobalInputCount = function () {
83
+ }
84
+ getGlobalInputCount() {
127
85
  return fromVarint(this.getGlobal(psbtGlobal.INPUT_COUNT));
128
- };
129
- PsbtV2.prototype.setGlobalOutputCount = function (outputCount) {
86
+ }
87
+ setGlobalOutputCount(outputCount) {
130
88
  this.setGlobal(psbtGlobal.OUTPUT_COUNT, varint(outputCount));
131
- };
132
- PsbtV2.prototype.getGlobalOutputCount = function () {
89
+ }
90
+ getGlobalOutputCount() {
133
91
  return fromVarint(this.getGlobal(psbtGlobal.OUTPUT_COUNT));
134
- };
135
- PsbtV2.prototype.setGlobalTxModifiable = function (byte) {
92
+ }
93
+ setGlobalTxModifiable(byte) {
136
94
  this.setGlobal(psbtGlobal.TX_MODIFIABLE, byte);
137
- };
138
- PsbtV2.prototype.getGlobalTxModifiable = function () {
95
+ }
96
+ getGlobalTxModifiable() {
139
97
  return this.getGlobalOptional(psbtGlobal.TX_MODIFIABLE);
140
- };
141
- PsbtV2.prototype.setGlobalPsbtVersion = function (psbtVersion) {
98
+ }
99
+ setGlobalPsbtVersion(psbtVersion) {
142
100
  this.setGlobal(psbtGlobal.VERSION, uint32LE(psbtVersion));
143
- };
144
- PsbtV2.prototype.getGlobalPsbtVersion = function () {
101
+ }
102
+ getGlobalPsbtVersion() {
145
103
  return this.getGlobal(psbtGlobal.VERSION).readUInt32LE(0);
146
- };
147
- PsbtV2.prototype.setInputNonWitnessUtxo = function (inputIndex, transaction) {
104
+ }
105
+ setInputNonWitnessUtxo(inputIndex, transaction) {
148
106
  this.setInput(inputIndex, psbtIn.NON_WITNESS_UTXO, b(), transaction);
149
- };
150
- PsbtV2.prototype.getInputNonWitnessUtxo = function (inputIndex) {
107
+ }
108
+ getInputNonWitnessUtxo(inputIndex) {
151
109
  return this.getInputOptional(inputIndex, psbtIn.NON_WITNESS_UTXO, b());
152
- };
153
- PsbtV2.prototype.setInputWitnessUtxo = function (inputIndex, amount, scriptPubKey) {
154
- var buf = new buffertools_1.BufferWriter();
110
+ }
111
+ setInputWitnessUtxo(inputIndex, amount, scriptPubKey) {
112
+ const buf = new buffertools_1.BufferWriter();
155
113
  buf.writeSlice(amount);
156
114
  buf.writeVarSlice(scriptPubKey);
157
115
  this.setInput(inputIndex, psbtIn.WITNESS_UTXO, b(), buf.buffer());
158
- };
159
- PsbtV2.prototype.getInputWitnessUtxo = function (inputIndex) {
160
- var utxo = this.getInputOptional(inputIndex, psbtIn.WITNESS_UTXO, b());
116
+ }
117
+ getInputWitnessUtxo(inputIndex) {
118
+ const utxo = this.getInputOptional(inputIndex, psbtIn.WITNESS_UTXO, b());
161
119
  if (!utxo)
162
120
  return undefined;
163
- var buf = new buffertools_1.BufferReader(utxo);
121
+ const buf = new buffertools_1.BufferReader(utxo);
164
122
  return { amount: buf.readSlice(8), scriptPubKey: buf.readVarSlice() };
165
- };
166
- PsbtV2.prototype.setInputPartialSig = function (inputIndex, pubkey, signature) {
123
+ }
124
+ setInputPartialSig(inputIndex, pubkey, signature) {
167
125
  this.setInput(inputIndex, psbtIn.PARTIAL_SIG, pubkey, signature);
168
- };
169
- PsbtV2.prototype.getInputPartialSig = function (inputIndex, pubkey) {
126
+ }
127
+ getInputPartialSig(inputIndex, pubkey) {
170
128
  return this.getInputOptional(inputIndex, psbtIn.PARTIAL_SIG, pubkey);
171
- };
172
- PsbtV2.prototype.setInputSighashType = function (inputIndex, sigHashtype) {
129
+ }
130
+ setInputSighashType(inputIndex, sigHashtype) {
173
131
  this.setInput(inputIndex, psbtIn.SIGHASH_TYPE, b(), uint32LE(sigHashtype));
174
- };
175
- PsbtV2.prototype.getInputSighashType = function (inputIndex) {
176
- var result = this.getInputOptional(inputIndex, psbtIn.SIGHASH_TYPE, b());
132
+ }
133
+ getInputSighashType(inputIndex) {
134
+ const result = this.getInputOptional(inputIndex, psbtIn.SIGHASH_TYPE, b());
177
135
  if (!result)
178
136
  return undefined;
179
137
  return result.readUInt32LE(0);
180
- };
181
- PsbtV2.prototype.setInputRedeemScript = function (inputIndex, redeemScript) {
138
+ }
139
+ setInputRedeemScript(inputIndex, redeemScript) {
182
140
  this.setInput(inputIndex, psbtIn.REDEEM_SCRIPT, b(), redeemScript);
183
- };
184
- PsbtV2.prototype.getInputRedeemScript = function (inputIndex) {
141
+ }
142
+ getInputRedeemScript(inputIndex) {
185
143
  return this.getInputOptional(inputIndex, psbtIn.REDEEM_SCRIPT, b());
186
- };
187
- PsbtV2.prototype.setInputBip32Derivation = function (inputIndex, pubkey, masterFingerprint, path) {
144
+ }
145
+ setInputBip32Derivation(inputIndex, pubkey, masterFingerprint, path) {
188
146
  if (pubkey.length != 33)
189
147
  throw new Error("Invalid pubkey length: " + pubkey.length);
190
148
  this.setInput(inputIndex, psbtIn.BIP32_DERIVATION, pubkey, this.encodeBip32Derivation(masterFingerprint, path));
191
- };
192
- PsbtV2.prototype.getInputBip32Derivation = function (inputIndex, pubkey) {
193
- var buf = this.getInputOptional(inputIndex, psbtIn.BIP32_DERIVATION, pubkey);
149
+ }
150
+ getInputBip32Derivation(inputIndex, pubkey) {
151
+ const buf = this.getInputOptional(inputIndex, psbtIn.BIP32_DERIVATION, pubkey);
194
152
  if (!buf)
195
153
  return undefined;
196
154
  return this.decodeBip32Derivation(buf);
197
- };
198
- PsbtV2.prototype.setInputFinalScriptsig = function (inputIndex, scriptSig) {
155
+ }
156
+ setInputFinalScriptsig(inputIndex, scriptSig) {
199
157
  this.setInput(inputIndex, psbtIn.FINAL_SCRIPTSIG, b(), scriptSig);
200
- };
201
- PsbtV2.prototype.getInputFinalScriptsig = function (inputIndex) {
158
+ }
159
+ getInputFinalScriptsig(inputIndex) {
202
160
  return this.getInputOptional(inputIndex, psbtIn.FINAL_SCRIPTSIG, b());
203
- };
204
- PsbtV2.prototype.setInputFinalScriptwitness = function (inputIndex, scriptWitness) {
161
+ }
162
+ setInputFinalScriptwitness(inputIndex, scriptWitness) {
205
163
  this.setInput(inputIndex, psbtIn.FINAL_SCRIPTWITNESS, b(), scriptWitness);
206
- };
207
- PsbtV2.prototype.getInputFinalScriptwitness = function (inputIndex) {
164
+ }
165
+ getInputFinalScriptwitness(inputIndex) {
208
166
  return this.getInput(inputIndex, psbtIn.FINAL_SCRIPTWITNESS, b());
209
- };
210
- PsbtV2.prototype.setInputPreviousTxId = function (inputIndex, txid) {
167
+ }
168
+ setInputPreviousTxId(inputIndex, txid) {
211
169
  this.setInput(inputIndex, psbtIn.PREVIOUS_TXID, b(), txid);
212
- };
213
- PsbtV2.prototype.getInputPreviousTxid = function (inputIndex) {
170
+ }
171
+ getInputPreviousTxid(inputIndex) {
214
172
  return this.getInput(inputIndex, psbtIn.PREVIOUS_TXID, b());
215
- };
216
- PsbtV2.prototype.setInputOutputIndex = function (inputIndex, outputIndex) {
173
+ }
174
+ setInputOutputIndex(inputIndex, outputIndex) {
217
175
  this.setInput(inputIndex, psbtIn.OUTPUT_INDEX, b(), uint32LE(outputIndex));
218
- };
219
- PsbtV2.prototype.getInputOutputIndex = function (inputIndex) {
176
+ }
177
+ getInputOutputIndex(inputIndex) {
220
178
  return this.getInput(inputIndex, psbtIn.OUTPUT_INDEX, b()).readUInt32LE(0);
221
- };
222
- PsbtV2.prototype.setInputSequence = function (inputIndex, sequence) {
179
+ }
180
+ setInputSequence(inputIndex, sequence) {
223
181
  this.setInput(inputIndex, psbtIn.SEQUENCE, b(), uint32LE(sequence));
224
- };
225
- PsbtV2.prototype.getInputSequence = function (inputIndex) {
182
+ }
183
+ getInputSequence(inputIndex) {
226
184
  var _a, _b;
227
185
  return ((_b = (_a = this.getInputOptional(inputIndex, psbtIn.SEQUENCE, b())) === null || _a === void 0 ? void 0 : _a.readUInt32LE(0)) !== null && _b !== void 0 ? _b : 0xffffffff);
228
- };
229
- PsbtV2.prototype.setInputTapKeySig = function (inputIndex, sig) {
186
+ }
187
+ setInputTapKeySig(inputIndex, sig) {
230
188
  this.setInput(inputIndex, psbtIn.TAP_KEY_SIG, b(), sig);
231
- };
232
- PsbtV2.prototype.getInputTapKeySig = function (inputIndex) {
189
+ }
190
+ getInputTapKeySig(inputIndex) {
233
191
  return this.getInputOptional(inputIndex, psbtIn.TAP_KEY_SIG, b());
234
- };
235
- PsbtV2.prototype.setInputTapBip32Derivation = function (inputIndex, pubkey, hashes, masterFingerprint, path) {
192
+ }
193
+ setInputTapBip32Derivation(inputIndex, pubkey, hashes, masterFingerprint, path) {
236
194
  if (pubkey.length != 32)
237
195
  throw new Error("Invalid pubkey length: " + pubkey.length);
238
- var buf = this.encodeTapBip32Derivation(hashes, masterFingerprint, path);
196
+ const buf = this.encodeTapBip32Derivation(hashes, masterFingerprint, path);
239
197
  this.setInput(inputIndex, psbtIn.TAP_BIP32_DERIVATION, pubkey, buf);
240
- };
241
- PsbtV2.prototype.getInputTapBip32Derivation = function (inputIndex, pubkey) {
242
- var buf = this.getInput(inputIndex, psbtIn.TAP_BIP32_DERIVATION, pubkey);
198
+ }
199
+ getInputTapBip32Derivation(inputIndex, pubkey) {
200
+ const buf = this.getInput(inputIndex, psbtIn.TAP_BIP32_DERIVATION, pubkey);
243
201
  return this.decodeTapBip32Derivation(buf);
244
- };
245
- PsbtV2.prototype.getInputKeyDatas = function (inputIndex, keyType) {
202
+ }
203
+ getInputKeyDatas(inputIndex, keyType) {
246
204
  return this.getKeyDatas(this.inputMaps[inputIndex], keyType);
247
- };
248
- PsbtV2.prototype.setOutputRedeemScript = function (outputIndex, redeemScript) {
205
+ }
206
+ setOutputRedeemScript(outputIndex, redeemScript) {
249
207
  this.setOutput(outputIndex, psbtOut.REDEEM_SCRIPT, b(), redeemScript);
250
- };
251
- PsbtV2.prototype.getOutputRedeemScript = function (outputIndex) {
208
+ }
209
+ getOutputRedeemScript(outputIndex) {
252
210
  return this.getOutput(outputIndex, psbtOut.REDEEM_SCRIPT, b());
253
- };
254
- PsbtV2.prototype.setOutputBip32Derivation = function (outputIndex, pubkey, masterFingerprint, path) {
211
+ }
212
+ setOutputBip32Derivation(outputIndex, pubkey, masterFingerprint, path) {
255
213
  this.setOutput(outputIndex, psbtOut.BIP_32_DERIVATION, pubkey, this.encodeBip32Derivation(masterFingerprint, path));
256
- };
257
- PsbtV2.prototype.getOutputBip32Derivation = function (outputIndex, pubkey) {
258
- var buf = this.getOutput(outputIndex, psbtOut.BIP_32_DERIVATION, pubkey);
214
+ }
215
+ getOutputBip32Derivation(outputIndex, pubkey) {
216
+ const buf = this.getOutput(outputIndex, psbtOut.BIP_32_DERIVATION, pubkey);
259
217
  return this.decodeBip32Derivation(buf);
260
- };
261
- PsbtV2.prototype.setOutputAmount = function (outputIndex, amount) {
218
+ }
219
+ setOutputAmount(outputIndex, amount) {
262
220
  this.setOutput(outputIndex, psbtOut.AMOUNT, b(), uint64LE(amount));
263
- };
264
- PsbtV2.prototype.getOutputAmount = function (outputIndex) {
265
- var buf = this.getOutput(outputIndex, psbtOut.AMOUNT, b());
221
+ }
222
+ getOutputAmount(outputIndex) {
223
+ const buf = this.getOutput(outputIndex, psbtOut.AMOUNT, b());
266
224
  return (0, buffertools_1.unsafeFrom64bitLE)(buf);
267
- };
268
- PsbtV2.prototype.setOutputScript = function (outputIndex, scriptPubKey) {
225
+ }
226
+ setOutputScript(outputIndex, scriptPubKey) {
269
227
  this.setOutput(outputIndex, psbtOut.SCRIPT, b(), scriptPubKey);
270
- };
271
- PsbtV2.prototype.getOutputScript = function (outputIndex) {
228
+ }
229
+ getOutputScript(outputIndex) {
272
230
  return this.getOutput(outputIndex, psbtOut.SCRIPT, b());
273
- };
274
- PsbtV2.prototype.setOutputTapBip32Derivation = function (outputIndex, pubkey, hashes, fingerprint, path) {
275
- var buf = this.encodeTapBip32Derivation(hashes, fingerprint, path);
231
+ }
232
+ setOutputTapBip32Derivation(outputIndex, pubkey, hashes, fingerprint, path) {
233
+ const buf = this.encodeTapBip32Derivation(hashes, fingerprint, path);
276
234
  this.setOutput(outputIndex, psbtOut.TAP_BIP32_DERIVATION, pubkey, buf);
277
- };
278
- PsbtV2.prototype.getOutputTapBip32Derivation = function (outputIndex, pubkey) {
279
- var buf = this.getOutput(outputIndex, psbtOut.TAP_BIP32_DERIVATION, pubkey);
235
+ }
236
+ getOutputTapBip32Derivation(outputIndex, pubkey) {
237
+ const buf = this.getOutput(outputIndex, psbtOut.TAP_BIP32_DERIVATION, pubkey);
280
238
  return this.decodeTapBip32Derivation(buf);
281
- };
282
- PsbtV2.prototype.deleteInputEntries = function (inputIndex, keyTypes) {
283
- var _this = this;
284
- var map = this.inputMaps[inputIndex];
285
- map.forEach(function (_v, k, m) {
286
- if (_this.isKeyType(k, keyTypes)) {
287
- m["delete"](k);
239
+ }
240
+ deleteInputEntries(inputIndex, keyTypes) {
241
+ const map = this.inputMaps[inputIndex];
242
+ map.forEach((_v, k, m) => {
243
+ if (this.isKeyType(k, keyTypes)) {
244
+ m.delete(k);
288
245
  }
289
246
  });
290
- };
291
- PsbtV2.prototype.copy = function (to) {
247
+ }
248
+ copy(to) {
292
249
  this.copyMap(this.globalMap, to.globalMap);
293
250
  this.copyMaps(this.inputMaps, to.inputMaps);
294
251
  this.copyMaps(this.outputMaps, to.outputMaps);
295
- };
296
- PsbtV2.prototype.copyMaps = function (from, to) {
297
- var _this = this;
298
- from.forEach(function (m, index) {
299
- var to_index = new Map();
300
- _this.copyMap(m, to_index);
252
+ }
253
+ copyMaps(from, to) {
254
+ from.forEach((m, index) => {
255
+ const to_index = new Map();
256
+ this.copyMap(m, to_index);
301
257
  to[index] = to_index;
302
258
  });
303
- };
304
- PsbtV2.prototype.copyMap = function (from, to) {
305
- from.forEach(function (v, k) { return to.set(k, Buffer.from(v)); });
306
- };
307
- PsbtV2.prototype.serialize = function () {
308
- var buf = new buffertools_1.BufferWriter();
259
+ }
260
+ copyMap(from, to) {
261
+ from.forEach((v, k) => to.set(k, Buffer.from(v)));
262
+ }
263
+ serialize() {
264
+ const buf = new buffertools_1.BufferWriter();
309
265
  buf.writeSlice(Buffer.from([0x70, 0x73, 0x62, 0x74, 0xff]));
310
266
  serializeMap(buf, this.globalMap);
311
- this.inputMaps.forEach(function (map) {
267
+ this.inputMaps.forEach((map) => {
312
268
  serializeMap(buf, map);
313
269
  });
314
- this.outputMaps.forEach(function (map) {
270
+ this.outputMaps.forEach((map) => {
315
271
  serializeMap(buf, map);
316
272
  });
317
273
  return buf.buffer();
318
- };
319
- PsbtV2.prototype.deserialize = function (psbt) {
320
- var buf = new buffertools_1.BufferReader(psbt);
274
+ }
275
+ deserialize(psbt) {
276
+ const buf = new buffertools_1.BufferReader(psbt);
321
277
  if (!buf.readSlice(5).equals(PSBT_MAGIC_BYTES)) {
322
278
  throw new Error("Invalid magic bytes");
323
279
  }
324
280
  while (this.readKeyPair(this.globalMap, buf))
325
281
  ;
326
- for (var i = 0; i < this.getGlobalInputCount(); i++) {
282
+ for (let i = 0; i < this.getGlobalInputCount(); i++) {
327
283
  this.inputMaps[i] = new Map();
328
284
  while (this.readKeyPair(this.inputMaps[i], buf))
329
285
  ;
330
286
  }
331
- for (var i = 0; i < this.getGlobalOutputCount(); i++) {
287
+ for (let i = 0; i < this.getGlobalOutputCount(); i++) {
332
288
  this.outputMaps[i] = new Map();
333
289
  while (this.readKeyPair(this.outputMaps[i], buf))
334
290
  ;
335
291
  }
336
- };
337
- PsbtV2.prototype.readKeyPair = function (map, buf) {
338
- var keyLen = buf.readVarInt();
292
+ }
293
+ readKeyPair(map, buf) {
294
+ const keyLen = buf.readVarInt();
339
295
  if (keyLen == 0) {
340
296
  return false;
341
297
  }
342
- var keyType = buf.readUInt8();
343
- var keyData = buf.readSlice(keyLen - 1);
344
- var value = buf.readVarSlice();
298
+ const keyType = buf.readUInt8();
299
+ const keyData = buf.readSlice(keyLen - 1);
300
+ const value = buf.readVarSlice();
345
301
  set(map, keyType, keyData, value);
346
302
  return true;
347
- };
348
- PsbtV2.prototype.getKeyDatas = function (map, keyType) {
349
- var _this = this;
350
- var result = [];
351
- map.forEach(function (_v, k) {
352
- if (_this.isKeyType(k, [keyType])) {
303
+ }
304
+ getKeyDatas(map, keyType) {
305
+ const result = [];
306
+ map.forEach((_v, k) => {
307
+ if (this.isKeyType(k, [keyType])) {
353
308
  result.push(Buffer.from(k.substring(2), "hex"));
354
309
  }
355
310
  });
356
311
  return result;
357
- };
358
- PsbtV2.prototype.isKeyType = function (hexKey, keyTypes) {
359
- var keyType = Buffer.from(hexKey.substring(0, 2), "hex").readUInt8(0);
360
- return keyTypes.some(function (k) { return k == keyType; });
361
- };
362
- PsbtV2.prototype.setGlobal = function (keyType, value) {
363
- var key = new Key(keyType, Buffer.from([]));
312
+ }
313
+ isKeyType(hexKey, keyTypes) {
314
+ const keyType = Buffer.from(hexKey.substring(0, 2), "hex").readUInt8(0);
315
+ return keyTypes.some((k) => k == keyType);
316
+ }
317
+ setGlobal(keyType, value) {
318
+ const key = new Key(keyType, Buffer.from([]));
364
319
  this.globalMap.set(key.toString(), value);
365
- };
366
- PsbtV2.prototype.getGlobal = function (keyType) {
320
+ }
321
+ getGlobal(keyType) {
367
322
  return get(this.globalMap, keyType, b(), false);
368
- };
369
- PsbtV2.prototype.getGlobalOptional = function (keyType) {
323
+ }
324
+ getGlobalOptional(keyType) {
370
325
  return get(this.globalMap, keyType, b(), true);
371
- };
372
- PsbtV2.prototype.setInput = function (index, keyType, keyData, value) {
326
+ }
327
+ setInput(index, keyType, keyData, value) {
373
328
  set(this.getMap(index, this.inputMaps), keyType, keyData, value);
374
- };
375
- PsbtV2.prototype.getInput = function (index, keyType, keyData) {
329
+ }
330
+ getInput(index, keyType, keyData) {
376
331
  return get(this.inputMaps[index], keyType, keyData, false);
377
- };
378
- PsbtV2.prototype.getInputOptional = function (index, keyType, keyData) {
332
+ }
333
+ getInputOptional(index, keyType, keyData) {
379
334
  return get(this.inputMaps[index], keyType, keyData, true);
380
- };
381
- PsbtV2.prototype.setOutput = function (index, keyType, keyData, value) {
335
+ }
336
+ setOutput(index, keyType, keyData, value) {
382
337
  set(this.getMap(index, this.outputMaps), keyType, keyData, value);
383
- };
384
- PsbtV2.prototype.getOutput = function (index, keyType, keyData) {
338
+ }
339
+ getOutput(index, keyType, keyData) {
385
340
  return get(this.outputMaps[index], keyType, keyData, false);
386
- };
387
- PsbtV2.prototype.getMap = function (index, maps) {
341
+ }
342
+ getMap(index, maps) {
388
343
  if (maps[index]) {
389
344
  return maps[index];
390
345
  }
391
346
  return (maps[index] = new Map());
392
- };
393
- PsbtV2.prototype.encodeBip32Derivation = function (masterFingerprint, path) {
394
- var buf = new buffertools_1.BufferWriter();
347
+ }
348
+ encodeBip32Derivation(masterFingerprint, path) {
349
+ const buf = new buffertools_1.BufferWriter();
395
350
  this.writeBip32Derivation(buf, masterFingerprint, path);
396
351
  return buf.buffer();
397
- };
398
- PsbtV2.prototype.decodeBip32Derivation = function (buffer) {
399
- var buf = new buffertools_1.BufferReader(buffer);
352
+ }
353
+ decodeBip32Derivation(buffer) {
354
+ const buf = new buffertools_1.BufferReader(buffer);
400
355
  return this.readBip32Derivation(buf);
401
- };
402
- PsbtV2.prototype.writeBip32Derivation = function (buf, masterFingerprint, path) {
356
+ }
357
+ writeBip32Derivation(buf, masterFingerprint, path) {
403
358
  buf.writeSlice(masterFingerprint);
404
- path.forEach(function (element) {
359
+ path.forEach((element) => {
405
360
  buf.writeUInt32(element);
406
361
  });
407
- };
408
- PsbtV2.prototype.readBip32Derivation = function (buf) {
409
- var masterFingerprint = buf.readSlice(4);
410
- var path = [];
362
+ }
363
+ readBip32Derivation(buf) {
364
+ const masterFingerprint = buf.readSlice(4);
365
+ const path = [];
411
366
  while (buf.offset < buf.buffer.length) {
412
367
  path.push(buf.readUInt32());
413
368
  }
414
- return { masterFingerprint: masterFingerprint, path: path };
415
- };
416
- PsbtV2.prototype.encodeTapBip32Derivation = function (hashes, masterFingerprint, path) {
417
- var buf = new buffertools_1.BufferWriter();
369
+ return { masterFingerprint, path };
370
+ }
371
+ encodeTapBip32Derivation(hashes, masterFingerprint, path) {
372
+ const buf = new buffertools_1.BufferWriter();
418
373
  buf.writeVarInt(hashes.length);
419
- hashes.forEach(function (h) {
374
+ hashes.forEach((h) => {
420
375
  buf.writeSlice(h);
421
376
  });
422
377
  this.writeBip32Derivation(buf, masterFingerprint, path);
423
378
  return buf.buffer();
424
- };
425
- PsbtV2.prototype.decodeTapBip32Derivation = function (buffer) {
426
- var buf = new buffertools_1.BufferReader(buffer);
427
- var hashCount = buf.readVarInt();
428
- var hashes = [];
429
- for (var i = 0; i < hashCount; i++) {
379
+ }
380
+ decodeTapBip32Derivation(buffer) {
381
+ const buf = new buffertools_1.BufferReader(buffer);
382
+ const hashCount = buf.readVarInt();
383
+ const hashes = [];
384
+ for (let i = 0; i < hashCount; i++) {
430
385
  hashes.push(buf.readSlice(32));
431
386
  }
432
- var deriv = this.readBip32Derivation(buf);
433
- return __assign({ hashes: hashes }, deriv);
434
- };
435
- return PsbtV2;
436
- }());
387
+ const deriv = this.readBip32Derivation(buf);
388
+ return Object.assign({ hashes }, deriv);
389
+ }
390
+ }
437
391
  exports.PsbtV2 = PsbtV2;
438
392
  function get(map, keyType, keyData, acceptUndefined) {
439
393
  if (!map)
440
394
  throw Error("No such map");
441
- var key = new Key(keyType, keyData);
442
- var value = map.get(key.toString());
395
+ const key = new Key(keyType, keyData);
396
+ const value = map.get(key.toString());
443
397
  if (!value) {
444
398
  if (acceptUndefined) {
445
399
  return undefined;
@@ -449,56 +403,43 @@ function get(map, keyType, keyData, acceptUndefined) {
449
403
  // Make sure to return a copy, to protect the underlying data.
450
404
  return Buffer.from(value);
451
405
  }
452
- var Key = /** @class */ (function () {
453
- function Key(keyType, keyData) {
406
+ class Key {
407
+ constructor(keyType, keyData) {
454
408
  this.keyType = keyType;
455
409
  this.keyData = keyData;
456
410
  }
457
- Key.prototype.toString = function () {
458
- var buf = new buffertools_1.BufferWriter();
411
+ toString() {
412
+ const buf = new buffertools_1.BufferWriter();
459
413
  this.toBuffer(buf);
460
414
  return buf.buffer().toString("hex");
461
- };
462
- Key.prototype.serialize = function (buf) {
415
+ }
416
+ serialize(buf) {
463
417
  buf.writeVarInt(1 + this.keyData.length);
464
418
  this.toBuffer(buf);
465
- };
466
- Key.prototype.toBuffer = function (buf) {
419
+ }
420
+ toBuffer(buf) {
467
421
  buf.writeUInt8(this.keyType);
468
422
  buf.writeSlice(this.keyData);
469
- };
470
- return Key;
471
- }());
472
- var KeyPair = /** @class */ (function () {
473
- function KeyPair(key, value) {
423
+ }
424
+ }
425
+ class KeyPair {
426
+ constructor(key, value) {
474
427
  this.key = key;
475
428
  this.value = value;
476
429
  }
477
- KeyPair.prototype.serialize = function (buf) {
430
+ serialize(buf) {
478
431
  this.key.serialize(buf);
479
432
  buf.writeVarSlice(this.value);
480
- };
481
- return KeyPair;
482
- }());
433
+ }
434
+ }
483
435
  function createKey(buf) {
484
436
  return new Key(buf.readUInt8(0), buf.slice(1));
485
437
  }
486
438
  function serializeMap(buf, map) {
487
- var e_1, _a;
488
- try {
489
- for (var _b = __values(map.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
490
- var k = _c.value;
491
- var value = map.get(k);
492
- var keyPair = new KeyPair(createKey(Buffer.from(k, "hex")), value);
493
- keyPair.serialize(buf);
494
- }
495
- }
496
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
497
- finally {
498
- try {
499
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
500
- }
501
- finally { if (e_1) throw e_1.error; }
439
+ for (const k of map.keys()) {
440
+ const value = map.get(k);
441
+ const keyPair = new KeyPair(createKey(Buffer.from(k, "hex")), value);
442
+ keyPair.serialize(buf);
502
443
  }
503
444
  buf.writeUInt8(0);
504
445
  }
@@ -506,11 +447,11 @@ function b() {
506
447
  return Buffer.from([]);
507
448
  }
508
449
  function set(map, keyType, keyData, value) {
509
- var key = new Key(keyType, keyData);
450
+ const key = new Key(keyType, keyData);
510
451
  map.set(key.toString(), value);
511
452
  }
512
453
  function uint32LE(n) {
513
- var b = Buffer.alloc(4);
454
+ const b = Buffer.alloc(4);
514
455
  b.writeUInt32LE(n, 0);
515
456
  return b;
516
457
  }
@@ -518,7 +459,7 @@ function uint64LE(n) {
518
459
  return (0, buffertools_1.unsafeTo64bitLE)(n);
519
460
  }
520
461
  function varint(n) {
521
- var b = new buffertools_1.BufferWriter();
462
+ const b = new buffertools_1.BufferWriter();
522
463
  b.writeVarInt(n);
523
464
  return b.buffer();
524
465
  }