@bsv/sdk 1.0.24 → 1.0.29

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 (329) hide show
  1. package/package.json +1 -1
  2. package/dist/cjs/mod.js +0 -25
  3. package/dist/cjs/mod.js.map +0 -1
  4. package/dist/cjs/package.json +0 -49
  5. package/dist/cjs/src/compat/BSM.js +0 -77
  6. package/dist/cjs/src/compat/BSM.js.map +0 -1
  7. package/dist/cjs/src/compat/ECIES.js +0 -512
  8. package/dist/cjs/src/compat/ECIES.js.map +0 -1
  9. package/dist/cjs/src/compat/HD.js +0 -344
  10. package/dist/cjs/src/compat/HD.js.map +0 -1
  11. package/dist/cjs/src/compat/Mnemonic.js +0 -298
  12. package/dist/cjs/src/compat/Mnemonic.js.map +0 -1
  13. package/dist/cjs/src/compat/bip-39-wordlist-en.js +0 -2057
  14. package/dist/cjs/src/compat/bip-39-wordlist-en.js.map +0 -1
  15. package/dist/cjs/src/compat/index.js +0 -37
  16. package/dist/cjs/src/compat/index.js.map +0 -1
  17. package/dist/cjs/src/messages/EncryptedMessage.js +0 -69
  18. package/dist/cjs/src/messages/EncryptedMessage.js.map +0 -1
  19. package/dist/cjs/src/messages/SignedMessage.js +0 -85
  20. package/dist/cjs/src/messages/SignedMessage.js.map +0 -1
  21. package/dist/cjs/src/messages/index.js +0 -29
  22. package/dist/cjs/src/messages/index.js.map +0 -1
  23. package/dist/cjs/src/primitives/AESGCM.js +0 -384
  24. package/dist/cjs/src/primitives/AESGCM.js.map +0 -1
  25. package/dist/cjs/src/primitives/BasePoint.js +0 -19
  26. package/dist/cjs/src/primitives/BasePoint.js.map +0 -1
  27. package/dist/cjs/src/primitives/BigNumber.js +0 -4272
  28. package/dist/cjs/src/primitives/BigNumber.js.map +0 -1
  29. package/dist/cjs/src/primitives/Curve.js +0 -1126
  30. package/dist/cjs/src/primitives/Curve.js.map +0 -1
  31. package/dist/cjs/src/primitives/DRBG.js +0 -99
  32. package/dist/cjs/src/primitives/DRBG.js.map +0 -1
  33. package/dist/cjs/src/primitives/ECDSA.js +0 -169
  34. package/dist/cjs/src/primitives/ECDSA.js.map +0 -1
  35. package/dist/cjs/src/primitives/Hash.js +0 -1387
  36. package/dist/cjs/src/primitives/Hash.js.map +0 -1
  37. package/dist/cjs/src/primitives/JacobianPoint.js +0 -400
  38. package/dist/cjs/src/primitives/JacobianPoint.js.map +0 -1
  39. package/dist/cjs/src/primitives/K256.js +0 -111
  40. package/dist/cjs/src/primitives/K256.js.map +0 -1
  41. package/dist/cjs/src/primitives/Mersenne.js +0 -118
  42. package/dist/cjs/src/primitives/Mersenne.js.map +0 -1
  43. package/dist/cjs/src/primitives/MontgomoryMethod.js +0 -150
  44. package/dist/cjs/src/primitives/MontgomoryMethod.js.map +0 -1
  45. package/dist/cjs/src/primitives/Point.js +0 -819
  46. package/dist/cjs/src/primitives/Point.js.map +0 -1
  47. package/dist/cjs/src/primitives/PrivateKey.js +0 -246
  48. package/dist/cjs/src/primitives/PrivateKey.js.map +0 -1
  49. package/dist/cjs/src/primitives/PublicKey.js +0 -168
  50. package/dist/cjs/src/primitives/PublicKey.js.map +0 -1
  51. package/dist/cjs/src/primitives/Random.js +0 -57
  52. package/dist/cjs/src/primitives/Random.js.map +0 -1
  53. package/dist/cjs/src/primitives/ReductionContext.js +0 -490
  54. package/dist/cjs/src/primitives/ReductionContext.js.map +0 -1
  55. package/dist/cjs/src/primitives/Signature.js +0 -357
  56. package/dist/cjs/src/primitives/Signature.js.map +0 -1
  57. package/dist/cjs/src/primitives/SymmetricKey.js +0 -82
  58. package/dist/cjs/src/primitives/SymmetricKey.js.map +0 -1
  59. package/dist/cjs/src/primitives/TransactionSignature.js +0 -172
  60. package/dist/cjs/src/primitives/TransactionSignature.js.map +0 -1
  61. package/dist/cjs/src/primitives/index.js +0 -51
  62. package/dist/cjs/src/primitives/index.js.map +0 -1
  63. package/dist/cjs/src/primitives/utils.js +0 -624
  64. package/dist/cjs/src/primitives/utils.js.map +0 -1
  65. package/dist/cjs/src/script/LockingScript.js +0 -35
  66. package/dist/cjs/src/script/LockingScript.js.map +0 -1
  67. package/dist/cjs/src/script/OP.js +0 -207
  68. package/dist/cjs/src/script/OP.js.map +0 -1
  69. package/dist/cjs/src/script/Script.js +0 -435
  70. package/dist/cjs/src/script/Script.js.map +0 -1
  71. package/dist/cjs/src/script/ScriptChunk.js +0 -3
  72. package/dist/cjs/src/script/ScriptChunk.js.map +0 -1
  73. package/dist/cjs/src/script/ScriptTemplate.js +0 -3
  74. package/dist/cjs/src/script/ScriptTemplate.js.map +0 -1
  75. package/dist/cjs/src/script/Spend.js +0 -1252
  76. package/dist/cjs/src/script/Spend.js.map +0 -1
  77. package/dist/cjs/src/script/UnlockingScript.js +0 -35
  78. package/dist/cjs/src/script/UnlockingScript.js.map +0 -1
  79. package/dist/cjs/src/script/index.js +0 -32
  80. package/dist/cjs/src/script/index.js.map +0 -1
  81. package/dist/cjs/src/script/templates/P2PKH.js +0 -120
  82. package/dist/cjs/src/script/templates/P2PKH.js.map +0 -1
  83. package/dist/cjs/src/script/templates/RPuzzle.js +0 -125
  84. package/dist/cjs/src/script/templates/RPuzzle.js.map +0 -1
  85. package/dist/cjs/src/script/templates/index.js +0 -11
  86. package/dist/cjs/src/script/templates/index.js.map +0 -1
  87. package/dist/cjs/src/transaction/Broadcaster.js +0 -3
  88. package/dist/cjs/src/transaction/Broadcaster.js.map +0 -1
  89. package/dist/cjs/src/transaction/ChainTracker.js +0 -3
  90. package/dist/cjs/src/transaction/ChainTracker.js.map +0 -1
  91. package/dist/cjs/src/transaction/FeeModel.js +0 -3
  92. package/dist/cjs/src/transaction/FeeModel.js.map +0 -1
  93. package/dist/cjs/src/transaction/MerklePath.js +0 -239
  94. package/dist/cjs/src/transaction/MerklePath.js.map +0 -1
  95. package/dist/cjs/src/transaction/Transaction.js +0 -616
  96. package/dist/cjs/src/transaction/Transaction.js.map +0 -1
  97. package/dist/cjs/src/transaction/TransactionInput.js +0 -3
  98. package/dist/cjs/src/transaction/TransactionInput.js.map +0 -1
  99. package/dist/cjs/src/transaction/TransactionOutput.js +0 -3
  100. package/dist/cjs/src/transaction/TransactionOutput.js.map +0 -1
  101. package/dist/cjs/src/transaction/broadcasters/ARC.js +0 -112
  102. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +0 -1
  103. package/dist/cjs/src/transaction/broadcasters/index.js +0 -9
  104. package/dist/cjs/src/transaction/broadcasters/index.js.map +0 -1
  105. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +0 -69
  106. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +0 -1
  107. package/dist/cjs/src/transaction/fee-models/index.js +0 -9
  108. package/dist/cjs/src/transaction/fee-models/index.js.map +0 -1
  109. package/dist/cjs/src/transaction/index.js +0 -11
  110. package/dist/cjs/src/transaction/index.js.map +0 -1
  111. package/dist/cjs/tsconfig.cjs.tsbuildinfo +0 -1
  112. package/dist/esm/mod.js +0 -9
  113. package/dist/esm/mod.js.map +0 -1
  114. package/dist/esm/src/compat/BSM.js +0 -45
  115. package/dist/esm/src/compat/BSM.js.map +0 -1
  116. package/dist/esm/src/compat/ECIES.js +0 -483
  117. package/dist/esm/src/compat/ECIES.js.map +0 -1
  118. package/dist/esm/src/compat/HD.js +0 -322
  119. package/dist/esm/src/compat/HD.js.map +0 -1
  120. package/dist/esm/src/compat/Mnemonic.js +0 -272
  121. package/dist/esm/src/compat/Mnemonic.js.map +0 -1
  122. package/dist/esm/src/compat/bip-39-wordlist-en.js +0 -2054
  123. package/dist/esm/src/compat/bip-39-wordlist-en.js.map +0 -1
  124. package/dist/esm/src/compat/index.js +0 -5
  125. package/dist/esm/src/compat/index.js.map +0 -1
  126. package/dist/esm/src/messages/EncryptedMessage.js +0 -61
  127. package/dist/esm/src/messages/EncryptedMessage.js.map +0 -1
  128. package/dist/esm/src/messages/SignedMessage.js +0 -77
  129. package/dist/esm/src/messages/SignedMessage.js.map +0 -1
  130. package/dist/esm/src/messages/index.js +0 -3
  131. package/dist/esm/src/messages/index.js.map +0 -1
  132. package/dist/esm/src/primitives/AESGCM.js +0 -371
  133. package/dist/esm/src/primitives/AESGCM.js.map +0 -1
  134. package/dist/esm/src/primitives/BasePoint.js +0 -16
  135. package/dist/esm/src/primitives/BasePoint.js.map +0 -1
  136. package/dist/esm/src/primitives/BigNumber.js +0 -4307
  137. package/dist/esm/src/primitives/BigNumber.js.map +0 -1
  138. package/dist/esm/src/primitives/Curve.js +0 -1141
  139. package/dist/esm/src/primitives/Curve.js.map +0 -1
  140. package/dist/esm/src/primitives/DRBG.js +0 -98
  141. package/dist/esm/src/primitives/DRBG.js.map +0 -1
  142. package/dist/esm/src/primitives/ECDSA.js +0 -161
  143. package/dist/esm/src/primitives/ECDSA.js.map +0 -1
  144. package/dist/esm/src/primitives/Hash.js +0 -1391
  145. package/dist/esm/src/primitives/Hash.js.map +0 -1
  146. package/dist/esm/src/primitives/JacobianPoint.js +0 -398
  147. package/dist/esm/src/primitives/JacobianPoint.js.map +0 -1
  148. package/dist/esm/src/primitives/K256.js +0 -105
  149. package/dist/esm/src/primitives/K256.js.map +0 -1
  150. package/dist/esm/src/primitives/Mersenne.js +0 -117
  151. package/dist/esm/src/primitives/Mersenne.js.map +0 -1
  152. package/dist/esm/src/primitives/MontgomoryMethod.js +0 -149
  153. package/dist/esm/src/primitives/MontgomoryMethod.js.map +0 -1
  154. package/dist/esm/src/primitives/Point.js +0 -816
  155. package/dist/esm/src/primitives/Point.js.map +0 -1
  156. package/dist/esm/src/primitives/PrivateKey.js +0 -240
  157. package/dist/esm/src/primitives/PrivateKey.js.map +0 -1
  158. package/dist/esm/src/primitives/PublicKey.js +0 -162
  159. package/dist/esm/src/primitives/PublicKey.js.map +0 -1
  160. package/dist/esm/src/primitives/Random.js +0 -56
  161. package/dist/esm/src/primitives/Random.js.map +0 -1
  162. package/dist/esm/src/primitives/ReductionContext.js +0 -486
  163. package/dist/esm/src/primitives/ReductionContext.js.map +0 -1
  164. package/dist/esm/src/primitives/Signature.js +0 -360
  165. package/dist/esm/src/primitives/Signature.js.map +0 -1
  166. package/dist/esm/src/primitives/SymmetricKey.js +0 -76
  167. package/dist/esm/src/primitives/SymmetricKey.js.map +0 -1
  168. package/dist/esm/src/primitives/TransactionSignature.js +0 -144
  169. package/dist/esm/src/primitives/TransactionSignature.js.map +0 -1
  170. package/dist/esm/src/primitives/index.js +0 -13
  171. package/dist/esm/src/primitives/index.js.map +0 -1
  172. package/dist/esm/src/primitives/utils.js +0 -609
  173. package/dist/esm/src/primitives/utils.js.map +0 -1
  174. package/dist/esm/src/script/LockingScript.js +0 -29
  175. package/dist/esm/src/script/LockingScript.js.map +0 -1
  176. package/dist/esm/src/script/OP.js +0 -205
  177. package/dist/esm/src/script/OP.js.map +0 -1
  178. package/dist/esm/src/script/Script.js +0 -430
  179. package/dist/esm/src/script/Script.js.map +0 -1
  180. package/dist/esm/src/script/ScriptChunk.js +0 -2
  181. package/dist/esm/src/script/ScriptChunk.js.map +0 -1
  182. package/dist/esm/src/script/ScriptTemplate.js +0 -2
  183. package/dist/esm/src/script/ScriptTemplate.js.map +0 -1
  184. package/dist/esm/src/script/Spend.js +0 -1240
  185. package/dist/esm/src/script/Spend.js.map +0 -1
  186. package/dist/esm/src/script/UnlockingScript.js +0 -29
  187. package/dist/esm/src/script/UnlockingScript.js.map +0 -1
  188. package/dist/esm/src/script/index.js +0 -7
  189. package/dist/esm/src/script/index.js.map +0 -1
  190. package/dist/esm/src/script/templates/P2PKH.js +0 -113
  191. package/dist/esm/src/script/templates/P2PKH.js.map +0 -1
  192. package/dist/esm/src/script/templates/RPuzzle.js +0 -119
  193. package/dist/esm/src/script/templates/RPuzzle.js.map +0 -1
  194. package/dist/esm/src/script/templates/index.js +0 -3
  195. package/dist/esm/src/script/templates/index.js.map +0 -1
  196. package/dist/esm/src/transaction/Broadcaster.js +0 -2
  197. package/dist/esm/src/transaction/Broadcaster.js.map +0 -1
  198. package/dist/esm/src/transaction/ChainTracker.js +0 -2
  199. package/dist/esm/src/transaction/ChainTracker.js.map +0 -1
  200. package/dist/esm/src/transaction/FeeModel.js +0 -2
  201. package/dist/esm/src/transaction/FeeModel.js.map +0 -1
  202. package/dist/esm/src/transaction/MerklePath.js +0 -237
  203. package/dist/esm/src/transaction/MerklePath.js.map +0 -1
  204. package/dist/esm/src/transaction/Transaction.js +0 -617
  205. package/dist/esm/src/transaction/Transaction.js.map +0 -1
  206. package/dist/esm/src/transaction/TransactionInput.js +0 -2
  207. package/dist/esm/src/transaction/TransactionInput.js.map +0 -1
  208. package/dist/esm/src/transaction/TransactionOutput.js +0 -2
  209. package/dist/esm/src/transaction/TransactionOutput.js.map +0 -1
  210. package/dist/esm/src/transaction/broadcasters/ARC.js +0 -111
  211. package/dist/esm/src/transaction/broadcasters/ARC.js.map +0 -1
  212. package/dist/esm/src/transaction/broadcasters/index.js +0 -2
  213. package/dist/esm/src/transaction/broadcasters/index.js.map +0 -1
  214. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +0 -71
  215. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +0 -1
  216. package/dist/esm/src/transaction/fee-models/index.js +0 -2
  217. package/dist/esm/src/transaction/fee-models/index.js.map +0 -1
  218. package/dist/esm/src/transaction/index.js +0 -3
  219. package/dist/esm/src/transaction/index.js.map +0 -1
  220. package/dist/esm/tsconfig.esm.tsbuildinfo +0 -1
  221. package/dist/types/mod.d.ts +0 -9
  222. package/dist/types/mod.d.ts.map +0 -1
  223. package/dist/types/src/compat/BSM.d.ts +0 -28
  224. package/dist/types/src/compat/BSM.d.ts.map +0 -1
  225. package/dist/types/src/compat/ECIES.d.ts +0 -62
  226. package/dist/types/src/compat/ECIES.d.ts.map +0 -1
  227. package/dist/types/src/compat/HD.d.ts +0 -131
  228. package/dist/types/src/compat/HD.d.ts.map +0 -1
  229. package/dist/types/src/compat/Mnemonic.d.ts +0 -132
  230. package/dist/types/src/compat/Mnemonic.d.ts.map +0 -1
  231. package/dist/types/src/compat/bip-39-wordlist-en.d.ts +0 -5
  232. package/dist/types/src/compat/bip-39-wordlist-en.d.ts.map +0 -1
  233. package/dist/types/src/compat/index.d.ts +0 -5
  234. package/dist/types/src/compat/index.d.ts.map +0 -1
  235. package/dist/types/src/messages/EncryptedMessage.d.ts +0 -20
  236. package/dist/types/src/messages/EncryptedMessage.d.ts.map +0 -1
  237. package/dist/types/src/messages/SignedMessage.d.ts +0 -21
  238. package/dist/types/src/messages/SignedMessage.d.ts.map +0 -1
  239. package/dist/types/src/messages/index.d.ts +0 -3
  240. package/dist/types/src/messages/index.d.ts.map +0 -1
  241. package/dist/types/src/primitives/AESGCM.d.ts +0 -14
  242. package/dist/types/src/primitives/AESGCM.d.ts.map +0 -1
  243. package/dist/types/src/primitives/BasePoint.d.ts +0 -22
  244. package/dist/types/src/primitives/BasePoint.d.ts.map +0 -1
  245. package/dist/types/src/primitives/BigNumber.d.ts +0 -1895
  246. package/dist/types/src/primitives/BigNumber.d.ts.map +0 -1
  247. package/dist/types/src/primitives/Curve.d.ts +0 -55
  248. package/dist/types/src/primitives/Curve.d.ts.map +0 -1
  249. package/dist/types/src/primitives/DRBG.d.ts +0 -54
  250. package/dist/types/src/primitives/DRBG.d.ts.map +0 -1
  251. package/dist/types/src/primitives/ECDSA.d.ts +0 -39
  252. package/dist/types/src/primitives/ECDSA.d.ts.map +0 -1
  253. package/dist/types/src/primitives/Hash.d.ts +0 -450
  254. package/dist/types/src/primitives/Hash.d.ts.map +0 -1
  255. package/dist/types/src/primitives/JacobianPoint.d.ts +0 -164
  256. package/dist/types/src/primitives/JacobianPoint.d.ts.map +0 -1
  257. package/dist/types/src/primitives/K256.d.ts +0 -53
  258. package/dist/types/src/primitives/K256.d.ts.map +0 -1
  259. package/dist/types/src/primitives/Mersenne.d.ts +0 -72
  260. package/dist/types/src/primitives/Mersenne.d.ts.map +0 -1
  261. package/dist/types/src/primitives/MontgomoryMethod.d.ts +0 -96
  262. package/dist/types/src/primitives/MontgomoryMethod.d.ts.map +0 -1
  263. package/dist/types/src/primitives/Point.d.ts +0 -303
  264. package/dist/types/src/primitives/Point.d.ts.map +0 -1
  265. package/dist/types/src/primitives/PrivateKey.d.ts +0 -174
  266. package/dist/types/src/primitives/PrivateKey.d.ts.map +0 -1
  267. package/dist/types/src/primitives/PublicKey.d.ts +0 -120
  268. package/dist/types/src/primitives/PublicKey.d.ts.map +0 -1
  269. package/dist/types/src/primitives/Random.d.ts +0 -14
  270. package/dist/types/src/primitives/Random.d.ts.map +0 -1
  271. package/dist/types/src/primitives/ReductionContext.d.ts +0 -308
  272. package/dist/types/src/primitives/ReductionContext.d.ts.map +0 -1
  273. package/dist/types/src/primitives/Signature.d.ts +0 -162
  274. package/dist/types/src/primitives/Signature.d.ts.map +0 -1
  275. package/dist/types/src/primitives/SymmetricKey.d.ts +0 -55
  276. package/dist/types/src/primitives/SymmetricKey.d.ts.map +0 -1
  277. package/dist/types/src/primitives/TransactionSignature.d.ts +0 -36
  278. package/dist/types/src/primitives/TransactionSignature.d.ts.map +0 -1
  279. package/dist/types/src/primitives/index.d.ts +0 -13
  280. package/dist/types/src/primitives/index.d.ts.map +0 -1
  281. package/dist/types/src/primitives/utils.d.ts +0 -124
  282. package/dist/types/src/primitives/utils.d.ts.map +0 -1
  283. package/dist/types/src/script/LockingScript.d.ts +0 -25
  284. package/dist/types/src/script/LockingScript.d.ts.map +0 -1
  285. package/dist/types/src/script/OP.d.ts +0 -193
  286. package/dist/types/src/script/OP.d.ts.map +0 -1
  287. package/dist/types/src/script/Script.d.ts +0 -148
  288. package/dist/types/src/script/Script.d.ts.map +0 -1
  289. package/dist/types/src/script/ScriptChunk.d.ts +0 -8
  290. package/dist/types/src/script/ScriptChunk.d.ts.map +0 -1
  291. package/dist/types/src/script/ScriptTemplate.d.ts +0 -33
  292. package/dist/types/src/script/ScriptTemplate.d.ts.map +0 -1
  293. package/dist/types/src/script/Spend.d.ts +0 -103
  294. package/dist/types/src/script/Spend.d.ts.map +0 -1
  295. package/dist/types/src/script/UnlockingScript.d.ts +0 -25
  296. package/dist/types/src/script/UnlockingScript.d.ts.map +0 -1
  297. package/dist/types/src/script/index.d.ts +0 -8
  298. package/dist/types/src/script/index.d.ts.map +0 -1
  299. package/dist/types/src/script/templates/P2PKH.d.ts +0 -40
  300. package/dist/types/src/script/templates/P2PKH.d.ts.map +0 -1
  301. package/dist/types/src/script/templates/RPuzzle.d.ts +0 -47
  302. package/dist/types/src/script/templates/RPuzzle.d.ts.map +0 -1
  303. package/dist/types/src/script/templates/index.d.ts +0 -3
  304. package/dist/types/src/script/templates/index.d.ts.map +0 -1
  305. package/dist/types/src/transaction/Broadcaster.d.ts +0 -39
  306. package/dist/types/src/transaction/Broadcaster.d.ts.map +0 -1
  307. package/dist/types/src/transaction/ChainTracker.d.ts +0 -23
  308. package/dist/types/src/transaction/ChainTracker.d.ts.map +0 -1
  309. package/dist/types/src/transaction/FeeModel.d.ts +0 -12
  310. package/dist/types/src/transaction/FeeModel.d.ts.map +0 -1
  311. package/dist/types/src/transaction/MerklePath.d.ts +0 -91
  312. package/dist/types/src/transaction/MerklePath.d.ts.map +0 -1
  313. package/dist/types/src/transaction/Transaction.d.ts +0 -215
  314. package/dist/types/src/transaction/Transaction.d.ts.map +0 -1
  315. package/dist/types/src/transaction/TransactionInput.d.ts +0 -63
  316. package/dist/types/src/transaction/TransactionInput.d.ts.map +0 -1
  317. package/dist/types/src/transaction/TransactionOutput.d.ts +0 -36
  318. package/dist/types/src/transaction/TransactionOutput.d.ts.map +0 -1
  319. package/dist/types/src/transaction/broadcasters/ARC.d.ts +0 -28
  320. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +0 -1
  321. package/dist/types/src/transaction/broadcasters/index.d.ts +0 -2
  322. package/dist/types/src/transaction/broadcasters/index.d.ts.map +0 -1
  323. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts +0 -26
  324. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +0 -1
  325. package/dist/types/src/transaction/fee-models/index.d.ts +0 -2
  326. package/dist/types/src/transaction/fee-models/index.d.ts.map +0 -1
  327. package/dist/types/src/transaction/index.d.ts +0 -7
  328. package/dist/types/src/transaction/index.d.ts.map +0 -1
  329. package/dist/types/tsconfig.types.tsbuildinfo +0 -1
