@bsv/sdk 2.0.16 → 2.1.1

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 (405) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/package.json +14 -13
  3. package/dist/cjs/src/auth/Peer.js +8 -13
  4. package/dist/cjs/src/auth/Peer.js.map +1 -1
  5. package/dist/cjs/src/auth/SessionManager.js +4 -7
  6. package/dist/cjs/src/auth/SessionManager.js.map +1 -1
  7. package/dist/cjs/src/auth/certificates/MasterCertificate.js +1 -1
  8. package/dist/cjs/src/auth/certificates/MasterCertificate.js.map +1 -1
  9. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  10. package/dist/cjs/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  11. package/dist/cjs/src/auth/clients/AuthFetch.js +32 -32
  12. package/dist/cjs/src/auth/clients/AuthFetch.js.map +1 -1
  13. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  14. package/dist/cjs/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  15. package/dist/cjs/src/compat/ECIES.js +29 -34
  16. package/dist/cjs/src/compat/ECIES.js.map +1 -1
  17. package/dist/cjs/src/compat/HD.js +9 -4
  18. package/dist/cjs/src/compat/HD.js.map +1 -1
  19. package/dist/cjs/src/compat/Mnemonic.js +12 -12
  20. package/dist/cjs/src/compat/Mnemonic.js.map +1 -1
  21. package/dist/cjs/src/identity/ContactsManager.js +172 -232
  22. package/dist/cjs/src/identity/ContactsManager.js.map +1 -1
  23. package/dist/cjs/src/identity/IdentityClient.js +122 -55
  24. package/dist/cjs/src/identity/IdentityClient.js.map +1 -1
  25. package/dist/cjs/src/kvstore/GlobalKVStore.js +30 -31
  26. package/dist/cjs/src/kvstore/GlobalKVStore.js.map +1 -1
  27. package/dist/cjs/src/kvstore/LocalKVStore.js +9 -9
  28. package/dist/cjs/src/kvstore/LocalKVStore.js.map +1 -1
  29. package/dist/cjs/src/kvstore/kvStoreInterpreter.js +2 -2
  30. package/dist/cjs/src/kvstore/kvStoreInterpreter.js.map +1 -1
  31. package/dist/cjs/src/messages/SignedMessage.js +1 -1
  32. package/dist/cjs/src/messages/SignedMessage.js.map +1 -1
  33. package/dist/cjs/src/overlay-tools/Historian.js +1 -1
  34. package/dist/cjs/src/overlay-tools/Historian.js.map +1 -1
  35. package/dist/cjs/src/overlay-tools/LookupResolver.js +139 -46
  36. package/dist/cjs/src/overlay-tools/LookupResolver.js.map +1 -1
  37. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js +75 -146
  38. package/dist/cjs/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  39. package/dist/cjs/src/primitives/AESGCM.js +2 -2
  40. package/dist/cjs/src/primitives/AESGCM.js.map +1 -1
  41. package/dist/cjs/src/primitives/BigNumber.js +164 -148
  42. package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
  43. package/dist/cjs/src/primitives/Curve.js +17 -15
  44. package/dist/cjs/src/primitives/Curve.js.map +1 -1
  45. package/dist/cjs/src/primitives/ECDSA.js +12 -7
  46. package/dist/cjs/src/primitives/ECDSA.js.map +1 -1
  47. package/dist/cjs/src/primitives/Hash.js +140 -56
  48. package/dist/cjs/src/primitives/Hash.js.map +1 -1
  49. package/dist/cjs/src/primitives/JacobianPoint.js +8 -8
  50. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -1
  51. package/dist/cjs/src/primitives/K256.js +3 -3
  52. package/dist/cjs/src/primitives/K256.js.map +1 -1
  53. package/dist/cjs/src/primitives/Point.js +36 -40
  54. package/dist/cjs/src/primitives/Point.js.map +1 -1
  55. package/dist/cjs/src/primitives/PrivateKey.js +4 -4
  56. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  57. package/dist/cjs/src/primitives/PublicKey.js +4 -4
  58. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  59. package/dist/cjs/src/primitives/Random.js +10 -14
  60. package/dist/cjs/src/primitives/Random.js.map +1 -1
  61. package/dist/cjs/src/primitives/ReaderUint8Array.js +6 -6
  62. package/dist/cjs/src/primitives/ReaderUint8Array.js.map +1 -1
  63. package/dist/cjs/src/primitives/Schnorr.js +2 -2
  64. package/dist/cjs/src/primitives/Schnorr.js.map +1 -1
  65. package/dist/cjs/src/primitives/Secp256r1.js +2 -1
  66. package/dist/cjs/src/primitives/Secp256r1.js.map +1 -1
  67. package/dist/cjs/src/primitives/Signature.js +8 -8
  68. package/dist/cjs/src/primitives/Signature.js.map +1 -1
  69. package/dist/cjs/src/primitives/TransactionSignature.js +20 -21
  70. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -1
  71. package/dist/cjs/src/primitives/utils.js +39 -46
  72. package/dist/cjs/src/primitives/utils.js.map +1 -1
  73. package/dist/cjs/src/registry/RegistryClient.js +31 -23
  74. package/dist/cjs/src/registry/RegistryClient.js.map +1 -1
  75. package/dist/cjs/src/remittance/RemittanceManager.js +19 -18
  76. package/dist/cjs/src/remittance/RemittanceManager.js.map +1 -1
  77. package/dist/cjs/src/remittance/modules/BasicBRC29.js.map +1 -1
  78. package/dist/cjs/src/script/Script.js +93 -170
  79. package/dist/cjs/src/script/Script.js.map +1 -1
  80. package/dist/cjs/src/script/ScriptEvaluationError.js +2 -2
  81. package/dist/cjs/src/script/ScriptEvaluationError.js.map +1 -1
  82. package/dist/cjs/src/script/Spend.js +14 -12
  83. package/dist/cjs/src/script/Spend.js.map +1 -1
  84. package/dist/cjs/src/script/templates/PushDrop.js +22 -18
  85. package/dist/cjs/src/script/templates/PushDrop.js.map +1 -1
  86. package/dist/cjs/src/script/templates/RPuzzle.js +2 -4
  87. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  88. package/dist/cjs/src/storage/StorageDownloader.js +42 -9
  89. package/dist/cjs/src/storage/StorageDownloader.js.map +1 -1
  90. package/dist/cjs/src/totp/totp.js +1 -1
  91. package/dist/cjs/src/totp/totp.js.map +1 -1
  92. package/dist/cjs/src/transaction/Beef.js +239 -192
  93. package/dist/cjs/src/transaction/Beef.js.map +1 -1
  94. package/dist/cjs/src/transaction/BeefConstants.js +19 -0
  95. package/dist/cjs/src/transaction/BeefConstants.js.map +1 -0
  96. package/dist/cjs/src/transaction/BeefTx.js +12 -12
  97. package/dist/cjs/src/transaction/BeefTx.js.map +1 -1
  98. package/dist/cjs/src/transaction/MerklePath.js +4 -4
  99. package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
  100. package/dist/cjs/src/transaction/Transaction.js +49 -52
  101. package/dist/cjs/src/transaction/Transaction.js.map +1 -1
  102. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  103. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  104. package/dist/cjs/src/transaction/http/BinaryFetchClient.js +9 -9
  105. package/dist/cjs/src/transaction/http/BinaryFetchClient.js.map +1 -1
  106. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +9 -9
  107. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  108. package/dist/cjs/src/wallet/CachedKeyDeriver.js +1 -1
  109. package/dist/cjs/src/wallet/CachedKeyDeriver.js.map +1 -1
  110. package/dist/cjs/src/wallet/WalletClient.js.map +1 -1
  111. package/dist/cjs/src/wallet/WalletError.js.map +1 -1
  112. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  113. package/dist/cjs/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  114. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js +9 -9
  115. package/dist/cjs/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  116. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js +92 -92
  117. package/dist/cjs/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  118. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  119. package/dist/cjs/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  120. package/dist/cjs/src/wallet/substrates/XDM.js +4 -4
  121. package/dist/cjs/src/wallet/substrates/XDM.js.map +1 -1
  122. package/dist/cjs/src/wallet/substrates/window.CWI.js +2 -2
  123. package/dist/cjs/src/wallet/substrates/window.CWI.js.map +1 -1
  124. package/dist/cjs/src/wallet/validationHelpers.js +9 -9
  125. package/dist/cjs/src/wallet/validationHelpers.js.map +1 -1
  126. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  127. package/dist/esm/src/auth/Peer.js +25 -13
  128. package/dist/esm/src/auth/Peer.js.map +1 -1
  129. package/dist/esm/src/auth/SessionManager.js +4 -7
  130. package/dist/esm/src/auth/SessionManager.js.map +1 -1
  131. package/dist/esm/src/auth/certificates/MasterCertificate.js +1 -1
  132. package/dist/esm/src/auth/certificates/MasterCertificate.js.map +1 -1
  133. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js +1 -1
  134. package/dist/esm/src/auth/certificates/__tests/CompletedProtoWallet.js.map +1 -1
  135. package/dist/esm/src/auth/clients/AuthFetch.js +32 -32
  136. package/dist/esm/src/auth/clients/AuthFetch.js.map +1 -1
  137. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js +4 -4
  138. package/dist/esm/src/auth/transports/SimplifiedFetchTransport.js.map +1 -1
  139. package/dist/esm/src/compat/ECIES.js +29 -34
  140. package/dist/esm/src/compat/ECIES.js.map +1 -1
  141. package/dist/esm/src/compat/HD.js +9 -4
  142. package/dist/esm/src/compat/HD.js.map +1 -1
  143. package/dist/esm/src/compat/Mnemonic.js +12 -12
  144. package/dist/esm/src/compat/Mnemonic.js.map +1 -1
  145. package/dist/esm/src/identity/ContactsManager.js +172 -232
  146. package/dist/esm/src/identity/ContactsManager.js.map +1 -1
  147. package/dist/esm/src/identity/IdentityClient.js +122 -55
  148. package/dist/esm/src/identity/IdentityClient.js.map +1 -1
  149. package/dist/esm/src/kvstore/GlobalKVStore.js +30 -31
  150. package/dist/esm/src/kvstore/GlobalKVStore.js.map +1 -1
  151. package/dist/esm/src/kvstore/LocalKVStore.js +9 -9
  152. package/dist/esm/src/kvstore/LocalKVStore.js.map +1 -1
  153. package/dist/esm/src/kvstore/kvStoreInterpreter.js +2 -2
  154. package/dist/esm/src/kvstore/kvStoreInterpreter.js.map +1 -1
  155. package/dist/esm/src/messages/SignedMessage.js +1 -1
  156. package/dist/esm/src/messages/SignedMessage.js.map +1 -1
  157. package/dist/esm/src/overlay-tools/Historian.js +1 -1
  158. package/dist/esm/src/overlay-tools/Historian.js.map +1 -1
  159. package/dist/esm/src/overlay-tools/LookupResolver.js +139 -46
  160. package/dist/esm/src/overlay-tools/LookupResolver.js.map +1 -1
  161. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js +74 -146
  162. package/dist/esm/src/overlay-tools/SHIPBroadcaster.js.map +1 -1
  163. package/dist/esm/src/primitives/AESGCM.js +2 -2
  164. package/dist/esm/src/primitives/AESGCM.js.map +1 -1
  165. package/dist/esm/src/primitives/BigNumber.js +167 -154
  166. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  167. package/dist/esm/src/primitives/Curve.js +17 -15
  168. package/dist/esm/src/primitives/Curve.js.map +1 -1
  169. package/dist/esm/src/primitives/ECDSA.js +12 -7
  170. package/dist/esm/src/primitives/ECDSA.js.map +1 -1
  171. package/dist/esm/src/primitives/Hash.js +140 -56
  172. package/dist/esm/src/primitives/Hash.js.map +1 -1
  173. package/dist/esm/src/primitives/JacobianPoint.js +8 -8
  174. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -1
  175. package/dist/esm/src/primitives/K256.js +3 -3
  176. package/dist/esm/src/primitives/K256.js.map +1 -1
  177. package/dist/esm/src/primitives/Point.js +36 -40
  178. package/dist/esm/src/primitives/Point.js.map +1 -1
  179. package/dist/esm/src/primitives/PrivateKey.js +4 -4
  180. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  181. package/dist/esm/src/primitives/PublicKey.js +4 -4
  182. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  183. package/dist/esm/src/primitives/Random.js +10 -14
  184. package/dist/esm/src/primitives/Random.js.map +1 -1
  185. package/dist/esm/src/primitives/ReaderUint8Array.js +6 -6
  186. package/dist/esm/src/primitives/ReaderUint8Array.js.map +1 -1
  187. package/dist/esm/src/primitives/Schnorr.js +1 -1
  188. package/dist/esm/src/primitives/Schnorr.js.map +1 -1
  189. package/dist/esm/src/primitives/Secp256r1.js +2 -1
  190. package/dist/esm/src/primitives/Secp256r1.js.map +1 -1
  191. package/dist/esm/src/primitives/Signature.js +8 -8
  192. package/dist/esm/src/primitives/Signature.js.map +1 -1
  193. package/dist/esm/src/primitives/TransactionSignature.js +20 -21
  194. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -1
  195. package/dist/esm/src/primitives/utils.js +39 -48
  196. package/dist/esm/src/primitives/utils.js.map +1 -1
  197. package/dist/esm/src/registry/RegistryClient.js +31 -23
  198. package/dist/esm/src/registry/RegistryClient.js.map +1 -1
  199. package/dist/esm/src/remittance/RemittanceManager.js +19 -18
  200. package/dist/esm/src/remittance/RemittanceManager.js.map +1 -1
  201. package/dist/esm/src/remittance/modules/BasicBRC29.js.map +1 -1
  202. package/dist/esm/src/script/Script.js +93 -170
  203. package/dist/esm/src/script/Script.js.map +1 -1
  204. package/dist/esm/src/script/ScriptEvaluationError.js +2 -2
  205. package/dist/esm/src/script/ScriptEvaluationError.js.map +1 -1
  206. package/dist/esm/src/script/Spend.js +14 -12
  207. package/dist/esm/src/script/Spend.js.map +1 -1
  208. package/dist/esm/src/script/templates/PushDrop.js +4 -3
  209. package/dist/esm/src/script/templates/PushDrop.js.map +1 -1
  210. package/dist/esm/src/script/templates/RPuzzle.js +2 -4
  211. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  212. package/dist/esm/src/storage/StorageDownloader.js +1 -1
  213. package/dist/esm/src/storage/StorageDownloader.js.map +1 -1
  214. package/dist/esm/src/totp/totp.js +1 -1
  215. package/dist/esm/src/totp/totp.js.map +1 -1
  216. package/dist/esm/src/transaction/Beef.js +229 -186
  217. package/dist/esm/src/transaction/Beef.js.map +1 -1
  218. package/dist/esm/src/transaction/BeefConstants.js +16 -0
  219. package/dist/esm/src/transaction/BeefConstants.js.map +1 -0
  220. package/dist/esm/src/transaction/BeefTx.js +3 -3
  221. package/dist/esm/src/transaction/BeefTx.js.map +1 -1
  222. package/dist/esm/src/transaction/MerklePath.js +4 -4
  223. package/dist/esm/src/transaction/MerklePath.js.map +1 -1
  224. package/dist/esm/src/transaction/Transaction.js +49 -52
  225. package/dist/esm/src/transaction/Transaction.js.map +1 -1
  226. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +1 -1
  227. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  228. package/dist/esm/src/transaction/http/BinaryFetchClient.js +9 -9
  229. package/dist/esm/src/transaction/http/BinaryFetchClient.js.map +1 -1
  230. package/dist/esm/src/transaction/http/DefaultHttpClient.js +9 -9
  231. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  232. package/dist/esm/src/wallet/CachedKeyDeriver.js +1 -1
  233. package/dist/esm/src/wallet/CachedKeyDeriver.js.map +1 -1
  234. package/dist/esm/src/wallet/WalletClient.js.map +1 -1
  235. package/dist/esm/src/wallet/WalletError.js.map +1 -1
  236. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js +5 -4
  237. package/dist/esm/src/wallet/substrates/HTTPWalletJSON.js.map +1 -1
  238. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js +9 -9
  239. package/dist/esm/src/wallet/substrates/ReactNativeWebView.js.map +1 -1
  240. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js +92 -92
  241. package/dist/esm/src/wallet/substrates/WalletWireProcessor.js.map +1 -1
  242. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js +387 -711
  243. package/dist/esm/src/wallet/substrates/WalletWireTransceiver.js.map +1 -1
  244. package/dist/esm/src/wallet/substrates/XDM.js +4 -4
  245. package/dist/esm/src/wallet/substrates/XDM.js.map +1 -1
  246. package/dist/esm/src/wallet/substrates/window.CWI.js +2 -2
  247. package/dist/esm/src/wallet/substrates/window.CWI.js.map +1 -1
  248. package/dist/esm/src/wallet/validationHelpers.js +9 -9
  249. package/dist/esm/src/wallet/validationHelpers.js.map +1 -1
  250. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  251. package/dist/types/src/auth/Peer.d.ts +13 -0
  252. package/dist/types/src/auth/Peer.d.ts.map +1 -1
  253. package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
  254. package/dist/types/src/auth/clients/AuthFetch.d.ts.map +1 -1
  255. package/dist/types/src/compat/ECIES.d.ts.map +1 -1
  256. package/dist/types/src/compat/HD.d.ts.map +1 -1
  257. package/dist/types/src/identity/ContactsManager.d.ts +18 -0
  258. package/dist/types/src/identity/ContactsManager.d.ts.map +1 -1
  259. package/dist/types/src/identity/IdentityClient.d.ts +47 -8
  260. package/dist/types/src/identity/IdentityClient.d.ts.map +1 -1
  261. package/dist/types/src/kvstore/GlobalKVStore.d.ts.map +1 -1
  262. package/dist/types/src/overlay-tools/LookupResolver.d.ts +59 -1
  263. package/dist/types/src/overlay-tools/LookupResolver.d.ts.map +1 -1
  264. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts +18 -3
  265. package/dist/types/src/overlay-tools/SHIPBroadcaster.d.ts.map +1 -1
  266. package/dist/types/src/primitives/BigNumber.d.ts +13 -3
  267. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
  268. package/dist/types/src/primitives/Curve.d.ts.map +1 -1
  269. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -1
  270. package/dist/types/src/primitives/Hash.d.ts +3 -3
  271. package/dist/types/src/primitives/Hash.d.ts.map +1 -1
  272. package/dist/types/src/primitives/JacobianPoint.d.ts +3 -1
  273. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -1
  274. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  275. package/dist/types/src/primitives/Random.d.ts +2 -2
  276. package/dist/types/src/primitives/Random.d.ts.map +1 -1
  277. package/dist/types/src/primitives/ReaderUint8Array.d.ts.map +1 -1
  278. package/dist/types/src/primitives/Schnorr.d.ts +2 -1
  279. package/dist/types/src/primitives/Schnorr.d.ts.map +1 -1
  280. package/dist/types/src/primitives/Secp256r1.d.ts.map +1 -1
  281. package/dist/types/src/primitives/utils.d.ts +2 -4
  282. package/dist/types/src/primitives/utils.d.ts.map +1 -1
  283. package/dist/types/src/registry/RegistryClient.d.ts.map +1 -1
  284. package/dist/types/src/remittance/RemittanceManager.d.ts.map +1 -1
  285. package/dist/types/src/remittance/modules/BasicBRC29.d.ts.map +1 -1
  286. package/dist/types/src/script/Script.d.ts +15 -8
  287. package/dist/types/src/script/Script.d.ts.map +1 -1
  288. package/dist/types/src/script/Spend.d.ts.map +1 -1
  289. package/dist/types/src/script/templates/PushDrop.d.ts +3 -1
  290. package/dist/types/src/script/templates/PushDrop.d.ts.map +1 -1
  291. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -1
  292. package/dist/types/src/transaction/Beef.d.ts +46 -8
  293. package/dist/types/src/transaction/Beef.d.ts.map +1 -1
  294. package/dist/types/src/transaction/BeefConstants.d.ts +15 -0
  295. package/dist/types/src/transaction/BeefConstants.d.ts.map +1 -0
  296. package/dist/types/src/transaction/Transaction.d.ts.map +1 -1
  297. package/dist/types/src/wallet/CachedKeyDeriver.d.ts.map +1 -1
  298. package/dist/types/src/wallet/KeyDeriver.d.ts +1 -1
  299. package/dist/types/src/wallet/KeyDeriver.d.ts.map +1 -1
  300. package/dist/types/src/wallet/Wallet.interfaces.d.ts +2 -2
  301. package/dist/types/src/wallet/Wallet.interfaces.d.ts.map +1 -1
  302. package/dist/types/src/wallet/WalletClient.d.ts +7 -7
  303. package/dist/types/src/wallet/WalletClient.d.ts.map +1 -1
  304. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts +7 -7
  305. package/dist/types/src/wallet/substrates/HTTPWalletJSON.d.ts.map +1 -1
  306. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts +36 -7
  307. package/dist/types/src/wallet/substrates/WalletWireTransceiver.d.ts.map +1 -1
  308. package/dist/types/src/wallet/substrates/window.CWI.d.ts +8 -8
  309. package/dist/types/src/wallet/substrates/window.CWI.d.ts.map +1 -1
  310. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  311. package/dist/umd/bundle.js +3 -3
  312. package/docs/reference/kvstore.md +1 -2
  313. package/docs/reference/primitives.md +0 -1
  314. package/docs/reference/script.md +0 -7
  315. package/docs/reference/transaction.md +2 -2
  316. package/package.json +29 -28
  317. package/src/auth/Peer.ts +26 -13
  318. package/src/auth/SessionManager.ts +4 -7
  319. package/src/auth/certificates/MasterCertificate.ts +1 -1
  320. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -1
  321. package/src/auth/clients/AuthFetch.ts +41 -41
  322. package/src/auth/transports/SimplifiedFetchTransport.ts +4 -4
  323. package/src/compat/ECIES.ts +29 -34
  324. package/src/compat/HD.ts +10 -5
  325. package/src/compat/Mnemonic.ts +11 -11
  326. package/src/compat/__tests/HD.test.ts +19 -0
  327. package/src/identity/ContactsManager.ts +194 -257
  328. package/src/identity/IdentityClient.ts +155 -66
  329. package/src/identity/__tests/IdentityClient.test.ts +25 -1
  330. package/src/kvstore/GlobalKVStore.ts +31 -32
  331. package/src/kvstore/LocalKVStore.ts +8 -8
  332. package/src/kvstore/kvStoreInterpreter.ts +2 -2
  333. package/src/messages/SignedMessage.ts +1 -1
  334. package/src/overlay-tools/Historian.ts +1 -1
  335. package/src/overlay-tools/LookupResolver.ts +182 -45
  336. package/src/overlay-tools/SHIPBroadcaster.ts +92 -168
  337. package/src/primitives/AESGCM.ts +2 -2
  338. package/src/primitives/BigNumber.ts +122 -113
  339. package/src/primitives/Curve.ts +16 -15
  340. package/src/primitives/ECDSA.ts +10 -8
  341. package/src/primitives/Hash.ts +152 -53
  342. package/src/primitives/JacobianPoint.ts +13 -11
  343. package/src/primitives/K256.ts +3 -3
  344. package/src/primitives/Point.ts +35 -38
  345. package/src/primitives/PrivateKey.ts +3 -3
  346. package/src/primitives/PublicKey.ts +3 -3
  347. package/src/primitives/Random.ts +11 -14
  348. package/src/primitives/ReaderUint8Array.ts +7 -7
  349. package/src/primitives/Schnorr.ts +2 -1
  350. package/src/primitives/Secp256r1.ts +2 -1
  351. package/src/primitives/Signature.ts +8 -8
  352. package/src/primitives/TransactionSignature.ts +16 -16
  353. package/src/primitives/utils.ts +37 -47
  354. package/src/registry/RegistryClient.ts +25 -25
  355. package/src/remittance/RemittanceManager.ts +17 -18
  356. package/src/remittance/modules/BasicBRC29.ts +2 -5
  357. package/src/script/Script.ts +114 -170
  358. package/src/script/ScriptEvaluationError.ts +2 -2
  359. package/src/script/Spend.ts +14 -15
  360. package/src/script/templates/PushDrop.ts +5 -3
  361. package/src/script/templates/RPuzzle.ts +2 -4
  362. package/src/storage/StorageDownloader.ts +1 -1
  363. package/src/totp/totp.ts +1 -1
  364. package/src/transaction/Beef.ts +241 -203
  365. package/src/transaction/BeefConstants.ts +16 -0
  366. package/src/transaction/BeefTx.ts +3 -3
  367. package/src/transaction/MerklePath.ts +4 -4
  368. package/src/transaction/Transaction.ts +48 -51
  369. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +1 -1
  370. package/src/transaction/http/BinaryFetchClient.ts +8 -8
  371. package/src/transaction/http/DefaultHttpClient.ts +8 -8
  372. package/src/wallet/CachedKeyDeriver.ts +8 -6
  373. package/src/wallet/KeyDeriver.ts +1 -1
  374. package/src/wallet/Wallet.interfaces.ts +2 -4
  375. package/src/wallet/WalletClient.ts +8 -8
  376. package/src/wallet/WalletError.ts +1 -1
  377. package/src/wallet/__tests/WalletClient.substrate.test.ts +10 -6
  378. package/src/wallet/substrates/HTTPWalletJSON.ts +22 -21
  379. package/src/wallet/substrates/ReactNativeWebView.ts +9 -9
  380. package/src/wallet/substrates/WalletWireProcessor.ts +83 -83
  381. package/src/wallet/substrates/WalletWireTransceiver.ts +528 -938
  382. package/src/wallet/substrates/XDM.ts +4 -4
  383. package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +38 -25
  384. package/src/wallet/substrates/__tests/ReactNativeWebView.test.ts +174 -0
  385. package/src/wallet/substrates/__tests/window.CWI.test.ts +256 -0
  386. package/src/wallet/substrates/window.CWI.ts +10 -10
  387. package/src/wallet/validationHelpers.ts +9 -9
  388. package/docs/swagger/dist/LICENSE +0 -21
  389. package/docs/swagger/dist/favicon-16x16.png +0 -0
  390. package/docs/swagger/dist/favicon-32x32.png +0 -0
  391. package/docs/swagger/dist/index.css +0 -16
  392. package/docs/swagger/dist/oauth2-redirect.html +0 -79
  393. package/docs/swagger/dist/swagger-initializer.js +0 -20
  394. package/docs/swagger/dist/swagger-ui-bundle.js +0 -2
  395. package/docs/swagger/dist/swagger-ui-bundle.js.map +0 -1
  396. package/docs/swagger/dist/swagger-ui-es-bundle-core.js +0 -3
  397. package/docs/swagger/dist/swagger-ui-es-bundle-core.js.map +0 -1
  398. package/docs/swagger/dist/swagger-ui-es-bundle.js +0 -2
  399. package/docs/swagger/dist/swagger-ui-es-bundle.js.map +0 -1
  400. package/docs/swagger/dist/swagger-ui-standalone-preset.js +0 -2
  401. package/docs/swagger/dist/swagger-ui-standalone-preset.js.map +0 -1
  402. package/docs/swagger/dist/swagger-ui.css +0 -3
  403. package/docs/swagger/dist/swagger-ui.css.map +0 -1
  404. package/docs/swagger/dist/swagger-ui.js +0 -2
  405. package/docs/swagger/dist/swagger-ui.js.map +0 -1
