@unconfirmed/effect-sui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (568) 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/Features.d.ts +91 -0
  388. package/dist/wallet/Features.d.ts.map +1 -0
  389. package/dist/wallet/Features.js +14 -0
  390. package/dist/wallet/Features.js.map +1 -0
  391. package/dist/wallet/Wallet.d.ts +151 -0
  392. package/dist/wallet/Wallet.d.ts.map +1 -0
  393. package/dist/wallet/Wallet.js +399 -0
  394. package/dist/wallet/Wallet.js.map +1 -0
  395. package/dist/wallet/index.d.ts +6 -0
  396. package/dist/wallet/index.d.ts.map +1 -0
  397. package/dist/wallet/index.js +6 -0
  398. package/dist/wallet/index.js.map +1 -0
  399. package/dist/zklogin/AddressSeed.d.ts +40 -0
  400. package/dist/zklogin/AddressSeed.d.ts.map +1 -0
  401. package/dist/zklogin/AddressSeed.js +91 -0
  402. package/dist/zklogin/AddressSeed.js.map +1 -0
  403. package/dist/zklogin/Errors.d.ts +24 -0
  404. package/dist/zklogin/Errors.d.ts.map +1 -0
  405. package/dist/zklogin/Errors.js +25 -0
  406. package/dist/zklogin/Errors.js.map +1 -0
  407. package/dist/zklogin/Jwt.d.ts +51 -0
  408. package/dist/zklogin/Jwt.d.ts.map +1 -0
  409. package/dist/zklogin/Jwt.js +159 -0
  410. package/dist/zklogin/Jwt.js.map +1 -0
  411. package/dist/zklogin/Nonce.d.ts +9 -0
  412. package/dist/zklogin/Nonce.d.ts.map +1 -0
  413. package/dist/zklogin/Nonce.js +34 -0
  414. package/dist/zklogin/Nonce.js.map +1 -0
  415. package/dist/zklogin/Poseidon.d.ts +24 -0
  416. package/dist/zklogin/Poseidon.d.ts.map +1 -0
  417. package/dist/zklogin/Poseidon.js +54 -0
  418. package/dist/zklogin/Poseidon.js.map +1 -0
  419. package/dist/zklogin/PublicIdentifier.d.ts +49 -0
  420. package/dist/zklogin/PublicIdentifier.d.ts.map +1 -0
  421. package/dist/zklogin/PublicIdentifier.js +90 -0
  422. package/dist/zklogin/PublicIdentifier.js.map +1 -0
  423. package/dist/zklogin/Signature.d.ts +55 -0
  424. package/dist/zklogin/Signature.d.ts.map +1 -0
  425. package/dist/zklogin/Signature.js +70 -0
  426. package/dist/zklogin/Signature.js.map +1 -0
  427. package/dist/zklogin/ZkLogin.d.ts +41 -0
  428. package/dist/zklogin/ZkLogin.d.ts.map +1 -0
  429. package/dist/zklogin/ZkLogin.js +87 -0
  430. package/dist/zklogin/ZkLogin.js.map +1 -0
  431. package/dist/zklogin/ZkLoginAddress.d.ts +30 -0
  432. package/dist/zklogin/ZkLoginAddress.d.ts.map +1 -0
  433. package/dist/zklogin/ZkLoginAddress.js +31 -0
  434. package/dist/zklogin/ZkLoginAddress.js.map +1 -0
  435. package/dist/zklogin/ZkLoginVerifier.d.ts +37 -0
  436. package/dist/zklogin/ZkLoginVerifier.d.ts.map +1 -0
  437. package/dist/zklogin/ZkLoginVerifier.js +4 -0
  438. package/dist/zklogin/ZkLoginVerifier.js.map +1 -0
  439. package/dist/zklogin/ZkLoginVerifierGrpc.d.ts +12 -0
  440. package/dist/zklogin/ZkLoginVerifierGrpc.d.ts.map +1 -0
  441. package/dist/zklogin/ZkLoginVerifierGrpc.js +53 -0
  442. package/dist/zklogin/ZkLoginVerifierGrpc.js.map +1 -0
  443. package/dist/zklogin/index.d.ts +17 -0
  444. package/dist/zklogin/index.d.ts.map +1 -0
  445. package/dist/zklogin/index.js +17 -0
  446. package/dist/zklogin/index.js.map +1 -0
  447. package/dist/zklogin/internal/parse.d.ts +9 -0
  448. package/dist/zklogin/internal/parse.d.ts.map +1 -0
  449. package/dist/zklogin/internal/parse.js +33 -0
  450. package/dist/zklogin/internal/parse.js.map +1 -0
  451. package/dist/zklogin/internal/poseidon.d.ts +21 -0
  452. package/dist/zklogin/internal/poseidon.d.ts.map +1 -0
  453. package/dist/zklogin/internal/poseidon.js +40 -0
  454. package/dist/zklogin/internal/poseidon.js.map +1 -0
  455. package/package.json +69 -4
  456. package/src/Address.ts +45 -0
  457. package/src/AddressAlias.ts +160 -0
  458. package/src/Bip32.ts +37 -0
  459. package/src/Chain.ts +21 -0
  460. package/src/CheckpointData.ts +106 -0
  461. package/src/Checkpoints.ts +18 -0
  462. package/src/CoinReservation.ts +65 -0
  463. package/src/Coins.ts +86 -0
  464. package/src/DynamicFields.ts +179 -0
  465. package/src/Ecdsa.ts +103 -0
  466. package/src/Ed25519.ts +84 -0
  467. package/src/Events.ts +133 -0
  468. package/src/Hash.ts +39 -0
  469. package/src/MlDsa65.ts +92 -0
  470. package/src/Mnemonic.ts +109 -0
  471. package/src/Move.ts +440 -0
  472. package/src/MultiSig.ts +320 -0
  473. package/src/Objects.ts +112 -0
  474. package/src/Packages.ts +52 -0
  475. package/src/Passkey.ts +10 -0
  476. package/src/PrivateKey.ts +138 -0
  477. package/src/Ptb.ts +579 -0
  478. package/src/Resolve.ts +1367 -0
  479. package/src/RpcError.ts +41 -0
  480. package/src/Secp256k1.ts +29 -0
  481. package/src/Secp256r1.ts +29 -0
  482. package/src/SignatureScheme.ts +166 -0
  483. package/src/Signer.ts +62 -0
  484. package/src/Testing.ts +830 -0
  485. package/src/TransactionData.ts +134 -0
  486. package/src/TransactionJson.ts +1002 -0
  487. package/src/Transactions.ts +211 -0
  488. package/src/Tx.ts +367 -0
  489. package/src/TypeTag.ts +123 -0
  490. package/src/Verify.ts +42 -0
  491. package/src/enoki/EnokiClient.ts +204 -0
  492. package/src/enoki/EnokiHttp.ts +222 -0
  493. package/src/enoki/Sponsor.ts +280 -0
  494. package/src/enoki/ZkLoginFlow.ts +176 -0
  495. package/src/enoki/index.ts +8 -0
  496. package/src/graphql/ChainGraphQL.ts +76 -0
  497. package/src/graphql/CheckpointDataGraphQL.ts +191 -0
  498. package/src/graphql/CheckpointsGraphQL.ts +96 -0
  499. package/src/graphql/CoinsGraphQL.ts +85 -0
  500. package/src/graphql/DynamicFieldsGraphQL.ts +167 -0
  501. package/src/graphql/EventsGraphQL.ts +301 -0
  502. package/src/graphql/ObjectsGraphQL.ts +112 -0
  503. package/src/graphql/PackagesGraphQL.ts +173 -0
  504. package/src/graphql/SuiGraphQL.ts +77 -0
  505. package/src/graphql/TransactionsGraphQL.ts +292 -0
  506. package/src/graphql/convert.ts +450 -0
  507. package/src/graphql/index.ts +74 -0
  508. package/src/graphql/merge.ts +62 -0
  509. package/src/graphql/paging.ts +110 -0
  510. package/src/graphql/subscription.ts +58 -0
  511. package/src/graphql/tip.ts +38 -0
  512. package/src/grpc/ChainGrpc.ts +51 -0
  513. package/src/grpc/CheckpointDataGrpc.ts +47 -0
  514. package/src/grpc/CheckpointsGrpc.ts +37 -0
  515. package/src/grpc/CoinsGrpc.ts +50 -0
  516. package/src/grpc/DynamicFieldsGrpc.ts +128 -0
  517. package/src/grpc/EventsGrpc.ts +101 -0
  518. package/src/grpc/GrpcWeb.ts +343 -0
  519. package/src/grpc/ObjectsGrpc.ts +95 -0
  520. package/src/grpc/PackagesGrpc.ts +98 -0
  521. package/src/grpc/Rpc.ts +156 -0
  522. package/src/grpc/TransactionsGrpc.ts +88 -0
  523. package/src/grpc/cache.ts +68 -0
  524. package/src/grpc/convert.ts +227 -0
  525. package/src/grpc/generated/lean.ts +276 -0
  526. package/src/grpc/generated/proto.ts +2130 -0
  527. package/src/grpc/generated/rpc.ts +417 -0
  528. package/src/grpc/index.ts +97 -0
  529. package/src/grpc/scan.ts +183 -0
  530. package/src/grpc/transaction.ts +182 -0
  531. package/src/index.ts +35 -0
  532. package/src/internal/allowances.ts +238 -0
  533. package/src/internal/mnemonic.ts +99 -0
  534. package/src/internal/passkey/BrowserProvider.ts +131 -0
  535. package/src/internal/passkey/Passkey.ts +408 -0
  536. package/src/internal/passkey/SoftwareProvider.ts +90 -0
  537. package/src/lifecycle/Evidence.ts +85 -0
  538. package/src/lifecycle/EvidenceGraphQL.ts +67 -0
  539. package/src/lifecycle/EvidenceGrpc.ts +47 -0
  540. package/src/lifecycle/Journal.ts +117 -0
  541. package/src/lifecycle/JournalEntry.ts +68 -0
  542. package/src/lifecycle/JournalKeyValueStore.ts +276 -0
  543. package/src/lifecycle/KeyValueStoreIndexedDb.ts +361 -0
  544. package/src/lifecycle/KeyValueStoreOpfs.ts +230 -0
  545. package/src/lifecycle/Lifecycle.ts +990 -0
  546. package/src/lifecycle/Outcome.ts +130 -0
  547. package/src/lifecycle/SenderLock.ts +73 -0
  548. package/src/lifecycle/SenderLockWebLocks.ts +136 -0
  549. package/src/lifecycle/SignedTransaction.ts +133 -0
  550. package/src/lifecycle/SubmitConfig.ts +77 -0
  551. package/src/lifecycle/index.ts +12 -0
  552. package/src/wallet/Features.ts +114 -0
  553. package/src/wallet/Wallet.ts +550 -0
  554. package/src/wallet/index.ts +5 -0
  555. package/src/zklogin/AddressSeed.ts +130 -0
  556. package/src/zklogin/Errors.ts +27 -0
  557. package/src/zklogin/Jwt.ts +186 -0
  558. package/src/zklogin/Nonce.ts +46 -0
  559. package/src/zklogin/Poseidon.ts +62 -0
  560. package/src/zklogin/PublicIdentifier.ts +111 -0
  561. package/src/zklogin/Signature.ts +88 -0
  562. package/src/zklogin/ZkLogin.ts +145 -0
  563. package/src/zklogin/ZkLoginAddress.ts +72 -0
  564. package/src/zklogin/ZkLoginVerifier.ts +37 -0
  565. package/src/zklogin/ZkLoginVerifierGrpc.ts +66 -0
  566. package/src/zklogin/index.ts +16 -0
  567. package/src/zklogin/internal/parse.ts +30 -0
  568. package/src/zklogin/internal/poseidon.ts +47 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * `Evidence` over gRPC, from one node: `GetServiceInfo` (its epoch), then
