@mysten/sui 2.39.1 → 3.0.0

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 (427) hide show
  1. package/CHANGELOG.md +160 -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 +4 -2
  28. package/dist/client/index.mjs +5 -2
  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 +12 -0
  64. package/dist/client/transaction-data.d.mts.map +1 -0
  65. package/dist/client/transaction-data.mjs +469 -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 +3 -1
  72. package/dist/client/utils.d.mts.map +1 -1
  73. package/dist/client/utils.mjs +91 -26
  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 +2 -2
  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 +293 -117
  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/rpc/v2/error_reason.d.mts +176 -1
  137. package/dist/grpc/proto/sui/rpc/v2/error_reason.d.mts.map +1 -1
  138. package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs +175 -0
  139. package/dist/grpc/proto/sui/rpc/v2/error_reason.mjs.map +1 -1
  140. package/dist/grpc/proto/sui/rpc/v2/executed_transaction.d.mts +2 -2
  141. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  142. package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts +111 -0
  143. package/dist/grpc/proto/sui/rpc/v2/ledger_service.d.mts.map +1 -1
  144. package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs +46 -0
  145. package/dist/grpc/proto/sui/rpc/v2/ledger_service.mjs.map +1 -1
  146. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  147. package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts +24 -1
  148. package/dist/grpc/proto/sui/rpc/v2/move_package_service.d.mts.map +1 -1
  149. package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs +25 -7
  150. package/dist/grpc/proto/sui/rpc/v2/move_package_service.mjs.map +1 -1
  151. package/dist/grpc/proto/sui/rpc/v2/object.mjs +1 -1
  152. package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts +111 -9
  153. package/dist/grpc/proto/sui/rpc/v2/query_options.d.mts.map +1 -1
  154. package/dist/grpc/proto/sui/rpc/v2/query_options.mjs +63 -19
  155. package/dist/grpc/proto/sui/rpc/v2/query_options.mjs.map +1 -1
  156. package/dist/grpc/proto/sui/rpc/v2/signature.d.mts +5 -5
  157. package/dist/grpc/proto/sui/rpc/v2/signature.mjs.map +1 -1
  158. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts +5 -1
  159. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.d.mts.map +1 -1
  160. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs +4 -0
  161. package/dist/grpc/proto/sui/rpc/v2/signature_scheme.mjs.map +1 -1
  162. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  163. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts +20 -1
  164. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.d.mts.map +1 -1
  165. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs +30 -13
  166. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.mjs.map +1 -1
  167. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  168. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +16 -10
  169. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts.map +1 -1
  170. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs +8 -5
  171. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.mjs.map +1 -1
  172. package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts +11 -5
  173. package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
  174. package/dist/grpc/proto/sui/rpc/v2/transaction.mjs +6 -0
  175. package/dist/grpc/proto/sui/rpc/v2/transaction.mjs.map +1 -1
  176. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +6 -2
  177. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
  178. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
  179. package/dist/grpc/proto/types.d.mts +7 -7
  180. package/dist/grpc/proto/types.mjs +3 -2
  181. package/dist/grpc/pull-call.d.mts +20 -0
  182. package/dist/grpc/pull-call.d.mts.map +1 -0
  183. package/dist/grpc/pull-call.mjs +28 -0
  184. package/dist/grpc/pull-call.mjs.map +1 -0
  185. package/dist/grpc/stream/call.mjs +238 -0
  186. package/dist/grpc/stream/call.mjs.map +1 -0
  187. package/dist/grpc/stream/families.d.mts +26 -0
  188. package/dist/grpc/stream/families.d.mts.map +1 -0
  189. package/dist/grpc/stream/families.mjs +145 -0
  190. package/dist/grpc/stream/families.mjs.map +1 -0
  191. package/dist/grpc/stream/index.d.mts +41 -0
  192. package/dist/grpc/stream/index.d.mts.map +1 -0
  193. package/dist/grpc/stream/index.mjs +127 -0
  194. package/dist/grpc/stream/index.mjs.map +1 -0
  195. package/dist/grpc/stream/live.mjs +31 -0
  196. package/dist/grpc/stream/live.mjs.map +1 -0
  197. package/dist/grpc/stream/page.mjs +120 -0
  198. package/dist/grpc/stream/page.mjs.map +1 -0
  199. package/dist/grpc/stream-types.d.mts +28 -0
  200. package/dist/grpc/stream-types.d.mts.map +1 -0
  201. package/dist/grpc/transport.d.mts +8 -3
  202. package/dist/grpc/transport.d.mts.map +1 -1
  203. package/dist/grpc/transport.mjs +88 -45
  204. package/dist/grpc/transport.mjs.map +1 -1
  205. package/dist/jsonRpc/index.d.mts +34 -12
  206. package/dist/jsonRpc/index.d.mts.map +1 -0
  207. package/dist/jsonRpc/index.mjs +39 -5
  208. package/dist/jsonRpc/index.mjs.map +1 -0
  209. package/dist/jsonRpc/types.d.mts +420 -0
  210. package/dist/jsonRpc/types.d.mts.map +1 -0
  211. package/dist/keypairs/passkey/keypair.d.mts +1 -1
  212. package/dist/multisig/publickey.d.mts +12 -4
  213. package/dist/multisig/publickey.d.mts.map +1 -1
  214. package/dist/multisig/publickey.mjs +5 -5
  215. package/dist/multisig/publickey.mjs.map +1 -1
  216. package/dist/multisig/signer.d.mts +1 -1
  217. package/dist/transactions/ObjectCache.d.mts +1 -1
  218. package/dist/transactions/ObjectCache.mjs +5 -5
  219. package/dist/transactions/ObjectCache.mjs.map +1 -1
  220. package/dist/transactions/Transaction.d.mts +11 -10
  221. package/dist/transactions/Transaction.d.mts.map +1 -1
  222. package/dist/transactions/Transaction.mjs +17 -6
  223. package/dist/transactions/Transaction.mjs.map +1 -1
  224. package/dist/transactions/data/internal.d.mts +135 -133
  225. package/dist/transactions/data/internal.d.mts.map +1 -1
  226. package/dist/transactions/data/internal.mjs +2 -1
  227. package/dist/transactions/data/internal.mjs.map +1 -1
  228. package/dist/transactions/data/v1.d.mts +239 -239
  229. package/dist/transactions/data/v1.d.mts.map +1 -1
  230. package/dist/transactions/data/v2.d.mts +16 -16
  231. package/dist/transactions/data/v2.d.mts.map +1 -1
  232. package/dist/transactions/executor/parallel.d.mts +2 -2
  233. package/dist/transactions/executor/serial.d.mts +1 -1
  234. package/dist/transactions/executor/serial.mjs +2 -2
  235. package/dist/transactions/executor/serial.mjs.map +1 -1
  236. package/dist/transactions/index.d.mts +3 -2
  237. package/dist/transactions/index.mjs +4 -3
  238. package/dist/transactions/intents/AllowanceBalance.mjs +1 -1
  239. package/dist/transactions/intents/CoinWithBalance.mjs +1 -1
  240. package/dist/transactions/resolve.d.mts +6 -0
  241. package/dist/transactions/resolve.d.mts.map +1 -1
  242. package/dist/transactions/resolve.mjs.map +1 -1
  243. package/dist/transactions/restricted-move-calls.d.mts +25 -0
  244. package/dist/transactions/restricted-move-calls.d.mts.map +1 -0
  245. package/dist/transactions/restricted-move-calls.mjs +47 -0
  246. package/dist/transactions/restricted-move-calls.mjs.map +1 -0
  247. package/dist/transactions/serializer.d.mts +1 -4
  248. package/dist/transactions/serializer.d.mts.map +1 -1
  249. package/dist/transactions/serializer.mjs +1 -44
  250. package/dist/transactions/serializer.mjs.map +1 -1
  251. package/dist/transactions/utils.d.mts +0 -1
  252. package/dist/transactions/utils.d.mts.map +1 -1
  253. package/dist/transactions/utils.mjs.map +1 -1
  254. package/dist/utils/abort.mjs +89 -0
  255. package/dist/utils/abort.mjs.map +1 -0
  256. package/dist/utils/coin-reservation.mjs +1 -4
  257. package/dist/utils/coin-reservation.mjs.map +1 -1
  258. package/dist/utils/index.mjs +1 -1
  259. package/dist/utils/sui-types.mjs +1 -1
  260. package/dist/verify/index.d.mts +2 -2
  261. package/dist/verify/verify.d.mts +74 -24
  262. package/dist/verify/verify.d.mts.map +1 -1
  263. package/dist/verify/verify.mjs +128 -42
  264. package/dist/verify/verify.mjs.map +1 -1
  265. package/dist/version.mjs +1 -1
  266. package/dist/version.mjs.map +1 -1
  267. package/dist/zklogin/bcs.d.mts +14 -14
  268. package/dist/zklogin/publickey.d.mts.map +1 -1
  269. package/dist/zklogin/publickey.mjs +15 -20
  270. package/dist/zklogin/publickey.mjs.map +1 -1
  271. package/docs/bcs.md +2 -2
  272. package/docs/clients/core.md +19 -18
  273. package/docs/clients/executing.md +53 -8
  274. package/docs/clients/graphql.md +81 -11
  275. package/docs/clients/grpc.md +31 -15
  276. package/docs/clients/index.md +8 -7
  277. package/docs/clients/querying.md +134 -30
  278. package/docs/clients/streaming.md +324 -0
  279. package/docs/cryptography/index.md +85 -58
  280. package/docs/llms-index.md +4 -2
  281. package/docs/migrations/sui-2.0/dapp-kit.md +3 -2
  282. package/docs/migrations/sui-2.0/json-rpc-migration.md +106 -79
  283. package/docs/migrations/sui-3.0/index.md +250 -0
  284. package/docs/plugins.md +10 -10
  285. package/docs/sdk-building.md +3 -4
  286. package/docs/transactions/coins-and-balances.md +6 -11
  287. package/docs/transactions/reference.md +36 -1
  288. package/package.json +2 -3
  289. package/src/bcs/bcs.ts +80 -41
  290. package/src/bcs/effects.ts +61 -25
  291. package/src/bcs/index.ts +2 -0
  292. package/src/bcs/transactions.ts +36 -17
  293. package/src/bcs/types.ts +10 -4
  294. package/src/client/core-resolver.ts +3 -5
  295. package/src/client/core.ts +180 -8
  296. package/src/client/errors.ts +12 -0
  297. package/src/client/index.ts +4 -1
  298. package/src/client/mvr.ts +37 -10
  299. package/src/client/query-filters.ts +151 -97
  300. package/src/client/stream/adapter.ts +110 -0
  301. package/src/client/stream/errors.ts +40 -0
  302. package/src/client/stream/filter.ts +17 -0
  303. package/src/client/stream/follow.ts +63 -0
  304. package/src/client/stream/index.ts +9 -0
  305. package/src/client/stream/pager.ts +158 -0
  306. package/src/client/stream/plan.ts +147 -0
  307. package/src/client/stream/position.ts +143 -0
  308. package/src/client/stream/run.ts +147 -0
  309. package/src/client/stream/session.ts +259 -0
  310. package/src/client/stream/status.ts +44 -0
  311. package/src/client/stream/token.ts +104 -0
  312. package/src/client/transaction-data.ts +587 -0
  313. package/src/client/transaction-resolver.ts +158 -69
  314. package/src/client/types.ts +530 -115
  315. package/src/client/utils.ts +147 -50
  316. package/src/cryptography/publickey.ts +12 -1
  317. package/src/cryptography/signature.ts +6 -3
  318. package/src/graphql/client.ts +204 -135
  319. package/src/graphql/core.ts +446 -139
  320. package/src/graphql/errors.ts +24 -0
  321. package/src/graphql/filters.ts +48 -0
  322. package/src/graphql/generated/queries.ts +1455 -277
  323. package/src/graphql/generated/schema.graphql +282 -9
  324. package/src/graphql/generated/tada-env.ts +933 -4
  325. package/src/graphql/queries/checkpoints.graphql +34 -0
  326. package/src/graphql/queries/getDynamicFields.graphql +1 -0
  327. package/src/graphql/queries/listEvents.graphql +16 -24
  328. package/src/graphql/queries/streams.graphql +212 -0
  329. package/src/graphql/queries/transactions.graphql +71 -28
  330. package/src/graphql/queries/verifySignature.graphql +17 -0
  331. package/src/graphql/sse-parser.ts +99 -0
  332. package/src/graphql/stream/families.ts +515 -0
  333. package/src/graphql/stream/index.ts +55 -0
  334. package/src/graphql/stream/live.ts +70 -0
  335. package/src/graphql/stream/page.ts +47 -0
  336. package/src/graphql/stream/query.ts +52 -0
  337. package/src/graphql/subscribe.ts +83 -0
  338. package/src/grpc/client.ts +81 -79
  339. package/src/grpc/core.ts +388 -274
  340. package/src/grpc/filters.ts +59 -60
  341. package/src/grpc/grpc-web-pull.ts +360 -0
  342. package/src/grpc/index.ts +5 -0
  343. package/src/grpc/network-error.ts +33 -0
  344. package/src/grpc/proto/sui/rpc/v2/error_reason.ts +175 -0
  345. package/src/grpc/proto/sui/rpc/v2/ledger_service.ts +145 -0
  346. package/src/grpc/proto/sui/rpc/v2/move_package_service.ts +43 -1
  347. package/src/grpc/proto/sui/rpc/v2/query_options.ts +132 -8
  348. package/src/grpc/proto/sui/rpc/v2/signature.ts +4 -4
  349. package/src/grpc/proto/sui/rpc/v2/signature_scheme.ts +4 -0
  350. package/src/grpc/proto/sui/rpc/v2/signature_verification_service.ts +30 -0
  351. package/src/grpc/proto/sui/rpc/v2/subscription_service.client.ts +16 -10
  352. package/src/grpc/proto/sui/rpc/v2/transaction.ts +6 -0
  353. package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +5 -1
  354. package/src/grpc/pull-call.ts +54 -0
  355. package/src/grpc/stream/call.ts +317 -0
  356. package/src/grpc/stream/families.ts +228 -0
  357. package/src/grpc/stream/index.ts +182 -0
  358. package/src/grpc/stream/live.ts +33 -0
  359. package/src/grpc/stream/page.ts +161 -0
  360. package/src/grpc/stream-types.ts +33 -0
  361. package/src/grpc/transport.ts +116 -59
  362. package/src/jsonRpc/index.ts +60 -17
  363. package/src/jsonRpc/types.ts +421 -0
  364. package/src/multisig/publickey.ts +19 -7
  365. package/src/transactions/ObjectCache.ts +6 -6
  366. package/src/transactions/Transaction.ts +30 -6
  367. package/src/transactions/data/internal.ts +2 -0
  368. package/src/transactions/executor/serial.ts +2 -2
  369. package/src/transactions/index.ts +8 -1
  370. package/src/transactions/resolve.ts +6 -0
  371. package/src/transactions/restricted-move-calls.ts +87 -0
  372. package/src/transactions/serializer.ts +0 -70
  373. package/src/transactions/utils.ts +0 -37
  374. package/src/utils/abort.ts +101 -0
  375. package/src/verify/index.ts +1 -0
  376. package/src/verify/verify.ts +190 -62
  377. package/src/version.ts +1 -1
  378. package/src/zklogin/publickey.ts +18 -34
  379. package/dist/client/core-resolver.d.mts +0 -9
  380. package/dist/client/core-resolver.d.mts.map +0 -1
  381. package/dist/jsonRpc/client.d.mts +0 -507
  382. package/dist/jsonRpc/client.d.mts.map +0 -1
  383. package/dist/jsonRpc/client.mjs +0 -868
  384. package/dist/jsonRpc/client.mjs.map +0 -1
  385. package/dist/jsonRpc/core.d.mts +0 -168
  386. package/dist/jsonRpc/core.d.mts.map +0 -1
  387. package/dist/jsonRpc/core.mjs +0 -1054
  388. package/dist/jsonRpc/core.mjs.map +0 -1
  389. package/dist/jsonRpc/errors.d.mts +0 -27
  390. package/dist/jsonRpc/errors.d.mts.map +0 -1
  391. package/dist/jsonRpc/errors.mjs +0 -50
  392. package/dist/jsonRpc/errors.mjs.map +0 -1
  393. package/dist/jsonRpc/http-transport.d.mts +0 -62
  394. package/dist/jsonRpc/http-transport.d.mts.map +0 -1
  395. package/dist/jsonRpc/http-transport.mjs +0 -60
  396. package/dist/jsonRpc/http-transport.mjs.map +0 -1
  397. package/dist/jsonRpc/network.d.mts +0 -9
  398. package/dist/jsonRpc/network.d.mts.map +0 -1
  399. package/dist/jsonRpc/network.mjs +0 -18
  400. package/dist/jsonRpc/network.mjs.map +0 -1
  401. package/dist/jsonRpc/types/chain.d.mts +0 -169
  402. package/dist/jsonRpc/types/chain.d.mts.map +0 -1
  403. package/dist/jsonRpc/types/changes.d.mts +0 -48
  404. package/dist/jsonRpc/types/changes.d.mts.map +0 -1
  405. package/dist/jsonRpc/types/coins.d.mts +0 -15
  406. package/dist/jsonRpc/types/coins.d.mts.map +0 -1
  407. package/dist/jsonRpc/types/common.d.mts +0 -9
  408. package/dist/jsonRpc/types/common.d.mts.map +0 -1
  409. package/dist/jsonRpc/types/generated.d.mts +0 -1976
  410. package/dist/jsonRpc/types/generated.d.mts.map +0 -1
  411. package/dist/jsonRpc/types/index.d.mts +0 -6
  412. package/dist/jsonRpc/types/params.d.mts +0 -898
  413. package/dist/jsonRpc/types/params.d.mts.map +0 -1
  414. package/src/graphql/generated/tsconfig.tada.json +0 -11
  415. package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -15
  416. package/src/jsonRpc/client.ts +0 -1252
  417. package/src/jsonRpc/core.ts +0 -1557
  418. package/src/jsonRpc/errors.ts +0 -57
  419. package/src/jsonRpc/http-transport.ts +0 -118
  420. package/src/jsonRpc/network.ts +0 -21
  421. package/src/jsonRpc/types/chain.ts +0 -190
  422. package/src/jsonRpc/types/changes.ts +0 -35
  423. package/src/jsonRpc/types/coins.ts +0 -14
  424. package/src/jsonRpc/types/common.ts +0 -8
  425. package/src/jsonRpc/types/generated.ts +0 -2165
  426. package/src/jsonRpc/types/index.ts +0 -9
  427. package/src/jsonRpc/types/params.ts +0 -908
