wowok 2.1.9 → 2.1.12

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 (887) hide show
  1. package/NOTICE +46 -0
  2. package/dist/cjs/bcs/bcs.d.ts +199 -199
  3. package/dist/cjs/bcs/bcs.js +273 -318
  4. package/dist/cjs/bcs/bcs.js.map +1 -0
  5. package/dist/cjs/bcs/effects.d.ts +109 -109
  6. package/dist/cjs/bcs/effects.js +205 -230
  7. package/dist/cjs/bcs/effects.js.map +1 -0
  8. package/dist/cjs/bcs/index.d.ts +1 -2584
  9. package/dist/cjs/bcs/index.js +61 -76
  10. package/dist/cjs/bcs/index.js.map +1 -0
  11. package/dist/cjs/bcs/pure.js +38 -58
  12. package/dist/cjs/bcs/pure.js.map +1 -0
  13. package/dist/cjs/bcs/type-tag-serializer.js +102 -114
  14. package/dist/cjs/bcs/type-tag-serializer.js.map +1 -0
  15. package/dist/cjs/bcs/types.js +6 -23
  16. package/dist/cjs/bcs/types.js.map +1 -0
  17. package/dist/cjs/client/index.js +17 -33
  18. package/dist/cjs/client/index.js.map +1 -0
  19. package/dist/cjs/client/network.js +25 -40
  20. package/dist/cjs/client/network.js.map +1 -0
  21. package/dist/cjs/cryptography/index.js +29 -45
  22. package/dist/cjs/cryptography/index.js.map +1 -0
  23. package/dist/cjs/cryptography/intent.d.ts +1 -1
  24. package/dist/cjs/cryptography/intent.js +20 -31
  25. package/dist/cjs/cryptography/intent.js.map +1 -0
  26. package/dist/cjs/cryptography/keypair.js +102 -116
  27. package/dist/cjs/cryptography/keypair.js.map +1 -0
  28. package/dist/cjs/cryptography/mnemonics.js +43 -41
  29. package/dist/cjs/cryptography/mnemonics.js.map +1 -0
  30. package/dist/cjs/cryptography/publickey.js +112 -134
  31. package/dist/cjs/cryptography/publickey.js.map +1 -0
  32. package/dist/cjs/cryptography/signature-scheme.js +24 -43
  33. package/dist/cjs/cryptography/signature-scheme.js.map +1 -0
  34. package/dist/cjs/cryptography/signature.d.ts +2 -24
  35. package/dist/cjs/cryptography/signature.js +50 -67
  36. package/dist/cjs/cryptography/signature.js.map +1 -0
  37. package/dist/cjs/experimental/cache.js +65 -0
  38. package/dist/cjs/experimental/cache.js.map +1 -0
  39. package/dist/cjs/experimental/client.js +27 -0
  40. package/dist/cjs/experimental/client.js.map +1 -0
  41. package/dist/cjs/experimental/core.js +89 -0
  42. package/dist/cjs/experimental/core.js.map +1 -0
  43. package/dist/cjs/experimental/errors.js +32 -0
  44. package/dist/cjs/experimental/errors.js.map +1 -0
  45. package/dist/cjs/experimental/index.js +15 -0
  46. package/dist/cjs/experimental/index.js.map +1 -0
  47. package/dist/cjs/experimental/persistent-storage.js +343 -0
  48. package/dist/cjs/experimental/persistent-storage.js.map +1 -0
  49. package/dist/cjs/experimental/persistent-storage.test.js +200 -0
  50. package/dist/cjs/experimental/persistent-storage.test.js.map +1 -0
  51. package/dist/cjs/experimental/transports/utils.js +104 -0
  52. package/dist/cjs/experimental/transports/utils.js.map +1 -0
  53. package/dist/cjs/experimental/types.js +6 -0
  54. package/dist/cjs/experimental/types.js.map +1 -0
  55. package/dist/cjs/faucet/faucet.js +106 -124
  56. package/dist/cjs/faucet/faucet.js.map +1 -0
  57. package/dist/cjs/faucet/index.js +12 -28
  58. package/dist/cjs/faucet/index.js.map +1 -0
  59. package/dist/cjs/grpc/client.js +47 -62
  60. package/dist/cjs/grpc/client.js.map +1 -0
  61. package/dist/cjs/grpc/core.js +580 -617
  62. package/dist/cjs/grpc/core.js.map +1 -0
  63. package/dist/cjs/grpc/index.js +9 -25
  64. package/dist/cjs/grpc/index.js.map +1 -0
  65. package/dist/cjs/grpc/proto/google/protobuf/any.js +168 -135
  66. package/dist/cjs/grpc/proto/google/protobuf/any.js.map +1 -0
  67. package/dist/cjs/grpc/proto/google/protobuf/duration.js +105 -90
  68. package/dist/cjs/grpc/proto/google/protobuf/duration.js.map +1 -0
  69. package/dist/cjs/grpc/proto/google/protobuf/empty.js +50 -28
  70. package/dist/cjs/grpc/proto/google/protobuf/empty.js.map +1 -0
  71. package/dist/cjs/grpc/proto/google/protobuf/field_mask.js +96 -75
  72. package/dist/cjs/grpc/proto/google/protobuf/field_mask.js.map +1 -0
  73. package/dist/cjs/grpc/proto/google/protobuf/struct.js +266 -215
  74. package/dist/cjs/grpc/proto/google/protobuf/struct.js.map +1 -0
  75. package/dist/cjs/grpc/proto/google/protobuf/timestamp.js +150 -131
  76. package/dist/cjs/grpc/proto/google/protobuf/timestamp.js.map +1 -0
  77. package/dist/cjs/grpc/proto/google/rpc/error_details.js +331 -302
  78. package/dist/cjs/grpc/proto/google/rpc/error_details.js.map +1 -0
  79. package/dist/cjs/grpc/proto/google/rpc/status.js +50 -50
  80. package/dist/cjs/grpc/proto/google/rpc/status.js.map +1 -0
  81. package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js +84 -68
  82. package/dist/cjs/grpc/proto/sui/rpc/v2/argument.js.map +1 -0
  83. package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js +45 -50
  84. package/dist/cjs/grpc/proto/sui/rpc/v2/balance_change.js.map +1 -0
  85. package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js +38 -43
  86. package/dist/cjs/grpc/proto/sui/rpc/v2/bcs.js.map +1 -0
  87. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js +70 -75
  88. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint.js.map +1 -0
  89. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js +79 -81
  90. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_contents.js.map +1 -0
  91. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js +183 -166
  92. package/dist/cjs/grpc/proto/sui/rpc/v2/checkpoint_summary.js.map +1 -0
  93. package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js +369 -296
  94. package/dist/cjs/grpc/proto/sui/rpc/v2/effects.js.map +1 -0
  95. package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js +80 -85
  96. package/dist/cjs/grpc/proto/sui/rpc/v2/epoch.js.map +1 -0
  97. package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js +31 -28
  98. package/dist/cjs/grpc/proto/sui/rpc/v2/error_reason.js.map +1 -0
  99. package/dist/cjs/grpc/proto/sui/rpc/v2/event.js +81 -83
  100. package/dist/cjs/grpc/proto/sui/rpc/v2/event.js.map +1 -0
  101. package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js +80 -85
  102. package/dist/cjs/grpc/proto/sui/rpc/v2/executed_transaction.js.map +1 -0
  103. package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js +876 -506
  104. package/dist/cjs/grpc/proto/sui/rpc/v2/execution_status.js.map +1 -0
  105. package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js +56 -61
  106. package/dist/cjs/grpc/proto/sui/rpc/v2/gas_cost_summary.js.map +1 -0
  107. package/dist/cjs/grpc/proto/sui/rpc/v2/input.js +103 -83
  108. package/dist/cjs/grpc/proto/sui/rpc/v2/input.js.map +1 -0
  109. package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js +76 -78
  110. package/dist/cjs/grpc/proto/sui/rpc/v2/jwk.js.map +1 -0
  111. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js +69 -119
  112. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.client.js.map +1 -0
  113. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js +392 -350
  114. package/dist/cjs/grpc/proto/sui/rpc/v2/ledger_service.js.map +1 -0
  115. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js +599 -473
  116. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package.js.map +1 -0
  117. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js +46 -78
  118. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.client.js.map +1 -0
  119. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js +242 -224
  120. package/dist/cjs/grpc/proto/sui/rpc/v2/move_package_service.js.map +1 -0
  121. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js +32 -52
  122. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.client.js.map +1 -0
  123. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js +139 -134
  124. package/dist/cjs/grpc/proto/sui/rpc/v2/name_service.js.map +1 -0
  125. package/dist/cjs/grpc/proto/sui/rpc/v2/object.js +109 -111
  126. package/dist/cjs/grpc/proto/sui/rpc/v2/object.js.map +1 -0
  127. package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js +46 -51
  128. package/dist/cjs/grpc/proto/sui/rpc/v2/object_reference.js.map +1 -0
  129. package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js +76 -61
  130. package/dist/cjs/grpc/proto/sui/rpc/v2/owner.js.map +1 -0
  131. package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js +46 -59
  132. package/dist/cjs/grpc/proto/sui/rpc/v2/protocol_config.js.map +1 -0
  133. package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js +568 -522
  134. package/dist/cjs/grpc/proto/sui/rpc/v2/signature.js.map +1 -0
  135. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js +54 -32
  136. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_scheme.js.map +1 -0
  137. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +27 -47
  138. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.client.js.map +1 -0
  139. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js +83 -86
  140. package/dist/cjs/grpc/proto/sui/rpc/v2/signature_verification_service.js.map +1 -0
  141. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js +53 -85
  142. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.client.js.map +1 -0
  143. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js +645 -529
  144. package/dist/cjs/grpc/proto/sui/rpc/v2/state_service.js.map +1 -0
  145. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js +37 -51
  146. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.client.js.map +1 -0
  147. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js +58 -61
  148. package/dist/cjs/grpc/proto/sui/rpc/v2/subscription_service.js.map +1 -0
  149. package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js +749 -730
  150. package/dist/cjs/grpc/proto/sui/rpc/v2/system_state.js.map +1 -0
  151. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js +1218 -975
  152. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction.js.map +1 -0
  153. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +32 -46
  154. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js.map +1 -0
  155. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js +186 -167
  156. package/dist/cjs/grpc/proto/sui/rpc/v2/transaction_execution_service.js.map +1 -0
  157. package/dist/cjs/index.js +96 -91
  158. package/dist/cjs/index.js.map +1 -0
  159. package/dist/cjs/jsonRpc/client.js +654 -743
  160. package/dist/cjs/jsonRpc/client.js.map +1 -0
  161. package/dist/cjs/jsonRpc/core.d.ts +7 -7
  162. package/dist/cjs/jsonRpc/core.js +562 -606
  163. package/dist/cjs/jsonRpc/core.js.map +1 -0
  164. package/dist/cjs/jsonRpc/errors.js +38 -56
  165. package/dist/cjs/jsonRpc/errors.js.map +1 -0
  166. package/dist/cjs/jsonRpc/http-transport.js +70 -114
  167. package/dist/cjs/jsonRpc/http-transport.js.map +1 -0
  168. package/dist/cjs/jsonRpc/index.js +14 -30
  169. package/dist/cjs/jsonRpc/index.js.map +1 -0
  170. package/dist/cjs/jsonRpc/json-rpc-resolver.js +286 -290
  171. package/dist/cjs/jsonRpc/json-rpc-resolver.js.map +1 -0
  172. package/dist/cjs/jsonRpc/rpc-websocket-client.js +150 -207
  173. package/dist/cjs/jsonRpc/rpc-websocket-client.js.map +1 -0
  174. package/dist/cjs/jsonRpc/types/chain.js +4 -15
  175. package/dist/cjs/jsonRpc/types/chain.js.map +1 -0
  176. package/dist/cjs/jsonRpc/types/changes.js +4 -15
  177. package/dist/cjs/jsonRpc/types/changes.js.map +1 -0
  178. package/dist/cjs/jsonRpc/types/coins.js +4 -15
  179. package/dist/cjs/jsonRpc/types/coins.js.map +1 -0
  180. package/dist/cjs/jsonRpc/types/common.js +4 -15
  181. package/dist/cjs/jsonRpc/types/common.js.map +1 -0
  182. package/dist/cjs/jsonRpc/types/generated.d.ts +1 -1
  183. package/dist/cjs/jsonRpc/types/generated.js +4 -15
  184. package/dist/cjs/jsonRpc/types/generated.js.map +1 -0
  185. package/dist/cjs/jsonRpc/types/index.js +4 -15
  186. package/dist/cjs/jsonRpc/types/index.js.map +1 -0
  187. package/dist/cjs/jsonRpc/types/params.js +4 -15
  188. package/dist/cjs/jsonRpc/types/params.js.map +1 -0
  189. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js +54 -69
  190. package/dist/cjs/keypairs/ed25519/ed25519-hd-key.js.map +1 -0
  191. package/dist/cjs/keypairs/ed25519/index.js +10 -26
  192. package/dist/cjs/keypairs/ed25519/index.js.map +1 -0
  193. package/dist/cjs/keypairs/ed25519/keypair.js +134 -159
  194. package/dist/cjs/keypairs/ed25519/keypair.js.map +1 -0
  195. package/dist/cjs/keypairs/ed25519/publickey.js +70 -84
  196. package/dist/cjs/keypairs/ed25519/publickey.js.map +1 -0
  197. package/dist/cjs/keypairs/index.js +21 -19
  198. package/dist/cjs/keypairs/index.js.map +1 -0
  199. package/dist/cjs/keypairs/passkey/index.js +11 -27
  200. package/dist/cjs/keypairs/passkey/index.js.map +1 -0
  201. package/dist/cjs/keypairs/passkey/keypair.js +245 -256
  202. package/dist/cjs/keypairs/passkey/keypair.js.map +1 -0
  203. package/dist/cjs/keypairs/passkey/publickey.js +163 -162
  204. package/dist/cjs/keypairs/passkey/publickey.js.map +1 -0
  205. package/dist/cjs/keypairs/passkey/types.js +4 -15
  206. package/dist/cjs/keypairs/passkey/types.js.map +1 -0
  207. package/dist/cjs/keypairs/secp256k1/index.js +10 -26
  208. package/dist/cjs/keypairs/secp256k1/index.js.map +1 -0
  209. package/dist/cjs/keypairs/secp256k1/keypair.js +129 -151
  210. package/dist/cjs/keypairs/secp256k1/keypair.js.map +1 -0
  211. package/dist/cjs/keypairs/secp256k1/publickey.js +71 -89
  212. package/dist/cjs/keypairs/secp256k1/publickey.js.map +1 -0
  213. package/dist/cjs/keypairs/secp256r1/index.js +10 -26
  214. package/dist/cjs/keypairs/secp256r1/index.js.map +1 -0
  215. package/dist/cjs/keypairs/secp256r1/keypair.js +127 -148
  216. package/dist/cjs/keypairs/secp256r1/keypair.js.map +1 -0
  217. package/dist/cjs/keypairs/secp256r1/publickey.js +72 -90
  218. package/dist/cjs/keypairs/secp256r1/publickey.js.map +1 -0
  219. package/dist/cjs/multisig/index.js +10 -26
  220. package/dist/cjs/multisig/index.js.map +1 -0
  221. package/dist/cjs/multisig/publickey.d.ts +1 -1
  222. package/dist/cjs/multisig/publickey.js +228 -276
  223. package/dist/cjs/multisig/publickey.js.map +1 -0
  224. package/dist/cjs/multisig/signer.js +62 -110
  225. package/dist/cjs/multisig/signer.js.map +1 -0
  226. package/dist/cjs/transactions/Arguments.d.ts +4 -4
  227. package/dist/cjs/transactions/Arguments.js +13 -34
  228. package/dist/cjs/transactions/Arguments.js.map +1 -0
  229. package/dist/cjs/transactions/Commands.js +111 -141
  230. package/dist/cjs/transactions/Commands.js.map +1 -0
  231. package/dist/cjs/transactions/Inputs.js +53 -82
  232. package/dist/cjs/transactions/Inputs.js.map +1 -0
  233. package/dist/cjs/transactions/ObjectCache.d.ts +8 -8
  234. package/dist/cjs/transactions/ObjectCache.js +204 -241
  235. package/dist/cjs/transactions/ObjectCache.js.map +1 -0
  236. package/dist/cjs/transactions/Transaction.d.ts +31 -31
  237. package/dist/cjs/transactions/Transaction.js +628 -719
  238. package/dist/cjs/transactions/Transaction.js.map +1 -0
  239. package/dist/cjs/transactions/TransactionData.d.ts +9 -9
  240. package/dist/cjs/transactions/TransactionData.js +396 -440
  241. package/dist/cjs/transactions/TransactionData.js.map +1 -0
  242. package/dist/cjs/transactions/__tests__/Transaction.test.js +169 -0
  243. package/dist/cjs/transactions/__tests__/Transaction.test.js.map +1 -0
  244. package/dist/cjs/transactions/__tests__/bcs.test.js +202 -0
  245. package/dist/cjs/transactions/__tests__/bcs.test.js.map +1 -0
  246. package/dist/cjs/transactions/data/internal.js +166 -207
  247. package/dist/cjs/transactions/data/internal.js.map +1 -0
  248. package/dist/cjs/transactions/data/v1.js +436 -495
  249. package/dist/cjs/transactions/data/v1.js.map +1 -0
  250. package/dist/cjs/transactions/data/v2.d.ts +5 -5
  251. package/dist/cjs/transactions/data/v2.js +94 -107
  252. package/dist/cjs/transactions/data/v2.js.map +1 -0
  253. package/dist/cjs/transactions/executor/caching.js +71 -113
  254. package/dist/cjs/transactions/executor/caching.js.map +1 -0
  255. package/dist/cjs/transactions/executor/parallel.js +339 -378
  256. package/dist/cjs/transactions/executor/parallel.js.map +1 -0
  257. package/dist/cjs/transactions/executor/queue.js +60 -80
  258. package/dist/cjs/transactions/executor/queue.js.map +1 -0
  259. package/dist/cjs/transactions/executor/serial.d.ts +4 -4
  260. package/dist/cjs/transactions/executor/serial.js +102 -131
  261. package/dist/cjs/transactions/executor/serial.js.map +1 -0
  262. package/dist/cjs/transactions/hash.js +17 -28
  263. package/dist/cjs/transactions/hash.js.map +1 -0
  264. package/dist/cjs/transactions/index.js +33 -49
  265. package/dist/cjs/transactions/index.js.map +1 -0
  266. package/dist/cjs/transactions/intents/CoinWithBalance.js +137 -191
  267. package/dist/cjs/transactions/intents/CoinWithBalance.js.map +1 -0
  268. package/dist/cjs/transactions/object.js +88 -111
  269. package/dist/cjs/transactions/object.js.map +1 -0
  270. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js +20 -32
  271. package/dist/cjs/transactions/plugins/NamedPackagesPlugin.js.map +1 -0
  272. package/dist/cjs/transactions/pure.js +38 -60
  273. package/dist/cjs/transactions/pure.js.map +1 -0
  274. package/dist/cjs/transactions/resolve.js +62 -88
  275. package/dist/cjs/transactions/resolve.js.map +1 -0
  276. package/dist/cjs/transactions/serializer.js +150 -163
  277. package/dist/cjs/transactions/serializer.js.map +1 -0
  278. package/dist/cjs/transactions/utils.d.ts +1 -1
  279. package/dist/cjs/transactions/utils.js +114 -125
  280. package/dist/cjs/transactions/utils.js.map +1 -0
  281. package/dist/cjs/utils/constants.js +29 -56
  282. package/dist/cjs/utils/constants.js.map +1 -0
  283. package/dist/cjs/utils/derived-objects.js +14 -30
  284. package/dist/cjs/utils/derived-objects.js.map +1 -0
  285. package/dist/cjs/utils/dynamic-fields.js +20 -37
  286. package/dist/cjs/utils/dynamic-fields.js.map +1 -0
  287. package/dist/cjs/utils/format.js +14 -30
  288. package/dist/cjs/utils/format.js.map +1 -0
  289. package/dist/cjs/utils/index.js +50 -64
  290. package/dist/cjs/utils/index.js.map +1 -0
  291. package/dist/cjs/utils/move-registry.js +37 -35
  292. package/dist/cjs/utils/move-registry.js.map +1 -0
  293. package/dist/cjs/utils/sui-types.js +74 -68
  294. package/dist/cjs/utils/sui-types.js.map +1 -0
  295. package/dist/cjs/utils/suins.js +30 -46
  296. package/dist/cjs/utils/suins.js.map +1 -0
  297. package/dist/cjs/verify/index.js +12 -27
  298. package/dist/cjs/verify/index.js.map +1 -0
  299. package/dist/cjs/verify/verify.js +83 -110
  300. package/dist/cjs/verify/verify.js.map +1 -0
  301. package/dist/cjs/version.js +8 -25
  302. package/dist/cjs/version.js.map +1 -0
  303. package/dist/cjs/w/call/allocation.js +323 -413
  304. package/dist/cjs/w/call/allocation.js.map +1 -0
  305. package/dist/cjs/w/call/arb.js +105 -136
  306. package/dist/cjs/w/call/arb.js.map +1 -0
  307. package/dist/cjs/w/call/arbitration.js +1206 -1581
  308. package/dist/cjs/w/call/arbitration.js.map +1 -0
  309. package/dist/cjs/w/call/base.js +303 -333
  310. package/dist/cjs/w/call/base.js.map +1 -0
  311. package/dist/cjs/w/call/contact.js +335 -452
  312. package/dist/cjs/w/call/contact.js.map +1 -0
  313. package/dist/cjs/w/call/demand.js +690 -844
  314. package/dist/cjs/w/call/demand.js.map +1 -0
  315. package/dist/cjs/w/call/entity.js +167 -201
  316. package/dist/cjs/w/call/entity.js.map +1 -0
  317. package/dist/cjs/w/call/guard-ins.d.ts +1 -0
  318. package/dist/cjs/w/call/guard-ins.js +4376 -4384
  319. package/dist/cjs/w/call/guard-ins.js.map +1 -0
  320. package/dist/cjs/w/call/guard.d.ts +10 -0
  321. package/dist/cjs/w/call/guard.js +1078 -1119
  322. package/dist/cjs/w/call/guard.js.map +1 -0
  323. package/dist/cjs/w/call/index.d.ts +1 -1
  324. package/dist/cjs/w/call/index.js +69 -69
  325. package/dist/cjs/w/call/index.js.map +1 -0
  326. package/dist/cjs/w/call/machine.js +1105 -1419
  327. package/dist/cjs/w/call/machine.js.map +1 -0
  328. package/dist/cjs/w/call/order.js +314 -454
  329. package/dist/cjs/w/call/order.js.map +1 -0
  330. package/dist/cjs/w/call/passport.js +214 -253
  331. package/dist/cjs/w/call/passport.js.map +1 -0
  332. package/dist/cjs/w/call/payment.js +187 -224
  333. package/dist/cjs/w/call/payment.js.map +1 -0
  334. package/dist/cjs/w/call/permission.js +1183 -1294
  335. package/dist/cjs/w/call/permission.js.map +1 -0
  336. package/dist/cjs/w/call/personal.js +132 -170
  337. package/dist/cjs/w/call/personal.js.map +1 -0
  338. package/dist/cjs/w/call/progress.js +634 -794
  339. package/dist/cjs/w/call/progress.js.map +1 -0
  340. package/dist/cjs/w/call/proof.js +67 -116
  341. package/dist/cjs/w/call/proof.js.map +1 -0
  342. package/dist/cjs/w/call/repository.js +1037 -1251
  343. package/dist/cjs/w/call/repository.js.map +1 -0
  344. package/dist/cjs/w/call/resource.js +111 -131
  345. package/dist/cjs/w/call/resource.js.map +1 -0
  346. package/dist/cjs/w/call/reward.js +675 -853
  347. package/dist/cjs/w/call/reward.js.map +1 -0
  348. package/dist/cjs/w/call/service.js +1879 -2385
  349. package/dist/cjs/w/call/service.js.map +1 -0
  350. package/dist/cjs/w/call/treasury.js +841 -1138
  351. package/dist/cjs/w/call/treasury.js.map +1 -0
  352. package/dist/cjs/w/call/util.js +593 -624
  353. package/dist/cjs/w/call/util.js.map +1 -0
  354. package/dist/cjs/w/common.d.ts +1 -1
  355. package/dist/cjs/w/common.js +548 -518
  356. package/dist/cjs/w/common.js.map +1 -0
  357. package/dist/cjs/w/exception.js +574 -584
  358. package/dist/cjs/w/exception.js.map +1 -0
  359. package/dist/cjs/w/index.js +26 -23
  360. package/dist/cjs/w/index.js.map +1 -0
  361. package/dist/cjs/w/local/account.js +664 -741
  362. package/dist/cjs/w/local/account.js.map +1 -0
  363. package/dist/cjs/w/local/cache.js +180 -166
  364. package/dist/cjs/w/local/cache.js.map +1 -0
  365. package/dist/cjs/w/local/config.js +51 -80
  366. package/dist/cjs/w/local/config.js.map +1 -0
  367. package/dist/cjs/w/local/index.js +225 -290
  368. package/dist/cjs/w/local/index.js.map +1 -0
  369. package/dist/cjs/w/local/local.d.ts +2 -2
  370. package/dist/cjs/w/local/local.js +638 -646
  371. package/dist/cjs/w/local/local.js.map +1 -0
  372. package/dist/cjs/w/local/storage.js +210 -164
  373. package/dist/cjs/w/local/storage.js.map +1 -0
  374. package/dist/cjs/w/local/token.js +158 -175
  375. package/dist/cjs/w/local/token.js.map +1 -0
  376. package/dist/cjs/w/local/util.js +80 -51
  377. package/dist/cjs/w/local/util.js.map +1 -0
  378. package/dist/cjs/w/local/wip.js +1078 -802
  379. package/dist/cjs/w/local/wip.js.map +1 -0
  380. package/dist/cjs/w/messenger/crypto.js +496 -389
  381. package/dist/cjs/w/messenger/crypto.js.map +1 -0
  382. package/dist/cjs/w/messenger/index.js +53 -35
  383. package/dist/cjs/w/messenger/index.js.map +1 -0
  384. package/dist/cjs/w/messenger/messenger-api.js +1159 -1035
  385. package/dist/cjs/w/messenger/messenger-api.js.map +1 -0
  386. package/dist/cjs/w/messenger/messenger-manager.js +954 -1083
  387. package/dist/cjs/w/messenger/messenger-manager.js.map +1 -0
  388. package/dist/cjs/w/messenger/messenger.d.ts +1 -1
  389. package/dist/cjs/w/messenger/messenger.js +1304 -1450
  390. package/dist/cjs/w/messenger/messenger.js.map +1 -0
  391. package/dist/cjs/w/messenger/server.js +390 -512
  392. package/dist/cjs/w/messenger/server.js.map +1 -0
  393. package/dist/cjs/w/messenger/session.js +399 -403
  394. package/dist/cjs/w/messenger/session.js.map +1 -0
  395. package/dist/cjs/w/messenger/storage.js +881 -777
  396. package/dist/cjs/w/messenger/storage.js.map +1 -0
  397. package/dist/cjs/w/messenger/types.d.ts +2 -2
  398. package/dist/cjs/w/messenger/types.js +83 -103
  399. package/dist/cjs/w/messenger/types.js.map +1 -0
  400. package/dist/cjs/w/messenger/utils.js +29 -34
  401. package/dist/cjs/w/messenger/utils.js.map +1 -0
  402. package/dist/cjs/w/query/bult-in.js +101 -110
  403. package/dist/cjs/w/query/bult-in.js.map +1 -0
  404. package/dist/cjs/w/query/event.js +134 -146
  405. package/dist/cjs/w/query/event.js.map +1 -0
  406. package/dist/cjs/w/query/index.js +22 -20
  407. package/dist/cjs/w/query/index.js.map +1 -0
  408. package/dist/cjs/w/query/object.js +1576 -1576
  409. package/dist/cjs/w/query/object.js.map +1 -0
  410. package/dist/cjs/w/query/received.js +66 -88
  411. package/dist/cjs/w/query/received.js.map +1 -0
  412. package/dist/cjs/w/query/util.js +53 -77
  413. package/dist/cjs/w/query/util.js.map +1 -0
  414. package/dist/cjs/w/util.js +589 -675
  415. package/dist/cjs/w/util.js.map +1 -0
  416. package/dist/esm/bcs/bcs.d.ts +199 -199
  417. package/dist/esm/bcs/bcs.js +269 -310
  418. package/dist/esm/bcs/bcs.js.map +1 -0
  419. package/dist/esm/bcs/effects.d.ts +109 -109
  420. package/dist/esm/bcs/effects.js +171 -179
  421. package/dist/esm/bcs/effects.js.map +1 -0
  422. package/dist/esm/bcs/index.d.ts +1 -2584
  423. package/dist/esm/bcs/index.js +51 -94
  424. package/dist/esm/bcs/index.js.map +1 -0
  425. package/dist/esm/bcs/pure.js +35 -38
  426. package/dist/esm/bcs/pure.js.map +1 -0
  427. package/dist/esm/bcs/type-tag-serializer.js +98 -95
  428. package/dist/esm/bcs/type-tag-serializer.js.map +1 -0
  429. package/dist/esm/bcs/types.js +5 -5
  430. package/dist/esm/bcs/types.js.map +1 -0
  431. package/dist/esm/client/index.js +7 -23
  432. package/dist/esm/client/index.js.map +1 -0
  433. package/dist/esm/client/network.js +23 -22
  434. package/dist/esm/client/network.js.map +1 -0
  435. package/dist/esm/cryptography/index.js +9 -46
  436. package/dist/esm/cryptography/index.js.map +1 -0
  437. package/dist/esm/cryptography/intent.d.ts +1 -1
  438. package/dist/esm/cryptography/intent.js +18 -12
  439. package/dist/esm/cryptography/intent.js.map +1 -0
  440. package/dist/esm/cryptography/keypair.js +95 -99
  441. package/dist/esm/cryptography/keypair.js.map +1 -0
  442. package/dist/esm/cryptography/mnemonics.js +40 -24
  443. package/dist/esm/cryptography/mnemonics.js.map +1 -0
  444. package/dist/esm/cryptography/publickey.js +104 -115
  445. package/dist/esm/cryptography/publickey.js.map +1 -0
  446. package/dist/esm/cryptography/signature-scheme.js +22 -24
  447. package/dist/esm/cryptography/signature-scheme.js.map +1 -0
  448. package/dist/esm/cryptography/signature.d.ts +2 -24
  449. package/dist/esm/cryptography/signature.js +44 -48
  450. package/dist/esm/cryptography/signature.js.map +1 -0
  451. package/dist/esm/experimental/cache.js +61 -0
  452. package/dist/esm/experimental/cache.js.map +1 -0
  453. package/dist/esm/experimental/client.js +23 -0
  454. package/dist/esm/experimental/client.js.map +1 -0
  455. package/dist/esm/experimental/core.js +85 -0
  456. package/dist/esm/experimental/core.js.map +1 -0
  457. package/dist/esm/experimental/errors.js +27 -0
  458. package/dist/esm/experimental/errors.js.map +1 -0
  459. package/dist/esm/experimental/index.js +8 -0
  460. package/dist/esm/experimental/index.js.map +1 -0
  461. package/dist/esm/experimental/persistent-storage.js +337 -0
  462. package/dist/esm/experimental/persistent-storage.js.map +1 -0
  463. package/dist/esm/experimental/persistent-storage.test.js +198 -0
  464. package/dist/esm/experimental/persistent-storage.test.js.map +1 -0
  465. package/dist/esm/experimental/transports/utils.js +100 -0
  466. package/dist/esm/experimental/transports/utils.js.map +1 -0
  467. package/dist/esm/experimental/types.js +5 -0
  468. package/dist/esm/experimental/types.js.map +1 -0
  469. package/dist/esm/faucet/faucet.js +104 -111
  470. package/dist/esm/faucet/faucet.js.map +1 -0
  471. package/dist/esm/faucet/index.js +4 -16
  472. package/dist/esm/faucet/index.js.map +1 -0
  473. package/dist/esm/grpc/client.js +34 -34
  474. package/dist/esm/grpc/client.js.map +1 -0
  475. package/dist/esm/grpc/core.js +570 -601
  476. package/dist/esm/grpc/core.js.map +1 -0
  477. package/dist/esm/grpc/index.js +5 -6
  478. package/dist/esm/grpc/index.js.map +1 -0
  479. package/dist/esm/grpc/proto/google/protobuf/any.js +161 -111
  480. package/dist/esm/grpc/proto/google/protobuf/any.js.map +1 -0
  481. package/dist/esm/grpc/proto/google/protobuf/duration.js +99 -67
  482. package/dist/esm/grpc/proto/google/protobuf/duration.js.map +1 -0
  483. package/dist/esm/grpc/proto/google/protobuf/empty.js +46 -7
  484. package/dist/esm/grpc/proto/google/protobuf/empty.js.map +1 -0
  485. package/dist/esm/grpc/proto/google/protobuf/field_mask.js +90 -52
  486. package/dist/esm/grpc/proto/google/protobuf/field_mask.js.map +1 -0
  487. package/dist/esm/grpc/proto/google/protobuf/struct.js +258 -190
  488. package/dist/esm/grpc/proto/google/protobuf/struct.js.map +1 -0
  489. package/dist/esm/grpc/proto/google/protobuf/timestamp.js +144 -108
  490. package/dist/esm/grpc/proto/google/protobuf/timestamp.js.map +1 -0
  491. package/dist/esm/grpc/proto/google/rpc/error_details.js +313 -267
  492. package/dist/esm/grpc/proto/google/rpc/error_details.js.map +1 -0
  493. package/dist/esm/grpc/proto/google/rpc/status.js +45 -28
  494. package/dist/esm/grpc/proto/google/rpc/status.js.map +1 -0
  495. package/dist/esm/grpc/proto/sui/rpc/v2/argument.js +80 -47
  496. package/dist/esm/grpc/proto/sui/rpc/v2/argument.js.map +1 -0
  497. package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js +41 -29
  498. package/dist/esm/grpc/proto/sui/rpc/v2/balance_change.js.map +1 -0
  499. package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js +34 -22
  500. package/dist/esm/grpc/proto/sui/rpc/v2/bcs.js.map +1 -0
  501. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js +61 -49
  502. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint.js.map +1 -0
  503. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js +72 -57
  504. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_contents.js.map +1 -0
  505. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js +173 -139
  506. package/dist/esm/grpc/proto/sui/rpc/v2/checkpoint_summary.js.map +1 -0
  507. package/dist/esm/grpc/proto/sui/rpc/v2/effects.js +358 -268
  508. package/dist/esm/grpc/proto/sui/rpc/v2/effects.js.map +1 -0
  509. package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js +72 -60
  510. package/dist/esm/grpc/proto/sui/rpc/v2/epoch.js.map +1 -0
  511. package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js +29 -9
  512. package/dist/esm/grpc/proto/sui/rpc/v2/error_reason.js.map +1 -0
  513. package/dist/esm/grpc/proto/sui/rpc/v2/event.js +74 -59
  514. package/dist/esm/grpc/proto/sui/rpc/v2/event.js.map +1 -0
  515. package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js +69 -57
  516. package/dist/esm/grpc/proto/sui/rpc/v2/executed_transaction.js.map +1 -0
  517. package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js +861 -474
  518. package/dist/esm/grpc/proto/sui/rpc/v2/execution_status.js.map +1 -0
  519. package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js +52 -40
  520. package/dist/esm/grpc/proto/sui/rpc/v2/gas_cost_summary.js.map +1 -0
  521. package/dist/esm/grpc/proto/sui/rpc/v2/input.js +98 -61
  522. package/dist/esm/grpc/proto/sui/rpc/v2/input.js.map +1 -0
  523. package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js +71 -56
  524. package/dist/esm/grpc/proto/sui/rpc/v2/jwk.js.map +1 -0
  525. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js +65 -100
  526. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.client.js.map +1 -0
  527. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js +365 -306
  528. package/dist/esm/grpc/proto/sui/rpc/v2/ledger_service.js.map +1 -0
  529. package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js +585 -442
  530. package/dist/esm/grpc/proto/sui/rpc/v2/move_package.js.map +1 -0
  531. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js +42 -59
  532. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.client.js.map +1 -0
  533. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js +226 -191
  534. package/dist/esm/grpc/proto/sui/rpc/v2/move_package_service.js.map +1 -0
  535. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js +28 -33
  536. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.client.js.map +1 -0
  537. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js +129 -107
  538. package/dist/esm/grpc/proto/sui/rpc/v2/name_service.js.map +1 -0
  539. package/dist/esm/grpc/proto/sui/rpc/v2/object.js +100 -85
  540. package/dist/esm/grpc/proto/sui/rpc/v2/object.js.map +1 -0
  541. package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js +42 -30
  542. package/dist/esm/grpc/proto/sui/rpc/v2/object_reference.js.map +1 -0
  543. package/dist/esm/grpc/proto/sui/rpc/v2/owner.js +72 -40
  544. package/dist/esm/grpc/proto/sui/rpc/v2/owner.js.map +1 -0
  545. package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js +42 -38
  546. package/dist/esm/grpc/proto/sui/rpc/v2/protocol_config.js.map +1 -0
  547. package/dist/esm/grpc/proto/sui/rpc/v2/signature.js +544 -481
  548. package/dist/esm/grpc/proto/sui/rpc/v2/signature.js.map +1 -0
  549. package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js +52 -13
  550. package/dist/esm/grpc/proto/sui/rpc/v2/signature_scheme.js.map +1 -0
  551. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js +23 -28
  552. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.client.js.map +1 -0
  553. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js +74 -60
  554. package/dist/esm/grpc/proto/sui/rpc/v2/signature_verification_service.js.map +1 -0
  555. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js +49 -66
  556. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.client.js.map +1 -0
  557. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js +623 -490
  558. package/dist/esm/grpc/proto/sui/rpc/v2/state_service.js.map +1 -0
  559. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js +33 -32
  560. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.client.js.map +1 -0
  561. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js +50 -36
  562. package/dist/esm/grpc/proto/sui/rpc/v2/subscription_service.js.map +1 -0
  563. package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js +737 -701
  564. package/dist/esm/grpc/proto/sui/rpc/v2/system_state.js.map +1 -0
  565. package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js +1177 -917
  566. package/dist/esm/grpc/proto/sui/rpc/v2/transaction.js.map +1 -0
  567. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js +28 -27
  568. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.client.js.map +1 -0
  569. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js +169 -133
  570. package/dist/esm/grpc/proto/sui/rpc/v2/transaction_execution_service.js.map +1 -0
  571. package/dist/esm/index.js +21 -107
  572. package/dist/esm/index.js.map +1 -0
  573. package/dist/esm/jsonRpc/client.js +646 -727
  574. package/dist/esm/jsonRpc/client.js.map +1 -0
  575. package/dist/esm/jsonRpc/core.d.ts +7 -7
  576. package/dist/esm/jsonRpc/core.js +550 -581
  577. package/dist/esm/jsonRpc/core.js.map +1 -0
  578. package/dist/esm/jsonRpc/errors.js +36 -41
  579. package/dist/esm/jsonRpc/errors.js.map +1 -0
  580. package/dist/esm/jsonRpc/http-transport.js +65 -93
  581. package/dist/esm/jsonRpc/http-transport.js.map +1 -0
  582. package/dist/esm/jsonRpc/index.js +6 -20
  583. package/dist/esm/jsonRpc/index.js.map +1 -0
  584. package/dist/esm/jsonRpc/json-rpc-resolver.js +281 -276
  585. package/dist/esm/jsonRpc/json-rpc-resolver.js.map +1 -0
  586. package/dist/esm/jsonRpc/rpc-websocket-client.js +147 -189
  587. package/dist/esm/jsonRpc/rpc-websocket-client.js.map +1 -0
  588. package/dist/esm/jsonRpc/types/chain.js +4 -0
  589. package/dist/esm/jsonRpc/types/chain.js.map +1 -0
  590. package/dist/esm/jsonRpc/types/changes.js +4 -0
  591. package/dist/esm/jsonRpc/types/changes.js.map +1 -0
  592. package/dist/esm/jsonRpc/types/coins.js +4 -0
  593. package/dist/esm/jsonRpc/types/coins.js.map +1 -0
  594. package/dist/esm/jsonRpc/types/common.js +4 -0
  595. package/dist/esm/jsonRpc/types/common.js.map +1 -0
  596. package/dist/esm/jsonRpc/types/generated.d.ts +1 -1
  597. package/dist/esm/jsonRpc/types/generated.js +4 -0
  598. package/dist/esm/jsonRpc/types/generated.js.map +1 -0
  599. package/dist/esm/jsonRpc/types/index.js +4 -0
  600. package/dist/esm/jsonRpc/types/index.js.map +1 -0
  601. package/dist/esm/jsonRpc/types/params.js +4 -0
  602. package/dist/esm/jsonRpc/types/params.js.map +1 -0
  603. package/dist/esm/keypairs/ed25519/ed25519-hd-key.js +49 -48
  604. package/dist/esm/keypairs/ed25519/ed25519-hd-key.js.map +1 -0
  605. package/dist/esm/keypairs/ed25519/index.js +5 -10
  606. package/dist/esm/keypairs/ed25519/index.js.map +1 -0
  607. package/dist/esm/keypairs/ed25519/keypair.js +128 -146
  608. package/dist/esm/keypairs/ed25519/keypair.js.map +1 -0
  609. package/dist/esm/keypairs/ed25519/publickey.js +64 -67
  610. package/dist/esm/keypairs/ed25519/publickey.js.map +1 -0
  611. package/dist/esm/keypairs/index.js +3 -0
  612. package/dist/esm/keypairs/index.js.map +1 -0
  613. package/dist/esm/keypairs/passkey/index.js +5 -12
  614. package/dist/esm/keypairs/passkey/index.js.map +1 -0
  615. package/dist/esm/keypairs/passkey/keypair.js +236 -243
  616. package/dist/esm/keypairs/passkey/keypair.js.map +1 -0
  617. package/dist/esm/keypairs/passkey/publickey.js +154 -140
  618. package/dist/esm/keypairs/passkey/publickey.js.map +1 -0
  619. package/dist/esm/keypairs/passkey/types.js +4 -0
  620. package/dist/esm/keypairs/passkey/types.js.map +1 -0
  621. package/dist/esm/keypairs/secp256k1/index.js +5 -10
  622. package/dist/esm/keypairs/secp256k1/index.js.map +1 -0
  623. package/dist/esm/keypairs/secp256k1/keypair.js +120 -134
  624. package/dist/esm/keypairs/secp256k1/keypair.js.map +1 -0
  625. package/dist/esm/keypairs/secp256k1/publickey.js +64 -71
  626. package/dist/esm/keypairs/secp256k1/publickey.js.map +1 -0
  627. package/dist/esm/keypairs/secp256r1/index.js +5 -10
  628. package/dist/esm/keypairs/secp256r1/index.js.map +1 -0
  629. package/dist/esm/keypairs/secp256r1/keypair.js +118 -131
  630. package/dist/esm/keypairs/secp256r1/keypair.js.map +1 -0
  631. package/dist/esm/keypairs/secp256r1/publickey.js +63 -66
  632. package/dist/esm/keypairs/secp256r1/publickey.js.map +1 -0
  633. package/dist/esm/multisig/index.js +5 -10
  634. package/dist/esm/multisig/index.js.map +1 -0
  635. package/dist/esm/multisig/publickey.d.ts +1 -1
  636. package/dist/esm/multisig/publickey.js +216 -253
  637. package/dist/esm/multisig/publickey.js.map +1 -0
  638. package/dist/esm/multisig/signer.js +57 -89
  639. package/dist/esm/multisig/signer.js.map +1 -0
  640. package/dist/esm/transactions/Arguments.d.ts +4 -4
  641. package/dist/esm/transactions/Arguments.js +9 -13
  642. package/dist/esm/transactions/Arguments.js.map +1 -0
  643. package/dist/esm/transactions/Commands.js +105 -118
  644. package/dist/esm/transactions/Commands.js.map +1 -0
  645. package/dist/esm/transactions/Inputs.js +49 -61
  646. package/dist/esm/transactions/Inputs.js.map +1 -0
  647. package/dist/esm/transactions/ObjectCache.d.ts +8 -8
  648. package/dist/esm/transactions/ObjectCache.js +200 -223
  649. package/dist/esm/transactions/ObjectCache.js.map +1 -0
  650. package/dist/esm/transactions/Transaction.d.ts +32 -32
  651. package/dist/esm/transactions/Transaction.js +611 -696
  652. package/dist/esm/transactions/Transaction.js.map +1 -0
  653. package/dist/esm/transactions/TransactionData.d.ts +9 -9
  654. package/dist/esm/transactions/TransactionData.js +386 -415
  655. package/dist/esm/transactions/TransactionData.js.map +1 -0
  656. package/dist/esm/transactions/__tests__/Transaction.test.js +167 -0
  657. package/dist/esm/transactions/__tests__/Transaction.test.js.map +1 -0
  658. package/dist/esm/transactions/__tests__/bcs.test.js +200 -0
  659. package/dist/esm/transactions/__tests__/bcs.test.js.map +1 -0
  660. package/dist/esm/transactions/data/internal.js +158 -205
  661. package/dist/esm/transactions/data/internal.js.map +1 -0
  662. package/dist/esm/transactions/data/v1.js +419 -487
  663. package/dist/esm/transactions/data/v1.js.map +1 -0
  664. package/dist/esm/transactions/data/v2.d.ts +5 -5
  665. package/dist/esm/transactions/data/v2.js +89 -107
  666. package/dist/esm/transactions/data/v2.js.map +1 -0
  667. package/dist/esm/transactions/executor/caching.d.ts +2 -2
  668. package/dist/esm/transactions/executor/caching.js +66 -93
  669. package/dist/esm/transactions/executor/caching.js.map +1 -0
  670. package/dist/esm/transactions/executor/parallel.js +329 -352
  671. package/dist/esm/transactions/executor/parallel.js.map +1 -0
  672. package/dist/esm/transactions/executor/queue.js +58 -64
  673. package/dist/esm/transactions/executor/queue.js.map +1 -0
  674. package/dist/esm/transactions/executor/serial.d.ts +5 -5
  675. package/dist/esm/transactions/executor/serial.js +96 -110
  676. package/dist/esm/transactions/executor/serial.js.map +1 -0
  677. package/dist/esm/transactions/hash.js +15 -9
  678. package/dist/esm/transactions/hash.js.map +1 -0
  679. package/dist/esm/transactions/index.js +15 -41
  680. package/dist/esm/transactions/index.js.map +1 -0
  681. package/dist/esm/transactions/intents/CoinWithBalance.js +127 -165
  682. package/dist/esm/transactions/intents/CoinWithBalance.js.map +1 -0
  683. package/dist/esm/transactions/object.js +86 -92
  684. package/dist/esm/transactions/object.js.map +1 -0
  685. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js +18 -15
  686. package/dist/esm/transactions/plugins/NamedPackagesPlugin.js.map +1 -0
  687. package/dist/esm/transactions/pure.js +34 -39
  688. package/dist/esm/transactions/pure.js.map +1 -0
  689. package/dist/esm/transactions/resolve.js +58 -69
  690. package/dist/esm/transactions/resolve.js.map +1 -0
  691. package/dist/esm/transactions/serializer.js +145 -144
  692. package/dist/esm/transactions/serializer.js.map +1 -0
  693. package/dist/esm/transactions/utils.d.ts +1 -1
  694. package/dist/esm/transactions/utils.js +110 -109
  695. package/dist/esm/transactions/utils.js.map +1 -0
  696. package/dist/esm/utils/constants.js +26 -36
  697. package/dist/esm/utils/constants.js.map +1 -0
  698. package/dist/esm/utils/derived-objects.js +11 -10
  699. package/dist/esm/utils/derived-objects.js.map +1 -0
  700. package/dist/esm/utils/dynamic-fields.js +16 -16
  701. package/dist/esm/utils/dynamic-fields.js.map +1 -0
  702. package/dist/esm/utils/format.js +13 -13
  703. package/dist/esm/utils/format.js.map +1 -0
  704. package/dist/esm/utils/index.js +15 -76
  705. package/dist/esm/utils/index.js.map +1 -0
  706. package/dist/esm/utils/move-registry.js +34 -17
  707. package/dist/esm/utils/move-registry.js.map +1 -0
  708. package/dist/esm/utils/sui-types.js +70 -54
  709. package/dist/esm/utils/sui-types.js.map +1 -0
  710. package/dist/esm/utils/suins.js +29 -29
  711. package/dist/esm/utils/suins.js.map +1 -0
  712. package/dist/esm/verify/index.js +5 -14
  713. package/dist/esm/verify/index.js.map +1 -0
  714. package/dist/esm/verify/verify.js +76 -93
  715. package/dist/esm/verify/verify.js.map +1 -0
  716. package/dist/esm/version.js +6 -6
  717. package/dist/esm/version.js.map +1 -0
  718. package/dist/esm/w/call/allocation.js +307 -402
  719. package/dist/esm/w/call/allocation.js.map +1 -0
  720. package/dist/esm/w/call/arb.js +100 -129
  721. package/dist/esm/w/call/arb.js.map +1 -0
  722. package/dist/esm/w/call/arbitration.js +1170 -1568
  723. package/dist/esm/w/call/arbitration.js.map +1 -0
  724. package/dist/esm/w/call/base.js +288 -315
  725. package/dist/esm/w/call/base.js.map +1 -0
  726. package/dist/esm/w/call/contact.js +318 -442
  727. package/dist/esm/w/call/contact.js.map +1 -0
  728. package/dist/esm/w/call/demand.js +673 -841
  729. package/dist/esm/w/call/demand.js.map +1 -0
  730. package/dist/esm/w/call/entity.js +162 -203
  731. package/dist/esm/w/call/entity.js.map +1 -0
  732. package/dist/esm/w/call/guard-ins.d.ts +1 -0
  733. package/dist/esm/w/call/guard-ins.js +4373 -4366
  734. package/dist/esm/w/call/guard-ins.js.map +1 -0
  735. package/dist/esm/w/call/guard.d.ts +10 -0
  736. package/dist/esm/w/call/guard.js +1061 -1115
  737. package/dist/esm/w/call/guard.js.map +1 -0
  738. package/dist/esm/w/call/index.d.ts +1 -1
  739. package/dist/esm/w/call/index.js +24 -54
  740. package/dist/esm/w/call/index.js.map +1 -0
  741. package/dist/esm/w/call/machine.js +1086 -1433
  742. package/dist/esm/w/call/machine.js.map +1 -0
  743. package/dist/esm/w/call/order.js +301 -448
  744. package/dist/esm/w/call/order.js.map +1 -0
  745. package/dist/esm/w/call/passport.js +204 -240
  746. package/dist/esm/w/call/passport.js.map +1 -0
  747. package/dist/esm/w/call/payment.js +177 -215
  748. package/dist/esm/w/call/payment.js.map +1 -0
  749. package/dist/esm/w/call/permission.js +1172 -1320
  750. package/dist/esm/w/call/permission.js.map +1 -0
  751. package/dist/esm/w/call/personal.js +121 -156
  752. package/dist/esm/w/call/personal.js.map +1 -0
  753. package/dist/esm/w/call/progress.js +625 -797
  754. package/dist/esm/w/call/progress.js.map +1 -0
  755. package/dist/esm/w/call/proof.js +61 -103
  756. package/dist/esm/w/call/proof.js.map +1 -0
  757. package/dist/esm/w/call/repository.js +1017 -1251
  758. package/dist/esm/w/call/repository.js.map +1 -0
  759. package/dist/esm/w/call/resource.js +108 -124
  760. package/dist/esm/w/call/resource.js.map +1 -0
  761. package/dist/esm/w/call/reward.js +660 -847
  762. package/dist/esm/w/call/reward.js.map +1 -0
  763. package/dist/esm/w/call/service.js +1849 -2400
  764. package/dist/esm/w/call/service.js.map +1 -0
  765. package/dist/esm/w/call/treasury.js +815 -1125
  766. package/dist/esm/w/call/treasury.js.map +1 -0
  767. package/dist/esm/w/call/util.js +553 -576
  768. package/dist/esm/w/call/util.js.map +1 -0
  769. package/dist/esm/w/common.d.ts +1 -1
  770. package/dist/esm/w/common.js +579 -580
  771. package/dist/esm/w/common.js.map +1 -0
  772. package/dist/esm/w/exception.js +570 -573
  773. package/dist/esm/w/exception.js.map +1 -0
  774. package/dist/esm/w/index.js +4 -0
  775. package/dist/esm/w/index.js.map +1 -0
  776. package/dist/esm/w/local/account.js +652 -709
  777. package/dist/esm/w/local/account.js.map +1 -0
  778. package/dist/esm/w/local/cache.js +176 -147
  779. package/dist/esm/w/local/cache.js.map +1 -0
  780. package/dist/esm/w/local/config.js +46 -60
  781. package/dist/esm/w/local/config.js.map +1 -0
  782. package/dist/esm/w/local/index.js +196 -273
  783. package/dist/esm/w/local/index.js.map +1 -0
  784. package/dist/esm/w/local/local.d.ts +2 -2
  785. package/dist/esm/w/local/local.js +631 -626
  786. package/dist/esm/w/local/local.js.map +1 -0
  787. package/dist/esm/w/local/storage.js +168 -136
  788. package/dist/esm/w/local/storage.js.map +1 -0
  789. package/dist/esm/w/local/token.js +149 -151
  790. package/dist/esm/w/local/token.js.map +1 -0
  791. package/dist/esm/w/local/util.js +45 -22
  792. package/dist/esm/w/local/util.js.map +1 -0
  793. package/dist/esm/w/local/wip.js +1038 -781
  794. package/dist/esm/w/local/wip.js.map +1 -0
  795. package/dist/esm/w/messenger/crypto.js +491 -387
  796. package/dist/esm/w/messenger/crypto.js.map +1 -0
  797. package/dist/esm/w/messenger/index.js +27 -24
  798. package/dist/esm/w/messenger/index.js.map +1 -0
  799. package/dist/esm/w/messenger/messenger-api.js +1111 -1017
  800. package/dist/esm/w/messenger/messenger-api.js.map +1 -0
  801. package/dist/esm/w/messenger/messenger-manager.js +944 -1052
  802. package/dist/esm/w/messenger/messenger-manager.js.map +1 -0
  803. package/dist/esm/w/messenger/messenger.d.ts +1 -1
  804. package/dist/esm/w/messenger/messenger.js +1258 -1421
  805. package/dist/esm/w/messenger/messenger.js.map +1 -0
  806. package/dist/esm/w/messenger/server.js +388 -499
  807. package/dist/esm/w/messenger/server.js.map +1 -0
  808. package/dist/esm/w/messenger/session.js +394 -399
  809. package/dist/esm/w/messenger/session.js.map +1 -0
  810. package/dist/esm/w/messenger/storage.js +840 -751
  811. package/dist/esm/w/messenger/storage.js.map +1 -0
  812. package/dist/esm/w/messenger/types.d.ts +2 -2
  813. package/dist/esm/w/messenger/types.js +80 -85
  814. package/dist/esm/w/messenger/types.js.map +1 -0
  815. package/dist/esm/w/messenger/utils.js +28 -16
  816. package/dist/esm/w/messenger/utils.js.map +1 -0
  817. package/dist/esm/w/query/bult-in.js +95 -100
  818. package/dist/esm/w/query/bult-in.js.map +1 -0
  819. package/dist/esm/w/query/event.js +128 -125
  820. package/dist/esm/w/query/event.js.map +1 -0
  821. package/dist/esm/w/query/index.js +3 -0
  822. package/dist/esm/w/query/index.js.map +1 -0
  823. package/dist/esm/w/query/object.js +1560 -1574
  824. package/dist/esm/w/query/object.js.map +1 -0
  825. package/dist/esm/w/query/received.js +57 -63
  826. package/dist/esm/w/query/received.js.map +1 -0
  827. package/dist/esm/w/query/util.js +48 -56
  828. package/dist/esm/w/query/util.js.map +1 -0
  829. package/dist/esm/w/util.js +578 -673
  830. package/dist/esm/w/util.js.map +1 -0
  831. package/package.json +14 -9
  832. package/dist/cjs/graphql/client.js +0 -98
  833. package/dist/cjs/graphql/core.js +0 -506
  834. package/dist/cjs/graphql/generated/2024.1/tada-env.js +0 -13141
  835. package/dist/cjs/graphql/generated/2024.1/tsconfig.tada.js +0 -11
  836. package/dist/cjs/graphql/generated/2024.4/tada-env.js +0 -13287
  837. package/dist/cjs/graphql/generated/2024.4/tsconfig.tada.js +0 -11
  838. package/dist/cjs/graphql/generated/latest/tada-env.js +0 -12925
  839. package/dist/cjs/graphql/generated/latest/tsconfig.tada.js +0 -11
  840. package/dist/cjs/graphql/generated/queries.js +0 -807
  841. package/dist/cjs/graphql/index.js +0 -25
  842. package/dist/cjs/graphql/schemas/2024.1/index.js +0 -28
  843. package/dist/cjs/graphql/schemas/2024.4/index.js +0 -28
  844. package/dist/cjs/graphql/schemas/latest/index.js +0 -28
  845. package/dist/cjs/graphql/types.js +0 -16
  846. package/dist/cjs/package.json +0 -5
  847. package/dist/cjs/w/local/.eslintrc.js +0 -15
  848. package/dist/cjs/w/messenger/.eslintrc.js +0 -15
  849. package/dist/cjs/zklogin/address.js +0 -93
  850. package/dist/cjs/zklogin/bcs.js +0 -41
  851. package/dist/cjs/zklogin/index.js +0 -45
  852. package/dist/cjs/zklogin/jwt-decode.js +0 -88
  853. package/dist/cjs/zklogin/jwt-utils.js +0 -128
  854. package/dist/cjs/zklogin/nonce.js +0 -60
  855. package/dist/cjs/zklogin/poseidon.js +0 -64
  856. package/dist/cjs/zklogin/publickey.js +0 -281
  857. package/dist/cjs/zklogin/signature.js +0 -57
  858. package/dist/cjs/zklogin/utils.js +0 -98
  859. package/dist/esm/graphql/client.js +0 -79
  860. package/dist/esm/graphql/core.js +0 -505
  861. package/dist/esm/graphql/generated/2024.1/tada-env.js +0 -13121
  862. package/dist/esm/graphql/generated/2024.1/tsconfig.tada.js +0 -16
  863. package/dist/esm/graphql/generated/2024.4/tada-env.js +0 -13267
  864. package/dist/esm/graphql/generated/2024.4/tsconfig.tada.js +0 -16
  865. package/dist/esm/graphql/generated/latest/tada-env.js +0 -12905
  866. package/dist/esm/graphql/generated/latest/tsconfig.tada.js +0 -16
  867. package/dist/esm/graphql/generated/queries.js +0 -788
  868. package/dist/esm/graphql/index.js +0 -8
  869. package/dist/esm/graphql/schemas/2024.1/index.js +0 -8
  870. package/dist/esm/graphql/schemas/2024.4/index.js +0 -8
  871. package/dist/esm/graphql/schemas/latest/index.js +0 -8
  872. package/dist/esm/graphql/types.js +0 -0
  873. package/dist/esm/package.json +0 -5
  874. package/dist/esm/w/local/.eslintrc.js +0 -23
  875. package/dist/esm/w/messenger/.eslintrc.js +0 -23
  876. package/dist/esm/zklogin/address.js +0 -78
  877. package/dist/esm/zklogin/bcs.js +0 -21
  878. package/dist/esm/zklogin/index.js +0 -38
  879. package/dist/esm/zklogin/jwt-decode.js +0 -68
  880. package/dist/esm/zklogin/jwt-utils.js +0 -108
  881. package/dist/esm/zklogin/nonce.js +0 -40
  882. package/dist/esm/zklogin/poseidon.js +0 -61
  883. package/dist/esm/zklogin/publickey.js +0 -265
  884. package/dist/esm/zklogin/signature.js +0 -37
  885. package/dist/esm/zklogin/utils.js +0 -78
  886. package/dist/tsconfig.esm.tsbuildinfo +0 -1
  887. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,1118 +1,1010 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1
