@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,990 @@
1
+ /**
2
+ * The crash-safe transaction lifecycle on top of the core capability services.
3
+ *
4
+ * const effects = yield* Lifecycle.run(recipe, { signer })
5
+ *
6
+ * `run` = core `Tx.build` -> sign -> journal -> `submit`. Each step is also
7
+ * exported for flows that stop in between.
8
+ *
9
+ * Rules (ported from `sui-effect`, the predecessor):
10
+ * - **Submit never rebuilds.** The `Signed` journal entry is written before the
11
+ * first execute; a retryable transport failure or timeout re-sends the
12
+ * identical bytes (one digest: they land at most once); when retries run out
13
+ * `reconcile` decides. Once bytes may have been sent, no transport error
14
+ * escapes: the answer is `Executed`, `ExecutionFailed`, `NotApplied` or
15
+ * `SubmissionUnknown` (which carries the bytes).
16
+ * - **Objects, never history listings, are evidence.** `NotApplied` needs proof:
17
+ * `inputConsumed` (another transaction's own effects consumed exactly a
18
+ * version these bytes pinned) or `expired` (window closed, then a miss, then
19
+ * after `reconcileRecheck` both again, on a node whose history covers the
20
+ * window). Positive evidence (a pinned object last mutated by *this* digest)
21
+ * vetoes `expired`.
22
+ * - **The journal never changes an answer.** `JournalError` only escapes from
23
+ * the `Signed` write, before anything was sent; later write failures are
24
+ * logged and the outcome stands.
25
+ */
26
+ import type { Address } from "../Address.ts"
27
+ import { Chain } from "../Chain.ts"
28
+ import { Objects } from "../Objects.ts"
29
+ import * as Resolve from "../Resolve.ts"
30
+ import { RpcError } from "../RpcError.ts"
31
+ import * as Signer from "../Signer.ts"
32
+ import * as T from "../TransactionData.ts"
33
+ import { type Effects, type Include, type IncludeOptions, Transactions } from "../Transactions.ts"
34
+ import * as Tx from "../Tx.ts"
35
+ import * as Clock from "effect/Clock"
36
+ import * as DateTime from "effect/DateTime"
37
+ import * as Duration from "effect/Duration"
38
+ import * as Effect from "effect/Effect"
39
+ import * as Option from "effect/Option"
40
+ import * as Result from "effect/Result"
41
+ import { Evidence } from "./Evidence.ts"
42
+ import { Journal } from "./Journal.ts"
43
+ import { SenderLock } from "./SenderLock.ts"
44
+ import { includeOf, isUnresolved, JournalEntry } from "./JournalEntry.ts"
45
+ import {
46
+ DigestMismatch,
47
+ ExecutionFailed,
48
+ type JournalError,
49
+ NotApplied,
50
+ type Reconciled,
51
+ SubmissionUnknown,
52
+ type SubmitError
53
+ } from "./Outcome.ts"
54
+ import * as Signed from "./SignedTransaction.ts"
55
+ import { SubmitConfig, type SubmitConfigService } from "./SubmitConfig.ts"
56
+
57
+ type SignedTransaction = Signed.SignedTransaction
58
+
59
+ /** What the lifecycle reads from the chain. */
60
+ export type Services = Transactions | Objects | Chain
61
+
62
+ type Settled = ExecutionFailed | NotApplied | SubmissionUnknown
63
+
64
+ /** The optional parts of the effects a submission asked for (`Transactions.IncludeOptions`). */
65
+ type Includes = ReadonlyArray<Include> | undefined
66
+
67
+ const withInclude = (include: Includes): IncludeOptions | undefined => include && { include }
68
+
69
+ // -----------------------------------------------------------------------------
70
+ // Small helpers
71
+ // -----------------------------------------------------------------------------
72
+
73
+ /** One line for a failure, never bytes. */
74
+ export const describe = (error: unknown): string => {
75
+ if (typeof error !== "object" || error === null) return String(error)
76
+ const e = error as Record<string, unknown>
77
+ const tag = typeof e._tag === "string" ? e._tag : "Error"
78
+ if (tag === "RpcError") return `RpcError ${String(e.code)} from ${String(e.method)}: ${String(e.message)}`
79
+ const detail = e.message ?? e.reason ?? e.description ?? e.evidence
80
+ return typeof detail === "string" && detail.length > 0 ? `${tag}: ${detail}` : tag
81
+ }
82
+
83
+ const isRetryable = (e: RpcError): boolean => e.retryable
84
+
85
+ const executionFailed = (effects: Effects): ExecutionFailed | undefined =>
86
+ effects.status._tag === "Failure"
87
+ ? new ExecutionFailed({ digest: effects.digest, ...Resolve.failureFields(effects.status) })
88
+ : undefined
89
+
90
+ /** One `Transactions.get`, with "not found" as `None`. */
91
+ const lookupOnce = (digest: string, include?: Includes): Effect.Effect<Option.Option<Effects>, RpcError, Transactions> =>
92
+ Effect.flatMap(Effect.service(Transactions), (t) => t.get(digest, withInclude(include))).pipe(
93
+ Effect.map(Option.some),
94
+ Effect.catchTag("TransactionNotFound", () => Effect.succeedNone)
95
+ )
96
+
97
+ /**
98
+ * Ask for `digest` every `interval` until it is served or `timeout` passes.
99
+ * `None` means every lookup missed; a transport failure that lasted to the
100
+ * deadline (or was not retryable) is returned as the failure, because it is
101
+ * not a miss. `include` adds those parts to the effects.
102
+ */
103
+ export const awaitTransaction = Effect.fnUntraced(function*(
104
+ digest: string,
105
+ options: { readonly timeout: Duration.Input; readonly interval: Duration.Input } & IncludeOptions
106
+ ): Effect.fn.Return<Option.Option<Effects>, RpcError, Transactions> {
107
+ const interval = Duration.toMillis(options.interval)
108
+ const deadline = (yield* Clock.currentTimeMillis) + Duration.toMillis(options.timeout)
109
+ while (true) {
110
+ const result = yield* Effect.result(lookupOnce(digest, options.include))
111
+ if (result._tag === "Success" && Option.isSome(result.success)) return result.success
112
+ if (result._tag === "Failure" && !isRetryable(result.failure)) return yield* result.failure
113
+ if ((yield* Clock.currentTimeMillis) + interval > deadline) {
114
+ return result._tag === "Failure" ? yield* result.failure : Option.none()
115
+ }
116
+ yield* Effect.sleep(interval)
117
+ }
118
+ })
119
+
120
+ // -----------------------------------------------------------------------------
121
+ // Journal bookkeeping
122
+ // -----------------------------------------------------------------------------
123
+
124
+ const entry = {
125
+ signed: (signed: SignedTransaction, include: Includes) =>
126
+ Effect.map(DateTime.now, (at) => JournalEntry.cases.Signed.make({ digest: signed.digest, signed, ...withInclude(include), at })),
127
+ executed: (digest: string, include: Includes) =>
128
+ Effect.map(DateTime.now, (at) => JournalEntry.cases.Executed.make({ digest, ...withInclude(include), at })),
129
+ failed: (error: ExecutionFailed) =>
130
+ Effect.map(
131
+ DateTime.now,
132
+ (at) => JournalEntry.cases.Failed.make({ digest: error.digest, description: error.description, at })
133
+ ),
134
+ notApplied: (error: NotApplied) =>
135
+ Effect.map(
136
+ DateTime.now,
137
+ (at) => JournalEntry.cases.NotApplied.make({ digest: error.digest, evidence: error.evidence, at })
138
+ ),
139
+ /** `firstAt`: when the bytes were first journalled, kept across rewrites. */
140
+ unknown: (signed: SignedTransaction, include: Includes, lastError: string, attempts: number, firstAt?: DateTime.Utc) =>
141
+ Effect.map(DateTime.now, (now) =>
142
+ JournalEntry.cases.Unknown.make({
143
+ digest: signed.digest,
144
+ signed,
145
+ ...withInclude(include),
146
+ lastError,
147
+ attempts,
148
+ at: firstAt ?? now
149
+ }))
150
+ }
151
+
152
+ /** Write an entry after the network answered: a failure is logged, never returned. */
153
+ const journalSettled = (e: JournalEntry): Effect.Effect<void> =>
154
+ Effect.flatMap(Effect.service(Journal), (j) => j.put(e)).pipe(
155
+ Effect.catchTag("JournalError", (error) =>
156
+ Effect.logError("the journal could not record a settled transaction; the outcome stands", error)),
157
+ Effect.annotateLogs({ digest: e.digest, entry: e._tag })
158
+ )
159
+
160
+ const terminalEntry = (
161
+ result: Result.Result<Effects, Settled>,
162
+ digest: string,
163
+ include: Includes
164
+ ): Option.Option<Effect.Effect<JournalEntry>> =>
165
+ result._tag === "Success"
166
+ ? Option.some(entry.executed(digest, include))
167
+ : result.failure._tag === "ExecutionFailed"
168
+ ? Option.some(entry.failed(result.failure))
169
+ : result.failure._tag === "NotApplied"
170
+ ? Option.some(entry.notApplied(result.failure))
171
+ : Option.none()
172
+
173
+ // -----------------------------------------------------------------------------
174
+ // Reconcile
175
+ // -----------------------------------------------------------------------------
176
+
177
+ type InputEvidence =
178
+ | { readonly _tag: "NoEvidence" }
179
+ | { readonly _tag: "ConsumedByOther"; readonly objectId: string; readonly by: string }
180
+ | { readonly _tag: "AppliedByUs"; readonly objectId: string }
181
+ | { readonly _tag: "Unreadable"; readonly objectId: string; readonly reason: string }
182
+
183
+ /**
184
+ * What the pinned objects prove. A version that has not moved proves nothing.
185
+ * One that moved is read for *who* moved it: this digest (applied), or another
186
+ * transaction whose effects took exactly the pinned version as input
187
+ * (`inputConsumed`). Anything else is inconclusive; every ref is tried.
188
+ */
189
+ /**
190
+ * The version of `objectId` that transaction `by` took as input, from its own
191
+ * effects (a failed transaction consumed its inputs too). None when the node
192
+ * does not serve it, answers for another digest, or the object was not an input.
193
+ */
194
+ const consumedVersion = (by: string, objectId: string): Effect.Effect<Option.Option<bigint>, RpcError, Transactions> =>
195
+ Effect.map(lookupOnce(by), (found) =>
196
+ Option.flatMap(found, (effects) =>
197
+ effects.digest !== by
198
+ ? Option.none()
199
+ : Option.fromNullishOr(effects.changedObjects.find((c) => c.objectId === objectId)?.inputVersion)))
200
+
201
+ const inputEvidence = Effect.fnUntraced(function*(
202
+ digest: string,
203
+ signed: SignedTransaction
204
+ ): Effect.fn.Return<InputEvidence, RpcError, Objects | Transactions> {
205
+ const objects = yield* Objects
206
+ let inconclusive: InputEvidence | undefined
207
+ const remember = (objectId: string, reason: string) => {
208
+ inconclusive ??= { _tag: "Unreadable", objectId, reason }
209
+ }
210
+ const refs = Signed.pinnedRefsOf(signed)
211
+ // All pinned objects at once, so a batching `Objects` sends one request.
212
+ const lives = yield* Effect.forEach(
213
+ refs,
214
+ (pinned) =>
215
+ objects.get(pinned.objectId as Address).pipe(
216
+ Effect.map(Option.some),
217
+ Effect.catchTag("ObjectNotFound", () => Effect.succeedNone)
218
+ ),
219
+ { concurrency: "unbounded" }
220
+ )
221
+ for (const [i, pinned] of refs.entries()) {
222
+ const objectId = pinned.objectId as Address
223
+ const live = lives[i]!
224
+ if (Option.isNone(live)) {
225
+ remember(objectId, "it is gone, and a deleted object names no transaction")
226
+ continue
227
+ }
228
+ if (live.value.version <= pinned.version) continue
229
+ const by = Option.fromNullishOr(live.value.previousTransaction)
230
+ if (Option.isNone(by)) {
231
+ remember(objectId, "the node does not say which transaction last mutated it")
232
+ continue
233
+ }
234
+ if (by.value === digest) return { _tag: "AppliedByUs", objectId }
235
+ const consumed = yield* consumedVersion(by.value, objectId)
236
+ if (Option.isNone(consumed)) {
237
+ remember(objectId, `the node does not say which version transaction ${by.value} consumed`)
238
+ continue
239
+ }
240
+ if (consumed.value === pinned.version) return { _tag: "ConsumedByOther", objectId, by: by.value }
241
+ remember(
242
+ objectId,
243
+ `transaction ${by.value} consumed version ${consumed.value}, not the pinned ${pinned.version}, and the state in between is not served`
244
+ )
245
+ }
246
+ return inconclusive ?? { _tag: "NoEvidence" }
247
+ })
248
+
249
+ /** Whether the epoch window is observably closed right now. */
250
+ const expiryClosed = Effect.fnUntraced(function*(signed: SignedTransaction): Effect.fn.Return<boolean, RpcError, Chain> {
251
+ const last = Signed.maxEpochOf(Signed.expirationOf(signed))
252
+ if (last === undefined) return false
253
+ const info = yield* Effect.flatMap(Effect.service(Chain), (c) => c.info)
254
+ return info.epoch > last
255
+ })
256
+
257
+
258
+ /** What one `Evidence` observation says about an expired window. */
259
+ type Round =
260
+ /** The evidence backend is past the window, does not serve the digest; `gap` says whether its history covers the window. */
261
+ | { readonly _tag: "Absent"; readonly gap: Option.Option<string> }
262
+ /** The evidence backend serves the digest. */
263
+ | { readonly _tag: "Found" }
264
+ /** The evidence backend has not reached the end of the window. */
265
+ | { readonly _tag: "Open" }
266
+ /** No `Evidence` service: the expiry rule is off. */
267
+ | { readonly _tag: "Unobservable" }
268
+
269
+ /**
270
+ * One observation from one backend (`Evidence.observe`): its epoch, whether it
271
+ * serves the digest and its history, read consistently. Nothing from `Chain`
272
+ * or `Transactions` is joined into it.
273
+ */
274
+ const observeRound = Effect.fnUntraced(function*(
275
+ digest: string,
276
+ signed: SignedTransaction
277
+ ): Effect.fn.Return<Round, RpcError> {
278
+ const expiration = Signed.expirationOf(signed)
279
+ const last = Signed.maxEpochOf(expiration)
280
+ if (last === undefined) return { _tag: "Open" }
281
+ const evidence = yield* Evidence
282
+ const seen = yield* evidence.observe(digest, Signed.minEpochOf(expiration) ?? 0n)
283
+ if (Option.isNone(seen)) return { _tag: "Unobservable" }
284
+ if (seen.value.found) return { _tag: "Found" }
285
+ if (seen.value.epoch <= last) return { _tag: "Open" }
286
+ return { _tag: "Absent", gap: seen.value.gap }
287
+ })
288
+
289
+ const UNOBSERVABLE = "no Evidence service is provided, so the expiry rule is off (see Evidence)"
290
+ const FOUND_ELSEWHERE = "the Evidence backend serves this transaction but Transactions does not yet"
291
+ const OPEN_ELSEWHERE = "the Evidence backend has not yet reached the end of its window"
292
+
293
+ /** The reconcile rules, before read failures become `SubmissionUnknown`. */
294
+ const recover = Effect.fnUntraced(function*(
295
+ config: SubmitConfigService,
296
+ digest: string,
297
+ signed: SignedTransaction | undefined,
298
+ include: Includes
299
+ ): Effect.fn.Return<Effects, Settled | RpcError, Services> {
300
+ const unknown = (reason: string) => new SubmissionUnknown({ digest, ...(signed && { signed }), reason })
301
+ const settle = (effects: Effects): Effect.Effect<Effects, Settled> => {
302
+ if (effects.digest !== digest) {
303
+ return Effect.fail(unknown(`the node answered for transaction ${effects.digest}, not ${digest}`))
304
+ }
305
+ const failed = executionFailed(effects)
306
+ return failed ? Effect.fail(failed) : Effect.succeed(effects)
307
+ }
308
+
309
+ if (signed !== undefined) {
310
+ const chain = Signed.chainOf(signed)
311
+ const info = yield* Effect.flatMap(Effect.service(Chain), (c) => c.info)
312
+ if (chain !== undefined && chain !== info.chainId) {
313
+ return yield* unknown(`these bytes were built for chain ${chain}, this node is on ${info.chainId}; nothing it says is evidence`)
314
+ }
315
+ }
316
+
317
+ const first = yield* awaitTransaction(digest, { timeout: config.lookupTimeout, interval: config.lookupInterval, ...withInclude(include) })
318
+ if (Option.isSome(first)) return yield* settle(first.value)
319
+ if (signed === undefined) return yield* unknown("the node does not know this digest and the signed bytes are not available")
320
+
321
+ // Ordered and repeated: closed, missing, (recheck) closed, missing. Each
322
+ // round needs both a `Transactions` miss and one `Evidence` backend that is
323
+ // past the window and does not serve the digest, so a lagging index on one
324
+ // side cannot turn a late landing into `expired`.
325
+ let expired: Option.Option<Option.Option<string>> = Option.none()
326
+ // Why a closed window settled nothing, when it did not.
327
+ let why: string | undefined
328
+ const round = Effect.fnUntraced(function*() {
329
+ const missed = yield* lookupOnce(digest, include)
330
+ if (Option.isSome(missed)) return { _tag: "Settled" as const, effects: missed.value }
331
+ const seen = yield* observeRound(digest, signed)
332
+ if (seen._tag === "Found") {
333
+ const again = yield* lookupOnce(digest, include)
334
+ if (Option.isSome(again)) return { _tag: "Settled" as const, effects: again.value }
335
+ }
336
+ return seen
337
+ })
338
+ if (config.expiryEvidence === "epochThenMiss" && (yield* expiryClosed(signed))) {
339
+ const first = yield* round()
340
+ if (first._tag === "Settled") return yield* settle(first.effects)
341
+ if (first._tag === "Absent") {
342
+ yield* Effect.sleep(config.reconcileRecheck)
343
+ if (yield* expiryClosed(signed)) {
344
+ const second = yield* round()
345
+ if (second._tag === "Settled") return yield* settle(second.effects)
346
+ if (second._tag === "Absent") expired = Option.some(second.gap)
347
+ else why = second._tag === "Found" ? FOUND_ELSEWHERE : second._tag === "Open" ? OPEN_ELSEWHERE : UNOBSERVABLE
348
+ }
349
+ } else {
350
+ why = first._tag === "Found" ? FOUND_ELSEWHERE : first._tag === "Open" ? OPEN_ELSEWHERE : UNOBSERVABLE
351
+ }
352
+ }
353
+
354
+ // Positive evidence vetoes "expired", so the objects are read first.
355
+ const evidence = yield* inputEvidence(digest, signed)
356
+ if (evidence._tag === "AppliedByUs") {
357
+ const again = yield* lookupOnce(digest, include)
358
+ if (Option.isSome(again)) return yield* settle(again.value)
359
+ return yield* unknown(
360
+ `object ${evidence.objectId} names this transaction as its last mutation, so it applied, but the node does not serve it` +
361
+ (Option.isSome(expired) ? " (its window has closed; do not re-send it)" : "")
362
+ )
363
+ }
364
+
365
+ if (Option.isSome(expired)) {
366
+ if (Option.isNone(expired.value)) return yield* new NotApplied({ digest, evidence: "expired" })
367
+ why = expired.value.value
368
+ }
369
+ const pruned = why
370
+
371
+ switch (evidence._tag) {
372
+ case "ConsumedByOther":
373
+ return yield* new NotApplied({
374
+ digest,
375
+ evidence: "inputConsumed",
376
+ message: `object ${evidence.objectId} at the pinned version was consumed by ${evidence.by}`
377
+ })
378
+ case "Unreadable":
379
+ return yield* unknown(
380
+ `object ${evidence.objectId} has moved on or is gone, and ${evidence.reason}, so nothing is proven` +
381
+ (pruned === undefined ? "" : `; ${pruned}`)
382
+ )
383
+ case "NoEvidence":
384
+ return yield* unknown(
385
+ pruned === undefined
386
+ ? "the node does not know this digest and nothing proves it cannot land"
387
+ : `the validity window has closed, but ${pruned}`
388
+ )
389
+ }
390
+ })
391
+
392
+ const reconcileUnjournaled = (digest: string, signed: SignedTransaction | undefined, include: Includes) =>
393
+ Effect.flatMap(Effect.service(SubmitConfig), (config) => recover(config, digest, signed, include)).pipe(
394
+ Effect.catchTag(
395
+ "RpcError",
396
+ (error) => Effect.fail(new SubmissionUnknown({ digest, ...(signed && { signed }), reason: describe(error) }))
397
+ )
398
+ )
399
+
400
+ /** The journal's entry for a digest; a read failure is logged and reads as none. */
401
+ const heldEntry = (digest: string): Effect.Effect<Option.Option<JournalEntry>> =>
402
+ Effect.flatMap(Effect.service(Journal), (j) => j.get(digest)).pipe(
403
+ Effect.catchTag("JournalError", (error) =>
404
+ Effect.as(Effect.logError("the journal could not be read; the outcome stands", error), Option.none()))
405
+ )
406
+
407
+ /** The `include` asked for, else the one the journal recorded for the digest. */
408
+ const includeFor = (digest: string, given: Includes): Effect.Effect<Includes> =>
409
+ given !== undefined
410
+ ? Effect.succeed(given)
411
+ : Effect.map(heldEntry(digest), (held) => Option.isSome(held) ? includeOf(held.value) : undefined)
412
+
413
+ /**
414
+ * A settled journal entry wins over a weaker conclusion. The chain finding the
415
+ * transaction always stands (it is positive evidence), but a journal that
416
+ * recorded `Executed` / `Failed` is never contradicted by `NotApplied` or
417
+ * `SubmissionUnknown` from a lagging node, and a recorded `NotApplied` is never
418
+ * weakened to `SubmissionUnknown`.
419
+ */
420
+ const honourJournal = (
421
+ held: Option.Option<JournalEntry>,
422
+ digest: string,
423
+ signed: SignedTransaction | undefined,
424
+ result: Result.Result<Effects, Settled>
425
+ ): Result.Result<Effects, Settled> => {
426
+ if (Option.isNone(held) || result._tag === "Success" || result.failure._tag === "ExecutionFailed") return result
427
+ const recorded = held.value
428
+ switch (recorded._tag) {
429
+ case "Executed":
430
+ return Result.fail(
431
+ new SubmissionUnknown({
432
+ digest,
433
+ ...(signed && { signed }),
434
+ reason:
435
+ `the journal records this transaction as executed, but the node does not serve it (${describe(result.failure)}); do not re-send it`
436
+ })
437
+ )
438
+ case "Failed":
439
+ return Result.fail(new ExecutionFailed({ digest, description: recorded.description }))
440
+ case "NotApplied":
441
+ return result.failure._tag === "NotApplied"
442
+ ? result
443
+ : Result.fail(new NotApplied({ digest, evidence: recorded.evidence }))
444
+ default:
445
+ return result
446
+ }
447
+ }
448
+
449
+ /** Write an unresolved entry unless the journal (as just read: `held`) holds a settled one. Write failures are logged. */
450
+ const journalUnresolved = (held: Option.Option<JournalEntry>, e: JournalEntry): Effect.Effect<void> =>
451
+ Option.isSome(held) && !isUnresolved(held.value) ? Effect.void : journalSettled(e)
452
+
453
+ const verified = (signed: SignedTransaction): Effect.Effect<SignedTransaction, DigestMismatch> => {
454
+ const computed = Signed.digestMismatch(signed)
455
+ return computed === undefined
456
+ ? Effect.succeed(signed)
457
+ : Effect.fail(new DigestMismatch({ digest: signed.digest, computed }))
458
+ }
459
+
460
+ export type ReconcileInput = SignedTransaction | SubmissionUnknown | string
461
+
462
+ /** A bare digest uses the signed bytes of the journal's unresolved entry for it, when they check out. */
463
+ const journalledBytes = (digest: string): Effect.Effect<{ digest: string; signed: SignedTransaction | undefined }> =>
464
+ Effect.map(heldEntry(digest), (held) => {
465
+ const signed = Option.isSome(held) && isUnresolved(held.value) ? held.value.signed : undefined
466
+ return {
467
+ digest,
468
+ signed: signed !== undefined && signed.digest === digest && Signed.digestMismatch(signed) === undefined ? signed : undefined
469
+ }
470
+ })
471
+
472
+ const inputOf = (input: ReconcileInput): Effect.Effect<{ digest: string; signed: SignedTransaction | undefined }, DigestMismatch> =>
473
+ typeof input === "string"
474
+ ? journalledBytes(input)
475
+ : input instanceof SubmissionUnknown
476
+ ? input.signed === undefined
477
+ ? journalledBytes(input.digest)
478
+ : Effect.flatMap(verified(input.signed), (signed) =>
479
+ signed.digest === input.digest
480
+ ? Effect.succeed({ digest: input.digest, signed })
481
+ : Effect.fail(new DigestMismatch({ digest: input.digest, computed: signed.digest })))
482
+ : Effect.map(verified(input), (signed) => ({ digest: signed.digest, signed }))
483
+
484
+ /**
485
+ * Decide what happened to a transaction. Found is `Executed` / `ExecutionFailed`;
486
+ * not found is `NotApplied` only on evidence, otherwise `SubmissionUnknown`.
487
+ * A bare digest uses the signed bytes the journal holds for it (an unresolved
488
+ * entry); without them it can never be proven absent. A settled journal entry is never
489
+ * contradicted by a weaker answer; a terminal answer settles an unresolved one.
490
+ * Signed bytes whose digest does not match fail with `DigestMismatch`.
491
+ * `include` adds those parts to the effects; without it, the `include` the
492
+ * journal recorded for the submission is used.
493
+ */
494
+ export const reconcile = Effect.fn("Lifecycle.reconcile")(function*(
495
+ input: ReconcileInput,
496
+ options?: IncludeOptions
497
+ ): Effect.fn.Return<Effects, Settled | DigestMismatch, Services> {
498
+ const { digest, signed } = yield* inputOf(input)
499
+ const include = yield* includeFor(digest, options?.include)
500
+ const result = yield* Effect.uninterruptibleMask((restore) =>
501
+ Effect.flatMap(restore(Effect.result(reconcileUnjournaled(digest, signed, include))), (raw) =>
502
+ Effect.gen(function*() {
503
+ const held = yield* heldEntry(digest)
504
+ const result = honourJournal(held, digest, signed, raw)
505
+ const make = terminalEntry(result, digest, include)
506
+ if (Option.isSome(make) && Option.isSome(held) && isUnresolved(held.value)) {
507
+ yield* journalSettled(yield* make.value)
508
+ }
509
+ return result
510
+ }))
511
+ )
512
+ return yield* Effect.fromResult(result)
513
+ })
514
+
515
+ /** Reconcile (with optional rechecks while unknown) and journal the answer. Never fails. */
516
+ const settle = Effect.fnUntraced(function*(
517
+ signed: SignedTransaction,
518
+ attempts: number,
519
+ lastError: string | undefined,
520
+ rechecks: number,
521
+ include: Includes
522
+ ): Effect.fn.Return<Result.Result<Effects, Settled>, never, Services> {
523
+ const config = yield* SubmitConfig
524
+ const answer = Effect.gen(function*() {
525
+ let result = yield* Effect.result(reconcileUnjournaled(signed.digest, signed, include))
526
+ for (let round = 0; round < rechecks; round++) {
527
+ if (result._tag !== "Failure" || result.failure._tag !== "SubmissionUnknown") break
528
+ yield* Effect.sleep(config.reconcileRecheck)
529
+ result = yield* Effect.result(reconcileUnjournaled(signed.digest, signed, include))
530
+ }
531
+ return result
532
+ })
533
+ return yield* Effect.uninterruptibleMask((restore) =>
534
+ Effect.flatMap(restore(answer), (raw) =>
535
+ Effect.gen(function*() {
536
+ const held = yield* heldEntry(signed.digest)
537
+ const result = honourJournal(held, signed.digest, signed, raw)
538
+ const make = terminalEntry(result, signed.digest, include)
539
+ if (Option.isSome(make)) {
540
+ yield* journalSettled(yield* make.value)
541
+ } else {
542
+ // Keep when the bytes were first journalled, and the send error that
543
+ // made them unknown when this round has no new one (reconcileAll).
544
+ const previous = Option.isSome(held) && isUnresolved(held.value) ? held.value : undefined
545
+ yield* journalUnresolved(
546
+ held,
547
+ yield* entry.unknown(
548
+ signed,
549
+ include,
550
+ lastError ?? (previous?._tag === "Unknown"
551
+ ? previous.lastError
552
+ : result._tag === "Failure" ? describe(result.failure) : "unknown"),
553
+ attempts,
554
+ previous?.at
555
+ )
556
+ )
557
+ }
558
+ return result
559
+ }))
560
+ )
561
+ })
562
+
563
+ // -----------------------------------------------------------------------------
564
+ // Submit
565
+ // -----------------------------------------------------------------------------
566
+
567
+ const LOCK_CONFLICT = /already locked by a different transaction|rejected as invalid by more than 1\/3 of validators/i
568
+ const LOCK_CONFLICT_RECHECKS = 3
569
+
570
+ /** Wait until reads see an executed transaction. Never fails and never changes the outcome. */
571
+ const awaitVisible = (config: SubmitConfigService, digest: string): Effect.Effect<void, never, Transactions> =>
572
+ config.awaitVisibility
573
+ ? awaitTransaction(digest, { timeout: config.visibilityTimeout, interval: config.lookupInterval }).pipe(
574
+ Effect.flatMap((found) =>
575
+ Option.isSome(found)
576
+ ? Effect.void
577
+ : Effect.logDebug("executed but not visible within visibilityTimeout; the outcome stands")
578
+ ),
579
+ Effect.catch((error) => Effect.logDebug(`executed, but waiting for visibility failed: ${describe(error)}`)),
580
+ Effect.annotateLogs({ digest }),
581
+ Effect.withSpan("Lifecycle.awaitVisible")
582
+ )
583
+ : Effect.void
584
+
585
+ /** What the caller already knows when it sends. */
586
+ interface SendHow {
587
+ /** The journal's entry as the caller just read it (undefined: not read). */
588
+ readonly held?: Option.Option<JournalEntry> | undefined
589
+ /** Write `Signed` even over a settled entry (re-sending a `refused` one on request). */
590
+ readonly overwriteSettled?: boolean
591
+ /** The parts of the effects to read back, journalled with the bytes. */
592
+ readonly include?: Includes
593
+ }
594
+
595
+ /**
596
+ * The `Signed` write before a send. Never over a settled entry (unless asked).
597
+ * On bytes that were never sent a failure is an honest `JournalError`; on
598
+ * bytes that may already have gone out (`resent`) it is `SubmissionUnknown`.
599
+ */
600
+ const journalBeforeSend = (
601
+ signed: SignedTransaction,
602
+ resent: boolean,
603
+ how: SendHow
604
+ ): Effect.Effect<void, JournalError | SubmissionUnknown> =>
605
+ Effect.gen(function*() {
606
+ const journal = yield* Journal
607
+ // The caller usually just read the entry; read it here only when it did not.
608
+ const held = how.held ?? (yield* journal.get(signed.digest))
609
+ if (Option.isSome(held) && !isUnresolved(held.value) && !how.overwriteSettled) return
610
+ yield* journal.put(yield* entry.signed(signed, how.include))
611
+ }).pipe(
612
+ Effect.catchTag("JournalError", (error): Effect.Effect<never, JournalError | SubmissionUnknown> =>
613
+ resent
614
+ ? Effect.fail(
615
+ new SubmissionUnknown({
616
+ digest: signed.digest,
617
+ signed,
618
+ reason: `these bytes may already be on chain and the journal could not record the re-send (${error.message}); nothing was re-sent`
619
+ })
620
+ )
621
+ : Effect.fail(error))
622
+ )
623
+
624
+ const send = Effect.fnUntraced(function*(
625
+ signed: SignedTransaction,
626
+ resent: boolean,
627
+ how: SendHow = {}
628
+ ): Effect.fn.Return<Effects, ExecutionFailed | NotApplied | SubmissionUnknown | JournalError, Services> {
629
+ const config = yield* SubmitConfig
630
+ const transactions = yield* Transactions
631
+ if (!resent) {
632
+ // Bytes for another chain are never sent (a re-send checks this too):
633
+ // the node would refuse them, and that refusal would be recorded as proof.
634
+ const chain = Signed.chainOf(signed)
635
+ const info = yield* Effect.result(Effect.flatMap(Effect.service(Chain), (c) => c.info))
636
+ if (chain !== undefined && info._tag === "Success" && chain !== info.success.chainId) {
637
+ return yield* new SubmissionUnknown({
638
+ digest: signed.digest,
639
+ signed,
640
+ reason: `these bytes were built for chain ${chain}, this node is on ${info.success.chainId}; nothing was sent`
641
+ })
642
+ }
643
+ }
644
+ yield* journalBeforeSend(signed, resent, how)
645
+
646
+ let attempts = 0
647
+ const once = Effect.suspend(() => {
648
+ attempts += 1
649
+ return transactions.execute(signed.bytes, signed.signatures, withInclude(how.include)).pipe(
650
+ Effect.timeoutOrElse({
651
+ duration: config.executeTimeout,
652
+ orElse: () =>
653
+ Effect.fail(
654
+ new RpcError({
655
+ method: "ExecuteTransaction",
656
+ code: "DEADLINE_EXCEEDED",
657
+ message: `no answer within executeTimeout (${Duration.format(config.executeTimeout)})`
658
+ })
659
+ )
660
+ })
661
+ )
662
+ })
663
+
664
+ // The attempts are interruptible; from the answer to its journal record, nothing is.
665
+ const result = yield* Effect.uninterruptibleMask((restore) =>
666
+ restore(
667
+ once.pipe(
668
+ Effect.retry({
669
+ schedule: config.resubmit,
670
+ times: Math.max(config.resubmitAttempts - 1, 0),
671
+ while: (e) => e._tag === "RpcError" && isRetryable(e)
672
+ })
673
+ )
674
+ ).pipe(
675
+ Effect.result,
676
+ Effect.tap((answered) => {
677
+ if (answered._tag !== "Success" || answered.success.digest !== signed.digest) return Effect.void
678
+ const failed = executionFailed(answered.success)
679
+ return Effect.flatMap(failed ? entry.failed(failed) : entry.executed(signed.digest, how.include), journalSettled)
680
+ })
681
+ )
682
+ )
683
+
684
+ if (result._tag === "Success") {
685
+ const effects = result.success
686
+ if (effects.digest !== signed.digest) {
687
+ return yield* reconcileSigned(signed, `the node answered for transaction ${effects.digest}`, attempts, 0, how.include)
688
+ }
689
+ const failed = executionFailed(effects)
690
+ if (failed) return yield* failed
691
+ yield* awaitVisible(config, signed.digest)
692
+ return effects
693
+ }
694
+ const failure = result.failure
695
+ // Accepted, but the answer can't be read as effects: it may have executed.
696
+ if (failure._tag === "ExecutedEffectsIncomplete") return yield* reconcileSigned(signed, failure.message, attempts, 0, how.include)
697
+ // A lock held by another transaction, whatever the code: the bytes reached
698
+ // validators, so it reconciles (with rechecks while the winner becomes readable).
699
+ if (LOCK_CONFLICT.test(failure.message)) {
700
+ return yield* reconcileSigned(signed, describe(failure), attempts, LOCK_CONFLICT_RECHECKS, how.include)
701
+ }
702
+ // Refused outright on the first send of bytes never sent before: nothing executed.
703
+ if (!resent && attempts === 1 && failure.code === "INVALID_ARGUMENT") {
704
+ const refused = new NotApplied({ digest: signed.digest, evidence: "refused", message: failure.message })
705
+ yield* Effect.flatMap(entry.notApplied(refused), journalSettled)
706
+ return yield* refused
707
+ }
708
+ return yield* reconcileSigned(signed, describe(failure), attempts, 0, how.include)
709
+ })
710
+
711
+ const reconcileSigned = Effect.fnUntraced(function*(
712
+ signed: SignedTransaction,
713
+ lastSend: string,
714
+ attempts: number,
715
+ rechecks: number,
716
+ include: Includes
717
+ ): Effect.fn.Return<Effects, Settled, Services> {
718
+ const settled = yield* settle(signed, attempts, lastSend, rechecks, include)
719
+ if (settled._tag === "Success") return settled.success
720
+ const failure = settled.failure
721
+ if (failure._tag !== "SubmissionUnknown") return yield* failure
722
+ return yield* new SubmissionUnknown({
723
+ digest: failure.digest,
724
+ signed,
725
+ reason: `${failure.reason}; the last send failed with ${lastSend}`
726
+ })
727
+ })
728
+
729
+ /**
730
+ * What the journal already says decides how to (re-)send: a settled entry is
731
+ * answered from the chain with the journal winning (never re-sent), an
732
+ * unresolved one means these bytes may already be out.
733
+ */
734
+ /**
735
+ * How a send was asked for: `fresh` bytes were signed just now (`run`), so a
736
+ * journal failure before the send is an honest `JournalError`; `submit` bytes
737
+ * come from the caller and may have been sent before; `resend` is `resubmit`.
738
+ */
739
+ type SendMode = "fresh" | "submit" | "resend"
740
+
741
+ const sendConsultingJournal = Effect.fnUntraced(function*(
742
+ signed: SignedTransaction,
743
+ mode: SendMode,
744
+ options?: ResubmitOptions
745
+ ): Effect.fn.Return<Effects, SubmitError, Services> {
746
+ const held = yield* Effect.flatMap(Effect.service(Journal), (j) => j.get(signed.digest)).pipe(
747
+ Effect.catchTag("JournalError", (error): Effect.Effect<never, JournalError | SubmissionUnknown> =>
748
+ mode === "fresh" ? Effect.fail(error) : Effect.fail(
749
+ new SubmissionUnknown({
750
+ digest: signed.digest,
751
+ signed,
752
+ reason: `the journal could not be read (${error.message}); nothing was sent, but these bytes may have been sent before`
753
+ })
754
+ ))
755
+ )
756
+ // Asked for now, else what the earlier send of these bytes asked for.
757
+ const include = options?.include ?? (Option.isSome(held) ? includeOf(held.value) : undefined)
758
+ if (Option.isSome(held)) {
759
+ switch (held.value._tag) {
760
+ case "Executed":
761
+ case "Failed":
762
+ return yield* reconcile(signed, withInclude(include))
763
+ case "NotApplied":
764
+ if (mode === "resend" && options?.retryRefused === true && held.value.evidence === "refused") {
765
+ return yield* resend(signed, { held, overwriteSettled: true, include })
766
+ }
767
+ return yield* new NotApplied({ digest: signed.digest, evidence: held.value.evidence })
768
+ default:
769
+ return yield* resend(signed, { held, include })
770
+ }
771
+ }
772
+ return yield* (mode === "resend" ? resend(signed, { held, include }) : send(signed, false, { held, include }))
773
+ })
774
+
775
+ /**
776
+ * Send signed bytes and find out what happened. Re-sends only the identical
777
+ * bytes; ends in `Executed`, `ExecutionFailed`, `NotApplied` (proven, or
778
+ * `refused` on the first send of bytes the journal has never seen) or
779
+ * `SubmissionUnknown`. Bytes the journal already holds are treated as a
780
+ * re-send (see `resubmit`); bytes built for another chain than the node's are
781
+ * not sent (`SubmissionUnknown`). `JournalError` only from the `Signed` write
782
+ * before bytes the journal has never seen (a journal that cannot be read is
783
+ * `SubmissionUnknown`: the bytes may have been sent before); `DigestMismatch`
784
+ * if the digest is not the bytes'. `include` (`["events", "balanceChanges"]`)
785
+ * adds those to the effects, and is journalled with the bytes so a later
786
+ * reconcile (`reconcileAll` after a crash) reads them too.
787
+ */
788
+ export const submit = Effect.fn("Lifecycle.submit")(function*(
789
+ input: SignedTransaction,
790
+ options?: IncludeOptions
791
+ ): Effect.fn.Return<Effects, SubmitError, Services> {
792
+ const signed = yield* verified(input)
793
+ yield* Effect.annotateCurrentSpan({ "sui.digest": signed.digest })
794
+ return yield* sendConsultingJournal(signed, "submit", options)
795
+ })
796
+
797
+ /** `submit` for bytes signed just now by `run`: a journal read failure before the send is `JournalError`. */
798
+ const submitFresh = (signed: SignedTransaction, include: Includes) =>
799
+ Effect.flatMap(verified(signed), (s) => sendConsultingJournal(s, "fresh", withInclude(include))).pipe(
800
+ Effect.withSpan("Lifecycle.submit")
801
+ )
802
+
803
+ export interface ResubmitOptions extends IncludeOptions {
804
+ /**
805
+ * Re-send bytes the journal records as `NotApplied{refused}`. A refusal
806
+ * means only that this process will not send them again on its own; the
807
+ * same bytes can be valid later (e.g. once the sender is funded), until
808
+ * their window closes. Default false.
809
+ */
810
+ readonly retryRefused?: boolean
811
+ }
812
+
813
+ /**
814
+ * Re-send the identical bytes. Refuses when the journal already says
815
+ * `NotApplied` (unless `retryRefused` and the evidence is `refused`);
816
+ * reconciles instead (journal winning) when the journal says it executed, the
817
+ * bytes name another chain, or their window has closed. Bytes not given
818
+ * (a `SubmissionUnknown` without them) are taken from the journal, as is
819
+ * `include` when not given. Never raises `JournalError`: the bytes may
820
+ * already be out.
821
+ */
822
+ export const resubmit = Effect.fn("Lifecycle.resubmit")(function*(
823
+ input: SignedTransaction | SubmissionUnknown,
824
+ options?: ResubmitOptions
825
+ ): Effect.fn.Return<Effects, Exclude<SubmitError, JournalError>, Services> {
826
+ const { digest, signed } = yield* inputOf(input)
827
+ if (signed === undefined) return yield* reconcile(digest, withInclude(options?.include))
828
+ return yield* (sendConsultingJournal(signed, "resend", options) as Effect.Effect<
829
+ Effects,
830
+ Exclude<SubmitError, JournalError>,
831
+ Services
832
+ >)
833
+ })
834
+
835
+ const resend = Effect.fnUntraced(function*(
836
+ signed: SignedTransaction,
837
+ how: SendHow = {}
838
+ ): Effect.fn.Return<Effects, Exclude<SubmitError, JournalError>, Services> {
839
+ const info = yield* Effect.result(Effect.flatMap(Effect.service(Chain), (c) => c.info))
840
+ const chain = Signed.chainOf(signed)
841
+ const otherChain = chain !== undefined && info._tag === "Success" && chain !== info.success.chainId
842
+ const closed = otherChain || (yield* Effect.orElseSucceed(expiryClosed(signed), () => false))
843
+ if (closed) {
844
+ const settled = yield* settle(signed, 1, undefined, 0, how.include)
845
+ return settled._tag === "Success" ? settled.success : yield* settled.failure
846
+ }
847
+ // `resent: true` turns a journal failure into SubmissionUnknown, never JournalError.
848
+ return yield* (send(signed, true, how) as Effect.Effect<Effects, Exclude<SubmitError, JournalError>, Services>)
849
+ })
850
+
851
+ export interface ReconcileAllOptions {
852
+ /** Re-send an entry still unknown after reconciling, as identical bytes. Default false. */
853
+ readonly resubmit?: boolean
854
+ /** Entries reconciled at once. Default 8. */
855
+ readonly concurrency?: number
856
+ }
857
+
858
+ /**
859
+ * Settle every unresolved journal entry: the startup call after a crash. Each
860
+ * entry gets `reconcile`'s rules (with one lookup, not `lookupTimeout` of
861
+ * polling: entries left over from a crash are old) and the journal is updated,
862
+ * `concurrency` entries at a time; with `{ resubmit: true }` an entry still
863
+ * unknown is re-sent as identical bytes. Entries the journal cannot read are
864
+ * reported as `Corrupt` (drop them with `Journal.remove`), never a failure of
865
+ * the whole call. Fails only when the journal cannot be listed.
866
+ */
867
+ export const reconcileAll = Effect.fn("Lifecycle.reconcileAll")(function*(
868
+ options?: ReconcileAllOptions
869
+ ): Effect.fn.Return<ReadonlyArray<Reconciled>, JournalError, Services> {
870
+ const journal = yield* Journal
871
+ const config = yield* SubmitConfig
872
+ const once: SubmitConfigService = { ...config, lookupTimeout: Duration.zero }
873
+ const { entries, corrupt } = yield* journal.listUnresolved
874
+ const corruptResults: Array<Reconciled> = corrupt.map((c) => ({ _tag: "Corrupt", digest: c.key, reason: c.reason }))
875
+ const settled = yield* Effect.forEach(entries, (e) =>
876
+ Effect.gen(function*(): Effect.fn.Return<Reconciled, never, Services> {
877
+ const computed = Signed.digestMismatch(e.signed)
878
+ if (computed !== undefined || e.signed.digest !== e.digest) {
879
+ return { _tag: "Corrupt", digest: e.digest, reason: `its bytes have digest ${computed ?? e.signed.digest}, not ${e.digest}` }
880
+ }
881
+ let result = yield* settle(e.signed, e._tag === "Unknown" ? e.attempts : 1, undefined, 0, e.include)
882
+ if (
883
+ options?.resubmit === true && result._tag === "Failure" && result.failure._tag === "SubmissionUnknown"
884
+ ) {
885
+ const sent = yield* Effect.result(resend(e.signed, { include: e.include }))
886
+ result = sent as Result.Result<Effects, Settled>
887
+ }
888
+ return toReconciled(e.digest, result)
889
+ }).pipe(Effect.provideService(SubmitConfig, once)), { concurrency: options?.concurrency ?? 8 })
890
+ return [...corruptResults, ...settled]
891
+ })
892
+
893
+ const toReconciled = (digest: string, result: Result.Result<Effects, Settled | DigestMismatch>): Reconciled => {
894
+ if (result._tag === "Success") return { _tag: "Executed", digest, effects: result.success }
895
+ const error = result.failure
896
+ switch (error._tag) {
897
+ case "ExecutionFailed":
898
+ return { _tag: "ExecutionFailed", digest, error }
899
+ case "NotApplied":
900
+ return { _tag: "NotApplied", digest, error }
901
+ case "SubmissionUnknown":
902
+ return { _tag: "SubmissionUnknown", digest, error }
903
+ case "DigestMismatch":
904
+ return { _tag: "SubmissionUnknown", digest, error: new SubmissionUnknown({ digest, reason: describe(error) }) }
905
+ }
906
+ }
907
+
908
+ // -----------------------------------------------------------------------------
909
+ // Sign and run
910
+ // -----------------------------------------------------------------------------
911
+
912
+ /**
913
+ * Sign transaction data (or its bytes) with every signer, concurrently.
914
+ * `chain` is recorded for expirations that name none. A signer that is
915
+ * neither the sender nor the gas owner is `Tx.SignerMismatch` before anyone
916
+ * signs, as in `Tx.execute` (an alias signs through `AddressAlias.signer`);
917
+ * bytes that do not parse as `TransactionData` are signed unchecked.
918
+ */
919
+ export const sign = Effect.fn("Lifecycle.sign")(function*(
920
+ data: T.TransactionData | Uint8Array,
921
+ signers: Signer.Signer | ReadonlyArray<Signer.Signer>,
922
+ options?: { readonly chain?: string }
923
+ ): Effect.fn.Return<SignedTransaction, Signer.SigningError | Tx.SignerMismatch> {
924
+ const bytes = data instanceof Uint8Array ? data : T.encode(data)
925
+ const all = Array.isArray(signers) ? signers : [signers as Signer.Signer]
926
+ const parsed = data instanceof Uint8Array ? Result.getOrUndefined(T.decode(data)) : data
927
+ if (parsed !== undefined) yield* refuseMismatch(all, parsed.sender, parsed.gasData.owner)
928
+ const signatures = yield* Effect.forEach(
929
+ all,
930
+ (s) => Effect.map(Signer.signTransaction(s, bytes), (x) => x.signature),
931
+ { concurrency: "unbounded" }
932
+ )
933
+ return Signed.make(bytes, signatures, options)
934
+ })
935
+
936
+ /** The first signer that is neither `sender` nor `gasOwner`, as `Tx.SignerMismatch`. */
937
+ const refuseMismatch = (
938
+ signers: ReadonlyArray<Signer.Signer>,
939
+ sender: Address,
940
+ gasOwner: Address
941
+ ): Effect.Effect<void, Tx.SignerMismatch> => {
942
+ for (const s of signers) {
943
+ const refused = Tx.signerMismatch(s.address, sender, gasOwner)
944
+ if (refused) return Effect.fail(refused)
945
+ }
946
+ return Effect.void
947
+ }
948
+
949
+ export interface RunOptions<E = never, R = never> extends Omit<Tx.ResolveOptions<E, R>, "sender">, IncludeOptions {
950
+ readonly signer: Signer.Signer
951
+ /** Defaults to the signer's address. */
952
+ readonly sender?: Address
953
+ /** Extra signers, e.g. a sponsor when `gasOwner` is not the sender. */
954
+ readonly cosigners?: ReadonlyArray<Signer.Signer>
955
+ }
956
+
957
+ /**
958
+ * Build (core `Tx.build`), sign, journal, submit. Unless given, the expiration
959
+ * is `ValidDuring` this epoch and the next, so the expiry rule can settle the
960
+ * bytes even when they pin nothing. `include` (`["events", "balanceChanges"]`)
961
+ * adds those to the effects (see `submit`).
962
+ *
963
+ * A signer (or cosigner) that is neither the sender nor the gas owner is
964
+ * `Tx.SignerMismatch` before any network call, as in `Tx.run`.
965
+ *
966
+ * Holds the `SenderLock` of the sender (and a distinct gas owner) for the
967
+ * build, and through signing and submission when the bytes pin a versioned
968
+ * object or gas payment; bytes that pin nothing are signed and sent after the
969
+ * lock is released.
970
+ */
971
+ export const run = <A, E1, R1, E2 = never, R2 = never>(recipe: Effect.Effect<A, E1, R1>, options: RunOptions<E2, R2>) =>
972
+ Effect.gen(function*() {
973
+ const { signer, cosigners, sender: given, include, ...resolve } = options
974
+ const sender = given ?? signer.address
975
+ const signers = [signer, ...(cosigners ?? [])]
976
+ yield* refuseMismatch(signers, sender, resolve.gasOwner ?? sender)
977
+ const info = yield* Effect.flatMap(Effect.service(Chain), (c) => c.info)
978
+ const lock = yield* SenderLock
979
+ const locked = yield* lock.withLocks([sender, ...(resolve.gasOwner ? [resolve.gasOwner] : [])])(
980
+ Effect.gen(function*() {
981
+ const expiration = options.expiration ?? (yield* Resolve.validDuring())
982
+ const data = yield* Tx.build(recipe, { ...resolve, expiration, sender })
983
+ if (!Signed.pinsObjects(data)) return { _tag: "Unpinned" as const, data }
984
+ const signed = yield* sign(data, signers, { chain: info.chainId })
985
+ return { _tag: "Done" as const, effects: yield* submitFresh(signed, include) }
986
+ })
987
+ )
988
+ if (locked._tag === "Done") return locked.effects
989
+ return yield* submitFresh(yield* sign(locked.data, signers, { chain: info.chainId }), include)
990
+ }).pipe(Effect.withSpan("Lifecycle.run"))