@@ -1,1557 +0,0 @@
1
- // Copyright (c) Mysten Labs, Inc.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { fromBase58, fromBase64, type InferBcsInput } from '@mysten/bcs';
5
-
6
- import { bcs, TypeTagSerializer } from '../bcs/index.js';
7
- import type {
8
- DevInspectResults,
9
- DryRunTransactionBlockResponse,
10
- EventId,
11
- ExecutionStatus as JsonRpcExecutionStatus,
12
- ObjectOwner,
13
- ObjectResponseError,
14
- SuiMoveAbilitySet,
15
- SuiMoveAbort,
16
- SuiMoveNormalizedType,
17
- SuiMoveVisibility,
18
- SuiObjectChange,
19
- SuiObjectData,
20
- SuiObjectDataFilter,
21
- SuiTransactionBlockResponse,
22
- TransactionEffects,
23
- } from './types/index.js';
24
- import {
25
- resolveEventFilter,
26
- resolvePagination,
27
- resolveTransactionFilter,
28
- validateTransactionQuery,
29
- } from '../client/query-filters.js';
30
- import { raceSignal } from '../client/mvr.js';
31
- import { Transaction } from '../transactions/Transaction.js';
32
- import { computeGasBudget, coreClientResolveTransactionPlugin } from '../client/core-resolver.js';
33
- import { TransactionDataBuilder } from '../transactions/TransactionData.js';
34
- import { chunk } from '@mysten/utils';
35
- import { normalizeSuiAddress, normalizeStructTag } from '../utils/sui-types.js';
36
- import { deriveDynamicFieldID } from '../utils/dynamic-fields.js';
37
- import { SUI_FRAMEWORK_ADDRESS, SUI_SYSTEM_ADDRESS } from '../utils/constants.js';
38
- import { CoreClient } from '../client/core.js';
39
- import type { SuiClientTypes } from '../client/types.js';
40
- import { ObjectError, TransactionError } from '../client/errors.js';
41
- import {
42
- formatMoveAbortMessage,
43
- parseTransactionBcs,
44
- parseTransactionEffectsBcs,
45
- } from '../client/index.js';
46
- import { isMockedGasObjectId } from '../client/utils.js';
47
- import type { SuiJsonRpcClient } from './client.js';
48
- import { JsonRpcError } from './errors.js';
49
-
50
- const MAX_GAS = 50_000_000_000;
51
-
52
- function mapJsonRpcObjectError(
53
- response: ObjectResponseError,
54
- requestedObjectId?: string,
55
- ): ObjectError {
56
- switch (response.code) {
57
- case 'notExists':
58
- return new ObjectError(response.code, `Object ${response.object_id} does not exist`, {
59
- cause: response,
60
- reason: 'notFound',
61
- objectId: requestedObjectId ?? response.object_id,
62
- });
63
- case 'dynamicFieldNotFound':
64
- return new ObjectError(
65
- response.code,
66
- `Dynamic field not found for object ${response.parent_object_id}`,
67
- {
68
- cause: response,
69
- reason: 'notFound',
70
- objectId: requestedObjectId ?? response.parent_object_id,
71
- },
72
- );
73
- case 'deleted':
74
- return new ObjectError(response.code, `Object ${response.object_id} has been deleted`, {
75
- cause: response,
76
- reason: 'deleted',
77
- objectId: requestedObjectId ?? response.object_id,
78
- });
79
- case 'displayError':
80
- return new ObjectError(response.code, `Display error: ${response.error}`, {
81
- cause: response,
82
- reason: 'unknown',
83
- objectId: requestedObjectId,
84
- });
85
- case 'unknown':
86
- default:
87
- return new ObjectError(
88
- response.code,
89
- `Unknown error while loading object${requestedObjectId ? ` ${requestedObjectId}` : ''}`,
90
- {
91
- cause: response,
92
- reason: 'unknown',
93
- objectId: requestedObjectId,
94
- },
95
- );
96
- }
97
- }
98
-
99
- function isJsonRpcTransactionNotFound(error: unknown, digest: string): boolean {
100
- if (!(error instanceof JsonRpcError) || error.code !== -32602) return false;
101
-
102
- return (
103
- error.message === `Invalid Params: Transaction ${digest} not found` ||
104
- error.message === `Could not find the referenced transaction [TransactionDigest(${digest})].`
105
- );
106
- }
107
-
108
- function parseJsonRpcExecutionStatus(
109
- status: JsonRpcExecutionStatus,
110
- abortError?: SuiMoveAbort | null,
111
- ): SuiClientTypes.ExecutionStatus {
112
- if (status.status === 'success') {
113
- return { success: true, error: null };
114
- }
115
-
116
- const rawMessage = status.error ?? 'Unknown';
117
-
118
- if (abortError) {
119
- const commandMatch = rawMessage.match(/in command (\d+)/);
120
- const command = commandMatch ? parseInt(commandMatch[1], 10) : undefined;
121
-
122
- const instructionMatch = rawMessage.match(/instruction:\s*(\d+)/);
123
- const instruction = instructionMatch ? parseInt(instructionMatch[1], 10) : undefined;
124
-
125
- const moduleParts = abortError.module_id?.split('::') ?? [];
126
- const pkg = moduleParts[0] ? normalizeSuiAddress(moduleParts[0]) : undefined;
127
- const module = moduleParts[1];
128
-
129
- return {
130
- success: false,
131
- error: {
132
- $kind: 'MoveAbort',
133
- message: formatMoveAbortMessage({
134
- command,
135
- location:
136
- pkg && module
137
- ? {
138
- package: pkg,
139
- module,
140
- functionName: abortError.function ?? undefined,
141
- instruction,
142
- }
143
- : undefined,
144
- abortCode: String(abortError.error_code ?? 0),
145
- cleverError: abortError.line != null ? { lineNumber: abortError.line } : undefined,
146
- }),
147
- command,
148
- MoveAbort: {
149
- abortCode: String(abortError.error_code ?? 0),
150
- location: abortError.module_id
151
- ? {
152
- package: normalizeSuiAddress(abortError.module_id.split('::')[0] ?? ''),
153
- module: abortError.module_id.split('::')[1] ?? '',
154
- functionName: abortError.function ?? undefined,
155
- instruction,
156
- }
157
- : undefined,
158
- },
159
- },
160
- };
161
- }
162
-
163
- return {
164
- success: false,
165
- error: {
166
- $kind: 'Unknown',
167
- message: rawMessage,
168
- Unknown: null,
169
- },
170
- };
171
- }
172
-
173
- /**
174
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
175
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
176
- */
177
- export class JSONRpcCoreClient extends CoreClient {
178
- #jsonRpcClient: SuiJsonRpcClient;
179
-
180
- /**
181
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
182
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
183
- */
184
- constructor({
185
- jsonRpcClient,
186
- mvr,
187
- }: {
188
- jsonRpcClient: SuiJsonRpcClient;
189
- mvr?: SuiClientTypes.MvrOptions;
190
- }) {
191
- super({ network: jsonRpcClient.network, base: jsonRpcClient, mvr });
192
- this.#jsonRpcClient = jsonRpcClient;
193
- }
194
-
195
- /**
196
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
197
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
198
- */
199
- async getObjects<Include extends SuiClientTypes.ObjectInclude = {}>(
200
- options: SuiClientTypes.GetObjectsOptions<Include>,
201
- ) {
202
- const batches = chunk(options.objectIds, 50);
203
- const results: SuiClientTypes.GetObjectsResponse<Include>['objects'] = [];
204
- for (const batch of batches) {
205
- const objects = await this.#jsonRpcClient.multiGetObjects({
206
- ids: batch,
207
- options: {
208
- showOwner: true,
209
- showType: true,
210
- showBcs: options.include?.content || options.include?.objectBcs ? true : false,
211
- showPreviousTransaction:
212
- options.include?.previousTransaction || options.include?.objectBcs ? true : false,
213
- showStorageRebate: options.include?.objectBcs ?? false,
214
- showContent: options.include?.json ?? false,
215
- showDisplay: options.include?.display ?? false,
216
- },
217
- signal: options.signal,
218
- });
219
-
220
- for (const [idx, object] of objects.entries()) {
221
- if (object.error) {
222
- results.push(mapJsonRpcObjectError(object.error, batch[idx]));
223
- } else {
224
- results.push(parseObject(object.data!, options.include));
225
- }
226
- }
227
- }
228
-
229
- return {
230
- objects: results,
231
- };
232
- }
233
- /**
234
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
235
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
236
- */
237
- async listOwnedObjects<Include extends SuiClientTypes.ObjectInclude = {}>(
238
- options: SuiClientTypes.ListOwnedObjectsOptions<Include>,
239
- ) {
240
- let filter: SuiObjectDataFilter | null = null;
241
- if (options.type) {
242
- const parts = options.type.split('::');
243
- if (parts.length === 1) {
244
- filter = { Package: options.type };
245
- } else if (parts.length === 2) {
246
- filter = { MoveModule: { package: parts[0], module: parts[1] } };
247
- } else {
248
- filter = { StructType: options.type };
249
- }
250
- }
251
-
252
- const objects = await this.#jsonRpcClient.getOwnedObjects({
253
- owner: options.owner,
254
- limit: options.limit,
255
- cursor: options.cursor,
256
- options: {
257
- showOwner: true,
258
- showType: true,
259
- showBcs: options.include?.content || options.include?.objectBcs ? true : false,
260
- showPreviousTransaction:
261
- options.include?.previousTransaction || options.include?.objectBcs ? true : false,
262
- showStorageRebate: options.include?.objectBcs ?? false,
263
- showContent: options.include?.json ?? false,
264
- showDisplay: options.include?.display ?? false,
265
- },
266
- filter,
267
- signal: options.signal,
268
- });
269
-
270
- return {
271
- objects: objects.data.map((result) => {
272
- if (result.error) {
273
- throw mapJsonRpcObjectError(result.error);
274
- }
275
-
276
- return parseObject(result.data!, options.include);
277
- }),
278
- hasNextPage: objects.hasNextPage,
279
- cursor: objects.nextCursor ?? null,
280
- };
281
- }
282
-
283
- /**
284
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
285
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
286
- */
287
- async listCoins(options: SuiClientTypes.ListCoinsOptions) {
288
- const coins = await this.#jsonRpcClient.getCoins({
289
- owner: options.owner,
290
- coinType: options.coinType,
291
- limit: options.limit,
292
- cursor: options.cursor,
293
- signal: options.signal,
294
- });
295
-
296
- return {
297
- objects: coins.data.map((coin): SuiClientTypes.Coin => ({
298
- objectId: coin.coinObjectId,
299
- version: coin.version,
300
- digest: coin.digest,
301
- balance: coin.balance,
302
- type: normalizeStructTag(`0x2::coin::Coin<${coin.coinType}>`),
303
- owner: {
304
- $kind: 'AddressOwner' as const,
305
- AddressOwner: options.owner,
306
- },
307
- })),
308
- hasNextPage: coins.hasNextPage,
309
- cursor: coins.nextCursor ?? null,
310
- };
311
- }
312
-
313
- /**
314
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
315
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
316
- */
317
- async getBalance(options: SuiClientTypes.GetBalanceOptions) {
318
- const balance = await this.#jsonRpcClient.getBalance({
319
- owner: options.owner,
320
- coinType: options.coinType,
321
- signal: options.signal,
322
- });
323
-
324
- const addressBalance = balance.fundsInAddressBalance ?? '0';
325
- const coinBalance = String(BigInt(balance.totalBalance) - BigInt(addressBalance));
326
-
327
- return {
328
- balance: {
329
- coinType: normalizeStructTag(balance.coinType),
330
- balance: balance.totalBalance,
331
- coinBalance,
332
- addressBalance,
333
- },
334
- };
335
- }
336
- /**
337
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
338
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
339
- */
340
- async getCoinMetadata(
341
- options: SuiClientTypes.GetCoinMetadataOptions,
342
- ): Promise<SuiClientTypes.GetCoinMetadataResponse> {
343
- const coinType = (
344
- await this.mvr.resolveType({ type: options.coinType, signal: options.signal })
345
- ).type;
346
-
347
- const result = await this.#jsonRpcClient.getCoinMetadata({
348
- coinType,
349
- signal: options.signal,
350
- });
351
-
352
- if (!result) {
353
- return { coinMetadata: null };
354
- }
355
-
356
- return {
357
- coinMetadata: {
358
- id: result.id ?? null,
359
- decimals: result.decimals,
360
- name: result.name,
361
- symbol: result.symbol,
362
- description: result.description,
363
- iconUrl: result.iconUrl ?? null,
364
- },
365
- };
366
- }
367
-
368
- /**
369
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
370
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
371
- */
372
- async listBalances(options: SuiClientTypes.ListBalancesOptions) {
373
- const balances = await this.#jsonRpcClient.getAllBalances({
374
- owner: options.owner,
375
- signal: options.signal,
376
- });
377
-
378
- return {
379
- balances: balances.map((balance) => {
380
- const addressBalance = balance.fundsInAddressBalance ?? '0';
381
- const coinBalance = String(BigInt(balance.totalBalance) - BigInt(addressBalance));
382
- return {
383
- coinType: normalizeStructTag(balance.coinType),
384
- balance: balance.totalBalance,
385
- coinBalance,
386
- addressBalance,
387
- };
388
- }),
389
- hasNextPage: false,
390
- cursor: null,
391
- };
392
- }
393
- /**
394
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
395
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
396
- */
397
- async getTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
398
- options: SuiClientTypes.GetTransactionOptions<Include>,
399
- ): Promise<SuiClientTypes.TransactionResult<Include>> {
400
- try {
401
- const transaction = await this.#jsonRpcClient.getTransactionBlock({
402
- digest: options.digest,
403
- options: {
404
- // showRawInput is always needed to extract signatures from SenderSignedData
405
- showRawInput: true,
406
- // showEffects is always needed to get status
407
- showEffects: true,
408
- showObjectChanges: options.include?.objectTypes ?? false,
409
- showRawEffects: options.include?.effects ?? false,
410
- showEvents: options.include?.events ?? false,
411
- showBalanceChanges: options.include?.balanceChanges ?? false,
412
- },
413
- signal: options.signal,
414
- });
415
-
416
- return parseTransaction(transaction, options.include);
417
- } catch (error) {
418
- if (isJsonRpcTransactionNotFound(error, options.digest)) {
419
- throw new TransactionError('notFound', options.digest, { cause: error });
420
- }
421
- throw error;
422
- }
423
- }
424
- /**
425
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
426
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
427
- */
428
- async executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
429
- options: SuiClientTypes.ExecuteTransactionOptions<Include>,
430
- ): Promise<SuiClientTypes.TransactionResult<Include>> {
431
- const transaction = await this.#jsonRpcClient.executeTransactionBlock({
432
- transactionBlock: options.transaction,
433
- signature: options.signatures,
434
- options: {
435
- // showRawInput is always needed to extract signatures from SenderSignedData
436
- showRawInput: true,
437
- // showEffects is always needed to get status
438
- showEffects: true,
439
- showRawEffects: options.include?.effects ?? false,
440
- showEvents: options.include?.events ?? false,
441
- showObjectChanges: options.include?.objectTypes ?? false,
442
- showBalanceChanges: options.include?.balanceChanges ?? false,
443
- },
444
- signal: options.signal,
445
- });
446
-
447
- return parseTransaction(transaction, options.include);
448
- }
449
- /**
450
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
451
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
452
- */
453
- async simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude = {}>(
454
- options: SuiClientTypes.SimulateTransactionOptions<Include>,
455
- ): Promise<SuiClientTypes.SimulateTransactionResult<Include>> {
456
- if (!(options.transaction instanceof Uint8Array)) {
457
- await options.transaction.build({ client: this, onlyTransactionKind: true });
458
- }
459
-
460
- const tx = Transaction.from(options.transaction);
461
-
462
- const data =
463
- options.transaction instanceof Uint8Array
464
- ? null
465
- : TransactionDataBuilder.restore(options.transaction.getData());
466
-
467
- const transactionBytes = data
468
- ? data.build({
469
- overrides: {
470
- gasData: {
471
- budget: data.gasData.budget ?? String(MAX_GAS),
472
- price:
473
- data.gasData.price ??
474
- String(await this.#jsonRpcClient.getReferenceGasPrice({ signal: options.signal })),
475
- payment: data.gasData.payment ?? [],
476
- },
477
- },
478
- })
479
- : (options.transaction as Uint8Array);
480
-
481
- const sender = tx.getData().sender ?? normalizeSuiAddress('0x0');
482
- const checksDisabled = options.checksEnabled === false;
483
-
484
- let dryRunResult: DryRunTransactionBlockResponse | null = null;
485
- try {
486
- dryRunResult = await this.#jsonRpcClient.dryRunTransactionBlock({
487
- transactionBlock: transactionBytes,
488
- signal: options.signal,
489
- });
490
- } catch (e) {
491
- if (!checksDisabled) {
492
- throw e;
493
- }
494
- }
495
-
496
- let devInspectResult: DevInspectResults | null = null;
497
- if (options.include?.commandResults || checksDisabled) {
498
- try {
499
- devInspectResult = await this.#jsonRpcClient.devInspectTransactionBlock({
500
- sender,
501
- transactionBlock: tx,
502
- signal: options.signal,
503
- });
504
- } catch {}
505
- }
506
-
507
- const dryRunFailed = !dryRunResult || dryRunResult.effects.status.status !== 'success';
508
- const effectsSource =
509
- checksDisabled && dryRunFailed && devInspectResult
510
- ? devInspectResult
511
- : (dryRunResult ?? devInspectResult);
512
- if (!effectsSource) {
513
- throw new Error('simulateTransaction failed: no results from dryRun or devInspect');
514
- }
515
-
516
- const { effects, objectTypes } = parseTransactionEffectsJson({
517
- effects: effectsSource.effects,
518
- objectChanges: (!dryRunFailed ? dryRunResult?.objectChanges : null) ?? [],
519
- });
520
-
521
- let parsedTransaction: SuiClientTypes.TransactionData | undefined;
522
- if (options.include?.transaction) {
523
- parsedTransaction = parseTransactionBcs(transactionBytes);
524
- if (data && !dryRunFailed && effects.gasUsed) {
525
- if (!data.gasData.budget) {
526
- parsedTransaction.gasData.budget = computeGasBudget(effects.gasUsed);
527
- }
528
- }
529
- }
530
-
531
- const transactionData: SuiClientTypes.Transaction<Include> = {
532
- digest: TransactionDataBuilder.getDigestFromBytes(transactionBytes),
533
- epoch: null,
534
- timestampMs: null,
535
- checkpoint: null,
536
- status: effects.status,
537
- effects: (options.include?.effects
538
- ? effects
539
- : undefined) as SuiClientTypes.Transaction<Include>['effects'],
540
- objectTypes: (options.include?.objectTypes
541
- ? objectTypes
542
- : undefined) as SuiClientTypes.Transaction<Include>['objectTypes'],
543
- signatures: [],
544
- transaction: (parsedTransaction ??
545
- undefined) as SuiClientTypes.Transaction<Include>['transaction'],
546
- bcs: (options.include?.bcs
547
- ? transactionBytes
548
- : undefined) as SuiClientTypes.Transaction<Include>['bcs'],
549
- balanceChanges: (options.include?.balanceChanges && dryRunResult && !dryRunFailed
550
- ? dryRunResult.balanceChanges.map((change) => ({
551
- coinType: normalizeStructTag(change.coinType),
552
- address: parseOwnerAddress(change.owner)!,
553
- amount: change.amount,
554
- }))
555
- : undefined) as SuiClientTypes.Transaction<Include>['balanceChanges'],
556
- events: (options.include?.events
557
- ? (effectsSource.events?.map((event) => ({
558
- packageId: event.packageId,
559
- module: event.transactionModule,
560
- sender: event.sender,
561
- eventType: event.type,
562
- bcs: 'bcs' in event ? fromBase64(event.bcs) : new Uint8Array(),
563
- json: (event.parsedJson as Record<string, unknown>) ?? null,
564
- })) ?? [])
565
- : undefined) as SuiClientTypes.Transaction<Include>['events'],
566
- };
567
-
568
- let commandResults: SuiClientTypes.CommandResult[] | undefined;
569
- if (options.include?.commandResults && devInspectResult?.results) {
570
- commandResults = devInspectResult.results.map((result) => ({
571
- returnValues: (result.returnValues ?? []).map(([bytes]) => ({
572
- bcs: new Uint8Array(bytes),
573
- })),
574
- mutatedReferences: (result.mutableReferenceOutputs ?? []).map(([, bytes]) => ({
575
- bcs: new Uint8Array(bytes),
576
- })),
577
- }));
578
- }
579
-
580
- const gasPaymentMocked = isMockedGasObjectId(effects.gasObject?.objectId);
581
-
582
- return effects.status.success
583
- ? {
584
- $kind: 'Transaction',
585
- Transaction: transactionData,
586
- commandResults:
587
- commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
588
- gasPaymentMocked,
589
- }
590
- : {
591
- $kind: 'FailedTransaction',
592
- FailedTransaction: transactionData,
593
- commandResults:
594
- commandResults as SuiClientTypes.SimulateTransactionResult<Include>['commandResults'],
595
- gasPaymentMocked,
596
- };
597
- }
598
- /**
599
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
600
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
601
- */
602
- async getReferenceGasPrice(options?: SuiClientTypes.GetReferenceGasPriceOptions) {
603
- const referenceGasPrice = await this.#jsonRpcClient.getReferenceGasPrice({
604
- signal: options?.signal,
605
- });
606
-
607
- return {
608
- referenceGasPrice: String(referenceGasPrice),
609
- };
610
- }
611
-
612
- /**
613
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
614
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
615
- */
616
- async getProtocolConfig(
617
- options?: SuiClientTypes.GetProtocolConfigOptions,
618
- ): Promise<SuiClientTypes.GetProtocolConfigResponse> {
619
- const result = await this.#jsonRpcClient.getProtocolConfig({ signal: options?.signal });
620
-
621
- const attributes: Record<string, string | null> = {};
622
- for (const [key, value] of Object.entries(result.attributes)) {
623
- if (value === null) {
624
- attributes[key] = null;
625
- } else if ('u16' in value) {
626
- attributes[key] = value.u16;
627
- } else if ('u32' in value) {
628
- attributes[key] = value.u32;
629
- } else if ('u64' in value) {
630
- attributes[key] = value.u64;
631
- } else if ('f64' in value) {
632
- attributes[key] = value.f64;
633
- } else if ('bool' in value) {
634
- attributes[key] = value.bool;
635
- } else {
636
- const entries = Object.entries(value);
637
- attributes[key] = entries.length === 1 ? String(entries[0][1]) : JSON.stringify(value);
638
- }
639
- }
640
-
641
- return {
642
- protocolConfig: {
643
- protocolVersion: result.protocolVersion,
644
- featureFlags: { ...result.featureFlags },
645
- attributes,
646
- },
647
- };
648
- }
649
-
650
- /**
651
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
652
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
653
- */
654
- async getCurrentSystemState(
655
- options?: SuiClientTypes.GetCurrentSystemStateOptions,
656
- ): Promise<SuiClientTypes.GetCurrentSystemStateResponse> {
657
- const systemState = await this.#jsonRpcClient.getLatestSuiSystemState({
658
- signal: options?.signal,
659
- });
660
-
661
- return {
662
- systemState: {
663
- systemStateVersion: systemState.systemStateVersion,
664
- epoch: systemState.epoch,
665
- protocolVersion: systemState.protocolVersion,
666
- referenceGasPrice: systemState.referenceGasPrice?.toString() ?? (null as never),
667
- epochStartTimestampMs: systemState.epochStartTimestampMs,
668
- safeMode: systemState.safeMode,
669
- safeModeStorageRewards: systemState.safeModeStorageRewards,
670
- safeModeComputationRewards: systemState.safeModeComputationRewards,
671
- safeModeStorageRebates: systemState.safeModeStorageRebates,
672
- safeModeNonRefundableStorageFee: systemState.safeModeNonRefundableStorageFee,
673
- parameters: {
674
- epochDurationMs: systemState.epochDurationMs,
675
- stakeSubsidyStartEpoch: systemState.stakeSubsidyStartEpoch,
676
- maxValidatorCount: systemState.maxValidatorCount,
677
- minValidatorJoiningStake: systemState.minValidatorJoiningStake,
678
- validatorLowStakeThreshold: systemState.validatorLowStakeThreshold,
679
- validatorLowStakeGracePeriod: systemState.validatorLowStakeGracePeriod,
680
- },
681
- storageFund: {
682
- totalObjectStorageRebates: systemState.storageFundTotalObjectStorageRebates,
683
- nonRefundableBalance: systemState.storageFundNonRefundableBalance,
684
- },
685
- stakeSubsidy: {
686
- balance: systemState.stakeSubsidyBalance,
687
- distributionCounter: systemState.stakeSubsidyDistributionCounter,
688
- currentDistributionAmount: systemState.stakeSubsidyCurrentDistributionAmount,
689
- stakeSubsidyPeriodLength: systemState.stakeSubsidyPeriodLength,
690
- stakeSubsidyDecreaseRate: systemState.stakeSubsidyDecreaseRate,
691
- },
692
- },
693
- };
694
- }
695
-
696
- /**
697
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
698
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
699
- */
700
- async listDynamicFields(options: SuiClientTypes.ListDynamicFieldsOptions) {
701
- const dynamicFields = await this.#jsonRpcClient.getDynamicFields({
702
- parentId: options.parentId,
703
- limit: options.limit,
704
- cursor: options.cursor,
705
- signal: options.signal,
706
- });
707
-
708
- return {
709
- dynamicFields: dynamicFields.data.map((dynamicField): SuiClientTypes.DynamicFieldEntry => {
710
- const isDynamicObject = dynamicField.type === 'DynamicObject';
711
- const fullType = isDynamicObject
712
- ? `0x2::dynamic_field::Field<0x2::dynamic_object_field::Wrapper<${dynamicField.name.type}>, 0x2::object::ID>`
713
- : `0x2::dynamic_field::Field<${dynamicField.name.type}, ${dynamicField.objectType}>`;
714
-
715
- const bcsBytes = fromBase64(dynamicField.bcsName);
716
- const derivedNameType = isDynamicObject
717
- ? `0x2::dynamic_object_field::Wrapper<${dynamicField.name.type}>`
718
- : dynamicField.name.type;
719
- return {
720
- $kind: isDynamicObject ? 'DynamicObject' : 'DynamicField',
721
- fieldId: deriveDynamicFieldID(options.parentId, derivedNameType, bcsBytes),
722
- type: normalizeStructTag(fullType),
723
- name: {
724
- type: dynamicField.name.type,
725
- bcs: bcsBytes,
726
- },
727
- valueType: dynamicField.objectType,
728
- childId: isDynamicObject ? dynamicField.objectId : undefined,
729
- } as SuiClientTypes.DynamicFieldEntry;
730
- }),
731
- hasNextPage: dynamicFields.hasNextPage,
732
- cursor: dynamicFields.nextCursor,
733
- };
734
- }
735
-
736
- /**
737
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
738
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
739
- */
740
- async listTransactions<Include extends SuiClientTypes.TransactionInclude = {}>(
741
- options: SuiClientTypes.ListTransactionsOptions<Include>,
742
- ): Promise<SuiClientTypes.ListTransactionsResponse<Include>> {
743
- const filter = options.filter
744
- ? await resolveTransactionFilter(this.mvr, options.filter, options.signal)
745
- : undefined;
746
-
747
- // Transaction cursors are digests, and bounds are interpreted relative to the
748
- // traversal direction
749
- const pagination = resolvePagination(options);
750
- const { descending, after, before } = pagination;
751
- validateTransactionQuery(filter, pagination);
752
-
753
- const page = await this.#jsonRpcClient.queryTransactionBlocks({
754
- filter:
755
- filter &&
756
- (filter.$kind === 'sender'
757
- ? { FromAddress: filter.sender }
758
- : {
759
- MoveFunction: {
760
- package: filter.package,
761
- module: filter.module ?? null,
762
- function: filter.function ?? null,
763
- },
764
- }),
765
- cursor: after ?? before,
766
- limit: pagination.limit,
767
- order: descending ? 'descending' : 'ascending',
768
- options: {
769
- // showRawInput is always needed to extract signatures from SenderSignedData
770
- showRawInput: true,
771
- // showEffects is always needed to get status
772
- showEffects: true,
773
- showObjectChanges: options.include?.objectTypes ?? false,
774
- showRawEffects: options.include?.effects ?? false,
775
- showEvents: options.include?.events ?? false,
776
- showBalanceChanges: options.include?.balanceChanges ?? false,
777
- },
778
- signal: options.signal,
779
- });
780
-
781
- return {
782
- transactions: page.data.map((transaction) => parseTransaction(transaction, options.include)),
783
- hasNextPage: page.hasNextPage,
784
- startCursor: page.data[0]?.digest ?? null,
785
- endCursor: page.data.length
786
- ? (page.nextCursor ?? page.data[page.data.length - 1].digest)
787
- : null,
788
- };
789
- }
790
-
791
- /**
792
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
793
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
794
- */
795
- async listEvents(
796
- options: SuiClientTypes.ListEventsOptions,
797
- ): Promise<SuiClientTypes.ListEventsResponse> {
798
- const filter = options.filter
799
- ? await resolveEventFilter(this.mvr, options.filter, options.signal)
800
- : undefined;
801
- // Event cursors are event ids, and bounds are interpreted relative to the
802
- // traversal direction
803
- const { descending, after, before, limit } = resolvePagination(options);
804
- const cursor = after ?? before;
805
-
806
- const page = await this.#jsonRpcClient.queryEvents({
807
- query: !filter
808
- ? { All: [] }
809
- : filter.$kind === 'sender'
810
- ? { Sender: filter.sender }
811
- : filter.$kind === 'emitModule'
812
- ? { MoveModule: { package: filter.package, module: filter.module } }
813
- : filter.$kind === 'eventTypeModule'
814
- ? { MoveEventModule: { package: filter.package, module: filter.module } }
815
- : { MoveEventType: filter.eventType },
816
- cursor: cursor ? parseEventCursor(cursor) : undefined,
817
- limit,
818
- order: descending ? 'descending' : 'ascending',
819
- signal: options.signal,
820
- });
821
-
822
- return {
823
- events: page.data.map((event): SuiClientTypes.EventEntry => ({
824
- packageId: normalizeSuiAddress(event.packageId),
825
- module: event.transactionModule,
826
- sender: normalizeSuiAddress(event.sender),
827
- eventType: normalizeStructTag(event.type),
828
- bcs: event.bcsEncoding === 'base58' ? fromBase58(event.bcs) : fromBase64(event.bcs),
829
- json: (event.parsedJson as Record<string, unknown>) ?? null,
830
- // queryEvents responses do not include checkpoint information
831
- checkpoint: null,
832
- transactionDigest: event.id.txDigest,
833
- eventIndex: Number(event.id.eventSeq),
834
- })),
835
- hasNextPage: page.hasNextPage,
836
- startCursor: page.data.length ? JSON.stringify(page.data[0].id) : null,
837
- endCursor:
838
- page.data.length && page.nextCursor
839
- ? JSON.stringify(page.nextCursor)
840
- : page.data.length
841
- ? JSON.stringify(page.data[page.data.length - 1].id)
842
- : null,
843
- };
844
- }
845
-
846
- /**
847
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
848
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
849
- */
850
- async verifyZkLoginSignature(options: SuiClientTypes.VerifyZkLoginSignatureOptions) {
851
- const result = await this.#jsonRpcClient.verifyZkLoginSignature({
852
- signal: options.signal,
853
- bytes: options.bytes,
854
- signature: options.signature,
855
- intentScope: options.intentScope,
856
- author: options.address,
857
- });
858
-
859
- return {
860
- success: result.success,
861
- errors: result.errors,
862
- };
863
- }
864
-
865
- /**
866
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
867
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
868
- */
869
- async defaultNameServiceName(
870
- options: SuiClientTypes.DefaultNameServiceNameOptions,
871
- ): Promise<SuiClientTypes.DefaultNameServiceNameResponse> {
872
- const name = (await this.#jsonRpcClient.resolveNameServiceNames(options)).data[0] ?? null;
873
- return {
874
- data: {
875
- name,
876
- },
877
- };
878
- }
879
-
880
- /**
881
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
882
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
883
- */
884
- async resolveNameServiceAddress(
885
- options: SuiClientTypes.ResolveNameServiceAddressOptions,
886
- ): Promise<SuiClientTypes.ResolveNameServiceAddressResponse> {
887
- return {
888
- address: await this.#jsonRpcClient.resolveNameServiceAddress(options),
889
- };
890
- }
891
-
892
- /**
893
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
894
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
895
- */
896
- resolveTransactionPlugin() {
897
- return coreClientResolveTransactionPlugin;
898
- }
899
-
900
- /**
901
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
902
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
903
- */
904
- async getMoveFunction(
905
- options: SuiClientTypes.GetMoveFunctionOptions,
906
- ): Promise<SuiClientTypes.GetMoveFunctionResponse> {
907
- const resolvedPackageId = (
908
- await this.mvr.resolvePackage({ package: options.packageId, signal: options.signal })
909
- ).package;
910
- const result = await this.#jsonRpcClient.getNormalizedMoveFunction({
911
- package: resolvedPackageId,
912
- module: options.moduleName,
913
- function: options.name,
914
- signal: options.signal,
915
- });
916
-
917
- return {
918
- function: {
919
- packageId: normalizeSuiAddress(resolvedPackageId),
920
- moduleName: options.moduleName,
921
- name: options.name,
922
- visibility: parseVisibility(result.visibility),
923
- isEntry: result.isEntry,
924
- typeParameters: result.typeParameters.map((abilities) => ({
925
- isPhantom: false,
926
- constraints: parseAbilities(abilities),
927
- })),
928
- parameters: result.parameters.map((param) => parseNormalizedSuiMoveType(param)),
929
- returns: result.return.map((ret) => parseNormalizedSuiMoveType(ret)),
930
- },
931
- };
932
- }
933
-
934
- /**
935
- * @deprecated JSON-RPC APIs are deprecated in the Sui TypeScript SDK. Use `SuiGrpcClient`
936
- * from `@mysten/sui/grpc` or `SuiGraphQLClient` from `@mysten/sui/graphql` instead.
937
- */
938
- async getChainIdentifier(
939
- options?: SuiClientTypes.GetChainIdentifierOptions,
940
- ): Promise<SuiClientTypes.GetChainIdentifierResponse> {
941
- // The result is cached and shared across callers, so the underlying request must
942
- // not carry any single caller's signal. Isolate cancellation per-caller instead.
943
- const cached = this.cache.read(['chainIdentifier'], async () => {
944
- const checkpoint = await this.#jsonRpcClient.getCheckpoint({ id: '0' });
945
- return {
946
- chainIdentifier: checkpoint.digest,
947
- };
948
- });
949
-
950
- return raceSignal(Promise.resolve(cached), options?.signal);
951
- }
952
- }
953
-
954
- function serializeObjectToBcs(object: SuiObjectData): Uint8Array | undefined {
955
- if (object.bcs?.dataType !== 'moveObject') {
956
- return undefined;
957
- }
958
-
959
- try {
960
- // Normalize the type string to ensure consistent address formatting (0x2 vs 0x00...02)
961
- const typeStr = normalizeStructTag(object.bcs.type);
962
- let moveObjectType: InferBcsInput<typeof bcs.MoveObjectType>;
963
-
964
- // Normalize constants for comparison
965
- const normalizedSuiFramework = normalizeSuiAddress(SUI_FRAMEWORK_ADDRESS);
966
- const gasCoinType = normalizeStructTag(
967
- `${SUI_FRAMEWORK_ADDRESS}::coin::Coin<${SUI_FRAMEWORK_ADDRESS}::sui::SUI>`,
968
- );
969
- const stakedSuiType = normalizeStructTag(`${SUI_SYSTEM_ADDRESS}::staking_pool::StakedSui`);
970
- const coinPrefix = `${normalizedSuiFramework}::coin::Coin<`;
971
-
972
- if (typeStr === gasCoinType) {
973
- moveObjectType = { GasCoin: null };
974
- } else if (typeStr === stakedSuiType) {
975
- moveObjectType = { StakedSui: null };
976
- } else if (typeStr.startsWith(coinPrefix)) {
977
- const innerTypeMatch = typeStr.match(
978
- new RegExp(
979
- `${normalizedSuiFramework.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}::coin::Coin<(.+)>$`,
980
- ),
981
- );
982
- if (innerTypeMatch) {
983
- const innerTypeTag = TypeTagSerializer.parseFromStr(innerTypeMatch[1], true);
984
- moveObjectType = { Coin: innerTypeTag };
985
- } else {
986
- throw new Error('Failed to parse Coin type');
987
- }
988
- } else {
989
- const typeTag = TypeTagSerializer.parseFromStr(typeStr, true);
990
- if (typeof typeTag !== 'object' || !('struct' in typeTag)) {
991
- throw new Error('Expected struct type tag');
992
- }
993
- moveObjectType = { Other: typeTag.struct };
994
- }
995
-
996
- const contents = fromBase64(object.bcs.bcsBytes);
997
- const owner = convertOwnerToBcs(object.owner!);
998
-
999
- return bcs.Object.serialize({
1000
- data: {
1001
- Move: {
1002
- type: moveObjectType,
1003
- hasPublicTransfer: object.bcs.hasPublicTransfer,
1004
- version: object.bcs.version,
1005
- contents,
1006
- },
1007
- },
1008
- owner,
1009
- previousTransaction: object.previousTransaction!,
1010
- storageRebate: object.storageRebate!,
1011
- }).toBytes();
1012
- } catch {
1013
- // If serialization fails, return undefined
1014
- return undefined;
1015
- }
1016
- }
1017
-
1018
- function parseObject<Include extends SuiClientTypes.ObjectInclude = {}>(
1019
- object: SuiObjectData,
1020
- include?: Include,
1021
- ): SuiClientTypes.Object<Include> {
1022
- const bcsContent =
1023
- object.bcs?.dataType === 'moveObject' ? fromBase64(object.bcs.bcsBytes) : undefined;
1024
-
1025
- const objectBcs = include?.objectBcs ? serializeObjectToBcs(object) : undefined;
1026
-
1027
- // Package objects have type "package" which is not a struct tag, so don't normalize it
1028
- const type =
1029
- object.type && object.type.includes('::')
1030
- ? normalizeStructTag(object.type)
1031
- : (object.type ?? '');
1032
-
1033
- const jsonContent =
1034
- include?.json && object.content?.dataType === 'moveObject'
1035
- ? (object.content.fields as Record<string, unknown>)
1036
- : include?.json
1037
- ? null
1038
- : undefined;
1039
-
1040
- const displayData = include?.display
1041
- ? object.display?.data != null
1042
- ? { output: object.display.data as Record<string, unknown>, errors: null }
1043
- : null
1044
- : undefined;
1045
-
1046
- return {
1047
- objectId: object.objectId,
1048
- version: object.version,
1049
- digest: object.digest,
1050
- type,
1051
- content: (include?.content
1052
- ? bcsContent
1053
- : undefined) as SuiClientTypes.Object<Include>['content'],
1054
- owner: parseOwner(object.owner!),
1055
- previousTransaction: (include?.previousTransaction
1056
- ? (object.previousTransaction ?? undefined)
1057
- : undefined) as SuiClientTypes.Object<Include>['previousTransaction'],
1058
- objectBcs: objectBcs as SuiClientTypes.Object<Include>['objectBcs'],
1059
- json: jsonContent as SuiClientTypes.Object<Include>['json'],
1060
- display: displayData as SuiClientTypes.Object<Include>['display'],
1061
- };
1062
- }
1063
-
1064
- function parseOwner(owner: ObjectOwner): SuiClientTypes.ObjectOwner {
1065
- if (owner === 'Immutable') {
1066
- return {
1067
- $kind: 'Immutable',
1068
- Immutable: true,
1069
- };
1070
- }
1071
-
1072
- if ('ConsensusAddressOwner' in owner) {
1073
- return {
1074
- $kind: 'ConsensusAddressOwner',
1075
- ConsensusAddressOwner: {
1076
- owner: owner.ConsensusAddressOwner.owner,
1077
- startVersion: owner.ConsensusAddressOwner.start_version,
1078
- },
1079
- };
1080
- }
1081
-
1082
- if ('AddressOwner' in owner) {
1083
- return {
1084
- $kind: 'AddressOwner',
1085
- AddressOwner: owner.AddressOwner,
1086
- };
1087
- }
1088
-
1089
- if ('ObjectOwner' in owner) {
1090
- return {
1091
- $kind: 'ObjectOwner',
1092
- ObjectOwner: owner.ObjectOwner,
1093
- };
1094
- }
1095
-
1096
- if ('Shared' in owner) {
1097
- return {
1098
- $kind: 'Shared',
1099
- Shared: {
1100
- initialSharedVersion: owner.Shared.initial_shared_version,
1101
- },
1102
- };
1103
- }
1104
-
1105
- throw new Error(`Unknown owner type: ${JSON.stringify(owner)}`);
1106
- }
1107
-
1108
- function convertOwnerToBcs(owner: ObjectOwner) {
1109
- if (owner === 'Immutable') {
1110
- return { Immutable: null };
1111
- }
1112
-
1113
- if ('AddressOwner' in owner) {
1114
- return { AddressOwner: owner.AddressOwner };
1115
- }
1116
-
1117
- if ('ObjectOwner' in owner) {
1118
- return { ObjectOwner: owner.ObjectOwner };
1119
- }
1120
-
1121
- if ('Shared' in owner) {
1122
- return {
1123
- Shared: { initialSharedVersion: owner.Shared.initial_shared_version },
1124
- };
1125
- }
1126
-
1127
- if (typeof owner === 'object' && owner !== null && 'ConsensusAddressOwner' in owner) {
1128
- return {
1129
- ConsensusAddressOwner: {
1130
- startVersion: owner.ConsensusAddressOwner.start_version,
1131
- owner: owner.ConsensusAddressOwner.owner,
1132
- },
1133
- };
1134
- }
1135
-
1136
- throw new Error(`Unknown owner type: ${JSON.stringify(owner)}`);
1137
- }
1138
-
1139
- function parseOwnerAddress(owner: ObjectOwner): string | null {
1140
- if (owner === 'Immutable') {
1141
- return null;
1142
- }
1143
-
1144
- if ('ConsensusAddressOwner' in owner) {
1145
- return owner.ConsensusAddressOwner.owner;
1146
- }
1147
-
1148
- if ('AddressOwner' in owner) {
1149
- return owner.AddressOwner;
1150
- }
1151
-
1152
- if ('ObjectOwner' in owner) {
1153
- return owner.ObjectOwner;
1154
- }
1155
-
1156
- if ('Shared' in owner) {
1157
- return null;
1158
- }
1159
-
1160
- throw new Error(`Unknown owner type: ${JSON.stringify(owner)}`);
1161
- }
1162
-
1163
- function parseEventCursor(cursor: string): EventId {
1164
- try {
1165
- const parsed = JSON.parse(cursor) as EventId;
1166
- if (typeof parsed?.txDigest !== 'string' || typeof parsed?.eventSeq !== 'string') {
1167
- throw new Error('malformed event cursor');
1168
- }
1169
- return parsed;
1170
- } catch {
1171
- throw new Error(`Invalid event cursor: ${cursor}`);
1172
- }
1173
- }
1174
-
1175
- function parseTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
1176
- transaction: SuiTransactionBlockResponse,
1177
- include?: Include,
1178
- ): SuiClientTypes.TransactionResult<Include> {
1179
- const objectTypes: Record<string, string> = {};
1180
-
1181
- if (include?.objectTypes) {
1182
- transaction.objectChanges?.forEach((change) => {
1183
- if (change.type !== 'published') {
1184
- objectTypes[change.objectId] = normalizeStructTag(change.objectType);
1185
- }
1186
- });
1187
- }
1188
-
1189
- let transactionData: SuiClientTypes.TransactionData | undefined;
1190
- let signatures: string[] = [];
1191
- let bcsBytes: Uint8Array | undefined;
1192
-
1193
- if (transaction.rawTransaction) {
1194
- const parsedTx = bcs.SenderSignedData.parse(fromBase64(transaction.rawTransaction))[0];
1195
- // System transactions, including genesis, carry a placeholder signature that gRPC and
1196
- // GraphQL report as-is.
1197
- signatures = parsedTx.txSignatures;
1198
-
1199
- if (include?.transaction || include?.bcs) {
1200
- const bytes = bcs.TransactionData.serialize(parsedTx.intentMessage.value).toBytes();
1201
-
1202
- if (include?.bcs) {
1203
- bcsBytes = bytes;
1204
- }
1205
-
1206
- if (include?.transaction) {
1207
- const data = TransactionDataBuilder.restore({
1208
- version: 2,
1209
- sender: parsedTx.intentMessage.value.V1.sender,
1210
- expiration: parsedTx.intentMessage.value.V1.expiration,
1211
- gasData: parsedTx.intentMessage.value.V1.gasData,
1212
- inputs: parsedTx.intentMessage.value.V1.kind.ProgrammableTransaction!.inputs,
1213
- commands: parsedTx.intentMessage.value.V1.kind.ProgrammableTransaction!.commands,
1214
- });
1215
- transactionData = { ...data };
1216
- }
1217
- }
1218
- }
1219
-
1220
- // Get status from JSON-RPC response
1221
- const status: SuiClientTypes.ExecutionStatus = transaction.effects?.status
1222
- ? parseJsonRpcExecutionStatus(transaction.effects.status, transaction.effects.abortError)
1223
- : {
1224
- success: false,
1225
- error: {
1226
- $kind: 'Unknown',
1227
- message: 'Unknown',
1228
- Unknown: null,
1229
- },
1230
- };
1231
-
1232
- const effectsBytes = transaction.rawEffects ? new Uint8Array(transaction.rawEffects) : null;
1233
-
1234
- const result: SuiClientTypes.Transaction<Include> = {
1235
- digest: transaction.digest,
1236
- epoch: transaction.effects?.executedEpoch ?? null,
1237
- timestampMs: transaction.timestampMs == null ? null : Number(transaction.timestampMs),
1238
- checkpoint: transaction.checkpoint ?? null,
1239
- status,
1240
- effects: (include?.effects && effectsBytes
1241
- ? parseTransactionEffectsBcs(effectsBytes)
1242
- : undefined) as SuiClientTypes.Transaction<Include>['effects'],
1243
- objectTypes: (include?.objectTypes
1244
- ? objectTypes
1245
- : undefined) as SuiClientTypes.Transaction<Include>['objectTypes'],
1246
- transaction: transactionData as SuiClientTypes.Transaction<Include>['transaction'],
1247
- bcs: bcsBytes as SuiClientTypes.Transaction<Include>['bcs'],
1248
- signatures,
1249
- balanceChanges: (include?.balanceChanges
1250
- ? (transaction.balanceChanges?.map((change) => ({
1251
- coinType: normalizeStructTag(change.coinType),
1252
- address: parseOwnerAddress(change.owner)!,
1253
- amount: change.amount,
1254
- })) ?? [])
1255
- : undefined) as SuiClientTypes.Transaction<Include>['balanceChanges'],
1256
- events: (include?.events
1257
- ? (transaction.events?.map((event) => ({
1258
- packageId: event.packageId,
1259
- module: event.transactionModule,
1260
- sender: event.sender,
1261
- eventType: event.type,
1262
- bcs: 'bcs' in event ? fromBase64(event.bcs) : new Uint8Array(),
1263
- json: (event.parsedJson as Record<string, unknown>) ?? null,
1264
- })) ?? [])
1265
- : undefined) as SuiClientTypes.Transaction<Include>['events'],
1266
- };
1267
-
1268
- return status.success
1269
- ? {
1270
- $kind: 'Transaction',
1271
- Transaction: result,
1272
- }
1273
- : {
1274
- $kind: 'FailedTransaction',
1275
- FailedTransaction: result,
1276
- };
1277
- }
1278
-
1279
- export function parseTransactionEffectsJson({
1280
- bytes,
1281
- effects,
1282
- objectChanges,
1283
- }: {
1284
- bytes?: Uint8Array;
1285
- effects: TransactionEffects;
1286
- objectChanges: SuiObjectChange[] | null;
1287
- }): {
1288
- effects: SuiClientTypes.TransactionEffects;
1289
- objectTypes: Record<string, string>;
1290
- } {
1291
- const changedObjects: SuiClientTypes.ChangedObject[] = [];
1292
- const unchangedConsensusObjects: SuiClientTypes.UnchangedConsensusObject[] = [];
1293
- const objectTypes: Record<string, string> = {};
1294
-
1295
- objectChanges?.forEach((change) => {
1296
- switch (change.type) {
1297
- case 'published':
1298
- changedObjects.push({
1299
- objectId: change.packageId,
1300
- inputState: 'DoesNotExist',
1301
- inputVersion: null,
1302
- inputDigest: null,
1303
- inputOwner: null,
1304
- outputState: 'PackageWrite',
1305
- outputVersion: change.version,
1306
- outputDigest: change.digest,
1307
- outputOwner: null,
1308
- idOperation: 'Created',
1309
- });
1310
- break;
1311
- case 'transferred':
1312
- changedObjects.push({
1313
- objectId: change.objectId,
1314
- inputState: 'Exists',
1315
- inputVersion: change.version,
1316
- inputDigest: change.digest,
1317
- inputOwner: {
1318
- $kind: 'AddressOwner' as const,
1319
- AddressOwner: change.sender,
1320
- },
1321
- outputState: 'ObjectWrite',
1322
- outputVersion: change.version,
1323
- outputDigest: change.digest,
1324
- outputOwner: parseOwner(change.recipient),
1325
- idOperation: 'None',
1326
- });
1327
- objectTypes[change.objectId] = normalizeStructTag(change.objectType);
1328
- break;
1329
- case 'mutated':
1330
- changedObjects.push({
1331
- objectId: change.objectId,
1332
- inputState: 'Exists',
1333
- inputVersion: change.previousVersion,
1334
- inputDigest: null,
1335
- inputOwner: parseOwner(change.owner),
1336
- outputState: 'ObjectWrite',
1337
- outputVersion: change.version,
1338
- outputDigest: change.digest,
1339
- outputOwner: parseOwner(change.owner),
1340
- idOperation: 'None',
1341
- });
1342
- objectTypes[change.objectId] = normalizeStructTag(change.objectType);
1343
- break;
1344
- case 'deleted':
1345
- changedObjects.push({
1346
- objectId: change.objectId,
1347
- inputState: 'Exists',
1348
- inputVersion: change.version,
1349
- inputDigest: effects.deleted?.find((d) => d.objectId === change.objectId)?.digest ?? null,
1350
- inputOwner: null,
1351
- outputState: 'DoesNotExist',
1352
- outputVersion: null,
1353
- outputDigest: null,
1354
- outputOwner: null,
1355
- idOperation: 'Deleted',
1356
- });
1357
- objectTypes[change.objectId] = normalizeStructTag(change.objectType);
1358
- break;
1359
- case 'wrapped':
1360
- changedObjects.push({
1361
- objectId: change.objectId,
1362
- inputState: 'Exists',
1363
- inputVersion: change.version,
1364
- inputDigest: null,
1365
- inputOwner: {
1366
- $kind: 'AddressOwner' as const,
1367
- AddressOwner: change.sender,
1368
- },
1369
- outputState: 'ObjectWrite',
1370
- outputVersion: change.version,
1371
- outputDigest:
1372
- effects.wrapped?.find((w) => w.objectId === change.objectId)?.digest ?? null,
1373
- outputOwner: {
1374
- $kind: 'ObjectOwner' as const,
1375
- ObjectOwner: change.sender,
1376
- },
1377
- idOperation: 'None',
1378
- });
1379
- objectTypes[change.objectId] = normalizeStructTag(change.objectType);
1380
- break;
1381
- case 'created':
1382
- changedObjects.push({
1383
- objectId: change.objectId,
1384
- inputState: 'DoesNotExist',
1385
- inputVersion: null,
1386
- inputDigest: null,
1387
- inputOwner: null,
1388
- outputState: 'ObjectWrite',
1389
- outputVersion: change.version,
1390
- outputDigest: change.digest,
1391
- outputOwner: parseOwner(change.owner),
1392
- idOperation: 'Created',
1393
- });
1394
- objectTypes[change.objectId] = normalizeStructTag(change.objectType);
1395
- break;
1396
- }
1397
- });
1398
-
1399
- // When the transaction has no gas object (system transactions, or gas paid
1400
- // from an address balance), the RPC substitutes a placeholder ref with the
1401
- // 0x0 object id rather than omitting the field.
1402
- const hasGasObject =
1403
- normalizeSuiAddress(effects.gasObject.reference.objectId) !== normalizeSuiAddress('0x0');
1404
-
1405
- let lamportVersion: string | null = null;
1406
- if (hasGasObject) {
1407
- lamportVersion = effects.gasObject.reference.version;
1408
- } else {
1409
- // Written objects are all assigned the lamport version, so recover it
1410
- // from the changed objects when the gas object can't provide it.
1411
- for (const change of changedObjects) {
1412
- if (
1413
- change.outputVersion &&
1414
- (lamportVersion === null || BigInt(change.outputVersion) > BigInt(lamportVersion))
1415
- ) {
1416
- lamportVersion = change.outputVersion;
1417
- }
1418
- }
1419
- }
1420
-
1421
- return {
1422
- objectTypes,
1423
- effects: {
1424
- bcs: bytes ?? null,
1425
- version: 2,
1426
- status: parseJsonRpcExecutionStatus(effects.status, effects.abortError),
1427
- gasUsed: effects.gasUsed,
1428
- transactionDigest: effects.transactionDigest,
1429
- gasObject: hasGasObject
1430
- ? {
1431
- objectId: effects.gasObject.reference.objectId,
1432
- inputState: 'Exists',
1433
- inputVersion: null,
1434
- inputDigest: null,
1435
- inputOwner: null,
1436
- outputState: 'ObjectWrite',
1437
- outputVersion: effects.gasObject.reference.version,
1438
- outputDigest: effects.gasObject.reference.digest,
1439
- outputOwner: parseOwner(effects.gasObject.owner),
1440
- idOperation: 'None',
1441
- }
1442
- : null,
1443
- eventsDigest: effects.eventsDigest ?? null,
1444
- dependencies: effects.dependencies ?? [],
1445
- lamportVersion,
1446
- changedObjects,
1447
- unchangedConsensusObjects,
1448
- auxiliaryDataDigest: null,
1449
- },
1450
- };
1451
- }
1452
-
1453
- function parseNormalizedSuiMoveType(type: SuiMoveNormalizedType): SuiClientTypes.OpenSignature {
1454
- if (typeof type !== 'string') {
1455
- if ('Reference' in type) {
1456
- return {
1457
- reference: 'immutable',
1458
- body: parseNormalizedSuiMoveTypeBody(type.Reference),
1459
- };
1460
- }
1461
-
1462
- if ('MutableReference' in type) {
1463
- return {
1464
- reference: 'mutable',
1465
- body: parseNormalizedSuiMoveTypeBody(type.MutableReference),
1466
- };
1467
- }
1468
- }
1469
-
1470
- return {
1471
- reference: null,
1472
- body: parseNormalizedSuiMoveTypeBody(type),
1473
- };
1474
- }
1475
-
1476
- function parseNormalizedSuiMoveTypeBody(
1477
- type: SuiMoveNormalizedType,
1478
- ): SuiClientTypes.OpenSignatureBody {
1479
- switch (type) {
1480
- case 'Address':
1481
- return { $kind: 'address' };
1482
- case 'Bool':
1483
- return { $kind: 'bool' };
1484
- case 'U8':
1485
- return { $kind: 'u8' };
1486
- case 'U16':
1487
- return { $kind: 'u16' };
1488
- case 'U32':
1489
- return { $kind: 'u32' };
1490
- case 'U64':
1491
- return { $kind: 'u64' };
1492
- case 'U128':
1493
- return { $kind: 'u128' };
1494
- case 'U256':
1495
- return { $kind: 'u256' };
1496
- }
1497
-
1498
- if (typeof type === 'string') {
1499
- throw new Error(`Unknown type: ${type}`);
1500
- }
1501
-
1502
- if ('Vector' in type) {
1503
- return {
1504
- $kind: 'vector',
1505
- vector: parseNormalizedSuiMoveTypeBody(type.Vector),
1506
- };
1507
- }
1508
-
1509
- if ('Struct' in type) {
1510
- return {
1511
- $kind: 'datatype',
1512
- datatype: {
1513
- typeName: `${normalizeSuiAddress(type.Struct.address)}::${type.Struct.module}::${type.Struct.name}`,
1514
- typeParameters: type.Struct.typeArguments.map((t) => parseNormalizedSuiMoveTypeBody(t)),
1515
- },
1516
- };
1517
- }
1518
-
1519
- if ('TypeParameter' in type) {
1520
- return {
1521
- $kind: 'typeParameter',
1522
- index: type.TypeParameter,
1523
- };
1524
- }
1525
-
1526
- throw new Error(`Unknown type: ${JSON.stringify(type)}`);
1527
- }
1528
-
1529
- function parseAbilities(abilitySet: SuiMoveAbilitySet): SuiClientTypes.Ability[] {
1530
- return abilitySet.abilities.map((ability) => {
1531
- switch (ability) {
1532
- case 'Copy':
1533
- return 'copy';
1534
- case 'Drop':
1535
- return 'drop';
1536
- case 'Store':
1537
- return 'store';
1538
- case 'Key':
1539
- return 'key';
1540
- default:
1541
- return 'unknown';
1542
- }
1543
- });
1544
- }
1545
-
1546
- function parseVisibility(visibility: SuiMoveVisibility): SuiClientTypes.Visibility {
1547
- switch (visibility) {
1548
- case 'Public':
1549
- return 'public';
1550
- case 'Private':
1551
- return 'private';
1552
- case 'Friend':
1553
- return 'friend';
1554
- default:
1555
- return 'unknown';
1556
- }
1557
- }