+ // Copyright (c) Wowok.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Messenger 管理器
5
+ *
6
+ * 支持最多20个账号同时收发消息
7
+ * 自动从account模块筛选有m字段的账号
8
+ * 自动初始化、注册并接收消息
9
+ */
4
10
  import { Messenger } from "./messenger.js";
5
11
  import { MessageStorage } from "./storage.js";
6
12
  import { MessengerPersistStorage } from "./storage.js";
7
13
  import { MessageType, MessageStatus, WTS_MAX_MESSAGE_COUNT } from "./types.js";
8
- import {
9
- MessengerError,
10
- MessengerErrorCode,
11
- DEFAULT_MESSENGER_CONFIG
12
- } from "./types.js";
14
+ import { MessengerError, MessengerErrorCode, DEFAULT_MESSENGER_CONFIG, } from "./types.js";
13
15
  import { canonicalizeJson } from "./utils.js";
14
16
  import { MAX_MESSENGER_ACCOUNTS } from "../local/account.js";
15
17
  import { GetAccountOrMark_Address } from "../local/index.js";
16
18
  const MAX_ACCOUNTS = MAX_MESSENGER_ACCOUNTS;
17
- class MessengerManager {
18
- constructor(options) {
19
- __publicField(this, "accounts", /* @__PURE__ */ new Map());
20
- __publicField(this, "config");
21
- __publicField(this, "messageListeners", /* @__PURE__ */ new Set());
22
- __publicField(this, "pollingTimers", /* @__PURE__ */ new Map());
23
- __publicField(this, "isWatching", false);
24
- __publicField(this, "persistStorage");
25
- __publicField(this, "instanceId");
26
- __publicField(this, "accountRefreshTimer", null);
27
- __publicField(this, "sseHeartbeatTimer", null);
28
- __publicField(this, "sseLockedAccounts", /* @__PURE__ */ new Set());
29
- this.config = {
30
- ...DEFAULT_MESSENGER_CONFIG,
31
- ...options?.messengerConfig
32
- };
33
- this.instanceId = options?.instanceId || "default";
34
- this.persistStorage = new MessengerPersistStorage();
35
- }
36
- findAccount(address) {
37
- return this.accounts.get(address.toLowerCase());
38
- }
39
- getConfig() {
40
- return this.config;
41
- }
42
- get_accounts() {
43
- return Array.from(this.accounts.values()).map((acc) => acc.address);
44
- }
45
- async refresh_accounts() {
46
- const { Account } = await import("../local/account.js");
47
- const messengerAccounts = await Account.Instance().list_messenger_accounts();
48
- const currentAddresses = new Set(this.accounts.keys());
49
- const newAddresses = new Set(
50
- messengerAccounts.map((a) => a.address.toLowerCase())
51
- );
52
- for (const address of currentAddresses) {
53
- if (!newAddresses.has(address)) {
54
- this.remove_account_internal(address);
55
- }
56
- }
57
- for (const account of messengerAccounts) {
58
- const addressLower = account.address.toLowerCase();
59
- if (!this.accounts.has(addressLower)) {
60
- await this.add_account_internal(account.address);
61
- }
62
- }
63
- if (this.accounts.size > 0 && !this.isWatching) {
64
- this.startPolling();
65
- } else if (this.accounts.size === 0 && this.isWatching) {
66
- this.stopPolling();
67
- }
68
- await this.syncAllContactLists();
69
- }
70
- async start() {
71
- await this.refresh_accounts();
72
- let hasSSEFailure = false;
73
- for (const account of this.accounts.values()) {
74
- if (!account.messenger.isEventSourceConnected()) {
75
- try {
76
- const hasLock = this.persistStorage.tryAcquireSSELock(
77
- account.address,
78
- this.instanceId
79
- );
80
- if (hasLock) {
81
- this.sseLockedAccounts.add(
82
- account.address.toLowerCase()
83
- );
84
- await account.messenger.connectEventSource(
85
- (messages) => {
86
- for (const listener of this.messageListeners) {
87
- listener(messages);
88
- }
89
- }
90
- );
91
- } else {
92
- console.debug(
93
- `Another process holds SSE lock for ${account.address}, using polling`
94
- );
95
- hasSSEFailure = true;
96
- }
97
- } catch (err) {
98
- console.warn(
99
- `Failed to connect SSE for ${account.address}, falling back to polling:`,
100
- err
101
- );
102
- hasSSEFailure = true;
103
- this.persistStorage.releaseSSELock(
104
- account.address,
105
- this.instanceId
106
- );
107
- this.sseLockedAccounts.delete(
108
- account.address.toLowerCase()
109
- );
110
- }
111
- }
112
- }
113
- if (hasSSEFailure && !this.isWatching) {
114
- this.startPolling();
115
- }
116
- this.startSSEHeartbeat();
117
- if (this.accountRefreshTimer) {
118
- clearInterval(this.accountRefreshTimer);
119
- }
120
- this.accountRefreshTimer = setInterval(() => {
121
- this.refresh_accounts().catch((err) => {
122
- console.error("Failed to refresh accounts:", err);
123
- });
124
- }, this.config.watch_interval_ms);
125
- }
126
- stop() {
127
- if (this.accountRefreshTimer) {
128
- clearInterval(this.accountRefreshTimer);
129
- this.accountRefreshTimer = null;
130
- }
131
- this.stopSSEHeartbeat();
132
- for (const accountAddress of this.sseLockedAccounts) {
133
- this.persistStorage.releaseSSELock(accountAddress, this.instanceId);
134
- }
135
- this.sseLockedAccounts.clear();
136
- this.stopPolling();
137
- this.clear_accounts();
138
- }
139
- startSSEHeartbeat() {
140
- if (this.sseHeartbeatTimer) {
141
- clearInterval(this.sseHeartbeatTimer);
142
- }
143
- this.sseHeartbeatTimer = setInterval(() => {
144
- for (const accountAddress of this.sseLockedAccounts) {
145
- this.persistStorage.updateSSELockHeartbeat(
146
- accountAddress,
147
- this.instanceId
148
- );
149
- }
150
- }, 5e3);
151
- }
152
- stopSSEHeartbeat() {
153
- if (this.sseHeartbeatTimer) {
154
- clearInterval(this.sseHeartbeatTimer);
155
- this.sseHeartbeatTimer = null;
156
- }
157
- }
158
- async add_account_internal(address) {
159
- const addressLower = address.toLowerCase();
160
- if (this.accounts.size >= MAX_ACCOUNTS) {
161
- throw new MessengerError(
162
- MessengerErrorCode.INVALID_INPUT,
163
- `Maximum ${MAX_ACCOUNTS} accounts allowed`
164
- );
165
- }
166
- const messenger = new Messenger(addressLower, this.config);
167
- try {
168
- await messenger.initialize();
169
- } catch (error) {
170
- throw new MessengerError(
171
- MessengerErrorCode.SERVER_ERROR,
172
- `Failed to initialize account ${addressLower}: ${error instanceof Error ? error.message : String(error)}`
173
- );
174
- }
175
- const contactLists = {
176
- friends: [],
177
- guards: [],
178
- lastUpdatedAt: 0
179
- };
180
- this.accounts.set(addressLower, {
181
- address: addressLower,
182
- messenger,
183
- initialized: true,
184
- contactLists
185
- });
186
- if (this.isWatching) {
187
- this.startAccountPolling(addressLower);
188
- }
189
- }
190
- remove_account_internal(address) {
191
- const addressLower = address.toLowerCase();
192
- const account = this.accounts.get(addressLower);
193
- if (!account) return false;
194
- if (account.initialized && account.messenger) {
195
- account.messenger.disconnectEventSource();
196
- account.messenger.disconnect();
197
- }
198
- const timer = this.pollingTimers.get(account.address);
199
- if (timer) {
200
- clearInterval(timer);
201
- this.pollingTimers.delete(account.address);
202
- }
203
- this.persistStorage.releaseSSELock(addressLower, this.instanceId);
204
- this.sseLockedAccounts.delete(addressLower);
205
- return this.accounts.delete(addressLower);
206
- }
207
- clear_accounts() {
208
- this.stopPolling();
209
- for (const info of this.accounts.values()) {
210
- info.messenger.disconnectEventSource();
211
- info.messenger.disconnect();
212
- }
213
- this.accounts.clear();
214
- }
215
- async send(from, to, content, options) {
216
- const { Account } = await import("../local/account.js");
217
- let accountInfo = this.findAccount(from);
218
- if (!accountInfo) {
219
- const account = await Account.Instance().get(from, false);
220
- if (!account) {
221
- throw new MessengerError(
222
- MessengerErrorCode.IDENTITY_NOT_FOUND,
223
- `Account ${from} not found`
224
- );
225
- }
226
- if (account.m == null) {
227
- if (options?.new_messenger_name == null) {
228
- throw new MessengerError(
229
- MessengerErrorCode.ACCOUNT_MESSENGER_NOT_ENABLED,
230
- `Account messenger name not set. Use new_messenger_name parameter to set it automatically.`
231
- );
232
- }
233
- await Account.Instance().set_messenger(
234
- from,
235
- options.new_messenger_name
236
- );
237
- }
238
- await this.refresh_accounts();
239
- accountInfo = this.findAccount(from);
240
- if (!accountInfo) {
241
- throw new MessengerError(
242
- MessengerErrorCode.SERVER_ERROR,
243
- `Failed to add account ${from} to messenger manager`
244
- );
245
- }
246
- }
247
- if (options?.new_messenger_name != null) {
248
- const account = await Account.Instance().get(from, false);
249
- if (account && account.m !== options.new_messenger_name) {
250
- await Account.Instance().set_messenger(
251
- from,
252
- options.new_messenger_name
253
- );
254
- }
255
- }
256
- return accountInfo.messenger.sendMessage(to, content, {
257
- guardAddress: options?.guardAddress,
258
- passportAddress: options?.passportAddress,
259
- force: options?.force
260
- });
261
- }
262
- async send_file(from, to, filePath, options) {
263
- const { Account } = await import("../local/account.js");
264
- let accountInfo = this.findAccount(from);
265
- if (!accountInfo) {
266
- const account = await Account.Instance().get(from, false);
267
- if (!account) {
268
- throw new MessengerError(
269
- MessengerErrorCode.IDENTITY_NOT_FOUND,
270
- `Account ${from} not found`
271
- );
272
- }
273
- if (account.m == null) {
274
- if (options?.new_messenger_name == null) {
275
- throw new MessengerError(
276
- MessengerErrorCode.ACCOUNT_MESSENGER_NOT_ENABLED,
277
- `Account messenger name not set. Use new_messenger_name parameter to set it automatically.`
278
- );
279
- }
280
- await Account.Instance().set_messenger(
281
- from,
282
- options.new_messenger_name
283
- );
284
- }
285
- await this.refresh_accounts();
286
- accountInfo = this.findAccount(from);
287
- if (!accountInfo) {
288
- throw new MessengerError(
289
- MessengerErrorCode.SERVER_ERROR,
290
- `Failed to add account ${from} to messenger manager`
291
- );
292
- }
293
- }
294
- if (options?.new_messenger_name != null) {
295
- const account = await Account.Instance().get(from, false);
296
- if (account && account.m !== options.new_messenger_name) {
297
- await Account.Instance().set_messenger(
298
- from,
299
- options.new_messenger_name
300
- );
301
- }
302
- }
303
- return accountInfo.messenger.sendZipFile(to, filePath, {
304
- fileName: options?.fileName,
305
- contentType: options?.contentType,
306
- guardAddress: options?.guardAddress,
307
- passportAddress: options?.passportAddress,
308
- force: options?.force
309
- });
310
- }
311
- async watch(filter) {
312
- let messages = [];
313
- if (filter?.account) {
314
- const address = filter.account.toLowerCase();
315
- const messageStorage = new MessageStorage(address);
316
- messages = messageStorage.getAllMessages(address);
317
- } else {
318
- for (const account of this.accounts.values()) {
319
- const messageStorage = new MessageStorage(account.address);
320
- const accountMessages = messageStorage.getAllMessages(
321
- account.address
322
- );
323
- messages.push(...accountMessages);
324
- }
325
- }
326
- if (filter) {
327
- const peerAddress = filter.peerAddress ? await GetAccountOrMark_Address(filter.peerAddress) : void 0;
328
- messages = messages.filter((msg) => {
329
- if (filter.account) {
330
- const accountLower = filter.account.toLowerCase();
331
- const fromLower = msg.fromAddress.toLowerCase();
332
- const toLower = msg.toAddress.toLowerCase();
333
- if (fromLower !== accountLower && toLower !== accountLower) {
334
- return false;
335
- }
336
- }
337
- if (filter.direction && msg.direction !== filter.direction) {
338
- return false;
339
- }
340
- if (filter.status && msg.status !== filter.status) {
341
- return false;
342
- }
343
- if (filter.msgType !== void 0 && msg.msgType !== filter.msgType) {
344
- return false;
345
- }
346
- if (filter.contentType) {
347
- switch (filter.contentType) {
348
- case "text":
349
- if (msg.msgType !== MessageType.NORMAL_MESSAGE)
350
- return false;
351
- break;
352
- case "zip":
353
- if (!msg.zipMetadata) return false;
354
- break;
355
- case "wts":
356
- if (!msg.zipMetadata || msg.zipMetadata?.contentType !== "wts") {
357
- return false;
358
- }
359
- break;
360
- case "wip":
361
- if (!msg.zipMetadata || msg.zipMetadata?.contentType !== "wip") {
362
- return false;
363
- }
364
- break;
365
- }
366
- }
367
- if (filter.peerAddress && peerAddress) {
368
- const peer = peerAddress.toLowerCase();
369
- const from = msg.fromAddress.toLowerCase();
370
- const to = msg.toAddress.toLowerCase();
371
- if (from !== peer && to !== peer) {
372
- return false;
373
- }
374
- }
375
- const timeField = filter.timeField || "createdAt";
376
- if (filter.startTime !== void 0 || filter.endTime !== void 0) {
377
- const msgTime = msg[timeField];
378
- if (msgTime !== void 0) {
379
- if (filter.startTime !== void 0 && msgTime < filter.startTime) {
380
- return false;
381
- }
382
- if (filter.endTime !== void 0 && msgTime > filter.endTime) {
383
- return false;
19
+ export class MessengerManager {
20
+ accounts = new Map();
21
+ config;
22
+ messageListeners = new Set();
23
+ pollingTimers = new Map();
24
+ isWatching = false;
25
+ persistStorage;
26
+ instanceId;
27
+ accountRefreshTimer = null;
28
+ sseHeartbeatTimer = null;
29
+ sseLockedAccounts = new Set();
30
+ constructor(options) {
31
+ this.config = {
32
+ ...DEFAULT_MESSENGER_CONFIG,
33
+ ...options?.messengerConfig,
34
+ };
35
+ this.instanceId = options?.instanceId || "default";
36
+ this.persistStorage = new MessengerPersistStorage();
37
+ }
38
+ findAccount(address) {
39
+ return this.accounts.get(address.toLowerCase());
40
+ }
41
+ getConfig() {
42
+ return this.config;
43
+ }
44
+ get_accounts() {
45
+ return Array.from(this.accounts.values()).map((acc) => acc.address);
46
+ }
47
+ async refresh_accounts() {
48
+ const { Account } = await import("../local/account.js");
49
+ const messengerAccounts = await Account.Instance().list_messenger_accounts();
50
+ const currentAddresses = new Set(this.accounts.keys());
51
+ const newAddresses = new Set(messengerAccounts.map((a) => a.address.toLowerCase()));
52
+ for (const address of currentAddresses) {
53
+ if (!newAddresses.has(address)) {
54
+ this.remove_account_internal(address);
384
55
  }
385
- }
386
56
  }
387
- if (filter.createdAtStart !== void 0 && msg.createdAt < filter.createdAtStart) {
388
- return false;
389
- }
390
- if (filter.createdAtEnd !== void 0 && msg.createdAt > filter.createdAtEnd) {
391
- return false;
57
+ for (const account of messengerAccounts) {
58
+ const addressLower = account.address.toLowerCase();
59
+ if (!this.accounts.has(addressLower)) {
60
+ await this.add_account_internal(account.address);
61
+ }
392
62
  }
393
- if (filter.receivedAtStart !== void 0) {
394
- if (msg.receivedAt === void 0 || msg.receivedAt < filter.receivedAtStart) {
395
- return false;
396
- }
63
+ if (this.accounts.size > 0 && !this.isWatching) {
64
+ this.startPolling();
65
+ }
66
+ else if (this.accounts.size === 0 && this.isWatching) {
67
+ this.stopPolling();
68
+ }
69
+ await this.syncAllContactLists();
70
+ }
71
+ async start() {
72
+ await this.refresh_accounts();
73
+ let hasSSEFailure = false;
74
+ for (const account of this.accounts.values()) {
75
+ if (!account.messenger.isEventSourceConnected()) {
76
+ try {
77
+ const hasLock = this.persistStorage.tryAcquireSSELock(account.address, this.instanceId);
78
+ if (hasLock) {
79
+ this.sseLockedAccounts.add(account.address.toLowerCase());
80
+ await account.messenger.connectEventSource((messages) => {
81
+ for (const listener of this.messageListeners) {
82
+ listener(messages);
83
+ }
84
+ });
85
+ }
86
+ else {
87
+ console.debug(`Another process holds SSE lock for ${account.address}, using polling`);
88
+ hasSSEFailure = true;
89
+ }
90
+ }
91
+ catch (err) {
92
+ console.warn(`Failed to connect SSE for ${account.address}, falling back to polling:`, err);
93
+ hasSSEFailure = true;
94
+ this.persistStorage.releaseSSELock(account.address, this.instanceId);
95
+ this.sseLockedAccounts.delete(account.address.toLowerCase());
96
+ }
97
+ }
397
98
  }
398
- if (filter.receivedAtEnd !== void 0) {
399
- if (msg.receivedAt === void 0 || msg.receivedAt > filter.receivedAtEnd) {
400
- return false;
401
- }
99
+ if (hasSSEFailure && !this.isWatching) {
100
+ this.startPolling();
402
101
  }
403
- if (filter.serverTimestampStart !== void 0) {
404
- if (msg.serverTimestamp === void 0 || msg.serverTimestamp < filter.serverTimestampStart) {
405
- return false;
406
- }
102
+ this.startSSEHeartbeat();
103
+ if (this.accountRefreshTimer) {
104
+ clearInterval(this.accountRefreshTimer);
407
105
  }
408
- if (filter.serverTimestampEnd !== void 0) {
409
- if (msg.serverTimestamp === void 0 || msg.serverTimestamp > filter.serverTimestampEnd) {
410
- return false;
411
- }
106
+ this.accountRefreshTimer = setInterval(() => {
107
+ this.refresh_accounts().catch((err) => {
108
+ console.error("Failed to refresh accounts:", err);
109
+ });
110
+ }, this.config.watch_interval_ms);
111
+ }
112
+ stop() {
113
+ if (this.accountRefreshTimer) {
114
+ clearInterval(this.accountRefreshTimer);
115
+ this.accountRefreshTimer = null;
412
116
  }
413
- if (filter.decryptedOnly && !msg.plaintext) {
414
- return false;
117
+ this.stopSSEHeartbeat();
118
+ for (const accountAddress of this.sseLockedAccounts) {
119
+ this.persistStorage.releaseSSELock(accountAddress, this.instanceId);
415
120
  }
416
- if (filter.arkConfirmedOnly) {
417
- if (!msg.arkConfirmed) {
418
- return false;
419
- }
121
+ this.sseLockedAccounts.clear();
122
+ this.stopPolling();
123
+ this.clear_accounts();
124
+ }
125
+ startSSEHeartbeat() {
126
+ if (this.sseHeartbeatTimer) {
127
+ clearInterval(this.sseHeartbeatTimer);
420
128
  }
421
- if (filter.proofedOnly) {
422
- if (!msg.proof) {
423
- return false;
424
- }
129
+ this.sseHeartbeatTimer = setInterval(() => {
130
+ for (const accountAddress of this.sseLockedAccounts) {
131
+ this.persistStorage.updateSSELockHeartbeat(accountAddress, this.instanceId);
132
+ }
133
+ }, 5000);
134
+ }
135
+ stopSSEHeartbeat() {
136
+ if (this.sseHeartbeatTimer) {
137
+ clearInterval(this.sseHeartbeatTimer);
138
+ this.sseHeartbeatTimer = null;
425
139
  }
426
- if (filter.arkTimestampStart !== void 0) {
427
- if (msg.arkConfirmed === void 0 || msg.arkConfirmed.timestamp < filter.arkTimestampStart) {
428
- return false;
429
- }
140
+ }
141
+ async add_account_internal(address) {
142
+ const addressLower = address.toLowerCase();
143
+ if (this.accounts.size >= MAX_ACCOUNTS) {
144
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Maximum ${MAX_ACCOUNTS} accounts allowed`);
430
145
  }
431
- if (filter.arkTimestampEnd !== void 0) {
432
- if (msg.arkConfirmed === void 0 || msg.arkConfirmed.timestamp > filter.arkTimestampEnd) {
433
- return false;
434
- }
146
+ const messenger = new Messenger(addressLower, this.config);
147
+ try {
148
+ await messenger.initialize();
435
149
  }
436
- if (filter.hasLastReceivedIndexOnly) {
437
- if (msg.lastReceivedLeafIndex === void 0 || msg.lastReceivedLeafIndex === null) {
438
- return false;
439
- }
150
+ catch (error) {
151
+ throw new MessengerError(MessengerErrorCode.SERVER_ERROR, `Failed to initialize account ${addressLower}: ${error instanceof Error ? error.message : String(error)}`);
440
152
  }
441
- if (filter.lastReceivedIndexMin !== void 0) {
442
- if (msg.lastReceivedLeafIndex === void 0 || msg.lastReceivedLeafIndex < filter.lastReceivedIndexMin) {
443
- return false;
444
- }
153
+ const contactLists = {
154
+ friends: [],
155
+ guards: [],
156
+ lastUpdatedAt: 0,
157
+ };
158
+ this.accounts.set(addressLower, {
159
+ address: addressLower,
160
+ messenger,
161
+ initialized: true,
162
+ contactLists,
163
+ });
164
+ if (this.isWatching) {
165
+ this.startAccountPolling(addressLower);
445
166
  }
446
- if (filter.lastReceivedIndexMax !== void 0) {
447
- if (msg.lastReceivedLeafIndex === void 0 || msg.lastReceivedLeafIndex > filter.lastReceivedIndexMax) {
167
+ }
168
+ remove_account_internal(address) {
169
+ const addressLower = address.toLowerCase();
170
+ const account = this.accounts.get(addressLower);
171
+ if (!account)
448
172
  return false;
449
- }
173
+ if (account.initialized && account.messenger) {
174
+ account.messenger.disconnectEventSource();
175
+ account.messenger.disconnect();
176
+ }
177
+ const timer = this.pollingTimers.get(account.address);
178
+ if (timer) {
179
+ clearInterval(timer);
180
+ this.pollingTimers.delete(account.address);
181
+ }
182
+ this.persistStorage.releaseSSELock(addressLower, this.instanceId);
183
+ this.sseLockedAccounts.delete(addressLower);
184
+ return this.accounts.delete(addressLower);
185
+ }
186
+ clear_accounts() {
187
+ this.stopPolling();
188
+ for (const info of this.accounts.values()) {
189
+ info.messenger.disconnectEventSource();
190
+ info.messenger.disconnect();
191
+ }
192
+ this.accounts.clear();
193
+ }
194
+ async send(from, to, content, options) {
195
+ const { Account } = await import("../local/account.js");
196
+ let accountInfo = this.findAccount(from);
197
+ if (!accountInfo) {
198
+ const account = await Account.Instance().get(from, false);
199
+ if (!account) {
200
+ throw new MessengerError(MessengerErrorCode.IDENTITY_NOT_FOUND, `Account ${from} not found`);
201
+ }
202
+ if (account.m == null) {
203
+ if (options?.new_messenger_name == null) {
204
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_MESSENGER_NOT_ENABLED, `Account messenger name not set. Use new_messenger_name parameter to set it automatically.`);
205
+ }
206
+ await Account.Instance().set_messenger(from, options.new_messenger_name);
207
+ }
208
+ await this.refresh_accounts();
209
+ accountInfo = this.findAccount(from);
210
+ if (!accountInfo) {
211
+ throw new MessengerError(MessengerErrorCode.SERVER_ERROR, `Failed to add account ${from} to messenger manager`);
212
+ }
450
213
  }
451
- if (filter.keyword && msg.plaintext) {
452
- if (!msg.plaintext.toLowerCase().includes(filter.keyword.toLowerCase())) {
453
- return false;
454
- }
214
+ if (options?.new_messenger_name != null) {
215
+ const account = await Account.Instance().get(from, false);
216
+ if (account && account.m !== options.new_messenger_name) {
217
+ await Account.Instance().set_messenger(from, options.new_messenger_name);
218
+ }
455
219
  }
456
- if (filter.listFilterMode && filter.listFilterMode !== "any") {
457
- const msgAccount = this.findAccount(msg.toAddress);
458
- if (!msgAccount) return false;
459
- const senderAddress = msg.fromAddress.toLowerCase();
460
- const lists = msgAccount.contactLists;
461
- const friends = new Set(
462
- lists.friends.map((a) => a.toLowerCase())
463
- );
464
- const guards = new Set(
465
- lists.guards.map((g) => g.guardAddress.toLowerCase())
466
- );
467
- const inFriends = friends.has(senderAddress);
468
- const inGuards = guards.has(senderAddress);
469
- const isStranger = !inFriends && !inGuards;
470
- switch (filter.listFilterMode) {
471
- case "friends":
472
- if (!inFriends) return false;
473
- break;
474
- case "guard":
475
- if (!inGuards) return false;
476
- break;
477
- case "stranger":
478
- if (!isStranger) return false;
479
- break;
480
- }
481
- if (filter.customListFilter) {
482
- const {
483
- includeAddresses,
484
- excludeAddresses,
485
- relation = "union"
486
- } = filter.customListFilter;
487
- if (excludeAddresses) {
488
- const excludeSet = new Set(
489
- excludeAddresses.map((a) => a.toLowerCase())
490
- );
491
- if (excludeSet.has(senderAddress)) return false;
220
+ return accountInfo.messenger.sendMessage(to, content, {
221
+ guardAddress: options?.guardAddress,
222
+ passportAddress: options?.passportAddress,
223
+ force: options?.force,
224
+ });
225
+ }
226
+ async send_file(from, to, filePath, options) {
227
+ const { Account } = await import("../local/account.js");
228
+ let accountInfo = this.findAccount(from);
229
+ if (!accountInfo) {
230
+ const account = await Account.Instance().get(from, false);
231
+ if (!account) {
232
+ throw new MessengerError(MessengerErrorCode.IDENTITY_NOT_FOUND, `Account ${from} not found`);
233
+ }
234
+ if (account.m == null) {
235
+ if (options?.new_messenger_name == null) {
236
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_MESSENGER_NOT_ENABLED, `Account messenger name not set. Use new_messenger_name parameter to set it automatically.`);
237
+ }
238
+ await Account.Instance().set_messenger(from, options.new_messenger_name);
492
239
  }
493
- if (includeAddresses && includeAddresses.length > 0) {
494
- const includeSet = new Set(
495
- includeAddresses.map((a) => a.toLowerCase())
496
- );
497
- const inIncludeList = includeSet.has(senderAddress);
498
- if (relation === "union") {
499
- const modeMatch = filter.listFilterMode === "friends" && inFriends || filter.listFilterMode === "guard" && inGuards || filter.listFilterMode === "stranger" && isStranger;
500
- if (!inIncludeList && !modeMatch) return false;
501
- } else {
502
- if (!inIncludeList) return false;
503
- }
240
+ await this.refresh_accounts();
241
+ accountInfo = this.findAccount(from);
242
+ if (!accountInfo) {
243
+ throw new MessengerError(MessengerErrorCode.SERVER_ERROR, `Failed to add account ${from} to messenger manager`);
504
244
  }
505
- }
506
245
  }
507
- return true;
508
- });
509
- }
510
- const sortOrder = filter?.sortOrder ?? "desc";
511
- const sortField = filter?.timeField || "createdAt";
512
- messages.sort((a, b) => {
513
- const aTime = a[sortField] || 0;
514
- const bTime = b[sortField] || 0;
515
- return sortOrder === "asc" ? aTime - bTime : bTime - aTime;
516
- });
517
- const { MAX_QUERY_LIMIT } = await import("./types.js");
518
- const defaultLimit = this.config.defaultQueryLimit ?? 50;
519
- const limit = Math.min(filter?.limit ?? defaultLimit, MAX_QUERY_LIMIT);
520
- const offset = filter?.offset ?? 0;
521
- messages = messages.slice(offset, offset + limit);
522
- return messages;
523
- }
524
- startPolling() {
525
- if (this.isWatching) return;
526
- this.isWatching = true;
527
- for (const info of this.accounts.values()) {
528
- const timer = setInterval(async () => {
529
- try {
530
- const messages = await info.messenger.pullMessages();
531
- if (messages.length > 0) {
532
- for (const listener of this.messageListeners) {
533
- listener(messages);
246
+ if (options?.new_messenger_name != null) {
247
+ const account = await Account.Instance().get(from, false);
248
+ if (account && account.m !== options.new_messenger_name) {
249
+ await Account.Instance().set_messenger(from, options.new_messenger_name);
534
250
  }
535
- }
536
- } catch (error) {
537
- console.error(
538
- `Failed to poll messages for ${info.address}:`,
539
- error
540
- );
541
251
  }
542
- }, this.config.watch_interval_ms);
543
- this.pollingTimers.set(info.address, timer);
544
- }
545
- }
546
- startAccountPolling(address) {
547
- const info = this.accounts.get(address.toLowerCase());
548
- if (!info || !info.initialized) return;
549
- const existingTimer = this.pollingTimers.get(info.address);
550
- if (existingTimer) {
551
- clearInterval(existingTimer);
252
+ return accountInfo.messenger.sendZipFile(to, filePath, {
253
+ fileName: options?.fileName,
254
+ contentType: options?.contentType,
255
+ guardAddress: options?.guardAddress,
256
+ passportAddress: options?.passportAddress,
257
+ force: options?.force,
258
+ });
552
259
  }
553
- const timer = setInterval(async () => {
554
- try {
555
- const messages = await info.messenger.pullMessages();
556
- if (messages.length > 0) {
557
- for (const listener of this.messageListeners) {
558
- listener(messages);
559
- }
260
+ async watch(filter) {
261
+ let messages = [];
262
+ if (filter?.account) {
263
+ const address = filter.account.toLowerCase();
264
+ const messageStorage = new MessageStorage(address);
265
+ messages = messageStorage.getAllMessages(address);
266
+ }
267
+ else {
268
+ for (const account of this.accounts.values()) {
269
+ const messageStorage = new MessageStorage(account.address);
270
+ const accountMessages = messageStorage.getAllMessages(account.address);
271
+ messages.push(...accountMessages);
272
+ }
560
273
  }
561
- } catch (error) {
562
- console.error(
563
- `Failed to poll messages for ${info.address}:`,
564
- error
565
- );
566
- }
567
- }, this.config.watch_interval_ms);
568
- this.pollingTimers.set(info.address, timer);
569
- }
570
- stopPolling() {
571
- for (const timer of this.pollingTimers.values()) {
572
- clearInterval(timer);
274
+ if (filter) {
275
+ const peerAddress = filter.peerAddress
276
+ ? await GetAccountOrMark_Address(filter.peerAddress)
277
+ : undefined;
278
+ messages = messages.filter((msg) => {
279
+ if (filter.account) {
280
+ const accountLower = filter.account.toLowerCase();
281
+ const fromLower = msg.fromAddress.toLowerCase();
282
+ const toLower = msg.toAddress.toLowerCase();
283
+ if (fromLower !== accountLower &&
284
+ toLower !== accountLower) {
285
+ return false;
286
+ }
287
+ }
288
+ if (filter.direction && msg.direction !== filter.direction) {
289
+ return false;
290
+ }
291
+ if (filter.status && msg.status !== filter.status) {
292
+ return false;
293
+ }
294
+ if (filter.msgType !== undefined &&
295
+ msg.msgType !== filter.msgType) {
296
+ return false;
297
+ }
298
+ if (filter.contentType) {
299
+ switch (filter.contentType) {
300
+ case "text":
301
+ if (msg.msgType !== MessageType.NORMAL_MESSAGE)
302
+ return false;
303
+ break;
304
+ case "zip":
305
+ if (!msg.zipMetadata)
306
+ return false;
307
+ break;
308
+ case "wts":
309
+ if (!msg.zipMetadata ||
310
+ msg.zipMetadata?.contentType !== "wts") {
311
+ return false;
312
+ }
313
+ break;
314
+ case "wip":
315
+ if (!msg.zipMetadata ||
316
+ msg.zipMetadata?.contentType !== "wip") {
317
+ return false;
318
+ }
319
+ break;
320
+ }
321
+ }
322
+ if (filter.peerAddress && peerAddress) {
323
+ const peer = peerAddress.toLowerCase();
324
+ const from = msg.fromAddress.toLowerCase();
325
+ const to = msg.toAddress.toLowerCase();
326
+ if (from !== peer && to !== peer) {
327
+ return false;
328
+ }
329
+ }
330
+ const timeField = filter.timeField || "createdAt";
331
+ if (filter.startTime !== undefined ||
332
+ filter.endTime !== undefined) {
333
+ const msgTime = msg[timeField];
334
+ if (msgTime !== undefined) {
335
+ if (filter.startTime !== undefined &&
336
+ msgTime < filter.startTime) {
337
+ return false;
338
+ }
339
+ if (filter.endTime !== undefined &&
340
+ msgTime > filter.endTime) {
341
+ return false;
342
+ }
343
+ }
344
+ }
345
+ if (filter.createdAtStart !== undefined &&
346
+ msg.createdAt < filter.createdAtStart) {
347
+ return false;
348
+ }
349
+ if (filter.createdAtEnd !== undefined &&
350
+ msg.createdAt > filter.createdAtEnd) {
351
+ return false;
352
+ }
353
+ if (filter.receivedAtStart !== undefined) {
354
+ if (msg.receivedAt === undefined ||
355
+ msg.receivedAt < filter.receivedAtStart) {
356
+ return false;
357
+ }
358
+ }
359
+ if (filter.receivedAtEnd !== undefined) {
360
+ if (msg.receivedAt === undefined ||
361
+ msg.receivedAt > filter.receivedAtEnd) {
362
+ return false;
363
+ }
364
+ }
365
+ if (filter.serverTimestampStart !== undefined) {
366
+ if (msg.serverTimestamp === undefined ||
367
+ msg.serverTimestamp < filter.serverTimestampStart) {
368
+ return false;
369
+ }
370
+ }
371
+ if (filter.serverTimestampEnd !== undefined) {
372
+ if (msg.serverTimestamp === undefined ||
373
+ msg.serverTimestamp > filter.serverTimestampEnd) {
374
+ return false;
375
+ }
376
+ }
377
+ if (filter.decryptedOnly && !msg.plaintext) {
378
+ return false;
379
+ }
380
+ if (filter.arkConfirmedOnly) {
381
+ if (!msg.arkConfirmed) {
382
+ return false;
383
+ }
384
+ }
385
+ if (filter.proofedOnly) {
386
+ if (!msg.proof) {
387
+ return false;
388
+ }
389
+ }
390
+ if (filter.arkTimestampStart !== undefined) {
391
+ if (msg.arkConfirmed === undefined ||
392
+ msg.arkConfirmed.timestamp < filter.arkTimestampStart) {
393
+ return false;
394
+ }
395
+ }
396
+ if (filter.arkTimestampEnd !== undefined) {
397
+ if (msg.arkConfirmed === undefined ||
398
+ msg.arkConfirmed.timestamp > filter.arkTimestampEnd) {
399
+ return false;
400
+ }
401
+ }
402
+ if (filter.hasLastReceivedIndexOnly) {
403
+ if (msg.lastReceivedLeafIndex === undefined ||
404
+ msg.lastReceivedLeafIndex === null) {
405
+ return false;
406
+ }
407
+ }
408
+ if (filter.lastReceivedIndexMin !== undefined) {
409
+ if (msg.lastReceivedLeafIndex === undefined ||
410
+ msg.lastReceivedLeafIndex < filter.lastReceivedIndexMin) {
411
+ return false;
412
+ }
413
+ }
414
+ if (filter.lastReceivedIndexMax !== undefined) {
415
+ if (msg.lastReceivedLeafIndex === undefined ||
416
+ msg.lastReceivedLeafIndex > filter.lastReceivedIndexMax) {
417
+ return false;
418
+ }
419
+ }
420
+ if (filter.keyword && msg.plaintext) {
421
+ if (!msg.plaintext
422
+ .toLowerCase()
423
+ .includes(filter.keyword.toLowerCase())) {
424
+ return false;
425
+ }
426
+ }
427
+ if (filter.listFilterMode && filter.listFilterMode !== "any") {
428
+ const msgAccount = this.findAccount(msg.toAddress);
429
+ if (!msgAccount)
430
+ return false;
431
+ const senderAddress = msg.fromAddress.toLowerCase();
432
+ const lists = msgAccount.contactLists;
433
+ const friends = new Set(lists.friends.map((a) => a.toLowerCase()));
434
+ const guards = new Set(lists.guards.map((g) => g.guardAddress.toLowerCase()));
435
+ const inFriends = friends.has(senderAddress);
436
+ const inGuards = guards.has(senderAddress);
437
+ const isStranger = !inFriends && !inGuards;
438
+ switch (filter.listFilterMode) {
439
+ case "friends":
440
+ if (!inFriends)
441
+ return false;
442
+ break;
443
+ case "guard":
444
+ if (!inGuards)
445
+ return false;
446
+ break;
447
+ case "stranger":
448
+ if (!isStranger)
449
+ return false;
450
+ break;
451
+ }
452
+ if (filter.customListFilter) {
453
+ const { includeAddresses, excludeAddresses, relation = "union", } = filter.customListFilter;
454
+ if (excludeAddresses) {
455
+ const excludeSet = new Set(excludeAddresses.map((a) => a.toLowerCase()));
456
+ if (excludeSet.has(senderAddress))
457
+ return false;
458
+ }
459
+ if (includeAddresses && includeAddresses.length > 0) {
460
+ const includeSet = new Set(includeAddresses.map((a) => a.toLowerCase()));
461
+ const inIncludeList = includeSet.has(senderAddress);
462
+ if (relation === "union") {
463
+ const modeMatch = (filter.listFilterMode === "friends" &&
464
+ inFriends) ||
465
+ (filter.listFilterMode === "guard" &&
466
+ inGuards) ||
467
+ (filter.listFilterMode === "stranger" &&
468
+ isStranger);
469
+ if (!inIncludeList && !modeMatch)
470
+ return false;
471
+ }
472
+ else {
473
+ if (!inIncludeList)
474
+ return false;
475
+ }
476
+ }
477
+ }
478
+ }
479
+ return true;
480
+ });
481
+ }
482
+ const sortOrder = filter?.sortOrder ?? "desc";
483
+ const sortField = filter?.timeField || "createdAt";
484
+ messages.sort((a, b) => {
485
+ const aTime = a[sortField] || 0;
486
+ const bTime = b[sortField] || 0;
487
+ return sortOrder === "asc" ? aTime - bTime : bTime - aTime;
488
+ });
489
+ const { MAX_QUERY_LIMIT } = await import("./types.js");
490
+ const defaultLimit = this.config.defaultQueryLimit ?? 50;
491
+ const limit = Math.min(filter?.limit ?? defaultLimit, MAX_QUERY_LIMIT);
492
+ const offset = filter?.offset ?? 0;
493
+ messages = messages.slice(offset, offset + limit);
494
+ return messages;
495
+ }
496
+ startPolling() {
497
+ if (this.isWatching)
498
+ return;
499
+ this.isWatching = true;
500
+ for (const info of this.accounts.values()) {
501
+ const timer = setInterval(async () => {
502
+ try {
503
+ const messages = await info.messenger.pullMessages();
504
+ if (messages.length > 0) {
505
+ for (const listener of this.messageListeners) {
506
+ listener(messages);
507
+ }
508
+ }
509
+ }
510
+ catch (error) {
511
+ console.error(`Failed to poll messages for ${info.address}:`, error);
512
+ }
513
+ }, this.config.watch_interval_ms);
514
+ this.pollingTimers.set(info.address, timer);
515
+ }
516
+ }
517
+ startAccountPolling(address) {
518
+ const info = this.accounts.get(address.toLowerCase());
519
+ if (!info || !info.initialized)
520
+ return;
521
+ const existingTimer = this.pollingTimers.get(info.address);
522
+ if (existingTimer) {
523
+ clearInterval(existingTimer);
524
+ }
525
+ const timer = setInterval(async () => {
526
+ try {
527
+ const messages = await info.messenger.pullMessages();
528
+ if (messages.length > 0) {
529
+ for (const listener of this.messageListeners) {
530
+ listener(messages);
531
+ }
532
+ }
533
+ }
534
+ catch (error) {
535
+ console.error(`Failed to poll messages for ${info.address}:`, error);
536
+ }
537
+ }, this.config.watch_interval_ms);
538
+ this.pollingTimers.set(info.address, timer);
573
539
  }
574
- this.pollingTimers.clear();
575
- this.isWatching = false;
576
- }
577
- onMessage(listener) {
578
- this.messageListeners.add(listener);
579
- }
580
- offMessage(listener) {
581
- this.messageListeners.delete(listener);
582
- }
583
- destroy() {
584
- this.stop();
585
- this.messageListeners.clear();
586
- }
587
- async syncContactLists(account) {
588
- const acc = this.findAccount(account);
589
- if (!acc) {
590
- return {
591
- success: false,
592
- friends: [],
593
- guards: [],
594
- error: `Account not found: ${account}`
595
- };
540
+ stopPolling() {
541
+ for (const timer of this.pollingTimers.values()) {
542
+ clearInterval(timer);
543
+ }
544
+ this.pollingTimers.clear();
545
+ this.isWatching = false;
596
546
  }
597
- try {
598
- const { Account } = await import("../local/account.js");
599
- const accountData = await Account.Instance().get(account, false);
600
- if (!accountData?.address) {
601
- return {
602
- success: false,
603
- friends: [],
604
- guards: [],
605
- error: `Account data not found: ${account}`
606
- };
607
- }
608
- const address = accountData.address;
609
- const [friends, guards] = await Promise.all([
610
- this.fetchFriendsList(address),
611
- this.fetchGuardList(address)
612
- ]);
613
- acc.contactLists = {
614
- friends,
615
- guards,
616
- lastUpdatedAt: Date.now()
617
- };
618
- return {
619
- success: true,
620
- friends,
621
- guards
622
- };
623
- } catch (error) {
624
- console.error(
625
- `Failed to sync contact lists for ${account}:`,
626
- error
627
- );
628
- return {
629
- success: false,
630
- friends: acc.contactLists.friends,
631
- guards: acc.contactLists.guards,
632
- error: error instanceof Error ? error.message : String(error)
633
- };
547
+ onMessage(listener) {
548
+ this.messageListeners.add(listener);
634
549
  }
635
- }
636
- async syncAllContactLists() {
637
- const results = /* @__PURE__ */ new Map();
638
- for (const acc of this.accounts.values()) {
639
- const result = await this.syncContactLists(acc.address);
640
- results.set(acc.address, result);
550
+ offMessage(listener) {
551
+ this.messageListeners.delete(listener);
641
552
  }
642
- return results;
643
- }
644
- getContactLists(account) {
645
- const acc = this.findAccount(account);
646
- return acc?.contactLists;
647
- }
648
- setContactLists(account, lists) {
649
- const acc = this.findAccount(account);
650
- if (!acc) return false;
651
- acc.contactLists = {
652
- ...acc.contactLists,
653
- ...lists,
654
- lastUpdatedAt: Date.now()
655
- };
656
- return true;
657
- }
658
- isStranger(account, senderAddress) {
659
- const acc = this.findAccount(account);
660
- if (!acc) return true;
661
- const sender = senderAddress.toLowerCase();
662
- const lists = acc.contactLists;
663
- const inFriends = lists.friends.some((a) => a.toLowerCase() === sender);
664
- const inGuards = lists.guards.some(
665
- (g) => g.guardAddress.toLowerCase() === sender
666
- );
667
- return !inFriends && !inGuards;
668
- }
669
- recordGuardSender(account, guardAddress) {
670
- const acc = this.findAccount(account);
671
- if (!acc) return false;
672
- const guardAddr = guardAddress.toLowerCase();
673
- const exists = acc.contactLists.guards.some(
674
- (g) => g.guardAddress.toLowerCase() === guardAddr
675
- );
676
- if (!exists) {
677
- acc.contactLists.guards.push({
678
- guardAddress,
679
- passportValiditySeconds: 86400
680
- });
681
- acc.contactLists.lastUpdatedAt = Date.now();
553
+ destroy() {
554
+ this.stop();
555
+ this.messageListeners.clear();
682
556
  }
683
- return true;
684
- }
685
- async fetchFriendsList(address) {
686
- try {
687
- const response = await fetch(
688
- `${this.config.serverUrl}/v1/spam-protection/${address}/friends-list`,
689
- {
690
- method: "POST",
691
- headers: { "Content-Type": "application/json" },
692
- body: JSON.stringify({
693
- userAddress: address,
694
- signature: "",
695
- timestamp: Date.now(),
696
- nonce: this.generateNonce()
697
- })
557
+ async syncContactLists(account) {
558
+ const acc = this.findAccount(account);
559
+ if (!acc) {
560
+ return {
561
+ success: false,
562
+ friends: [],
563
+ guards: [],
564
+ error: `Account not found: ${account}`,
565
+ };
698
566
  }
699
- );
700
- if (!response.ok) {
701
- throw new Error(`HTTP ${response.status}`);
702
- }
703
- return await response.json();
704
- } catch (error) {
705
- return [];
567
+ try {
568
+ const { Account } = await import("../local/account.js");
569
+ const accountData = await Account.Instance().get(account, false);
570
+ if (!accountData?.address) {
571
+ return {
572
+ success: false,
573
+ friends: [],
574
+ guards: [],
575
+ error: `Account data not found: ${account}`,
576
+ };
577
+ }
578
+ const address = accountData.address;
579
+ const [friends, guards] = await Promise.all([
580
+ this.fetchFriendsList(address),
581
+ this.fetchGuardList(address),
582
+ ]);
583
+ acc.contactLists = {
584
+ friends,
585
+ guards,
586
+ lastUpdatedAt: Date.now(),
587
+ };
588
+ return {
589
+ success: true,
590
+ friends,
591
+ guards,
592
+ };
593
+ }
594
+ catch (error) {
595
+ console.error(`Failed to sync contact lists for ${account}:`, error);
596
+ return {
597
+ success: false,
598
+ friends: acc.contactLists.friends,
599
+ guards: acc.contactLists.guards,
600
+ error: error instanceof Error ? error.message : String(error),
601
+ };
602
+ }
603
+ }
604
+ async syncAllContactLists() {
605
+ const results = new Map();
606
+ for (const acc of this.accounts.values()) {
607
+ const result = await this.syncContactLists(acc.address);
608
+ results.set(acc.address, result);
609
+ }
610
+ return results;
611
+ }
612
+ getContactLists(account) {
613
+ const acc = this.findAccount(account);
614
+ return acc?.contactLists;
615
+ }
616
+ setContactLists(account, lists) {
617
+ const acc = this.findAccount(account);
618
+ if (!acc)
619
+ return false;
620
+ acc.contactLists = {
621
+ ...acc.contactLists,
622
+ ...lists,
623
+ lastUpdatedAt: Date.now(),
624
+ };
625
+ return true;
706
626
  }
707
- }
708
- async fetchGuardList(address) {
709
- try {
710
- const response = await fetch(
711
- `${this.config.serverUrl}/v1/spam-protection/${address}/guard-list`,
712
- {
713
- method: "POST",
714
- headers: { "Content-Type": "application/json" },
715
- body: JSON.stringify({
716
- userAddress: address,
717
- signature: "",
718
- timestamp: Date.now(),
719
- nonce: this.generateNonce()
720
- })
627
+ isStranger(account, senderAddress) {
628
+ const acc = this.findAccount(account);
629
+ if (!acc)
630
+ return true;
631
+ const sender = senderAddress.toLowerCase();
632
+ const lists = acc.contactLists;
633
+ const inFriends = lists.friends.some((a) => a.toLowerCase() === sender);
634
+ const inGuards = lists.guards.some((g) => g.guardAddress.toLowerCase() === sender);
635
+ return !inFriends && !inGuards;
636
+ }
637
+ recordGuardSender(account, guardAddress) {
638
+ const acc = this.findAccount(account);
639
+ if (!acc)
640
+ return false;
641
+ const guardAddr = guardAddress.toLowerCase();
642
+ const exists = acc.contactLists.guards.some((g) => g.guardAddress.toLowerCase() === guardAddr);
643
+ if (!exists) {
644
+ acc.contactLists.guards.push({
645
+ guardAddress: guardAddress,
646
+ passportValiditySeconds: 86400,
647
+ });
648
+ acc.contactLists.lastUpdatedAt = Date.now();
721
649
  }
722
- );
723
- if (!response.ok) {
724
- throw new Error(`HTTP ${response.status}`);
725
- }
726
- return await response.json();
727
- } catch (error) {
728
- return [];
729
- }
730
- }
731
- generateNonce() {
732
- return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
733
- }
734
- async watch_paginated(filter) {
735
- const { MAX_QUERY_LIMIT } = await import("./types.js");
736
- const allMessages = await this.watch(filter);
737
- const total = allMessages.length;
738
- const defaultLimit = this.config.defaultQueryLimit ?? 50;
739
- const limit = Math.min(filter?.limit ?? defaultLimit, MAX_QUERY_LIMIT);
740
- const offset = filter?.offset ?? 0;
741
- const messages = allMessages.slice(offset, offset + limit);
742
- return {
743
- messages,
744
- total,
745
- offset,
746
- limit
747
- };
748
- }
749
- async get_conversations(account) {
750
- const filter = account ? { account } : void 0;
751
- const allMessages = await this.watch(filter);
752
- const conversations = /* @__PURE__ */ new Map();
753
- for (const msg of allMessages) {
754
- const myAddress = account?.toLowerCase();
755
- const peerAddress = msg.fromAddress.toLowerCase() === myAddress ? msg.toAddress : msg.fromAddress;
756
- if (!conversations.has(peerAddress)) {
757
- conversations.set(peerAddress, {
758
- peerAddress,
759
- lastMessageAt: msg.createdAt,
760
- messageCount: 0,
761
- unreadCount: 0,
762
- lastMessagePreview: msg.plaintext
763
- });
764
- }
765
- const conv = conversations.get(peerAddress);
766
- conv.messageCount++;
767
- if (msg.createdAt > conv.lastMessageAt) {
768
- conv.lastMessageAt = msg.createdAt;
769
- conv.lastMessagePreview = msg.plaintext;
770
- }
771
- if (msg.status !== MessageStatus.READ && msg.toAddress.toLowerCase() === myAddress) {
772
- conv.unreadCount++;
773
- }
774
- }
775
- return Array.from(conversations.values()).sort(
776
- (a, b) => b.lastMessageAt - a.lastMessageAt
777
- );
778
- }
779
- async generate_wts(params) {
780
- const fs = await import("fs");
781
- const path = await import("path");
782
- const myAddress = params.myAccount.toLowerCase();
783
- const peerAddress = params.peerAccount.toLowerCase();
784
- const messageStorage = new MessageStorage(myAddress);
785
- const myMessages = messageStorage.getAllMessages(myAddress);
786
- let messages = myMessages.filter((msg) => {
787
- const fromLower = msg.fromAddress.toLowerCase();
788
- const toLower = msg.toAddress.toLowerCase();
789
- const isBetween = fromLower === myAddress && toLower === peerAddress || fromLower === peerAddress && toLower === myAddress;
790
- return isBetween;
791
- });
792
- messages = messages.filter(
793
- (m) => m.leafIndex !== void 0 && m.serverTimestamp !== void 0
794
- ).reduce((acc, msg) => {
795
- const existing = acc.find((m) => m.messageId === msg.messageId);
796
- if (!existing) {
797
- acc.push(msg);
798
- }
799
- return acc;
800
- }, []).sort((a, b) => {
801
- return a.leafIndex - b.leafIndex;
802
- });
803
- const leafIndexMap = /* @__PURE__ */ new Map();
804
- for (const msg of messages) {
805
- const idx = msg.leafIndex;
806
- if (!leafIndexMap.has(idx)) {
807
- leafIndexMap.set(idx, []);
808
- }
809
- leafIndexMap.get(idx).push(msg);
650
+ return true;
810
651
  }
811
- const duplicates = Array.from(leafIndexMap.entries()).filter(
812
- ([, msgs]) => msgs.length > 1
813
- );
814
- if (duplicates.length > 0) {
815
- messages.sort(
816
- (a, b) => (b.serverTimestamp || 0) - (a.serverTimestamp || 0)
817
- );
818
- const seenLeafIndices = /* @__PURE__ */ new Set();
819
- const uniqueMessages = [];
820
- for (const msg of messages) {
821
- const idx = msg.leafIndex;
822
- if (!seenLeafIndices.has(idx)) {
823
- seenLeafIndices.add(idx);
824
- uniqueMessages.push(msg);
652
+ async fetchFriendsList(address) {
653
+ try {
654
+ const response = await fetch(`${this.config.serverUrl}/v1/spam-protection/${address}/friends-list`, {
655
+ method: "POST",
656
+ headers: { "Content-Type": "application/json" },
657
+ body: JSON.stringify({
658
+ userAddress: address,
659
+ signature: "",
660
+ timestamp: Date.now(),
661
+ nonce: this.generateNonce(),
662
+ }),
663
+ });
664
+ if (!response.ok) {
665
+ throw new Error(`HTTP ${response.status}`);
666
+ }
667
+ return (await response.json());
825
668
  }
826
- }
827
- messages = uniqueMessages.sort(
828
- (a, b) => a.leafIndex - b.leafIndex
829
- );
830
- }
831
- if (params.range) {
832
- switch (params.range.type) {
833
- case "time": {
834
- const start = Math.min(
835
- params.range.start,
836
- params.range.end
837
- );
838
- const end = Math.max(params.range.start, params.range.end);
839
- messages = messages.filter(
840
- (m) => m.createdAt >= start && m.createdAt <= end
841
- );
842
- break;
669
+ catch (error) {
670
+ return [];
843
671
  }
844
- case "messageId": {
845
- const start = params.range.start;
846
- const end = params.range.end;
847
- messages = messages.filter(
848
- (m) => m.messageId >= start && m.messageId <= end
849
- );
850
- break;
672
+ }
673
+ async fetchGuardList(address) {
674
+ try {
675
+ const response = await fetch(`${this.config.serverUrl}/v1/spam-protection/${address}/guard-list`, {
676
+ method: "POST",
677
+ headers: { "Content-Type": "application/json" },
678
+ body: JSON.stringify({
679
+ userAddress: address,
680
+ signature: "",
681
+ timestamp: Date.now(),
682
+ nonce: this.generateNonce(),
683
+ }),
684
+ });
685
+ if (!response.ok) {
686
+ throw new Error(`HTTP ${response.status}`);
687
+ }
688
+ return (await response.json());
851
689
  }
852
- case "seqIndex": {
853
- const start = Math.min(
854
- params.range.start,
855
- params.range.end
856
- );
857
- const end = Math.max(params.range.start, params.range.end);
858
- messages = messages.filter(
859
- (m) => m.leafIndex >= start && m.leafIndex <= end
860
- );
861
- break;
690
+ catch (error) {
691
+ return [];
862
692
  }
863
- }
864
- }
865
- if (messages.length === 0) {
866
- throw new MessengerError(
867
- MessengerErrorCode.INVALID_INPUT,
868
- "No messages found for the given criteria"
869
- );
870
693
  }
871
- if (messages.length > WTS_MAX_MESSAGE_COUNT) {
872
- throw new MessengerError(
873
- MessengerErrorCode.INVALID_INPUT,
874
- `Message count (${messages.length}) exceeds maximum allowed (${WTS_MAX_MESSAGE_COUNT})`
875
- );
694
+ generateNonce() {
695
+ return (Math.random().toString(36).substring(2, 15) +
696
+ Math.random().toString(36).substring(2, 15));
876
697
  }
877
- if (!fs.existsSync(params.outputDir)) {
878
- fs.mkdirSync(params.outputDir, { recursive: true });
698
+ async watch_paginated(filter) {
699
+ const { MAX_QUERY_LIMIT } = await import("./types.js");
700
+ const allMessages = await this.watch(filter);
701
+ const total = allMessages.length;
702
+ const defaultLimit = this.config.defaultQueryLimit ?? 50;
703
+ const limit = Math.min(filter?.limit ?? defaultLimit, MAX_QUERY_LIMIT);
704
+ const offset = filter?.offset ?? 0;
705
+ const messages = allMessages.slice(offset, offset + limit);
706
+ return {
707
+ messages,
708
+ total,
709
+ offset,
710
+ limit,
711
+ };
879
712
  }
880
- const sessionId = `${myAddress.slice(0, 6)}_${peerAddress.slice(0, 6)}`;
881
- const groups = [messages];
882
- const generatedFiles = [];
883
- const startTime = messages[0].createdAt;
884
- const endTime = messages[messages.length - 1].createdAt;
885
- for (const group of groups) {
886
- const leafIndices = group.map((m) => m.leafIndex).filter((i) => i !== void 0);
887
- const startLeafIndex = Math.min(...leafIndices);
888
- const endLeafIndex = Math.max(...leafIndices);
889
- for (const msg of group) {
890
- if (msg.serverTimestamp === void 0) {
891
- throw new MessengerError(
892
- MessengerErrorCode.INVALID_INPUT,
893
- `Message ${msg.messageId} missing serverTimestamp`
894
- );
895
- }
896
- if (msg.leafIndex === void 0) {
897
- throw new MessengerError(
898
- MessengerErrorCode.INVALID_INPUT,
899
- `Message ${msg.messageId} missing leafIndex`
900
- );
901
- }
902
- if (!msg.prevRoot) {
903
- throw new MessengerError(
904
- MessengerErrorCode.INVALID_INPUT,
905
- `Message ${msg.messageId} missing prevRoot`
906
- );
713
+ async get_conversations(account) {
714
+ const filter = account ? { account } : undefined;
715
+ const allMessages = await this.watch(filter);
716
+ const conversations = new Map();
717
+ for (const msg of allMessages) {
718
+ const myAddress = account?.toLowerCase();
719
+ const peerAddress = msg.fromAddress.toLowerCase() === myAddress
720
+ ? msg.toAddress
721
+ : msg.fromAddress;
722
+ if (!conversations.has(peerAddress)) {
723
+ conversations.set(peerAddress, {
724
+ peerAddress,
725
+ lastMessageAt: msg.createdAt,
726
+ messageCount: 0,
727
+ unreadCount: 0,
728
+ lastMessagePreview: msg.plaintext,
729
+ });
730
+ }
731
+ const conv = conversations.get(peerAddress);
732
+ conv.messageCount++;
733
+ if (msg.createdAt > conv.lastMessageAt) {
734
+ conv.lastMessageAt = msg.createdAt;
735
+ conv.lastMessagePreview = msg.plaintext;
736
+ }
737
+ if (msg.status !== MessageStatus.READ &&
738
+ msg.toAddress.toLowerCase() === myAddress) {
739
+ conv.unreadCount++;
740
+ }
907
741
  }
908
- if (!msg.newRoot) {
909
- throw new MessengerError(
910
- MessengerErrorCode.INVALID_INPUT,
911
- `Message ${msg.messageId} missing newRoot`
912
- );
742
+ return Array.from(conversations.values()).sort((a, b) => b.lastMessageAt - a.lastMessageAt);
743
+ }
744
+ async generate_wts(params) {
745
+ const fs = await import("fs");
746
+ const path = await import("path");
747
+ const myAddress = params.myAccount.toLowerCase();
748
+ const peerAddress = params.peerAccount.toLowerCase();
749
+ const messageStorage = new MessageStorage(myAddress);
750
+ const myMessages = messageStorage.getAllMessages(myAddress);
751
+ let messages = myMessages.filter((msg) => {
752
+ const fromLower = msg.fromAddress.toLowerCase();
753
+ const toLower = msg.toAddress.toLowerCase();
754
+ const isBetween = (fromLower === myAddress && toLower === peerAddress) ||
755
+ (fromLower === peerAddress && toLower === myAddress);
756
+ return isBetween;
757
+ });
758
+ messages = messages
759
+ .filter((m) => m.leafIndex !== undefined &&
760
+ m.serverTimestamp !== undefined)
761
+ .reduce((acc, msg) => {
762
+ const existing = acc.find((m) => m.messageId === msg.messageId);
763
+ if (!existing) {
764
+ acc.push(msg);
765
+ }
766
+ return acc;
767
+ }, [])
768
+ .sort((a, b) => {
769
+ return a.leafIndex - b.leafIndex;
770
+ });
771
+ const leafIndexMap = new Map();
772
+ for (const msg of messages) {
773
+ const idx = msg.leafIndex;
774
+ if (!leafIndexMap.has(idx)) {
775
+ leafIndexMap.set(idx, []);
776
+ }
777
+ leafIndexMap.get(idx).push(msg);
778
+ }
779
+ const duplicates = Array.from(leafIndexMap.entries()).filter(([, msgs]) => msgs.length > 1);
780
+ if (duplicates.length > 0) {
781
+ messages.sort((a, b) => (b.serverTimestamp || 0) - (a.serverTimestamp || 0));
782
+ const seenLeafIndices = new Set();
783
+ const uniqueMessages = [];
784
+ for (const msg of messages) {
785
+ const idx = msg.leafIndex;
786
+ if (!seenLeafIndices.has(idx)) {
787
+ seenLeafIndices.add(idx);
788
+ uniqueMessages.push(msg);
789
+ }
790
+ }
791
+ messages = uniqueMessages.sort((a, b) => a.leafIndex - b.leafIndex);
792
+ }
793
+ if (params.range) {
794
+ switch (params.range.type) {
795
+ case "time": {
796
+ const start = Math.min(params.range.start, params.range.end);
797
+ const end = Math.max(params.range.start, params.range.end);
798
+ messages = messages.filter((m) => m.createdAt >= start && m.createdAt <= end);
799
+ break;
800
+ }
801
+ case "messageId": {
802
+ const start = params.range.start;
803
+ const end = params.range.end;
804
+ messages = messages.filter((m) => m.messageId >= start && m.messageId <= end);
805
+ break;
806
+ }
807
+ case "seqIndex": {
808
+ const start = Math.min(params.range.start, params.range.end);
809
+ const end = Math.max(params.range.start, params.range.end);
810
+ messages = messages.filter((m) => m.leafIndex >= start && m.leafIndex <= end);
811
+ break;
812
+ }
813
+ }
913
814
  }
914
- if (!msg.serverSignature) {
915
- throw new MessengerError(
916
- MessengerErrorCode.INVALID_INPUT,
917
- `Message ${msg.messageId} missing serverSignature`
918
- );
815
+ if (messages.length === 0) {
816
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, "No messages found for the given criteria");
817
+ }
818
+ if (messages.length > WTS_MAX_MESSAGE_COUNT) {
819
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Message count (${messages.length}) exceeds maximum allowed (${WTS_MAX_MESSAGE_COUNT})`);
820
+ }
821
+ if (!fs.existsSync(params.outputDir)) {
822
+ fs.mkdirSync(params.outputDir, { recursive: true });
823
+ }
824
+ const sessionId = `${myAddress.slice(0, 6)}_${peerAddress.slice(0, 6)}`;
825
+ const groups = [messages];
826
+ const generatedFiles = [];
827
+ const startTime = messages[0].createdAt;
828
+ const endTime = messages[messages.length - 1].createdAt;
829
+ for (const group of groups) {
830
+ const leafIndices = group
831
+ .map((m) => m.leafIndex)
832
+ .filter((i) => i !== undefined);
833
+ const startLeafIndex = Math.min(...leafIndices);
834
+ const endLeafIndex = Math.max(...leafIndices);
835
+ for (const msg of group) {
836
+ if (msg.serverTimestamp === undefined) {
837
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Message ${msg.messageId} missing serverTimestamp`);
838
+ }
839
+ if (msg.leafIndex === undefined) {
840
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Message ${msg.messageId} missing leafIndex`);
841
+ }
842
+ if (!msg.prevRoot) {
843
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Message ${msg.messageId} missing prevRoot`);
844
+ }
845
+ if (!msg.newRoot) {
846
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Message ${msg.messageId} missing newRoot`);
847
+ }
848
+ if (!msg.serverSignature) {
849
+ throw new MessengerError(MessengerErrorCode.INVALID_INPUT, `Message ${msg.messageId} missing serverSignature`);
850
+ }
851
+ }
852
+ const wtsMessages = group.map((msg) => ({
853
+ id: msg.messageId,
854
+ from: msg.fromAddress,
855
+ to: msg.toAddress,
856
+ plaintext: params.excludePlaintext ? undefined : msg.plaintext,
857
+ plaintextHash: msg.plaintextHash,
858
+ clientTimestamp: msg.createdAt,
859
+ timestamp: msg.serverTimestamp,
860
+ leafIndex: msg.leafIndex,
861
+ prevRoot: msg.prevRoot,
862
+ merkleRoot: msg.newRoot,
863
+ serverSignature: msg.serverSignature,
864
+ serverPublicKey: msg.serverPublicKey || "",
865
+ guardAddress: msg.guardAddress,
866
+ passportAddress: msg.passportAddress,
867
+ lastReceivedLeafIndex: msg.lastReceivedLeafIndex,
868
+ arkConfirmed: msg.arkConfirmed
869
+ ? {
870
+ recipient: msg.arkConfirmed.recipient,
871
+ recipientPublicKey: msg.arkConfirmed.recipientPublicKey,
872
+ signature: msg.arkConfirmed.signature,
873
+ timestamp: msg.arkConfirmed.timestamp,
874
+ }
875
+ : undefined,
876
+ msgType: msg.msgType,
877
+ zipMetadata: msg.zipMetadata,
878
+ }));
879
+ const addresses = [myAddress, peerAddress].sort();
880
+ const wtsSession = {
881
+ id: `${addresses[0]}:${addresses[1]}`,
882
+ participants: addresses,
883
+ };
884
+ const payload = {
885
+ session: wtsSession,
886
+ messages: wtsMessages,
887
+ };
888
+ const wtsMeta = {
889
+ type: "wts",
890
+ version: "1.0",
891
+ created: new Date().toISOString(),
892
+ hash: "",
893
+ algorithm: "sha256",
894
+ startTime,
895
+ endTime,
896
+ messageCount: wtsMessages.length,
897
+ merkleRoot: wtsMessages[wtsMessages.length - 1].merkleRoot,
898
+ };
899
+ const wtsFile = {
900
+ wts: canonicalizeJson(wtsMeta),
901
+ payload,
902
+ meta: wtsMeta,
903
+ };
904
+ const fileName = `${sessionId}_${startLeafIndex}-${endLeafIndex}.wts`;
905
+ const filePath = path.join(params.outputDir, fileName);
906
+ fs.writeFileSync(filePath, JSON.stringify(wtsFile, null, 2));
907
+ generatedFiles.push(filePath);
919
908
  }
920
- }
921
- const wtsMessages = group.map((msg) => ({
922
- id: msg.messageId,
923
- from: msg.fromAddress,
924
- to: msg.toAddress,
925
- plaintext: params.excludePlaintext ? void 0 : msg.plaintext,
926
- plaintextHash: msg.plaintextHash,
927
- clientTimestamp: msg.createdAt,
928
- timestamp: msg.serverTimestamp,
929
- leafIndex: msg.leafIndex,
930
- prevRoot: msg.prevRoot,
931
- merkleRoot: msg.newRoot,
932
- serverSignature: msg.serverSignature,
933
- serverPublicKey: msg.serverPublicKey || "",
934
- guardAddress: msg.guardAddress,
935
- passportAddress: msg.passportAddress,
936
- lastReceivedLeafIndex: msg.lastReceivedLeafIndex,
937
- arkConfirmed: msg.arkConfirmed ? {
938
- recipient: msg.arkConfirmed.recipient,
939
- recipientPublicKey: msg.arkConfirmed.recipientPublicKey,
940
- signature: msg.arkConfirmed.signature,
941
- timestamp: msg.arkConfirmed.timestamp
942
- } : void 0,
943
- msgType: msg.msgType,
944
- zipMetadata: msg.zipMetadata
945
- }));
946
- const addresses = [myAddress, peerAddress].sort();
947
- const wtsSession = {
948
- id: `${addresses[0]}:${addresses[1]}`,
949
- participants: addresses
950
- };
951
- const payload = {
952
- session: wtsSession,
953
- messages: wtsMessages
954
- };
955
- const wtsMeta = {
956
- type: "wts",
957
- version: "1.0",
958
- created: (/* @__PURE__ */ new Date()).toISOString(),
959
- hash: "",
960
- algorithm: "sha256",
961
- startTime,
962
- endTime,
963
- messageCount: wtsMessages.length,
964
- merkleRoot: wtsMessages[wtsMessages.length - 1].merkleRoot
965
- };
966
- const wtsFile = {
967
- wts: canonicalizeJson(wtsMeta),
968
- payload,
969
- meta: wtsMeta
970
- };
971
- const fileName = `${sessionId}_${startLeafIndex}-${endLeafIndex}.wts`;
972
- const filePath = path.join(params.outputDir, fileName);
973
- fs.writeFileSync(filePath, JSON.stringify(wtsFile, null, 2));
974
- generatedFiles.push(filePath);
909
+ return {
910
+ files: generatedFiles,
911
+ totalMessageCount: messages.length,
912
+ timeRange: {
913
+ start: startTime,
914
+ end: endTime,
915
+ },
916
+ };
975
917
  }
976
- return {
977
- files: generatedFiles,
978
- totalMessageCount: messages.length,
979
- timeRange: {
980
- start: startTime,
981
- end: endTime
982
- }
983
- };
984
- }
985
- async addToBlacklist(account, addresses) {
986
- const acc = this.findAccount(account);
987
- if (!acc) {
988
- throw new MessengerError(
989
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
990
- `Account ${account} not in managed accounts`
991
- );
918
+ async addToBlacklist(account, addresses) {
919
+ const acc = this.findAccount(account);
920
+ if (!acc) {
921
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
922
+ }
923
+ return acc.messenger.addToBlacklist(addresses);
992
924
  }
993
- return acc.messenger.addToBlacklist(addresses);
994
- }
995
- async removeFromBlacklist(account, addresses) {
996
- const acc = this.findAccount(account);
997
- if (!acc) {
998
- throw new MessengerError(
999
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1000
- `Account ${account} not in managed accounts`
1001
- );
925
+ async removeFromBlacklist(account, addresses) {
926
+ const acc = this.findAccount(account);
927
+ if (!acc) {
928
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
929
+ }
930
+ return acc.messenger.removeFromBlacklist(addresses);
1002
931
  }
1003
- return acc.messenger.removeFromBlacklist(addresses);
1004
- }
1005
- async clearBlacklist(account) {
1006
- const acc = this.findAccount(account);
1007
- if (!acc) {
1008
- throw new MessengerError(
1009
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1010
- `Account ${account} not in managed accounts`
1011
- );
932
+ async clearBlacklist(account) {
933
+ const acc = this.findAccount(account);
934
+ if (!acc) {
935
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
936
+ }
937
+ return acc.messenger.clearBlacklist();
1012
938
  }
1013
- return acc.messenger.clearBlacklist();
1014
- }
1015
- async getBlacklist(account) {
1016
- const acc = this.findAccount(account);
1017
- if (!acc) {
1018
- throw new MessengerError(
1019
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1020
- `Account ${account} not in managed accounts`
1021
- );
939
+ async getBlacklist(account) {
940
+ const acc = this.findAccount(account);
941
+ if (!acc) {
942
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
943
+ }
944
+ return acc.messenger.getBlacklist();
1022
945
  }
1023
- return acc.messenger.getBlacklist();
1024
- }
1025
- async existInBlacklist(account, addresses) {
1026
- const acc = this.findAccount(account);
1027
- if (!acc) {
1028
- throw new MessengerError(
1029
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1030
- `Account ${account} not in managed accounts`
1031
- );
946
+ async existInBlacklist(account, addresses) {
947
+ const acc = this.findAccount(account);
948
+ if (!acc) {
949
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
950
+ }
951
+ return acc.messenger.existInBlacklist(addresses);
1032
952
  }
1033
- return acc.messenger.existInBlacklist(addresses);
1034
- }
1035
- async addToFriendsList(account, addresses) {
1036
- const acc = this.findAccount(account);
1037
- if (!acc) {
1038
- throw new MessengerError(
1039
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1040
- `Account ${account} not in managed accounts`
1041
- );
953
+ async addToFriendsList(account, addresses) {
954
+ const acc = this.findAccount(account);
955
+ if (!acc) {
956
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
957
+ }
958
+ return acc.messenger.addToFriendsList(addresses);
1042
959
  }
1043
- return acc.messenger.addToFriendsList(addresses);
1044
- }
1045
- async removeFromFriendsList(account, addresses) {
1046
- const acc = this.findAccount(account);
1047
- if (!acc) {
1048
- throw new MessengerError(
1049
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1050
- `Account ${account} not in managed accounts`
1051
- );
960
+ async removeFromFriendsList(account, addresses) {
961
+ const acc = this.findAccount(account);
962
+ if (!acc) {
963
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
964
+ }
965
+ return acc.messenger.removeFromFriendsList(addresses);
1052
966
  }
1053
- return acc.messenger.removeFromFriendsList(addresses);
1054
- }
1055
- async clearFriendsList(account) {
1056
- const acc = this.findAccount(account);
1057
- if (!acc) {
1058
- throw new MessengerError(
1059
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1060
- `Account ${account} not in managed accounts`
1061
- );
967
+ async clearFriendsList(account) {
968
+ const acc = this.findAccount(account);
969
+ if (!acc) {
970
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
971
+ }
972
+ return acc.messenger.clearFriendsList();
1062
973
  }
1063
- return acc.messenger.clearFriendsList();
1064
- }
1065
- async getFriendsList(account) {
1066
- const acc = this.findAccount(account);
1067
- if (!acc) {
1068
- throw new MessengerError(
1069
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1070
- `Account ${account} not in managed accounts`
1071
- );
974
+ async getFriendsList(account) {
975
+ const acc = this.findAccount(account);
976
+ if (!acc) {
977
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
978
+ }
979
+ return acc.messenger.getFriendsList();
1072
980
  }
1073
- return acc.messenger.getFriendsList();
1074
- }
1075
- async existInFriendsList(account, addresses) {
1076
- const acc = this.findAccount(account);
1077
- if (!acc) {
1078
- throw new MessengerError(
1079
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1080
- `Account ${account} not in managed accounts`
1081
- );
981
+ async existInFriendsList(account, addresses) {
982
+ const acc = this.findAccount(account);
983
+ if (!acc) {
984
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
985
+ }
986
+ return acc.messenger.existInFriendsList(addresses);
1082
987
  }
1083
- return acc.messenger.existInFriendsList(addresses);
1084
- }
1085
- async addToGuardList(account, guards) {
1086
- const acc = this.findAccount(account);
1087
- if (!acc) {
1088
- throw new MessengerError(
1089
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1090
- `Account ${account} not in managed accounts`
1091
- );
988
+ async addToGuardList(account, guards) {
989
+ const acc = this.findAccount(account);
990
+ if (!acc) {
991
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
992
+ }
993
+ return acc.messenger.addToGuardList(guards);
1092
994
  }
1093
- return acc.messenger.addToGuardList(guards);
1094
- }
1095
- async removeFromGuardList(account, addresses) {
1096
- const acc = this.findAccount(account);
1097
- if (!acc) {
1098
- throw new MessengerError(
1099
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1100
- `Account ${account} not in managed accounts`
1101
- );
995
+ async removeFromGuardList(account, addresses) {
996
+ const acc = this.findAccount(account);
997
+ if (!acc) {
998
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
999
+ }
1000
+ return acc.messenger.removeFromGuardList(addresses);
1102
1001
  }
1103
- return acc.messenger.removeFromGuardList(addresses);
1104
- }
1105
- async getGuardList(account) {
1106
- const acc = this.findAccount(account);
1107
- if (!acc) {
1108
- throw new MessengerError(
1109
- MessengerErrorCode.ACCOUNT_NOT_FOUND,
1110
- `Account ${account} not in managed accounts`
1111
- );
1002
+ async getGuardList(account) {
1003
+ const acc = this.findAccount(account);
1004
+ if (!acc) {
1005
+ throw new MessengerError(MessengerErrorCode.ACCOUNT_NOT_FOUND, `Account ${account} not in managed accounts`);
1006
+ }
1007
+ return acc.messenger.getGuardList();
1112
1008
  }
1113
- return acc.messenger.getGuardList();
1114
- }
1115
1009
  }
1116
- export {
1117
- MessengerManager
1118
- };
1010
+ //# sourceMappingURL=messenger-manager.js.map