@bsv/sdk 2.1.0 → 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 (383) hide show
  1. package/README.md +7 -7
  2. package/dist/cjs/package.json +1 -1
  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/package.json +1 -1
  313. package/src/auth/Peer.ts +26 -13
  314. package/src/auth/SessionManager.ts +4 -7
  315. package/src/auth/certificates/MasterCertificate.ts +1 -1
  316. package/src/auth/certificates/__tests/CompletedProtoWallet.ts +1 -1
  317. package/src/auth/clients/AuthFetch.ts +41 -41
  318. package/src/auth/transports/SimplifiedFetchTransport.ts +4 -4
  319. package/src/compat/ECIES.ts +29 -34
  320. package/src/compat/HD.ts +10 -5
  321. package/src/compat/Mnemonic.ts +11 -11
  322. package/src/compat/__tests/HD.test.ts +19 -0
  323. package/src/identity/ContactsManager.ts +194 -257
  324. package/src/identity/IdentityClient.ts +155 -66
  325. package/src/identity/__tests/IdentityClient.test.ts +25 -1
  326. package/src/kvstore/GlobalKVStore.ts +31 -32
  327. package/src/kvstore/LocalKVStore.ts +8 -8
  328. package/src/kvstore/kvStoreInterpreter.ts +2 -2
  329. package/src/messages/SignedMessage.ts +1 -1
  330. package/src/overlay-tools/Historian.ts +1 -1
  331. package/src/overlay-tools/LookupResolver.ts +182 -45
  332. package/src/overlay-tools/SHIPBroadcaster.ts +92 -168
  333. package/src/primitives/AESGCM.ts +2 -2
  334. package/src/primitives/BigNumber.ts +122 -113
  335. package/src/primitives/Curve.ts +16 -15
  336. package/src/primitives/ECDSA.ts +10 -8
  337. package/src/primitives/Hash.ts +152 -53
  338. package/src/primitives/JacobianPoint.ts +13 -11
  339. package/src/primitives/K256.ts +3 -3
  340. package/src/primitives/Point.ts +35 -38
  341. package/src/primitives/PrivateKey.ts +3 -3
  342. package/src/primitives/PublicKey.ts +3 -3
  343. package/src/primitives/Random.ts +11 -14
  344. package/src/primitives/ReaderUint8Array.ts +7 -7
  345. package/src/primitives/Schnorr.ts +2 -1
  346. package/src/primitives/Secp256r1.ts +2 -1
  347. package/src/primitives/Signature.ts +8 -8
  348. package/src/primitives/TransactionSignature.ts +16 -16
  349. package/src/primitives/utils.ts +37 -47
  350. package/src/registry/RegistryClient.ts +25 -25
  351. package/src/remittance/RemittanceManager.ts +17 -18
  352. package/src/remittance/modules/BasicBRC29.ts +2 -5
  353. package/src/script/Script.ts +114 -170
  354. package/src/script/ScriptEvaluationError.ts +2 -2
  355. package/src/script/Spend.ts +14 -15
  356. package/src/script/templates/PushDrop.ts +5 -3
  357. package/src/script/templates/RPuzzle.ts +2 -4
  358. package/src/storage/StorageDownloader.ts +1 -1
  359. package/src/totp/totp.ts +1 -1
  360. package/src/transaction/Beef.ts +241 -203
  361. package/src/transaction/BeefConstants.ts +16 -0
  362. package/src/transaction/BeefTx.ts +3 -3
  363. package/src/transaction/MerklePath.ts +4 -4
  364. package/src/transaction/Transaction.ts +48 -51
  365. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +1 -1
  366. package/src/transaction/http/BinaryFetchClient.ts +8 -8
  367. package/src/transaction/http/DefaultHttpClient.ts +8 -8
  368. package/src/wallet/CachedKeyDeriver.ts +8 -6
  369. package/src/wallet/KeyDeriver.ts +1 -1
  370. package/src/wallet/Wallet.interfaces.ts +2 -4
  371. package/src/wallet/WalletClient.ts +8 -8
  372. package/src/wallet/WalletError.ts +1 -1
  373. package/src/wallet/__tests/WalletClient.substrate.test.ts +10 -6
  374. package/src/wallet/substrates/HTTPWalletJSON.ts +22 -21
  375. package/src/wallet/substrates/ReactNativeWebView.ts +9 -9
  376. package/src/wallet/substrates/WalletWireProcessor.ts +83 -83
  377. package/src/wallet/substrates/WalletWireTransceiver.ts +528 -938
  378. package/src/wallet/substrates/XDM.ts +4 -4
  379. package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +38 -25
  380. package/src/wallet/substrates/__tests/ReactNativeWebView.test.ts +174 -0
  381. package/src/wallet/substrates/__tests/window.CWI.test.ts +256 -0
  382. package/src/wallet/substrates/window.CWI.ts +10 -10
  383. package/src/wallet/validationHelpers.ts +9 -9
