@mysten/sui 2.39.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (425) hide show
  1. package/CHANGELOG.md +169 -0
  2. package/README.md +5 -188
  3. package/dist/bcs/bcs.d.mts +6 -6
  4. package/dist/bcs/bcs.d.mts.map +1 -1
  5. package/dist/bcs/bcs.mjs +49 -22
  6. package/dist/bcs/bcs.mjs.map +1 -1
  7. package/dist/bcs/effects.mjs +49 -20
  8. package/dist/bcs/effects.mjs.map +1 -1
  9. package/dist/bcs/index.d.mts +1441 -624
  10. package/dist/bcs/index.d.mts.map +1 -1
  11. package/dist/bcs/index.mjs +2 -1
  12. package/dist/bcs/index.mjs.map +1 -1
  13. package/dist/bcs/transactions.d.mts +1059 -0
  14. package/dist/bcs/transactions.d.mts.map +1 -0
  15. package/dist/bcs/transactions.mjs +33 -14
  16. package/dist/bcs/transactions.mjs.map +1 -1
  17. package/dist/bcs/types.d.mts +6 -1
  18. package/dist/bcs/types.d.mts.map +1 -1
  19. package/dist/client/core-resolver.mjs +4 -4
  20. package/dist/client/core-resolver.mjs.map +1 -1
  21. package/dist/client/core.d.mts +55 -4
  22. package/dist/client/core.d.mts.map +1 -1
  23. package/dist/client/core.mjs +98 -1
  24. package/dist/client/core.mjs.map +1 -1
  25. package/dist/client/errors.mjs +11 -1
  26. package/dist/client/errors.mjs.map +1 -1
  27. package/dist/client/index.d.mts +5 -3
  28. package/dist/client/index.mjs +6 -3
  29. package/dist/client/mvr.d.mts +12 -2
  30. package/dist/client/mvr.d.mts.map +1 -1
  31. package/dist/client/mvr.mjs +34 -13
  32. package/dist/client/mvr.mjs.map +1 -1
  33. package/dist/client/query-filters.mjs +80 -76
  34. package/dist/client/query-filters.mjs.map +1 -1
  35. package/dist/client/stream/adapter.d.mts +102 -0
  36. package/dist/client/stream/adapter.d.mts.map +1 -0
  37. package/dist/client/stream/errors.d.mts +14 -0
  38. package/dist/client/stream/errors.d.mts.map +1 -0
  39. package/dist/client/stream/errors.mjs +25 -0
  40. package/dist/client/stream/errors.mjs.map +1 -0
  41. package/dist/client/stream/filter.mjs +18 -0
  42. package/dist/client/stream/filter.mjs.map +1 -0
  43. package/dist/client/stream/follow.mjs +48 -0
  44. package/dist/client/stream/follow.mjs.map +1 -0
  45. package/dist/client/stream/index.d.mts +4 -0
  46. package/dist/client/stream/pager.mjs +123 -0
  47. package/dist/client/stream/pager.mjs.map +1 -0
  48. package/dist/client/stream/plan.mjs +79 -0
  49. package/dist/client/stream/plan.mjs.map +1 -0
  50. package/dist/client/stream/position.d.mts +30 -0
  51. package/dist/client/stream/position.d.mts.map +1 -0
  52. package/dist/client/stream/position.mjs +121 -0
  53. package/dist/client/stream/position.mjs.map +1 -0
  54. package/dist/client/stream/run.d.mts +2 -0
  55. package/dist/client/stream/run.mjs +99 -0
  56. package/dist/client/stream/run.mjs.map +1 -0
  57. package/dist/client/stream/session.mjs +205 -0
  58. package/dist/client/stream/session.mjs.map +1 -0
  59. package/dist/client/stream/status.mjs +47 -0
  60. package/dist/client/stream/status.mjs.map +1 -0
  61. package/dist/client/stream/token.mjs +80 -0
  62. package/dist/client/stream/token.mjs.map +1 -0
  63. package/dist/client/transaction-data.d.mts +17 -0
  64. package/dist/client/transaction-data.d.mts.map +1 -0
  65. package/dist/client/transaction-data.mjs +472 -0
  66. package/dist/client/transaction-data.mjs.map +1 -0
  67. package/dist/client/transaction-resolver.mjs +102 -58
  68. package/dist/client/transaction-resolver.mjs.map +1 -1
  69. package/dist/client/types.d.mts +560 -240
  70. package/dist/client/types.d.mts.map +1 -1
  71. package/dist/client/utils.d.mts +2 -2
  72. package/dist/client/utils.d.mts.map +1 -1
  73. package/dist/client/utils.mjs +91 -30
  74. package/dist/client/utils.mjs.map +1 -1
  75. package/dist/cryptography/index.d.mts +1 -1
  76. package/dist/cryptography/keypair.d.mts +1 -1
  77. package/dist/cryptography/publickey.d.mts +11 -0
  78. package/dist/cryptography/publickey.d.mts.map +1 -1
  79. package/dist/cryptography/publickey.mjs +12 -1
  80. package/dist/cryptography/publickey.mjs.map +1 -1
  81. package/dist/cryptography/signature.d.mts +8 -8
  82. package/dist/cryptography/signature.mjs +18 -7
  83. package/dist/cryptography/signature.mjs.map +1 -1
  84. package/dist/graphql/client.d.mts +51 -35
  85. package/dist/graphql/client.d.mts.map +1 -1
  86. package/dist/graphql/client.mjs +125 -69
  87. package/dist/graphql/client.mjs.map +1 -1
  88. package/dist/graphql/core.d.mts +14 -9
  89. package/dist/graphql/core.d.mts.map +1 -1
  90. package/dist/graphql/core.mjs +294 -118
  91. package/dist/graphql/core.mjs.map +1 -1
  92. package/dist/graphql/errors.d.mts +20 -0
  93. package/dist/graphql/errors.d.mts.map +1 -0
  94. package/dist/graphql/errors.mjs +19 -0
  95. package/dist/graphql/errors.mjs.map +1 -0
  96. package/dist/graphql/filters.mjs +32 -0
  97. package/dist/graphql/filters.mjs.map +1 -0
  98. package/dist/graphql/generated/queries.d.mts.map +1 -1
  99. package/dist/graphql/generated/queries.mjs +1216 -208
  100. package/dist/graphql/generated/queries.mjs.map +1 -1
  101. package/dist/graphql/generated/tada-env.d.mts +820 -11
  102. package/dist/graphql/index.d.mts +2 -1
  103. package/dist/graphql/index.mjs +2 -1
  104. package/dist/graphql/sse-parser.mjs +82 -0
  105. package/dist/graphql/sse-parser.mjs.map +1 -0
  106. package/dist/graphql/stream/families.mjs +306 -0
  107. package/dist/graphql/stream/families.mjs.map +1 -0
  108. package/dist/graphql/stream/index.mjs +38 -0
  109. package/dist/graphql/stream/index.mjs.map +1 -0
  110. package/dist/graphql/stream/live.mjs +60 -0
  111. package/dist/graphql/stream/live.mjs.map +1 -0
  112. package/dist/graphql/stream/page.mjs +38 -0
  113. package/dist/graphql/stream/page.mjs.map +1 -0
  114. package/dist/graphql/stream/query.mjs +47 -0
  115. package/dist/graphql/stream/query.mjs.map +1 -0
  116. package/dist/graphql/subscribe.mjs +70 -0
  117. package/dist/graphql/subscribe.mjs.map +1 -0
  118. package/dist/grpc/client.d.mts +31 -27
  119. package/dist/grpc/client.d.mts.map +1 -1
  120. package/dist/grpc/client.mjs +42 -46
  121. package/dist/grpc/client.mjs.map +1 -1
  122. package/dist/grpc/core.d.mts +13 -6
  123. package/dist/grpc/core.d.mts.map +1 -1
  124. package/dist/grpc/core.mjs +254 -166
  125. package/dist/grpc/core.mjs.map +1 -1
  126. package/dist/grpc/filters.mjs +44 -34
  127. package/dist/grpc/filters.mjs.map +1 -1
  128. package/dist/grpc/grpc-web-pull.mjs +245 -0
  129. package/dist/grpc/grpc-web-pull.mjs.map +1 -0
  130. package/dist/grpc/index.d.mts +2 -1
  131. package/dist/grpc/index.mjs +1 -1
  132. package/dist/grpc/network-error.mjs +31 -0
  133. package/dist/grpc/network-error.mjs.map +1 -0
  134. package/dist/grpc/proto/google/rpc/error_details.mjs +306 -0
  135. package/dist/grpc/proto/google/rpc/error_details.mjs.map +1 -0
  136. package/dist/grpc/proto/sui/forking/v1alpha/forking_service.client.d.mts +4 -4
  137. package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts +176 -1
  138. package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts.map +1 -1
  139. package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs +175 -0
  140. package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs.map +1 -1
  141. package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts +2 -2
  142. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  143. package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts +111 -0
  144. package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts.map +1 -1
  145. package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs +46 -0
  146. package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs.map +1 -1
  147. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  148. package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts +24 -1
  149. package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts.map +1 -1
  150. package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs +25 -7
  151. package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs.map +1 -1
  152. package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
  153. package/dist/grpc/proto/sui/rpc/v2/object.mjs +1 -1
  154. package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts +111 -9
  155. package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts.map +1 -1
  156. package/dist/grpc/proto/sui/rpc/v2/query_options.mjs +63 -19
  157. package/dist/grpc/proto/sui/rpc/v2/query_options.mjs.map +1 -1
  158. package/dist/grpc/proto/sui/rpc/v2/signature.d.mts +5 -5
  159. package/dist/grpc/proto/sui/rpc/v2/signature.mjs.map +1 -1
  160. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts +5 -1
  161. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts.map +1 -1
  162. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs +4 -0
  163. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs.map +1 -1
  164. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  165. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts +20 -1
  166. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts.map +1 -1
  167. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs +30 -13
  168. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs.map +1 -1
  169. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  170. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +20 -14
  171. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts.map +1 -1
  172. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs +8 -5
  173. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs.map +1 -1
  174. package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts +11 -5
  175. package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
  176. package/dist/grpc/proto/sui/rpc/v2/transaction.mjs +6 -0
  177. package/dist/grpc/proto/sui/rpc/v2/transaction.mjs.map +1 -1
  178. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +6 -2
  179. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
  180. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
  181. package/dist/grpc/proto/types.d.mts +7 -7
  182. package/dist/grpc/proto/types.mjs +3 -2
  183. package/dist/grpc/pull-call.d.mts +20 -0
  184. package/dist/grpc/pull-call.d.mts.map +1 -0
  185. package/dist/grpc/pull-call.mjs +28 -0
  186. package/dist/grpc/pull-call.mjs.map +1 -0
  187. package/dist/grpc/stream/call.mjs +238 -0
  188. package/dist/grpc/stream/call.mjs.map +1 -0
  189. package/dist/grpc/stream/families.d.mts +26 -0
  190. package/dist/grpc/stream/families.d.mts.map +1 -0
  191. package/dist/grpc/stream/families.mjs +145 -0
  192. package/dist/grpc/stream/families.mjs.map +1 -0
  193. package/dist/grpc/stream/index.d.mts +41 -0
  194. package/dist/grpc/stream/index.d.mts.map +1 -0
  195. package/dist/grpc/stream/index.mjs +127 -0
  196. package/dist/grpc/stream/index.mjs.map +1 -0
  197. package/dist/grpc/stream/live.mjs +31 -0
  198. package/dist/grpc/stream/live.mjs.map +1 -0
  199. package/dist/grpc/stream/page.mjs +120 -0
  200. package/dist/grpc/stream/page.mjs.map +1 -0
  201. package/dist/grpc/stream-types.d.mts +28 -0
  202. package/dist/grpc/stream-types.d.mts.map +1 -0
  203. package/dist/grpc/transport.d.mts +8 -3
  204. package/dist/grpc/transport.d.mts.map +1 -1
  205. package/dist/grpc/transport.mjs +88 -45
  206. package/dist/grpc/transport.mjs.map +1 -1
  207. package/dist/jsonRpc/index.d.mts +34 -12
  208. package/dist/jsonRpc/index.d.mts.map +1 -0
  209. package/dist/jsonRpc/index.mjs +39 -5
  210. package/dist/jsonRpc/index.mjs.map +1 -0
  211. package/dist/jsonRpc/types.d.mts +420 -0
  212. package/dist/jsonRpc/types.d.mts.map +1 -0
  213. package/dist/keypairs/passkey/keypair.d.mts +1 -1
  214. package/dist/multisig/publickey.d.mts +12 -4
  215. package/dist/multisig/publickey.d.mts.map +1 -1
  216. package/dist/multisig/publickey.mjs +5 -5
  217. package/dist/multisig/publickey.mjs.map +1 -1
  218. package/dist/multisig/signer.d.mts +1 -1
  219. package/dist/transactions/ObjectCache.d.mts +1 -1
  220. package/dist/transactions/ObjectCache.mjs +5 -5
  221. package/dist/transactions/ObjectCache.mjs.map +1 -1
  222. package/dist/transactions/Transaction.d.mts +10 -9
  223. package/dist/transactions/Transaction.d.mts.map +1 -1
  224. package/dist/transactions/Transaction.mjs +17 -6
  225. package/dist/transactions/Transaction.mjs.map +1 -1
  226. package/dist/transactions/data/internal.d.mts +2 -0
  227. package/dist/transactions/data/internal.d.mts.map +1 -1
  228. package/dist/transactions/data/internal.mjs +2 -1
  229. package/dist/transactions/data/internal.mjs.map +1 -1
  230. package/dist/transactions/executor/parallel.d.mts +2 -2
  231. package/dist/transactions/executor/serial.d.mts +1 -1
  232. package/dist/transactions/executor/serial.mjs +2 -2
  233. package/dist/transactions/executor/serial.mjs.map +1 -1
  234. package/dist/transactions/index.d.mts +3 -2
  235. package/dist/transactions/index.mjs +4 -3
  236. package/dist/transactions/intents/AllowanceBalance.mjs +1 -1
  237. package/dist/transactions/intents/CoinWithBalance.mjs +1 -1
  238. package/dist/transactions/resolve.d.mts +6 -0
  239. package/dist/transactions/resolve.d.mts.map +1 -1
  240. package/dist/transactions/resolve.mjs.map +1 -1
  241. package/dist/transactions/restricted-move-calls.d.mts +25 -0
  242. package/dist/transactions/restricted-move-calls.d.mts.map +1 -0
  243. package/dist/transactions/restricted-move-calls.mjs +47 -0
  244. package/dist/transactions/restricted-move-calls.mjs.map +1 -0
  245. package/dist/transactions/serializer.d.mts +1 -4
  246. package/dist/transactions/serializer.d.mts.map +1 -1
  247. package/dist/transactions/serializer.mjs +1 -44
  248. package/dist/transactions/serializer.mjs.map +1 -1
  249. package/dist/transactions/utils.d.mts +0 -1
  250. package/dist/transactions/utils.d.mts.map +1 -1
  251. package/dist/transactions/utils.mjs.map +1 -1
  252. package/dist/utils/abort.mjs +89 -0
  253. package/dist/utils/abort.mjs.map +1 -0
  254. package/dist/utils/coin-reservation.mjs +1 -4
  255. package/dist/utils/coin-reservation.mjs.map +1 -1
  256. package/dist/utils/index.mjs +1 -1
  257. package/dist/utils/sui-types.mjs +1 -1
  258. package/dist/verify/index.d.mts +2 -2
  259. package/dist/verify/verify.d.mts +74 -24
  260. package/dist/verify/verify.d.mts.map +1 -1
  261. package/dist/verify/verify.mjs +128 -42
  262. package/dist/verify/verify.mjs.map +1 -1
  263. package/dist/version.mjs +1 -1
  264. package/dist/version.mjs.map +1 -1
  265. package/dist/zklogin/bcs.d.mts +14 -14
  266. package/dist/zklogin/publickey.d.mts.map +1 -1
  267. package/dist/zklogin/publickey.mjs +15 -20
  268. package/dist/zklogin/publickey.mjs.map +1 -1
  269. package/docs/bcs.md +2 -2
  270. package/docs/clients/core.md +19 -18
  271. package/docs/clients/executing.md +53 -8
  272. package/docs/clients/graphql.md +81 -11
  273. package/docs/clients/grpc.md +31 -15
  274. package/docs/clients/index.md +8 -7
  275. package/docs/clients/querying.md +134 -30
  276. package/docs/clients/streaming.md +324 -0
  277. package/docs/cryptography/index.md +85 -58
  278. package/docs/llms-index.md +4 -2
  279. package/docs/migrations/sui-2.0/dapp-kit.md +3 -2
  280. package/docs/migrations/sui-2.0/json-rpc-migration.md +106 -79
  281. package/docs/migrations/sui-3.0/index.md +247 -0
  282. package/docs/plugins.md +10 -10
  283. package/docs/sdk-building.md +3 -4
  284. package/docs/transactions/coins-and-balances.md +6 -11
  285. package/docs/transactions/reference.md +36 -1
  286. package/package.json +4 -5
  287. package/src/bcs/bcs.ts +80 -41
  288. package/src/bcs/effects.ts +61 -25
  289. package/src/bcs/index.ts +2 -0
  290. package/src/bcs/transactions.ts +36 -17
  291. package/src/bcs/types.ts +10 -4
  292. package/src/client/core-resolver.ts +3 -5
  293. package/src/client/core.ts +180 -8
  294. package/src/client/errors.ts +12 -0
  295. package/src/client/index.ts +4 -2
  296. package/src/client/mvr.ts +37 -10
  297. package/src/client/query-filters.ts +151 -97
  298. package/src/client/stream/adapter.ts +110 -0
  299. package/src/client/stream/errors.ts +40 -0
  300. package/src/client/stream/filter.ts +17 -0
  301. package/src/client/stream/follow.ts +63 -0
  302. package/src/client/stream/index.ts +9 -0
  303. package/src/client/stream/pager.ts +158 -0
  304. package/src/client/stream/plan.ts +147 -0
  305. package/src/client/stream/position.ts +143 -0
  306. package/src/client/stream/run.ts +147 -0
  307. package/src/client/stream/session.ts +259 -0
  308. package/src/client/stream/status.ts +44 -0
  309. package/src/client/stream/token.ts +104 -0
  310. package/src/client/transaction-data.ts +610 -0
  311. package/src/client/transaction-resolver.ts +158 -69
  312. package/src/client/types.ts +530 -115
  313. package/src/client/utils.ts +146 -61
  314. package/src/cryptography/publickey.ts +12 -1
  315. package/src/cryptography/signature.ts +6 -3
  316. package/src/graphql/client.ts +204 -135
  317. package/src/graphql/core.ts +446 -139
  318. package/src/graphql/errors.ts +24 -0
  319. package/src/graphql/filters.ts +48 -0
  320. package/src/graphql/generated/queries.ts +1455 -277
  321. package/src/graphql/generated/schema.graphql +282 -9
  322. package/src/graphql/generated/tada-env.ts +933 -4
  323. package/src/graphql/queries/checkpoints.graphql +34 -0
  324. package/src/graphql/queries/getDynamicFields.graphql +1 -0
  325. package/src/graphql/queries/listEvents.graphql +16 -24
  326. package/src/graphql/queries/streams.graphql +212 -0
  327. package/src/graphql/queries/transactions.graphql +71 -28
  328. package/src/graphql/queries/verifySignature.graphql +17 -0
  329. package/src/graphql/sse-parser.ts +99 -0
  330. package/src/graphql/stream/families.ts +515 -0
  331. package/src/graphql/stream/index.ts +55 -0
  332. package/src/graphql/stream/live.ts +70 -0
  333. package/src/graphql/stream/page.ts +47 -0
  334. package/src/graphql/stream/query.ts +52 -0
  335. package/src/graphql/subscribe.ts +83 -0
  336. package/src/grpc/client.ts +81 -79
  337. package/src/grpc/core.ts +388 -274
  338. package/src/grpc/filters.ts +59 -60
  339. package/src/grpc/grpc-web-pull.ts +360 -0
  340. package/src/grpc/index.ts +5 -0
  341. package/src/grpc/network-error.ts +33 -0
  342. package/src/grpc/proto/sui/rpc/v2/error_reason.ts +175 -0
  343. package/src/grpc/proto/sui/rpc/v2/ledger_service.ts +145 -0
  344. package/src/grpc/proto/sui/rpc/v2/move_package_service.ts +43 -1
  345. package/src/grpc/proto/sui/rpc/v2/query_options.ts +132 -8
  346. package/src/grpc/proto/sui/rpc/v2/signature.ts +4 -4
  347. package/src/grpc/proto/sui/rpc/v2/signature_scheme.ts +4 -0
  348. package/src/grpc/proto/sui/rpc/v2/signature_verification_service.ts +30 -0
  349. package/src/grpc/proto/sui/rpc/v2/subscription_service.client.ts +16 -10
  350. package/src/grpc/proto/sui/rpc/v2/transaction.ts +6 -0
  351. package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +5 -1
  352. package/src/grpc/pull-call.ts +54 -0
  353. package/src/grpc/stream/call.ts +317 -0
  354. package/src/grpc/stream/families.ts +228 -0
  355. package/src/grpc/stream/index.ts +182 -0
  356. package/src/grpc/stream/live.ts +33 -0
  357. package/src/grpc/stream/page.ts +161 -0
  358. package/src/grpc/stream-types.ts +33 -0
  359. package/src/grpc/transport.ts +116 -59
  360. package/src/jsonRpc/index.ts +60 -17
  361. package/src/jsonRpc/types.ts +421 -0
  362. package/src/multisig/publickey.ts +19 -7
  363. package/src/transactions/ObjectCache.ts +6 -6
  364. package/src/transactions/Transaction.ts +30 -6
  365. package/src/transactions/data/internal.ts +2 -0
  366. package/src/transactions/executor/serial.ts +2 -2
  367. package/src/transactions/index.ts +8 -1
  368. package/src/transactions/resolve.ts +6 -0
  369. package/src/transactions/restricted-move-calls.ts +87 -0
  370. package/src/transactions/serializer.ts +0 -70
  371. package/src/transactions/utils.ts +0 -37
  372. package/src/utils/abort.ts +101 -0
  373. package/src/verify/index.ts +1 -0
  374. package/src/verify/verify.ts +190 -62
  375. package/src/version.ts +1 -1
  376. package/src/zklogin/publickey.ts +18 -34
  377. package/dist/client/core-resolver.d.mts +0 -9
  378. package/dist/client/core-resolver.d.mts.map +0 -1
  379. package/dist/jsonRpc/client.d.mts +0 -507
  380. package/dist/jsonRpc/client.d.mts.map +0 -1
  381. package/dist/jsonRpc/client.mjs +0 -868
  382. package/dist/jsonRpc/client.mjs.map +0 -1
  383. package/dist/jsonRpc/core.d.mts +0 -168
  384. package/dist/jsonRpc/core.d.mts.map +0 -1
  385. package/dist/jsonRpc/core.mjs +0 -1054
  386. package/dist/jsonRpc/core.mjs.map +0 -1
  387. package/dist/jsonRpc/errors.d.mts +0 -27
  388. package/dist/jsonRpc/errors.d.mts.map +0 -1
  389. package/dist/jsonRpc/errors.mjs +0 -50
  390. package/dist/jsonRpc/errors.mjs.map +0 -1
  391. package/dist/jsonRpc/http-transport.d.mts +0 -62
  392. package/dist/jsonRpc/http-transport.d.mts.map +0 -1
  393. package/dist/jsonRpc/http-transport.mjs +0 -60
  394. package/dist/jsonRpc/http-transport.mjs.map +0 -1
  395. package/dist/jsonRpc/network.d.mts +0 -9
  396. package/dist/jsonRpc/network.d.mts.map +0 -1
  397. package/dist/jsonRpc/network.mjs +0 -18
  398. package/dist/jsonRpc/network.mjs.map +0 -1
  399. package/dist/jsonRpc/types/chain.d.mts +0 -169
  400. package/dist/jsonRpc/types/chain.d.mts.map +0 -1
  401. package/dist/jsonRpc/types/changes.d.mts +0 -48
  402. package/dist/jsonRpc/types/changes.d.mts.map +0 -1
  403. package/dist/jsonRpc/types/coins.d.mts +0 -15
  404. package/dist/jsonRpc/types/coins.d.mts.map +0 -1
  405. package/dist/jsonRpc/types/common.d.mts +0 -9
  406. package/dist/jsonRpc/types/common.d.mts.map +0 -1
  407. package/dist/jsonRpc/types/generated.d.mts +0 -1976
  408. package/dist/jsonRpc/types/generated.d.mts.map +0 -1
  409. package/dist/jsonRpc/types/index.d.mts +0 -6
  410. package/dist/jsonRpc/types/params.d.mts +0 -898
  411. package/dist/jsonRpc/types/params.d.mts.map +0 -1
  412. package/src/graphql/generated/tsconfig.tada.json +0 -11
  413. package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -15
  414. package/src/jsonRpc/client.ts +0 -1252
  415. package/src/jsonRpc/core.ts +0 -1557
  416. package/src/jsonRpc/errors.ts +0 -57
  417. package/src/jsonRpc/http-transport.ts +0 -118
  418. package/src/jsonRpc/network.ts +0 -21
  419. package/src/jsonRpc/types/chain.ts +0 -190
  420. package/src/jsonRpc/types/changes.ts +0 -35
  421. package/src/jsonRpc/types/coins.ts +0 -14
  422. package/src/jsonRpc/types/common.ts +0 -8
  423. package/src/jsonRpc/types/generated.ts +0 -2165
  424. package/src/jsonRpc/types/index.ts +0 -9
  425. package/src/jsonRpc/types/params.ts +0 -908
