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