@@ -38,6 +38,44 @@ export type LookupAnswer =
38
38
  }>
39
39
  }
40
40
 
41
+ /**
42
+ * Per-call options for {@link LookupResolver.query} and {@link LookupResolver.query$}.
43
+ * All optional; defaults preserve prior behavior.
44
+ */
45
+ export interface LookupQueryOptions {
46
+ /**
47
+ * Override the grace window (ms) between the first valid response and the resolution of the query.
48
+ * Late responders arriving within this window are merged into the result. Default 80 ms.
49
+ * Raise for identity-style paths (e.g. ~300 ms) where divergence between hosts matters.
50
+ */
51
+ graceMs?: number
52
+ /**
53
+ * Soft timeout (ms). When set:
54
+ * - `query()` resolves with whatever has arrived as soon as any host answers, or after this timeout.
55
+ * - `query$()` emits a (possibly empty) snapshot after this timeout if no host has answered yet,
56
+ * then continues yielding late-host enrichments until the iterator is broken or final emission.
57
+ */
58
+ softTimeoutMs?: number
59
+ }
60
+
61
+ /**
62
+ * One emission from {@link LookupResolver.query$}. Carries the cumulative output set discovered so far
63
+ * plus a small envelope describing progress across hosts. Callers can render fast on the first emission
64
+ * and refine in place as more hosts answer.
65
+ */
66
+ export interface LookupAnswerProgress {
67
+ type: 'output-list'
68
+ outputs: Array<{ beef: number[], outputIndex: number, context?: number[] }>
69
+ /** Parallel array of resolved tx ids for each output (same index as `outputs`). */
70
+ txIds: string[]
71
+ /** True only for the final emission, after every in-flight host has settled. */
72
+ isFinal: boolean
73
+ /** Number of ranked hosts that were queried. */
74
+ hostCount: number
75
+ /** Number of hosts that have settled (success / fail / timeout). */
76
+ completedHosts: number
77
+ }
78
+
41
79
  /** Default SLAP trackers */