package/src/client/mvr.ts CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  parseStructTag,
12
12
  } from '../utils/sui-types.js';
13
13
  import type { ClientCache } from './cache.js';
14
+ import { httpStatusReason, SuiClientError } from './errors.js';
14
15
  import type { TransactionDataBuilder } from '../transactions/TransactionData.js';
15
16
  import { PACKAGE_VERSION } from '../version.js';
16
17
  import type { SuiClientTypes } from './types.js';
@@ -30,6 +31,21 @@ export interface MvrClientOptions {
30
31
  };
31
32
  }
32
33
 
34
+ /** An MVR request that failed or got an error response. */
35
+ export class MvrRequestError extends SuiClientError {
36
+ /** Why repeating the same request may succeed; undefined when it can't. */
37
+ readonly reason?: SuiClientTypes.RetryReason;
38
+
39
+ constructor(
40
+ message: string,
41
+ options: { reason?: SuiClientTypes.RetryReason; cause?: unknown } = {},
42
+ ) {
43
+ super(message, { cause: options.cause });
44
+ this.name = 'MvrRequestError';
45
+ this.reason = options.reason;
46
+ }
47
+ }
48
+
33
49
  export class MvrClient implements SuiClientTypes.MvrMethods {
34
50
  #cache: ClientCache;
35
51
  #url?: string;
@@ -166,21 +182,32 @@ export class MvrClient implements SuiClientTypes.MvrMethods {
166
182
  throw new Error('MVR Api URL is not set for the current client');
167
183
  }
168
184
 
169
- const response = await fetch(`${this.#url}${url}`, {
170
- method: 'POST',
171
- headers: {
172
- 'Content-Type': 'application/json',
173
- ...MVR_API_HEADER,
174
- },
175
- body: JSON.stringify(body),
176
- });
185
+ let response: Response;
186
+ try {
187
+ response = await fetch(`${this.#url}${url}`, {
188
+ method: 'POST',
189
+ headers: {
190
+ 'Content-Type': 'application/json',
191
+ ...MVR_API_HEADER,
192
+ },
193
+ body: JSON.stringify(body),
194
+ });
195
+ } catch (cause) {
196
+ throw new MvrRequestError('MVR request failed', { cause, reason: 'Unavailable' });
197
+ }
177
198
 
178
199
  if (!response.ok) {
179
200
  const errorBody = await response.json().catch(() => ({}));
180
- throw new Error(`Failed to resolve types: ${errorBody?.message}`);
201
+ throw new MvrRequestError(`Failed to resolve types: ${errorBody?.message}`, {
202
+ reason: httpStatusReason(response.status),
203
+ });
181
204
  }
182
205
 
183
- return response.json();
206
+ try {
207
+ return await response.json();
208
+ } catch (cause) {
209
+ throw new MvrRequestError('MVR response could not be read', { cause, reason: 'Unavailable' });
210
+ }
184
211
  }