@@ -4,15 +4,8 @@ import ChainTracker from './ChainTracker.js'
4
4
  import BeefTx from './BeefTx.js'
5
5
  import { Reader, Writer, toHex, toArray, verifyNotNull, ReaderUint8Array, WriterUint8Array, toUint8Array } from '../primitives/utils.js'
6
6
  import { hash256 } from '../primitives/Hash.js'
7
-
8
- export const BEEF_V1 = 4022206465 // 0100BEEF in LE order
9
- export const BEEF_V2 = 4022206466 // 0200BEEF in LE order
10
- export const ATOMIC_BEEF = 0x01010101 // 01010101
11
- export enum TX_DATA_FORMAT {
12
- RAWTX = 0, // rawtx without BUMP
13
- RAWTX_AND_BUMP_INDEX = 1, // rawtx with bump index
14
- TXID_ONLY = 2, // txid only
15
- }
7
+ import { BEEF_V1, BEEF_V2, ATOMIC_BEEF } from './BeefConstants.js'
8
+ export { BEEF_V1, BEEF_V2, ATOMIC_BEEF, TX_DATA_FORMAT } from './BeefConstants.js'
16
9
 
17
10
  /*
18
11
  * BEEF standard: BRC-62: Background Evaluation Extended Format (BEEF) Transactions
@@ -95,7 +88,9 @@ export class Beef {
95
88
 
96
89
  private ensureSerializableState (): void {
97
90
  for (const tx of this.txs) {
98
- void tx.txid
91
+ // Access txid to ensure it is computed before serialization
92
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
93
+ tx.txid
99
94
  }
100
95
  }
101
96
 
@@ -126,7 +121,7 @@ export class Beef {
126
121
  }
127
122
 
128
123
  // If the transaction is not the last one, clone and modify
129
- const beef = (this.txs[this.txs.length - 1] === tx) ? this : this.clone()
124
+ const beef = (this.txs.at(-1) === tx) ? this : this.clone()
130
125
 
131
126
  if (beef !== this) {
132
127
  const i = this.txs.findIndex((t) => t.txid === txid)
@@ -195,7 +190,7 @@ export class Beef {
195
190
  */