42
80
  export const DEFAULT_SLAP_TRACKERS: string[] = [
43
81
  // BSVA clusters
@@ -119,7 +157,7 @@ export class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
119
157
 
120
158
  constructor (httpClient = defaultFetch, allowHTTP: boolean = false) {
121
159
  if (typeof httpClient !== 'function') {
122
- throw new Error(
160
+ throw new TypeError(
123
161
  'HTTPSOverlayLookupFacilitator requires a fetch implementation. ' +
124
162
  'In environments without fetch, provide a polyfill or custom implementation.'
125
163
  )
@@ -131,7 +169,7 @@ export class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
131
169
  async lookup (
132
170
  url: string,
133
171
  question: LookupQuestion,
134
- timeout: number = 5000
172
+ timeout: number = 2000
135
173
  ): Promise<LookupAnswer> {
136
174
  if (!url.startsWith('https:') && !this.allowHTTP) {
137
175
  throw new Error(
@@ -139,7 +177,7 @@ export class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
139
177
  )
140
178
  }
141
179
 
142
- const controller = typeof AbortController !== 'undefined' ? new AbortController() : undefined
180
+ const controller = typeof AbortController === 'undefined' ? undefined : new AbortController()
143
181
  const timer = setTimeout(() => {
144
182
  try { controller?.abort() } catch { /* noop */ }
145
183
  }, timeout)
@@ -190,7 +228,7 @@ export class HTTPSOverlayLookupFacilitator implements OverlayLookupFacilitator {
190
228
  }
191
229
  } catch (e) {
192
230
  // Normalize timeouts to a consistent error message
193
- if ((e as any)?.name === 'AbortError') throw new Error('Request timed out')
231
+ if ((e as { name?: string })?.name === 'AbortError') throw new Error('Request timed out')
194
232
  throw e
195
233
  } finally {
196
234
  clearTimeout(timer)
@@ -248,11 +286,48 @@ export default class LookupResolver {
248
286
 
249
287
  /**
250
288
  * Given a LookupQuestion, returns a LookupAnswer. Aggregates across multiple services and supports resiliency.
289
+ *
290
+ * Optional `options.graceMs` overrides the per-call grace window (default 80 ms).
291
+ * Optional `options.softTimeoutMs` resolves the query early with whatever has arrived once any host has
292
+ * answered (or with an empty result if no host has answered by `softTimeoutMs`).
251
293
  */
252
294
  async query (
253
295
  question: LookupQuestion,
254
- timeout?: number
296
+ timeout?: number,
297
+ options?: LookupQueryOptions
255
298
  ): Promise<LookupAnswer> {
299
+ let last: LookupAnswerProgress | null = null
300
+ // Existing fast-but-narrow contract: return at the first cumulative emission
301
+ // (the post-grace aggregate, or the final emission when every host settles
302
+ // before the grace window). Callers wanting progressive enrichment use query$().
303
+ for await (const partial of this.query$(question, timeout, options)) {
304
+ last = partial
305
+ break
306
+ }
307
+ return {
308
+ type: 'output-list',
309
+ outputs: last?.outputs ?? []
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Iterable form of {@link query}. Emits partial results as hosts answer.
315
+ *
316
+ * Emission order:
317
+ * - First emission: after the grace window expires (or as soon as the soft timeout elapses), containing
318
+ * every output gathered from hosts that answered by then.
319
+ * - Subsequent emissions: re-emitted whenever a late host returns extra outputs that weren't in earlier
320
+ * emissions. Each emission contains the cumulative `outputs` set.
321
+ * - Final emission: `isFinal: true` once all in-flight hosts have settled (success / fail / timeout). The
322
+ * caller can `break` early; outstanding work is bounded by the per-host timeout.
323
+ *
324
+ * No host work runs past its per-host `timeout` — there is no leak risk on early break.
325
+ */
326
+ async * query$ (
327
+ question: LookupQuestion,
328
+ timeout?: number,
329
+ options?: LookupQueryOptions
330
+ ): AsyncIterable<LookupAnswerProgress> {
256
331
  let competentHosts: string[] = []
257
332
  if (question.service === 'ls_slap') {
258
333
  competentHosts = this.networkPreset === 'local' ? ['http://localhost:8080'] : this.slapTrackers
@@ -282,48 +357,58 @@ export default class LookupResolver {
282
357
  throw new Error(`All competent hosts for ${question.service} are temporarily unavailable due to backoff.`)
283
358
  }
284
359
 
285
- // Fire all hosts; resolve as soon as we have results from any host,
286
- // then allow a short grace window for additional hosts to contribute.
287
- const GRACE_MS = 80
288
- const answers: LookupAnswer[] = await new Promise<LookupAnswer[]>((resolve) => {
289
- const collected: LookupAnswer[] = []
290
- let pending = rankedHosts.length
291
- let graceTimer: ReturnType<typeof setTimeout> | null = null
292
-
293
- const tryResolve = (): void => {
294
- if (graceTimer !== null) clearTimeout(graceTimer)
295
- resolve(collected)
296
- }
360
+ const graceMs = options?.graceMs ?? 80
361
+ const softTimeoutMs = options?.softTimeoutMs
297
362
 
298
- for (const host of rankedHosts) {
299
- this.lookupHostWithTracking(host, question, timeout)
300
- .then((answer) => {
301
- if (answer?.type === 'output-list' && Array.isArray(answer.outputs) && answer.outputs.length > 0) {
302
- collected.push(answer)
303
- // First valid response: start a grace window for others
304
- if (collected.length === 1 && pending > 1) {
305
- graceTimer = setTimeout(tryResolve, GRACE_MS)
306
- }
307
- }
308
- })
309
- .catch(() => { /* host failed; tracked by lookupHostWithTracking */ })
310
- .finally(() => {
311
- pending--
312
- if (pending === 0) tryResolve()
313
- })
363
+ const hostCount = rankedHosts.length
364
+ const outputsMap = new Map<string, { beef: number[], context?: number[], outputIndex: number }>()
365
+ const txIds: string[] = []
366
+ let completedHosts = 0
367
+ let firstResponseAt: number | null = null
368
+
369
+ type Event = { kind: 'answer', answer: LookupAnswer } | { kind: 'done' } | { kind: 'soft' }
370
+ const queue: Event[] = []
371
+ let waiter: ((v: void) => void) | null = null
372
+ const push = (e: Event): void => {
373
+ queue.push(e)
374
+ if (waiter !== null) {
375
+ const w = waiter
376
+ waiter = null
377
+ w()
314
378
  }
315
- })
379
+ }
316
380
 
317
- const outputsMap = new Map<string, { beef: number[], context?: number[], outputIndex: number }>()
381
+ for (const host of rankedHosts) {
382
+ this.lookupHostWithTracking(host, question, timeout)
383
+ .then((answer) => {
384
+ if (answer?.type === 'output-list' && Array.isArray(answer.outputs) && answer.outputs.length > 0) {
385
+ push({ kind: 'answer', answer })
386
+ }
387
+ })
388
+ .catch(() => { /* tracked already */ })
389
+ .finally(() => {
390
+ completedHosts++
391
+ push({ kind: 'done' })
392
+ })
393
+ }
394
+
395
+ let softTimer: ReturnType<typeof setTimeout> | null = null
396
+ if (typeof softTimeoutMs === 'number' && softTimeoutMs >= 0) {
397
+ softTimer = setTimeout(() => push({ kind: 'soft' }), softTimeoutMs)
398
+ }
399
+
400
+ let graceTimer: ReturnType<typeof setTimeout> | null = null
401
+ let graceFired = false
402
+ let emittedOnce = false
318
403
 
319
- // Memo key helper for tx parsing
320
- const beefKey = (beef: number[]): string => {
321
- if (typeof beef !== 'object') return '' // The invalid BEEF has an empty key.
404
+ const beefKey = (beef: number[] | undefined): string => {
405
+ if (typeof beef !== 'object' || beef == null) return ''
322
406
  return beef.join(',')
323
407
  }
324
408
 
325
- for (const response of answers) {
326
- for (const output of response.outputs) {
409
+ const mergeAnswer = (answer: LookupAnswer): boolean => {
410
+ let added = false
411
+ for (const output of answer.outputs) {
327
412
  const keyForBeef = beefKey(output.beef)
328
413
  let memo = this.txMemo.get(keyForBeef)
329
414
  const now = Date.now()
@@ -337,14 +422,66 @@ export default class LookupResolver {
337
422
  continue
338
423
  }
339
424
  }
340
-
341
425
  const uniqKey = `${memo.txId}.${output.outputIndex}`
342
- outputsMap.set(uniqKey, output)
426
+ if (!outputsMap.has(uniqKey)) {
427
+ outputsMap.set(uniqKey, output)
428
+ txIds.push(memo.txId)
429
+ added = true
430
+ }
343
431
  }
432
+ return added
344
433
  }
345
- return {
434
+
435
+ const snapshot = (isFinal: boolean): LookupAnswerProgress => ({
346
436
  type: 'output-list',
347
- outputs: Array.from(outputsMap.values())
437
+ outputs: Array.from(outputsMap.values()),
438
+ txIds: txIds.slice(),
439
+ isFinal,
440
+ hostCount,
441
+ completedHosts
442
+ })
443
+
444
+ try {
445
+ while (completedHosts < hostCount) {
446
+ if (queue.length === 0) {
447
+ await new Promise<void>((resolve) => { waiter = resolve })
448
+ }
449
+ const e = queue.shift() as Event
450
+ if (e.kind === 'answer') {
451
+ const added = mergeAnswer(e.answer)
452
+ if (firstResponseAt === null) {
453
+ firstResponseAt = Date.now()
454
+ if (!graceFired && graceMs > 0) {
455
+ graceTimer = setTimeout(() => {
456
+ graceFired = true
457
+ push({ kind: 'soft' })
458
+ }, graceMs)
459
+ } else {
460
+ graceFired = true
461
+ }
462
+ }
463
+ if (graceFired && added) {
464
+ emittedOnce = true
465
+ yield snapshot(false)
466
+ }
467
+ } else if (e.kind === 'soft') {
468
+ if (!emittedOnce) {
469
+ graceFired = true
470
+ emittedOnce = true
471
+ yield snapshot(false)
472
+ }
473
+ if (typeof softTimeoutMs === 'number' && firstResponseAt !== null) {
474
+ // Soft timeout: caller asked to bail out once any answer is in. Yield final.
475
+ break
476
+ }
477
+ } else if (e.kind === 'done') {
478
+ // continue loop; final emission happens after the loop
479
+ }
480
+ }
481
+ yield snapshot(true)
482
+ } finally {
483
+ if (graceTimer !== null) clearTimeout(graceTimer)
484
+ if (softTimer !== null) clearTimeout(softTimer)
348
485
  }
349
486
  }
350
487
 
@@ -375,7 +512,7 @@ export default class LookupResolver {
375
512
  try {
376
513
  const hosts = await this.hostsInFlight.get(service)
377
514
  if (typeof hosts !== 'object') {
378
- throw new Error('Hosts is not defined.')
515
+ throw new TypeError('Hosts is not defined.')
379
516
  }
380
517
  return hosts.slice()
381
518
  } catch {
@@ -50,6 +50,12 @@ export interface AdmittanceInstructions {
50
50
  */
51
51
  export type STEAK = Record<string, AdmittanceInstructions>
52
52
 
53
+ /** The require mode for topic acknowledgment: all topics must be present, or any one suffices. */
54
+ export type RequireMode = 'all' | 'any'
55
+
56
+ /** Specifies which topics must be acknowledged: all, any, or a specific list. */
57
+ export type TopicAcknowledgmentRequirement = RequireMode | string[]
58
+
53
59
  /** Configuration options for the SHIP broadcaster. */
54
60
  export interface SHIPBroadcasterConfig {
55
61
  /**
@@ -64,11 +70,11 @@ export interface SHIPBroadcasterConfig {
64
70
  /** The resolver used to locate suitable hosts with SHIP */
65
71
  resolver?: LookupResolver
66
72
  /** Determines which topics (all, any, or a specific list) must be present within all STEAKs received from every host for the broadcast to be considered a success. By default, all hosts must acknowledge all topics. */
67
- requireAcknowledgmentFromAllHostsForTopics?: 'all' | 'any' | string[]
73
+ requireAcknowledgmentFromAllHostsForTopics?: TopicAcknowledgmentRequirement
68
74
  /** Determines which topics (all, any, or a specific list) must be present within STEAK received from at least one host for the broadcast to be considered a success. */
69
- requireAcknowledgmentFromAnyHostForTopics?: 'all' | 'any' | string[]
75
+ requireAcknowledgmentFromAnyHostForTopics?: TopicAcknowledgmentRequirement
70
76
  /** Determines a mapping whose keys are specific hosts and whose values are the topics (all, any, or a specific list) that must be present within the STEAK received by the given hosts, in order for the broadcast to be considered a success. */
71
- requireAcknowledgmentFromSpecificHostsForTopics?: Record<string, 'all' | 'any' | string[]>
77
+ requireAcknowledgmentFromSpecificHostsForTopics?: Record<string, TopicAcknowledgmentRequirement>
72
78
  }
73
79
 
74
80
  /** Facilitates transaction broadcasts that return STEAK. */
@@ -128,9 +134,9 @@ export default class TopicBroadcaster implements Broadcaster {
128
134
  private readonly topics: string[]
129
135
  private readonly facilitator: OverlayBroadcastFacilitator
130
136
  private readonly resolver: LookupResolver
131
- private readonly requireAcknowledgmentFromAllHostsForTopics: | 'all' | 'any' | string[]
132
- private readonly requireAcknowledgmentFromAnyHostForTopics: | 'all' | 'any' | string[]
133
- private readonly requireAcknowledgmentFromSpecificHostsForTopics: Record<string, 'all' | 'any' | string[]>
137
+ private readonly requireAcknowledgmentFromAllHostsForTopics: TopicAcknowledgmentRequirement
138
+ private readonly requireAcknowledgmentFromAnyHostForTopics: TopicAcknowledgmentRequirement
139
+ private readonly requireAcknowledgmentFromSpecificHostsForTopics: Record<string, TopicAcknowledgmentRequirement>
134
140
  private readonly networkPreset: 'mainnet' | 'testnet' | 'local'
135
141
 
136
142
  // Cache for findInterestedHosts to avoid repeated SHIP tracker lookups
@@ -233,7 +239,7 @@ export default class TopicBroadcaster implements Broadcaster {
233
239
  for (const [topic, instructions] of Object.entries(steak)) {
234
240
  const outputsToAdmit = instructions.outputsToAdmit
235
241
  const coinsToRetain = instructions.coinsToRetain
236
- const coinsRemoved = instructions.coinsRemoved as number[]
242
+ const coinsRemoved = instructions.coinsRemoved
237
243
 
238
244
  if (
239
245
  outputsToAdmit?.length > 0 ||
@@ -248,162 +254,99 @@ export default class TopicBroadcaster implements Broadcaster {
248
254
  }
249
255
 
250
256
  // Now, perform the checks
257
+ const allHostsError = this.checkAllHostsRequirement(hostAcknowledgments)
258
+ if (allHostsError != null) return allHostsError
251
259
 
252
- // Check requireAcknowledgmentFromAllHostsForTopics
253
- let requiredTopicsAllHosts: string[]
254
- let requireAllHosts: 'all' | 'any'
255
-
256
- if (this.requireAcknowledgmentFromAllHostsForTopics === 'all') {
257
- requiredTopicsAllHosts = this.topics
258
- requireAllHosts = 'all'
259
- } else if (this.requireAcknowledgmentFromAllHostsForTopics === 'any') {
260
- requiredTopicsAllHosts = this.topics
261
- requireAllHosts = 'any'
262
- } else if (Array.isArray(this.requireAcknowledgmentFromAllHostsForTopics)) {
263
- requiredTopicsAllHosts = this.requireAcknowledgmentFromAllHostsForTopics
264
- requireAllHosts = 'all'
265
- } else {
266
- // Default to 'all' and 'all'
267
- requiredTopicsAllHosts = this.topics
268
- requireAllHosts = 'all'
269
- }
260
+ const anyHostError = this.checkAnyHostRequirement(hostAcknowledgments)
261
+ if (anyHostError != null) return anyHostError
270
262
 
271
- if (requiredTopicsAllHosts.length > 0) {
272
- const allHostsAcknowledged = this.checkAcknowledgmentFromAllHosts(
273
- hostAcknowledgments,
274
- requiredTopicsAllHosts,
275
- requireAllHosts
276
- )
277
- if (!allHostsAcknowledged) {
278
- return {
279
- status: 'error',
280
- code: 'ERR_REQUIRE_ACK_FROM_ALL_HOSTS_FAILED',
281
- description: 'Not all hosts acknowledged the required topics.'
282
- }
283
- }
263
+ const specificHostsError = this.checkSpecificHostsRequirement(hostAcknowledgments)
264
+ if (specificHostsError != null) return specificHostsError
265
+
266
+ // If all checks pass, return success
267
+ return {
268
+ status: 'success',
269
+ txid: tx.id('hex'),
270
+ message: `Sent to ${successfulHosts.length} Overlay Services ${successfulHosts.length === 1 ? 'host' : 'hosts'}.`
284
271
  }
272
+ }
285
273
 
286
- // Check requireAcknowledgmentFromAnyHostForTopics
287
- let requiredTopicsAnyHost: string[]
288
- let requireAnyHost: 'all' | 'any'
289
-
290
- if (this.requireAcknowledgmentFromAnyHostForTopics === 'all') {
291
- requiredTopicsAnyHost = this.topics
292
- requireAnyHost = 'all'
293
- } else if (this.requireAcknowledgmentFromAnyHostForTopics === 'any') {
294
- requiredTopicsAnyHost = this.topics
295
- requireAnyHost = 'any'
296
- } else if (Array.isArray(this.requireAcknowledgmentFromAnyHostForTopics)) {
297
- requiredTopicsAnyHost = this.requireAcknowledgmentFromAnyHostForTopics
298
- requireAnyHost = 'all'
299
- } else {
300
- // No requirement
301
- requiredTopicsAnyHost = []
302
- requireAnyHost = 'all'
274
+ /** Resolves the (requiredTopics, require) pair for requireAcknowledgmentFromAllHostsForTopics. */
275
+ private resolveAllHostsRequirement (): { requiredTopics: string[], require: RequireMode } {
276
+ const r = this.requireAcknowledgmentFromAllHostsForTopics
277
+ if (r === 'any') return { requiredTopics: this.topics, require: 'any' }
278
+ if (Array.isArray(r)) return { requiredTopics: r, require: 'all' }
279
+ // Default 'all' or unknown: all topics, all requirement
280
+ return { requiredTopics: this.topics, require: 'all' }
281
+ }
282
+
283
+ private checkAllHostsRequirement (hostAcknowledgments: Record<string, Set<string>>): BroadcastFailure | null {
284
+ const { requiredTopics, require } = this.resolveAllHostsRequirement()
285
+ if (requiredTopics.length === 0) return null
286
+ if (!this.checkAcknowledgmentFromAllHosts(hostAcknowledgments, requiredTopics, require)) {
287
+ return { status: 'error', code: 'ERR_REQUIRE_ACK_FROM_ALL_HOSTS_FAILED', description: 'Not all hosts acknowledged the required topics.' }
303
288
  }
289
+ return null
290
+ }
304
291
 
305
- if (requiredTopicsAnyHost.length > 0) {
306
- const anyHostAcknowledged = this.checkAcknowledgmentFromAnyHost(
307
- hostAcknowledgments,
308
- requiredTopicsAnyHost,
309
- requireAnyHost
310
- )
311
- if (!anyHostAcknowledged) {
312
- return {
313
- status: 'error',
314
- code: 'ERR_REQUIRE_ACK_FROM_ANY_HOST_FAILED',
315
- description: 'No host acknowledged the required topics.'
316
- }
317
- }
292
+ /** Resolves the (requiredTopics, require) pair for requireAcknowledgmentFromAnyHostForTopics. */
293
+ private resolveAnyHostRequirement (): { requiredTopics: string[], require: RequireMode } {
294
+ const r = this.requireAcknowledgmentFromAnyHostForTopics
295
+ if (r === 'all') return { requiredTopics: this.topics, require: 'all' }
296
+ if (r === 'any') return { requiredTopics: this.topics, require: 'any' }
297
+ if (Array.isArray(r)) return { requiredTopics: r, require: 'all' }
298
+ return { requiredTopics: [], require: 'all' }
299
+ }
300
+
301
+ private checkAnyHostRequirement (hostAcknowledgments: Record<string, Set<string>>): BroadcastFailure | null {
302
+ const { requiredTopics, require } = this.resolveAnyHostRequirement()
303
+ if (requiredTopics.length === 0) return null
304
+ if (!this.checkAcknowledgmentFromAnyHost(hostAcknowledgments, requiredTopics, require)) {
305
+ return { status: 'error', code: 'ERR_REQUIRE_ACK_FROM_ANY_HOST_FAILED', description: 'No host acknowledged the required topics.' }
318
306
  }
307
+ return null
308
+ }
319
309
 
320
- // Check requireAcknowledgmentFromSpecificHostsForTopics
321
- if (
322
- Object.keys(this.requireAcknowledgmentFromSpecificHostsForTopics).length >
323
- 0
324
- ) {
325
- const specificHostsAcknowledged =
326
- this.checkAcknowledgmentFromSpecificHosts(
327
- hostAcknowledgments,
328
- this.requireAcknowledgmentFromSpecificHostsForTopics
329
- )
330
- if (!specificHostsAcknowledged) {
331
- return {
332
- status: 'error',
333
- code: 'ERR_REQUIRE_ACK_FROM_SPECIFIC_HOSTS_FAILED',
334
- description:
335
- 'Specific hosts did not acknowledge the required topics.'
336
- }
337
- }
310
+ private checkSpecificHostsRequirement (hostAcknowledgments: Record<string, Set<string>>): BroadcastFailure | null {
311
+ if (Object.keys(this.requireAcknowledgmentFromSpecificHostsForTopics).length === 0) return null
312
+ if (!this.checkAcknowledgmentFromSpecificHosts(hostAcknowledgments, this.requireAcknowledgmentFromSpecificHostsForTopics)) {
313
+ return { status: 'error', code: 'ERR_REQUIRE_ACK_FROM_SPECIFIC_HOSTS_FAILED', description: 'Specific hosts did not acknowledge the required topics.' }
338
314
  }
315
+ return null
316
+ }
339
317
 
340
- // If all checks pass, return success
341
- return {
342
- status: 'success',
343
- txid: tx.id('hex'),
344
- message: `Sent to ${successfulHosts.length} Overlay Services ${successfulHosts.length === 1 ? 'host' : 'hosts'}.`
318
+ /**
319
+ * Returns true if `acknowledgedTopics` satisfies the given requirement against `requiredTopics`.
320
+ */
321
+ private topicsMatchRequirement (
322
+ acknowledgedTopics: Set<string>,
323
+ requiredTopics: string[],
324
+ require: RequireMode
325
+ ): boolean {
326
+ if (require === 'all') {
327
+ return requiredTopics.every(t => acknowledgedTopics.has(t))
345
328
  }
329
+ return requiredTopics.some(t => acknowledgedTopics.has(t))
346
330
  }
347
331
 
348
332
  private checkAcknowledgmentFromAllHosts (
349
333
  hostAcknowledgments: Record<string, Set<string>>,
350
334
  requiredTopics: string[],
351
- require: 'all' | 'any'
335
+ require: RequireMode
352
336
  ): boolean {
353
- for (const acknowledgedTopics of Object.values(hostAcknowledgments)) {
354
- if (require === 'all') {
355
- for (const topic of requiredTopics) {
356
- if (!acknowledgedTopics.has(topic)) {
357
- return false
358
- }
359
- }
360
- } else if (require === 'any') {
361
- let anyAcknowledged = false
362
- for (const topic of requiredTopics) {
363
- if (acknowledgedTopics.has(topic)) {
364
- anyAcknowledged = true
365
- break
366
- }
367
- }
368
- if (!anyAcknowledged) {
369
- return false
370
- }
371
- }
372
- }
373
- return true
337
+ return Object.values(hostAcknowledgments).every(
338
+ acknowledged => this.topicsMatchRequirement(acknowledged, requiredTopics, require)
339
+ )
374
340
  }
375
341
 
376
342
  private checkAcknowledgmentFromAnyHost (
377
343
  hostAcknowledgments: Record<string, Set<string>>,
378
344
  requiredTopics: string[],
379
- require: 'all' | 'any'
345
+ require: RequireMode
380
346
  ): boolean {
381
- if (require === 'all') {
382
- // All required topics must be acknowledged by at least one host
383
- for (const acknowledgedTopics of Object.values(hostAcknowledgments)) {
384
- let acknowledgesAllRequiredTopics = true
385
- for (const topic of requiredTopics) {
386
- if (!acknowledgedTopics.has(topic)) {
387
- acknowledgesAllRequiredTopics = false
388
- break
389
- }
390
- }
391
- if (acknowledgesAllRequiredTopics) {
392
- return true
393
- }
394
- }
395
- return false
396
- } else {
397
- // At least one required topic must be acknowledged by at least one host
398
- for (const acknowledgedTopics of Object.values(hostAcknowledgments)) {
399
- for (const topic of requiredTopics) {
400
- if (acknowledgedTopics.has(topic)) {
401
- return true
402
- }
403
- }
404
- }
405
- return false
406
- }
347
+ return Object.values(hostAcknowledgments).some(
348
+ acknowledged => this.topicsMatchRequirement(acknowledged, requiredTopics, require)
349
+ )
407
350
  }
408
351
 
409
352
  private checkAcknowledgmentFromSpecificHosts (
@@ -417,11 +360,8 @@ export default class TopicBroadcaster implements Broadcaster {
417
360
  return false
418
361
  }
419
362
  let requiredTopics: string[]
420
- let require: 'all' | 'any'
421
- if (
422
- requiredTopicsOrAllAny === 'all' ||
423
- requiredTopicsOrAllAny === 'any'
424
- ) {
363
+ let require: RequireMode
364
+ if (requiredTopicsOrAllAny === 'all' || requiredTopicsOrAllAny === 'any') {
425
365
  require = requiredTopicsOrAllAny
426
366
  requiredTopics = this.topics
427
367
  } else if (Array.isArray(requiredTopicsOrAllAny)) {
@@ -431,23 +371,8 @@ export default class TopicBroadcaster implements Broadcaster {
431
371
  // Invalid configuration
432
372
  continue
433
373
  }
434
- if (require === 'all') {
435
- for (const topic of requiredTopics) {
436
- if (!acknowledgedTopics.has(topic)) {
437
- return false
438
- }
439
- }
440
- } else if (require === 'any') {
441
- let anyAcknowledged = false
442
- for (const topic of requiredTopics) {
443
- if (acknowledgedTopics.has(topic)) {
444
- anyAcknowledged = true
445
- break
446
- }
447
- }
448
- if (!anyAcknowledged) {
449
- return false
450
- }
374
+ if (!this.topicsMatchRequirement(acknowledgedTopics, requiredTopics, require)) {
375
+ return false
451
376
  }
452
377
  }
453
378
  return true
@@ -462,8 +387,8 @@ export default class TopicBroadcaster implements Broadcaster {
462
387
  // Handle the local network preset
463
388
  if (this.networkPreset === 'local') {
464
389
  const resultSet = new Set<string>()
465
- for (let i = 0; i < this.topics.length; i++) {
466
- resultSet.add(this.topics[i])
390
+ for (const topic of this.topics) {
391
+ resultSet.add(topic)
467
392
  }
468
393
  return { 'http://localhost:8080': resultSet }
469
394
  }
@@ -519,11 +444,10 @@ export default class TopicBroadcaster implements Broadcaster {
519
444
  ) {
520
445
  continue
521
446
  }
522
- if (results[parsed.domain] === undefined) {
523
- results[parsed.domain] = new Set()
524
- }
447
+ results[parsed.domain] ??= new Set()
525
448
  results[parsed.domain].add(parsed.topicOrService)
526
- } catch (e) {
449
+ } catch (_notShipOutput) {
450
+ // Output could not be decoded as an overlay admin token — not a SHIP advertisement; skip
527
451
  continue
528
452
  }
529
453
  }
@@ -54,7 +54,7 @@ const Rcon = [
54
54
  const mul2 = new Uint8Array(256)
55
55
  const mul3 = new Uint8Array(256)
56
56
  for (let i = 0; i < 256; i++) {
57
- const m2 = ((i << 1) ^ ((i & 0x80) !== 0 ? 0x1b : 0)) & 0xff
57
+ const m2 = ((i << 1) ^ ((i & 0x80) === 0 ? 0 : 0x1b)) & 0xff
58
58
  mul2[i] = m2
59
59
  mul3[i] = m2 ^ i
60
60
  }
@@ -217,7 +217,7 @@ export const checkBit = function (
217
217
  byteIndex: number,
218
218
  bitIndex: number
219
219
  ): 1 | 0 {
220
- return (byteArray[byteIndex] & (0x01 << bitIndex)) !== 0 ? 1 : 0
220
+ return (byteArray[byteIndex] & (0x01 << bitIndex)) === 0 ? 0 : 1
221
221
  }
222
222
 
223
223
  export const getBytes = function (numericValue: number): number[] {