185
212
 
186
213
  async resolvePackage({
@@ -19,32 +19,22 @@ export interface ResolvedPagination {
19
19
  const DEFAULT_PAGE_SIZE = 50;
20
20
 
21
21
  /**
22
- * Validates pagination bounds and resolves the traversal direction.
22
+ * Resolves pagination bounds and the traversal direction.
23
23
  *
24
- * `after` and `before` are exclusive ledger-position bounds. Until every
25
- * transport can combine bounds freely, a query accepts at most one bound, and
26
- * the bound must match the traversal direction (`after` implies ascending,
27
- * `before` implies descending).
24
+ * `after` and `before` are exclusive, order-independent ledger-position bounds
25
+ * that can be combined to read a window. Without an explicit `order`, queries
26
+ * bounded only by `before` read in descending order, and every other query
27
+ * reads in ascending order.
28
28
  */
29
29
  export function resolvePagination(options: {
30
30
  after?: string | null;
31
31
  before?: string | null;
32
- order?: 'ascending' | 'descending';
32
+ order?: SuiClientTypes.Order;
33
33
  limit?: number;
34
34
  }): ResolvedPagination {
35
- if (options.after != null && options.before != null) {
36
- throw new Error('Only one of `after` or `before` may be provided');
37
- }
38
-
39
- const descending = options.order ? options.order === 'descending' : options.before != null;
40
-
41
- if (options.after != null && descending) {
42
- throw new Error('`after` can not be combined with descending queries');
43
- }
44
-
45
- if (options.before != null && !descending) {
46
- throw new Error('`before` can not be combined with ascending queries');
47
- }
35
+ const descending = options.order
36
+ ? options.order === 'descending'
37
+ : options.before != null && options.after == null;
48
38
 
49
39
  return {
50
40
  descending,
@@ -54,36 +44,77 @@ export function resolvePagination(options: {
54
44
  };
55
45
  }
56
46
 
57
- export type ResolvedTransactionFilter =
58
- | { $kind: 'sender'; sender: string }
59
- | { $kind: 'function'; package: string; module?: string; function?: string };
47
+ export interface ResolvedCheckpointRange {
48
+ /** Inclusive lower checkpoint bound. */
49
+ start?: bigint;
50
+ /** Exclusive upper checkpoint bound. */
51
+ end?: bigint;
52
+ }
60
53
 
61
54
  /**
62
- * Validates that a transaction query's filter supports pagination bounds.
63
- *
64
- * Function filters can only be paginated when fully qualified, since JSON-RPC
65
- * rejects cursors on package- or module-level `MoveFunction` filters.
55
+ * Validates `startCheckpoint`/`endCheckpoint` and converts them to bigints, so
56
+ * every transport rejects the same ranges.
66
57
  */
67
- export function validateTransactionQuery(
68
- filter: ResolvedTransactionFilter | undefined,
69
- pagination: ResolvedPagination,
70
- ): void {
71
- if (
72
- filter?.$kind === 'function' &&
73
- (pagination.after != null || pagination.before != null) &&
74
- (!filter.module || !filter.function)
75
- ) {
76
- throw new Error(
77
- 'Paginating transactions filtered by function requires a fully qualified `package::module::function`',
78
- );
58
+ export function resolveCheckpointRange(options: {
59
+ startCheckpoint?: SuiClientTypes.CheckpointNumber;
60
+ endCheckpoint?: SuiClientTypes.CheckpointNumber;
61
+ }): ResolvedCheckpointRange {
62
+ const start =
63
+ options.startCheckpoint == null
64
+ ? undefined
65
+ : parseCheckpointNumber(options.startCheckpoint, 'startCheckpoint');
66
+ const end =
67
+ options.endCheckpoint == null
68
+ ? undefined
69
+ : parseCheckpointNumber(options.endCheckpoint, 'endCheckpoint');
70
+
71
+ if (start != null && end != null && end < start) {
72
+ throw new Error('`endCheckpoint` must be greater than or equal to `startCheckpoint`');
73
+ }
74
+
75
+ return { start, end };
76
+ }
77
+
78
+ /**
79
+ * Validates a checkpoint sequence number and converts it to a bigint. Values
80
+ * are capped at `Number.MAX_SAFE_INTEGER` because GraphQL represents
81
+ * checkpoints as `UInt53`.
82
+ */
83
+ export function parseCheckpointNumber(
84
+ value: SuiClientTypes.CheckpointNumber,
85
+ label: string,
86
+ ): bigint {
87
+ const valid =
88
+ typeof value === 'bigint'
89
+ ? value >= 0n && value <= BigInt(Number.MAX_SAFE_INTEGER)
90
+ : typeof value === 'number'
91
+ ? Number.isSafeInteger(value) && value >= 0
92
+ : /^\d+$/.test(value) && BigInt(value) <= BigInt(Number.MAX_SAFE_INTEGER);
93
+
94
+ if (!valid) {
95
+ throw new Error(`Invalid ${label} "${value}": expected a non-negative integer`);
79
96
  }
97
+
98
+ return BigInt(value);
80
99
  }
81
100
 
82
- export type ResolvedEventFilter =
83
- | { $kind: 'sender'; sender: string }
84
- | { $kind: 'emitModule'; package: string; module: string }
85
- | { $kind: 'eventTypeModule'; package: string; module: string }
86
- | { $kind: 'eventType'; eventType: string };
101
+ /** A validated transaction filter with addresses normalized and MVR names resolved. */
102
+ export interface ResolvedTransactionFilter {
103
+ sender?: string;
104
+ affectedAddress?: string;
105
+ affectedObject?: string;
106
+ /** A normalized Move path: `0x…`, `0x…::module`, or `0x…::module::function`. */
107
+ function?: string;
108
+ }
109
+
110
+ /** A validated event filter with addresses normalized and MVR names resolved. */
111
+ export interface ResolvedEventFilter {
112
+ sender?: string;
113
+ /** `0x…` or `0x…::module`. */
114
+ emitModule?: string;
115
+ /** `0x…`, `0x…::module`, or a fully qualified type name. */
116
+ eventType?: string;
117
+ }
87
118
 
88
119
  /**
89
120
  * Validates a transaction filter and resolves any MVR names it contains.
@@ -96,100 +127,123 @@ export async function resolveTransactionFilter(
96
127
  filter: SuiClientTypes.TransactionFilter,
97
128
  signal?: AbortSignal,
98
129
  ): Promise<ResolvedTransactionFilter> {
99
- assertSinglePredicate(filter, ['sender', 'function'], 'transaction');
130
+ validateTransactionFilter(filter);
131
+
132
+ const resolved: ResolvedTransactionFilter = {};
100
133
 
101
134
  if (filter.sender != null) {
102
- return { $kind: 'sender', sender: normalizeSuiAddress(filter.sender) };
135
+ resolved.sender = normalizeSuiAddress(filter.sender);
103
136
  }
104
137
 
105
- const [pkg, module, fn, ...rest] = filter.function!.split('::');
138
+ if (filter.affectedAddress != null) {
139
+ resolved.affectedAddress = normalizeSuiAddress(filter.affectedAddress);
140
+ }
106
141
 
107
- if (!pkg || rest.length > 0 || module === '' || fn === '') {
108
- throw new Error(
109
- `Invalid function filter "${filter.function}": expected "package", "package::module", or "package::module::function"`,
110
- );
142
+ if (filter.affectedObject != null) {
143
+ resolved.affectedObject = normalizeSuiAddress(filter.affectedObject);
111
144
  }
112
145
 
113
- return {
114
- $kind: 'function',
115
- package: normalizeSuiAddress((await mvr.resolvePackage({ package: pkg, signal })).package),
116
- module,
117
- function: fn,
118
- };
146
+ if (filter.function != null) {
147
+ resolved.function = await resolvePackagePath(mvr, filter.function, signal);
148
+ }
149
+
150
+ return resolved;
119
151
  }
120
152
 
121
153
  /**
122
154
  * Validates an event filter and resolves any MVR names it contains.
123
155
  *
124
- * `emitModule` must name a module (`package::module`), and `eventType` must be
125
- * at least module-qualified (`package::module` or a full type). Every transport
126
- * resolves filters through this function so that validation errors and MVR
127
- * handling are identical across clients.
156
+ * Every transport resolves filters through this function so that validation
157
+ * errors and MVR handling are identical across clients.
128
158
  */
129
159
  export async function resolveEventFilter(
130
160
  mvr: SuiClientTypes.MvrMethods,
131
161
  filter: SuiClientTypes.EventFilter,
132
162
  signal?: AbortSignal,
133
163
  ): Promise<ResolvedEventFilter> {
134
- assertSinglePredicate(filter, ['sender', 'emitModule', 'eventType'], 'event');
164
+ validateEventFilter(filter);
165
+
166
+ const resolved: ResolvedEventFilter = {};
135
167
 
136
168
  if (filter.sender != null) {
137
- return { $kind: 'sender', sender: normalizeSuiAddress(filter.sender) };
169
+ resolved.sender = normalizeSuiAddress(filter.sender);
138
170
  }
139
171
 
140
172
  if (filter.emitModule != null) {
141
- const [pkg, module, ...rest] = filter.emitModule.split('::');
173
+ resolved.emitModule = await resolvePackagePath(mvr, filter.emitModule, signal);
174
+ }
175
+
176
+ if (filter.eventType != null) {
177
+ const eventType = filter.eventType;
178
+
179
+ if (eventType.split('::').length <= 2) {
180
+ resolved.eventType = await resolvePackagePath(mvr, eventType, signal);
181
+ } else {
182
+ resolved.eventType = (await mvr.resolveType({ type: eventType, signal })).type;
183
+ }
184
+ }
185
+
186
+ return resolved;
187
+ }
188
+
189
+ /**
190
+ * Checks a transaction filter's shape without resolving MVR names, throwing a plain `Error`.
191
+ * Addresses are not checked, so a malformed one reaches the server.
192
+ */
193
+ export function validateTransactionFilter(filter: SuiClientTypes.TransactionFilter) {
194
+ assertAtMostOne(filter, ['affectedAddress', 'affectedObject', 'function'], 'A transaction');
195
+
196
+ if (filter.function != null) {
197
+ const [pkg, module, fn, ...rest] = filter.function.split('::');
142
198
 
143
- if (!pkg || !module || rest.length > 0) {
199
+ if (!pkg || rest.length > 0 || module === '' || fn === '') {
144
200
  throw new Error(
145
- `Invalid emitModule filter "${filter.emitModule}": expected "package::module"`,
201
+ `Invalid function filter "${filter.function}": expected "package", "package::module", or "package::module::function"`,
146
202
  );
147
203
  }
148
-
149
- return {
150
- $kind: 'emitModule',
151
- package: normalizeSuiAddress((await mvr.resolvePackage({ package: pkg, signal })).package),
152
- module,
153
- };
154
204
  }
205
+ }
155
206
 
156
- const eventType = filter.eventType!;
157
- const segments = eventType.split('::');
158
-
159
- if (segments.length === 2 && segments.every((segment) => segment !== '')) {
160
- return {
161
- $kind: 'eventTypeModule',
162
- package: normalizeSuiAddress(
163
- (await mvr.resolvePackage({ package: segments[0], signal })).package,
164
- ),
165
- module: segments[1],
166
- };
207
+ /** Checks an event filter's shape like `validateTransactionFilter`. */
208
+ export function validateEventFilter(filter: SuiClientTypes.EventFilter) {
209
+ assertAtMostOne(filter, ['emitModule', 'eventType'], 'An event');
210
+
211
+ if (filter.emitModule != null) {
212
+ const segments = filter.emitModule.split('::');
213
+
214
+ if (segments.length > 2 || segments.some((segment) => segment === '')) {
215
+ throw new Error(
216
+ `Invalid emitModule filter "${filter.emitModule}": expected "package" or "package::module"`,
217
+ );
218
+ }
167
219
  }
168
220
 
169
- if (segments.length < 3 || segments.some((segment) => segment === '')) {
221
+ if (filter.eventType != null && filter.eventType.split('::').some((segment) => segment === '')) {
170
222
  throw new Error(
171
- `Invalid eventType filter "${eventType}": expected "package::module" or a fully qualified type name`,
223
+ `Invalid eventType filter "${filter.eventType}": expected "package", "package::module", or a fully qualified type name`,
172
224
  );
173
225
  }
226
+ }
174
227
 
175
- return {
176
- $kind: 'eventType',
177
- eventType: (await mvr.resolveType({ type: eventType, signal })).type,
178
- };
228
+ /** Resolves the package segment of a `package[::module[::name]]` path, keeping the rest. */
229
+ async function resolvePackagePath(
230
+ mvr: SuiClientTypes.MvrMethods,
231
+ path: string,
232
+ signal?: AbortSignal,
233
+ ): Promise<string> {
234
+ const [pkg, ...rest] = path.split('::');
235
+ const resolved = normalizeSuiAddress(
236
+ (await mvr.resolvePackage({ package: pkg, signal })).package,
237
+ );
238
+ return [resolved, ...rest].join('::');
179
239
  }
180
240
 
181
- function assertSinglePredicate(
182
- filter: Record<string, unknown>,
183
- predicates: string[],
184
- kind: string,
185
- ): void {
241
+ function assertAtMostOne(filter: Record<string, unknown>, predicates: string[], subject: string) {
186
242
  const present = predicates.filter((predicate) => filter[predicate] != null);
187
243
 
188
- if (present.length !== 1) {
244
+ if (present.length > 1) {
189
245
  throw new Error(
190
- `A ${kind} filter must specify exactly one of ${predicates.join(', ')}${
191
- present.length ? ` (got ${present.join(', ')})` : ''
192
- }`,
246
+ `${subject} filter may specify at most one of ${predicates.join(', ')} (got ${present.join(', ')})`,
193
247
  );
194
248
  }
195
249
  }
@@ -0,0 +1,110 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Internal contract between the ledger stream core and a transport. The core owns tokens,
6
+ * planning, paging, the live handoff, retries, deduplication and statuses so they match across
7
+ * transports. An adapter reads one page at a time, opens subscriptions, builds positions from what
8
+ * its server reports, and says which failures are worth retrying.
9
+ */
10
+
11
+ import type { SuiClientTypes } from '../types.js';
12
+ import type { StreamPosition } from './position.js';
13
+
14
+ export type StreamFamily = 'checkpoints' | 'transactions' | 'events';
15
+
16
+ /** Append-only: the transport tag is part of every token. */
17
+ export type StreamTransport = 'grpc' | 'graphql';
18
+
19
+ /** A checkpoint start (inclusive), or a position the stream continues after. */
20
+ export type Bound = { checkpoint: bigint } | { position: StreamPosition };
21
+
22
+ /** One page of a range: checkpoints `[range.start, range.end)`, after the start-side cursor. */
23
+ export interface PageRequest {
24
+ range: { start?: bigint; end?: bigint };
25
+ /** Ascending: continue after this cursor. */
26
+ after?: Uint8Array;
27
+ /** Descending: continue before this cursor. */
28
+ before?: Uint8Array;
29
+ order: SuiClientTypes.Order;
30
+ signal: AbortSignal;
31
+ }
32
+
33
+ /** An item, or without one, a resume point the server reported mid-page. */
34
+ export interface PageItem<Item> {
35
+ position: StreamPosition;
36
+ item?: Item;
37
+ }
38
+
39
+ /** What a page reports once its items are read. */
40
+ export interface PageEnd {
41
+ /** `cursor` continues the scan; `position` is that point, where the server reports it. */
42
+ next: { more: boolean; cursor?: Uint8Array; position?: StreamPosition };
43
+ /** Ascending, on the last page: every match through this checkpoint has been read. */
44
+ covered?: bigint;
45
+ /** A descending read without a low end stopped at this oldest retained checkpoint. */
46
+ retainedFrom?: bigint;
47
+ /** The server has not indexed what this page needs yet; the pass waits and reads again. */
48
+ notIndexed?: boolean;
49
+ }
50
+
51
+ /** A page's items and resume points in traversal order, as they arrive, then its end. */
52
+ export type Page<Item> = AsyncIterator<PageItem<Item>, PageEnd, undefined>;
53
+
54
+ export type LiveEvent<Item> =
55
+ | { $kind: 'Item'; position: StreamPosition; item: Item }
56
+ | { $kind: 'Progress'; position: StreamPosition };
57
+
58
+ export interface LiveSubscription<Item> extends AsyncIterable<LiveEvent<Item>> {
59
+ /** While enabled, events are buffered ahead of the consumer during a gap replay. */
60
+ readAhead?(enabled: boolean): void;
61
+ }
62
+
63
+ /** Stream item frames without the token, which the core adds. */
64
+ export type ItemFrame =
65
+ | SuiClientTypes.StreamCheckpoint<any>
66
+ | SuiClientTypes.StreamTransaction<any>
67
+ | SuiClientTypes.StreamEvent;
68
+
69
+ /** Everything the core can yield. */
70
+ export type CoreFrame<Frame> =
71
+ Frame | SuiClientTypes.StreamProgressFrame | SuiClientTypes.StreamCompletionFrame;
72
+
73
+ export interface LedgerStreamAdapter<Item, Frame extends { resumeToken: string } = ItemFrame> {
74
+ readonly transport: StreamTransport;
75
+ readonly family: StreamFamily;
76
+ /**
77
+ * `fromTip`: subscriptions start at the live tip, so the core pages history first and replays
78
+ * the gap up to the feed's first frame; every live position has a checkpoint.
79
+ * `resume`: `subscribe(from)` backfills after `from` on the server, then goes live.
80
+ */
81
+ readonly live: 'fromTip' | 'resume';
82
+ /** `resume` only: whether `subscribe(from)` can backfill from `from`; if not, the core pages first. */
83
+ canResume?(from: Bound): boolean;
84
+
85
+ /**
86
+ * Resolves names in the filter; the returned filter is hashed into every token. An adapter that
87
+ * reads the indexed tip with the chain identity returns it, and planning uses it.
88
+ */
89
+ initialize(signal: AbortSignal): Promise<{ chain: string; filter: unknown; indexedTip?: bigint }>;
90
+ /** The highest checkpoint that pages can read. */
91
+ indexedTip(signal: AbortSignal): Promise<bigint>;
92
+ /** One request, opened on the first read. The core always reads or closes it. */
93
+ fetchPage(request: PageRequest): Page<Item>;
94
+ /**
95
+ * A live subscription (`from` is used only by `resume` adapters). An adapter whose feed can stay
96
+ * quiet after it opens calls `onOpen` then, for the `Connected` status.
97
+ */
98
+ subscribe(
99
+ from: Bound | undefined,
100
+ signal: AbortSignal,
101
+ onOpen: () => void,
102
+ ): LiveSubscription<Item>;
103
+
104
+ mapItem(item: Item): Omit<Frame, 'resumeToken'>;
105
+ /** Why retrying may get past `error`, or `undefined` when it cannot. */
106
+ retryReason(error: unknown): SuiClientTypes.RetryReason | undefined;
107
+ }
108
+
109
+ /** An adapter whose item type is known only to itself. */
110
+ export type AnyLedgerStreamAdapter = LedgerStreamAdapter<any, any>;
@@ -0,0 +1,40 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { SuiClientError } from '../errors.js';
5
+
6
+ export type SuiStreamErrorCode =
7
+ /** An invalid option or bound. Never retried. */
8
+ | 'InvalidOptions'
9
+ /** Not a resume token, an unsupported version, or a non-canonical encoding. */
10
+ | 'InvalidToken'
11
+ /** A token from another transport, chain, family or filter, or a changed order. */
12
+ | 'IncompatibleToken'
13
+ /** The history the stream needs has been pruned by the server. */
14
+ | 'HistoryUnavailable'
15
+ /** The server broke a documented invariant. */
16
+ | 'Protocol'
17
+ /** The live feed kept ending without progress until the retry budget ran out. */
18
+ | 'Disconnected';
19
+
20
+ /** A ledger stream failure that is not a transport error. */
21
+ export class SuiStreamError extends SuiClientError {
22
+ readonly code: SuiStreamErrorCode;
23
+
24
+ constructor(code: SuiStreamErrorCode, message: string, options?: { cause?: unknown }) {
25
+ super(message, options);
26
+ this.name = 'SuiStreamError';
27
+ this.code = code;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Internal: a live feed ended. Feeds never complete, so the core reconnects. Never escapes the
33
+ * stream: an exhausted budget throws `Disconnected` instead.
34
+ */
35
+ export class StreamDisconnected extends Error {
36
+ constructor(message = 'Live feed ended') {
37
+ super(message);
38
+ this.name = 'StreamDisconnected';
39
+ }
40
+ }
@@ -0,0 +1,17 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import type { LedgerStreamRequest } from '../core.js';
5
+ import { validateEventFilter, validateTransactionFilter } from '../query-filters.js';
6
+ import { SuiStreamError } from './errors.js';
7
+
8
+ /** Rejects an invalid `filter` with `InvalidOptions` before any request, as the list methods do. */
9
+ export function validateStreamFilter(request: LedgerStreamRequest): void {
10
+ if (request.family === 'checkpoints' || !request.options.filter) return;
11
+ try {
12
+ if (request.family === 'transactions') validateTransactionFilter(request.options.filter);
13
+ else validateEventFilter(request.options.filter);
14
+ } catch (error) {
15
+ throw new SuiStreamError('InvalidOptions', (error as Error).message, { cause: error });
16
+ }
17
+ }
@@ -0,0 +1,63 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { linkedAbortController } from '../../utils/abort.js';
5
+ import type { CoreFrame, LedgerStreamAdapter } from './adapter.js';
6
+ import { SuiStreamError } from './errors.js';
7
+ import { boundaryPosition, insideCheckpoint } from './position.js';
8
+ import type { LiveFeed, StreamSession } from './session.js';
9
+
10
+ /**
11
+ * The live handoff, rerun on every reconnect. A `resume` adapter subscribes after the resume point
12
+ * and the server backfills from there. A `fromTip` adapter's subscription starts at the live tip,
13
+ * so the core pages history to the indexed tip first, then replays the gap up to the feed's first
14
+ * frame before delivering the feed. The pager and the feed never commit at the same time.
15
+ */
16
+ export async function* followLive<Item, Frame extends { resumeToken: string }>(
17
+ session: StreamSession<Item, Frame>,
18
+ adapter: LedgerStreamAdapter<Item, Frame>,
19
+ ): AsyncGenerator<CoreFrame<Frame>, never> {
20
+ const start = session.start;
21
+ const fromTip = adapter.live === 'fromTip';
22
+ if (start && (fromTip || adapter.canResume?.(start) === false)) yield* session.replay(undefined);
23
+ // A token exists before the first match.
24
+ if (!session.committed && start && 'checkpoint' in start) {
25
+ yield* session.baseline(boundaryPosition(start.checkpoint));
26
+ }
27
+
28
+ // Closing must not wait for a quiet subscription's pending read: abort it first.
29
+ const attempt = linkedAbortController(session.signal);
30
+ let feed: LiveFeed<Item> | undefined;
31
+ try {
32
+ session.subscribing();
33
+ const subscription = adapter.subscribe(session.start, attempt.controller.signal, () =>
34
+ session.connected(),
35
+ );
36
+ feed = session.openFeed(subscription);
37
+ if (fromTip && start) {
38
+ const { position } = await feed.first();
39
+ const { checkpoint } = position;
40
+ if (checkpoint === null) {
41
+ throw new SuiStreamError('Protocol', 'Live frame is missing its checkpoint');
42
+ }
43
+ // The gap ends at the feed's first frame. Replaying through a frame inside a checkpoint
44
+ // overlaps the feed, and the session drops what it repeats.
45
+ const inside = adapter.family !== 'checkpoints' && insideCheckpoint(position);
46
+ const end = inside ? checkpoint + 1n : checkpoint;
47
+ const next = session.nextUncovered;
48
+ if (next === null || next < end) {
49
+ subscription.readAhead?.(true);
50
+ try {
51
+ yield* session.replay(end);
52
+ } finally {
53
+ subscription.readAhead?.(false);
54
+ }
55
+ }
56
+ }
57
+ return yield* session.deliver(feed);
58
+ } finally {
59
+ attempt.controller.abort();
60
+ attempt.dispose();
61
+ await feed?.close();
62
+ }
63
+ }
@@ -0,0 +1,9 @@
1
+ // Copyright (c) Mysten Labs, Inc.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Internal barrel for transports. Only `SuiStreamError` is public (from `@mysten/sui/client`).
5
+ export type * from './adapter.js';
6
+ export { StreamDisconnected, SuiStreamError } from './errors.js';
7
+ export type { SuiStreamErrorCode } from './errors.js';
8
+ export { createLedgerStream } from './run.js';
9
+ export * from './position.js';