196
191
  findBump (txid: string): MerklePath | undefined {
197
192
  return this.bumps.find((b) =>
198
- b.path[0].some((leaf) => leaf.hash === txid) // ✅ Ensure boolean return with `.some()`
193
+ b.path[0].some((leaf) => leaf.hash === txid)
199
194
  )
200
195
  }
201
196
 
@@ -236,33 +231,42 @@ export class Beef {
236
231
  const beefTx = this.findTxid(txid)
237
232
  if ((beefTx == null) || (beefTx.tx == null)) return undefined // Ensure beefTx.tx exists before using it
238
233
 
239
- const addInputProof = (beef: Beef, tx: Transaction): void => {
240
- const mp = beef.findBump(tx.id('hex'))
241
- if (mp != null) {
242
- tx.merklePath = mp
243
- } else {
244
- for (const i of tx.inputs) {
245
- if (i.sourceTransaction == null) {
246
- const itx = beef.findTxid(verifyNotNull(i.sourceTXID, 'sourceTXID must be valid'))
247
- if (itx != null) {
248
- i.sourceTransaction = itx.tx
249
- }
250
- }
251
- if (i.sourceTransaction != null) {
252
- const mp = beef.findBump(i.sourceTransaction.id('hex'))
253
- if (mp != null) {
254
- i.sourceTransaction.merklePath = mp
255
- } else {
256
- addInputProof(beef, i.sourceTransaction)
257
- }
258
- }
259
- }
234
+ this.addInputProof(beefTx.tx)
235
+
236
+ return beefTx.tx
237
+ }
238
+
239
+ /** Recursively attach merkle paths and source transactions to all inputs. */
240
+ private addInputProof (tx: Transaction): void {
241
+ const mp = this.findBump(tx.id('hex'))
242
+ if (mp != null) {
243
+ tx.merklePath = mp
244
+ return
245
+ }
246
+ for (const i of tx.inputs) {
247
+ this.resolveInputSource(i)
248
+ if (i.sourceTransaction != null) {
249
+ this.attachMerklePathOrRecurse(i.sourceTransaction)
260
250
  }
261
251
  }
252
+ }
262
253
 
263
- addInputProof(this, beefTx.tx) // Safe because we checked that beefTx.tx exists
254
+ private resolveInputSource (i: Transaction['inputs'][number]): void {
255
+ if (i.sourceTransaction == null) {
256
+ const itx = this.findTxid(verifyNotNull(i.sourceTXID, 'sourceTXID must be valid'))
257
+ if (itx != null) {
258
+ i.sourceTransaction = itx.tx
259
+ }
260
+ }
261
+ }
264
262
 
265
- return beefTx.tx
263
+ private attachMerklePathOrRecurse (sourceTx: Transaction): void {
264
+ const mp = this.findBump(sourceTx.id('hex'))
265
+ if (mp != null) {
266
+ sourceTx.merklePath = mp
267
+ } else {
268
+ this.addInputProof(sourceTx)
269
+ }
266
270
  }
267
271
 
268
272
  /**
@@ -272,52 +276,48 @@ export class Beef {
272
276
  */
273
277
  mergeBump (bump: MerklePath): number {
274
278
  this.markMutated(false)
275
- let bumpIndex: number | undefined
276
- // If this proof is identical to another one previously added, we use that first. Otherwise, we try to merge it with proofs from the same block.
277
- for (let i = 0; i < this.bumps.length; i++) {
278
- const b = this.bumps[i]
279
- if (b === bump) {
280
- // Literally the same
281
- return i
282
- }
283
- if (b.blockHeight === bump.blockHeight) {
284
- // Probably the same...
285
- const rootA = b.computeRoot()
286
- const rootB = bump.computeRoot()
287
- if (rootA === rootB) {
288
- // Definitely the same... combine them to save space
289
- b.combine(bump)
290
- bumpIndex = i
291
- break
292
- }
293
- }
294
- }
295
-
296
- // if the proof is not yet added, add a new path.
297
- if (bumpIndex === undefined) {
298
- bumpIndex = this.bumps.length
299
- this.bumps.push(bump)
300
- }
279
+ const bumpIndex = this.findOrInsertBump(bump)
301
280
 
302
281
  // Review if any transactions are proven by this bump
303
282
  const b = this.bumps[bumpIndex]
304
283
  for (const tx of this.txs) {
305
- const txid = tx.txid
306
-
307
- if (tx.bumpIndex == null) { // ✅ Explicitly check for null or undefined
308
- for (const n of b.path[0]) {
309
- if (n.hash === txid) {
310
- tx.bumpIndex = bumpIndex
311
- n.txid = true
312
- break
313
- }
314
- }
284
+ if (tx.bumpIndex == null) {
285
+ this.tryMarkTxProvenByBump(tx, b, bumpIndex)
315
286
  }
316
287
  }
317
288
 
318
289
  return bumpIndex
319
290
  }
320
291
 
292
+ /**
293
+ * Find an existing compatible bump or insert a new one; return its index.
294
+ */
295
+ private findOrInsertBump (bump: MerklePath): number {
296
+ for (let i = 0; i < this.bumps.length; i++) {
297
+ const b = this.bumps[i]
298
+ if (b === bump) return i
299
+ if (b.blockHeight !== bump.blockHeight) continue
300
+ if (b.computeRoot() === bump.computeRoot()) {
301
+ b.combine(bump)
302
+ return i
303
+ }
304
+ }
305
+ this.bumps.push(bump)
306
+ return this.bumps.length - 1
307
+ }
308
+
309
+ /** If bump's level-0 path contains tx's txid, record the bumpIndex on tx. */
310
+ private tryMarkTxProvenByBump (tx: BeefTx, b: MerklePath, bumpIndex: number): void {
311
+ const txid = tx.txid
312
+ for (const n of b.path[0]) {
313
+ if (n.hash === txid) {
314
+ tx.bumpIndex = bumpIndex
315
+ n.txid = true
316
+ break
317
+ }
318
+ }
319
+ }
320
+
321
321
  /**
322
322
  * Merge a serialized transaction.
323
323
  *
@@ -514,56 +514,72 @@ export class Beef {
514
514
  // valid txids: only txids if allowed, bump txids, then txids with input's in txids
515
515
  const txids: Record<string, boolean> = {}
516
516
 
517
- for (const tx of this.txs) {
518
- if (tx.isTxidOnly) {
519
- if (allowTxidOnly !== true) return r // ✅ Explicit check for `true`
520
- txids[tx.txid] = true
521
- }
522
- }
517
+ if (!this.collectTxidOnlyTxids(txids, allowTxidOnly)) return r
523
518
 
524
- const confirmComputedRoot = (b: MerklePath, txid: string): boolean => {
525
- const root = b.computeRoot(txid)
526
- if (r.roots[b.blockHeight] === undefined || r.roots[b.blockHeight] === '') {
527
- // accept the root as valid for this block and reuse for subsequent txids
528
- r.roots[b.blockHeight] = root
529
- }
530
- if (r.roots[b.blockHeight] !== root) {
531
- return false
532
- }
533
- return true
519
+ if (!this.collectBumpTxids(txids, r)) return r
520
+
521
+ if (!this.verifyBumpIndexLeaves()) return r
522
+
523
+ if (!this.verifyInputDependencies(txids)) return r
524
+
525
+ r.valid = true
526
+ return r
527
+ }
528
+
529
+ /** Add txidOnly transaction txids; return false if not allowed. */
530
+ private collectTxidOnlyTxids (txids: Record<string, boolean>, allowTxidOnly?: boolean): boolean {
531
+ for (const tx of this.txs) {
532
+ if (!tx.isTxidOnly) continue
533
+ if (allowTxidOnly !== true) return false
534
+ txids[tx.txid] = true
534
535
  }
536
+ return true
537
+ }
535
538
 
539
+ /**
540
+ * Record txids proven by bumps; validate all bump roots agree per block height.
541
+ * Returns false if any root conflict is detected.
542
+ */
543
+ private collectBumpTxids (txids: Record<string, boolean>, r: { valid: boolean, roots: Record<number, string> }): boolean {
536
544
  for (const b of this.bumps) {
537
545
  for (const n of b.path[0]) {
538
- if (n.txid === true && typeof n.hash === 'string' && n.hash.length > 0) {
539
- txids[n.hash] = true
540
-
541
- // All txid hashes in all bumps must agree on computed merkle path roots
542
- if (!confirmComputedRoot(b, n.hash)) {
543
- return r
544
- }
545
- }
546
+ if (n.txid !== true || typeof n.hash !== 'string' || n.hash.length === 0) continue
547
+ txids[n.hash] = true
548
+ if (!this.confirmComputedRoot(b, n.hash, r)) return false
546
549
  }
547
550
  }
551
+ return true
552
+ }
548
553
 
549
- // All txs with a bumpIndex have matching txid leaf at level zero of BUMP.
554
+ /** Verify that every tx with a bumpIndex has a matching txid leaf in its bump. */
555
+ private verifyBumpIndexLeaves (): boolean {
550
556
  for (const t of this.txs) {
551
- if (t.bumpIndex !== undefined) {
552
- const leaf = this.bumps[t.bumpIndex].path[0].find(l => l.hash === t.txid)
553
- if (leaf == null) { return r }
554
- }
557
+ if (t.bumpIndex === undefined) continue
558
+ const leaf = this.bumps[t.bumpIndex].path[0].find(l => l.hash === t.txid)
559
+ if (leaf == null) return false
555
560
  }
561
+ return true
562
+ }
556
563
 
564
+ /** Verify all input txids appear before the spending tx in sorted order. */
565
+ private verifyInputDependencies (txids: Record<string, boolean>): boolean {
557
566
  for (const t of this.txs) {
558
- // all input txids must be included before they are referenced
559
567
  for (const i of t.inputTxids) {
560
- if (!txids[i]) return r
568
+ if (!txids[i]) return false
561
569
  }
562
570
  txids[t.txid] = true
563
571
  }
572
+ return true
573
+ }
564
574
 
565
- r.valid = true
566
- return r
575
+ /** Confirm the computed merkle root for txid in bump matches previously accepted root for that height. */
576
+ private confirmComputedRoot (b: MerklePath, txid: string, r: { valid: boolean, roots: Record<number, string> }): boolean {
577
+ const root = b.computeRoot(txid)
578
+ if (r.roots[b.blockHeight] === undefined || r.roots[b.blockHeight] === '') {
579
+ // accept the root as valid for this block and reuse for subsequent txids
580
+ r.roots[b.blockHeight] = root
581
+ }
582
+ return r.roots[b.blockHeight] === root
567
583
  }
568
584
 
569
585
  /**
@@ -747,14 +763,49 @@ export class Beef {
747
763
  // Hashtable of all transaction txids to transaction
748
764
  const txidToTx: Record<string, BeefTx> = {}
749
765
 
750
- // queue of unsorted transactions ...
751
- let queue: BeefTx[] = []
752
-
753
766
  // sorted transactions: hasProof to with longest dependency chain
754
767
  const result: BeefTx[] = []
755
-
756
768
  const txidOnly: BeefTx[] = []
757
769
 
770
+ // Partition into proven, txidOnly, and remaining queue
771
+ let queue = this.partitionTxs(txidToTx, validTxids, result, txidOnly)
772
+
773
+ // Separate queue entries that have missing inputs
774
+ const { txsMissingInputs, missingInputs, remaining } = this.separateMissingInputs(queue, txidToTx)
775
+ queue = remaining
776
+
777
+ // Topological sort of remaining queue
778
+ const txsNotValid = this.topoSort(queue, validTxids, result)
779
+
780
+ // New order of txs is unsortable (missing inputs or depends on missing inputs), txidOnly, sorted (so newest sorted is last)
781
+ this.txs = txsMissingInputs
782
+ .concat(txsNotValid)
783
+ .concat(txidOnly)
784
+ .concat(result)
785
+
786
+ this.needsSort = false
787
+ this.invalidateSerializationCaches()
788
+
789
+ return {
790
+ missingInputs: Object.keys(missingInputs),
791
+ notValid: txsNotValid.map((tx) => tx.txid),
792
+ valid: Object.keys(validTxids),
793
+ withMissingInputs: txsMissingInputs.map((tx) => tx.txid),
794
+ txidOnly: txidOnly.map((tx) => tx.txid)
795
+ }
796
+ }
797
+
798
+ /**
799
+ * Partition txs into proven (result), txidOnly, and a queue of the rest.
800
+ * Populates txidToTx and validTxids as side-effects.
801
+ */
802
+ private partitionTxs (
803
+ txidToTx: Record<string, BeefTx>,
804
+ validTxids: Record<string, boolean>,
805
+ result: BeefTx[],
806
+ txidOnly: BeefTx[]
807
+ ): BeefTx[] {
808
+ const queue: BeefTx[] = []
758
809
  for (const tx of this.txs) {
759
810
  txidToTx[tx.txid] = tx
760
811
  tx.isValid = tx.hasProof
@@ -768,43 +819,45 @@ export class Beef {
768
819
  queue.push(tx)
769
820
  }
770
821
  }
822
+ return queue
823
+ }
771
824
 
772
- // Hashtable of unknown input txids used to fund transactions without their own proof.
825
+ /**
826
+ * Separate queue entries that have at least one input txid not present in txidToTx.
827
+ */
828
+ private separateMissingInputs (
829
+ candidates: BeefTx[],
830
+ txidToTx: Record<string, BeefTx>
831
+ ): { txsMissingInputs: BeefTx[], missingInputs: Record<string, boolean>, remaining: BeefTx[] } {
773
832
  const missingInputs: Record<string, boolean> = {}
774
- // transactions with one or more missing inputs
775
833
  const txsMissingInputs: BeefTx[] = []
834
+ const remaining: BeefTx[] = []
776
835
 
777
- const possiblyMissingInputs = queue
778
- queue = []
779
-
780
- // all tx are isValid false, hasProof false.
781
- // if isTxidOnly then has inputTxids
782
- for (const tx of possiblyMissingInputs) {
836
+ for (const tx of candidates) {
783
837
  let hasMissingInput = false
784
-
785
- // For all the unproven transactions,
786
- // link their inputs that exist in this beef,
787
- // make a note of missing inputs.
788
838
  for (const inputTxid of tx.inputTxids) {
789
- if (txidToTx[inputTxid] === undefined) { // Explicitly check for undefined
839
+ if (txidToTx[inputTxid] === undefined) {
790
840
  missingInputs[inputTxid] = true
791
841
  hasMissingInput = true
792
842
  }
793
843
  }
794
-
795
844
  if (hasMissingInput) {
796
845
  txsMissingInputs.push(tx)
797
846
  } else {
798
- queue.push(tx)
847
+ remaining.push(tx)
799
848
  }
800
849
  }
801
850
 
802
- // As long as we have unsorted transactions...
851
+ return { txsMissingInputs, missingInputs, remaining }
852
+ }
853
+
854
+ /**
855
+ * Topologically sort queue into result; return anything that cannot be sorted.
856
+ */
857
+ private topoSort (queue: BeefTx[], validTxids: Record<string, boolean>, result: BeefTx[]): BeefTx[] {
803
858
  while (queue.length > 0) {
804
859
  const oldQueue = queue
805
860
  queue = []
806
- // all tx are isValid false, hasProof false.
807
- // if isTxidOnly then has inputTxids
808
861
  for (const tx of oldQueue) {
809
862
  if (tx.inputTxids.every((txid) => validTxids[txid])) {
810
863
  validTxids[tx.txid] = true
@@ -813,30 +866,9 @@ export class Beef {
813
866
  queue.push(tx)
814
867
  }
815
868
  }
816
- if (oldQueue.length === queue.length) {
817
- break
818
- }
819
- }
820
-
821
- // transactions that don't have proofs and don't chain to proofs
822
- const txsNotValid = queue
823
-
824
- // New order of txs is unsortable (missing inputs or depends on missing inputs), txidOnly, sorted (so newest sorted is last)
825
- this.txs = txsMissingInputs
826
- .concat(txsNotValid)
827
- .concat(txidOnly)
828
- .concat(result)
829
-
830
- this.needsSort = false
831
- this.invalidateSerializationCaches()
832
-
833
- return {
834
- missingInputs: Object.keys(missingInputs),
835
- notValid: txsNotValid.map((tx) => tx.txid),
836
- valid: Object.keys(validTxids),
837
- withMissingInputs: txsMissingInputs.map((tx) => tx.txid),
838
- txidOnly: txidOnly.map((tx) => tx.txid)
869
+ if (oldQueue.length === queue.length) break
839
870
  }
871
+ return queue
840
872
  }
841
873
 
842
874
  /**
@@ -859,6 +891,15 @@ export class Beef {
859
891
  * @param knownTxids
860
892
  */
861
893
  trimKnownTxids (knownTxids: string[]): void {
894
+ let mutated = this.removeKnownTxidOnlyTxs(knownTxids)
895
+ mutated = this.reindexBumps() || mutated
896
+ if (mutated) {
897
+ this.markMutated(true)
898
+ }
899
+ }
900
+
901
+ /** Remove txidOnly entries that appear in knownTxids; return true if any were removed. */
902
+ private removeKnownTxidOnlyTxs (knownTxids: string[]): boolean {
862
903
  let mutated = false
863
904
  for (let i = 0; i < this.txs.length;) {
864
905
  const tx = this.txs[i]
@@ -870,8 +911,14 @@ export class Beef {
870
911
  i++
871
912
  }
872
913
  }
914
+ return mutated
915
+ }
873
916
 
874
- // Trim unreferenced bumps after removing known txids
917
+ /**
918
+ * Remove bumps that are no longer referenced by any tx and update bumpIndex references.
919
+ * Returns true if any bumps were removed.
920
+ */
921
+ private reindexBumps (): boolean {
875
922
  const referencedBumpIndices = new Set<number>()
876
923
  for (const tx of this.txs) {
877
924
  if (tx.bumpIndex !== undefined) {
@@ -879,38 +926,32 @@ export class Beef {
879
926
  }
880
927
  }
881
928
 
882
- // Check if there are any unreferenced bumps to remove
883
- if (referencedBumpIndices.size < this.bumps.length) {
884
- // Build mapping of old indices to new indices after removal
885
- const indexMap = new Map<number, number>()
886
- let newIndex = 0
887
- for (let i = 0; i < this.bumps.length; i++) {
888
- if (referencedBumpIndices.has(i)) {
889
- indexMap.set(i, newIndex)
890
- newIndex++
891
- }
929
+ if (referencedBumpIndices.size >= this.bumps.length) return false
930
+
931
+ // Build mapping of old indices to new indices after removal
932
+ const indexMap = new Map<number, number>()
933
+ let newIndex = 0
934
+ for (let i = 0; i < this.bumps.length; i++) {
935
+ if (referencedBumpIndices.has(i)) {
936
+ indexMap.set(i, newIndex)
937
+ newIndex++
892
938
  }
939
+ }
893
940
 
894
- // Remove unreferenced bumps
895
- this.bumps = this.bumps.filter((_, i) => referencedBumpIndices.has(i))
941
+ // Remove unreferenced bumps
942
+ this.bumps = this.bumps.filter((_, i) => referencedBumpIndices.has(i))
896
943
 
897
- // Update all transaction bumpIndex references
898
- for (const tx of this.txs) {
899
- if (tx.bumpIndex !== undefined) {
900
- const newIndex = indexMap.get(tx.bumpIndex)
901
- if (newIndex === undefined) {
902
- throw new Error(`Internal error: bumpIndex ${tx.bumpIndex} not found in indexMap`)
903
- }
904
- tx.bumpIndex = newIndex
905
- }
944
+ // Update all transaction bumpIndex references
945
+ for (const tx of this.txs) {
946
+ if (tx.bumpIndex === undefined) continue
947
+ const mapped = indexMap.get(tx.bumpIndex)
948
+ if (mapped === undefined) {
949
+ throw new Error(`Internal error: bumpIndex ${tx.bumpIndex} not found in indexMap`)
906
950
  }
907
-
908
- mutated = true
951
+ tx.bumpIndex = mapped
909
952
  }
910
953
 
911
- if (mutated) {
912
- this.markMutated(true)
913
- }
954
+ return true
914
955
  }
915
956
 
916
957
  /**
@@ -932,7 +973,7 @@ export class Beef {
932
973
  for (const b of this.bumps) {
933
974
  i++
934
975
  log += ` BUMP ${i}\n block: ${b.blockHeight}\n txids: [\n${b.path[0]
935
- .filter((n) => n.txid === true) // ✅ Explicitly check if txid is `true`
976
+ .filter((n) => n.txid === true)
936
977
  .map((n) => ` '${n.hash ?? ''}'`)
937
978
  .join(',\n')}\n ]\n`
938
979
  }
@@ -947,7 +988,7 @@ export class Beef {
947
988
  if (t.isTxidOnly) {
948
989
  log += ' txidOnly\n'
949
990
  } else {
950
- log += ` rawTx length=${t.rawTx?.length ?? 0}\n` // ✅ Fix applied here
991
+ log += ` rawTx length=${t.rawTx?.length ?? 0}\n`
951
992
  }
952
993
  if (t.inputTxids.length > 0) {
953
994
  log += ` inputs: [\n${t.inputTxids
@@ -964,32 +1005,29 @@ export class Beef {
964
1005
  * leaves that can be computed from row zero.
965
1006
  */
966
1007
  addComputedLeaves (): void {
967
- const hash = (m: string): string =>
968
- toHex(hash256(toArray(m, 'hex').reverse()).reverse())
969
-
970
- for (const bump of this.bumps) { // ✅ Use `this` instead of `beef`
1008
+ for (const bump of this.bumps) {
971
1009
  for (let row = 1; row < bump.path.length; row++) {
972
- for (const leafL of bump.path[row - 1]) {
973
- if (typeof leafL.hash === 'string' && (leafL.offset & 1) === 0) {
974
- const leafR = bump.path[row - 1].find(
975
- (l) => l.offset === leafL.offset + 1
976
- )
977
- const offsetOnRow = leafL.offset >> 1
978
-
979
- if (
980
- leafR !== undefined &&
981
- typeof leafR.hash === 'string' &&
982
- bump.path[row].every((l) => l.offset !== offsetOnRow)
983
- ) {
984
- // Computable leaf is missing... add it.
985
- bump.path[row].push({
986
- offset: offsetOnRow,
987
- // String concatenation puts the right leaf on the left of the left leaf hash
988
- hash: hash(leafR.hash + leafL.hash)
989
- })
990
- }
991
- }
992
- }
1010
+ this.addComputedLeavesForRow(bump, row)
1011
+ }
1012
+ }
1013
+ }
1014
+
1015
+ /** Add any missing computable leaf at `row` derived from two known leaves at `row - 1`. */
1016
+ private addComputedLeavesForRow (bump: MerklePath, row: number): void {
1017
+ const hashPair = (m: string): string =>
1018
+ toHex(hash256(toArray(m, 'hex').reverse()).reverse())
1019
+ for (const leafL of bump.path[row - 1]) {
1020
+ if (typeof leafL.hash !== 'string' || (leafL.offset & 1) !== 0) continue
1021
+ const leafR = bump.path[row - 1].find((l) => l.offset === leafL.offset + 1)
1022
+ if (leafR === undefined || typeof leafR.hash !== 'string') continue
1023
+ const offsetOnRow = leafL.offset >> 1
1024
+ if (bump.path[row].every((l) => l.offset !== offsetOnRow)) {
1025
+ // Computable leaf is missing... add it.
1026
+ bump.path[row].push({
1027
+ offset: offsetOnRow,
1028
+ // String concatenation puts the right leaf on the left of the left leaf hash
1029
+ hash: hashPair(leafR.hash + leafL.hash)
1030
+ })
993
1031
  }
994
1032
  }
995
1033
  }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * BEEF format constants extracted to avoid the Beef.ts <-> BeefTx.ts circular import.
3
+ *
4
+ * BEEF standard: BRC-62: Background Evaluation Extended Format (BEEF) Transactions
5
+ * https://github.com/bsv-blockchain/BRCs/blob/master/transactions/0062.md
6
+ */
7
+
8
+ export const BEEF_V1 = 4022206465 // 0100BEEF in LE order
9
+ export const BEEF_V2 = 4022206466 // 0200BEEF in LE order
10
+ export const ATOMIC_BEEF = 0x01010101 // 01010101
11
+
12
+ export enum TX_DATA_FORMAT {
13
+ RAWTX = 0, // rawtx without BUMP
14
+ RAWTX_AND_BUMP_INDEX = 1, // rawtx with bump index
15
+ TXID_ONLY = 2, // txid only
16
+ }
@@ -1,7 +1,7 @@
1
1
  import { hash256 } from '../primitives/Hash.js'
2
2
  import { Reader, Writer, toHex, toArray, ReaderUint8Array, WriterUint8Array } from '../primitives/utils.js'
3
3
  import Transaction from './Transaction.js'
4
- import { BEEF_V2, TX_DATA_FORMAT } from './Beef.js'
4
+ import { BEEF_V2, TX_DATA_FORMAT } from './BeefConstants.js'
5
5
 
6
6
  /**
7
7
  * A single bitcoin transaction associated with a `Beef` validity proof set.
@@ -105,7 +105,7 @@ export default class BeefTx {
105
105
  } else if (tx instanceof Transaction) {
106
106
  this._tx = tx
107
107
  } else {
108
- throw new Error('Invalid transaction data type')
108
+ throw new TypeError('Invalid transaction data type')
109
109
  }
110
110
  this.bumpIndex = bumpIndex
111
111
  this.updateInputTxids()
@@ -204,7 +204,7 @@ export default class BeefTx {
204
204
  } else {
205
205
  // V1
206
206
  data = Transaction.fromReader(br)
207
- bumpIndex = br.readUInt8() !== 0 ? br.readVarIntNum() : undefined
207
+ bumpIndex = br.readUInt8() === 0 ? undefined : br.readVarIntNum()
208
208
  beefTx = BeefTx.fromTx(data, bumpIndex)
209
209
  }
210
210