@@ -1,1240 +0,0 @@
1
- import Script from './Script.js';
2
- import BigNumber from '../primitives/BigNumber.js';
3
- import OP from './OP.js';
4
- import { toHex } from '../primitives/utils.js';
5
- import * as Hash from '../primitives/Hash.js';
6
- import TransactionSignature from '../primitives/TransactionSignature.js';
7
- import PublicKey from '../primitives/PublicKey.js';
8
- import { verify } from '../primitives/ECDSA.js';
9
- // These constants control the current behavior of the interpreter.
10
- // In the future, all of them will go away.
11
- const maxScriptElementSize = 1024 * 1024 * 1024;
12
- const maxMultisigKeyCount = Math.pow(2, 31) - 1;
13
- const requireMinimalPush = true;
14
- const requirePushOnlyUnlockingScripts = true;
15
- const requireLowSSignatures = true;
16
- const requireCleanStack = true;
17
- /**
18
- * The Spend class represents a spend action within a Bitcoin SV transaction.
19
- * It encapsulates all the necessary data required for spending a UTXO (Unspent Transaction Output)
20
- * and includes details about the source transaction, output, and the spending transaction itself.
21
- *
22
- * @property {string} sourceTXID - The transaction ID of the source UTXO.
23
- * @property {number} sourceOutputIndex - The index of the output in the source transaction.
24
- * @property {BigNumber} sourceSatoshis - The amount of satoshis in the source UTXO.
25
- * @property {LockingScript} lockingScript - The locking script associated with the UTXO.
26
- * @property {number} transactionVersion - The version of the current transaction.
27
- * @property {Array<{ sourceTXID: string, sourceOutputIndex: number, sequence: number }>} otherInputs -
28
- * An array of other inputs in the transaction, each with a txid, outputIndex, and sequence number.
29
- * @property {Array<{ satoshis: BigNumber, lockingScript: LockingScript }>} outputs -
30
- * An array of outputs of the current transaction, including the satoshi value and locking script for each.
31
- * @property {number} inputIndex - The index of this input in the current transaction.
32
- * @property {UnlockingScript} unlockingScript - The unlocking script that unlocks the UTXO for spending.
33
- * @property {number} inputSequence - The sequence number of this input.
34
- */
35
- export default class Spend {
36
- sourceTXID;
37
- sourceOutputIndex;
38
- sourceSatoshis;
39
- lockingScript;
40
- transactionVersion;
41
- otherInputs;
42
- outputs;
43
- inputIndex;
44
- unlockingScript;
45
- inputSequence;
46
- lockTime;
47
- context;
48
- programCounter;
49
- lastCodeSeparator;
50
- stack;
51
- altStack;
52
- ifStack;
53
- /**
54
- * @constructor
55
- * Constructs the Spend object with necessary transaction details.
56
- * @param {string} params.sourceTXID - The transaction ID of the source UTXO.
57
- * @param {number} params.sourceOutputIndex - The index of the output in the source transaction.
58
- * @param {BigNumber} params.sourceSatoshis - The amount of satoshis in the source UTXO.
59
- * @param {LockingScript} params.lockingScript - The locking script associated with the UTXO.
60
- * @param {number} params.transactionVersion - The version of the current transaction.
61
- * @param {Array<{ sourceTXID: string, sourceOutputIndex: number, sequence: number }>} params.otherInputs -
62
- * An array of other inputs in the transaction.
63
- * @param {Array<{ satoshis: BigNumber, lockingScript: LockingScript }>} params.outputs -
64
- * The outputs of the current transaction.
65
- * @param {number} params.inputIndex - The index of this input in the current transaction.
66
- * @param {UnlockingScript} params.unlockingScript - The unlocking script for this spend.
67
- * @param {number} params.inputSequence - The sequence number of this input.
68
- * @param {number} params.lockTime - The lock time of the transaction.
69
- *
70
- * @example
71
- * const spend = new Spend({
72
- * sourceTXID: "abcd1234", // sourceTXID
73
- * sourceOutputIndex: 0, // sourceOutputIndex
74
- * sourceSatoshis: new BigNumber(1000), // sourceSatoshis
75
- * lockingScript: LockingScript.fromASM("OP_DUP OP_HASH160 abcd1234... OP_EQUALVERIFY OP_CHECKSIG"),
76
- * transactionVersion: 1, // transactionVersion
77
- * otherInputs: [{ sourceTXID: "abcd1234", sourceOutputIndex: 1, sequence: 0xffffffff }], // otherInputs
78
- * outputs: [{ satoshis: new BigNumber(500), lockingScript: LockingScript.fromASM("OP_DUP...") }], // outputs
79
- * inputIndex: 0, // inputIndex
80
- * unlockingScript: UnlockingScript.fromASM("3045... 02ab..."),
81
- * inputSequence: 0xffffffff // inputSequence
82
- * });
83
- */
84
- constructor(params) {
85
- this.sourceTXID = params.sourceTXID;
86
- this.sourceOutputIndex = params.sourceOutputIndex;
87
- this.sourceSatoshis = params.sourceSatoshis;
88
- this.lockingScript = params.lockingScript;
89
- this.transactionVersion = params.transactionVersion;
90
- this.otherInputs = params.otherInputs;
91
- this.outputs = params.outputs;
92
- this.inputIndex = params.inputIndex;
93
- this.unlockingScript = params.unlockingScript;
94
- this.inputSequence = params.inputSequence;
95
- this.lockTime = params.lockTime;
96
- this.reset();
97
- }
98
- reset() {
99
- this.context = 'UnlockingScript';
100
- this.programCounter = 0;
101
- this.lastCodeSeparator = null;
102
- this.stack = [];
103
- this.altStack = [];
104
- this.ifStack = [];
105
- }
106
- step() {
107
- // If the context is UnlockingScript and we have reached the end,
108
- // set the context to LockingScript and zero the program counter
109
- if (this.context === 'UnlockingScript' &&
110
- this.programCounter >= this.unlockingScript.chunks.length) {
111
- this.context = 'LockingScript';
112
- this.programCounter = 0;
113
- }
114
- let operation;
115
- if (this.context === 'UnlockingScript') {
116
- operation = this.unlockingScript.chunks[this.programCounter];
117
- }
118
- else {
119
- operation = this.lockingScript.chunks[this.programCounter];
120
- }
121
- const isOpcodeDisabled = (op) => {
122
- return op === OP.OP_2MUL ||
123
- op === OP.OP_2DIV ||
124
- op === OP.OP_VERIF ||
125
- op === OP.OP_VERNOTIF ||
126
- op === OP.OP_VER;
127
- };
128
- const isChunkMinimal = (chunk) => {
129
- const data = chunk.data;
130
- const op = chunk.op;
131
- if (!Array.isArray(data)) {
132
- return true;
133
- }
134
- if (data.length === 0) {
135
- // Could have used OP_0.
136
- return op === OP.OP_0;
137
- }
138
- else if (data.length === 1 && data[0] >= 1 && data[0] <= 16) {
139
- // Could have used OP_1 .. OP_16.
140
- return op === OP.OP_1 + (data[0] - 1);
141
- }
142
- else if (data.length === 1 && data[0] === 0x81) {
143
- // Could have used OP_1NEGATE.
144
- return op === OP.OP_1NEGATE;
145
- }
146
- else if (data.length <= 75) {
147
- // Could have used a direct push (opCode indicating number of bytes pushed + those bytes).
148
- return op === data.length;
149
- }
150
- else if (data.length <= 255) {
151
- // Could have used OP_PUSHDATA.
152
- return op === OP.OP_PUSHDATA1;
153
- }
154
- else if (data.length <= 65535) {
155
- // Could have used OP_PUSHDATA2.
156
- return op === OP.OP_PUSHDATA2;
157
- }
158
- return true;
159
- };
160
- // Following example from sCrypt now using Number.MAX_SAFE_INTEGER (bsv/lib/transaction/input/input.js).
161
- const isMinimallyEncoded = (buf, maxNumSize = Number.MAX_SAFE_INTEGER) => {
162
- if (buf.length > maxNumSize) {
163
- return false;
164
- }
165
- if (buf.length > 0) {
166
- // Check that the number is encoded with the minimum possible number
167
- // of bytes.
168
- //
169
- // If the most-significant-byte - excluding the sign bit - is zero
170
- // then we're not minimal. Note how this test also rejects the
171
- // negative-zero encoding, 0x80.
172
- if ((buf[buf.length - 1] & 0x7f) === 0) {
173
- // One exception: if there's more than one byte and the most
174
- // significant bit of the second-most-significant-byte is set it
175
- // would conflict with the sign bit. An example of this case is
176
- // +-255, which encode to 0xff00 and 0xff80 respectively.
177
- // (big-endian).
178
- if (buf.length <= 1 || (buf[buf.length - 2] & 0x80) === 0) {
179
- return false;
180
- }
181
- }
182
- }
183
- return true;
184
- };
185
- const minimallyEncode = (buf) => {
186
- if (buf.length === 0) {
187
- return buf;
188
- }
189
- // If the last byte is not 0x00 or 0x80, we are minimally encoded.
190
- const last = buf[buf.length - 1];
191
- if ((last & 0x7f) !== 0) {
192
- return buf;
193
- }
194
- // If the script is one byte long, then we have a zero, which encodes as an
195
- // empty array.
196
- if (buf.length === 1) {
197
- return [];
198
- }
199
- // If the next byte has it sign bit set, then we are minimaly encoded.
200
- if ((buf[buf.length - 2] & 0x80) !== 0) {
201
- return buf;
202
- }
203
- // We are not minimally encoded, we need to figure out how much to trim.
204
- for (let i = buf.length - 1; i > 0; i--) {
205
- // We found a non zero byte, time to encode.
206
- if (buf[i - 1] !== 0) {
207
- if ((buf[i - 1] & 0x80) !== 0) {
208
- // We found a byte with it sign bit set so we need one more
209
- // byte.
210
- buf[i++] = last;
211
- }
212
- else {
213
- // the sign bit is clear, we can use it.
214
- buf[i - 1] |= last;
215
- }
216
- return buf.slice(0, i);
217
- }
218
- }
219
- // If we found the whole thing is zeros, then we have a zero.
220
- return [];
221
- };
222
- const padDataToSize = (buf, len) => {
223
- let b = buf;
224
- while (b.length < len) {
225
- b = [0x00, ...b];
226
- }
227
- return b;
228
- };
229
- /**
230
- * This function is translated from bitcoind's IsDERSignature and is used in
231
- * the script interpreter. This "DER" format actually includes an extra byte,
232
- * the nHashType, at the end. It is really the tx format, not DER format.
233
- *
234
- * A canonical signature exists of: [30] [total len] [02] [len R] [R] [02] [len S] [S] [hashtype]
235
- * Where R and S are not negative (their first byte has its highest bit not set), and not
236
- * excessively padded (do not start with a 0 byte, unless an otherwise negative number follows,
237
- * in which case a single 0 byte is necessary and even required).
238
- *
239
- * See https://bitcointalk.org/index.php?topic=8392.msg127623#msg127623
240
- */
241
- const isChecksigFormat = (buf) => {
242
- if (buf.length < 9) {
243
- // Non-canonical signature: too short
244
- return false;
245
- }
246
- if (buf.length > 73) {
247
- // Non-canonical signature: too long
248
- return false;
249
- }
250
- if (buf[0] !== 0x30) {
251
- // Non-canonical signature: wrong type
252
- return false;
253
- }
254
- if (buf[1] !== buf.length - 3) {
255
- // Non-canonical signature: wrong length marker
256
- return false;
257
- }
258
- const nLEnR = buf[3];
259
- if (5 + nLEnR >= buf.length) {
260
- // Non-canonical signature: S length misplaced
261
- return false;
262
- }
263
- const nLEnS = buf[5 + nLEnR];
264
- if (nLEnR + nLEnS + 7 !== buf.length) {
265
- // Non-canonical signature: R+S length mismatch
266
- return false;
267
- }
268
- const R = buf.slice(4);
269
- if (buf[4 - 2] !== 0x02) {
270
- // Non-canonical signature: R value type mismatch
271
- return false;
272
- }
273
- if (nLEnR === 0) {
274
- // Non-canonical signature: R length is zero
275
- return false;
276
- }
277
- if ((R[0] & 0x80) !== 0) {
278
- // Non-canonical signature: R value negative
279
- return false;
280
- }
281
- if (nLEnR > 1 && R[0] === 0x00 && (R[1] & 0x80) === 0) {
282
- // Non-canonical signature: R value excessively padded
283
- return false;
284
- }
285
- const S = buf.slice(6 + nLEnR);
286
- if (buf[6 + nLEnR - 2] !== 0x02) {
287
- // Non-canonical signature: S value type mismatch
288
- return false;
289
- }
290
- if (nLEnS === 0) {
291
- // Non-canonical signature: S length is zero
292
- return false;
293
- }
294
- if ((S[0] & 0x80) !== 0) {
295
- // Non-canonical signature: S value negative
296
- return false;
297
- }
298
- if (nLEnS > 1 && S[0] === 0x00 && (S[1] & 0x80) === 0) {
299
- // Non-canonical signature: S value excessively padded
300
- return false;
301
- }
302
- return true;
303
- };
304
- const checkSignatureEncoding = (buf) => {
305
- // Empty signature. Not strictly DER encoded, but allowed to provide a
306
- // compact way to provide an invalid signature for use with CHECK(MULTI)SIG
307
- if (buf.length === 0) {
308
- return true;
309
- }
310
- if (!isChecksigFormat(buf)) {
311
- this.scriptEvaluationError('The signature format is invalid.');
312
- }
313
- const sig = TransactionSignature.fromChecksigFormat(buf);
314
- if (requireLowSSignatures && !sig.hasLowS()) {
315
- this.scriptEvaluationError('The signature must have a low S value.');
316
- }
317
- if ((sig.scope & TransactionSignature.SIGHASH_FORKID) === 0) {
318
- this.scriptEvaluationError('The signature must use SIGHASH_FORKID.');
319
- return false;
320
- }
321
- return true;
322
- };
323
- const checkPublicKeyEncoding = (buf) => {
324
- if (buf.length < 33) {
325
- this.scriptEvaluationError('The public key is too short, it must be at least 33 bytes.');
326
- }
327
- if (buf[0] === 0x04) {
328
- if (buf.length !== 65) {
329
- this.scriptEvaluationError('The non-compressed public key must be 65 bytes.');
330
- }
331
- }
332
- else if ((buf[0] === 0x02 || buf[0] === 0x03)) {
333
- if (buf.length !== 33) {
334
- this.scriptEvaluationError('The compressed public key must be 33 bytes.');
335
- }
336
- }
337
- else {
338
- this.scriptEvaluationError('The public key is in an unknown format.');
339
- }
340
- return true;
341
- };
342
- const verifySignature = (sig, pubkey, subscript) => {
343
- const preimage = TransactionSignature.format({
344
- sourceTXID: this.sourceTXID,
345
- sourceOutputIndex: this.sourceOutputIndex,
346
- sourceSatoshis: this.sourceSatoshis,
347
- transactionVersion: this.transactionVersion,
348
- otherInputs: this.otherInputs,
349
- outputs: this.outputs,
350
- inputIndex: this.inputIndex,
351
- subscript,
352
- inputSequence: this.inputSequence,
353
- lockTime: this.lockTime,
354
- scope: sig.scope
355
- });
356
- const hash = new BigNumber(Hash.hash256(preimage));
357
- return verify(hash, sig, pubkey);
358
- };
359
- const isScriptExecuting = !this.ifStack.includes(false);
360
- let buf, buf1, buf2, buf3, spliced, n, size, rawnum, num, signbit, x1, x2, x3, bn, bn1, bn2, bn3, bufSig, bufPubkey, subscript, bufHash;
361
- let sig, pubkey, i, fOk, nKeysCount, ikey, ikey2, nSigsCount, isig;
362
- let fValue, fEqual, fSuccess;
363
- // Read instruction
364
- const currentOpcode = operation.op;
365
- if (typeof currentOpcode === 'undefined') {
366
- this.scriptEvaluationError(`An opcode is missing in this chunk of the ${this.context}!`);
367
- }
368
- if (Array.isArray(operation.data) &&
369
- operation.data.length > maxScriptElementSize) {
370
- this.scriptEvaluationError(`It's not currently possible to push data larger than ${maxScriptElementSize} bytes.`);
371
- }
372
- if (isScriptExecuting && isOpcodeDisabled(currentOpcode)) {
373
- this.scriptEvaluationError('This opcode is currently disabled.');
374
- }
375
- if (isScriptExecuting && currentOpcode >= 0 &&
376
- currentOpcode <= OP.OP_PUSHDATA4) {
377
- if (requireMinimalPush && !isChunkMinimal(operation)) {
378
- this.scriptEvaluationError('This data is not minimally-encoded.');
379
- }
380
- if (!Array.isArray(operation.data)) {
381
- this.stack.push([]);
382
- }
383
- else {
384
- this.stack.push(operation.data);
385
- }
386
- }
387
- else if (isScriptExecuting || (OP.OP_IF <= currentOpcode && currentOpcode <= OP.OP_ENDIF)) {
388
- switch (currentOpcode) {
389
- case OP.OP_1NEGATE:
390
- case OP.OP_1:
391
- case OP.OP_2:
392
- case OP.OP_3:
393
- case OP.OP_4:
394
- case OP.OP_5:
395
- case OP.OP_6:
396
- case OP.OP_7:
397
- case OP.OP_8:
398
- case OP.OP_9:
399
- case OP.OP_10:
400
- case OP.OP_11:
401
- case OP.OP_12:
402
- case OP.OP_13:
403
- case OP.OP_14:
404
- case OP.OP_15:
405
- case OP.OP_16:
406
- n = currentOpcode - (OP.OP_1 - 1);
407
- buf = new BigNumber(n).toScriptNum();
408
- this.stack.push(buf);
409
- break;
410
- case OP.OP_NOP:
411
- case OP.OP_NOP2:
412
- case OP.OP_NOP3:
413
- case OP.OP_NOP1:
414
- case OP.OP_NOP4:
415
- case OP.OP_NOP5:
416
- case OP.OP_NOP6:
417
- case OP.OP_NOP7:
418
- case OP.OP_NOP8:
419
- case OP.OP_NOP9:
420
- case OP.OP_NOP10:
421
- case OP.OP_NOP11:
422
- case OP.OP_NOP12:
423
- case OP.OP_NOP13:
424
- case OP.OP_NOP14:
425
- case OP.OP_NOP15:
426
- case OP.OP_NOP16:
427
- case OP.OP_NOP17:
428
- case OP.OP_NOP18:
429
- case OP.OP_NOP19:
430
- case OP.OP_NOP20:
431
- case OP.OP_NOP21:
432
- case OP.OP_NOP22:
433
- case OP.OP_NOP23:
434
- case OP.OP_NOP24:
435
- case OP.OP_NOP25:
436
- case OP.OP_NOP26:
437
- case OP.OP_NOP27:
438
- case OP.OP_NOP28:
439
- case OP.OP_NOP29:
440
- case OP.OP_NOP30:
441
- case OP.OP_NOP31:
442
- case OP.OP_NOP32:
443
- case OP.OP_NOP33:
444
- case OP.OP_NOP34:
445
- case OP.OP_NOP35:
446
- case OP.OP_NOP36:
447
- case OP.OP_NOP37:
448
- case OP.OP_NOP38:
449
- case OP.OP_NOP39:
450
- case OP.OP_NOP40:
451
- case OP.OP_NOP41:
452
- case OP.OP_NOP42:
453
- case OP.OP_NOP43:
454
- case OP.OP_NOP44:
455
- case OP.OP_NOP45:
456
- case OP.OP_NOP46:
457
- case OP.OP_NOP47:
458
- case OP.OP_NOP48:
459
- case OP.OP_NOP49:
460
- case OP.OP_NOP50:
461
- case OP.OP_NOP51:
462
- case OP.OP_NOP52:
463
- case OP.OP_NOP53:
464
- case OP.OP_NOP54:
465
- case OP.OP_NOP55:
466
- case OP.OP_NOP56:
467
- case OP.OP_NOP57:
468
- case OP.OP_NOP58:
469
- case OP.OP_NOP59:
470
- case OP.OP_NOP60:
471
- case OP.OP_NOP61:
472
- case OP.OP_NOP62:
473
- case OP.OP_NOP63:
474
- case OP.OP_NOP64:
475
- case OP.OP_NOP65:
476
- case OP.OP_NOP66:
477
- case OP.OP_NOP67:
478
- case OP.OP_NOP68:
479
- case OP.OP_NOP69:
480
- case OP.OP_NOP70:
481
- case OP.OP_NOP71:
482
- case OP.OP_NOP72:
483
- case OP.OP_NOP73:
484
- case OP.OP_NOP77:
485
- break;
486
- case OP.OP_IF:
487
- case OP.OP_NOTIF:
488
- fValue = false;
489
- if (isScriptExecuting) {
490
- if (this.stack.length < 1) {
491
- this.scriptEvaluationError('OP_IF and OP_NOTIF require at least one item on the stack when they are used!');
492
- }
493
- buf = this.stacktop(-1);
494
- fValue = this.castToBool(buf);
495
- if (currentOpcode === OP.OP_NOTIF) {
496
- fValue = !fValue;
497
- }
498
- this.stack.pop();
499
- }
500
- this.ifStack.push(fValue);
501
- break;
502
- case OP.OP_ELSE:
503
- if (this.ifStack.length === 0) {
504
- this.scriptEvaluationError('OP_ELSE requires a preceeding OP_IF.');
505
- }
506
- this.ifStack[this.ifStack.length - 1] = !this.ifStack[this.ifStack.length - 1];
507
- break;
508
- case OP.OP_ENDIF:
509
- if (this.ifStack.length === 0) {
510
- this.scriptEvaluationError('OP_ENDIF requires a preceeding OP_IF.');
511
- }
512
- this.ifStack.pop();
513
- break;
514
- case OP.OP_VERIFY:
515
- if (this.stack.length < 1) {
516
- this.scriptEvaluationError('OP_VERIFY requires at least one item to be on the stack.');
517
- }
518
- buf = this.stacktop(-1);
519
- fValue = this.castToBool(buf);
520
- if (fValue) {
521
- this.stack.pop();
522
- }
523
- else {
524
- this.scriptEvaluationError('OP_VERIFY requires the top stack value to be truthy.');
525
- }
526
- break;
527
- case OP.OP_RETURN:
528
- if (this.context === 'UnlockingScript') {
529
- this.programCounter = this.unlockingScript.chunks.length;
530
- }
531
- else {
532
- this.programCounter = this.lockingScript.chunks.length;
533
- }
534
- this.ifStack = [];
535
- break;
536
- case OP.OP_TOALTSTACK:
537
- if (this.stack.length < 1) {
538
- this.scriptEvaluationError('OP_TOALTSTACK requires at oeast one item to be on the stack.');
539
- }
540
- this.altStack.push(this.stack.pop());
541
- break;
542
- case OP.OP_FROMALTSTACK:
543
- if (this.altStack.length < 1) {
544
- this.scriptEvaluationError('OP_FROMALTSTACK requires at least one item to be on the stack.');
545
- }
546
- this.stack.push(this.altStack.pop());
547
- break;
548
- case OP.OP_2DROP:
549
- if (this.stack.length < 2) {
550
- this.scriptEvaluationError('OP_2DROP requires at least two items to be on the stack.');
551
- }
552
- this.stack.pop();
553
- this.stack.pop();
554
- break;
555
- case OP.OP_2DUP:
556
- if (this.stack.length < 2) {
557
- this.scriptEvaluationError('OP_2DUP requires at least two items to be on the stack.');
558
- }
559
- buf1 = this.stacktop(-2);
560
- buf2 = this.stacktop(-1);
561
- this.stack.push([...buf1]);
562
- this.stack.push([...buf2]);
563
- break;
564
- case OP.OP_3DUP:
565
- if (this.stack.length < 3) {
566
- this.scriptEvaluationError('OP_3DUP requires at least three items to be on the stack.');
567
- }
568
- buf1 = this.stacktop(-3);
569
- buf2 = this.stacktop(-2);
570
- buf3 = this.stacktop(-1);
571
- this.stack.push([...buf1]);
572
- this.stack.push([...buf2]);
573
- this.stack.push([...buf3]);
574
- break;
575
- case OP.OP_2OVER:
576
- if (this.stack.length < 4) {
577
- this.scriptEvaluationError('OP_2OVER requires at least four items to be on the stack.');
578
- }
579
- buf1 = this.stacktop(-4);
580
- buf2 = this.stacktop(-3);
581
- this.stack.push([...buf1]);
582
- this.stack.push([...buf2]);
583
- break;
584
- case OP.OP_2ROT:
585
- if (this.stack.length < 6) {
586
- this.scriptEvaluationError('OP_2ROT requires at least six items to be on the stack.');
587
- }
588
- spliced = this.stack.splice(this.stack.length - 6, 2);
589
- this.stack.push(spliced[0]);
590
- this.stack.push(spliced[1]);
591
- break;
592
- case OP.OP_2SWAP:
593
- if (this.stack.length < 4) {
594
- this.scriptEvaluationError('OP_2SWAP requires at least four items to be on the stack.');
595
- }
596
- spliced = this.stack.splice(this.stack.length - 4, 2);
597
- this.stack.push(spliced[0]);
598
- this.stack.push(spliced[1]);
599
- break;
600
- case OP.OP_IFDUP:
601
- if (this.stack.length < 1) {
602
- this.scriptEvaluationError('OP_IFDUP requires at least one item to be on the stack.');
603
- }
604
- buf = this.stacktop(-1);
605
- fValue = this.castToBool(buf);
606
- if (fValue) {
607
- this.stack.push([...buf]);
608
- }
609
- break;
610
- case OP.OP_DEPTH:
611
- buf = new BigNumber(this.stack.length).toScriptNum();
612
- this.stack.push(buf);
613
- break;
614
- case OP.OP_DROP:
615
- if (this.stack.length < 1) {
616
- this.scriptEvaluationError('OP_DROP requires at least one item to be on the stack.');
617
- }
618
- this.stack.pop();
619
- break;
620
- case OP.OP_DUP:
621
- if (this.stack.length < 1) {
622
- this.scriptEvaluationError('OP_DUP requires at least one item to be on the stack.');
623
- }
624
- this.stack.push([...this.stacktop(-1)]);
625
- break;
626
- case OP.OP_NIP:
627
- if (this.stack.length < 2) {
628
- this.scriptEvaluationError('OP_NIP requires at least two items to be on the stack.');
629
- }
630
- this.stack.splice(this.stack.length - 2, 1);
631
- break;
632
- case OP.OP_OVER:
633
- if (this.stack.length < 2) {
634
- this.scriptEvaluationError('OP_OVER requires at least two items to be on the stack.');
635
- }
636
- this.stack.push([...this.stacktop(-2)]);
637
- break;
638
- case OP.OP_PICK:
639
- case OP.OP_ROLL:
640
- if (this.stack.length < 2) {
641
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least two items to be on the stack.`);
642
- }
643
- buf = this.stacktop(-1);
644
- bn = BigNumber.fromScriptNum(buf, requireMinimalPush);
645
- n = bn.toNumber();
646
- this.stack.pop();
647
- if (n < 0 || n >= this.stack.length) {
648
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the top stack element to be 0 or a positive number less than the current size of the stack.`);
649
- }
650
- buf = this.stacktop(-n - 1);
651
- if (currentOpcode === OP.OP_ROLL) {
652
- this.stack.splice(this.stack.length - n - 1, 1);
653
- }
654
- this.stack.push([...buf]);
655
- break;
656
- case OP.OP_ROT:
657
- if (this.stack.length < 3) {
658
- this.scriptEvaluationError('OP_ROT requires at least three items to be on the stack.');
659
- }
660
- x1 = this.stacktop(-3);
661
- x2 = this.stacktop(-2);
662
- x3 = this.stacktop(-1);
663
- this.stack[this.stack.length - 3] = x2;
664
- this.stack[this.stack.length - 2] = x3;
665
- this.stack[this.stack.length - 1] = x1;
666
- break;
667
- case OP.OP_SWAP:
668
- if (this.stack.length < 2) {
669
- this.scriptEvaluationError('OP_SWAP requires at least two items to be on the stack.');
670
- }
671
- x1 = this.stacktop(-2);
672
- x2 = this.stacktop(-1);
673
- this.stack[this.stack.length - 2] = x2;
674
- this.stack[this.stack.length - 1] = x1;
675
- break;
676
- case OP.OP_TUCK:
677
- if (this.stack.length < 2) {
678
- this.scriptEvaluationError('OP_TUCK requires at least two items to be on the stack.');
679
- }
680
- this.stack.splice(this.stack.length - 2, 0, [...this.stacktop(-1)]);
681
- break;
682
- case OP.OP_SIZE:
683
- if (this.stack.length < 1) {
684
- this.scriptEvaluationError('OP_SIZE requires at least one item to be on the stack.');
685
- }
686
- bn = new BigNumber(this.stacktop(-1).length);
687
- this.stack.push(bn.toScriptNum());
688
- break;
689
- case OP.OP_AND:
690
- case OP.OP_OR:
691
- case OP.OP_XOR:
692
- if (this.stack.length < 2) {
693
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least one item to be on the stack.`);
694
- }
695
- buf1 = this.stacktop(-2);
696
- buf2 = this.stacktop(-1);
697
- if (buf1.length !== buf2.length) {
698
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the top two stack items to be the same size.`);
699
- }
700
- switch (currentOpcode) {
701
- case OP.OP_AND:
702
- for (let i = 0; i < buf1.length; i++) {
703
- buf1[i] &= buf2[i];
704
- }
705
- break;
706
- case OP.OP_OR:
707
- for (let i = 0; i < buf1.length; i++) {
708
- buf1[i] |= buf2[i];
709
- }
710
- break;
711
- case OP.OP_XOR:
712
- for (let i = 0; i < buf1.length; i++) {
713
- buf1[i] ^= buf2[i];
714
- }
715
- break;
716
- }
717
- // And pop vch2.
718
- this.stack.pop();
719
- break;
720
- case OP.OP_INVERT:
721
- if (this.stack.length < 1) {
722
- this.scriptEvaluationError('OP_INVERT requires at least one item to be on the stack.');
723
- }
724
- buf = this.stacktop(-1);
725
- for (let i = 0; i < buf.length; i++) {
726
- buf[i] = ~buf[i];
727
- }
728
- break;
729
- case OP.OP_LSHIFT:
730
- case OP.OP_RSHIFT:
731
- if (this.stack.length < 2) {
732
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least two items to be on the stack.`);
733
- }
734
- buf1 = this.stacktop(-2);
735
- if (buf1.length === 0) {
736
- this.stack.pop();
737
- }
738
- else {
739
- bn1 = new BigNumber(buf1);
740
- bn2 = BigNumber.fromScriptNum(this.stacktop(-1), requireMinimalPush);
741
- n = bn2.toNumber();
742
- if (n < 0) {
743
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the top item on the stack not to be negative.`);
744
- }
745
- this.stack.pop();
746
- this.stack.pop();
747
- let shifted;
748
- if (currentOpcode === OP.OP_LSHIFT) {
749
- shifted = bn1.ushln(n);
750
- }
751
- if (currentOpcode === OP.OP_RSHIFT) {
752
- shifted = bn1.ushrn(n);
753
- }
754
- const bufShifted = padDataToSize([...shifted.toArray().slice(buf1.length * -1)], buf1.length);
755
- this.stack.push(bufShifted);
756
- }
757
- break;
758
- case OP.OP_EQUAL:
759
- case OP.OP_EQUALVERIFY:
760
- if (this.stack.length < 2) {
761
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least two items to be on the stack.`);
762
- }
763
- buf1 = this.stacktop(-2);
764
- buf2 = this.stacktop(-1);
765
- fEqual = toHex(buf1) === toHex(buf2);
766
- this.stack.pop();
767
- this.stack.pop();
768
- this.stack.push(fEqual ? [1] : []);
769
- if (currentOpcode === OP.OP_EQUALVERIFY) {
770
- if (fEqual) {
771
- this.stack.pop();
772
- }
773
- else {
774
- this.scriptEvaluationError('OP_EQUALVERIFY requires the top two stack items to be equal.');
775
- }
776
- }
777
- break;
778
- case OP.OP_1ADD:
779
- case OP.OP_1SUB:
780
- case OP.OP_NEGATE:
781
- case OP.OP_ABS:
782
- case OP.OP_NOT:
783
- case OP.OP_0NOTEQUAL:
784
- if (this.stack.length < 1) {
785
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least one items to be on the stack.`);
786
- }
787
- buf = this.stacktop(-1);
788
- bn = BigNumber.fromScriptNum(buf, requireMinimalPush);
789
- switch (currentOpcode) {
790
- case OP.OP_1ADD:
791
- bn = bn.addn(1);
792
- break;
793
- case OP.OP_1SUB:
794
- bn = bn.subn(1);
795
- break;
796
- case OP.OP_NEGATE:
797
- bn = bn.neg();
798
- break;
799
- case OP.OP_ABS:
800
- if (bn.cmpn(0) < 0) {
801
- bn = bn.neg();
802
- }
803
- break;
804
- case OP.OP_NOT:
805
- bn = new BigNumber((bn.cmpn(0) === 0) ? 1 : 0 + 0);
806
- break;
807
- case OP.OP_0NOTEQUAL:
808
- bn = new BigNumber((bn.cmpn(0) !== 0) ? 1 : 0 + 0);
809
- break;
810
- }
811
- this.stack.pop();
812
- this.stack.push(bn.toScriptNum());
813
- break;
814
- case OP.OP_ADD:
815
- case OP.OP_SUB:
816
- case OP.OP_MUL:
817
- case OP.OP_MOD:
818
- case OP.OP_DIV:
819
- case OP.OP_BOOLAND:
820
- case OP.OP_BOOLOR:
821
- case OP.OP_NUMEQUAL:
822
- case OP.OP_NUMEQUALVERIFY:
823
- case OP.OP_NUMNOTEQUAL:
824
- case OP.OP_LESSTHAN:
825
- case OP.OP_GREATERTHAN:
826
- case OP.OP_LESSTHANOREQUAL:
827
- case OP.OP_GREATERTHANOREQUAL:
828
- case OP.OP_MIN:
829
- case OP.OP_MAX:
830
- if (this.stack.length < 2) {
831
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least two items to be on the stack.`);
832
- }
833
- bn1 = BigNumber.fromScriptNum(this.stacktop(-2), requireMinimalPush);
834
- bn2 = BigNumber.fromScriptNum(this.stacktop(-1), requireMinimalPush);
835
- bn = new BigNumber(0);
836
- switch (currentOpcode) {
837
- case OP.OP_ADD:
838
- bn = bn1.add(bn2);
839
- break;
840
- case OP.OP_SUB:
841
- bn = bn1.sub(bn2);
842
- break;
843
- case OP.OP_MUL:
844
- bn = bn1.mul(bn2);
845
- break;
846
- case OP.OP_DIV:
847
- if (bn2.cmpn(0) === 0) {
848
- this.scriptEvaluationError('OP_DIV cannot divide by zero!');
849
- }
850
- bn = bn1.div(bn2);
851
- break;
852
- case OP.OP_MOD:
853
- if (bn2.cmpn(0) === 0) {
854
- this.scriptEvaluationError('OP_MOD cannot divide by zero!');
855
- }
856
- bn = bn1.mod(bn2);
857
- break;
858
- case OP.OP_BOOLAND:
859
- bn = new BigNumber(((bn1.cmpn(0) !== 0) && (bn2.cmpn(0) !== 0)) ? 1 : 0 + 0);
860
- break;
861
- case OP.OP_BOOLOR:
862
- bn = new BigNumber(((bn1.cmpn(0) !== 0) || (bn2.cmpn(0) !== 0)) ? 1 : 0 + 0);
863
- break;
864
- case OP.OP_NUMEQUAL:
865
- bn = new BigNumber((bn1.cmp(bn2) === 0) ? 1 : 0 + 0);
866
- break;
867
- case OP.OP_NUMEQUALVERIFY:
868
- bn = new BigNumber((bn1.cmp(bn2) === 0) ? 1 : 0 + 0);
869
- break;
870
- case OP.OP_NUMNOTEQUAL:
871
- bn = new BigNumber((bn1.cmp(bn2) !== 0) ? 1 : 0 + 0);
872
- break;
873
- case OP.OP_LESSTHAN:
874
- bn = new BigNumber((bn1.cmp(bn2) < 0) ? 1 : 0 + 0);
875
- break;
876
- case OP.OP_GREATERTHAN:
877
- bn = new BigNumber((bn1.cmp(bn2) > 0) ? 1 : 0 + 0);
878
- break;
879
- case OP.OP_LESSTHANOREQUAL:
880
- bn = new BigNumber((bn1.cmp(bn2) <= 0) ? 1 : 0 + 0);
881
- break;
882
- case OP.OP_GREATERTHANOREQUAL:
883
- bn = new BigNumber((bn1.cmp(bn2) >= 0) ? 1 : 0 + 0);
884
- break;
885
- case OP.OP_MIN:
886
- bn = (bn1.cmp(bn2) < 0 ? bn1 : bn2);
887
- break;
888
- case OP.OP_MAX:
889
- bn = (bn1.cmp(bn2) > 0 ? bn1 : bn2);
890
- break;
891
- }
892
- this.stack.pop();
893
- this.stack.pop();
894
- this.stack.push(bn.toScriptNum());
895
- if (currentOpcode === OP.OP_NUMEQUALVERIFY) {
896
- if (this.castToBool(this.stacktop(-1))) {
897
- this.stack.pop();
898
- }
899
- else {
900
- this.scriptEvaluationError('OP_NUMEQUALVERIFY requires the top stack item to be truthy.');
901
- }
902
- }
903
- break;
904
- case OP.OP_WITHIN:
905
- if (this.stack.length < 3) {
906
- this.scriptEvaluationError('OP_WITHIN requires at least three items to be on the stack.');
907
- }
908
- bn1 = BigNumber.fromScriptNum(this.stacktop(-3), requireMinimalPush);
909
- bn2 = BigNumber.fromScriptNum(this.stacktop(-2), requireMinimalPush);
910
- bn3 = BigNumber.fromScriptNum(this.stacktop(-1), requireMinimalPush);
911
- fValue = (bn2.cmp(bn1) <= 0) && (bn1.cmp(bn3) < 0);
912
- this.stack.pop();
913
- this.stack.pop();
914
- this.stack.pop();
915
- this.stack.push(fValue ? [1] : []);
916
- break;
917
- case OP.OP_RIPEMD160:
918
- case OP.OP_SHA1:
919
- case OP.OP_SHA256:
920
- case OP.OP_HASH160:
921
- case OP.OP_HASH256:
922
- if (this.stack.length < 1) {
923
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least one item to be on the stack.`);
924
- }
925
- buf = this.stacktop(-1);
926
- if (currentOpcode === OP.OP_RIPEMD160) {
927
- bufHash = Hash.ripemd160(buf);
928
- }
929
- else if (currentOpcode === OP.OP_SHA1) {
930
- bufHash = Hash.sha1(buf);
931
- }
932
- else if (currentOpcode === OP.OP_SHA256) {
933
- bufHash = Hash.sha256(buf);
934
- }
935
- else if (currentOpcode === OP.OP_HASH160) {
936
- bufHash = Hash.hash160(buf);
937
- }
938
- else if (currentOpcode === OP.OP_HASH256) {
939
- bufHash = Hash.hash256(buf);
940
- }
941
- this.stack.pop();
942
- this.stack.push(bufHash);
943
- break;
944
- case OP.OP_CODESEPARATOR:
945
- this.lastCodeSeparator = this.programCounter;
946
- break;
947
- case OP.OP_CHECKSIG:
948
- case OP.OP_CHECKSIGVERIFY:
949
- if (this.stack.length < 2) {
950
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least two items to be on the stack.`);
951
- }
952
- bufSig = this.stacktop(-2);
953
- bufPubkey = this.stacktop(-1);
954
- if (!checkSignatureEncoding(bufSig) ||
955
- !checkPublicKeyEncoding(bufPubkey)) {
956
- this.scriptEvaluationError(`${OP[currentOpcode]} requires correct encoding for the public key and signature.`);
957
- }
958
- // Subset of script starting at the most recent codeseparator
959
- // CScript scriptCode(pbegincodehash, pend);
960
- if (this.context === 'UnlockingScript') {
961
- subscript = new Script(this.unlockingScript.chunks.slice(this.lastCodeSeparator));
962
- }
963
- else {
964
- subscript = new Script(this.lockingScript.chunks.slice(this.lastCodeSeparator));
965
- }
966
- // Drop the signature, since there's no way for a signature to sign itself
967
- subscript.findAndDelete(new Script().writeBin(bufSig));
968
- try {
969
- sig = TransactionSignature.fromChecksigFormat(bufSig);
970
- pubkey = PublicKey.fromString(toHex(bufPubkey));
971
- fSuccess = verifySignature(sig, pubkey, subscript);
972
- }
973
- catch (e) {
974
- // invalid sig or pubkey
975
- fSuccess = false;
976
- }
977
- if (!fSuccess && bufSig.length > 0) {
978
- this.scriptEvaluationError(`${OP[currentOpcode]} failed to verify the signature, and requires an empty signature when verification fails.`);
979
- }
980
- this.stack.pop();
981
- this.stack.pop();
982
- // stack.push_back(fSuccess ? vchTrue : vchFalse);
983
- this.stack.push(fSuccess ? [1] : []);
984
- if (currentOpcode === OP.OP_CHECKSIGVERIFY) {
985
- if (fSuccess) {
986
- this.stack.pop();
987
- }
988
- else {
989
- this.scriptEvaluationError('OP_CHECKSIGVERIFY requires that a valid signature is provided.');
990
- }
991
- }
992
- break;
993
- case OP.OP_CHECKMULTISIG:
994
- case OP.OP_CHECKMULTISIGVERIFY:
995
- i = 1;
996
- if (this.stack.length < i) {
997
- this.scriptEvaluationError(`${OP[currentOpcode]} requires at least 1 item to be on the stack.`);
998
- }
999
- nKeysCount = BigNumber.fromScriptNum(this.stacktop(-i), requireMinimalPush).toNumber();
1000
- // TODO: Keys and opcount are parameterized in client. No magic numbers!
1001
- if (nKeysCount < 0 || nKeysCount > maxMultisigKeyCount) {
1002
- this.scriptEvaluationError(`${OP[currentOpcode]} requires a key count between 0 and ${maxMultisigKeyCount}.`);
1003
- }
1004
- ikey = ++i;
1005
- i += nKeysCount;
1006
- // ikey2 is the position of last non-signature item in
1007
- // the stack. Top stack item = 1. With
1008
- // SCRIPT_VERIFY_NULLFAIL, this is used for cleanup if
1009
- // operation fails.
1010
- ikey2 = nKeysCount + 2;
1011
- if (this.stack.length < i) {
1012
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the number of stack items not to be less than the number of keys used.`);
1013
- }
1014
- nSigsCount = BigNumber.fromScriptNum(this.stacktop(-i), requireMinimalPush).toNumber();
1015
- if (nSigsCount < 0 || nSigsCount > nKeysCount) {
1016
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the number of signatures to be no greater than the number of keys.`);
1017
- }
1018
- isig = ++i;
1019
- i += nSigsCount;
1020
- if (this.stack.length < i) {
1021
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the number of stack items not to be less than the number of signatures provided.`);
1022
- }
1023
- // Subset of script starting at the most recent codeseparator
1024
- if (this.context === 'UnlockingScript') {
1025
- subscript = new Script(this.unlockingScript.chunks.slice(this.lastCodeSeparator));
1026
- }
1027
- else {
1028
- subscript = new Script(this.lockingScript.chunks.slice(this.lastCodeSeparator));
1029
- }
1030
- // Drop the signatures, since there's no way for a signature to sign itself
1031
- for (let k = 0; k < nSigsCount; k++) {
1032
- bufSig = this.stacktop(-isig - k);
1033
- subscript.findAndDelete(new Script().writeBin(bufSig));
1034
- }
1035
- fSuccess = true;
1036
- while (fSuccess && nSigsCount > 0) {
1037
- // valtype& vchSig = this.stacktop(-isig);
1038
- bufSig = this.stacktop(-isig);
1039
- // valtype& vchPubKey = this.stacktop(-ikey);
1040
- bufPubkey = this.stacktop(-ikey);
1041
- if (!checkSignatureEncoding(bufSig) ||
1042
- !checkPublicKeyEncoding(bufPubkey)) {
1043
- this.scriptEvaluationError(`${OP[currentOpcode]} requires correct encoding for the public key and signature.`);
1044
- }
1045
- try {
1046
- sig = TransactionSignature.fromChecksigFormat(bufSig);
1047
- pubkey = PublicKey.fromString(toHex(bufPubkey));
1048
- fOk = verifySignature(sig, pubkey, subscript);
1049
- }
1050
- catch (e) {
1051
- // invalid sig or pubkey
1052
- fOk = false;
1053
- }
1054
- if (fOk) {
1055
- isig++;
1056
- nSigsCount--;
1057
- }
1058
- ikey++;
1059
- nKeysCount--;
1060
- // If there are more signatures left than keys left,
1061
- // then too many signatures have failed
1062
- if (nSigsCount > nKeysCount) {
1063
- fSuccess = false;
1064
- }
1065
- }
1066
- // Clean up stack of actual arguments
1067
- while (i-- > 1) {
1068
- if (!fSuccess && !ikey2 && (this.stacktop(-1).length > 0)) {
1069
- this.scriptEvaluationError(`${OP[currentOpcode]} failed to verify a signature, and requires an empty signature when verification fails.`);
1070
- }
1071
- if (ikey2 > 0) {
1072
- ikey2--;
1073
- }
1074
- this.stack.pop();
1075
- }
1076
- // A bug causes CHECKMULTISIG to consume one extra argument
1077
- // whose contents were not checked in any way.
1078
- //
1079
- // Unfortunately this is a potential source of mutability,
1080
- // so optionally verify it is exactly equal to zero prior
1081
- // to removing it from the stack.
1082
- if (this.stack.length < 1) {
1083
- this.scriptEvaluationError(`${OP[currentOpcode]} requires an extra item to be on the stack.`);
1084
- }
1085
- if (this.stacktop(-1).length > 0) { // NOTE: Is this necessary? We don't care about malleability.
1086
- this.scriptEvaluationError(`${OP[currentOpcode]} requires the extra stack item to be empty.`);
1087
- }
1088
- this.stack.pop();
1089
- this.stack.push(fSuccess ? [1] : []);
1090
- if (currentOpcode === OP.OP_CHECKMULTISIGVERIFY) {
1091
- if (fSuccess) {
1092
- this.stack.pop();
1093
- }
1094
- else {
1095
- this.scriptEvaluationError('OP_CHECKMULTISIGVERIFY requires that a sufficient number of valid signatures are provided.');
1096
- }
1097
- }
1098
- break;
1099
- case OP.OP_CAT:
1100
- if (this.stack.length < 2) {
1101
- this.scriptEvaluationError('OP_CAT requires at least two items to be on the stack.');
1102
- }
1103
- buf1 = this.stacktop(-2);
1104
- buf2 = this.stacktop(-1);
1105
- if (buf1.length + buf2.length > maxScriptElementSize) {
1106
- this.scriptEvaluationError(`It's not currently possible to push data larger than ${maxScriptElementSize} bytes.`);
1107
- }
1108
- this.stack[this.stack.length - 2] = [...buf1, ...buf2];
1109
- this.stack.pop();
1110
- break;
1111
- case OP.OP_SPLIT:
1112
- if (this.stack.length < 2) {
1113
- this.scriptEvaluationError('OP_SPLIT requires at least two items to be on the stack.');
1114
- }
1115
- buf1 = this.stacktop(-2);
1116
- // Make sure the split point is apropriate.
1117
- n = BigNumber.fromScriptNum(this.stacktop(-1), requireMinimalPush).toNumber();
1118
- if (n < 0 || n > buf1.length) {
1119
- this.scriptEvaluationError('OP_SPLIT requires the first stack item to be a non-negative number less than or equal to the size of the second-from-top stack item.');
1120
- }
1121
- // Prepare the results in their own buffer as `data`
1122
- // will be invalidated.
1123
- // Copy buffer data, to slice it before
1124
- buf2 = [...buf1];
1125
- // Replace existing stack values by the new values.
1126
- this.stack[this.stack.length - 2] = buf2.slice(0, n);
1127
- this.stack[this.stack.length - 1] = buf2.slice(n);
1128
- break;
1129
- case OP.OP_NUM2BIN:
1130
- if (this.stack.length < 2) {
1131
- this.scriptEvaluationError('OP_NUM2BIN requires at least two items to be on the stack.');
1132
- }
1133
- size = BigNumber.fromScriptNum(this.stacktop(-1), requireMinimalPush).toNumber();
1134
- if (size > maxScriptElementSize) {
1135
- this.scriptEvaluationError(`It's not currently possible to push data larger than ${maxScriptElementSize} bytes.`);
1136
- }
1137
- this.stack.pop();
1138
- rawnum = this.stacktop(-1);
1139
- // Try to see if we can fit that number in the number of
1140
- // byte requested.
1141
- rawnum = minimallyEncode(rawnum);
1142
- if (rawnum.length > size) {
1143
- this.scriptEvaluationError('OP_NUM2BIN requires that the size expressed in the top stack item is large enough to hold the value expressed in the second-from-top stack item.');
1144
- }
1145
- // We already have an element of the right size, we
1146
- // don't need to do anything.
1147
- if (rawnum.length === size) {
1148
- this.stack[this.stack.length - 1] = rawnum;
1149
- break;
1150
- }
1151
- signbit = 0x00;
1152
- if (rawnum.length > 0) {
1153
- signbit = rawnum[rawnum.length - 1] & 0x80;
1154
- rawnum[rawnum.length - 1] &= 0x7f;
1155
- }
1156
- num = new Array(size);
1157
- num.fill(0);
1158
- for (n = 0; n < size; n++) {
1159
- num[n] = rawnum[n];
1160
- }
1161
- n = rawnum.length - 1;
1162
- while (n++ < size - 2) {
1163
- num[n] = 0x00;
1164
- }
1165
- num[n] = signbit;
1166
- this.stack[this.stack.length - 1] = num;
1167
- break;
1168
- case OP.OP_BIN2NUM:
1169
- if (this.stack.length < 1) {
1170
- this.scriptEvaluationError('OP_BIN2NUM requires at least one item to be on the stack.');
1171
- }
1172
- buf1 = this.stacktop(-1);
1173
- buf2 = minimallyEncode(buf1);
1174
- this.stack[this.stack.length - 1] = buf2;
1175
- // The resulting number must be a valid number.
1176
- if (!isMinimallyEncoded(buf2)) {
1177
- this.scriptEvaluationError('OP_BIN2NUM requires that the resulting number is valid.');
1178
- }
1179
- break;
1180
- default:
1181
- this.scriptEvaluationError('Invalid opcode!');
1182
- }
1183
- }
1184
- // Finally, increment the program counter
1185
- this.programCounter++;
1186
- }
1187
- /**
1188
- * @method validate
1189
- * Validates the spend action by interpreting the locking and unlocking scripts.
1190
- * @returns {boolean} Returns true if the scripts are valid and the spend is legitimate, otherwise false.
1191
- * @example
1192
- * if (spend.validate()) {
1193
- * console.log("Spend is valid!");
1194
- * } else {
1195
- * console.log("Invalid spend!");
1196
- * }
1197
- */
1198
- validate() {
1199
- if (requirePushOnlyUnlockingScripts && !this.unlockingScript.isPushOnly()) {
1200
- this.scriptEvaluationError('Unlocking scripts can only contain push operations, and no other opcodes.');
1201
- }
1202
- while (true) {
1203
- this.step();
1204
- if (this.context === 'LockingScript' && this.programCounter >= this.lockingScript.chunks.length) {
1205
- break;
1206
- }
1207
- }
1208
- if (this.ifStack.length > 0) {
1209
- this.scriptEvaluationError('Every OP_IF must be terminated prior to the end of the script.');
1210
- }
1211
- if (requireCleanStack) {
1212
- if (this.stack.length !== 1) {
1213
- this.scriptEvaluationError('The clean stack rule requires exactly one item to be on the stack after script execution.');
1214
- }
1215
- }
1216
- if (!this.castToBool(this.stacktop(-1))) {
1217
- this.scriptEvaluationError('The top stack element must be truthy after script evaluation.');
1218
- }
1219
- return true;
1220
- }
1221
- stacktop(i) {
1222
- return this.stack[this.stack.length + i];
1223
- }
1224
- castToBool(val) {
1225
- for (let i = 0; i < val.length; i++) {
1226
- if (val[i] !== 0) {
1227
- // can be negative zero
1228
- if (i === val.length - 1 && val[i] === 0x80) {
1229
- return false;
1230
- }
1231
- return true;
1232
- }
1233
- }
1234
- return false;
1235
- }
1236
- scriptEvaluationError(str) {
1237
- throw new Error(`Script evaluation error: ${str}\n\nSource TXID: ${this.sourceTXID}\nSource output index: ${this.sourceOutputIndex}\nContext: ${this.context}\nProgram counter: ${this.programCounter}\nStack size: ${this.stack.length}\nAlt stack size: ${this.altStack.length}`);
1238
- }
1239
- }
1240
- //# sourceMappingURL=Spend.js.map