@opcat-labs/opcat 1.0.0 → 1.0.2

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 (293) hide show
  1. package/.cjs2esm.json +18 -0
  2. package/.mocharc.yaml +1 -1
  3. package/CHANGELOG.md +13 -0
  4. package/README.md +6 -0
  5. package/{lib/address.js → cjs/address.cjs} +77 -72
  6. package/cjs/block/block.cjs +332 -0
  7. package/{lib/block/blockheader.js → cjs/block/blockheader.cjs} +8 -7
  8. package/cjs/block/index.cjs +2 -0
  9. package/{lib/block/merkleblock.js → cjs/block/merkleblock.cjs} +23 -15
  10. package/cjs/bn.cjs +3411 -0
  11. package/{lib/crypto/bn.js → cjs/crypto/bn.cjs} +3 -3
  12. package/{lib/crypto/ecdsa.js → cjs/crypto/ecdsa.cjs} +150 -14
  13. package/{lib/crypto/hash.node.js → cjs/crypto/hash.cjs} +13 -2
  14. package/cjs/crypto/index.cjs +16 -0
  15. package/{lib/crypto/point.js → cjs/crypto/point.cjs} +11 -4
  16. package/cjs/crypto/random.cjs +18 -0
  17. package/{lib/crypto/signature.js → cjs/crypto/signature.cjs} +158 -8
  18. package/{lib/encoding/base58.js → cjs/encoding/base58.cjs} +58 -2
  19. package/cjs/encoding/base58check.cjs +192 -0
  20. package/cjs/encoding/bufferreader.cjs +333 -0
  21. package/cjs/encoding/bufferwriter.cjs +244 -0
  22. package/{lib/encoding/decode-asm.js → cjs/encoding/decode-asm.cjs} +4 -4
  23. package/{lib/encoding/decode-hex.js → cjs/encoding/decode-hex.cjs} +1 -1
  24. package/cjs/encoding/index.cjs +14 -0
  25. package/cjs/encoding/varint.cjs +116 -0
  26. package/{lib/errors/index.js → cjs/errors/index.cjs} +9 -9
  27. package/{lib/errors/spec.js → cjs/errors/spec.cjs} +2 -2
  28. package/cjs/hash-cache.cjs +98 -0
  29. package/{lib/hdprivatekey.js → cjs/hdprivatekey.cjs} +232 -140
  30. package/{lib/hdpublickey.js → cjs/hdpublickey.cjs} +120 -93
  31. package/cjs/index.cjs +94 -0
  32. package/cjs/interpreter/index.cjs +2 -0
  33. package/cjs/interpreter/interpreter.cjs +1988 -0
  34. package/{lib/script/stack.js → cjs/interpreter/stack.cjs} +9 -2
  35. package/{lib/message/message.js → cjs/message/message.cjs} +62 -25
  36. package/cjs/mnemonic/index.cjs +3 -0
  37. package/{lib/mnemonic/mnemonic.js → cjs/mnemonic/mnemonic.cjs} +44 -13
  38. package/{lib/mnemonic/pbkdf2.node.js → cjs/mnemonic/pbkdf2.cjs} +9 -2
  39. package/cjs/mnemonic/words/index.cjs +66 -0
  40. package/cjs/network.cjs +13 -0
  41. package/cjs/networks.cjs +321 -0
  42. package/{lib/opcode.js → cjs/opcode.cjs} +69 -5
  43. package/cjs/privatekey.cjs +422 -0
  44. package/{lib/publickey.js → cjs/publickey.cjs} +14 -16
  45. package/cjs/script/index.cjs +2 -0
  46. package/{lib/script/script.js → cjs/script/script.cjs} +322 -67
  47. package/cjs/transaction/index.cjs +5 -0
  48. package/cjs/transaction/input/index.cjs +34 -0
  49. package/cjs/transaction/input/input.cjs +396 -0
  50. package/{lib/transaction/input/multisig.js → cjs/transaction/input/multisig.cjs} +112 -18
  51. package/{lib/transaction/input/publickey.js → cjs/transaction/input/publickey.cjs} +29 -19
  52. package/{lib/transaction/input/publickeyhash.js → cjs/transaction/input/publickeyhash.cjs} +25 -17
  53. package/{lib/transaction/output.js → cjs/transaction/output.cjs} +100 -15
  54. package/cjs/transaction/sighash.cjs +187 -0
  55. package/{lib/transaction/signature.js → cjs/transaction/signature.cjs} +30 -6
  56. package/cjs/transaction/transaction.cjs +2000 -0
  57. package/{lib/transaction/unspentoutput.js → cjs/transaction/unspentoutput.cjs} +5 -5
  58. package/cjs/util/derivation.cjs +53 -0
  59. package/cjs/util/index.cjs +11 -0
  60. package/cjs/util/js.cjs +95 -0
  61. package/{lib/util/preconditions.js → cjs/util/preconditions.cjs} +2 -2
  62. package/esm/address.js +483 -0
  63. package/{lib → esm}/block/block.js +82 -27
  64. package/esm/block/blockheader.js +296 -0
  65. package/esm/block/index.js +2 -0
  66. package/esm/block/merkleblock.js +331 -0
  67. package/esm/bn.js +3411 -0
  68. package/esm/crypto/bn.js +278 -0
  69. package/esm/crypto/ecdsa.js +475 -0
  70. package/{lib/crypto/hash.browser.js → esm/crypto/hash.js} +18 -7
  71. package/esm/crypto/index.js +16 -0
  72. package/esm/crypto/point.js +228 -0
  73. package/esm/crypto/random.js +18 -0
  74. package/esm/crypto/signature.js +475 -0
  75. package/esm/encoding/base58.js +167 -0
  76. package/esm/encoding/base58check.js +192 -0
  77. package/esm/encoding/bufferreader.js +333 -0
  78. package/esm/encoding/bufferwriter.js +243 -0
  79. package/esm/encoding/decode-asm.js +24 -0
  80. package/esm/encoding/decode-hex.js +32 -0
  81. package/esm/encoding/decode-script-chunks.js +43 -0
  82. package/esm/encoding/encode-hex.js +284 -0
  83. package/esm/encoding/index.js +14 -0
  84. package/esm/encoding/is-hex.js +7 -0
  85. package/esm/encoding/varint.js +116 -0
  86. package/esm/errors/index.js +54 -0
  87. package/esm/errors/spec.js +314 -0
  88. package/esm/hash-cache.js +98 -0
  89. package/esm/hdprivatekey.js +768 -0
  90. package/esm/hdpublickey.js +549 -0
  91. package/esm/index.js +66 -0
  92. package/esm/interpreter/index.js +2 -0
  93. package/{lib/script → esm/interpreter}/interpreter.js +219 -66
  94. package/esm/interpreter/stack.js +116 -0
  95. package/esm/message/message.js +228 -0
  96. package/esm/mnemonic/index.js +3 -0
  97. package/esm/mnemonic/mnemonic.js +332 -0
  98. package/{lib/mnemonic/pbkdf2.browser.js → esm/mnemonic/pbkdf2.js} +13 -6
  99. package/esm/mnemonic/words/chinese.js +2054 -0
  100. package/esm/mnemonic/words/english.js +2054 -0
  101. package/esm/mnemonic/words/french.js +2054 -0
  102. package/esm/mnemonic/words/index.js +66 -0
  103. package/esm/mnemonic/words/italian.js +2054 -0
  104. package/esm/mnemonic/words/japanese.js +2054 -0
  105. package/esm/mnemonic/words/spanish.js +2054 -0
  106. package/esm/network.js +13 -0
  107. package/{lib → esm}/networks.js +61 -120
  108. package/esm/opcode.js +319 -0
  109. package/{lib → esm}/privatekey.js +76 -28
  110. package/esm/publickey.js +384 -0
  111. package/esm/script/index.js +2 -0
  112. package/esm/script/script.js +1329 -0
  113. package/esm/script/write-i32-le.js +17 -0
  114. package/esm/script/write-push-data.js +35 -0
  115. package/esm/script/write-u16-le.js +12 -0
  116. package/esm/script/write-u32-le.js +16 -0
  117. package/esm/script/write-u64-le.js +24 -0
  118. package/esm/script/write-u8-le.js +8 -0
  119. package/esm/script/write-varint.js +46 -0
  120. package/esm/transaction/index.js +5 -0
  121. package/esm/transaction/input/index.js +33 -0
  122. package/{lib → esm}/transaction/input/input.js +132 -90
  123. package/esm/transaction/input/multisig.js +335 -0
  124. package/esm/transaction/input/publickey.js +108 -0
  125. package/esm/transaction/input/publickeyhash.js +124 -0
  126. package/esm/transaction/output.js +316 -0
  127. package/{lib → esm}/transaction/sighash.js +42 -22
  128. package/esm/transaction/signature.js +120 -0
  129. package/{lib → esm}/transaction/transaction.js +522 -163
  130. package/esm/transaction/unspentoutput.js +112 -0
  131. package/esm/util/_.js +47 -0
  132. package/esm/util/derivation.js +53 -0
  133. package/esm/util/index.js +12 -0
  134. package/esm/util/js.js +95 -0
  135. package/esm/util/preconditions.js +33 -0
  136. package/fixup.cjs +17 -0
  137. package/package.json +40 -26
  138. package/test/{address.js → address.cjs} +14 -43
  139. package/test/block/{block.js → block.cjs} +3 -5
  140. package/test/block/{blockheader.js → blockheader.cjs} +2 -2
  141. package/test/block/{merklebloack.js → merklebloack.cjs} +2 -2
  142. package/test/crypto/{ecdsa.js → ecdsa.cjs} +9 -9
  143. package/test/crypto/{hash.browser.js → hash.browser.cjs} +2 -1
  144. package/test/crypto/{signature.js → signature.cjs} +2 -2
  145. package/test/data/bitcoind/script_tests.json +5 -5
  146. package/test/{hashCache.js → hashCache.cjs} +2 -1
  147. package/test/{hdkeys.js → hdkeys.cjs} +4 -2
  148. package/test/{hdprivatekey.js → hdprivatekey.cjs} +7 -6
  149. package/test/{hdpublickey.js → hdpublickey.cjs} +2 -7
  150. package/test/mnemonic/{pbkdf2.test.js → pbkdf2.test.cjs} +2 -2
  151. package/test/{networks.js → networks.cjs} +12 -31
  152. package/test/{publickey.js → publickey.cjs} +2 -2
  153. package/test/script/{interpreter.js → interpreter.cjs} +5 -5
  154. package/test/script/{script.js → script.cjs} +8 -2
  155. package/test/transaction/{deserialize.js → deserialize.cjs} +2 -2
  156. package/test/transaction/input/{input.js → input.cjs} +1 -1
  157. package/test/transaction/input/{multisig.js → multisig.cjs} +2 -1
  158. package/test/transaction/input/{publickeyhash.js → publickeyhash.cjs} +1 -1
  159. package/test/transaction/{sighash.js → sighash.cjs} +1 -1
  160. package/test/transaction/{transaction.js → transaction.cjs} +2 -2
  161. package/tsconfig.json +13 -0
  162. package/types/address.d.cts +252 -0
  163. package/types/block/block.d.cts +139 -0
  164. package/types/block/blockheader.d.cts +125 -0
  165. package/types/block/index.d.cts +2 -0
  166. package/types/block/merkleblock.d.cts +95 -0
  167. package/types/bn.d.cts +202 -0
  168. package/types/crypto/bn.d.cts +2 -0
  169. package/types/crypto/ecdsa.d.cts +187 -0
  170. package/types/crypto/hash.d.cts +118 -0
  171. package/types/crypto/index.d.cts +7 -0
  172. package/types/crypto/point.d.cts +134 -0
  173. package/types/crypto/random.d.cts +13 -0
  174. package/types/crypto/signature.d.cts +160 -0
  175. package/types/encoding/base58.d.cts +106 -0
  176. package/types/encoding/base58check.d.cts +107 -0
  177. package/types/encoding/bufferreader.d.cts +164 -0
  178. package/types/encoding/bufferwriter.d.cts +126 -0
  179. package/types/encoding/decode-asm.d.cts +2 -0
  180. package/types/encoding/decode-hex.d.cts +2 -0
  181. package/types/encoding/decode-script-chunks.d.cts +14 -0
  182. package/types/encoding/encode-hex.d.cts +2 -0
  183. package/types/encoding/index.d.cts +6 -0
  184. package/types/encoding/is-hex.d.cts +2 -0
  185. package/types/encoding/varint.d.cts +66 -0
  186. package/types/errors/index.d.cts +4 -0
  187. package/types/errors/spec.d.cts +22 -0
  188. package/types/hash-cache.d.cts +65 -0
  189. package/types/hdprivatekey.d.cts +281 -0
  190. package/types/hdpublickey.d.cts +240 -0
  191. package/types/index.d.cts +26 -0
  192. package/types/interpreter/index.d.cts +2 -0
  193. package/types/interpreter/interpreter.d.cts +228 -0
  194. package/types/interpreter/stack.d.cts +35 -0
  195. package/types/message/message.d.cts +110 -0
  196. package/types/mnemonic/index.d.cts +2 -0
  197. package/types/mnemonic/mnemonic.d.cts +171 -0
  198. package/types/mnemonic/pbkdf2.d.cts +14 -0
  199. package/types/mnemonic/words/chinese.d.cts +2 -0
  200. package/types/mnemonic/words/english.d.cts +2 -0
  201. package/types/mnemonic/words/french.d.cts +2 -0
  202. package/types/mnemonic/words/index.d.cts +22 -0
  203. package/types/mnemonic/words/italian.d.cts +2 -0
  204. package/types/mnemonic/words/japanese.d.cts +2 -0
  205. package/types/mnemonic/words/spanish.d.cts +2 -0
  206. package/types/network.d.cts +11 -0
  207. package/types/networks.d.cts +76 -0
  208. package/types/opcode.d.cts +93 -0
  209. package/types/privatekey.d.cts +169 -0
  210. package/types/publickey.d.cts +202 -0
  211. package/types/script/index.d.cts +2 -0
  212. package/types/script/script.d.cts +449 -0
  213. package/types/script/write-i32-le.d.cts +2 -0
  214. package/types/script/write-push-data.d.cts +2 -0
  215. package/types/script/write-u16-le.d.cts +2 -0
  216. package/types/script/write-u32-le.d.cts +2 -0
  217. package/types/script/write-u64-le.d.cts +2 -0
  218. package/types/script/write-u8-le.d.cts +2 -0
  219. package/types/script/write-varint.d.cts +2 -0
  220. package/types/transaction/index.d.cts +2 -0
  221. package/types/transaction/input/index.d.cts +2 -0
  222. package/types/transaction/input/input.d.cts +178 -0
  223. package/types/transaction/input/multisig.d.cts +127 -0
  224. package/types/transaction/input/publickey.d.cts +44 -0
  225. package/types/transaction/input/publickeyhash.d.cts +45 -0
  226. package/types/transaction/output.d.cts +118 -0
  227. package/types/transaction/sighash.d.cts +61 -0
  228. package/types/transaction/signature.d.cts +43 -0
  229. package/types/transaction/transaction.d.cts +716 -0
  230. package/types/transaction/unspentoutput.d.cts +83 -0
  231. package/types/util/_.d.cts +26 -0
  232. package/types/util/derivation.d.cts +21 -0
  233. package/types/util/index.d.cts +5 -0
  234. package/types/util/js.d.cts +50 -0
  235. package/types/util/preconditions.d.cts +3 -0
  236. package/index.d.ts +0 -1541
  237. package/index.js +0 -74
  238. package/lib/block/index.js +0 -4
  239. package/lib/bn.js +0 -3423
  240. package/lib/crypto/hash.js +0 -2
  241. package/lib/crypto/random.browser.js +0 -28
  242. package/lib/crypto/random.js +0 -2
  243. package/lib/crypto/random.node.js +0 -11
  244. package/lib/encoding/base58check.js +0 -121
  245. package/lib/encoding/bufferreader.js +0 -212
  246. package/lib/encoding/bufferwriter.js +0 -140
  247. package/lib/encoding/varint.js +0 -75
  248. package/lib/hash-cache.js +0 -50
  249. package/lib/mnemonic/pbkdf2.js +0 -2
  250. package/lib/mnemonic/words/index.js +0 -8
  251. package/lib/script/index.js +0 -5
  252. package/lib/transaction/index.js +0 -7
  253. package/lib/transaction/input/index.js +0 -5
  254. package/lib/util/js.js +0 -90
  255. /package/{lib/encoding/decode-script-chunks.js → cjs/encoding/decode-script-chunks.cjs} +0 -0
  256. /package/{lib/encoding/encode-hex.js → cjs/encoding/encode-hex.cjs} +0 -0
  257. /package/{lib/encoding/is-hex.js → cjs/encoding/is-hex.cjs} +0 -0
  258. /package/{lib/mnemonic/words/chinese.js → cjs/mnemonic/words/chinese.cjs} +0 -0
  259. /package/{lib/mnemonic/words/english.js → cjs/mnemonic/words/english.cjs} +0 -0
  260. /package/{lib/mnemonic/words/french.js → cjs/mnemonic/words/french.cjs} +0 -0
  261. /package/{lib/mnemonic/words/italian.js → cjs/mnemonic/words/italian.cjs} +0 -0
  262. /package/{lib/mnemonic/words/japanese.js → cjs/mnemonic/words/japanese.cjs} +0 -0
  263. /package/{lib/mnemonic/words/spanish.js → cjs/mnemonic/words/spanish.cjs} +0 -0
  264. /package/{lib/script/write-i32-le.js → cjs/script/write-i32-le.cjs} +0 -0
  265. /package/{lib/script/write-push-data.js → cjs/script/write-push-data.cjs} +0 -0
  266. /package/{lib/script/write-u16-le.js → cjs/script/write-u16-le.cjs} +0 -0
  267. /package/{lib/script/write-u32-le.js → cjs/script/write-u32-le.cjs} +0 -0
  268. /package/{lib/script/write-u64-le.js → cjs/script/write-u64-le.cjs} +0 -0
  269. /package/{lib/script/write-u8-le.js → cjs/script/write-u8-le.cjs} +0 -0
  270. /package/{lib/script/write-varint.js → cjs/script/write-varint.cjs} +0 -0
  271. /package/{lib/util/_.js → cjs/util/_.cjs} +0 -0
  272. /package/test/crypto/{bn.js → bn.cjs} +0 -0
  273. /package/test/crypto/{hash.js → hash.cjs} +0 -0
  274. /package/test/crypto/{point.js → point.cjs} +0 -0
  275. /package/test/crypto/{random.js → random.cjs} +0 -0
  276. /package/test/data/{blk86756-testnet.js → blk86756-testnet.cjs} +0 -0
  277. /package/test/data/{merkleblocks.js → merkleblocks.cjs} +0 -0
  278. /package/test/encoding/{base58.js → base58.cjs} +0 -0
  279. /package/test/encoding/{base58check.js → base58check.cjs} +0 -0
  280. /package/test/encoding/{bufferreader.js → bufferreader.cjs} +0 -0
  281. /package/test/encoding/{bufferwriter.js → bufferwriter.cjs} +0 -0
  282. /package/test/encoding/{varint.js → varint.cjs} +0 -0
  283. /package/test/{index.js → index.cjs} +0 -0
  284. /package/test/message/{message.js → message.cjs} +0 -0
  285. /package/test/mnemonic/{mnemonic.js → mnemonic.cjs} +0 -0
  286. /package/test/{opcode.js → opcode.cjs} +0 -0
  287. /package/test/{privatekey.js → privatekey.cjs} +0 -0
  288. /package/test/transaction/input/{publickey.js → publickey.cjs} +0 -0
  289. /package/test/transaction/{output.js → output.cjs} +0 -0
  290. /package/test/transaction/{signature.js → signature.cjs} +0 -0
  291. /package/test/transaction/{unspentoutput.js → unspentoutput.cjs} +0 -0
  292. /package/test/util/{js.js → js.cjs} +0 -0
  293. /package/test/util/{preconditions.js → preconditions.cjs} +0 -0
