@unconfirmed/effect-sui 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (573) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/Address.d.ts +18 -0
  4. package/dist/Address.d.ts.map +1 -0
  5. package/dist/Address.js +33 -0
  6. package/dist/Address.js.map +1 -0
  7. package/dist/AddressAlias.d.ts +107 -0
  8. package/dist/AddressAlias.d.ts.map +1 -0
  9. package/dist/AddressAlias.js +104 -0
  10. package/dist/AddressAlias.js.map +1 -0
  11. package/dist/Bip32.d.ts +6 -0
  12. package/dist/Bip32.d.ts.map +1 -0
  13. package/dist/Bip32.js +34 -0
  14. package/dist/Bip32.js.map +1 -0
  15. package/dist/Chain.d.ts +23 -0
  16. package/dist/Chain.d.ts.map +1 -0
  17. package/dist/Chain.js +7 -0
  18. package/dist/Chain.js.map +1 -0
  19. package/dist/CheckpointData.d.ts +74 -0
  20. package/dist/CheckpointData.d.ts.map +1 -0
  21. package/dist/CheckpointData.js +48 -0
  22. package/dist/CheckpointData.js.map +1 -0
  23. package/dist/Checkpoints.d.ts +23 -0
  24. package/dist/Checkpoints.d.ts.map +1 -0
  25. package/dist/Checkpoints.js +7 -0
  26. package/dist/Checkpoints.js.map +1 -0
  27. package/dist/CoinReservation.d.ts +18 -0
  28. package/dist/CoinReservation.d.ts.map +1 -0
  29. package/dist/CoinReservation.js +58 -0
  30. package/dist/CoinReservation.js.map +1 -0
  31. package/dist/Coins.d.ts +42 -0
  32. package/dist/Coins.d.ts.map +1 -0
  33. package/dist/Coins.js +49 -0
  34. package/dist/Coins.js.map +1 -0
  35. package/dist/DynamicFields.d.ts +115 -0
  36. package/dist/DynamicFields.d.ts.map +1 -0
  37. package/dist/DynamicFields.js +101 -0
  38. package/dist/DynamicFields.js.map +1 -0
  39. package/dist/Ecdsa.d.ts +39 -0
  40. package/dist/Ecdsa.d.ts.map +1 -0
  41. package/dist/Ecdsa.js +76 -0
  42. package/dist/Ecdsa.js.map +1 -0
  43. package/dist/Ed25519.d.ts +22 -0
  44. package/dist/Ed25519.d.ts.map +1 -0
  45. package/dist/Ed25519.js +77 -0
  46. package/dist/Ed25519.js.map +1 -0
  47. package/dist/Events.d.ts +105 -0
  48. package/dist/Events.d.ts.map +1 -0
  49. package/dist/Events.js +51 -0
  50. package/dist/Events.js.map +1 -0
  51. package/dist/Hash.d.ts +16 -0
  52. package/dist/Hash.d.ts.map +1 -0
  53. package/dist/Hash.js +32 -0
  54. package/dist/Hash.js.map +1 -0
  55. package/dist/MlDsa65.d.ts +17 -0
  56. package/dist/MlDsa65.d.ts.map +1 -0
  57. package/dist/MlDsa65.js +84 -0
  58. package/dist/MlDsa65.js.map +1 -0
  59. package/dist/Mnemonic.d.ts +20 -0
  60. package/dist/Mnemonic.d.ts.map +1 -0
  61. package/dist/Mnemonic.js +71 -0
  62. package/dist/Mnemonic.js.map +1 -0
  63. package/dist/Move.d.ts +261 -0
  64. package/dist/Move.d.ts.map +1 -0
  65. package/dist/Move.js +232 -0
  66. package/dist/Move.js.map +1 -0
  67. package/dist/MultiSig.d.ts +106 -0
  68. package/dist/MultiSig.d.ts.map +1 -0
  69. package/dist/MultiSig.js +254 -0
  70. package/dist/MultiSig.js.map +1 -0
  71. package/dist/Objects.d.ts +95 -0
  72. package/dist/Objects.d.ts.map +1 -0
  73. package/dist/Objects.js +57 -0
  74. package/dist/Objects.js.map +1 -0
  75. package/dist/Packages.d.ts +49 -0
  76. package/dist/Packages.d.ts.map +1 -0
  77. package/dist/Packages.js +16 -0
  78. package/dist/Packages.js.map +1 -0
  79. package/dist/Passkey.d.ts +11 -0
  80. package/dist/Passkey.d.ts.map +1 -0
  81. package/dist/Passkey.js +11 -0
  82. package/dist/Passkey.js.map +1 -0
  83. package/dist/PrivateKey.d.ts +39 -0
  84. package/dist/PrivateKey.d.ts.map +1 -0
  85. package/dist/PrivateKey.js +118 -0
  86. package/dist/PrivateKey.js.map +1 -0
  87. package/dist/Ptb.d.ts +413 -0
  88. package/dist/Ptb.d.ts.map +1 -0
  89. package/dist/Ptb.js +338 -0
  90. package/dist/Ptb.js.map +1 -0
  91. package/dist/Resolve.d.ts +502 -0
  92. package/dist/Resolve.d.ts.map +1 -0
  93. package/dist/Resolve.js +1188 -0
  94. package/dist/Resolve.js.map +1 -0
  95. package/dist/RpcError.d.ts +19 -0
  96. package/dist/RpcError.d.ts.map +1 -0
  97. package/dist/RpcError.js +37 -0
  98. package/dist/RpcError.js.map +1 -0
  99. package/dist/Secp256k1.d.ts +11 -0
  100. package/dist/Secp256k1.d.ts.map +1 -0
  101. package/dist/Secp256k1.js +23 -0
  102. package/dist/Secp256k1.js.map +1 -0
  103. package/dist/Secp256r1.d.ts +11 -0
  104. package/dist/Secp256r1.d.ts.map +1 -0
  105. package/dist/Secp256r1.js +23 -0
  106. package/dist/Secp256r1.js.map +1 -0
  107. package/dist/SignatureScheme.d.ts +103 -0
  108. package/dist/SignatureScheme.d.ts.map +1 -0
  109. package/dist/SignatureScheme.js +93 -0
  110. package/dist/SignatureScheme.js.map +1 -0
  111. package/dist/Signer.d.ts +54 -0
  112. package/dist/Signer.d.ts.map +1 -0
  113. package/dist/Signer.js +31 -0
  114. package/dist/Signer.js.map +1 -0
  115. package/dist/Testing.d.ts +171 -0
  116. package/dist/Testing.d.ts.map +1 -0
  117. package/dist/Testing.js +531 -0
  118. package/dist/Testing.js.map +1 -0
  119. package/dist/TransactionData.d.ts +3218 -0
  120. package/dist/TransactionData.d.ts.map +1 -0
  121. package/dist/TransactionData.js +105 -0
  122. package/dist/TransactionData.js.map +1 -0
  123. package/dist/TransactionJson.d.ts +1544 -0
  124. package/dist/TransactionJson.d.ts.map +1 -0
  125. package/dist/TransactionJson.js +926 -0
  126. package/dist/TransactionJson.js.map +1 -0
  127. package/dist/Transactions.d.ts +181 -0
  128. package/dist/Transactions.d.ts.map +1 -0
  129. package/dist/Transactions.js +49 -0
  130. package/dist/Transactions.js.map +1 -0
  131. package/dist/Tx.d.ts +1419 -0
  132. package/dist/Tx.d.ts.map +1 -0
  133. package/dist/Tx.js +266 -0
  134. package/dist/Tx.js.map +1 -0
  135. package/dist/TypeTag.d.ts +42 -0
  136. package/dist/TypeTag.d.ts.map +1 -0
  137. package/dist/TypeTag.js +110 -0
  138. package/dist/TypeTag.js.map +1 -0
  139. package/dist/Verify.d.ts +23 -0
  140. package/dist/Verify.d.ts.map +1 -0
  141. package/dist/Verify.js +29 -0
  142. package/dist/Verify.js.map +1 -0
  143. package/dist/enoki/EnokiClient.d.ts +184 -0
  144. package/dist/enoki/EnokiClient.d.ts.map +1 -0
  145. package/dist/enoki/EnokiClient.js +105 -0
  146. package/dist/enoki/EnokiClient.js.map +1 -0
  147. package/dist/enoki/EnokiHttp.d.ts +33 -0
  148. package/dist/enoki/EnokiHttp.d.ts.map +1 -0
  149. package/dist/enoki/EnokiHttp.js +160 -0
  150. package/dist/enoki/EnokiHttp.js.map +1 -0
  151. package/dist/enoki/Sponsor.d.ts +119 -0
  152. package/dist/enoki/Sponsor.d.ts.map +1 -0
  153. package/dist/enoki/Sponsor.js +170 -0
  154. package/dist/enoki/Sponsor.js.map +1 -0
  155. package/dist/enoki/ZkLoginFlow.d.ts +84 -0
  156. package/dist/enoki/ZkLoginFlow.d.ts.map +1 -0
  157. package/dist/enoki/ZkLoginFlow.js +138 -0
  158. package/dist/enoki/ZkLoginFlow.js.map +1 -0
  159. package/dist/enoki/index.d.ts +9 -0
  160. package/dist/enoki/index.d.ts.map +1 -0
  161. package/dist/enoki/index.js +9 -0
  162. package/dist/enoki/index.js.map +1 -0
  163. package/dist/graphql/ChainGraphQL.d.ts +35 -0
  164. package/dist/graphql/ChainGraphQL.d.ts.map +1 -0
  165. package/dist/graphql/ChainGraphQL.js +62 -0
  166. package/dist/graphql/ChainGraphQL.js.map +1 -0
  167. package/dist/graphql/CheckpointDataGraphQL.d.ts +785 -0
  168. package/dist/graphql/CheckpointDataGraphQL.d.ts.map +1 -0
  169. package/dist/graphql/CheckpointDataGraphQL.js +157 -0
  170. package/dist/graphql/CheckpointDataGraphQL.js.map +1 -0
  171. package/dist/graphql/CheckpointsGraphQL.d.ts +91 -0
  172. package/dist/graphql/CheckpointsGraphQL.d.ts.map +1 -0
  173. package/dist/graphql/CheckpointsGraphQL.js +80 -0
  174. package/dist/graphql/CheckpointsGraphQL.js.map +1 -0
  175. package/dist/graphql/CoinsGraphQL.d.ts +81 -0
  176. package/dist/graphql/CoinsGraphQL.d.ts.map +1 -0
  177. package/dist/graphql/CoinsGraphQL.js +63 -0
  178. package/dist/graphql/CoinsGraphQL.js.map +1 -0
  179. package/dist/graphql/DynamicFieldsGraphQL.d.ts +94 -0
  180. package/dist/graphql/DynamicFieldsGraphQL.d.ts.map +1 -0
  181. package/dist/graphql/DynamicFieldsGraphQL.js +126 -0
  182. package/dist/graphql/DynamicFieldsGraphQL.js.map +1 -0
  183. package/dist/graphql/EventsGraphQL.d.ts +266 -0
  184. package/dist/graphql/EventsGraphQL.d.ts.map +1 -0
  185. package/dist/graphql/EventsGraphQL.js +249 -0
  186. package/dist/graphql/EventsGraphQL.js.map +1 -0
  187. package/dist/graphql/ObjectsGraphQL.d.ts +130 -0
  188. package/dist/graphql/ObjectsGraphQL.d.ts.map +1 -0
  189. package/dist/graphql/ObjectsGraphQL.js +79 -0
  190. package/dist/graphql/ObjectsGraphQL.js.map +1 -0
  191. package/dist/graphql/PackagesGraphQL.d.ts +82 -0
  192. package/dist/graphql/PackagesGraphQL.d.ts.map +1 -0
  193. package/dist/graphql/PackagesGraphQL.js +145 -0
  194. package/dist/graphql/PackagesGraphQL.js.map +1 -0
  195. package/dist/graphql/SuiGraphQL.d.ts +37 -0
  196. package/dist/graphql/SuiGraphQL.d.ts.map +1 -0
  197. package/dist/graphql/SuiGraphQL.js +47 -0
  198. package/dist/graphql/SuiGraphQL.js.map +1 -0
  199. package/dist/graphql/TransactionsGraphQL.d.ts +1309 -0
  200. package/dist/graphql/TransactionsGraphQL.d.ts.map +1 -0
  201. package/dist/graphql/TransactionsGraphQL.js +206 -0
  202. package/dist/graphql/TransactionsGraphQL.js.map +1 -0
  203. package/dist/graphql/convert.d.ts +505 -0
  204. package/dist/graphql/convert.d.ts.map +1 -0
  205. package/dist/graphql/convert.js +384 -0
  206. package/dist/graphql/convert.js.map +1 -0
  207. package/dist/graphql/index.d.ts +41 -0
  208. package/dist/graphql/index.d.ts.map +1 -0
  209. package/dist/graphql/index.js +20 -0
  210. package/dist/graphql/index.js.map +1 -0
  211. package/dist/graphql/merge.d.ts +8 -0
  212. package/dist/graphql/merge.d.ts.map +1 -0
  213. package/dist/graphql/merge.js +55 -0
  214. package/dist/graphql/merge.js.map +1 -0
  215. package/dist/graphql/paging.d.ts +219 -0
  216. package/dist/graphql/paging.d.ts.map +1 -0
  217. package/dist/graphql/paging.js +74 -0
  218. package/dist/graphql/paging.js.map +1 -0
  219. package/dist/graphql/subscription.d.ts +27 -0
  220. package/dist/graphql/subscription.d.ts.map +1 -0
  221. package/dist/graphql/subscription.js +47 -0
  222. package/dist/graphql/subscription.js.map +1 -0
  223. package/dist/graphql/tip.d.ts +31 -0
  224. package/dist/graphql/tip.d.ts.map +1 -0
  225. package/dist/graphql/tip.js +29 -0
  226. package/dist/graphql/tip.js.map +1 -0
  227. package/dist/grpc/ChainGrpc.d.ts +11 -0
  228. package/dist/grpc/ChainGrpc.d.ts.map +1 -0
  229. package/dist/grpc/ChainGrpc.js +40 -0
  230. package/dist/grpc/ChainGrpc.js.map +1 -0
  231. package/dist/grpc/CheckpointDataGrpc.d.ts +6 -0
  232. package/dist/grpc/CheckpointDataGrpc.d.ts.map +1 -0
  233. package/dist/grpc/CheckpointDataGrpc.js +27 -0
  234. package/dist/grpc/CheckpointDataGrpc.js.map +1 -0
  235. package/dist/grpc/CheckpointsGrpc.d.ts +6 -0
  236. package/dist/grpc/CheckpointsGrpc.d.ts.map +1 -0
  237. package/dist/grpc/CheckpointsGrpc.js +25 -0
  238. package/dist/grpc/CheckpointsGrpc.js.map +1 -0
  239. package/dist/grpc/CoinsGrpc.d.ts +7 -0
  240. package/dist/grpc/CoinsGrpc.d.ts.map +1 -0
  241. package/dist/grpc/CoinsGrpc.js +34 -0
  242. package/dist/grpc/CoinsGrpc.js.map +1 -0
  243. package/dist/grpc/DynamicFieldsGrpc.d.ts +11 -0
  244. package/dist/grpc/DynamicFieldsGrpc.d.ts.map +1 -0
  245. package/dist/grpc/DynamicFieldsGrpc.js +91 -0
  246. package/dist/grpc/DynamicFieldsGrpc.js.map +1 -0
  247. package/dist/grpc/EventsGrpc.d.ts +13 -0
  248. package/dist/grpc/EventsGrpc.d.ts.map +1 -0
  249. package/dist/grpc/EventsGrpc.js +88 -0
  250. package/dist/grpc/EventsGrpc.js.map +1 -0
  251. package/dist/grpc/GrpcWeb.d.ts +71 -0
  252. package/dist/grpc/GrpcWeb.d.ts.map +1 -0
  253. package/dist/grpc/GrpcWeb.js +243 -0
  254. package/dist/grpc/GrpcWeb.js.map +1 -0
  255. package/dist/grpc/ObjectsGrpc.d.ts +10 -0
  256. package/dist/grpc/ObjectsGrpc.d.ts.map +1 -0
  257. package/dist/grpc/ObjectsGrpc.js +72 -0
  258. package/dist/grpc/ObjectsGrpc.js.map +1 -0
  259. package/dist/grpc/PackagesGrpc.d.ts +9 -0
  260. package/dist/grpc/PackagesGrpc.d.ts.map +1 -0
  261. package/dist/grpc/PackagesGrpc.js +78 -0
  262. package/dist/grpc/PackagesGrpc.js.map +1 -0
  263. package/dist/grpc/Rpc.d.ts +46 -0
  264. package/dist/grpc/Rpc.d.ts.map +1 -0
  265. package/dist/grpc/Rpc.js +111 -0
  266. package/dist/grpc/Rpc.js.map +1 -0
  267. package/dist/grpc/TransactionsGrpc.d.ts +6 -0
  268. package/dist/grpc/TransactionsGrpc.d.ts.map +1 -0
  269. package/dist/grpc/TransactionsGrpc.js +56 -0
  270. package/dist/grpc/TransactionsGrpc.js.map +1 -0
  271. package/dist/grpc/cache.d.ts +7 -0
  272. package/dist/grpc/cache.d.ts.map +1 -0
  273. package/dist/grpc/cache.js +55 -0
  274. package/dist/grpc/cache.js.map +1 -0
  275. package/dist/grpc/convert.d.ts +43 -0
  276. package/dist/grpc/convert.d.ts.map +1 -0
  277. package/dist/grpc/convert.js +198 -0
  278. package/dist/grpc/convert.js.map +1 -0
  279. package/dist/grpc/generated/lean.d.ts +36 -0
  280. package/dist/grpc/generated/lean.d.ts.map +1 -0
  281. package/dist/grpc/generated/lean.js +205 -0
  282. package/dist/grpc/generated/lean.js.map +1 -0
  283. package/dist/grpc/generated/proto.d.ts +2000 -0
  284. package/dist/grpc/generated/proto.d.ts.map +1 -0
  285. package/dist/grpc/generated/proto.js +356 -0
  286. package/dist/grpc/generated/proto.js.map +1 -0
  287. package/dist/grpc/generated/rpc.d.ts +62 -0
  288. package/dist/grpc/generated/rpc.d.ts.map +1 -0
  289. package/dist/grpc/generated/rpc.js +324 -0
  290. package/dist/grpc/generated/rpc.js.map +1 -0
  291. package/dist/grpc/index.d.ts +58 -0
  292. package/dist/grpc/index.d.ts.map +1 -0
  293. package/dist/grpc/index.js +43 -0
  294. package/dist/grpc/index.js.map +1 -0
  295. package/dist/grpc/scan.d.ts +79 -0
  296. package/dist/grpc/scan.d.ts.map +1 -0
  297. package/dist/grpc/scan.js +126 -0
  298. package/dist/grpc/scan.js.map +1 -0
  299. package/dist/grpc/transaction.d.ts +9 -0
  300. package/dist/grpc/transaction.d.ts.map +1 -0
  301. package/dist/grpc/transaction.js +168 -0
  302. package/dist/grpc/transaction.js.map +1 -0
  303. package/dist/index.d.ts +36 -0
  304. package/dist/index.d.ts.map +1 -0
  305. package/dist/index.js +36 -0
  306. package/dist/index.js.map +1 -0
  307. package/dist/internal/allowances.d.ts +18 -0
  308. package/dist/internal/allowances.d.ts.map +1 -0
  309. package/dist/internal/allowances.js +194 -0
  310. package/dist/internal/allowances.js.map +1 -0
  311. package/dist/internal/mnemonic.d.ts +53 -0
  312. package/dist/internal/mnemonic.d.ts.map +1 -0
  313. package/dist/internal/mnemonic.js +66 -0
  314. package/dist/internal/mnemonic.js.map +1 -0
  315. package/dist/internal/passkey/BrowserProvider.d.ts +10 -0
  316. package/dist/internal/passkey/BrowserProvider.d.ts.map +1 -0
  317. package/dist/internal/passkey/BrowserProvider.js +101 -0
  318. package/dist/internal/passkey/BrowserProvider.js.map +1 -0
  319. package/dist/internal/passkey/Passkey.d.ts +104 -0
  320. package/dist/internal/passkey/Passkey.d.ts.map +1 -0
  321. package/dist/internal/passkey/Passkey.js +333 -0
  322. package/dist/internal/passkey/Passkey.js.map +1 -0
  323. package/dist/internal/passkey/SoftwareProvider.d.ts +23 -0
  324. package/dist/internal/passkey/SoftwareProvider.d.ts.map +1 -0
  325. package/dist/internal/passkey/SoftwareProvider.js +61 -0
  326. package/dist/internal/passkey/SoftwareProvider.js.map +1 -0
  327. package/dist/lifecycle/Evidence.d.ts +62 -0
  328. package/dist/lifecycle/Evidence.d.ts.map +1 -0
  329. package/dist/lifecycle/Evidence.js +30 -0
  330. package/dist/lifecycle/Evidence.js.map +1 -0
  331. package/dist/lifecycle/EvidenceGraphQL.d.ts +59 -0
  332. package/dist/lifecycle/EvidenceGraphQL.d.ts.map +1 -0
  333. package/dist/lifecycle/EvidenceGraphQL.js +53 -0
  334. package/dist/lifecycle/EvidenceGraphQL.js.map +1 -0
  335. package/dist/lifecycle/EvidenceGrpc.d.ts +4 -0
  336. package/dist/lifecycle/EvidenceGrpc.d.ts.map +1 -0
  337. package/dist/lifecycle/EvidenceGrpc.js +37 -0
  338. package/dist/lifecycle/EvidenceGrpc.js.map +1 -0
  339. package/dist/lifecycle/Journal.d.ts +69 -0
  340. package/dist/lifecycle/Journal.d.ts.map +1 -0
  341. package/dist/lifecycle/Journal.js +70 -0
  342. package/dist/lifecycle/Journal.js.map +1 -0
  343. package/dist/lifecycle/JournalEntry.d.ts +67 -0
  344. package/dist/lifecycle/JournalEntry.d.ts.map +1 -0
  345. package/dist/lifecycle/JournalEntry.js +45 -0
  346. package/dist/lifecycle/JournalEntry.js.map +1 -0
  347. package/dist/lifecycle/JournalKeyValueStore.d.ts +30 -0
  348. package/dist/lifecycle/JournalKeyValueStore.d.ts.map +1 -0
  349. package/dist/lifecycle/JournalKeyValueStore.js +217 -0
  350. package/dist/lifecycle/JournalKeyValueStore.js.map +1 -0
  351. package/dist/lifecycle/KeyValueStoreIndexedDb.d.ts +54 -0
  352. package/dist/lifecycle/KeyValueStoreIndexedDb.d.ts.map +1 -0
  353. package/dist/lifecycle/KeyValueStoreIndexedDb.js +321 -0
  354. package/dist/lifecycle/KeyValueStoreIndexedDb.js.map +1 -0
  355. package/dist/lifecycle/KeyValueStoreOpfs.d.ts +65 -0
  356. package/dist/lifecycle/KeyValueStoreOpfs.d.ts.map +1 -0
  357. package/dist/lifecycle/KeyValueStoreOpfs.js +207 -0
  358. package/dist/lifecycle/KeyValueStoreOpfs.js.map +1 -0
  359. package/dist/lifecycle/Lifecycle.d.ts +416 -0
  360. package/dist/lifecycle/Lifecycle.d.ts.map +1 -0
  361. package/dist/lifecycle/Lifecycle.js +666 -0
  362. package/dist/lifecycle/Lifecycle.js.map +1 -0
  363. package/dist/lifecycle/Outcome.d.ts +132 -0
  364. package/dist/lifecycle/Outcome.d.ts.map +1 -0
  365. package/dist/lifecycle/Outcome.js +106 -0
  366. package/dist/lifecycle/Outcome.js.map +1 -0
  367. package/dist/lifecycle/SenderLock.d.ts +37 -0
  368. package/dist/lifecycle/SenderLock.d.ts.map +1 -0
  369. package/dist/lifecycle/SenderLock.js +57 -0
  370. package/dist/lifecycle/SenderLock.js.map +1 -0
  371. package/dist/lifecycle/SenderLockWebLocks.d.ts +37 -0
  372. package/dist/lifecycle/SenderLockWebLocks.d.ts.map +1 -0
  373. package/dist/lifecycle/SenderLockWebLocks.js +100 -0
  374. package/dist/lifecycle/SenderLockWebLocks.js.map +1 -0
  375. package/dist/lifecycle/SignedTransaction.d.ts +55 -0
  376. package/dist/lifecycle/SignedTransaction.d.ts.map +1 -0
  377. package/dist/lifecycle/SignedTransaction.js +109 -0
  378. package/dist/lifecycle/SignedTransaction.js.map +1 -0
  379. package/dist/lifecycle/SubmitConfig.d.ts +44 -0
  380. package/dist/lifecycle/SubmitConfig.d.ts.map +1 -0
  381. package/dist/lifecycle/SubmitConfig.js +39 -0
  382. package/dist/lifecycle/SubmitConfig.js.map +1 -0
  383. package/dist/lifecycle/index.d.ts +13 -0
  384. package/dist/lifecycle/index.d.ts.map +1 -0
  385. package/dist/lifecycle/index.js +13 -0
  386. package/dist/lifecycle/index.js.map +1 -0
  387. package/dist/wallet/Connection.d.ts +119 -0
  388. package/dist/wallet/Connection.d.ts.map +1 -0
  389. package/dist/wallet/Connection.js +197 -0
  390. package/dist/wallet/Connection.js.map +1 -0
  391. package/dist/wallet/Features.d.ts +91 -0
  392. package/dist/wallet/Features.d.ts.map +1 -0
  393. package/dist/wallet/Features.js +14 -0
  394. package/dist/wallet/Features.js.map +1 -0
  395. package/dist/wallet/Wallet.d.ts +151 -0
  396. package/dist/wallet/Wallet.d.ts.map +1 -0
  397. package/dist/wallet/Wallet.js +399 -0
  398. package/dist/wallet/Wallet.js.map +1 -0
  399. package/dist/wallet/index.d.ts +7 -0
  400. package/dist/wallet/index.d.ts.map +1 -0
  401. package/dist/wallet/index.js +7 -0
  402. package/dist/wallet/index.js.map +1 -0
  403. package/dist/zklogin/AddressSeed.d.ts +40 -0
  404. package/dist/zklogin/AddressSeed.d.ts.map +1 -0
  405. package/dist/zklogin/AddressSeed.js +91 -0
  406. package/dist/zklogin/AddressSeed.js.map +1 -0
  407. package/dist/zklogin/Errors.d.ts +24 -0
  408. package/dist/zklogin/Errors.d.ts.map +1 -0
  409. package/dist/zklogin/Errors.js +25 -0
  410. package/dist/zklogin/Errors.js.map +1 -0
  411. package/dist/zklogin/Jwt.d.ts +51 -0
  412. package/dist/zklogin/Jwt.d.ts.map +1 -0
  413. package/dist/zklogin/Jwt.js +159 -0
  414. package/dist/zklogin/Jwt.js.map +1 -0
  415. package/dist/zklogin/Nonce.d.ts +9 -0
  416. package/dist/zklogin/Nonce.d.ts.map +1 -0
  417. package/dist/zklogin/Nonce.js +34 -0
  418. package/dist/zklogin/Nonce.js.map +1 -0
  419. package/dist/zklogin/Poseidon.d.ts +24 -0
  420. package/dist/zklogin/Poseidon.d.ts.map +1 -0
  421. package/dist/zklogin/Poseidon.js +54 -0
  422. package/dist/zklogin/Poseidon.js.map +1 -0
  423. package/dist/zklogin/PublicIdentifier.d.ts +49 -0
  424. package/dist/zklogin/PublicIdentifier.d.ts.map +1 -0
  425. package/dist/zklogin/PublicIdentifier.js +90 -0
  426. package/dist/zklogin/PublicIdentifier.js.map +1 -0
  427. package/dist/zklogin/Signature.d.ts +55 -0
  428. package/dist/zklogin/Signature.d.ts.map +1 -0
  429. package/dist/zklogin/Signature.js +70 -0
  430. package/dist/zklogin/Signature.js.map +1 -0
  431. package/dist/zklogin/ZkLogin.d.ts +41 -0
  432. package/dist/zklogin/ZkLogin.d.ts.map +1 -0
  433. package/dist/zklogin/ZkLogin.js +87 -0
  434. package/dist/zklogin/ZkLogin.js.map +1 -0
  435. package/dist/zklogin/ZkLoginAddress.d.ts +30 -0
  436. package/dist/zklogin/ZkLoginAddress.d.ts.map +1 -0
  437. package/dist/zklogin/ZkLoginAddress.js +31 -0
  438. package/dist/zklogin/ZkLoginAddress.js.map +1 -0
  439. package/dist/zklogin/ZkLoginVerifier.d.ts +37 -0
  440. package/dist/zklogin/ZkLoginVerifier.d.ts.map +1 -0
  441. package/dist/zklogin/ZkLoginVerifier.js +4 -0
  442. package/dist/zklogin/ZkLoginVerifier.js.map +1 -0
  443. package/dist/zklogin/ZkLoginVerifierGrpc.d.ts +12 -0
  444. package/dist/zklogin/ZkLoginVerifierGrpc.d.ts.map +1 -0
  445. package/dist/zklogin/ZkLoginVerifierGrpc.js +53 -0
  446. package/dist/zklogin/ZkLoginVerifierGrpc.js.map +1 -0
  447. package/dist/zklogin/index.d.ts +17 -0
  448. package/dist/zklogin/index.d.ts.map +1 -0
  449. package/dist/zklogin/index.js +17 -0
  450. package/dist/zklogin/index.js.map +1 -0
  451. package/dist/zklogin/internal/parse.d.ts +9 -0
  452. package/dist/zklogin/internal/parse.d.ts.map +1 -0
  453. package/dist/zklogin/internal/parse.js +33 -0
  454. package/dist/zklogin/internal/parse.js.map +1 -0
  455. package/dist/zklogin/internal/poseidon.d.ts +21 -0
  456. package/dist/zklogin/internal/poseidon.d.ts.map +1 -0
  457. package/dist/zklogin/internal/poseidon.js +40 -0
  458. package/dist/zklogin/internal/poseidon.js.map +1 -0
  459. package/package.json +69 -4
  460. package/src/Address.ts +45 -0
  461. package/src/AddressAlias.ts +160 -0
  462. package/src/Bip32.ts +37 -0
  463. package/src/Chain.ts +21 -0
  464. package/src/CheckpointData.ts +106 -0
  465. package/src/Checkpoints.ts +18 -0
  466. package/src/CoinReservation.ts +65 -0
  467. package/src/Coins.ts +86 -0
  468. package/src/DynamicFields.ts +179 -0
  469. package/src/Ecdsa.ts +103 -0
  470. package/src/Ed25519.ts +84 -0
  471. package/src/Events.ts +133 -0
  472. package/src/Hash.ts +39 -0
  473. package/src/MlDsa65.ts +92 -0
  474. package/src/Mnemonic.ts +109 -0
  475. package/src/Move.ts +440 -0
  476. package/src/MultiSig.ts +320 -0
  477. package/src/Objects.ts +112 -0
  478. package/src/Packages.ts +52 -0
  479. package/src/Passkey.ts +10 -0
  480. package/src/PrivateKey.ts +138 -0
  481. package/src/Ptb.ts +579 -0
  482. package/src/Resolve.ts +1367 -0
  483. package/src/RpcError.ts +41 -0
  484. package/src/Secp256k1.ts +29 -0
  485. package/src/Secp256r1.ts +29 -0
  486. package/src/SignatureScheme.ts +166 -0
  487. package/src/Signer.ts +62 -0
  488. package/src/Testing.ts +830 -0
  489. package/src/TransactionData.ts +134 -0
  490. package/src/TransactionJson.ts +1002 -0
  491. package/src/Transactions.ts +211 -0
  492. package/src/Tx.ts +367 -0
  493. package/src/TypeTag.ts +123 -0
  494. package/src/Verify.ts +42 -0
  495. package/src/enoki/EnokiClient.ts +204 -0
  496. package/src/enoki/EnokiHttp.ts +222 -0
  497. package/src/enoki/Sponsor.ts +280 -0
  498. package/src/enoki/ZkLoginFlow.ts +176 -0
  499. package/src/enoki/index.ts +8 -0
  500. package/src/graphql/ChainGraphQL.ts +76 -0
  501. package/src/graphql/CheckpointDataGraphQL.ts +191 -0
  502. package/src/graphql/CheckpointsGraphQL.ts +96 -0
  503. package/src/graphql/CoinsGraphQL.ts +85 -0
  504. package/src/graphql/DynamicFieldsGraphQL.ts +167 -0
  505. package/src/graphql/EventsGraphQL.ts +301 -0
  506. package/src/graphql/ObjectsGraphQL.ts +112 -0
  507. package/src/graphql/PackagesGraphQL.ts +173 -0
  508. package/src/graphql/SuiGraphQL.ts +77 -0
  509. package/src/graphql/TransactionsGraphQL.ts +292 -0
  510. package/src/graphql/convert.ts +450 -0
  511. package/src/graphql/index.ts +74 -0
  512. package/src/graphql/merge.ts +62 -0
  513. package/src/graphql/paging.ts +110 -0
  514. package/src/graphql/subscription.ts +58 -0
  515. package/src/graphql/tip.ts +38 -0
  516. package/src/grpc/ChainGrpc.ts +51 -0
  517. package/src/grpc/CheckpointDataGrpc.ts +47 -0
  518. package/src/grpc/CheckpointsGrpc.ts +37 -0
  519. package/src/grpc/CoinsGrpc.ts +50 -0
  520. package/src/grpc/DynamicFieldsGrpc.ts +128 -0
  521. package/src/grpc/EventsGrpc.ts +101 -0
  522. package/src/grpc/GrpcWeb.ts +343 -0
  523. package/src/grpc/ObjectsGrpc.ts +95 -0
  524. package/src/grpc/PackagesGrpc.ts +98 -0
  525. package/src/grpc/Rpc.ts +156 -0
  526. package/src/grpc/TransactionsGrpc.ts +88 -0
  527. package/src/grpc/cache.ts +68 -0
  528. package/src/grpc/convert.ts +227 -0
  529. package/src/grpc/generated/lean.ts +276 -0
  530. package/src/grpc/generated/proto.ts +2130 -0
  531. package/src/grpc/generated/rpc.ts +417 -0
  532. package/src/grpc/index.ts +97 -0
  533. package/src/grpc/scan.ts +183 -0
  534. package/src/grpc/transaction.ts +182 -0
  535. package/src/index.ts +35 -0
  536. package/src/internal/allowances.ts +238 -0
  537. package/src/internal/mnemonic.ts +99 -0
  538. package/src/internal/passkey/BrowserProvider.ts +131 -0
  539. package/src/internal/passkey/Passkey.ts +408 -0
  540. package/src/internal/passkey/SoftwareProvider.ts +90 -0
  541. package/src/lifecycle/Evidence.ts +85 -0
  542. package/src/lifecycle/EvidenceGraphQL.ts +67 -0
  543. package/src/lifecycle/EvidenceGrpc.ts +47 -0
  544. package/src/lifecycle/Journal.ts +117 -0
  545. package/src/lifecycle/JournalEntry.ts +68 -0
  546. package/src/lifecycle/JournalKeyValueStore.ts +276 -0
  547. package/src/lifecycle/KeyValueStoreIndexedDb.ts +361 -0
  548. package/src/lifecycle/KeyValueStoreOpfs.ts +230 -0
  549. package/src/lifecycle/Lifecycle.ts +990 -0
  550. package/src/lifecycle/Outcome.ts +130 -0
  551. package/src/lifecycle/SenderLock.ts +73 -0
  552. package/src/lifecycle/SenderLockWebLocks.ts +136 -0
  553. package/src/lifecycle/SignedTransaction.ts +133 -0
  554. package/src/lifecycle/SubmitConfig.ts +77 -0
  555. package/src/lifecycle/index.ts +12 -0
  556. package/src/wallet/Connection.ts +323 -0
  557. package/src/wallet/Features.ts +114 -0
  558. package/src/wallet/Wallet.ts +550 -0
  559. package/src/wallet/index.ts +6 -0
  560. package/src/zklogin/AddressSeed.ts +130 -0
  561. package/src/zklogin/Errors.ts +27 -0
  562. package/src/zklogin/Jwt.ts +186 -0
  563. package/src/zklogin/Nonce.ts +46 -0
  564. package/src/zklogin/Poseidon.ts +62 -0
  565. package/src/zklogin/PublicIdentifier.ts +111 -0
  566. package/src/zklogin/Signature.ts +88 -0
  567. package/src/zklogin/ZkLogin.ts +145 -0
  568. package/src/zklogin/ZkLoginAddress.ts +72 -0
  569. package/src/zklogin/ZkLoginVerifier.ts +37 -0
  570. package/src/zklogin/ZkLoginVerifierGrpc.ts +66 -0
  571. package/src/zklogin/index.ts +16 -0
  572. package/src/zklogin/internal/parse.ts +30 -0
  573. package/src/zklogin/internal/poseidon.ts +47 -0