3
+ * `GetTransaction` (does it serve the digest), then `GetServiceInfo` again (its
4
+ * lowest available checkpoint, after the miss) and, if it has pruned,
5
+ * `GetEpoch` for where the window starts. Nothing is cached. Its own subpath,
6
+ * so nothing else loads the gRPC code.
7
+ *
8
+ * EvidenceGrpc.layer.pipe(Layer.provide(GrpcWeb.layer({ url })))
9
+ *
10
+ * Point it at the same endpoint as `Transactions`. Behind a load balancer the
11
+ * calls may reach different nodes; use `SubmitConfig` `expiryEvidence: "never"`
12
+ * there.
13
+ */
14
+ import * as Rpc from "../grpc/generated/rpc.ts"
15
+ import { GrpcWeb } from "../grpc/GrpcWeb.ts"
16
+ import * as Effect from "effect/Effect"
17
+ import * as Layer from "effect/Layer"
18
+ import * as Option from "effect/Option"
19
+ import { Evidence, historyGap } from "./Evidence.ts"
20
+
21
+ export const layer: Layer.Layer<never, never, GrpcWeb> = Layer.effect(
22
+ Evidence,
23
+ Effect.gen(function*() {
24
+ const grpc = yield* GrpcWeb
25
+ const serviceInfo = grpc.unary(Rpc.LedgerService_GetServiceInfo, {})
26
+ const epochFirstCheckpoint = (epoch: bigint) =>
27
+ grpc.unary(Rpc.LedgerService_GetEpoch, { epoch, read_mask: { paths: ["epoch", "first_checkpoint"] } }).pipe(
28
+ Effect.map((r) => r.epoch?.epoch === epoch ? Option.fromNullishOr(r.epoch?.first_checkpoint) : Option.none<bigint>()),
29
+ Effect.catchIf((e) => e.code === "NOT_FOUND", () => Effect.succeedNone)
30
+ )
31
+ return {
32
+ observe: (digest, fromEpoch) =>
33
+ Effect.gen(function*() {
34
+ const before = yield* serviceInfo
35
+ if (before.epoch === undefined) return Option.none()
36
+ const found = yield* grpc.unary(Rpc.LedgerService_GetTransaction, { digest, read_mask: { paths: ["digest"] } }).pipe(
37
+ Effect.map((r) => r.transaction?.digest === digest),
38
+ Effect.catchIf((e) => e.code === "NOT_FOUND", () => Effect.succeed(false))
39
+ )
40
+ const after = yield* serviceInfo
41
+ // Proto3 optional: absent means unreported, which is never "full history".
42
+ const gap = yield* historyGap(Option.fromNullishOr(after.lowest_available_checkpoint), fromEpoch, epochFirstCheckpoint)
43
+ return Option.some({ epoch: before.epoch, found, gap })
44
+ }).pipe(Effect.withSpan("Evidence.observe", { attributes: { digest } }))
45
+ }
46
+ })
47
+ )
@@ -0,0 +1,117 @@
1
+ /**
2
+ * `Journal`: what this process has put on the wire.
3
+ *
4
+ * A `Context.Reference` with an in-memory default, so it never appears in an
5
+ * `R` and the shortest program needs no wiring. The default is computed once
6
+ * and is process-wide (it keeps the latest {@link MEMORY_SETTLED_CAP} settled
7
+ * entries); a test (or a process that wants its own) provides `layerMemory`,
8
+ * and a long-lived service provides the durable `JournalKeyValueStore.layer`,
9
+ * then calls `Lifecycle.reconcileAll` at startup.
10
+ */
11
+ import * as Context from "effect/Context"
12
+ import * as DateTime from "effect/DateTime"
13
+ import * as Effect from "effect/Effect"
14
+ import * as Layer from "effect/Layer"
15
+ import * as Option from "effect/Option"
16
+ import { isUnresolved, type JournalEntry, millisOf, oldestFirst, type Unresolved } from "./JournalEntry.ts"
17
+ import type { JournalError } from "./Outcome.ts"
18
+
19
+ /**
20
+ * A stored entry that cannot be read back: it does not decode (truncated
21
+ * write, a foreign value under the journal's keys, an unknown schema version)
22
+ * or does not match its key. Listings report it instead of failing, so one
23
+ * bad entry never strands the others; `remove(key)` deletes it.
24
+ */
25
+ export interface CorruptEntry {
26
+ /** The digest part of its key. */
27
+ readonly key: string
28
+ readonly reason: string
29
+ }
30
+
31
+ export interface UnresolvedListing {
32
+ /** Every readable `Signed` / `Unknown` entry, oldest first. */
33
+ readonly entries: ReadonlyArray<Unresolved>
34
+ /** Entries that could not be read, by key. */
35
+ readonly corrupt: ReadonlyArray<CorruptEntry>
36
+ }
37
+
38
+ export interface JournalService {
39
+ /** Record an entry, replacing any earlier one for the same digest. */
40
+ readonly put: (entry: JournalEntry) => Effect.Effect<void, JournalError>
41
+ /** The entry for `digest`; an entry that cannot be read is a `JournalError`. */
42
+ readonly get: (digest: string) => Effect.Effect<Option.Option<JournalEntry>, JournalError>
43
+ /** Every unresolved entry, plus the entries that could not be read. */
44
+ readonly listUnresolved: Effect.Effect<UnresolvedListing, JournalError>
45
+ /**
46
+ * Delete settled entries (`Executed`, `Failed`, `NotApplied`) recorded
47
+ * strictly before `before`; answer how many. Unresolved and corrupt entries
48
+ * are never deleted here, however old: use `remove`.
49
+ */
50
+ readonly pruneSettled: (before: DateTime.DateTime) => Effect.Effect<number, JournalError>
51
+ /**
52
+ * Delete the entry for `digest` (or a corrupt entry's key), whatever it
53
+ * holds. The way to drop an unresolved submission you have given up on, e.g.
54
+ * one whose validity window closed long ago but that no evidence settles.
55
+ * The journal then forgets the bytes: nothing will reconcile or re-send them.
56
+ */
57
+ readonly remove: (digest: string) => Effect.Effect<void, JournalError>
58
+ }
59
+
60
+ /** Settled entries the in-memory journal keeps; the oldest are dropped beyond this. */
61
+ export const MEMORY_SETTLED_CAP = 10_000
62
+
63
+ /**
64
+ * An in-memory journal over a `Map`. Survives nothing. Keeps every unresolved
65
+ * entry and the latest `maxSettled` settled ones (default
66
+ * {@link MEMORY_SETTLED_CAP}), so a long-lived process does not grow without bound.
67
+ */
68
+ export const makeMemory = (options?: { readonly maxSettled?: number }): JournalService => {
69
+ const max = options?.maxSettled ?? MEMORY_SETTLED_CAP
70
+ const entries = new Map<string, JournalEntry>()
71
+ // Settled digests in insertion order (a Set iterates in insertion order).
72
+ const settled = new Set<string>()
73
+ return {
74
+ put: (entry) =>
75
+ Effect.sync(() => {
76
+ entries.set(entry.digest, entry)
77
+ settled.delete(entry.digest)
78
+ if (isUnresolved(entry)) return
79
+ settled.add(entry.digest)
80
+ while (settled.size > max) {
81
+ const oldest = settled.values().next().value!
82
+ settled.delete(oldest)
83
+ entries.delete(oldest)
84
+ }
85
+ }),
86
+ get: (digest) => Effect.sync(() => Option.fromNullishOr(entries.get(digest))),
87
+ listUnresolved: Effect.sync(() => ({
88
+ entries: [...entries.values()].filter(isUnresolved).sort(oldestFirst),
89
+ corrupt: []
90
+ })),
91
+ pruneSettled: (before) =>
92
+ Effect.sync(() => {
93
+ const cutoff = DateTime.toEpochMillis(before)
94
+ let n = 0
95
+ for (const [digest, entry] of entries) {
96
+ if (!isUnresolved(entry) && millisOf(entry) < cutoff) {
97
+ entries.delete(digest)
98
+ settled.delete(digest)
99
+ n++
100
+ }
101
+ }
102
+ return n
103
+ }),
104
+ remove: (digest) =>
105
+ Effect.sync(() => {
106
+ entries.delete(digest)
107
+ settled.delete(digest)
108
+ })
109
+ }
110
+ }
111
+
112
+ export const Journal = Context.Reference<JournalService>("@unconfirmed/effect-sui/lifecycle/Journal", {
113
+ defaultValue: () => makeMemory()
114
+ })
115
+
116
+ /** A fresh in-memory journal. */
117
+ export const layerMemory: Layer.Layer<never> = Layer.sync(Journal, () => makeMemory())
@@ -0,0 +1,68 @@
1
+ /**
2
+ * One line of the submission journal, as a Schema tagged union so a durable
3
+ * journal stores it as JSON.
4
+ *
5
+ * `Signed` is written before the first execute: the bytes may be on the wire.
6
+ * `Unknown` means the answer never arrived; the bytes are kept for later.
7
+ * `Executed`, `Failed` and `NotApplied` are terminal. `NotApplied` is its own
8
+ * terminal case so a proven-dead submission does not stay unresolved forever.
9
+ *
10
+ * `Signed`, `Unknown` and `Executed` keep the `include` the submission asked
11
+ * for, so a reconcile after a crash returns the same parts of the effects.
12
+ */
13
+ import type { Include } from "../Transactions.ts"
14
+ import * as DateTime from "effect/DateTime"
15
+ import * as Schema from "effect/Schema"
16
+ import { NotAppliedEvidence } from "./Outcome.ts"
17
+ import { SignedTransaction } from "./SignedTransaction.ts"
18
+
19
+ /** `Transactions.Include`: the optional parts of the effects to read. Absent from entries written before it existed. */
20
+ const include = Schema.optionalKey(Schema.Array(Schema.Literals(["events", "balanceChanges"] satisfies ReadonlyArray<Include>)))
21
+
22
+ export const JournalEntry = Schema.TaggedUnion({
23
+ Signed: {
24
+ digest: Schema.String,
25
+ signed: SignedTransaction,
26
+ include,
27
+ at: Schema.DateTimeUtcFromMillis
28
+ },
29
+ Unknown: {
30
+ digest: Schema.String,
31
+ signed: SignedTransaction,
32
+ include,
33
+ lastError: Schema.String,
34
+ attempts: Schema.Int,
35
+ at: Schema.DateTimeUtcFromMillis
36
+ },
37
+ Executed: {
38
+ digest: Schema.String,
39
+ include,
40
+ at: Schema.DateTimeUtcFromMillis
41
+ },
42
+ Failed: {
43
+ digest: Schema.String,
44
+ description: Schema.String,
45
+ at: Schema.DateTimeUtcFromMillis
46
+ },
47
+ NotApplied: {
48
+ digest: Schema.String,
49
+ evidence: NotAppliedEvidence,
50
+ at: Schema.DateTimeUtcFromMillis
51
+ }
52
+ })
53
+ export type JournalEntry = typeof JournalEntry.Type
54
+
55
+ export type Unresolved = Extract<JournalEntry, { readonly _tag: "Signed" | "Unknown" }>
56
+
57
+ /** `Signed` and `Unknown` still need an answer from the network. */
58
+ export const isUnresolved: (entry: JournalEntry) => entry is Unresolved = JournalEntry.isAnyOf(["Signed", "Unknown"])
59
+
60
+ /** The `include` an entry recorded, if any. */
61
+ export const includeOf = (entry: JournalEntry): ReadonlyArray<Include> | undefined =>
62
+ entry._tag === "Signed" || entry._tag === "Unknown" || entry._tag === "Executed" ? entry.include : undefined
63
+
64
+ export const millisOf = (entry: JournalEntry): number => DateTime.toEpochMillis(entry.at)
65
+
66
+ /** Oldest first, then by digest, for a stable order. */
67
+ export const oldestFirst = (a: JournalEntry, b: JournalEntry): number =>
68
+ millisOf(a) - millisOf(b) || (a.digest < b.digest ? -1 : a.digest > b.digest ? 1 : 0)
@@ -0,0 +1,276 @@
1
+ /**
2
+ * The durable `Journal`, over Effect's `KeyValueStore` (`effect/persistence`).
3
+ *
4
+ * One key per entry, `entry:<digest>`, holding the entry as JSON with a schema
5
+ * version (`{"v":1,...}`; entries written before versioning have no `v` and
6
+ * are read as version 1). Nothing is read-modify-written, so two journals (or
7
+ * two processes) over one store do not lose each other's entries. A terminal
8
+ * entry also gets a settled marker, `settled:<digest>`: a negative index that
9
+ * lets `listUnresolved` skip it (one `keys` plus one read per unresolved
10
+ * entry, however many settled ones the store keeps). The write order makes a
11
+ * crash cost at worst one spurious read, never a hidden entry:
12
+ *
13
+ * - unresolved put: clear marker, write entry, clear marker again;
14
+ * - terminal put: write entry, write marker, re-read the entry and remove the
15
+ * marker unless the read confirms a terminal entry;
16
+ * - a listing that reads an unmarked terminal entry marks it the same way
17
+ * (best effort).
18
+ *
19
+ * The one window it cannot close (it would need compare-and-set): a settling
20
+ * writer that dies between its marker write and its re-read while another
21
+ * writer's unresolved put of the same digest landed just before the marker.
22
+ * That entry is then hidden from listings (never from `get`) until rewritten.
23
+ *
24
+ * An entry that cannot be read back (does not parse or decode, has a schema
25
+ * version this code does not know, sits under another digest's key, or holds
26
+ * bytes of another digest) is reported in the listing's `corrupt` list, never
27
+ * a failure of the whole listing; `get` of it is a `JournalError`, and
28
+ * `remove` deletes it.
29
+ *
30
+ * Building the layer does no network work; call `Lifecycle.reconcileAll`.
31
+ */
32
+ import * as Hash from "../Hash.ts"
33
+ import * as DateTime from "effect/DateTime"
34
+ import * as Effect from "effect/Effect"
35
+ import * as Layer from "effect/Layer"
36
+ import * as Option from "effect/Option"
37
+ import * as KeyValueStore from "effect/persistence/KeyValueStore"
38
+ import * as Result from "effect/Result"
39
+ import * as Schema from "effect/Schema"
40
+ import { type CorruptEntry, Journal, type JournalService } from "./Journal.ts"
41
+ import { isUnresolved, JournalEntry, millisOf, oldestFirst, type Unresolved } from "./JournalEntry.ts"
42
+ import { JournalError } from "./Outcome.ts"
43
+
44
+ const ENTRY = "entry:"
45
+ const SETTLED = "settled:"
46
+ const CONCURRENCY = 8
47
+
48
+ /**
49
+ * The stored schema version. Bump it, and keep reading the older ones, when
50
+ * `JournalEntry` changes shape. An added optional field (`include`) is no
51
+ * change of shape: older entries decode without it, and older code reading a
52
+ * newer entry drops it rather than reporting the entry corrupt, so the signed
53
+ * bytes are never stranded.
54
+ */
55
+ export const VERSION = 1
56
+
57
+ const decodeEntry = Schema.decodeUnknownEffect(JournalEntry)
58
+ const encodeEntry = Schema.encodeEffect(JournalEntry)
59
+
60
+ const journalError = (cause: unknown): JournalError =>
61
+ new JournalError({ message: cause instanceof Error ? cause.message : String(cause) })
62
+
63
+ const messageOf = (cause: unknown): string => (cause instanceof Error ? cause.message : String(cause))
64
+
65
+ /** The stored JSON for an entry, versioned. */
66
+ const encode = (entry: JournalEntry): Effect.Effect<string, JournalError> =>
67
+ Effect.map(Effect.mapError(encodeEntry(entry), journalError), (encoded) => JSON.stringify({ v: VERSION, ...encoded }))
68
+
69
+ /**
70
+ * Decode and check a stored value: the reason it is unreadable, or the entry.
71
+ * It must be a known version, sit under its own digest, and signed bytes must
72
+ * hash to that digest.
73
+ */
74
+ const decode = (key: string, raw: string): Effect.Effect<Result.Result<JournalEntry, string>> =>
75
+ Effect.gen(function*() {
76
+ let json: unknown
77
+ try {
78
+ json = JSON.parse(raw)
79
+ } catch (e) {
80
+ return Result.fail(`not JSON: ${messageOf(e)}`)
81
+ }
82
+ if (typeof json !== "object" || json === null || Array.isArray(json)) return Result.fail("not a JSON object")
83
+ const { v, ...rest } = json as Record<string, unknown>
84
+ if (v !== undefined && v !== VERSION) return Result.fail(`unknown journal schema version ${JSON.stringify(v)}`)
85
+ const decoded = yield* Effect.result(decodeEntry(rest))
86
+ if (decoded._tag === "Failure") return Result.fail(`does not decode: ${messageOf(decoded.failure)}`)
87
+ const entry = decoded.success
88
+ if (entry.digest !== key) return Result.fail(`the entry under ${key} is for ${entry.digest}`)
89
+ if (entry._tag === "Signed" || entry._tag === "Unknown") {
90
+ const computed = Hash.transactionDigest(entry.signed.bytes)
91
+ if (computed !== entry.digest || entry.signed.digest !== entry.digest) {
92
+ return Result.fail(`the entry ${entry.digest} holds bytes with digest ${computed}`)
93
+ }
94
+ }
95
+ return Result.succeed(entry)
96
+ })
97
+
98
+ type Read =
99
+ | { readonly _tag: "Missing" }
100
+ | { readonly _tag: "Entry"; readonly entry: JournalEntry }
101
+ | { readonly _tag: "Corrupt"; readonly corrupt: CorruptEntry }
102
+
103
+ /** Read one entry; a store failure is a `JournalError`, an unreadable value is `Corrupt`. */
104
+ const read = (kv: KeyValueStore.KeyValueStore, digest: string): Effect.Effect<Read, JournalError> =>
105
+ kv.get(`${ENTRY}${digest}`).pipe(
106
+ Effect.mapError(journalError),
107
+ Effect.flatMap((raw): Effect.Effect<Read> =>
108
+ raw === undefined
109
+ ? Effect.succeed({ _tag: "Missing" })
110
+ : Effect.map(decode(digest, raw), (r): Read =>
111
+ r._tag === "Success"
112
+ ? { _tag: "Entry", entry: r.success }
113
+ : { _tag: "Corrupt", corrupt: { key: digest, reason: r.failure } })
114
+ )
115
+ )
116
+
117
+ /** `read` for `get`: an unreadable entry is a `JournalError`. */
118
+ const readEntry = (kv: KeyValueStore.KeyValueStore, digest: string): Effect.Effect<Option.Option<JournalEntry>, JournalError> =>
119
+ Effect.flatMap(read(kv, digest), (r) =>
120
+ r._tag === "Missing"
121
+ ? Effect.succeedNone
122
+ : r._tag === "Entry"
123
+ ? Effect.succeedSome(r.entry)
124
+ : Effect.fail(new JournalError({ message: `the journal entry ${digest} cannot be read: ${r.corrupt.reason}` })))
125
+
126
+ /** Removing a key that is absent is a no-op in every `KeyValueStore`. */
127
+ const clearMarker = (kv: KeyValueStore.KeyValueStore, digest: string) =>
128
+ Effect.mapError(kv.remove(`${SETTLED}${digest}`), journalError)
129
+
130
+ const listKeys = (kv: KeyValueStore.KeyValueStore) =>
131
+ Effect.map(Effect.mapError(kv.keys, journalError), (keys) => {
132
+ const entries: Array<string> = []
133
+ const settled = new Set<string>()
134
+ for (const key of keys) {
135
+ if (key.startsWith(ENTRY)) entries.push(key.slice(ENTRY.length))
136
+ else if (key.startsWith(SETTLED)) settled.add(key.slice(SETTLED.length))
137
+ }
138
+ return { entries, settled }
139
+ })
140
+
141
+ /** Mark settled, re-read, and take the marker back unless the read confirms a terminal entry. */
142
+ const settleMarker = (kv: KeyValueStore.KeyValueStore, entry: JournalEntry) =>
143
+ Effect.gen(function*() {
144
+ const key = `${SETTLED}${entry.digest}`
145
+ yield* Effect.mapError(kv.set(key, entry._tag), journalError)
146
+ const confirmed = yield* read(kv, entry.digest).pipe(
147
+ Effect.map((again) => again._tag === "Entry" && !isUnresolved(again.entry)),
148
+ Effect.orElseSucceed(() => false)
149
+ )
150
+ if (!confirmed) yield* Effect.mapError(kv.remove(key), journalError)
151
+ })
152
+
153
+ /** A journal over `store`, optionally under a key prefix. Every member fails only with `JournalError`. */
154
+ export const make = (store: KeyValueStore.KeyValueStore, options?: { readonly prefix?: string }): JournalService => {
155
+ const kv = options?.prefix === undefined ? store : KeyValueStore.prefix(store, options.prefix)
156
+ return {
157
+ put: Effect.fn("Journal.put")(function*(entry: JournalEntry) {
158
+ const json = yield* encode(entry)
159
+ const set = Effect.mapError(kv.set(`${ENTRY}${entry.digest}`, json), journalError)
160
+ if (isUnresolved(entry)) {
161
+ yield* clearMarker(kv, entry.digest)
162
+ yield* set
163
+ yield* clearMarker(kv, entry.digest)
164
+ } else {
165
+ yield* set
166
+ yield* settleMarker(kv, entry)
167
+ }
168
+ }),
169
+ get: (digest) => readEntry(kv, digest).pipe(Effect.withSpan("Journal.get")),
170
+ listUnresolved: Effect.gen(function*() {
171
+ const { entries, settled } = yield* listKeys(kv)
172
+ const reads = yield* Effect.forEach(
173
+ entries.filter((digest) => !settled.has(digest)),
174
+ (digest) =>
175
+ read(kv, digest).pipe(
176
+ Effect.tap((r) => r._tag === "Entry" && !isUnresolved(r.entry) ? Effect.ignore(settleMarker(kv, r.entry)) : Effect.void)
177
+ ),
178
+ { concurrency: CONCURRENCY }
179
+ )
180
+ const unresolved: Array<Unresolved> = []
181
+ const corrupt: Array<CorruptEntry> = []
182
+ for (const r of reads) {
183
+ if (r._tag === "Entry" && isUnresolved(r.entry)) unresolved.push(r.entry)
184
+ else if (r._tag === "Corrupt") corrupt.push(r.corrupt)
185
+ }
186
+ if (corrupt.length > 0) {
187
+ yield* Effect.logWarning(`the journal holds ${corrupt.length} unreadable entr${corrupt.length === 1 ? "y" : "ies"}`).pipe(
188
+ Effect.annotateLogs({ corrupt: corrupt.map((c) => `${c.key}: ${c.reason}`).join("; ") })
189
+ )
190
+ }
191
+ return { entries: unresolved.sort(oldestFirst), corrupt }
192
+ }).pipe(Effect.withSpan("Journal.listUnresolved")),
193
+ pruneSettled: Effect.fn("Journal.pruneSettled")(function*(before: DateTime.DateTime) {
194
+ const cutoff = DateTime.toEpochMillis(before)
195
+ const { entries, settled: markers } = yield* listKeys(kv)
196
+ const reads = yield* Effect.forEach(entries, (digest) => read(kv, digest), { concurrency: CONCURRENCY })
197
+ const prunable: Array<JournalEntry> = []
198
+ for (const r of reads) {
199
+ if (r._tag === "Entry" && !isUnresolved(r.entry) && millisOf(r.entry) < cutoff) prunable.push(r.entry)
200
+ }
201
+ // Marker first: a crash in between leaves an unmarked settled entry, read once later.
202
+ // Then re-read: an unresolved entry written for the digest since the bulk
203
+ // read (the same bytes submitted again) is never deleted. Without a
204
+ // compare-and-set the window between this re-read and the remove remains.
205
+ const deleted = yield* Effect.forEach(
206
+ prunable,
207
+ (entry) =>
208
+ Effect.gen(function*() {
209
+ yield* clearMarker(kv, entry.digest)
210
+ const again = yield* read(kv, entry.digest)
211
+ if (
212
+ again._tag !== "Entry" || isUnresolved(again.entry) || again.entry._tag !== entry._tag ||
213
+ millisOf(again.entry) !== millisOf(entry)
214
+ ) {
215
+ if (again._tag === "Entry" && !isUnresolved(again.entry)) yield* Effect.ignore(settleMarker(kv, again.entry))
216
+ return 0
217
+ }
218
+ yield* Effect.mapError(kv.remove(`${ENTRY}${entry.digest}`), journalError)
219
+ return 1
220
+ }),
221
+ { concurrency: CONCURRENCY }
222
+ )
223
+ const present = new Set(entries)
224
+ yield* Effect.forEach(
225
+ [...markers].filter((digest) => !present.has(digest)),
226
+ (digest) => clearMarker(kv, digest),
227
+ { concurrency: CONCURRENCY, discard: true }
228
+ )
229
+ return deleted.reduce((a: number, b: number) => a + b, 0)
230
+ }),
231
+ remove: Effect.fn("Journal.remove")(function*(digest: string) {
232
+ // Entry first: a crash in between leaves an orphan marker, which `pruneSettled` clears.
233
+ yield* Effect.mapError(kv.remove(`${ENTRY}${digest}`), journalError)
234
+ yield* clearMarker(kv, digest)
235
+ })
236
+ }
237
+ }
238
+
239
+ export interface Options {
240
+ /**
241
+ * `"fail"` refuses to build while the store holds unresolved or unreadable
242
+ * entries (settle them first with `Lifecycle.reconcileAll` under another
243
+ * journal layer, or by hand); `"ignore"` builds and leaves them for
244
+ * `reconcileAll`. Default `"ignore"`.
245
+ */
246
+ readonly onUnresolved?: "fail" | "ignore"
247
+ /** A key prefix, so several journals can share one store. */
248
+ readonly prefix?: string
249
+ }
250
+
251
+ /** The durable journal as a layer over whatever `KeyValueStore` is provided. */
252
+ export const layer = (options?: Options): Layer.Layer<never, JournalError, KeyValueStore.KeyValueStore> =>
253
+ Layer.effect(
254
+ Journal,
255
+ Effect.gen(function*() {
256
+ const journal = make(yield* KeyValueStore.KeyValueStore, options?.prefix === undefined ? {} : { prefix: options.prefix })
257
+ if (options?.onUnresolved === "fail") {
258
+ const { entries, corrupt } = yield* journal.listUnresolved
259
+ if (entries.length > 0 || corrupt.length > 0) {
260
+ const parts = [
261
+ ...(entries.length > 0
262
+ ? [`${entries.length} unresolved submission(s): ${entries.map((e) => e.digest).join(", ")}`]
263
+ : []),
264
+ ...(corrupt.length > 0
265
+ ? [`${corrupt.length} unreadable entr${corrupt.length === 1 ? "y" : "ies"}: ${corrupt.map((c) => c.key).join(", ")}`]
266
+ : [])
267
+ ]
268
+ return yield* new JournalError({
269
+ message: `the journal holds ${parts.join(" and ")}; settle them with Lifecycle.reconcileAll ` +
270
+ `(unreadable ones with Journal.remove) or build with { onUnresolved: "ignore" }`
271
+ })
272
+ }
273
+ }
274
+ return journal
275
+ })
276
+ )