@@ -0,0 +1,127 @@
1
+ export = MultiSigInput;
2
+ /**
3
+ * Represents a MultiSigInput for a transaction.
4
+ * @constructor
5
+ * @param {Object} input - The input object containing publicKeys, threshold, and signatures.
6
+ * @param {Array} pubkeys - Array of public keys (optional, defaults to input.publicKeys).
7
+ * @param {number} threshold - Required number of signatures (optional, defaults to input.threshold).
8
+ * @param {Array} signatures - Array of signatures (optional, defaults to input.signatures).
9
+ * @description Validates that provided public keys match the output script and initializes signatures.
10
+ */
11
+ declare function MultiSigInput(input: any, pubkeys: any[], threshold: number, signatures: any[], ...args: any[]): void;
12
+ declare class MultiSigInput {
13
+ /**
14
+ * Represents a MultiSigInput for a transaction.
15
+ * @constructor
16
+ * @param {Object} input - The input object containing publicKeys, threshold, and signatures.
17
+ * @param {Array} pubkeys - Array of public keys (optional, defaults to input.publicKeys).
18
+ * @param {number} threshold - Required number of signatures (optional, defaults to input.threshold).
19
+ * @param {Array} signatures - Array of signatures (optional, defaults to input.signatures).
20
+ * @description Validates that provided public keys match the output script and initializes signatures.
21
+ */
22
+ constructor(input: any, pubkeys: any[], threshold: number, signatures: any[], ...args: any[]);
23
+ publicKeys: PublicKey[];
24
+ publicKeyIndex: {};
25
+ threshold: number;
26
+ signatures: any[];
27
+ /**
28
+ * Converts the MultiSigInput instance to a plain object representation.
29
+ * Includes threshold, publicKeys (converted to strings), and serialized signatures.
30
+ * @returns {Object} The plain object representation of the MultiSigInput.
31
+ */
32
+ toObject(...args: any[]): any;
33
+ private _deserializeSignatures;
34
+ private _serializeSignatures;
35
+ /**
36
+ * Gets signatures for a MultiSigInput by signing the transaction with the provided private key.
37
+ * Only signs for public keys that match the private key's public key.
38
+ *
39
+ * @param {Transaction} transaction - The transaction to sign
40
+ * @param {PrivateKey} privateKey - The private key used for signing
41
+ * @param {number} index - The input index
42
+ * @param {number} [sigtype=Signature.SIGHASH_ALL] - The signature type
43
+ * @returns {TransactionSignature[]} Array of transaction signatures
44
+ */
45
+ getSignatures(transaction: Transaction, privateKey: PrivateKey, index: number, sigtype?: number): TransactionSignature[];
46
+ /**
47
+ * Adds a signature to the MultiSigInput if valid and not already fully signed.
48
+ * @param {Object} transaction - The transaction to validate the signature against.
49
+ * @param {Object} signature - The signature object containing publicKey and signature data.
50
+ * @throws {Error} If already fully signed, no matching public key, or invalid signature.
51
+ * @returns {MultiSigInput} Returns the instance for chaining.
52
+ */
53
+ addSignature(transaction: any, signature: any): MultiSigInput;
54
+ /**
55
+ * Updates the multisig input script by rebuilding it with current public keys, threshold, and signatures.
56
+ * @returns {MultiSigInput} Returns the instance for chaining.
57
+ */
58
+ _updateScript(): MultiSigInput;
59
+ /**
60
+ * Creates DER-encoded signatures from the input's signature data.
61
+ * Filters out undefined signatures and converts each valid signature to a Buffer
62
+ * containing the DER-encoded signature followed by its sigtype byte.
63
+ * @returns {Buffer[]} Array of signature Buffers
64
+ */
65
+ _createSignatures(): Buffer[];
66
+ /**
67
+ * Clears all signatures from the MultiSigInput by resetting the signatures array
68
+ * and updating the script. The signatures array length matches the publicKeys array.
69
+ */
70
+ clearSignatures(): void;
71
+ /**
72
+ * Checks if the MultiSigInput is fully signed by comparing the number of signatures
73
+ * with the required threshold.
74
+ * @returns {boolean} True if the input has enough signatures, false otherwise.
75
+ */
76
+ isFullySigned(): boolean;
77
+ /**
78
+ * Returns the number of missing signatures required to meet the threshold.
79
+ * @returns {number} The count of missing signatures.
80
+ */
81
+ countMissingSignatures(): number;
82
+ /**
83
+ * Counts the number of valid signatures in the MultiSigInput.
84
+ * @returns {number} The count of non-null/undefined signatures.
85
+ */
86
+ countSignatures(): number;
87
+ /**
88
+ * Returns an array of public keys that haven't been signed yet in this MultiSigInput.
89
+ * @returns {Array} Array of unsigned public keys
90
+ */
91
+ publicKeysWithoutSignature(): any[];
92
+ /**
93
+ * Verifies a signature for a MultiSigInput transaction.
94
+ *
95
+ * @param {Object} transaction - The transaction to verify.
96
+ * @param {Object} signature - The signature object containing signature data.
97
+ * @param {Buffer} signature.signature - The signature to verify.
98
+ * @param {Buffer} signature.publicKey - The public key corresponding to the signature.
99
+ * @param {number} signature.inputIndex - The index of the input being signed.
100
+ * @param {number} signature.sigtype - The signature type (assigned to nhashtype as a workaround).
101
+ * @returns {boolean} True if the signature is valid, false otherwise.
102
+ */
103
+ isValidSignature(transaction: any, signature: {
104
+ signature: Buffer;
105
+ publicKey: Buffer;
106
+ inputIndex: number;
107
+ sigtype: number;
108
+ }): boolean;
109
+ private _estimateSize;
110
+ }
111
+ declare namespace MultiSigInput {
112
+ /**
113
+ * Normalizes signatures for a MultiSigInput by matching each public key with its corresponding signature.
114
+ * Filters and validates signatures against the provided public keys and transaction.
115
+ *
116
+ * @param {Object} transaction - The transaction to verify against.
117
+ * @param {Object} input - The input containing prevTxId and outputIndex.
118
+ * @param {number} inputIndex - The index of the input in the transaction.
119
+ * @param {Array<Buffer>} signatures - Array of signature buffers to normalize.
120
+ * @param {Array<PublicKey>} publicKeys - Array of public keys to match signatures against.
121
+ * @returns {Array<TransactionSignature|null>} Array of matched signatures or null for unmatched keys.
122
+ */
123
+ function normalizeSignatures(transaction: any, input: any, inputIndex: number, signatures: Buffer[], publicKeys: PublicKey[]): TransactionSignature[];
124
+ let SIGNATURE_SIZE: number;
125
+ }
126
+ import PublicKey = require("../../publickey.cjs");
127
+ import TransactionSignature = require("../signature.cjs");
@@ -0,0 +1,44 @@
1
+ export = PublicKeyInput;
2
+ /**
3
+ * Represents a special kind of input of PayToPublicKey kind.
4
+ * @constructor
5
+ */
6
+ declare function PublicKeyInput(...args: any[]): void;
7
+ declare class PublicKeyInput {
8
+ /**
9
+ * Represents a special kind of input of PayToPublicKey kind.
10
+ * @constructor
11
+ */
12
+ constructor(...args: any[]);
13
+ /**
14
+ * @param {Transaction} transaction - the transaction to be signed
15
+ * @param {PrivateKey} privateKey - the private key with which to sign the transaction
16
+ * @param {number} index - the index of the input in the transaction input vector
17
+ * @param {number} [sigtype] - the type of signature, defaults to Signature.SIGHASH_ALL
18
+ * @return {Array} of objects that can be
19
+ */
20
+ getSignatures(transaction: Transaction, privateKey: PrivateKey, index: number, sigtype?: number): any[];
21
+ /**
22
+ * Adds a signature to the public key input after validating it.
23
+ * @param {Object} transaction - The transaction to validate against.
24
+ * @param {TransactionSignature} signature - The signature object containing signature data and type.
25
+ * @returns {PublicKeyInput} Returns the instance for chaining.
26
+ * @throws {Error} Throws if the signature is invalid.
27
+ */
28
+ addSignature(transaction: any, signature: TransactionSignature): PublicKeyInput;
29
+ /**
30
+ * Clears all signatures from this input by setting an empty script.
31
+ * @returns {PublicKeyInput} The instance for chaining.
32
+ */
33
+ clearSignatures(): PublicKeyInput;
34
+ /**
35
+ * Checks if the public key input is fully signed by verifying the script contains a public key.
36
+ * @returns {boolean} True if the script contains a public key, false otherwise.
37
+ */
38
+ isFullySigned(): boolean;
39
+ private _estimateSize;
40
+ }
41
+ declare namespace PublicKeyInput {
42
+ let SCRIPT_MAX_SIZE: number;
43
+ }
44
+ import TransactionSignature = require("../signature.cjs");
@@ -0,0 +1,45 @@
1
+ export = PublicKeyHashInput;
2
+ /**
3
+ * Represents a special kind of input of PayToPublicKeyHash kind.
4
+ * @constructor
5
+ */
6
+ declare function PublicKeyHashInput(...args: any[]): void;
7
+ declare class PublicKeyHashInput {
8
+ /**
9
+ * Represents a special kind of input of PayToPublicKeyHash kind.
10
+ * @constructor
11
+ */
12
+ constructor(...args: any[]);
13
+ /**
14
+ * @param {Transaction} transaction - the transaction to be signed
15
+ * @param {PrivateKey} privateKey - the private key with which to sign the transaction
16
+ * @param {number} index - the index of the input in the transaction input vector
17
+ * @param {number} [sigtype] - the type of signature, defaults to Signature.SIGHASH_ALL
18
+ * @param {Buffer} [hashData] - the precalculated hash of the public key associated with the privateKey provided
19
+ * @return {Array} of objects that can be
20
+ */
21
+ getSignatures(transaction: Transaction, privateKey: PrivateKey, index: number, sigtype?: number, hashData?: Buffer): any[];
22
+ /**
23
+ * Adds a signature to the input and updates the script.
24
+ * @param {Transaction} transaction - The transaction to validate against.
25
+ * @param {TransactionSignature} signature - The signature object containing publicKey, signature (DER format), and sigtype.
26
+ * @returns {PublicKeyHashInput} Returns the instance for chaining.
27
+ * @throws {Error} Throws if the signature is invalid.
28
+ */
29
+ addSignature(transaction: Transaction, signature: TransactionSignature): PublicKeyHashInput;
30
+ /**
31
+ * Clear the input's signature
32
+ * @return {PublicKeyHashInput} this, for chaining
33
+ */
34
+ clearSignatures(): PublicKeyHashInput;
35
+ /**
36
+ * Query whether the input is signed
37
+ * @return {boolean}
38
+ */
39
+ isFullySigned(): boolean;
40
+ private _estimateSize;
41
+ }
42
+ declare namespace PublicKeyHashInput {
43
+ let SCRIPT_MAX_SIZE: number;
44
+ }
45
+ import TransactionSignature = require("../signature.cjs");
@@ -0,0 +1,118 @@
1
+ export = Output;
2
+ /**
3
+ * Represents a transaction output in the Bitcoin protocol.
4
+ * @constructor
5
+ * @param {Object} args - The arguments to create an Output.
6
+ * @param {number} args.satoshis - The amount in satoshis.
7
+ * @param {Buffer|string|Script} args.script - The output script (either as Buffer or hex string).
8
+ * @param {Buffer|string} [args.data] - Additional data associated with the output.
9
+ * @throws {TypeError} If arguments are invalid or unrecognized.
10
+ */
11
+ declare function Output(args: {
12
+ satoshis: number;
13
+ script: Buffer | string | Script;
14
+ data?: Buffer | string;
15
+ }): Output;
16
+ declare class Output {
17
+ /**
18
+ * Represents a transaction output in the Bitcoin protocol.
19
+ * @constructor
20
+ * @param {Object} args - The arguments to create an Output.
21
+ * @param {number} args.satoshis - The amount in satoshis.
22
+ * @param {Buffer|string|Script} args.script - The output script (either as Buffer or hex string).
23
+ * @param {Buffer|string} [args.data] - Additional data associated with the output.
24
+ * @throws {TypeError} If arguments are invalid or unrecognized.
25
+ */
26
+ constructor(args: {
27
+ satoshis: number;
28
+ script: Buffer | string | Script;
29
+ data?: Buffer | string;
30
+ });
31
+ satoshis: number;
32
+ get script(): Script;
33
+ get data(): Buffer;
34
+ /**
35
+ * Checks if the satoshis value in this output is invalid.
36
+ * @returns {string|boolean} Returns an error message string if invalid (satoshis exceed max safe integer,
37
+ * corrupted value, or negative), otherwise returns false.
38
+ */
39
+ invalidSatoshis(): string | boolean;
40
+ set satoshisBN(value: any);
41
+ get satoshisBN(): any;
42
+ /**
43
+ * Converts the Output instance to a plain object representation.
44
+ * The resulting object includes satoshis, script (as hex string), and data (as hex string).
45
+ * @returns {Object} - An object with satoshis, script, and data properties.
46
+ */
47
+ toObject: () => any;
48
+ toJSON(): any;
49
+ /**
50
+ * Sets the output data.
51
+ * @param {Buffer|string} data - The data to set. Can be a Buffer or hex string.
52
+ * @throws {TypeError} If data is not a Buffer or valid hex string.
53
+ */
54
+ setData(data: Buffer | string): void;
55
+ _data: Buffer;
56
+ /**
57
+ * Sets the script for this output from a buffer.
58
+ * @param {Buffer} buffer - The buffer containing the script data.
59
+ * @throws {errors.Script.InvalidBuffer} If the buffer is invalid.
60
+ */
61
+ setScriptFromBuffer(buffer: Buffer): void;
62
+ _script: Script;
63
+ /**
64
+ * Sets the script for this output.
65
+ * @param {Script|string|Buffer} script - The script to set, which can be a Script instance, hex string, or Buffer.
66
+ * @returns {Output} Returns the output instance for chaining.
67
+ * @throws {TypeError} Throws if the script type is invalid.
68
+ */
69
+ setScript(script: Script | string | Buffer): Output;
70
+ /**
71
+ * Returns a human-readable string representation of the Output object.
72
+ * Format: '<Output (satoshis sats) scriptString>'
73
+ * @returns {string} Formatted string showing satoshis and script inspection result
74
+ */
75
+ inspect(): string;
76
+ /**
77
+ * Converts the Output instance to a buffer writer format.
78
+ * @param {boolean} hashScriptPubkey - If true, hashes script and data with SHA256; otherwise writes them directly.
79
+ * @param {BufferWriter} [writer] - Optional BufferWriter instance. If not provided, a new one is created.
80
+ * @returns {BufferWriter} The buffer writer containing the serialized output data.
81
+ */
82
+ toBufferWriter(hashScriptPubkey: boolean, writer?: BufferWriter): BufferWriter;
83
+ /**
84
+ * Calculates the total size of the output in bytes.
85
+ * Includes the script size, data size, and their respective varint sizes,
86
+ * plus a fixed 8-byte overhead.
87
+ * 8 value
88
+ * ??? script+data size (VARINT)
89
+ * script size
90
+ * data size
91
+ * @returns {number} The total output size in bytes.
92
+ */
93
+ getSize(): number;
94
+ /**
95
+ * Creates a shallow clone of the Output instance.
96
+ * @returns {Output} A new Output instance with the same properties as the original.
97
+ */
98
+ clone(): Output;
99
+ }
100
+ declare namespace Output {
101
+ /**
102
+ * Creates an Output instance from a plain JavaScript object.
103
+ * @param {Object} data - The input object to convert to an Output
104
+ * @returns {Output} A new Output instance
105
+ * @static
106
+ */
107
+ function fromObject(data: any): Output;
108
+ /**
109
+ * Creates an Output instance from a BufferReader.
110
+ * @param {BufferReader} br - The buffer reader containing output data
111
+ * @returns {Output} A new Output instance
112
+ * @throws {TypeError} If the buffer contains unrecognized output format
113
+ * @static
114
+ */
115
+ function fromBufferReader(br: BufferReader): Output;
116
+ }
117
+ import Script = require("../script/script.cjs");
118
+ import BufferWriter = require("../encoding/bufferwriter.cjs");
@@ -0,0 +1,61 @@
1
+ export = Sighash;
2
+ /**
3
+ * Represents a Sighash utility for cryptographic signature operations.
4
+ * @constructor
5
+ */
6
+ declare function Sighash(): void;
7
+ declare class Sighash {
8
+ }
9
+ declare namespace Sighash {
10
+ /**
11
+ * Returns a buffer with the which is hashed with sighash that needs to be signed
12
+ * for OP_CHECKSIG.
13
+ *
14
+ * @name Signing.sighash
15
+ * @param {Transaction} transaction the transaction to sign
16
+ * @param {number} sighashType the type of the hash
17
+ * @param {number} inputNumber the input index for the signature
18
+ * @param {Script} subscript the script that will be signed
19
+ * @param {satoshisBN} input's amount (for ForkId signatures)
20
+ *
21
+ */
22
+ function sighashPreimage(transaction: Transaction, sighashType: number, inputNumber: number): Buffer;
23
+ function getLowSSighashPreimage(tx: any, sigtype: any, inputIndex: any): Buffer;
24
+ /**
25
+ * Returns a buffer of length 32 bytes with the hash that needs to be signed
26
+ * for OP_CHECKSIG.
27
+ *
28
+ * @name Signing.sighash
29
+ * @param {Transaction} transaction the transaction to sign
30
+ * @param {number} sighashType the type of the hash
31
+ * @param {number} inputNumber the input index for the signature
32
+ *
33
+ */
34
+ function sighash(transaction: Transaction, sighashType: number, inputNumber: number): Buffer;
35
+ /**
36
+ * Create a signature
37
+ *
38
+ * @name Signing.sign
39
+ * @param {Transaction} transaction
40
+ * @param {PrivateKey} privateKey
41
+ * @param {number} sighash
42
+ * @param {number} inputIndex
43
+ * @return {Signature}
44
+ */
45
+ function sign(transaction: Transaction, privateKey: PrivateKey, sighashType: any, inputIndex: number): Signature;
46
+ /**
47
+ * Verify a signature
48
+ *
49
+ * @name Signing.verify
50
+ * @param {Transaction} transaction
51
+ * @param {Signature} signature
52
+ * @param {PublicKey} publicKey
53
+ * @param {number} inputIndex
54
+ * @param {Script} subscript
55
+ * @param {satoshisBN} input's amount
56
+ * @param {flags} verification flags
57
+ * @return {boolean}
58
+ */
59
+ function verify(transaction: Transaction, signature: Signature, publicKey: PublicKey, inputIndex: number): boolean;
60
+ }
61
+ import Signature = require("../crypto/signature.cjs");
@@ -0,0 +1,43 @@
1
+ export = TransactionSignature;
2
+ /**
3
+ * @desc
4
+ * Wrapper around Signature with fields related to signing a transaction specifically
5
+ *
6
+ * @param {Object|string|TransactionSignature} arg
7
+ * @constructor
8
+ */
9
+ declare function TransactionSignature(arg: any | string | TransactionSignature): TransactionSignature;
10
+ declare class TransactionSignature {
11
+ /**
12
+ * @desc
13
+ * Wrapper around Signature with fields related to signing a transaction specifically
14
+ *
15
+ * @param {Object|string|TransactionSignature} arg
16
+ * @constructor
17
+ */
18
+ constructor(arg: any | string | TransactionSignature);
19
+ private _fromObject;
20
+ publicKey: PublicKey;
21
+ prevTxId: Buffer;
22
+ outputIndex: number;
23
+ inputIndex: number;
24
+ signature: Signature;
25
+ sigtype: number;
26
+ private _checkObjectArgs;
27
+ /**
28
+ * Serializes a transaction to a plain JS object
29
+ * @return {Object}
30
+ */
31
+ toObject: () => any;
32
+ toJSON(): any;
33
+ }
34
+ declare namespace TransactionSignature {
35
+ /**
36
+ * Builds a TransactionSignature from an object
37
+ * @param {Object} object
38
+ * @return {TransactionSignature}
39
+ */
40
+ function fromObject(object: any): TransactionSignature;
41
+ }
42
+ import PublicKey = require("../publickey.cjs");
43
+ import Signature = require("../crypto/signature.cjs");