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