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