@@ -0,0 +1,1188 @@
1
+ /**
2
+ * Turning a `Draft` into `TransactionData`, as a pipeline of small steps.
3
+ *
4
+ * Each step is `Plan -> Effect<Plan, E, R>`: it fills in one thing and states
5
+ * exactly which capability it needs. `Tx.resolve` runs the default pipeline;
6
+ * anything else (a sponsor setting gas, a custom coin picker, a policy check
7
+ * that rejects some Move calls) is one more step in the `pipe`.
8
+ *
9
+ * inputs Objects | Packages object refs, shared mutability, Receiving
10
+ * balances Coins | Objects `Ptb.coin` / `Ptb.balance` from address balance or coins,
11
+ * or under an allowance (checked against the allowance)
12
+ * gasPrice Chain reference gas price
13
+ * budget Transactions | Chain dry run with a placeholder payment
14
+ * payment (strategy) `auto` (default): address balance, else coins;
15
+ * or `addressBalance`, `coins`, `fixed(refs)`
16
+ *
17
+ * Or on the node: `server` completes object inputs, gas price, budget and
18
+ * payment in one simulation (`Transactions.resolve`) and verifies the answer
19
+ * (`verifyResolution`). It runs after `balances` and replaces `inputs`
20
+ * through payment.
21
+ */
22
+ import * as Effect from "effect/Effect";
23
+ import * as Option from "effect/Option";
24
+ import * as Schema from "effect/Schema";
25
+ import * as Stream from "effect/Stream";
26
+ import * as Bcs from "@unconfirmed/effect-bcs/Bcs";
27
+ import { normalize } from "./Address.js";
28
+ import { Chain } from "./Chain.js";
29
+ import { Coins } from "./Coins.js";
30
+ import { Objects } from "./Objects.js";
31
+ import { Packages } from "./Packages.js";
32
+ import * as CoinReservation from "./CoinReservation.js";
33
+ import * as T from "./TransactionData.js";
34
+ import { Transactions } from "./Transactions.js";
35
+ import * as TypeTag from "./TypeTag.js";
36
+ export class Incomplete extends /* @__PURE__ */ Schema.TaggedError()("Incomplete", {
37
+ missing: Schema.String
38
+ }) {
39
+ get message() {
40
+ return `missing ${this.missing}`;
41
+ }
42
+ }
43
+ /** The plan can't become valid transaction data (an invalid address, too many inputs, a reference to a later result, ...). */
44
+ export class InvalidTransaction extends /* @__PURE__ */ Schema.TaggedError()("InvalidTransaction", {
45
+ reason: Schema.String
46
+ }) {
47
+ get message() {
48
+ return this.reason;
49
+ }
50
+ }
51
+ /**
52
+ * A Move abort as the node reports it, from its structured error (not the
53
+ * description text). The same field (`abort`) on `GasEstimationFailed`,
54
+ * `Tx.SimulationFailed` and `Tx.ExecutionFailed`, so a caller matches one
55
+ * shape wherever the abort surfaced. Location fields are present when the
56
+ * transport reports them (gRPC and GraphQL do).
57
+ */
58
+ export const MoveAbort = /* @__PURE__ */ Schema.Struct({
59
+ /**
60
+ * The abort code: for a clever error (`#[error(code = N)] const E: vector<u8> = ...`)
61
+ * the code it declares, otherwise the u64 the chain aborted with (for a clever
62
+ * error without a code, its encoded u64). gRPC and GraphQL agree on it. Match
63
+ * a clever error by `constant`.
64
+ */
65
+ code: Schema.BigInt,
66
+ /** The aborting module's package. */
67
+ package: /* @__PURE__ */ Schema.optionalKey(Schema.String),
68
+ module: /* @__PURE__ */ Schema.optionalKey(Schema.String),
69
+ function: /* @__PURE__ */ Schema.optionalKey(Schema.String),
70
+ /** The bytecode offset of the abort in `function`. */
71
+ instruction: /* @__PURE__ */ Schema.optionalKey(Schema.Number),
72
+ /** A clever error's constant (`EAliasAlreadyExists`). */
73
+ constant: /* @__PURE__ */ Schema.optionalKey(Schema.String),
74
+ /** A clever error's source line. */
75
+ line: /* @__PURE__ */ Schema.optionalKey(Schema.Number),
76
+ /** A clever error's value, rendered as text by the node. */
77
+ rendered: /* @__PURE__ */ Schema.optionalKey(Schema.String)
78
+ });
79
+ /** The fields every failed-execution error shares: the node's description, the failing command, the Move abort. */
80
+ export const FailureFields = {
81
+ /** The node's description of the failure (free text; match on `command` and `abort` instead). */
82
+ description: Schema.String,
83
+ command: /* @__PURE__ */ Schema.optionalKey(Schema.Number),
84
+ abort: /* @__PURE__ */ Schema.optionalKey(MoveAbort)
85
+ };
86
+ /** `<description> in command N, abort code C at 0x…::module::function`. */
87
+ export const describeFailure = (f) => {
88
+ const a = f.abort;
89
+ const at = a?.module === undefined ? "" : ` at ${a.package ?? "?"}::${a.module}${a.function === undefined ? "" : `::${a.function}`}`;
90
+ return `${f.description}${f.command === undefined ? "" : ` in command ${f.command}`}${a === undefined ? "" : `, abort code ${a.code}${at}`}`;
91
+ };
92
+ /** The budget dry run (or the node's resolving simulation) failed: the transaction would fail on chain as it stands. */
93
+ export class GasEstimationFailed extends /* @__PURE__ */ Schema.TaggedError()("GasEstimationFailed", FailureFields) {
94
+ get message() {
95
+ return `gas estimation failed: ${describeFailure(this)}`;
96
+ }
97
+ }
98
+ /**
99
+ * The node's resolution (`Resolve.server`) failed verification: it changed
100
+ * something it must not (sender, gas owner, commands, an input it was given),
101
+ * or picked something it may not (another object, a weaker shared-object
102
+ * mutability, gas coins the gas owner doesn't own, an unbounded validity).
103
+ * Nothing was signed.
104
+ */
105
+ export class ResolutionRejected extends /* @__PURE__ */ Schema.TaggedError()("ResolutionRejected", {
106
+ reason: Schema.String
107
+ }) {
108
+ get message() {
109
+ return `refused the node's resolution: ${this.reason}`;
110
+ }
111
+ }
112
+ /** The resolved budget is above the caller's `maxGasBudget`. */
113
+ export class GasBudgetExceeded extends /* @__PURE__ */ Schema.TaggedError()("GasBudgetExceeded", {
114
+ budget: Schema.BigInt,
115
+ max: Schema.BigInt
116
+ }) {
117
+ get message() {
118
+ return `gas budget ${this.budget} is above the maximum ${this.max}`;
119
+ }
120
+ }
121
+ /**
122
+ * The gas owner's SUI can't pay. `required` is the budget, plus, when commands
123
+ * spend from the gas coin, the amounts they split off it.
124
+ */
125
+ export class InsufficientGas extends /* @__PURE__ */ Schema.TaggedError()("InsufficientGas", {
126
+ owner: Schema.String,
127
+ required: Schema.BigInt,
128
+ available: Schema.BigInt
129
+ }) {
130
+ get message() {
131
+ return `${this.owner} has ${this.available} MIST for gas, needs ${this.required}`;
132
+ }
133
+ }
134
+ export class InsufficientBalance extends /* @__PURE__ */ Schema.TaggedError()("InsufficientBalance", {
135
+ owner: Schema.String,
136
+ coinType: Schema.String,
137
+ required: Schema.BigInt,
138
+ available: Schema.BigInt
139
+ }) {
140
+ get message() {
141
+ return `${this.owner} has ${this.available} of ${this.coinType}, needs ${this.required}`;
142
+ }
143
+ }
144
+ export class InvalidBalanceIntent extends /* @__PURE__ */ Schema.TaggedError()("InvalidBalanceIntent", {
145
+ reason: Schema.String
146
+ }) {
147
+ get message() {
148
+ return this.reason;
149
+ }
150
+ }
151
+ /** No object with the allowance's id. */
152
+ export class AllowanceNotFound extends /* @__PURE__ */ Schema.TaggedError()("AllowanceNotFound", {
153
+ allowance: Schema.String
154
+ }) {
155
+ get message() {
156
+ return `allowance ${this.allowance} not found`;
157
+ }
158
+ }
159
+ /** The object isn't a shared `Allowance<Balance<T>>` for the intent's coin type, or its funder isn't the one the caller named. */
160
+ export class InvalidAllowance extends /* @__PURE__ */ Schema.TaggedError()("InvalidAllowance", {
161
+ allowance: Schema.String,
162
+ reason: Schema.String
163
+ }) {
164
+ get message() {
165
+ return `allowance ${this.allowance}: ${this.reason}`;
166
+ }
167
+ }
168
+ /**
169
+ * The permit doesn't fit the allowance: an app-bound allowance spent without a
170
+ * `SpendPermit`, a permit for another app, or a permit for an allowance that
171
+ * isn't app-bound. `null` means "no app".
172
+ */
173
+ export class AllowanceAppMismatch extends /* @__PURE__ */ Schema.TaggedError()("AllowanceAppMismatch", {
174
+ allowance: Schema.String,
175
+ allowanceApp: Schema.NullOr(Schema.String),
176
+ permitApp: Schema.NullOr(Schema.String)
177
+ }) {
178
+ get message() {
179
+ return `allowance ${this.allowance} is for app ${this.allowanceApp ?? "none"}, permit is for ${this.permitApp ?? "none"}`;
180
+ }
181
+ }
182
+ /** The sender isn't the allowance's spender (`null`: the allowance has none, so nobody can spend). */
183
+ export class AllowanceSpenderMismatch extends /* @__PURE__ */ Schema.TaggedError()("AllowanceSpenderMismatch", {
184
+ allowance: Schema.String,
185
+ spender: Schema.NullOr(Schema.String),
186
+ sender: Schema.String
187
+ }) {
188
+ get message() {
189
+ return `allowance ${this.allowance} spender is ${this.spender ?? "none"}, sender is ${this.sender}`;
190
+ }
191
+ }
192
+ /** The allowance's start time (inclusive) is after the chain clock. */
193
+ export class AllowanceNotStarted extends /* @__PURE__ */ Schema.TaggedError()("AllowanceNotStarted", {
194
+ allowance: Schema.String,
195
+ startTimestampMs: Schema.BigInt,
196
+ nowMs: Schema.BigInt
197
+ }) {
198
+ get message() {
199
+ return `allowance ${this.allowance} starts at ${this.startTimestampMs} ms, now ${this.nowMs}`;
200
+ }
201
+ }
202
+ /** The allowance's expiration (exclusive) has passed on the chain clock. */
203
+ export class AllowanceExpired extends /* @__PURE__ */ Schema.TaggedError()("AllowanceExpired", {
204
+ allowance: Schema.String,
205
+ expirationTimestampMs: Schema.BigInt,
206
+ nowMs: Schema.BigInt
207
+ }) {
208
+ get message() {
209
+ return `allowance ${this.allowance} expired at ${this.expirationTimestampMs} ms, now ${this.nowMs}`;
210
+ }
211
+ }
212
+ /** The transaction's spends would exceed the allowance's lifetime cap or its current rate-limit window. */
213
+ export class InsufficientAllowance extends /* @__PURE__ */ Schema.TaggedError()("InsufficientAllowance", {
214
+ allowance: Schema.String,
215
+ coinType: Schema.String,
216
+ limit: Schema.Literals(["lifetime", "rate"]),
217
+ required: Schema.BigInt,
218
+ available: Schema.BigInt
219
+ }) {
220
+ get message() {
221
+ return `allowance ${this.allowance} ${this.limit} limit has ${this.available} of ${this.coinType}, needs ${this.required}`;
222
+ }
223
+ }
224
+ // -----------------------------------------------------------------------------
225
+ // inputs
226
+ // -----------------------------------------------------------------------------
227
+ const TX_CONTEXT = "0x0000000000000000000000000000000000000000000000000000000000000002::tx_context::TxContext";
228
+ const RECEIVING = "0x0000000000000000000000000000000000000000000000000000000000000002::transfer::Receiving";
229
+ /** How each input is used: from commands, and from the called functions' parameter references. */
230
+ const usages = (draft, functions) => {
231
+ const out = new Map();
232
+ const mark = (arg, mutable, receiving = false) => {
233
+ if (arg._tag !== "Input")
234
+ return;
235
+ const u = out.get(arg.value);
236
+ out.set(arg.value, { mutable: (u?.mutable ?? false) || mutable, receiving: (u?.receiving ?? false) || receiving });
237
+ };
238
+ draft.commands.forEach((c, i) => {
239
+ switch (c._tag) {
240
+ case "MoveCall": {
241
+ const params = (functions.get(i)?.parameters ?? []).filter((p) => p.typeName !== TX_CONTEXT);
242
+ c.arguments.forEach((a, j) => {
243
+ const p = params[j];
244
+ mark(a, p === undefined || p.reference !== "Immutable", p?.typeName === RECEIVING);
245
+ });
246
+ return;
247
+ }
248
+ case "TransferObjects":
249
+ return c.objects.forEach((a) => mark(a, true));
250
+ case "SplitCoins":
251
+ return mark(c.coin, true);
252
+ case "MergeCoins":
253
+ return [c.destination, ...c.sources].forEach((a) => mark(a, true));
254
+ case "MakeMoveVec":
255
+ return c.elements.forEach((a) => mark(a, true));
256
+ case "AllowanceIntent":
257
+ mark(c.allowance, true);
258
+ mark(c.clock, false);
259
+ if (c.permit)
260
+ mark(c.permit, true);
261
+ return;
262
+ default:
263
+ return;
264
+ }
265
+ });
266
+ return out;
267
+ };
268
+ const objectArg = (o, usage, forced) => {
269
+ if (o.owner._tag === "Unknown") {
270
+ return new InvalidTransaction({ reason: `object ${o.objectId} has an owner kind (${o.owner.kind}) this SDK can't use as an input` });
271
+ }
272
+ if (o.owner._tag === "Shared" || o.owner._tag === "ConsensusAddressOwner") {
273
+ const mutable = forced ?? usage?.mutable ?? true;
274
+ return {
275
+ _tag: "SharedObject",
276
+ objectId: o.objectId,
277
+ initialSharedVersion: o.owner._tag === "Shared" ? o.owner.initialSharedVersion : o.owner.startVersion,
278
+ mutability: { _tag: mutable ? "Mutable" : "Immutable" }
279
+ };
280
+ }
281
+ const ref = { objectId: o.objectId, version: o.version, digest: o.digest };
282
+ return usage?.receiving ? { _tag: "Receiving", ...ref } : { _tag: "ImmOrOwnedObject", ...ref };
283
+ };
284
+ /**
285
+ * The signatures of the Move calls that take one of the `pending` inputs, by
286
+ * command index: one `getFunction` per target, all at once.
287
+ */
288
+ const functionsFor = (draft, pending) => {
289
+ const targetOf = (c) => `${c.package}::${c.module}::${c.function}`;
290
+ const calls = draft.commands.flatMap((c, index) => c._tag === "MoveCall" && c.arguments.some((a) => a._tag === "Input" && pending.has(a.value)) ? [{ c, index }] : []);
291
+ if (calls.length === 0)
292
+ return Effect.succeed(new Map());
293
+ const targets = new Map(calls.map(({ c }) => [targetOf(c), c]));
294
+ return Effect.flatMap(Effect.service(Packages), (packages) => Effect.map(Effect.forEach(targets, ([key, c]) => Effect.map(packages.getFunction(c), (f) => [key, f]), { concurrency: "unbounded" }), (signatures) => {
295
+ const byTarget = new Map(signatures);
296
+ return new Map(calls.map(({ c, index }) => [index, byTarget.get(targetOf(c))]));
297
+ }));
298
+ };
299
+ /** Inputs that allowance intents spend from: `Resolve.balances` reads and resolves those itself. */
300
+ const allowanceInputs = (draft) => new Set(draft.commands.flatMap((c) => (c._tag === "AllowanceIntent" && c.allowance._tag === "Input" ? [c.allowance.value] : [])));
301
+ /**
302
+ * Resolve object inputs. All lookups run at once; the `Objects` and
303
+ * `Packages` implementations batch and cache them. Signatures are read only
304
+ * for Move calls that take an unresolved object, once per target. Allowance
305
+ * objects are left for `Resolve.balances`, which reads their contents anyway.
306
+ */
307
+ export const inputs = (plan) => Effect.gen(function* () {
308
+ const skip = allowanceInputs(plan.draft);
309
+ const unresolved = plan.draft.inputs.flatMap((input, index) => input._tag === "UnresolvedObject" && !skip.has(index) ? [{ input, index }] : []);
310
+ if (unresolved.length === 0)
311
+ return plan;
312
+ const objects = yield* Objects;
313
+ const [resolved, functions] = yield* Effect.all([
314
+ Effect.forEach(unresolved, ({ input }) => objects.get(input.objectId), { concurrency: "unbounded" }),
315
+ functionsFor(plan.draft, new Set(unresolved.map(({ index }) => index)))
316
+ ], { concurrency: "unbounded" });
317
+ const use = usages(plan.draft, functions);
318
+ const next = [...plan.draft.inputs];
319
+ for (const [i, { input, index }] of unresolved.entries()) {
320
+ const arg = objectArg(resolved[i], use.get(index), input.mutable);
321
+ if (arg instanceof InvalidTransaction)
322
+ return yield* arg;
323
+ next[index] = { _tag: "Object", value: arg };
324
+ }
325
+ return { ...plan, draft: { ...plan.draft, inputs: next } };
326
+ });
327
+ // -----------------------------------------------------------------------------
328
+ // balances (coin / balance intents)
329
+ // -----------------------------------------------------------------------------
330
+ /** Every argument a command reads. */
331
+ export const argumentsOf = (c) => {
332
+ switch (c._tag) {
333
+ case "MoveCall":
334
+ return c.arguments;
335
+ case "TransferObjects":
336
+ return [...c.objects, c.address];
337
+ case "SplitCoins":
338
+ return [c.coin, ...c.amounts];
339
+ case "MergeCoins":
340
+ return [c.destination, ...c.sources];
341
+ case "MakeMoveVec":
342
+ return c.elements;
343
+ case "Upgrade":
344
+ return [c.ticket];
345
+ case "AllowanceIntent":
346
+ return c.permit ? [c.allowance, c.clock, c.permit] : [c.allowance, c.clock];
347
+ default:
348
+ return [];
349
+ }
350
+ };
351
+ export function mapArguments(c, f) {
352
+ switch (c._tag) {
353
+ case "MoveCall":
354
+ return { ...c, arguments: c.arguments.map(f) };
355
+ case "TransferObjects":
356
+ return { ...c, objects: c.objects.map(f), address: f(c.address) };
357
+ case "SplitCoins":
358
+ return { ...c, coin: f(c.coin), amounts: c.amounts.map(f) };
359
+ case "MergeCoins":
360
+ return { ...c, destination: f(c.destination), sources: c.sources.map(f) };
361
+ case "MakeMoveVec":
362
+ return { ...c, elements: c.elements.map(f) };
363
+ case "Upgrade":
364
+ return { ...c, ticket: f(c.ticket) };
365
+ case "AllowanceIntent":
366
+ return { ...c, allowance: f(c.allowance), clock: f(c.clock), ...(c.permit && { permit: f(c.permit) }) };
367
+ default:
368
+ return c;
369
+ }
370
+ }
371
+ const encodeU64 = /* @__PURE__ */ Bcs.encodeSync(Bcs.u64);
372
+ const encodeAddress = /* @__PURE__ */ Bcs.encodeSync(Bcs.Address);
373
+ const GAS = "gas";
374
+ /** @internal */
375
+ export const moveCall = (target, typeArguments, args) => {
376
+ const [pkg, module, fn] = target.split("::");
377
+ return {
378
+ _tag: "MoveCall",
379
+ package: normalize(pkg),
380
+ module,
381
+ function: fn,
382
+ typeArguments: (typeof typeArguments === "string" ? [typeArguments] : typeArguments).map(TypeTag.parse),
383
+ arguments: args
384
+ };
385
+ };
386
+ /** Where a command's results go after a rewrite: the same shape at a new position. */
387
+ /** @internal */
388
+ export const movedTo = (at) => (n) => n === undefined ? { _tag: "Result", value: at } : { _tag: "NestedResult", value: [at, n] };
389
+ /** A draft the intent rewrite can't map; thrown inside the rewrite and turned into `InvalidBalanceIntent`. */
390
+ class RewriteError {
391
+ reason;
392
+ constructor(reason) {
393
+ this.reason = reason;
394
+ }
395
+ }
396
+ /** An intent's single result, which is all a `Result` or `NestedResult(_, 0)` of it can mean. */
397
+ /** @internal */
398
+ export const singleResult = (index, r) => (n) => {
399
+ if (n === undefined || n === 0)
400
+ return r;
401
+ throw new RewriteError(`a coin/balance intent has a single result; NestedResult(${index}, ${n}) is invalid`);
402
+ };
403
+ /** Map a result reference through the rewrite so far; a reference to a command not yet seen is invalid. */
404
+ /** @internal */
405
+ export const remapWith = (results) => (a) => {
406
+ if (a._tag !== "Result" && a._tag !== "NestedResult")
407
+ return a;
408
+ const index = a._tag === "Result" ? a.value : a.value[0];
409
+ const to = results.get(index);
410
+ if (to === undefined)
411
+ throw new RewriteError(`command result ${index} is used before (or by) the command that makes it`);
412
+ return to(a._tag === "Result" ? undefined : a.value[1]);
413
+ };
414
+ /** Run a rewrite; its `RewriteError` becomes `InvalidBalanceIntent`. */
415
+ /** @internal */
416
+ export const rewrite = (f) => Effect.try({
417
+ try: f,
418
+ catch: (e) => {
419
+ if (e instanceof RewriteError)
420
+ return new InvalidBalanceIntent({ reason: e.reason });
421
+ throw e;
422
+ }
423
+ });
424
+ // -----------------------------------------------------------------------------
425
+ // allowances (coin / balance intents under an allowance)
426
+ // -----------------------------------------------------------------------------
427
+ /**
428
+ * Resolve allowance intents (`Ptb.coin({ allowance })` / `Ptb.balance({ allowance })`)
429
+ * as `@mysten/sui`'s `AllowanceBalance` resolver does: each becomes a
430
+ * `SenderAllowance` withdrawal from the funder, `allowance::balance_spend`
431
+ * (or `app_balance_spend<T, A>` with the permit) and, for a coin,
432
+ * `coin::from_balance`. The allowance input becomes a mutable shared object.
433
+ *
434
+ * Before that it reads each allowance (and, if its settings are time-bound or
435
+ * windowed, the clock) and refuses what the chain would abort: the wrong type
436
+ * or funder, a missing or wrong permit, a sender that isn't the spender, a
437
+ * spend outside the start/expiration window, beyond the lifetime cap or the
438
+ * current rate-limit window, or more than the funder's address balance holds.
439
+ *
440
+ * `Resolve.balances` runs this first; it's exported for hand-built pipelines.
441
+ */
442
+ export const allowances = (plan) => {
443
+ // The resolver travels with the intent, so programs without allowance intents don't link it.
444
+ const intent = plan.draft.commands.find((c) => c._tag === "AllowanceIntent");
445
+ return intent === undefined ? Effect.succeed(plan) : intent.resolve(plan);
446
+ };
447
+ const senderWithdrawal = (amount, coinType) => ({
448
+ _tag: "FundsWithdrawal",
449
+ reservation: { _tag: "MaxAmountU64", value: amount },
450
+ typeArg: { _tag: "Balance", value: TypeTag.parse(coinType) },
451
+ withdrawFrom: { _tag: "Sender" }
452
+ });
453
+ /**
454
+ * Source every `Ptb.coin` / `Ptb.balance` intent, replacing each with real
455
+ * commands (and remapping every later result reference), as `@mysten/sui`'s
456
+ * `coinWithBalance` resolver does:
457
+ *
458
+ * - all intents of a type are `balance` and the address balance covers them:
459
+ * one `balance::redeem_funds` per intent, no coins touched;
460
+ * - otherwise one source coin per type — `coin::redeem_funds` of the whole
461
+ * amount when the address balance covers it, else the gas coin (SUI with
462
+ * `useGasCoin`), else owned coins topped up from the address balance — then
463
+ * a single `SplitCoins` for all intents of that type, `coin::into_balance`
464
+ * for balance intents, and the remainder sent back to the sender's address
465
+ * balance (or a zero coin destroyed).
466
+ *
467
+ * Allowance intents (`Ptb.coin({ allowance })`) are resolved first, by
468
+ * `Resolve.allowances`, as `@mysten/sui` resolves `AllowanceBalance` before
469
+ * `CoinWithBalance`; the `Objects` requirement is only used for those.
470
+ *
471
+ * Run it after `Resolve.inputs` (so coins already used as inputs are skipped)
472
+ * and before the gas steps.
473
+ */
474
+ export const balances = (plan) => Effect.flatMap(allowances(plan), coinIntents);
475
+ const coinIntents = (plan) => Effect.gen(function* () {
476
+ if (!plan.draft.commands.some((c) => c._tag === "BalanceIntent"))
477
+ return plan;
478
+ const coinsService = yield* Coins;
479
+ // Group non-zero intents by source key ("gas" = SUI that may use the gas coin).
480
+ const types = new Map();
481
+ for (const c of plan.draft.commands) {
482
+ if (c._tag !== "BalanceIntent" || c.amount === 0n)
483
+ continue;
484
+ const key = c.coinType === TypeTag.SUI && c.useGasCoin ? GAS : c.coinType;
485
+ let t = types.get(key);
486
+ if (!t)
487
+ types.set(key, t = { coinType: c.coinType, intents: [], total: 0n, addressBalance: 0n, coins: [], coinTotal: 0n });
488
+ t.intents.push(c);
489
+ t.total += c.amount;
490
+ }
491
+ if (types.has(GAS) && types.has(TypeTag.SUI)) {
492
+ return yield* new InvalidBalanceIntent({
493
+ reason: "SUI intents that may use the gas coin can't be mixed with ones that don't (useGasCoin: false)"
494
+ });
495
+ }
496
+ // What the sender has, per type (all types at once). Coins already taken
497
+ // as inputs (resolved, or left for the node) are not picked again.
498
+ const used = new Set(plan.draft.inputs.flatMap((i) => i._tag === "Object" ? [i.value.objectId] : i._tag === "UnresolvedObject" ? [i.objectId] : []));
499
+ yield* Effect.forEach([...types], ([key, t]) => Effect.gen(function* () {
500
+ const balance = yield* balanceOf(plan, coinsService, plan.sender, t.coinType);
501
+ const reserved = reservedBy(plan, plan.sender, t.coinType);
502
+ const ab = balance.addressBalance - reserved;
503
+ if (ab < 0n) {
504
+ return yield* new InsufficientBalance({ owner: plan.sender, coinType: t.coinType, required: reserved, available: balance.addressBalance });
505
+ }
506
+ t.addressBalance = ab;
507
+ // The gas coin holds the sender's coins and (through a reservation) its
508
+ // address balance, so the gas path needs the same total as the others.
509
+ if (balance.total - reserved < t.total) {
510
+ return yield* new InsufficientBalance({ owner: plan.sender, coinType: t.coinType, required: t.total, available: balance.total - reserved });
511
+ }
512
+ if (key === GAS || ab >= t.total)
513
+ return;
514
+ // Owned coins, topped up from the address balance.
515
+ const needFromCoins = t.total - ab;
516
+ const picked = yield* coinsOf(plan, coinsService, plan.sender, t.coinType).pipe(Stream.filter((coin) => !used.has(coin.ref.objectId)), Stream.scan(() => ({ total: 0n, refs: [] }), (acc, coin) => ({
517
+ total: acc.total + coin.balance,
518
+ refs: [...acc.refs, coin.ref]
519
+ })), Stream.takeUntil((acc) => acc.total >= needFromCoins), Stream.runLast);
520
+ const got = Option.getOrElse(picked, () => ({ total: 0n, refs: [] }));
521
+ if (got.total + ab < t.total) {
522
+ return yield* new InsufficientBalance({ owner: plan.sender, coinType: t.coinType, required: t.total, available: got.total + ab });
523
+ }
524
+ t.coins = got.refs;
525
+ t.coinTotal = got.total;
526
+ }), { concurrency: "unbounded", discard: true });
527
+ // Rewrite the command list.
528
+ const inputs = [...plan.draft.inputs];
529
+ const addInput = (arg) => {
530
+ inputs.push(arg);
531
+ return { _tag: "Input", value: inputs.length - 1 };
532
+ };
533
+ const out = [];
534
+ const results = new Map();
535
+ const remap = remapWith(results);
536
+ const pending = new Map();
537
+ yield* rewrite(() => {
538
+ for (const [index, c] of plan.draft.commands.entries()) {
539
+ if (c._tag !== "BalanceIntent") {
540
+ const at = out.length;
541
+ out.push(mapArguments(c, remap));
542
+ results.set(index, (n) => (n === undefined ? { _tag: "Result", value: at } : { _tag: "NestedResult", value: [at, n] }));
543
+ continue;
544
+ }
545
+ if (c.amount === 0n) {
546
+ const at = out.length;
547
+ out.push(moveCall(c.output === "balance" ? "0x2::balance::zero" : "0x2::coin::zero", c.coinType, []));
548
+ results.set(index, (n) => (n === undefined ? { _tag: "Result", value: at } : { _tag: "NestedResult", value: [at, n] }));
549
+ continue;
550
+ }
551
+ const key = c.coinType === TypeTag.SUI && c.useGasCoin ? GAS : c.coinType;
552
+ const t = types.get(key);
553
+ let result;
554
+ if (t.intents.every((i) => i.output === "balance") && t.addressBalance >= t.total) {
555
+ out.push(moveCall("0x2::balance::redeem_funds", t.coinType, [addInput(senderWithdrawal(c.amount, t.coinType))]));
556
+ result = { _tag: "NestedResult", value: [out.length - 1, 0] };
557
+ }
558
+ else {
559
+ if (!pending.has(key)) {
560
+ const sources = [];
561
+ let fromAddressBalance = false;
562
+ let exact = false;
563
+ if (t.addressBalance >= t.total) {
564
+ fromAddressBalance = true;
565
+ out.push(moveCall("0x2::coin::redeem_funds", t.coinType, [addInput(senderWithdrawal(t.total, t.coinType))]));
566
+ sources.push({ _tag: "Result", value: out.length - 1 });
567
+ }
568
+ else if (key === GAS) {
569
+ sources.push({ _tag: "GasCoin" });
570
+ }
571
+ else {
572
+ const topUp = t.total > t.coinTotal ? t.total - t.coinTotal : 0n;
573
+ exact = t.coinTotal + topUp === t.total;
574
+ for (const ref of t.coins)
575
+ sources.push(addInput({ _tag: "Object", value: { _tag: "ImmOrOwnedObject", ...ref } }));
576
+ if (topUp > 0n) {
577
+ fromAddressBalance = true;
578
+ out.push(moveCall("0x2::coin::redeem_funds", t.coinType, [addInput(senderWithdrawal(topUp, t.coinType))]));
579
+ sources.push({ _tag: "Result", value: out.length - 1 });
580
+ }
581
+ }
582
+ const base = sources[0];
583
+ const rest = sources.slice(1);
584
+ for (let i = 0; i < rest.length; i += 500)
585
+ out.push({ _tag: "MergeCoins", destination: base, sources: rest.slice(i, i + 500) });
586
+ const split = out.length;
587
+ out.push({ _tag: "SplitCoins", coin: base, amounts: t.intents.map((i) => addInput({ _tag: "Pure", bytes: encodeU64(i.amount) })) });
588
+ const typeResults = [];
589
+ t.intents.forEach((i, n) => {
590
+ const piece = { _tag: "NestedResult", value: [split, n] };
591
+ if (i.output === "balance") {
592
+ out.push(moveCall("0x2::coin::into_balance", t.coinType, [piece]));
593
+ typeResults.push({ _tag: "NestedResult", value: [out.length - 1, 0] });
594
+ }
595
+ else {
596
+ typeResults.push(piece);
597
+ }
598
+ });
599
+ // The remainder: back to the sender's address balance, or a zero coin destroyed.
600
+ // A split from the gas coin leaves its remainder in the gas coin.
601
+ if (key !== GAS || fromAddressBalance) {
602
+ if (t.intents.some((i) => i.output === "balance") || fromAddressBalance) {
603
+ out.push(moveCall("0x2::coin::send_funds", t.coinType, [base, addInput({ _tag: "Pure", bytes: encodeAddress(plan.sender) })]));
604
+ }
605
+ else if (exact) {
606
+ out.push(moveCall("0x2::coin::destroy_zero", t.coinType, [base]));
607
+ }
608
+ }
609
+ pending.set(key, typeResults);
610
+ }
611
+ result = pending.get(key).shift();
612
+ }
613
+ results.set(index, singleResult(index, result));
614
+ }
615
+ });
616
+ return { ...plan, draft: { inputs, commands: out } };
617
+ });
618
+ // -----------------------------------------------------------------------------
619
+ // gas
620
+ // -----------------------------------------------------------------------------
621
+ /** How many of the gas owner's SUI coins `prefetch` lists (one page of the gRPC listing). */
622
+ const PREFETCH_COINS = 100;
623
+ /**
624
+ * Everything the default pipeline reads whatever the transaction is, in one
625
+ * round trip: the reference gas price (unless set), chain info (for the dry
626
+ * run's `ValidDuring`, a coin reservation or an address-balance expiration)
627
+ * and, unless `payment: false`, the gas owner's SUI balance and first page of
628
+ * SUI coins. `Tx.resolve` runs it alongside `Resolve.inputs`; later steps use
629
+ * what it read instead of asking again (as `@mysten/sui` does with one
630
+ * `Promise.all`).
631
+ */
632
+ export const prefetch = (plan, options) => Effect.gen(function* () {
633
+ const chain = Effect.service(Chain);
634
+ const coins = Effect.service(Coins);
635
+ const owner = plan.gasOwner ?? plan.sender;
636
+ const payment = options?.payment !== false && plan.gasPayment === undefined;
637
+ const [gasPrice, info, gasBalance, gasCoins] = yield* Effect.all([
638
+ plan.gasPrice !== undefined ? Effect.succeed(plan.gasPrice) : Effect.flatMap(chain, (c) => c.referenceGasPrice),
639
+ payment || (plan.gasBudget === undefined && plan.expiration === undefined)
640
+ ? Effect.flatMap(chain, (c) => c.info)
641
+ : Effect.succeed(undefined),
642
+ payment ? Effect.flatMap(coins, (c) => c.getBalance(owner, TypeTag.SUI)) : Effect.succeed(undefined),
643
+ payment
644
+ ? Effect.flatMap(coins, (c) => Stream.runCollect(Stream.take(c.list(owner, TypeTag.SUI), PREFETCH_COINS)))
645
+ : Effect.succeed(undefined)
646
+ ], { concurrency: "unbounded" });
647
+ return {
648
+ ...plan,
649
+ gasPrice,
650
+ prefetched: {
651
+ ...(info !== undefined && { chain: info }),
652
+ owner,
653
+ ...(gasBalance !== undefined && { gasBalance }),
654
+ ...(gasCoins !== undefined && { gasCoins })
655
+ }
656
+ };
657
+ });
658
+ /** `owner`'s balance of `coinType`: the prefetched SUI balance when the plan has it, else read. */
659
+ const balanceOf = (plan, coins, owner, coinType) => {
660
+ const pre = plan.prefetched;
661
+ return coinType === TypeTag.SUI && pre?.owner === owner && pre.gasBalance !== undefined
662
+ ? Effect.succeed(pre.gasBalance)
663
+ : coins.getBalance(owner, coinType);
664
+ };
665
+ /** `owner`'s coins of `coinType`: the prefetched SUI coins when they are all of them, else listed. */
666
+ const coinsOf = (plan, coins, owner, coinType) => {
667
+ const pre = plan.prefetched;
668
+ return coinType === TypeTag.SUI && pre?.owner === owner && pre.gasCoins !== undefined && pre.gasCoins.length < PREFETCH_COINS
669
+ ? Stream.fromIterable(pre.gasCoins)
670
+ : coins.list(owner, coinType);
671
+ };
672
+ const chainInfo = (plan) => plan.prefetched?.chain !== undefined ? Effect.succeed(plan.prefetched.chain) : Effect.flatMap(Effect.service(Chain), (c) => c.info);
673
+ export const gasPrice = (plan) => plan.gasPrice !== undefined
674
+ ? Effect.succeed(plan)
675
+ : Effect.map(Effect.flatMap(Effect.service(Chain), (c) => c.referenceGasPrice), (gasPrice) => ({ ...plan, gasPrice }));
676
+ const validDuringFor = (info) => ({
677
+ _tag: "ValidDuring",
678
+ minEpoch: Option.some(info.epoch),
679
+ maxEpoch: Option.some(info.epoch + 1n),
680
+ minTimestamp: Option.none(),
681
+ maxTimestamp: Option.none(),
682
+ chain: info.chainId,
683
+ nonce: crypto.getRandomValues(new Uint32Array(1))[0]
684
+ });
685
+ /** A `ValidDuring` expiration for this epoch and the next: the replay protection address-balance gas needs. */
686
+ export const validDuring = /* @__PURE__ */ Effect.fn("Resolve.validDuring")(function* () {
687
+ return validDuringFor(yield* Effect.flatMap(Effect.service(Chain), (c) => c.info));
688
+ });
689
+ const MAX_BUDGET = 50000000000n;
690
+ const GAS_SAFE_OVERHEAD = 1000n;
691
+ const programmable = (draft) => Effect.suspend(() => draft.commands.some((c) => c._tag === "BalanceIntent" || c._tag === "AllowanceIntent")
692
+ ? Effect.fail(new Incomplete({ missing: "coin/balance intents (run Resolve.balances)" }))
693
+ : draft.inputs.some((i) => i._tag === "UnresolvedObject")
694
+ ? Effect.fail(new Incomplete({ missing: "object inputs (run Resolve.inputs)" }))
695
+ : Effect.succeed({
696
+ _tag: "ProgrammableTransaction",
697
+ inputs: draft.inputs,
698
+ commands: draft.commands
699
+ }));
700
+ /** Commands may only use results of earlier commands, and inputs that exist. */
701
+ export const checkReferences = (kind) => {
702
+ if (kind._tag !== "ProgrammableTransaction")
703
+ return undefined;
704
+ for (const [i, c] of kind.commands.entries()) {
705
+ for (const a of argumentsOf(c)) {
706
+ const r = a._tag === "Result" ? a.value : a._tag === "NestedResult" ? a.value[0] : undefined;
707
+ if (r !== undefined && r >= i)
708
+ return new InvalidTransaction({ reason: `command ${i} uses the result of command ${r}` });
709
+ if (a._tag === "Input" && a.value >= kind.inputs.length)
710
+ return new InvalidTransaction({ reason: `command ${i} uses input ${a.value}, which doesn't exist` });
711
+ }
712
+ }
713
+ return undefined;
714
+ };
715
+ /** BCS bytes of transaction data; data that can't be encoded (bad address, too many inputs) is `InvalidTransaction`. */
716
+ export const encode = (data) => Effect.suspend(() => {
717
+ const bad = checkReferences(data.kind);
718
+ if (bad)
719
+ return Effect.fail(bad);
720
+ return Effect.try({
721
+ try: () => T.encode(data),
722
+ catch: (e) => new InvalidTransaction({ reason: e instanceof Error ? e.message : String(e) })
723
+ });
724
+ });
725
+ const encodeTransactionKind = /* @__PURE__ */ Bcs.encodeSync(T.TransactionKind);
726
+ /** BCS bytes of a transaction kind (`Ptb.buildKind`), checked like `encode`. */
727
+ export const encodeKind = (kind) => Effect.suspend(() => {
728
+ const bad = checkReferences(kind);
729
+ if (bad)
730
+ return Effect.fail(bad);
731
+ return Effect.try({
732
+ try: () => encodeTransactionKind(kind),
733
+ catch: (e) => new InvalidTransaction({ reason: e instanceof Error ? e.message : String(e) })
734
+ });
735
+ });
736
+ /** A failure status's Move abort, when it is one. */
737
+ export const abortOf = (status) => {
738
+ if (status.abortCode === undefined)
739
+ return undefined;
740
+ const loc = status.location;
741
+ const clever = status.cleverError;
742
+ return {
743
+ // A clever error's own code when it declares one, as GraphQL reports it; else the u64 the chain aborted with.
744
+ code: clever?.errorCode ?? status.abortCode,
745
+ ...(loc !== undefined && { package: loc.package, module: loc.module }),
746
+ ...(loc?.function !== undefined && { function: loc.function }),
747
+ ...(loc?.instruction !== undefined && { instruction: loc.instruction }),
748
+ ...(clever?.constantName !== undefined && { constant: clever.constantName }),
749
+ ...(clever?.lineNumber !== undefined && { line: Number(clever.lineNumber) }),
750
+ ...(clever?.rendered !== undefined && { rendered: clever.rendered })
751
+ };
752
+ };
753
+ /** A failure status's fields (`FailureFields`), for the errors that report one. */
754
+ export const failureFields = (status) => {
755
+ const abort = abortOf(status);
756
+ return {
757
+ description: status.description,
758
+ ...(status.command !== undefined && { command: status.command }),
759
+ ...(abort !== undefined && { abort })
760
+ };
761
+ };
762
+ /**
763
+ * Estimate the budget with a dry run: maximum budget, empty payment and a
764
+ * `ValidDuring` expiration, so the node mocks the gas coin and the estimate
765
+ * does not depend on which coins pay.
766
+ */
767
+ export const budget = (plan) => plan.gasBudget !== undefined
768
+ ? Effect.succeed(plan)
769
+ : Effect.gen(function* () {
770
+ const price = plan.gasPrice ?? (yield* Effect.flatMap(Effect.service(Chain), (c) => c.referenceGasPrice));
771
+ const kind = yield* programmable(plan.draft);
772
+ const dryRun = yield* encode({
773
+ _tag: "V1",
774
+ kind,
775
+ sender: plan.sender,
776
+ gasData: { payment: [], owner: plan.gasOwner ?? plan.sender, price, budget: MAX_BUDGET },
777
+ expiration: plan.expiration ?? validDuringFor(yield* chainInfo(plan))
778
+ });
779
+ const sim = yield* Effect.flatMap(Effect.service(Transactions), (t) => t.simulate(dryRun));
780
+ if (sim.effects.status._tag === "Failure")
781
+ return yield* new GasEstimationFailed(failureFields(sim.effects.status));
782
+ const g = sim.effects.gasUsed;
783
+ const base = g.computationCost + GAS_SAFE_OVERHEAD * price;
784
+ const total = base + g.storageCost - g.storageRebate;
785
+ return { ...plan, gasPrice: price, gasBudget: total > base ? total : base };
786
+ });
787
+ /** Does any command take the gas coin as an argument? */
788
+ export const usesGasCoin = (draft) => draft.commands.some((c) => argumentsOf(c).some((a) => a._tag === "GasCoin"));
789
+ const decodeU64 = (bytes) => bytes.length === 8 ? new DataView(bytes.buffer, bytes.byteOffset, 8).getBigUint64(0, true) : undefined;
790
+ /**
791
+ * What commands split off the gas coin, as far as the draft says: the pure
792
+ * amounts of every `SplitCoins(GasCoin, ...)`. Other uses (a Move call taking
793
+ * the gas coin, an amount computed on chain) can't be known before execution.
794
+ */
795
+ export const gasCoinSpend = (draft) => {
796
+ let total = 0n;
797
+ for (const c of draft.commands) {
798
+ if (c._tag !== "SplitCoins" || c.coin._tag !== "GasCoin")
799
+ continue;
800
+ for (const a of c.amounts) {
801
+ const input = a._tag === "Input" ? draft.inputs[a.value] : undefined;
802
+ if (input?._tag === "Pure")
803
+ total += decodeU64(input.bytes) ?? 0n;
804
+ }
805
+ }
806
+ return total;
807
+ };
808
+ /** Who a withdrawal input draws from. */
809
+ const withdrawalOwner = (w, plan) => w.withdrawFrom._tag === "SenderAllowance"
810
+ ? w.withdrawFrom.funder
811
+ : w.withdrawFrom._tag === "Sender"
812
+ ? plan.sender
813
+ : plan.gasOwner ?? plan.sender;
814
+ /** The `coinType` amounts that the transaction's withdrawal inputs reserve from `owner`'s address balance. */
815
+ export const reservedBy = (plan, owner, coinType) => {
816
+ let total = 0n;
817
+ for (const input of plan.draft.inputs) {
818
+ if (input._tag !== "FundsWithdrawal")
819
+ continue;
820
+ if (withdrawalOwner(input, plan) !== owner)
821
+ continue;
822
+ if (TypeTag.format(input.typeArg.value) !== coinType)
823
+ continue;
824
+ total += input.reservation.value;
825
+ }
826
+ return total;
827
+ };
828
+ /**
829
+ * Address-balance gas needs replay protection: a `ValidDuring` window is set
830
+ * when the caller gave no expiration. An explicit one is kept as given, as
831
+ * `@mysten/sui` does (validators refuse `None`/`Epoch` with an empty payment,
832
+ * which is a visible failure rather than a silently widened validity).
833
+ */
834
+ const keepExpiration = (plan) => plan.expiration !== undefined ? Effect.succeed(plan.expiration) : Effect.map(chainInfo(plan), validDuringFor);
835
+ const needBudget = (plan) => plan.gasBudget === undefined
836
+ ? Effect.fail(new Incomplete({ missing: "gas budget (run Resolve.budget first)" }))
837
+ : Effect.succeed(plan.gasBudget);
838
+ /** A reservation ref for whatever the owner's SUI address balance holds beyond the transaction's own withdrawals. */
839
+ const reservation = (plan, owner, available) => Effect.map(chainInfo(plan), (info) => CoinReservation.make({ reserved: available, owner, chainId: info.chainId, epoch: info.epoch }));
840
+ const gasBalance = (plan, owner) => Effect.flatMap(Effect.service(Coins), (c) => balanceOf(plan, c, owner, TypeTag.SUI));
841
+ /**
842
+ * Pay entirely from the gas owner's SUI address balance, or fail with
843
+ * `InsufficientGas` before anything is signed. No coin is touched: the payment
844
+ * is empty with a `ValidDuring` expiration, or, when the transaction uses the
845
+ * gas coin, a single coin reservation that funds it from the balance (which
846
+ * must then also cover what commands split off the gas coin).
847
+ */
848
+ export const addressBalance = (plan) => Effect.gen(function* () {
849
+ if (plan.gasPayment !== undefined)
850
+ return plan;
851
+ const budget = yield* needBudget(plan);
852
+ const owner = plan.gasOwner ?? plan.sender;
853
+ const balance = yield* gasBalance(plan, owner);
854
+ const available = balance.addressBalance - reservedBy(plan, owner, TypeTag.SUI);
855
+ const gasCoin = usesGasCoin(plan.draft);
856
+ const required = budget + (gasCoin ? gasCoinSpend(plan.draft) : 0n);
857
+ if (available < required)
858
+ return yield* new InsufficientGas({ owner, required, available: available < 0n ? 0n : available });
859
+ if (gasCoin)
860
+ return { ...plan, gasPayment: [yield* reservation(plan, owner, available)] };
861
+ return { ...plan, gasPayment: [], expiration: yield* keepExpiration(plan) };
862
+ });
863
+ /** SUI coins of `owner` not already used as inputs, in listing order, until they reach `target` or `limit` coins (`target` undefined: all of them, up to `limit`). */
864
+ const pickCoins = (plan, owner, target, limit) => Effect.gen(function* () {
865
+ const used = new Set(plan.draft.inputs.flatMap((i) => (i._tag === "Object" ? [i.value.objectId] : [])));
866
+ const picked = yield* Effect.flatMap(Effect.service(Coins), (c) => coinsOf(plan, c, owner, TypeTag.SUI).pipe(Stream.filter((coin) => !used.has(coin.ref.objectId)), Stream.scan(() => ({ total: 0n, refs: [] }), (acc, coin) => ({
867
+ total: acc.total + coin.balance,
868
+ refs: [...acc.refs, coin.ref]
869
+ })), Stream.takeUntil((acc) => (target !== undefined && acc.total >= target) || acc.refs.length >= limit), Stream.runLast));
870
+ return Option.getOrElse(picked, () => ({ total: 0n, refs: [] }));
871
+ });
872
+ /**
873
+ * Payment when commands spend from the gas coin: every SUI coin of the owner
874
+ * not used as an input (up to the 256-object limit, one taken by a reservation
875
+ * of the address balance when it holds any), as `@mysten/sui` does, so the gas
876
+ * coin holds everything the owner has. Fails with `InsufficientGas` when that
877
+ * is less than the budget plus the amounts split off the gas coin.
878
+ */
879
+ const payWithGasCoin = (plan, owner, budget, available) => Effect.gen(function* () {
880
+ const fromBalance = available > 0n ? available : 0n;
881
+ const limit = fromBalance > 0n ? MAX_GAS_OBJECTS - 1 : MAX_GAS_OBJECTS;
882
+ const required = budget + gasCoinSpend(plan.draft);
883
+ // The prefetched first page, when it already covers what the gas coin must
884
+ // hold (as `@mysten/sui` uses its first page); otherwise every coin, listed.
885
+ const used = new Set(plan.draft.inputs.flatMap((i) => (i._tag === "Object" ? [i.value.objectId] : [])));
886
+ const page = plan.prefetched?.owner === owner ? plan.prefetched.gasCoins?.filter((c) => !used.has(c.ref.objectId)).slice(0, limit) : undefined;
887
+ const pageTotal = page?.reduce((s, c) => s + c.balance, 0n) ?? 0n;
888
+ const coins = page !== undefined && page.length > 0 && pageTotal + fromBalance >= required
889
+ ? { total: pageTotal, refs: page.map((c) => c.ref) }
890
+ : yield* pickCoins(plan, owner, undefined, limit);
891
+ const total = coins.total + fromBalance;
892
+ if (total < required || (fromBalance === 0n && coins.refs.length === 0)) {
893
+ return yield* new InsufficientGas({ owner, required, available: total });
894
+ }
895
+ const refs = fromBalance > 0n ? [yield* reservation(plan, owner, fromBalance), ...coins.refs] : coins.refs;
896
+ return { ...plan, gasPayment: refs };
897
+ });
898
+ const MAX_GAS_OBJECTS = 256;
899
+ /**
900
+ * The recommended default, matching `@mysten/sui`: pay from the address
901
+ * balance when it covers the budget (plus the transaction's own SUI
902
+ * withdrawals) and the gas coin isn't used. When commands use the gas coin,
903
+ * pay with every SUI coin, plus a coin reservation of the address balance, so
904
+ * the gas coin can cover what they spend. Otherwise pay with SUI coins up to
905
+ * the budget. Fails with `InsufficientGas` when none of that covers it.
906
+ */
907
+ export const auto = (plan) => Effect.gen(function* () {
908
+ if (plan.gasPayment !== undefined)
909
+ return plan;
910
+ const budget = yield* needBudget(plan);
911
+ const owner = plan.gasOwner ?? plan.sender;
912
+ const gasCoin = usesGasCoin(plan.draft);
913
+ const balance = yield* gasBalance(plan, owner);
914
+ const available = balance.addressBalance - reservedBy(plan, owner, TypeTag.SUI);
915
+ if (budget === 0n || (!gasCoin && available >= budget)) {
916
+ return { ...plan, gasPayment: [], expiration: yield* keepExpiration(plan) };
917
+ }
918
+ if (gasCoin)
919
+ return yield* payWithGasCoin(plan, owner, budget, available);
920
+ const coins = yield* pickCoins(plan, owner, budget, MAX_GAS_OBJECTS);
921
+ if (coins.total < budget) {
922
+ return yield* new InsufficientGas({ owner, required: budget, available: coins.total + (available > 0n ? available : 0n) });
923
+ }
924
+ return { ...plan, gasPayment: coins.refs };
925
+ });
926
+ /**
927
+ * An empty payment with a `ValidDuring` expiration and no balance check: for
928
+ * simulation (`checks: false`) and for bytes whose payer will be funded
929
+ * before they're submitted. Executing it without a funded address balance
930
+ * fails at the node.
931
+ */
932
+ export const unchecked = (plan) => plan.gasPayment !== undefined
933
+ ? Effect.succeed(plan)
934
+ : Effect.map(keepExpiration(plan), (expiration) => ({ ...plan, gasPayment: [], expiration }));
935
+ /** Pay with exactly these coins. */
936
+ export const fixed = (payment) => Object.assign((plan) => Effect.succeed({ ...plan, gasPayment: payment }), { payment });
937
+ /**
938
+ * Pay with SUI coins owned by the gas owner (at most 256): until they cover the
939
+ * budget, or, when commands use the gas coin, all of them (which must cover the
940
+ * budget plus what is split off the gas coin).
941
+ */
942
+ export const coins = (plan) => Effect.gen(function* () {
943
+ if (plan.gasPayment !== undefined)
944
+ return plan;
945
+ if (plan.gasBudget === undefined)
946
+ return yield* new Incomplete({ missing: "gas budget (run Resolve.budget first)" });
947
+ const owner = plan.gasOwner ?? plan.sender;
948
+ const budget = plan.gasBudget;
949
+ const gasCoin = usesGasCoin(plan.draft);
950
+ const required = budget + (gasCoin ? gasCoinSpend(plan.draft) : 0n);
951
+ const best = yield* pickCoins(plan, owner, gasCoin ? undefined : budget, MAX_GAS_OBJECTS);
952
+ if (best.total < required || (gasCoin && best.refs.length === 0))
953
+ return yield* new InsufficientGas({ owner, required, available: best.total });
954
+ return { ...plan, gasPayment: best.refs };
955
+ });
956
+ // -----------------------------------------------------------------------------
957
+ // server (one simulation on the node, verified)
958
+ // -----------------------------------------------------------------------------
959
+ const encodeCommands = /* @__PURE__ */ Bcs.encodeSync(Bcs.vector(T.Command));
960
+ const encodeCallArg = /* @__PURE__ */ Bcs.encodeSync(T.CallArg);
961
+ const encodeRefs = /* @__PURE__ */ Bcs.encodeSync(Bcs.vector(T.ObjectRef));
962
+ const encodeExpiration = /* @__PURE__ */ Bcs.encodeSync(T.TransactionExpiration);
963
+ const sameBytes = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
964
+ const hasIntents = (draft) => draft.commands.some((c) => c._tag === "BalanceIntent" || c._tag === "AllowanceIntent");
965
+ /** Is the reservation ref `ref` one for `owner`'s SUI address balance on the chain `chainId`? */
966
+ const reservationFor = (ref, owner, chainId) => {
967
+ try {
968
+ return CoinReservation.make({ reserved: 0n, owner, chainId, epoch: 0n }).objectId === ref.objectId;
969
+ }
970
+ catch {
971
+ return false;
972
+ }
973
+ };
974
+ /**
975
+ * Check the node's completed transaction against the plan it was asked to
976
+ * complete (`Resolve.server` runs this; exported for tests and custom flows).
977
+ *
978
+ * - sender and gas owner unchanged; commands byte-for-byte unchanged;
979
+ * - every input the plan had resolved unchanged; every unresolved one an
980
+ * object with the id asked for: a shared object at least as mutable as the
981
+ * commands need (forced mutability exactly as forced), `Receiving` exactly
982
+ * where a called function takes `Receiving<T>`;
983
+ * - gas price, budget, payment and expiration exactly as given when given;
984
+ * otherwise a positive price, a budget within `maxGasBudget` (default: the
985
+ * protocol maximum, 50 SUI), payment coins the simulation shows the gas
986
+ * owner owned at those versions (or reservations of the gas owner's address
987
+ * balance), no input doubling as gas, and no expiration or a `ValidDuring`
988
+ * of at most two epochs around the simulated one.
989
+ *
990
+ * `functions` are the signatures of the Move calls taking an unresolved
991
+ * object, by command index (as `Resolve.inputs` reads them).
992
+ */
993
+ export const verifyResolution = (plan, data, effects, functions, epoch) => {
994
+ const refuse = (reason) => new ResolutionRejected({ reason });
995
+ const gasOwner = plan.gasOwner ?? plan.sender;
996
+ if (data.sender !== plan.sender)
997
+ return refuse(`sender changed to ${data.sender}`);
998
+ if (data.gasData.owner !== gasOwner)
999
+ return refuse(`gas owner changed to ${data.gasData.owner}`);
1000
+ const kind = data.kind;
1001
+ const ours = plan.draft.commands;
1002
+ if (!sameBytes(encodeCommands(kind.commands), encodeCommands(ours)))
1003
+ return refuse("the commands changed");
1004
+ if (kind.inputs.length !== plan.draft.inputs.length) {
1005
+ return refuse(`${kind.inputs.length} inputs for ${plan.draft.inputs.length}`);
1006
+ }
1007
+ const use = usages(plan.draft, functions);
1008
+ const objectIds = new Set();
1009
+ for (const [i, asked] of plan.draft.inputs.entries()) {
1010
+ const got = kind.inputs[i];
1011
+ if (got._tag === "Object")
1012
+ objectIds.add(got.value.objectId);
1013
+ if (asked._tag !== "UnresolvedObject") {
1014
+ if (!sameBytes(encodeCallArg(got), encodeCallArg(asked)))
1015
+ return refuse(`input ${i} changed`);
1016
+ continue;
1017
+ }
1018
+ if (got._tag !== "Object" || got.value.objectId !== asked.objectId) {
1019
+ return refuse(`input ${i} is not object ${asked.objectId}`);
1020
+ }
1021
+ const usage = use.get(i);
1022
+ const o = got.value;
1023
+ switch (o._tag) {
1024
+ case "SharedObject": {
1025
+ if (usage?.receiving)
1026
+ return refuse(`input ${i} must be Receiving, got a shared object`);
1027
+ const m = o.mutability._tag;
1028
+ if (asked.mutable !== undefined) {
1029
+ if (m !== (asked.mutable ? "Mutable" : "Immutable")) {
1030
+ return refuse(`input ${i} was forced ${asked.mutable ? "mutable" : "immutable"}, got ${m}`);
1031
+ }
1032
+ }
1033
+ else if ((usage?.mutable ?? true) && m !== "Mutable") {
1034
+ return refuse(`input ${i} (shared ${o.objectId}) must be Mutable for its commands, got ${m}`);
1035
+ }
1036
+ break;
1037
+ }
1038
+ case "Receiving":
1039
+ if (!usage?.receiving)
1040
+ return refuse(`input ${i} is Receiving, but no command receives it`);
1041
+ break;
1042
+ case "ImmOrOwnedObject":
1043
+ if (usage?.receiving)
1044
+ return refuse(`input ${i} must be Receiving, got an owned object`);
1045
+ break;
1046
+ }
1047
+ }
1048
+ const gas = data.gasData;
1049
+ if (plan.gasPrice !== undefined ? gas.price !== plan.gasPrice : gas.price <= 0n)
1050
+ return refuse(`gas price ${gas.price}`);
1051
+ const maxBudget = plan.maxGasBudget ?? MAX_BUDGET;
1052
+ if (plan.gasBudget !== undefined) {
1053
+ if (gas.budget !== plan.gasBudget)
1054
+ return refuse(`gas budget changed to ${gas.budget}`);
1055
+ }
1056
+ else if (gas.budget > maxBudget) {
1057
+ return refuse(`gas budget ${gas.budget} is above ${maxBudget}`);
1058
+ }
1059
+ const e = data.expiration;
1060
+ if (plan.expiration !== undefined) {
1061
+ if (!sameBytes(encodeExpiration(e), encodeExpiration(plan.expiration)))
1062
+ return refuse("the expiration changed");
1063
+ }
1064
+ else if (e._tag !== "None") {
1065
+ if (e._tag !== "ValidDuring")
1066
+ return refuse(`expiration ${e._tag} where none was asked for`);
1067
+ const v = e;
1068
+ const bounded = Option.isSome(v.minEpoch) && Option.isSome(v.maxEpoch) && Option.isNone(v.minTimestamp) &&
1069
+ Option.isNone(v.maxTimestamp) && v.maxEpoch.value >= v.minEpoch.value && v.maxEpoch.value - v.minEpoch.value <= 1n &&
1070
+ (epoch === undefined || (v.minEpoch.value <= epoch && epoch <= v.maxEpoch.value));
1071
+ if (!bounded)
1072
+ return refuse("the expiration is not a ValidDuring window of at most two epochs around the simulated one");
1073
+ }
1074
+ if (plan.gasPayment !== undefined) {
1075
+ return sameBytes(encodeRefs(gas.payment), encodeRefs(plan.gasPayment)) ? undefined : refuse("the gas payment changed");
1076
+ }
1077
+ const chainId = e._tag === "ValidDuring" || e._tag === "Validity" ? e.chain : undefined;
1078
+ const seen = new Set();
1079
+ for (const ref of gas.payment) {
1080
+ if (seen.has(ref.objectId))
1081
+ return refuse(`gas object ${ref.objectId} appears twice`);
1082
+ seen.add(ref.objectId);
1083
+ if (objectIds.has(ref.objectId))
1084
+ return refuse(`gas object ${ref.objectId} is also an input`);
1085
+ if (CoinReservation.isReservation(ref)) {
1086
+ if (ref.version !== 0n || chainId === undefined || !reservationFor(ref, gasOwner, chainId)) {
1087
+ return refuse(`gas reservation ${ref.objectId} is not one of ${gasOwner}'s address balance`);
1088
+ }
1089
+ continue;
1090
+ }
1091
+ const c = effects.changedObjects.find((x) => x.objectId === ref.objectId);
1092
+ const owner = c?.inputOwner;
1093
+ if (c === undefined || c.inputVersion !== ref.version || c.inputDigest !== ref.digest ||
1094
+ owner?._tag !== "AddressOwner" || owner.address !== gasOwner) {
1095
+ return refuse(`gas coin ${ref.objectId} is not owned by ${gasOwner} at version ${ref.version}`);
1096
+ }
1097
+ }
1098
+ return undefined;
1099
+ };
1100
+ /** The plan as a request to the node: unresolved objects by id, gas fields only where fixed. */
1101
+ const unresolvedOf = (plan) => ({
1102
+ sender: plan.sender,
1103
+ gasOwner: plan.gasOwner ?? plan.sender,
1104
+ inputs: plan.draft.inputs,
1105
+ commands: plan.draft.commands,
1106
+ ...(plan.gasPrice !== undefined && { gasPrice: plan.gasPrice }),
1107
+ ...(plan.gasBudget !== undefined && { gasBudget: plan.gasBudget }),
1108
+ ...(plan.gasPayment !== undefined && { gasPayment: plan.gasPayment }),
1109
+ ...(plan.expiration !== undefined && { expiration: plan.expiration })
1110
+ });
1111
+ /**
1112
+ * Complete the plan on the node in one simulation (`Transactions.resolve`,
1113
+ * checks and gas selection on), as `@mysten/sui`'s gRPC and GraphQL clients
1114
+ * do: object versions and shared-object mutability, gas price, budget and
1115
+ * payment (from coins or the address balance, with a `ValidDuring` expiration
1116
+ * then), keeping whatever the plan already fixed. The signatures of the Move
1117
+ * calls taking an unresolved object are read at the same time (cached by
1118
+ * `Packages`), and the answer is checked by `verifyResolution` before use.
1119
+ *
1120
+ * Run `Resolve.balances` first (coin/balance intents stay client-side), then
1121
+ * `finish`. A simulated failure is `GasEstimationFailed`; a transport without
1122
+ * `resolve` is `Incomplete`.
1123
+ */
1124
+ export const server = (plan) => Effect.gen(function* () {
1125
+ if (hasIntents(plan.draft))
1126
+ return yield* new Incomplete({ missing: "coin/balance intents (run Resolve.balances)" });
1127
+ const transactions = yield* Transactions;
1128
+ if (transactions.resolve === undefined) {
1129
+ return yield* new Incomplete({ missing: "server-side resolution (this Transactions transport has no resolve)" });
1130
+ }
1131
+ const bad = checkReferences({
1132
+ _tag: "ProgrammableTransaction",
1133
+ inputs: plan.draft.inputs,
1134
+ commands: plan.draft.commands
1135
+ });
1136
+ if (bad)
1137
+ return yield* bad;
1138
+ const pending = new Set(plan.draft.inputs.flatMap((input, i) => (input._tag === "UnresolvedObject" ? [i] : [])));
1139
+ const [resolution, functions] = yield* Effect.all([
1140
+ transactions.resolve(unresolvedOf(plan)),
1141
+ functionsFor(plan.draft, pending)
1142
+ ], { concurrency: "unbounded" });
1143
+ if (resolution.effects.status._tag === "Failure")
1144
+ return yield* new GasEstimationFailed(failureFields(resolution.effects.status));
1145
+ const decoded = T.decode(resolution.transaction);
1146
+ if (decoded._tag === "Failure")
1147
+ return yield* new ResolutionRejected({ reason: `not TransactionData: ${decoded.failure.message}` });
1148
+ const data = decoded.success;
1149
+ const refused = verifyResolution(plan, data, resolution.effects, functions, resolution.epoch);
1150
+ if (refused)
1151
+ return yield* refused;
1152
+ return {
1153
+ ...plan,
1154
+ draft: { inputs: data.kind.inputs, commands: plan.draft.commands },
1155
+ gasPrice: data.gasData.price,
1156
+ gasBudget: data.gasData.budget,
1157
+ gasPayment: data.gasData.payment,
1158
+ ...(data.expiration._tag !== "None" || plan.expiration !== undefined ? { expiration: data.expiration } : {})
1159
+ };
1160
+ }).pipe(Effect.withSpan("Resolve.server"));
1161
+ // -----------------------------------------------------------------------------
1162
+ // finish
1163
+ // -----------------------------------------------------------------------------
1164
+ /** The final `TransactionData`; fails with `InvalidTransaction` if it can't be encoded as it stands. */
1165
+ export const finish = (plan) => Effect.gen(function* () {
1166
+ const kind = yield* programmable(plan.draft);
1167
+ if (plan.gasPrice === undefined)
1168
+ return yield* new Incomplete({ missing: "gas price" });
1169
+ if (plan.gasBudget === undefined)
1170
+ return yield* new Incomplete({ missing: "gas budget" });
1171
+ if (plan.gasPayment === undefined)
1172
+ return yield* new Incomplete({ missing: "gas payment" });
1173
+ const data = {
1174
+ _tag: "V1",
1175
+ kind,
1176
+ sender: plan.sender,
1177
+ gasData: {
1178
+ payment: plan.gasPayment,
1179
+ owner: plan.gasOwner ?? plan.sender,
1180
+ price: plan.gasPrice,
1181
+ budget: plan.gasBudget
1182
+ },
1183
+ expiration: plan.expiration ?? { _tag: "None" }
1184
+ };
1185
+ yield* encode(data);
1186
+ return data;
1187
+ });
1188
+ //# sourceMappingURL=Resolve.js.map