@seedprotocol/publish 0.6.7 → 0.6.9

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 (291) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +64 -24
  3. package/dist/chainConfig-3sSqEVQh.js +1433 -0
  4. package/dist/chainConfig-3sSqEVQh.js.map +1 -0
  5. package/dist/chainConfig-3wlYarAG.js +1433 -0
  6. package/dist/chainConfig-3wlYarAG.js.map +1 -0
  7. package/dist/chainConfig-BRcsMopd.js +1442 -0
  8. package/dist/chainConfig-BRcsMopd.js.map +1 -0
  9. package/dist/chainConfig-BYm5OXpk.js +1433 -0
  10. package/dist/chainConfig-BYm5OXpk.js.map +1 -0
  11. package/dist/chainConfig-CA1Hrrjg.js +1387 -0
  12. package/dist/chainConfig-CA1Hrrjg.js.map +1 -0
  13. package/dist/chainConfig-CYy0XJ0M.js +1283 -0
  14. package/dist/chainConfig-CYy0XJ0M.js.map +1 -0
  15. package/dist/chainConfig-CfVGYAsY.js +1311 -0
  16. package/dist/chainConfig-CfVGYAsY.js.map +1 -0
  17. package/dist/chainConfig-DDA4YmAB.js +1424 -0
  18. package/dist/chainConfig-DDA4YmAB.js.map +1 -0
  19. package/dist/config-CPBd5C_b.js +1201 -0
  20. package/dist/config-CPBd5C_b.js.map +1 -0
  21. package/dist/config-DkIapO94.js +955 -0
  22. package/dist/config-DkIapO94.js.map +1 -0
  23. package/dist/config-EQZZNH9H.js +955 -0
  24. package/dist/config-EQZZNH9H.js.map +1 -0
  25. package/dist/config.d.ts +85 -13
  26. package/dist/config.d.ts.map +1 -1
  27. package/dist/ensureAutomationSessionKey-BMHLKfjj.js +85 -0
  28. package/dist/ensureAutomationSessionKey-BMHLKfjj.js.map +1 -0
  29. package/dist/ensureAutomationSessionKey-BZ9_3FMW.js +86 -0
  30. package/dist/ensureAutomationSessionKey-BZ9_3FMW.js.map +1 -0
  31. package/dist/ensureAutomationSessionKey-Bw74ZSGI.js +85 -0
  32. package/dist/ensureAutomationSessionKey-Bw74ZSGI.js.map +1 -0
  33. package/dist/ensureAutomationSessionKey-C8D7BFjU.js +85 -0
  34. package/dist/ensureAutomationSessionKey-C8D7BFjU.js.map +1 -0
  35. package/dist/ensureAutomationSessionKey-CClLVX2w.js +85 -0
  36. package/dist/ensureAutomationSessionKey-CClLVX2w.js.map +1 -0
  37. package/dist/ensureAutomationSessionKey-CNNN1jBQ.js +85 -0
  38. package/dist/ensureAutomationSessionKey-CNNN1jBQ.js.map +1 -0
  39. package/dist/ensureAutomationSessionKey-CeUbjcCl.js +85 -0
  40. package/dist/ensureAutomationSessionKey-CeUbjcCl.js.map +1 -0
  41. package/dist/ensureAutomationSessionKey-D8Gki6U6.js +85 -0
  42. package/dist/ensureAutomationSessionKey-D8Gki6U6.js.map +1 -0
  43. package/dist/ensureAutomationSessionKey-DEH7nwUc.js +86 -0
  44. package/dist/ensureAutomationSessionKey-DEH7nwUc.js.map +1 -0
  45. package/dist/ensureAutomationSessionKey-Dhvbii2M.js +86 -0
  46. package/dist/ensureAutomationSessionKey-Dhvbii2M.js.map +1 -0
  47. package/dist/ensureAutomationSessionKey-Dyfk8qVp.js +85 -0
  48. package/dist/ensureAutomationSessionKey-Dyfk8qVp.js.map +1 -0
  49. package/dist/ensureModularPublishBootstrap-5HJDqJJM.js +24 -0
  50. package/dist/ensureModularPublishBootstrap-5HJDqJJM.js.map +1 -0
  51. package/dist/ensureModularPublishBootstrap-BW8jKN_A.js +24 -0
  52. package/dist/ensureModularPublishBootstrap-BW8jKN_A.js.map +1 -0
  53. package/dist/ensureModularPublishBootstrap-BhYNmLzT.js +24 -0
  54. package/dist/ensureModularPublishBootstrap-BhYNmLzT.js.map +1 -0
  55. package/dist/ensureModularPublishBootstrap-Bsw1xSCt.js +24 -0
  56. package/dist/ensureModularPublishBootstrap-Bsw1xSCt.js.map +1 -0
  57. package/dist/ensureModularPublishBootstrap-Btih5xbB.js +129 -0
  58. package/dist/ensureModularPublishBootstrap-Btih5xbB.js.map +1 -0
  59. package/dist/ensureModularPublishBootstrap-CI4U08Gc.js +129 -0
  60. package/dist/ensureModularPublishBootstrap-CI4U08Gc.js.map +1 -0
  61. package/dist/ensureModularPublishBootstrap-CcU-hXll.js +128 -0
  62. package/dist/ensureModularPublishBootstrap-CcU-hXll.js.map +1 -0
  63. package/dist/ensureModularPublishBootstrap-CdrykHAi.js +24 -0
  64. package/dist/ensureModularPublishBootstrap-CdrykHAi.js.map +1 -0
  65. package/dist/ensureModularPublishBootstrap-DGBKVGg5.js +24 -0
  66. package/dist/ensureModularPublishBootstrap-DGBKVGg5.js.map +1 -0
  67. package/dist/ensureModularPublishBootstrap-DaREOqSc.js +129 -0
  68. package/dist/ensureModularPublishBootstrap-DaREOqSc.js.map +1 -0
  69. package/dist/ensureModularPublishBootstrap-DxIG-LUP.js +24 -0
  70. package/dist/ensureModularPublishBootstrap-DxIG-LUP.js.map +1 -0
  71. package/dist/ensureSmartWalletThenPublish-BSYzckyS.js +49 -0
  72. package/dist/ensureSmartWalletThenPublish-BSYzckyS.js.map +1 -0
  73. package/dist/ensureSmartWalletThenPublish-Bf8FN1un.js +49 -0
  74. package/dist/ensureSmartWalletThenPublish-Bf8FN1un.js.map +1 -0
  75. package/dist/ensureSmartWalletThenPublish-Bl415Ss6.js +48 -0
  76. package/dist/ensureSmartWalletThenPublish-Bl415Ss6.js.map +1 -0
  77. package/dist/ensureSmartWalletThenPublish-Bm58tc-b.js +48 -0
  78. package/dist/ensureSmartWalletThenPublish-Bm58tc-b.js.map +1 -0
  79. package/dist/ensureSmartWalletThenPublish-CE7acryB.js +49 -0
  80. package/dist/ensureSmartWalletThenPublish-CE7acryB.js.map +1 -0
  81. package/dist/ensureSmartWalletThenPublish-D5GSZRyZ.js +48 -0
  82. package/dist/ensureSmartWalletThenPublish-D5GSZRyZ.js.map +1 -0
  83. package/dist/ensureSmartWalletThenPublish-DAomriGc.js +48 -0
  84. package/dist/ensureSmartWalletThenPublish-DAomriGc.js.map +1 -0
  85. package/dist/ensureSmartWalletThenPublish-DaZf3q5S.js +48 -0
  86. package/dist/ensureSmartWalletThenPublish-DaZf3q5S.js.map +1 -0
  87. package/dist/ensureSmartWalletThenPublish-Dta2AOyJ.js +48 -0
  88. package/dist/ensureSmartWalletThenPublish-Dta2AOyJ.js.map +1 -0
  89. package/dist/ensureSmartWalletThenPublish-ekb0xJRn.js +48 -0
  90. package/dist/ensureSmartWalletThenPublish-ekb0xJRn.js.map +1 -0
  91. package/dist/ensureSmartWalletThenPublish-v5fhvKxZ.js +48 -0
  92. package/dist/ensureSmartWalletThenPublish-v5fhvKxZ.js.map +1 -0
  93. package/dist/errors-Du3LNbJN.js.map +1 -1
  94. package/dist/errors.d.ts +2 -2
  95. package/dist/errors.d.ts.map +1 -1
  96. package/dist/helpers/abi/executor.d.ts +125 -0
  97. package/dist/helpers/abi/executor.d.ts.map +1 -1
  98. package/dist/helpers/abi/factory.d.ts +1 -1
  99. package/dist/helpers/abi/factory.d.ts.map +1 -1
  100. package/dist/helpers/abi/publisher.d.ts +18 -74
  101. package/dist/helpers/abi/publisher.d.ts.map +1 -1
  102. package/dist/helpers/abi/seedErrors.d.ts +141 -0
  103. package/dist/helpers/abi/seedErrors.d.ts.map +1 -0
  104. package/dist/helpers/abi/seedExecutorRouter.d.ts +60 -0
  105. package/dist/helpers/abi/seedExecutorRouter.d.ts.map +1 -0
  106. package/dist/helpers/adapters/permissionlessTxSender.d.ts +26 -0
  107. package/dist/helpers/adapters/permissionlessTxSender.d.ts.map +1 -1
  108. package/dist/helpers/adapters/thirdwebAccount.d.ts +10 -2
  109. package/dist/helpers/adapters/thirdwebAccount.d.ts.map +1 -1
  110. package/dist/helpers/approvedTargetsForAutomationPublish.d.ts +1 -1
  111. package/dist/helpers/blockchain.d.ts +4 -0
  112. package/dist/helpers/blockchain.d.ts.map +1 -1
  113. package/dist/helpers/chainClient.d.ts.map +1 -1
  114. package/dist/helpers/chainConfig.d.ts +2 -0
  115. package/dist/helpers/chainConfig.d.ts.map +1 -1
  116. package/dist/helpers/constants.d.ts +14 -3
  117. package/dist/helpers/constants.d.ts.map +1 -1
  118. package/dist/helpers/contracts/index.d.ts +27 -14
  119. package/dist/helpers/contracts/index.d.ts.map +1 -1
  120. package/dist/helpers/defaultApprovedTargetsForModularPublish.d.ts +12 -2
  121. package/dist/helpers/defaultApprovedTargetsForModularPublish.d.ts.map +1 -1
  122. package/dist/helpers/describeRevert.d.ts +33 -0
  123. package/dist/helpers/describeRevert.d.ts.map +1 -0
  124. package/dist/helpers/easDirect.d.ts +3 -8
  125. package/dist/helpers/easDirect.d.ts.map +1 -1
  126. package/dist/helpers/enrollPublishAutomation.d.ts +6 -2
  127. package/dist/helpers/enrollPublishAutomation.d.ts.map +1 -1
  128. package/dist/helpers/ensureAutomationSessionKey.d.ts.map +1 -1
  129. package/dist/helpers/ensureEip7702ModularAccountReady.d.ts +1 -1
  130. package/dist/helpers/ensureEip7702ModularAccountReady.d.ts.map +1 -1
  131. package/dist/helpers/ensureExecutorModule.d.ts +6 -3
  132. package/dist/helpers/ensureExecutorModule.d.ts.map +1 -1
  133. package/dist/helpers/ensureManagedAccountEasConfigured.d.ts +8 -3
  134. package/dist/helpers/ensureManagedAccountEasConfigured.d.ts.map +1 -1
  135. package/dist/helpers/ensureManagedAccountReady.d.ts.map +1 -1
  136. package/dist/helpers/ensureManagedSignerSessionKey.d.ts +5 -0
  137. package/dist/helpers/ensureManagedSignerSessionKey.d.ts.map +1 -1
  138. package/dist/helpers/ensureModularPublishBootstrap.d.ts +6 -2
  139. package/dist/helpers/ensureModularPublishBootstrap.d.ts.map +1 -1
  140. package/dist/helpers/ensureSmartWalletThenPublish.d.ts.map +1 -1
  141. package/dist/helpers/executorModuleReadiness.d.ts +28 -0
  142. package/dist/helpers/executorModuleReadiness.d.ts.map +1 -0
  143. package/dist/helpers/managedAccountAdmin.d.ts +12 -0
  144. package/dist/helpers/managedAccountAdmin.d.ts.map +1 -0
  145. package/dist/helpers/publishThirdwebClient.d.ts +10 -0
  146. package/dist/helpers/publishThirdwebClient.d.ts.map +1 -0
  147. package/dist/helpers/retryNonceTooLow.d.ts +12 -0
  148. package/dist/helpers/retryNonceTooLow.d.ts.map +1 -0
  149. package/dist/helpers/seedSigner.d.ts.map +1 -1
  150. package/dist/helpers/seedTwin.d.ts +47 -0
  151. package/dist/helpers/seedTwin.d.ts.map +1 -0
  152. package/dist/helpers/thirdweb.d.ts +21 -6
  153. package/dist/helpers/thirdweb.d.ts.map +1 -1
  154. package/dist/helpers/thirdwebChain.d.ts +21 -0
  155. package/dist/helpers/thirdwebChain.d.ts.map +1 -0
  156. package/dist/helpers/verifyPublishChain.d.ts +21 -0
  157. package/dist/helpers/verifyPublishChain.d.ts.map +1 -0
  158. package/dist/hooks/useItemPublishStatus.d.ts +2 -0
  159. package/dist/hooks/useItemPublishStatus.d.ts.map +1 -1
  160. package/dist/index.d.ts +10 -4
  161. package/dist/index.d.ts.map +1 -1
  162. package/dist/index.js +463 -408
  163. package/dist/index.js.map +1 -1
  164. package/dist/managedAccountAdmin-B64V1rlU.js +29 -0
  165. package/dist/managedAccountAdmin-B64V1rlU.js.map +1 -0
  166. package/dist/managedAccountAdmin-BVLGWpEb.js +29 -0
  167. package/dist/managedAccountAdmin-BVLGWpEb.js.map +1 -0
  168. package/dist/managedAccountAdmin-Bje6X8Ds.js +29 -0
  169. package/dist/managedAccountAdmin-Bje6X8Ds.js.map +1 -0
  170. package/dist/managedAccountAdmin-C84-IlQ9.js +29 -0
  171. package/dist/managedAccountAdmin-C84-IlQ9.js.map +1 -0
  172. package/dist/managedAccountAdmin-DJMw6UH6.js +29 -0
  173. package/dist/managedAccountAdmin-DJMw6UH6.js.map +1 -0
  174. package/dist/managedAccountAdmin-DhCRBoPX.js +29 -0
  175. package/dist/managedAccountAdmin-DhCRBoPX.js.map +1 -0
  176. package/dist/managedAccountAdmin-NXD66lP5.js +29 -0
  177. package/dist/managedAccountAdmin-NXD66lP5.js.map +1 -0
  178. package/dist/publishAuthorization-B0G1em4a.js +3695 -0
  179. package/dist/publishAuthorization-B0G1em4a.js.map +1 -0
  180. package/dist/publishAuthorization-B1BVVfp0.js +3604 -0
  181. package/dist/publishAuthorization-B1BVVfp0.js.map +1 -0
  182. package/dist/publishAuthorization-BEqRnP2h.js +3925 -0
  183. package/dist/publishAuthorization-BEqRnP2h.js.map +1 -0
  184. package/dist/publishAuthorization-Bltn3y_K.js +3599 -0
  185. package/dist/publishAuthorization-Bltn3y_K.js.map +1 -0
  186. package/dist/publishAuthorization-By2Tt9kW.js +3912 -0
  187. package/dist/publishAuthorization-By2Tt9kW.js.map +1 -0
  188. package/dist/publishAuthorization-CxBkijU6.js +3925 -0
  189. package/dist/publishAuthorization-CxBkijU6.js.map +1 -0
  190. package/dist/publishAuthorization-CxWY7lAQ.js +3706 -0
  191. package/dist/publishAuthorization-CxWY7lAQ.js.map +1 -0
  192. package/dist/publishAuthorization-DEriY_jm.js +3687 -0
  193. package/dist/publishAuthorization-DEriY_jm.js.map +1 -0
  194. package/dist/publishAuthorization-DfAQs1sN.js +3707 -0
  195. package/dist/publishAuthorization-DfAQs1sN.js.map +1 -0
  196. package/dist/publishAuthorization-DjVrnMC0.js +3925 -0
  197. package/dist/publishAuthorization-DjVrnMC0.js.map +1 -0
  198. package/dist/publishAuthorization-DqhhCAhd.js +3652 -0
  199. package/dist/publishAuthorization-DqhhCAhd.js.map +1 -0
  200. package/dist/publishThirdwebClient-BdgkcqM7.js +18 -0
  201. package/dist/publishThirdwebClient-BdgkcqM7.js.map +1 -0
  202. package/dist/publishThirdwebClient-BkmDN480.js +18 -0
  203. package/dist/publishThirdwebClient-BkmDN480.js.map +1 -0
  204. package/dist/publishThirdwebClient-BnDhP3N-.js +18 -0
  205. package/dist/publishThirdwebClient-BnDhP3N-.js.map +1 -0
  206. package/dist/publishThirdwebClient-CBD9sKJR.js +18 -0
  207. package/dist/publishThirdwebClient-CBD9sKJR.js.map +1 -0
  208. package/dist/publishThirdwebClient-CQ29pzG2.js +18 -0
  209. package/dist/publishThirdwebClient-CQ29pzG2.js.map +1 -0
  210. package/dist/publishThirdwebClient-CZIVmr9Z.js +18 -0
  211. package/dist/publishThirdwebClient-CZIVmr9Z.js.map +1 -0
  212. package/dist/publishThirdwebClient-Ce7iBIsj.js +18 -0
  213. package/dist/publishThirdwebClient-Ce7iBIsj.js.map +1 -0
  214. package/dist/publishThirdwebClient-DroRrOFQ.js +18 -0
  215. package/dist/publishThirdwebClient-DroRrOFQ.js.map +1 -0
  216. package/dist/publishThirdwebClient-DzXFjQ7L.js +18 -0
  217. package/dist/publishThirdwebClient-DzXFjQ7L.js.map +1 -0
  218. package/dist/publishThirdwebClient-Dzb2vcEs.js +18 -0
  219. package/dist/publishThirdwebClient-Dzb2vcEs.js.map +1 -0
  220. package/dist/publishThirdwebClient-i8P7fivi.js +18 -0
  221. package/dist/publishThirdwebClient-i8P7fivi.js.map +1 -0
  222. package/dist/react/ConnectButton.d.ts.map +1 -1
  223. package/dist/resolveRevokeAccount-B5iXpuRT.js +38 -0
  224. package/dist/resolveRevokeAccount-B5iXpuRT.js.map +1 -0
  225. package/dist/resolveRevokeAccount-B7ImSb4Y.js +38 -0
  226. package/dist/resolveRevokeAccount-B7ImSb4Y.js.map +1 -0
  227. package/dist/resolveRevokeAccount-BM1j2l5Q.js +38 -0
  228. package/dist/resolveRevokeAccount-BM1j2l5Q.js.map +1 -0
  229. package/dist/resolveRevokeAccount-BtVG0xxc.js +38 -0
  230. package/dist/resolveRevokeAccount-BtVG0xxc.js.map +1 -0
  231. package/dist/resolveRevokeAccount-CJZZdBcQ.js +39 -0
  232. package/dist/resolveRevokeAccount-CJZZdBcQ.js.map +1 -0
  233. package/dist/resolveRevokeAccount-CaIMuCee.js +39 -0
  234. package/dist/resolveRevokeAccount-CaIMuCee.js.map +1 -0
  235. package/dist/resolveRevokeAccount-Cg4TQgnd.js +38 -0
  236. package/dist/resolveRevokeAccount-Cg4TQgnd.js.map +1 -0
  237. package/dist/resolveRevokeAccount-DHnxtEIj.js +39 -0
  238. package/dist/resolveRevokeAccount-DHnxtEIj.js.map +1 -0
  239. package/dist/resolveRevokeAccount-DJKfLlyK.js +38 -0
  240. package/dist/resolveRevokeAccount-DJKfLlyK.js.map +1 -0
  241. package/dist/resolveRevokeAccount-S-2WXkNh.js +38 -0
  242. package/dist/resolveRevokeAccount-S-2WXkNh.js.map +1 -0
  243. package/dist/resolveRevokeAccount-mzR11KJ4.js +38 -0
  244. package/dist/resolveRevokeAccount-mzR11KJ4.js.map +1 -0
  245. package/dist/services/publish/actors/checking.d.ts.map +1 -1
  246. package/dist/services/publish/actors/createAttestations.d.ts.map +1 -1
  247. package/dist/services/publish/helpers/ensureEasSchemas.d.ts +12 -1
  248. package/dist/services/publish/helpers/ensureEasSchemas.d.ts.map +1 -1
  249. package/dist/services/publish/helpers/getPublishUploadData.d.ts.map +1 -1
  250. package/dist/services/publishManager/actions/createPublish.d.ts.map +1 -1
  251. package/dist/services/publishManager/actions/drainPendingCreates.d.ts +3 -0
  252. package/dist/services/publishManager/actions/drainPendingCreates.d.ts.map +1 -0
  253. package/dist/services/publishManager/actions/publishDone.d.ts.map +1 -1
  254. package/dist/services/publishManager/actions/queueCreatePublish.d.ts +2 -0
  255. package/dist/services/publishManager/actions/queueCreatePublish.d.ts.map +1 -0
  256. package/dist/services/publishManager/actors/restoreFromDb.d.ts.map +1 -1
  257. package/dist/services/publishManager/actors/savePublish.d.ts +11 -0
  258. package/dist/services/publishManager/actors/savePublish.d.ts.map +1 -1
  259. package/dist/services/publishManager/createPublishResult.d.ts +6 -0
  260. package/dist/services/publishManager/createPublishResult.d.ts.map +1 -0
  261. package/dist/services/publishManager/index.d.ts +61 -1
  262. package/dist/services/publishManager/index.d.ts.map +1 -1
  263. package/dist/services/revoke/revokeAttestations.d.ts +3 -2
  264. package/dist/services/revoke/revokeAttestations.d.ts.map +1 -1
  265. package/dist/thirdweb.d.ts +1 -0
  266. package/dist/thirdweb.d.ts.map +1 -1
  267. package/dist/thirdweb.js +204 -128
  268. package/dist/thirdweb.js.map +1 -1
  269. package/dist/worker-2dUZSapK.js +69 -0
  270. package/dist/worker-2dUZSapK.js.map +1 -0
  271. package/dist/worker-B8gN5WTx.js +69 -0
  272. package/dist/worker-B8gN5WTx.js.map +1 -0
  273. package/dist/worker-BgErCNTb.js +69 -0
  274. package/dist/worker-BgErCNTb.js.map +1 -0
  275. package/dist/worker-C07rPV2G.js +69 -0
  276. package/dist/worker-C07rPV2G.js.map +1 -0
  277. package/dist/worker-C9Za_dlQ.js +69 -0
  278. package/dist/worker-C9Za_dlQ.js.map +1 -0
  279. package/dist/worker-CEgulQnm.js +69 -0
  280. package/dist/worker-CEgulQnm.js.map +1 -0
  281. package/dist/worker-C_TL94He.js +69 -0
  282. package/dist/worker-C_TL94He.js.map +1 -0
  283. package/dist/worker-CbtzcKG6.js +69 -0
  284. package/dist/worker-CbtzcKG6.js.map +1 -0
  285. package/dist/worker-DHUm-TeQ.js +69 -0
  286. package/dist/worker-DHUm-TeQ.js.map +1 -0
  287. package/dist/worker-DypHzXgH.js +69 -0
  288. package/dist/worker-DypHzXgH.js.map +1 -0
  289. package/dist/worker-ZL4Wg19t.js +69 -0
  290. package/dist/worker-ZL4Wg19t.js.map +1 -0
  291. package/package.json +6 -6
@@ -0,0 +1,3652 @@
1
+ import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
+ import { $ as t, A as n, B as r, C as i, D as a, E as o, G as s, I as c, J as l, K as u, L as d, N as f, O as p, P as m, Q as h, R as g, S as _, T as v, U as ee, V as te, W as y, Z as b, _ as x, at as ne, ct as S, et as re, g as C, h as w, k as ie, nt as ae, ot as oe, q as se, r as T, rt as ce, tt as le, w as ue, y as de, z as fe } from "./config-CPBd5C_b.js";
3
+ import { a as pe, o as me, r as E, s as he, t as ge } from "./errors-Du3LNbJN.js";
4
+ import { t as D } from "./publishThirdwebClient-DzXFjQ7L.js";
5
+ import { BaseArweaveClient as _e, BaseDb as O, BaseFileManager as k, INTERNAL_DATA_TYPES as ve, Item as A, ModelPropertyDataTypes as ye, applyPropertyAttestationUidsFromPublish as be, arweaveL1FinalizeJobs as xe, getCorrectId as Se, getEasSchemaForItemProperty as Ce, getItemPropertiesFromEas as we, getRelatedItemsForPublish as Te, getSegmentedItemProperties as Ee, getUploadPipelineTransactionStatus as De, htmlEmbeddedImageCoPublish as Oe, isItemOwned as ke, isPublishedSeedRef as Ae, itemHasPublishUploadCandidates as je, normalizeDataType as Me, normalizeRelationPropertyValue as Ne, prepareHtmlEmbeddedImagesForPublish as Pe, publishProcesses as j, resolvePublishPayloadValues as Fe, resolveSeedIdsFromRefString as Ie, rewriteHtmlEmbeddedImagesOnDisk as Le, setSchemaUidForModel as Re, setSchemaUidForSchemaDefinition as ze, updateVersionUid as Be, validateItemForPublish as Ve } from "@seedprotocol/sdk";
6
+ import { BaseError as He, decodeAbiParameters as Ue, decodeErrorResult as We, encodeAbiParameters as Ge, parseEventLogs as Ke, zeroAddress as qe } from "viem";
7
+ import { deploySmartAccount as Je, getContract as Ye, sendTransaction as Xe } from "thirdweb";
8
+ import { optimismSepolia as M } from "thirdweb/chains";
9
+ import { ethers as N, keccak256 as Ze, toUtf8Bytes as Qe } from "ethers";
10
+ import { createContext as $e, useContext as et, useEffect as tt, useRef as nt, useState as rt } from "react";
11
+ import it from "arweave";
12
+ import { NO_EXPIRATION as at, SchemaEncoder as ot, SchemaRegistry as st, ZERO_ADDRESS as ct, ZERO_BYTES32 as lt } from "@ethereum-attestation-service/eas-sdk";
13
+ import { assign as P, createActor as ut, enqueueActions as dt, fromCallback as F, fromPromise as I, setup as ft } from "xstate";
14
+ import L from "debug";
15
+ import { and as pt, desc as mt, eq as R } from "drizzle-orm";
16
+ import { createWallet as ht, inAppWallet as gt } from "thirdweb/wallets";
17
+ import { useActiveAccount as _t } from "thirdweb/react";
18
+ import { getInstalledModules as vt, installModule as yt } from "thirdweb/modules";
19
+ import { PUBLISH_AUTHORIZATION_DEFAULT_EXPIRATION_SECS as bt, PUBLISH_AUTHORIZATION_SCHEMA_DEF as xt, PUBLISH_AUTHORIZATION_SCHEMA_DEF as St, PUBLISH_AUTHORIZATION_SCHEMA_NAME as Ct, PUBLISH_AUTHORIZATION_SCHEMA_NAME as wt, PUBLISH_AUTHORIZATION_SCOPES as Tt, PUBLISH_AUTHORIZATION_SCOPES as Et, assessPublishAuthorization as Dt, decodePublishAuthorizationData as Ot, getPublishAuthorizationFromEas as kt, isValidEasAttestationUid as At, normalizeBytes32Hex as jt } from "@seedprotocol/eas";
20
+ //#region src/react/PublishConfigContext.tsx
21
+ var Mt = $e(null);
22
+ function Nt() {
23
+ let e = et(Mt);
24
+ if (!e) throw Error("usePublishConfig: PublishConfig is missing. Pass config to PublishProvider or call initPublish() before render.");
25
+ return e;
26
+ }
27
+ //#endregion
28
+ //#region src/helpers/blockchain.ts
29
+ var z = () => {
30
+ let e = _e.getHost(), t = it;
31
+ return Object.keys(t).includes("default") && t.default ? t.default.init({
32
+ host: e,
33
+ protocol: "https"
34
+ }) : t.init({
35
+ host: e,
36
+ protocol: "https"
37
+ });
38
+ };
39
+ //#endregion
40
+ //#region src/helpers/schemaRegistry.ts
41
+ async function B(e) {
42
+ return ee(e);
43
+ }
44
+ function Pt(e) {
45
+ return c(e);
46
+ }
47
+ //#endregion
48
+ //#region src/helpers/nameSchemaAttestation.ts
49
+ var Ft = "0x0000000000000000000000000000000000000000";
50
+ function It(e) {
51
+ let t = new ot("bytes32 schemaId,string name").encodeData([{
52
+ name: "schemaId",
53
+ value: e.schemaUid,
54
+ type: "bytes32"
55
+ }, {
56
+ name: "name",
57
+ value: e.schemaName,
58
+ type: "string"
59
+ }]);
60
+ return n({
61
+ schema: ae,
62
+ data: {
63
+ recipient: Ft,
64
+ expirationTime: BigInt(at),
65
+ revocable: !0,
66
+ refUID: lt,
67
+ data: t,
68
+ value: 0n
69
+ }
70
+ });
71
+ }
72
+ //#endregion
73
+ //#region src/services/publish/helpers/ensureEasSchemas.ts
74
+ var V = "0x0000000000000000000000000000000000000000", H = !0;
75
+ function Lt(e) {
76
+ return e.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
77
+ }
78
+ async function Rt(e) {
79
+ let { itemRelationProperties: t, itemImageProperties: n, itemListProperties: r } = await Ee(e), i = /* @__PURE__ */ new Set();
80
+ e.modelName && i.add(e.modelName);
81
+ for (let e of t) {
82
+ let t = e.propertyDef?.ref;
83
+ t && i.add(t);
84
+ }
85
+ for (let e of n) {
86
+ let t = Me(e.propertyDef?.dataType);
87
+ t === ye.File ? i.add("File") : t === ye.Html ? i.add("Html") : i.add("Image");
88
+ }
89
+ for (let e of r) {
90
+ let t = e.propertyDef?.ref;
91
+ t && i.add(t);
92
+ }
93
+ return i;
94
+ }
95
+ async function U(e, t) {
96
+ let n = await e.sendTransaction(t);
97
+ await l(n.transactionHash);
98
+ }
99
+ function zt(e) {
100
+ let t = Me(e);
101
+ return ve[t]?.eas ?? "string";
102
+ }
103
+ function Bt(e, t) {
104
+ if (e) throw Error(`schema "${t}" is not registered; automation keys can't register schemas. Call ensureEasSchemasForItem with the owner wallet first.`);
105
+ }
106
+ async function Vt(e, t) {
107
+ if (typeof t?.blockSchemaRegistration == "boolean") return t.blockSchemaRegistration;
108
+ let n = t?.managedAddress?.trim();
109
+ if (!n || !w(e)) return !1;
110
+ let { isAutomationSessionActive: r } = await import("./ensureAutomationSessionKey-DEH7nwUc.js").then((e) => e.n);
111
+ return r(n, e.signer.address);
112
+ }
113
+ async function Ht(e, t, n) {
114
+ await Ut(e, t, n);
115
+ }
116
+ async function Ut(e, t, n) {
117
+ let r = await Vt(t, n), i = w(t) ? t.txSender : x(t) ? t : (() => {
118
+ throw Error("@seedprotocol/publish: ensureEasSchemasForItem requires a PublishWallet or SeedTxSender");
119
+ })(), { itemBasicProperties: a, itemRelationProperties: o, itemImageProperties: s, itemListProperties: c } = await Ee(e), l = [
120
+ ...a,
121
+ ...o,
122
+ ...s,
123
+ ...c
124
+ ], u = /* @__PURE__ */ new Set(), d = await Rt(e), f = /* @__PURE__ */ new Set();
125
+ for (let e of d) {
126
+ let t = `bytes32 ${Lt(e)}`, n = st.getSchemaUID(t, V, H);
127
+ if (await B(n)) {
128
+ Re({
129
+ modelName: e,
130
+ schemaUid: n
131
+ });
132
+ continue;
133
+ }
134
+ if (f.has(n)) {
135
+ Re({
136
+ modelName: e,
137
+ schemaUid: n
138
+ });
139
+ continue;
140
+ }
141
+ Bt(r, t);
142
+ try {
143
+ await U(i, Pt({
144
+ schema: t,
145
+ resolverAddress: V,
146
+ revocable: H
147
+ }));
148
+ } catch (t) {
149
+ throw Error(`Failed to register EAS schema for model ${e}: ${t instanceof Error ? t.message : String(t)}`);
150
+ }
151
+ try {
152
+ await U(i, It({
153
+ schemaUid: n,
154
+ schemaName: Lt(e)
155
+ }));
156
+ } catch (t) {
157
+ throw Error(`Failed to name EAS schema for model ${e}: ${t instanceof Error ? t.message : String(t)}`);
158
+ }
159
+ f.add(n), Re({
160
+ modelName: e,
161
+ schemaUid: n
162
+ });
163
+ }
164
+ let p = "string storage_transaction_id", m = st.getSchemaUID(p, V, H);
165
+ if (await B(m)) ze({
166
+ text: p,
167
+ schemaUid: m
168
+ });
169
+ else if (!u.has(m) && (d.has("Image") || d.has("File") || d.has("Html"))) {
170
+ Bt(r, p);
171
+ try {
172
+ await U(i, Pt({
173
+ schema: p,
174
+ resolverAddress: V,
175
+ revocable: H
176
+ })), await U(i, It({
177
+ schemaUid: m,
178
+ schemaName: "storage_transaction_id"
179
+ }));
180
+ } catch (e) {
181
+ throw Error(`Failed to register EAS schema for storageTransactionId: ${e instanceof Error ? e.message : String(e)}`);
182
+ }
183
+ u.add(m), ze({
184
+ text: p,
185
+ schemaUid: m
186
+ });
187
+ }
188
+ for (let e of l) {
189
+ if (!e.propertyDef) continue;
190
+ let t = zt(e.propertyDef.dataType), n = e, a = n.storagePropertyName && n.storagePropertyName.length > 0 ? n.storagePropertyName : e.propertyName, o = Lt(a), s = `${t} ${o}`, c = [
191
+ "string",
192
+ "address",
193
+ "bool",
194
+ "bytes",
195
+ "bytes32",
196
+ "uint8",
197
+ "uint16",
198
+ "uint32",
199
+ "uint64",
200
+ "uint128",
201
+ "uint256"
202
+ ].includes(t) ? t : void 0, l = await Ce({
203
+ schemaUid: e.schemaUid,
204
+ propertyName: a,
205
+ easDataType: c
206
+ });
207
+ if (l) {
208
+ let e = await B(l.id);
209
+ if (e && e.schema === s) {
210
+ ze({
211
+ text: s,
212
+ schemaUid: l.id
213
+ });
214
+ continue;
215
+ }
216
+ }
217
+ let d = st.getSchemaUID(s, V, H);
218
+ if (await B(d)) {
219
+ ze({
220
+ text: s,
221
+ schemaUid: d
222
+ });
223
+ continue;
224
+ }
225
+ if (u.has(d)) {
226
+ ze({
227
+ text: s,
228
+ schemaUid: d
229
+ });
230
+ continue;
231
+ }
232
+ Bt(r, s);
233
+ try {
234
+ await U(i, Pt({
235
+ schema: s,
236
+ resolverAddress: V,
237
+ revocable: H
238
+ }));
239
+ } catch (t) {
240
+ throw Error(`Failed to register EAS schema for property ${e.propertyName}: ${t instanceof Error ? t.message : String(t)}`);
241
+ }
242
+ try {
243
+ await U(i, It({
244
+ schemaUid: d,
245
+ schemaName: o
246
+ }));
247
+ } catch (t) {
248
+ throw Error(`Failed to name EAS schema for property ${e.propertyName}: ${t instanceof Error ? t.message : String(t)}`);
249
+ }
250
+ u.add(d), ze({
251
+ text: s,
252
+ schemaUid: d
253
+ });
254
+ }
255
+ let h = await Te(e);
256
+ for (let e of h) await Ut(e, t, {
257
+ managedAddress: n?.managedAddress,
258
+ blockSchemaRegistration: r
259
+ });
260
+ }
261
+ //#endregion
262
+ //#region src/services/publish/actors/utils.ts
263
+ var W = "0x" + "0".repeat(64), Wt = async (e) => {
264
+ let t;
265
+ try {
266
+ t = await A.find({ seedLocalId: e });
267
+ } catch {}
268
+ return t || new Promise((t) => {
269
+ let n = setInterval(() => {
270
+ try {
271
+ A.find({ seedLocalId: e }).then((e) => {
272
+ e && (clearInterval(n), t(e));
273
+ });
274
+ } catch {}
275
+ }, 200);
276
+ });
277
+ };
278
+ function Gt(e) {
279
+ if (!e || typeof e != "object") return;
280
+ let t = e;
281
+ if (Array.isArray(t.data_root)) return {
282
+ data_root: new Uint8Array(t.data_root),
283
+ chunks: (t.chunks ?? []).map((e) => ({
284
+ ...e,
285
+ dataHash: new Uint8Array(e.dataHash ?? [])
286
+ })),
287
+ proofs: (t.proofs ?? []).map((e) => ({
288
+ ...e,
289
+ proof: new Uint8Array(e.proof ?? [])
290
+ }))
291
+ };
292
+ }
293
+ function Kt(e) {
294
+ return {
295
+ data_root: Array.from(e.data_root),
296
+ chunks: e.chunks.map((e) => ({
297
+ ...e,
298
+ dataHash: Array.from(e.dataHash)
299
+ })),
300
+ proofs: e.proofs.map((e) => ({
301
+ ...e,
302
+ proof: Array.from(e.proof)
303
+ }))
304
+ };
305
+ }
306
+ //#endregion
307
+ //#region src/services/publish/actors/createArweaveTransactions.ts
308
+ var qt = I(async ({ input: { context: e } }) => {
309
+ let { item: t } = e;
310
+ t.getPublishUploads || (t = await Wt(t.seedLocalId));
311
+ let n = {};
312
+ e.arweaveUploadTags?.length && (n.arweaveUploadTags = e.arweaveUploadTags);
313
+ let r = e.htmlEmbeddedDeferredHtmlSeedLocalIds;
314
+ r?.length && (n.deferHtmlStorageSeedLocalIds = r);
315
+ let i = await t.getPublishUploads(Object.keys(n).length ? n : void 0), a = T(), o = e.signArweaveTransactions ?? a.signArweaveTransactions, s = e.arweaveJwk ?? a.arweaveJwk, c = i.map((e) => ({
316
+ versionLocalId: e.versionLocalId,
317
+ itemPropertyName: e.itemPropertyName,
318
+ transactionJson: e.transactionToSign.toJSON()
319
+ })), l;
320
+ if (o) l = await o(c);
321
+ else if (s) {
322
+ let e = z(), t = s;
323
+ l = [];
324
+ for (let n of c) {
325
+ let r = e.transactions.fromRaw(n.transactionJson);
326
+ r.data && r.data.byteLength > 0 && !r.chunks && await r.prepareChunks(r.data), await e.transactions.sign(r, t);
327
+ let i = r.toJSON();
328
+ l.push({
329
+ transaction: {
330
+ ...i,
331
+ chunks: r.chunks ? Kt(r.chunks) : void 0
332
+ },
333
+ versionId: n.versionLocalId,
334
+ modelName: n.itemPropertyName
335
+ });
336
+ }
337
+ } else throw Error("Arweave signing not configured. Provide signArweaveTransactions or arweaveJwk at createPublish or in PublishProvider config.");
338
+ let u = z();
339
+ return {
340
+ arweaveTransactions: l.map((e) => {
341
+ let { chunks: t, ...n } = e.transaction, r = { ...n }, i = Gt(t);
342
+ return i && (r.chunks = i), {
343
+ transaction: u.transactions.fromRaw(r),
344
+ versionId: e.versionId,
345
+ modelName: e.modelName
346
+ };
347
+ }),
348
+ publishUploads: i
349
+ };
350
+ }), Jt = I(async ({ input: { context: e } }) => {
351
+ let { item: t } = e;
352
+ t.getPublishUploads || (t = await Wt(t.seedLocalId));
353
+ let n = {};
354
+ e.arweaveUploadTags?.length && (n.arweaveUploadTags = e.arweaveUploadTags);
355
+ let r = e.htmlEmbeddedDeferredHtmlSeedLocalIds;
356
+ r?.length && (n.onlyHtmlStorageSeedLocalIds = r, n.skipRelationRecursion = !0);
357
+ let i = await t.getPublishUploads(Object.keys(n).length ? n : void 0), a = T(), o = e.signArweaveTransactions ?? a.signArweaveTransactions, s = e.arweaveJwk ?? a.arweaveJwk, c = i.map((e) => ({
358
+ versionLocalId: e.versionLocalId,
359
+ itemPropertyName: e.itemPropertyName,
360
+ transactionJson: e.transactionToSign.toJSON()
361
+ })), l;
362
+ if (o) l = await o(c);
363
+ else if (s) {
364
+ let e = z(), t = s;
365
+ l = [];
366
+ for (let n of c) {
367
+ let r = e.transactions.fromRaw(n.transactionJson);
368
+ r.data && r.data.byteLength > 0 && !r.chunks && await r.prepareChunks(r.data), await e.transactions.sign(r, t);
369
+ let i = r.toJSON();
370
+ l.push({
371
+ transaction: {
372
+ ...i,
373
+ chunks: r.chunks ? Kt(r.chunks) : void 0
374
+ },
375
+ versionId: n.versionLocalId,
376
+ modelName: n.itemPropertyName
377
+ });
378
+ }
379
+ } else throw Error("Arweave signing not configured. Provide signArweaveTransactions or arweaveJwk at createPublish or in PublishProvider config.");
380
+ let u = z();
381
+ return {
382
+ arweaveTransactions: l.map((e) => {
383
+ let { chunks: t, ...n } = e.transaction, r = { ...n }, i = Gt(t);
384
+ return i && (r.chunks = i), {
385
+ transaction: u.transactions.fromRaw(r),
386
+ versionId: e.versionId,
387
+ modelName: e.modelName
388
+ };
389
+ }),
390
+ publishUploads: i
391
+ };
392
+ }), Yt = I(async ({ input: { context: e } }) => {
393
+ let t = e.htmlEmbeddedDataUriPolicy ?? "materialize";
394
+ return { deferredHtmlSeedLocalIds: (await Pe(e.item, t)).deferredHtmlSeedLocalIds };
395
+ });
396
+ //#endregion
397
+ //#region src/services/publish/actors/rewritingHtmlEmbedded.ts
398
+ function Xt(e, t) {
399
+ let n = [], r = Math.min(e?.length ?? 0, t?.length ?? 0);
400
+ for (let i = 0; i < r; i++) {
401
+ let r = e[i], a = t[i], o = r.transaction?.id;
402
+ typeof o == "string" && o.length > 0 && n.push({
403
+ txId: o,
404
+ seedLocalId: a.seedLocalId,
405
+ versionLocalId: a.versionLocalId
406
+ });
407
+ }
408
+ return n;
409
+ }
410
+ var Zt = I(async ({ input: { context: e } }) => {
411
+ let t = Xt(e.htmlEmbeddedPhase1ArweaveTransactions, e.htmlEmbeddedPhase1PublishUploads);
412
+ await Le(e.item.seedLocalId, t);
413
+ }), Qt = (e, t, n) => {
414
+ let r = [];
415
+ return e && r.push({
416
+ name: "Content-SHA-256",
417
+ value: e
418
+ }), t && r.push({
419
+ name: "Content-Type",
420
+ value: t
421
+ }), n?.length && r.push(...n), r;
422
+ }, $t = async (e) => {
423
+ let t = (e instanceof Uint8Array, new Uint8Array(e)), n = await crypto.subtle.digest("SHA-256", t);
424
+ return Array.from(new Uint8Array(n)).map((e) => e.toString(16).padStart(2, "0")).join("");
425
+ }, en = {
426
+ png: "image/png",
427
+ jpg: "image/jpeg",
428
+ jpeg: "image/jpeg",
429
+ gif: "image/gif",
430
+ webp: "image/webp",
431
+ svg: "image/svg+xml",
432
+ html: "text/html",
433
+ htm: "text/html",
434
+ json: "application/json",
435
+ txt: "text/plain"
436
+ }, tn = (e) => {
437
+ let t = e.split(".").pop()?.toLowerCase();
438
+ return t ? en[t] : void 0;
439
+ }, nn = async (e) => typeof Blob < "u" && e instanceof Blob ? new Uint8Array(await e.arrayBuffer()) : new Uint8Array(e), rn = (e) => {
440
+ switch (e) {
441
+ case "Image": return k.getFilesPath("images");
442
+ case "File": return k.getFilesPath("files");
443
+ case "Html": return k.getFilesPath("html");
444
+ case "Json": return k.getFilesPath("json");
445
+ default: return k.getFilesPath("images");
446
+ }
447
+ }, an = /^data:(image\/[a-zA-Z0-9.+-]+);base64,([\s\S]*)$/i;
448
+ function on(e) {
449
+ let t = an.exec((e ?? "").trim());
450
+ if (!t) return null;
451
+ try {
452
+ let e = t[1].toLowerCase().trim(), n = t[2].replace(/\s/g, "");
453
+ return {
454
+ mimeType: e,
455
+ bytes: Uint8Array.from(atob(n), (e) => e.charCodeAt(0))
456
+ };
457
+ } catch {
458
+ return null;
459
+ }
460
+ }
461
+ var sn = async (e, t, n, r) => {
462
+ let i = r?.arweaveUploadTags, a = e.itemProperty, o = [];
463
+ for (let t of e.childProperties) {
464
+ let e = t.localStoragePath;
465
+ e && !e.endsWith("undefined") && await k.pathExists(e) && o.push({
466
+ propertyName: t.propertyName,
467
+ localStoragePath: e
468
+ });
469
+ }
470
+ let s;
471
+ if ((!o || o.length === 0) && n?.localStoragePath) {
472
+ let e = n.localStoragePath;
473
+ if (e && !e.endsWith("undefined") && await k.pathExists(e)) try {
474
+ s = await nn(await k.readFileAsBuffer(e));
475
+ } catch {
476
+ s = await nn((await k.getFs()).readFileSync(e));
477
+ }
478
+ }
479
+ if (o.length > 0) {
480
+ let e = "===FILE_SEPARATOR===", t = "", n = await k.getFs();
481
+ for (let r of o) {
482
+ let i;
483
+ try {
484
+ i = await n.promises.readFile(r.localStoragePath);
485
+ } catch {
486
+ i = n.readFileSync(r.localStoragePath);
487
+ }
488
+ t += `${e}${r.propertyName}${e}${i}`;
489
+ }
490
+ s = typeof document < "u" ? new TextEncoder().encode(t) : new Uint8Array(Buffer.from(t));
491
+ }
492
+ if (!s) return t;
493
+ let c = new Uint8Array(s), l = await $t(c), u;
494
+ o.length === 0 && n?.localStoragePath ? u = tn(n.localStoragePath) : o.length > 0 && (u = "application/octet-stream");
495
+ let d = n ? n.localId : a.localId, f = n ? n.propertyName : a.propertyName;
496
+ return t.push({
497
+ data: c,
498
+ contentHash: l,
499
+ contentType: u,
500
+ tags: Qt(l, u, i),
501
+ itemPropertyName: f,
502
+ itemPropertyLocalId: d,
503
+ seedLocalId: a.seedLocalId,
504
+ versionLocalId: a.versionLocalId
505
+ }), t;
506
+ }, cn = async (e, t) => {
507
+ let n = [], r = t?.arweaveUploadTags;
508
+ for (let i of e) {
509
+ let e = i.getService().getSnapshot(), a = "context" in e ? e.context : null;
510
+ if (!a) continue;
511
+ let o = a.propertyValue, s = a.refResolvedValue;
512
+ if (!s) continue;
513
+ let { localId: c } = Se(o ?? "");
514
+ if (!c) continue;
515
+ let l = i.propertyDef?.refValueType ?? i.propertyDef?.dataType ?? "Image";
516
+ if (l === ye.Html) {
517
+ if (t?.deferHtmlStorageSeedLocalIds?.includes(c) || t?.onlyHtmlStorageSeedLocalIds?.length && !t.onlyHtmlStorageSeedLocalIds.includes(c)) continue;
518
+ } else if (t?.onlyHtmlStorageSeedLocalIds?.length) continue;
519
+ let u = `${rn(l)}/${s}`;
520
+ if (!await k.pathExists(u)) continue;
521
+ let d = await nn(await k.readFileAsBuffer(u)), f = await $t(d), p = tn(s);
522
+ n.push({
523
+ data: d,
524
+ contentHash: f,
525
+ contentType: p,
526
+ tags: Qt(f, p, r),
527
+ itemPropertyName: i.propertyName,
528
+ itemPropertyLocalId: i.localId,
529
+ seedLocalId: c,
530
+ versionLocalId: i.versionLocalId
531
+ });
532
+ }
533
+ return n;
534
+ };
535
+ async function ln(e, t, n) {
536
+ let r = O.getAppDb();
537
+ if (!r || n?.onlyHtmlStorageSeedLocalIds?.length) return t;
538
+ let i = await r.select().from(Oe).where(R(Oe.parentSeedLocalId, e.seedLocalId)), a = new Set(t.map((e) => e.seedLocalId));
539
+ for (let e of i) {
540
+ if (a.has(e.imageSeedLocalId)) continue;
541
+ let r = await A.find({
542
+ seedLocalId: e.imageSeedLocalId,
543
+ modelName: "Image"
544
+ });
545
+ if (!r) continue;
546
+ let i = r.internalProperties.storageTransactionId ?? r.allProperties.storageTransactionId, o = i?.getService().getSnapshot(), s = o && "context" in o ? o.context : void 0, c = on(typeof s?.propertyValue == "string" ? s.propertyValue ?? "" : ""), l = [];
547
+ if (c && i && i.localId && i.versionLocalId) {
548
+ let e = await $t(c.bytes);
549
+ l = [{
550
+ data: c.bytes,
551
+ contentHash: e,
552
+ contentType: c.mimeType,
553
+ tags: Qt(e, c.mimeType, n?.arweaveUploadTags),
554
+ itemPropertyName: i.propertyName,
555
+ itemPropertyLocalId: i.localId,
556
+ seedLocalId: r.seedLocalId,
557
+ versionLocalId: i.versionLocalId
558
+ }];
559
+ }
560
+ for (let e of l) a.has(e.seedLocalId) || (t.push(e), a.add(e.seedLocalId));
561
+ }
562
+ return t;
563
+ }
564
+ var un = async (e, t = [], n, r) => {
565
+ let { itemUploadProperties: i, itemRelationProperties: a, itemImageProperties: o } = await Ee(e);
566
+ if (!n && r?.onlyHtmlStorageSeedLocalIds?.length) {
567
+ let e = await cn(o, r);
568
+ return t.push(...e), t;
569
+ }
570
+ for (let e of i) t = await sn(e, t, n, r);
571
+ let s = await cn(o, r);
572
+ if (t.push(...s), !n && !r?.onlyHtmlStorageSeedLocalIds?.length && (t = await ln(e, t, r)), r?.skipRelationRecursion) return t;
573
+ for (let e of a) {
574
+ let n = e.getService().getSnapshot(), i = "context" in n ? n.context : null;
575
+ if (!i) continue;
576
+ let a = i.propertyValue;
577
+ if (!a || e.uid) continue;
578
+ let { seedLocalId: o, seedUid: s } = Ie(Ne(a) ?? "");
579
+ if (!o && !s) throw Error(`Invalid relation value for ${e.propertyName}: expected local seed id or 0x uid`);
580
+ let c = await A.find({
581
+ seedLocalId: o,
582
+ seedUid: s
583
+ });
584
+ if (!c) {
585
+ if (Ae(a)) continue;
586
+ throw Error(`No relatedItem found for ${e.propertyName}`);
587
+ }
588
+ t = await un(c, t, e, r);
589
+ }
590
+ return t;
591
+ }, dn = 3, fn = new TextEncoder().encode("seed-recovery"), pn = 32, mn = 18446744073709551615n;
592
+ function hn(e, t, n) {
593
+ let r = N.solidityPackedKeccak256([
594
+ "uint256",
595
+ "address",
596
+ "uint64"
597
+ ], [
598
+ BigInt(t),
599
+ e,
600
+ n & mn
601
+ ]);
602
+ return N.getBytes(r);
603
+ }
604
+ function gn(e) {
605
+ if (e.length === 0) return new Uint8Array([0]);
606
+ if (e.length !== pn) throw Error(`ANS-104 target/anchor must be empty or ${pn} bytes, got ${e.length}`);
607
+ let t = /* @__PURE__ */ new Uint8Array(33);
608
+ return t[0] = 1, t.set(e, 1), t;
609
+ }
610
+ function _n(e) {
611
+ return typeof e == "object" && !!e && "privateKey" in e && typeof e.privateKey == "string";
612
+ }
613
+ function vn(e, t, n) {
614
+ let r = e >= 0 ? e << 1 : ~e << 1 | 1, i = n;
615
+ do {
616
+ let e = r & 127;
617
+ r >>>= 7, t[i++] = r ? e | 128 : e;
618
+ } while (r);
619
+ return i - n;
620
+ }
621
+ var yn = (e) => {
622
+ if (!e?.length) return /* @__PURE__ */ new Uint8Array();
623
+ let t = new TextEncoder(), n = /* @__PURE__ */ new Uint8Array(16), r = [], i = (e) => {
624
+ let t = vn(e, n, 0);
625
+ r.push(n.slice(0, t));
626
+ };
627
+ i(e.length);
628
+ for (let n of e) {
629
+ let e = t.encode(n.name), a = t.encode(n.value);
630
+ i(e.length), r.push(e), i(a.length), r.push(a);
631
+ }
632
+ i(0);
633
+ let a = r.reduce((e, t) => e + t.length, 0), o = new Uint8Array(a), s = 0;
634
+ for (let e of r) o.set(e, s), s += e.length;
635
+ return o;
636
+ }, bn = (e) => {
637
+ let t = /* @__PURE__ */ new Uint8Array(8), n = new DataView(t.buffer);
638
+ return n.setUint32(0, e & 4294967295, !0), n.setUint32(4, Math.floor(e / 4294967296), !0), t;
639
+ };
640
+ async function xn(e) {
641
+ return new Uint8Array(await crypto.subtle.digest("SHA-384", e));
642
+ }
643
+ function Sn(e, t) {
644
+ let n = new Uint8Array(e.length + t.length);
645
+ return n.set(e, 0), n.set(t, e.length), n;
646
+ }
647
+ async function Cn(e) {
648
+ let t = new TextEncoder();
649
+ if (Array.isArray(e)) {
650
+ let n = await xn(Sn(t.encode("list"), t.encode(e.length.toString())));
651
+ for (let t of e) {
652
+ let e = await Cn(t);
653
+ n = await xn(Sn(n, e));
654
+ }
655
+ return n;
656
+ }
657
+ return xn(Sn(await xn(Sn(t.encode("blob"), t.encode(e.byteLength.toString()))), await xn(e)));
658
+ }
659
+ async function wn(e, t, n, r, i) {
660
+ let a = new TextEncoder();
661
+ return Cn([
662
+ a.encode("dataitem"),
663
+ a.encode("1"),
664
+ a.encode(dn.toString()),
665
+ e,
666
+ t,
667
+ n,
668
+ r,
669
+ i
670
+ ]);
671
+ }
672
+ function Tn(e, t, n, r, i) {
673
+ let a = yn(t), o = bn(t.length), s = bn(a.length), c = [
674
+ e,
675
+ gn(r),
676
+ gn(i),
677
+ o,
678
+ s,
679
+ a,
680
+ n
681
+ ], l = c.reduce((e, t) => e + t.length, 0), u = new Uint8Array(l), d = 0;
682
+ for (let e of c) u.set(e, d), d += e.length;
683
+ return u;
684
+ }
685
+ async function En(e, t) {
686
+ let n = /* @__PURE__ */ new Uint8Array(2);
687
+ new DataView(n.buffer).setUint16(0, dn, !0);
688
+ let r = 67 + t.length, i = new Uint8Array(r);
689
+ i.set(n, 0), i.set(e, 2), i.set(t, 67);
690
+ let a = await crypto.subtle.digest("SHA-256", new Uint8Array(e));
691
+ return {
692
+ id: Mn(new Uint8Array(a)),
693
+ raw: i
694
+ };
695
+ }
696
+ var Dn = async (e, t, n, r = /* @__PURE__ */ new Uint8Array()) => {
697
+ let i = N.SigningKey.computePublicKey(t.privateKey, !1), a = N.getBytes(i), o = yn(n), s = /* @__PURE__ */ new Uint8Array(), c = await wn(a, s, r, o, e);
698
+ return En(N.getBytes(await t.signMessage(c)), Tn(a, n, e, s, r));
699
+ }, On = async (e, t, n, r = /* @__PURE__ */ new Uint8Array()) => {
700
+ let i = N.hexlify(fn), a = await t.signMessage({ message: { raw: i } }), o = N.hashMessage(fn), s = N.SigningKey.recoverPublicKey(o, a), c = N.getBytes(s), l = yn(n), u = /* @__PURE__ */ new Uint8Array(), d = await wn(c, u, r, l, e), f = N.hexlify(d), p = await t.signMessage({ message: { raw: f } });
701
+ return En(N.getBytes(p), Tn(c, n, e, u, r));
702
+ };
703
+ function kn(e) {
704
+ if (e.length < 133) return null;
705
+ let t = e[132];
706
+ if (t !== 0 && t !== 1) return null;
707
+ let n = t === 1;
708
+ if (n && e.length < 165) return null;
709
+ let r = 132 + (n ? 33 : 1);
710
+ if (e.length < r + 1) return null;
711
+ let i = e[r];
712
+ if (i !== 0 && i !== 1) return null;
713
+ let a = i === 1;
714
+ return a && e.length < r + 33 ? null : r + (a ? 33 : 1);
715
+ }
716
+ function An(e) {
717
+ let t = kn(e);
718
+ if (t == null) return null;
719
+ let n = e[132] === 1, r = n ? e.slice(133, 165) : /* @__PURE__ */ new Uint8Array(), i = 132 + (n ? 33 : 1);
720
+ return {
721
+ rawTarget: r,
722
+ rawAnchor: e[i] === 1 ? e.slice(i + 1, i + 33) : /* @__PURE__ */ new Uint8Array(),
723
+ tagsStart: t
724
+ };
725
+ }
726
+ async function jn(e) {
727
+ let t = An(e);
728
+ if (t == null) return !1;
729
+ let { rawTarget: n, rawAnchor: r, tagsStart: i } = t, a = i + 16;
730
+ if (e.length < a) return !1;
731
+ let o = new DataView(e.buffer, e.byteOffset, e.byteLength);
732
+ if (o.getUint16(0, !0) !== dn) return !1;
733
+ let s = e.slice(2, 67), c = e.slice(67, 132), l = Number(o.getUint32(i + 8, !0) + o.getUint32(i + 12, !0) * 4294967296), u = i + 16 + l;
734
+ if (e.length < u) return !1;
735
+ let d = e.slice(i + 16, u), f = e.slice(u);
736
+ try {
737
+ let e = await wn(c, n, r, d, f), t = N.hashMessage(e), i = N.hexlify(s), a = N.SigningKey.recoverPublicKey(t, i), o = N.getBytes(a);
738
+ return o.length === c.length && o.every((e, t) => e === c[t]);
739
+ } catch {
740
+ return !1;
741
+ }
742
+ }
743
+ var Mn = (e) => {
744
+ let t = "";
745
+ for (let n of e) t += String.fromCharCode(n);
746
+ return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
747
+ }, Nn = L("seedProtocol:createArweaveDataItems");
748
+ async function Pn(e, t, n) {
749
+ let r, i;
750
+ if (t) r = (await t(e)).map((e) => ({
751
+ transaction: { id: e.transaction.id },
752
+ versionId: e.versionId,
753
+ modelName: e.modelName
754
+ }));
755
+ else if (n) {
756
+ let t = [], a = Date.now();
757
+ for (let r = 0; r < e.length; r++) {
758
+ let i = e[r], o = i.tags, s = /* @__PURE__ */ new Uint8Array(8);
759
+ crypto.getRandomValues(s);
760
+ let c = (new DataView(s.buffer).getBigUint64(0, !1) ^ BigInt(r)) & 18446744073709551615n, l;
761
+ if (_n(n)) {
762
+ let e = hn(n.address, a, c);
763
+ l = await Dn(i.data, n, o, e);
764
+ } else {
765
+ let e = w(n) ? n.signer : n, t = hn(e.address, a, c);
766
+ l = await On(i.data, e, o, t);
767
+ }
768
+ if (!await jn(l.raw)) throw Nn("DataItem verification failed: id=%s modelName=%s", l.id, i.itemPropertyName), Error(`DataItem signature verification failed for ${i.itemPropertyName}. The signing key may not match the owner, or the payload may have been modified.`);
769
+ t.push(l);
770
+ }
771
+ i = t, r = t.map((t, n) => ({
772
+ transaction: { id: t.id },
773
+ versionId: e[n]?.versionLocalId,
774
+ modelName: e[n]?.itemPropertyName
775
+ }));
776
+ } else throw Error("@seedprotocol/publish: useArweaveBundler requires signDataItems or dataItemSigner (pass at createPublish or in PublishProvider config)");
777
+ let a = e.map((e) => ({
778
+ itemPropertyName: e.itemPropertyName,
779
+ itemPropertyLocalId: e.itemPropertyLocalId,
780
+ seedLocalId: e.seedLocalId,
781
+ versionLocalId: e.versionLocalId,
782
+ transactionToSign: null
783
+ }));
784
+ return {
785
+ arweaveTransactions: r,
786
+ publishUploads: a,
787
+ signedDataItems: i
788
+ };
789
+ }
790
+ var Fn = I(async ({ input: { context: e } }) => {
791
+ let { item: t } = e;
792
+ t.getPublishUploads || (t = await Wt(t.seedLocalId));
793
+ let n = {};
794
+ e.arweaveUploadTags?.length && (n.arweaveUploadTags = e.arweaveUploadTags);
795
+ let r = e.htmlEmbeddedDeferredHtmlSeedLocalIds;
796
+ r?.length && (n.deferHtmlStorageSeedLocalIds = r);
797
+ let i = await un(t, [], void 0, Object.keys(n).length ? n : void 0), a = T();
798
+ return Pn(i, e.signDataItems ?? a.signDataItems, e.dataItemSigner ?? a.dataItemSigner);
799
+ });
800
+ //#endregion
801
+ //#region src/services/publish/actors/createArweaveDataItemsPhase2.ts
802
+ async function In(e) {
803
+ let { item: t } = e;
804
+ t.getPublishUploads || (t = await Wt(t.seedLocalId));
805
+ let n = {};
806
+ e.arweaveUploadTags?.length && (n.arweaveUploadTags = e.arweaveUploadTags);
807
+ let r = e.htmlEmbeddedDeferredHtmlSeedLocalIds;
808
+ r?.length && (n.onlyHtmlStorageSeedLocalIds = r, n.skipRelationRecursion = !0);
809
+ let i = await un(t, [], void 0, Object.keys(n).length ? n : void 0), a = T(), o = e.signDataItems ?? a.signDataItems, s = e.dataItemSigner ?? a.dataItemSigner;
810
+ return i.length === 0 ? {
811
+ arweaveTransactions: [],
812
+ publishUploads: [],
813
+ signedDataItems: void 0
814
+ } : Pn(i, o, s);
815
+ }
816
+ var Ln = I(async ({ input: { context: e } }) => In(e)), Rn = 8192;
817
+ function zn(e) {
818
+ let t = new Uint8Array(e), n = "";
819
+ for (let e = 0; e < t.length; e += Rn) {
820
+ let r = t.subarray(e, Math.min(e + Rn, t.length));
821
+ n += String.fromCharCode.apply(null, r);
822
+ }
823
+ return btoa(n);
824
+ }
825
+ async function Bn(e) {
826
+ let t = [];
827
+ for (let [n, r] of e.entries()) {
828
+ let e = r;
829
+ if (typeof e == "object" && e && "arrayBuffer" in e) {
830
+ let r = zn(await e.arrayBuffer()), i = e;
831
+ t.push({
832
+ name: n,
833
+ value: r,
834
+ encoding: "base64",
835
+ filename: i.name || void 0
836
+ });
837
+ } else t.push({
838
+ name: n,
839
+ value: String(r)
840
+ });
841
+ }
842
+ return t;
843
+ }
844
+ function Vn(e, t, n) {
845
+ let r = ["Upload server returned ", String(e)], i = t && typeof t == "object" && "message" in t ? String(t.message) : t && typeof t == "object" && "error" in t ? String(t.error) : null;
846
+ return i ? r.push(`: ${i}`) : n && r.push(` (${n})`), r.join("");
847
+ }
848
+ function Hn(e) {
849
+ if (!e) return "Upload server unavailable. Please try again or check your connection.";
850
+ let t = e.toLowerCase();
851
+ return /other side closed|econnreset|socket hang up|connection closed/i.test(t) ? "Upload server closed the connection. It may be busy or the request may be too large—try again." : /etimedout|timeout/i.test(t) ? "Upload request timed out. Please try again." : /enotfound|getaddrinfo|dns/i.test(t) ? "Upload server could not be reached. Check the upload URL and your network." : "Upload failed. Please try again or check the upload server.";
852
+ }
853
+ async function Un(e, t, n) {
854
+ let r = typeof window < "u" ? window.Main : void 0;
855
+ if (r?.uploadArweaveStart) {
856
+ let n = await Bn(t);
857
+ return r.uploadArweaveStart(e, n);
858
+ }
859
+ let i = await fetch(e, {
860
+ method: "POST",
861
+ body: t
862
+ }), a = await i.json().catch(() => ({}));
863
+ return {
864
+ status: i.status,
865
+ body: a
866
+ };
867
+ }
868
+ //#endregion
869
+ //#region src/services/publish/actors/sendReimbursementRequest.ts
870
+ var Wn = I(async ({ input: { context: e, event: t } }) => {
871
+ let { arweaveTransactions: n = [], transactionKeys: r, reimbursementTransactionId: i } = e;
872
+ if (i) return { transactionId: i };
873
+ let a = n.map(({ transaction: e }) => e), o = new FormData();
874
+ for (let e of a) {
875
+ let { data: t, chunks: n, ...r } = e, i = t instanceof Blob ? t : new Blob([t]);
876
+ o.append(`${e.id}-data`, i, `${e.id}-data`);
877
+ let a = new Blob([JSON.stringify(n)], { type: "application/json" });
878
+ o.append(`${e.id}-chunks`, a, `${e.id}-chunks`);
879
+ let s = new Blob([JSON.stringify(r)], { type: "application/json" });
880
+ o.append(`${e.id}-json`, s, `${e.id}-json`);
881
+ }
882
+ let { uploadApiBaseUrl: s } = T(), { status: c, body: l, message: u } = await Un(`${s}/api/upload/arweave/start`, o, s);
883
+ if (c >= 300 || c < 200) {
884
+ let e = c === 0 ? u : null;
885
+ e && console.error("[upload]", e);
886
+ let t = c === 0 ? Hn(e) : Vn(c, l, r);
887
+ throw Error(t);
888
+ }
889
+ return l;
890
+ }), Gn = I(async ({ input: { context: e, event: t } }) => {
891
+ let { requestResponse: n, reimbursementTransactionId: r } = e;
892
+ if (!n) throw Error("No request response");
893
+ if (!r) throw Error("No reimbursement transaction id");
894
+ let i = z();
895
+ await new Promise((e, t) => {
896
+ let n = setInterval(async () => {
897
+ let t;
898
+ try {
899
+ t = await i.transactions.getStatus(r);
900
+ } catch {
901
+ return;
902
+ }
903
+ t && t.confirmed && (clearInterval(n), e());
904
+ }, 5e3);
905
+ });
906
+ }), G = L("seedProtocol:services:publish:actors");
907
+ function Kn(e) {
908
+ if (e instanceof Uint8Array) return e;
909
+ if (e instanceof ArrayBuffer) return new Uint8Array(e);
910
+ throw Error("Transaction data must be Uint8Array or ArrayBuffer for upload resume");
911
+ }
912
+ var qn = F(({ sendBack: e, input: t }) => {
913
+ let n = t.context, r = (n.arweaveTransactions ?? []).map(({ transaction: e }) => e), i = z(), a = n.uploaderState && typeof n.currentTransactionIndex == "number", o = a ? n.currentTransactionIndex : 0;
914
+ (async () => {
915
+ let t = r.length;
916
+ for (let s = o; s < t; s++) {
917
+ let c = r[s];
918
+ if (!c) continue;
919
+ let l = i.transactions.fromRaw(c);
920
+ if (!await i.transactions.verify(l)) throw Error("Transaction verification failed");
921
+ let u, d = n.uploaderState;
922
+ if (a && s === o && d) {
923
+ let e = l.data, t = e instanceof Uint8Array ? e : Kn(e);
924
+ u = await i.transactions.getUploader(d, t);
925
+ } else u = await i.transactions.getUploader(l, l.data);
926
+ for (; !u.isComplete;) {
927
+ G("uploading chunk"), G(`uploader.pctComplete: ${u.pctComplete}`), G(`uploader.uploadedChunks: ${u.uploadedChunks}`), G(`uploader.totalChunks: ${u.totalChunks}`), G(u.lastResponseError), G(u.lastResponseStatus);
928
+ try {
929
+ await u.uploadChunk(), e({
930
+ type: "updatePercentage",
931
+ completionPercentage: Math.trunc((s + u.pctComplete / 100) / t * 100),
932
+ uploaderState: u.toJSON(),
933
+ currentTransactionIndex: s
934
+ }), G(`${u.pctComplete}% complete, ${u.uploadedChunks}/${u.totalChunks}`);
935
+ } catch (e) {
936
+ G(e);
937
+ }
938
+ }
939
+ }
940
+ return "done";
941
+ })().then((t) => {
942
+ e({
943
+ type: "uploadComplete",
944
+ result: t
945
+ });
946
+ }).catch((t) => {
947
+ e({
948
+ type: "uploadError",
949
+ error: t
950
+ });
951
+ });
952
+ }), Jn = 12e4, Yn = Function("s", "return import(s)"), Xn = null, Zn = async () => {
953
+ if (Xn) return Xn;
954
+ if (typeof window < "u") return null;
955
+ try {
956
+ let e = await Yn(`node:${["fs", "promises"].join("/")}`);
957
+ return Xn = {
958
+ readFile: e.readFile,
959
+ stat: e.stat
960
+ }, Xn;
961
+ } catch {
962
+ return null;
963
+ }
964
+ }, Qn = F(({ sendBack: e, input: { context: t } }) => {
965
+ let { signedDataItems: n } = t, { uploadApiBaseUrl: r, useArweaveBundler: i } = T();
966
+ if (!i || !r) {
967
+ e({
968
+ type: "uploadError",
969
+ error: /* @__PURE__ */ Error("Arweave bundler not configured. Set useArweaveBundler and uploadApiBaseUrl.")
970
+ });
971
+ return;
972
+ }
973
+ let a = `${r.replace(/\/$/, "")}/api/upload/arweave/batch`;
974
+ if (!n || n.length === 0) {
975
+ e({
976
+ type: "uploadComplete",
977
+ result: "done"
978
+ });
979
+ return;
980
+ }
981
+ (async () => {
982
+ let e = n, t = e.length, r = Array(t).fill(null), i = async (e, t) => {
983
+ let n = e;
984
+ if (n.raw != null && (n.raw instanceof Uint8Array || Buffer.isBuffer(n.raw))) return n.raw.byteLength;
985
+ if (typeof n.getRaw == "function") {
986
+ let e = n.getRaw(), i = e instanceof Promise ? await e : e, a = Buffer.isBuffer(i) ? i : Buffer.from(i);
987
+ return r[t] = a, a.length;
988
+ }
989
+ if (n.filename != null) {
990
+ let e = await Zn();
991
+ if (!e) throw Error("DataItem.filename requires Node.js fs access. In browser runtime, provide DataItem.raw or DataItem.getRaw().");
992
+ return (await e.stat(n.filename)).size;
993
+ }
994
+ throw Error("Cannot get raw bytes from DataItem");
995
+ }, o = 4, s = [];
996
+ for (let n = 0; n < t; n++) {
997
+ let t = await i(e[n], n);
998
+ s.push(t), o += 4 + t;
999
+ }
1000
+ let c = Buffer.alloc(o), l = 0;
1001
+ c.writeUInt32BE(t, l), l += 4;
1002
+ for (let n = 0; n < t; n++) {
1003
+ let t = s[n], i = r[n];
1004
+ if (i) {
1005
+ c.writeUInt32BE(t, l), l += 4, i.copy(c, l), l += t;
1006
+ continue;
1007
+ }
1008
+ let a = e[n];
1009
+ if (a.raw != null && (a.raw instanceof Uint8Array || Buffer.isBuffer(a.raw))) {
1010
+ c.writeUInt32BE(t, l), l += 4, c.set(a.raw, l), l += t;
1011
+ continue;
1012
+ }
1013
+ if (a.filename != null) {
1014
+ let e = await Zn();
1015
+ if (!e) throw Error("DataItem.filename requires Node.js fs access. In browser runtime, provide DataItem.raw or DataItem.getRaw().");
1016
+ let t = await e.readFile(a.filename);
1017
+ c.writeUInt32BE(t.length, l), l += 4, t.copy(c, l), l += t.length;
1018
+ continue;
1019
+ }
1020
+ throw Error("Cannot get raw bytes from DataItem");
1021
+ }
1022
+ let u = new AbortController(), d = setTimeout(() => u.abort(), Jn), f;
1023
+ try {
1024
+ f = await fetch(a, {
1025
+ method: "POST",
1026
+ headers: { "Content-Type": "application/octet-stream" },
1027
+ body: c,
1028
+ signal: u.signal
1029
+ });
1030
+ } catch (e) {
1031
+ throw clearTimeout(d), e instanceof Error && e.name === "AbortError" ? Error(`Arweave batch upload timed out after ${Jn / 1e3}s (upload API did not respond). Check uploadApiBaseUrl and network.`) : e;
1032
+ }
1033
+ if (clearTimeout(d), !f.ok) throw Error(`Batch upload failed: ${f.status}`);
1034
+ let p = await f.json().catch(() => ({})), m = typeof p.failed == "number" ? p.failed : 0;
1035
+ if (m > 0) {
1036
+ let e = p.total ?? "?", t = p.succeeded ?? 0;
1037
+ throw Error(`Arweave batch upload failed: ${m} of ${e} item(s) failed (${t} succeeded)`);
1038
+ }
1039
+ })().then(() => e({
1040
+ type: "uploadComplete",
1041
+ result: "done"
1042
+ })).catch((t) => e({
1043
+ type: "uploadError",
1044
+ error: t
1045
+ }));
1046
+ }), $n = /* @__PURE__ */ e({
1047
+ ExternalWalletsForDeploy: () => pr,
1048
+ appMetadata: () => gr,
1049
+ deployManagedAccountViaFactory: () => hr,
1050
+ deploySmartWalletContract: () => mr,
1051
+ getConnectedAccount: () => vr,
1052
+ getConnectedManagedAccountAddress: () => _r,
1053
+ getConnectedModularAccount: () => yr,
1054
+ getManagedAccountWallet: () => xr,
1055
+ getModularAccountWallet: () => Cr,
1056
+ getSharedPublishInAppWalletStorage: () => rr,
1057
+ getSmartWalletAddressForAdmin: () => lr,
1058
+ getWalletsForConnectButton: () => Tr,
1059
+ isSmartWalletDeployed: () => ur,
1060
+ pollSmartWalletDeployed: () => dr,
1061
+ resolveSmartWalletForPublish: () => fr,
1062
+ syncPublishInAppAuthToken: () => ir,
1063
+ useActiveSmartWalletContract: () => cr,
1064
+ useLocalWalletAccount: () => sr,
1065
+ wallets: () => or
1066
+ }), er = L("permaPress:helpers:thirdweb"), tr = "seedProtocol:inAppPublish:", nr = null;
1067
+ function rr() {
1068
+ return nr ||= {
1069
+ getItem: async (e) => typeof window > "u" ? null : localStorage.getItem(tr + e),
1070
+ setItem: async (e, t) => {
1071
+ typeof window > "u" || localStorage.setItem(tr + e, t);
1072
+ },
1073
+ removeItem: async (e) => {
1074
+ typeof window > "u" || localStorage.removeItem(tr + e);
1075
+ }
1076
+ }, nr;
1077
+ }
1078
+ function ir() {
1079
+ if (typeof window > "u") return {
1080
+ syncedBareToPrefixed: !1,
1081
+ syncedPrefixedToBare: !1
1082
+ };
1083
+ let { thirdwebClientId: e } = T();
1084
+ if (!e) return {
1085
+ syncedBareToPrefixed: !1,
1086
+ syncedPrefixedToBare: !1
1087
+ };
1088
+ try {
1089
+ let t = `walletToken-${e}`, n = `${tr}${t}`, r = localStorage.getItem(t), i = localStorage.getItem(n), a = !1, o = !1;
1090
+ return r && !i && (localStorage.setItem(n, r), a = !0), i && !r && (localStorage.setItem(t, i), o = !0), i && r && r !== i && (localStorage.setItem(t, i), o = !0), {
1091
+ syncedBareToPrefixed: a,
1092
+ syncedPrefixedToBare: o
1093
+ };
1094
+ } catch {
1095
+ return {
1096
+ syncedBareToPrefixed: !1,
1097
+ syncedPrefixedToBare: !1
1098
+ };
1099
+ }
1100
+ }
1101
+ async function ar(e = M) {
1102
+ ir();
1103
+ let t = xr();
1104
+ return await t.autoConnect({
1105
+ client: D(),
1106
+ chain: e
1107
+ }), t;
1108
+ }
1109
+ var or = [ht("io.metamask")], sr = () => {
1110
+ let [e, t] = rt(null);
1111
+ return ht("io.metamask"), nt(!1), tt(() => {}, []), e;
1112
+ }, cr = () => {
1113
+ let e = _t(), [t, n] = rt(null);
1114
+ return tt(() => {
1115
+ e && e.address && n(Ye({
1116
+ client: D(),
1117
+ chain: M,
1118
+ address: e.address
1119
+ }));
1120
+ }, [e]), t;
1121
+ };
1122
+ async function lr(e, t = "0x") {
1123
+ return r(e, t);
1124
+ }
1125
+ async function ur(e) {
1126
+ return u(e);
1127
+ }
1128
+ async function dr(e, t, n) {
1129
+ return se(e, t, n);
1130
+ }
1131
+ async function fr(e) {
1132
+ if (!e) return { needsDeploy: !0 };
1133
+ if (await ur(e.address)) return {
1134
+ address: e.address,
1135
+ account: e
1136
+ };
1137
+ let t = await lr(e.address);
1138
+ return await ur(t) ? {
1139
+ address: t,
1140
+ account: e
1141
+ } : { needsDeploy: !0 };
1142
+ }
1143
+ var pr = [ht("io.metamask"), ht("me.rainbow")], mr = async (e) => {
1144
+ let t = Ye({
1145
+ client: D(),
1146
+ chain: M,
1147
+ address: e.address
1148
+ }), n = await Je({
1149
+ smartAccount: e,
1150
+ chain: M,
1151
+ client: D(),
1152
+ accountContract: t
1153
+ });
1154
+ return er("deploySmartAccount result:", n), n;
1155
+ };
1156
+ async function hr(e) {
1157
+ let { asThirdwebPublishWallet: t } = await import("./config-CPBd5C_b.js").then((e) => e.c), n = t(e.signingAccount), r = ie(e.adminAddress, e.data ?? "0x");
1158
+ await n.txSender.sendTransaction(r);
1159
+ }
1160
+ var gr = {
1161
+ name: "Seed Protocol",
1162
+ description: "Seed Protocol",
1163
+ url: "https://seedprotocol.io"
1164
+ };
1165
+ async function _r(e = M) {
1166
+ let t = (await ar(e)).getAccount();
1167
+ if (!t) throw Error("Failed to get managed account");
1168
+ return t.address;
1169
+ }
1170
+ async function vr() {
1171
+ try {
1172
+ let e = Cr();
1173
+ return await e.autoConnect({
1174
+ client: D(),
1175
+ chain: M
1176
+ }), e.getAccount() ?? null;
1177
+ } catch {
1178
+ return null;
1179
+ }
1180
+ }
1181
+ async function yr() {
1182
+ return vr();
1183
+ }
1184
+ var br = null, xr = () => (br ||= gt({
1185
+ storage: rr(),
1186
+ auth: { options: [
1187
+ "farcaster",
1188
+ "email",
1189
+ "passkey",
1190
+ "phone"
1191
+ ] },
1192
+ executionMode: {
1193
+ mode: "EIP4337",
1194
+ smartAccount: {
1195
+ chain: M,
1196
+ factoryAddress: S,
1197
+ gasless: !0
1198
+ }
1199
+ }
1200
+ }), br), Sr = null, Cr = () => (Sr ||= gt({
1201
+ storage: rr(),
1202
+ auth: { options: [
1203
+ "farcaster",
1204
+ "email",
1205
+ "passkey",
1206
+ "phone"
1207
+ ] },
1208
+ executionMode: {
1209
+ mode: "EIP7702",
1210
+ sponsorGas: !0
1211
+ }
1212
+ }), Sr), wr = null, Tr = () => (wr ||= T().useModularExecutor ? [Cr()] : [xr()], wr), Er = "The executor module could not be installed on your publishing account on Optimism Sepolia. Reconnect and try again, or contact support if this persists.";
1213
+ async function Dr(e, t, n) {
1214
+ let { modularAccountModuleContract: r } = n;
1215
+ if (!r) return;
1216
+ let i = Ye({
1217
+ client: D(),
1218
+ chain: M,
1219
+ address: e
1220
+ });
1221
+ if (await u(e)) try {
1222
+ let e = await vt({ contract: i }), n = r.toLowerCase();
1223
+ if (e.some((e) => e.implementation?.toLowerCase() === n)) return;
1224
+ let a = yt({
1225
+ contract: i,
1226
+ moduleContract: r,
1227
+ data: Ge([{ type: "address" }], [le])
1228
+ }), o = await Xe({
1229
+ transaction: a,
1230
+ account: t
1231
+ });
1232
+ await l(o.transactionHash);
1233
+ } catch (t) {
1234
+ if (me(t)) return;
1235
+ throw new E(Er, "EXECUTOR_MODULE_NOT_INSTALLED", e, t);
1236
+ }
1237
+ }
1238
+ //#endregion
1239
+ //#region src/helpers/ensureManagedAccountReady.ts
1240
+ var Or = "Could not connect the managed publishing account on Optimism Sepolia. Reconnect with the same sign-in method and try again.", kr = "Your publishing smart account is not deployed on Optimism Sepolia yet. Complete wallet setup, enable autoDeployManagedAccount in config if appropriate, then try again.", Ar = "The managed account could not be confirmed on Optimism Sepolia after deployment. Wait a moment and retry, or check your network connection.", jr = "Automatic deployment of the managed publishing account failed on Optimism Sepolia. Retry or deploy the account through your wallet provider.";
1241
+ async function Mr() {
1242
+ let { useModularExecutor: e } = T();
1243
+ if (!e) return { kind: "skip" };
1244
+ let t;
1245
+ try {
1246
+ t = await _r(M);
1247
+ } catch (e) {
1248
+ return {
1249
+ kind: "unavailable",
1250
+ cause: e
1251
+ };
1252
+ }
1253
+ return await ur(t) ? {
1254
+ kind: "ready",
1255
+ managedAddress: t
1256
+ } : {
1257
+ kind: "not_deployed",
1258
+ managedAddress: t
1259
+ };
1260
+ }
1261
+ async function Nr() {
1262
+ ir();
1263
+ let e = xr();
1264
+ await e.autoConnect({
1265
+ client: D(),
1266
+ chain: M
1267
+ });
1268
+ let t = e.getAccount();
1269
+ if (!t) throw new E(Or, "MANAGED_ACCOUNT_UNAVAILABLE");
1270
+ return t;
1271
+ }
1272
+ var Pr = 9e4;
1273
+ async function Fr(e) {
1274
+ let t;
1275
+ try {
1276
+ await Promise.race([mr(e), new Promise((e, n) => {
1277
+ t = setTimeout(() => n(/* @__PURE__ */ Error(`Managed account deploy timed out after ${Pr / 1e3}s`)), Pr);
1278
+ })]);
1279
+ } finally {
1280
+ t != null && clearTimeout(t);
1281
+ }
1282
+ }
1283
+ async function Ir(e) {
1284
+ let t = T(), n = await Nr(), { fromThirdwebAccount: r } = await import("./config-CPBd5C_b.js").then((e) => e.c), i = {
1285
+ managedAddress: e,
1286
+ managedSigningAccount: r(n)
1287
+ };
1288
+ try {
1289
+ if (t.deployManagedAccount) await t.deployManagedAccount(i);
1290
+ else {
1291
+ let e = await yr();
1292
+ if (e) {
1293
+ let t = Cr();
1294
+ await t.autoConnect({
1295
+ client: D(),
1296
+ chain: M
1297
+ }), await hr({
1298
+ adminAddress: t.getAdminAccount?.()?.address ?? e.address,
1299
+ signingAccount: e
1300
+ });
1301
+ } else await Fr(n);
1302
+ }
1303
+ } catch (t) {
1304
+ if (await dr(e, /UserOp|user operation/i.test(he(t)) ? 15 : 5)) return;
1305
+ throw new E(jr, "MANAGED_ACCOUNT_NOT_DEPLOYED", e, t);
1306
+ }
1307
+ if (!await dr(e)) throw new E(Ar, "MANAGED_ACCOUNT_NOT_DEPLOYED", e);
1308
+ }
1309
+ async function Lr() {
1310
+ let e = T();
1311
+ if (!e.useModularExecutor) throw Error("runModularExecutorPublishPrep: useModularExecutor is false");
1312
+ let t = await Mr();
1313
+ if (t.kind === "unavailable") return {
1314
+ ok: !1,
1315
+ error: new E(Or, "MANAGED_ACCOUNT_UNAVAILABLE", void 0, t.cause)
1316
+ };
1317
+ if (t.kind === "not_deployed") {
1318
+ if (e.autoDeployManagedAccount) {
1319
+ try {
1320
+ await Ir(t.managedAddress);
1321
+ } catch (e) {
1322
+ return {
1323
+ ok: !1,
1324
+ error: pe(e) ? e : new E(jr, "MANAGED_ACCOUNT_NOT_DEPLOYED", t.managedAddress, e)
1325
+ };
1326
+ }
1327
+ if (t = await Mr(), t.kind !== "ready") return {
1328
+ ok: !1,
1329
+ error: new E(Ar, "MANAGED_ACCOUNT_NOT_DEPLOYED", t.kind === "not_deployed" ? t.managedAddress : void 0)
1330
+ };
1331
+ } else return {
1332
+ ok: !1,
1333
+ error: new E(kr, "MANAGED_ACCOUNT_NOT_DEPLOYED", t.managedAddress)
1334
+ };
1335
+ }
1336
+ if (t.kind === "ready") {
1337
+ if (e.modularAccountModuleContract) try {
1338
+ let n = await Nr();
1339
+ await Dr(t.managedAddress, n, e);
1340
+ } catch (e) {
1341
+ return pe(e) ? {
1342
+ ok: !1,
1343
+ error: e
1344
+ } : {
1345
+ ok: !1,
1346
+ error: new E("Executor module setup failed on Optimism Sepolia.", "EXECUTOR_MODULE_NOT_INSTALLED", t.managedAddress, e)
1347
+ };
1348
+ }
1349
+ return {
1350
+ ok: !0,
1351
+ managedAddress: t.managedAddress
1352
+ };
1353
+ }
1354
+ throw Error("runModularExecutorPublishPrep: unexpected readiness state");
1355
+ }
1356
+ //#endregion
1357
+ //#region src/helpers/executorModuleReadiness.ts
1358
+ var Rr = /* @__PURE__ */ e({
1359
+ assertExecutorModuleReadyForAccount: () => Gr,
1360
+ simulateCallFromAccount: () => Yr
1361
+ }), zr = "This ManagedAccount is a legacy Router account. The Seed executor module cannot act for it, so publish automation is not available for this account yet.", Br = "The Seed executor module is not initialized for this ManagedAccount, so automation session keys cannot publish or revoke through it.", Vr = "The Seed executor module is configured with a different EAS contract for this ManagedAccount than publish config. Automation session keys cannot change it.", Hr = "Could not read the Seed executor module state for this ManagedAccount.";
1362
+ function Ur() {
1363
+ let e = T().modularAccountModuleContract?.trim();
1364
+ if (!e || !/^0x[0-9a-fA-F]{40}$/.test(e)) throw Error("@seedprotocol/publish: publish automation requires PublishConfig.modularAccountModuleContract (executor module).");
1365
+ return e;
1366
+ }
1367
+ async function Wr(e) {
1368
+ try {
1369
+ return await te(e), !0;
1370
+ } catch {
1371
+ return !1;
1372
+ }
1373
+ }
1374
+ async function Gr(e) {
1375
+ let t = Ur(), n = e, r, i;
1376
+ try {
1377
+ r = await fe(t, n), i = r ? await g(t, n) : qe;
1378
+ } catch (t) {
1379
+ throw new E(Hr, "AUTOMATION_UNSUPPORTED_ACCOUNT", e, t);
1380
+ }
1381
+ if (!r) {
1382
+ let t = await Wr(n) ? zr : Br;
1383
+ throw new E(t, "AUTOMATION_UNSUPPORTED_ACCOUNT", e);
1384
+ }
1385
+ let a = T().easContractAddress?.toLowerCase();
1386
+ if (a && i.toLowerCase() !== a) throw new E(Vr, "AUTOMATION_UNSUPPORTED_ACCOUNT", e);
1387
+ }
1388
+ function Kr(e) {
1389
+ if (e instanceof He) return e.walk((e) => {
1390
+ let t = e.data;
1391
+ return typeof t == "string" && t.startsWith("0x") && t.length > 2;
1392
+ })?.data;
1393
+ }
1394
+ function qr(e) {
1395
+ if (Kr(e)) return !0;
1396
+ let t = e instanceof He ? `${e.shortMessage} ${e.details}` : String(e);
1397
+ return /revert/i.test(t);
1398
+ }
1399
+ function Jr(e) {
1400
+ if (!e) return "reverted with no data. The target likely has no matching function (for example, the executor module has no multiRevoke) or the account cannot run executor calls";
1401
+ try {
1402
+ let t = We({
1403
+ abi: [...h, ...re],
1404
+ data: e
1405
+ }), n = t.args?.length ? `(${t.args.map(String).join(", ")})` : "";
1406
+ return `reverted with ${t.errorName}${n}`;
1407
+ } catch {
1408
+ return `reverted with data ${e}`;
1409
+ }
1410
+ }
1411
+ async function Yr(e) {
1412
+ let { managedAddress: t, tx: n, action: r } = e;
1413
+ try {
1414
+ await s().call({
1415
+ account: t,
1416
+ to: n.to,
1417
+ data: n.data,
1418
+ value: n.value
1419
+ });
1420
+ } catch (e) {
1421
+ let n = qr(e) ? Jr(Kr(e)) : "could not be simulated";
1422
+ throw new E(`Simulated ${r} from ${t} ${n}; nothing was sent.`, "AUTOMATION_PREFLIGHT_FAILED", t, e);
1423
+ }
1424
+ }
1425
+ //#endregion
1426
+ //#region src/helpers/resolvePublishWallet.ts
1427
+ function Xr(e) {
1428
+ if (w(e.wallet)) return e.wallet;
1429
+ if (w(e.account)) return e.account;
1430
+ let t = de();
1431
+ if (t) return t;
1432
+ throw Error("@seedprotocol/publish: no PublishWallet available. Pass fromEthersWallet / fromEip1193Provider / fromThirdwebAccount, or call setPublishWallet / useSeedWallet.");
1433
+ }
1434
+ //#endregion
1435
+ //#region src/services/publish/actors/persistSeedUid.ts
1436
+ var Zr = L("seedProtocol:services:publish:actors:persistSeedUid"), Qr = "0x" + "0".repeat(64), $r = 15e3;
1437
+ function ei(e, t) {
1438
+ let n = e.seedLocalId, r = n ? t.find((e) => e?.localId === n) : void 0, i = r?.seedUid && r.seedUid !== Qr ? r.seedUid : t[0]?.seedUid;
1439
+ i && i !== Qr && (e.seedUid = i);
1440
+ }
1441
+ async function ti(e, t, n) {
1442
+ let r = e.persistSeedUid;
1443
+ if (typeof r != "function") return;
1444
+ let i = new Promise((e, t) => setTimeout(() => t(/* @__PURE__ */ Error("persistSeedUid timed out")), $r));
1445
+ try {
1446
+ await Promise.race([r.call(e, t, n), i]);
1447
+ } catch (e) {
1448
+ Zr("persistSeedUid failed (attestations already on-chain):", e);
1449
+ }
1450
+ }
1451
+ //#endregion
1452
+ //#region src/services/publish/helpers/verifyArweaveTransactionsExist.ts
1453
+ async function ni(e) {
1454
+ if (e.length === 0) return;
1455
+ let { arweaveUploadVerificationBaseUrl: t } = T(), n = await Promise.all(e.map((e) => De(t, e)));
1456
+ for (let t = 0; t < e.length; t++) {
1457
+ let r = e[t], i = n[t];
1458
+ if (i) {
1459
+ if (i.status === 404) throw Error(`Arweave transaction ${r} not found. Upload may have failed. Delete this publish record and try again.`);
1460
+ if (i.status !== 200) {
1461
+ let e = i.status === 504 ? "request timed out (upload service did not respond in time)" : `status: ${i.status}`;
1462
+ throw Error(`Arweave transaction ${r} is not yet available from the upload service (${e}). Wait and retry.`);
1463
+ }
1464
+ }
1465
+ }
1466
+ }
1467
+ //#endregion
1468
+ //#region src/services/publish/actors/seedUidHelpers.ts
1469
+ function K(e) {
1470
+ return e == null || e === "" ? W : ("0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(64, "0").slice(-64)).toLowerCase();
1471
+ }
1472
+ function ri(e, n, r) {
1473
+ if (!n || !e.logs?.length) return;
1474
+ let i = K(n);
1475
+ if (i === W) return;
1476
+ let a = r ? b : t;
1477
+ try {
1478
+ let t = Ke({
1479
+ abi: a,
1480
+ eventName: "CreatedAttestation",
1481
+ logs: e.logs,
1482
+ strict: !1
1483
+ });
1484
+ for (let e of t) {
1485
+ let t = e.args?.result;
1486
+ if (t?.attestationUid && K(t.schemaUid) === i) {
1487
+ let e = t.attestationUid;
1488
+ return e && K(e) !== W ? e : void 0;
1489
+ }
1490
+ }
1491
+ } catch {}
1492
+ }
1493
+ function ii(e, n, r, i) {
1494
+ let a = n.toLowerCase(), o = e.logs?.filter((e) => e.address && e.address.toLowerCase() === a);
1495
+ if (!o?.length) return {};
1496
+ try {
1497
+ if (i) {
1498
+ let e = Ke({
1499
+ abi: b,
1500
+ eventName: "SeedPublished",
1501
+ logs: o,
1502
+ strict: !1
1503
+ })[0];
1504
+ if (!e) return {};
1505
+ let t = e.args;
1506
+ return {
1507
+ seedUid: t?.seedUid && K(t.seedUid) !== W ? t.seedUid : void 0,
1508
+ versionUid: t?.versionUid && K(t.versionUid) !== W ? t.versionUid : void 0
1509
+ };
1510
+ }
1511
+ let e = Ke({
1512
+ abi: t,
1513
+ eventName: "SeedPublished",
1514
+ logs: o,
1515
+ strict: !1
1516
+ })[0];
1517
+ if (!e) return {};
1518
+ let n = e.args?.returnedDataFromEAS;
1519
+ if (!n || n === "0x") return {};
1520
+ let a = Ue([{ type: "bytes32[]" }], n)[0];
1521
+ if (!a?.length) return {};
1522
+ let s = r, c = a[s], l = a[s + 1];
1523
+ return {
1524
+ seedUid: c && c !== W ? c : a.length === 1 && a[0] && a[0] !== W ? a[0] : void 0,
1525
+ versionUid: l && l !== W ? l : void 0
1526
+ };
1527
+ } catch {
1528
+ return {};
1529
+ }
1530
+ }
1531
+ function ai(e, t, n, r) {
1532
+ return ii(e, t, n, r).seedUid;
1533
+ }
1534
+ function oi(e, n, r) {
1535
+ if (!n || !e.logs?.length) return;
1536
+ let i = K(n);
1537
+ if (i === W) return;
1538
+ let a = r ? b : t;
1539
+ try {
1540
+ let t = Ke({
1541
+ abi: a,
1542
+ eventName: "CreatedAttestation",
1543
+ logs: e.logs,
1544
+ strict: !1
1545
+ });
1546
+ for (let e of t) {
1547
+ let t = e.args?.result;
1548
+ if (t?.attestationUid && K(t.schemaUid) === i) {
1549
+ let e = t.attestationUid;
1550
+ return e && K(e) !== W ? e : void 0;
1551
+ }
1552
+ }
1553
+ } catch {}
1554
+ }
1555
+ function si(e, n) {
1556
+ if (!e.logs?.length) return [];
1557
+ let r = n ? b : t;
1558
+ try {
1559
+ let t = Ke({
1560
+ abi: r,
1561
+ eventName: "CreatedAttestation",
1562
+ logs: e.logs,
1563
+ strict: !1
1564
+ }), n = [];
1565
+ for (let e of t) {
1566
+ let t = e.args?.result;
1567
+ if (!t?.attestationUid) continue;
1568
+ let r = t.attestationUid;
1569
+ if (!r || K(r) === W) continue;
1570
+ let i = t.schemaUid;
1571
+ i && n.push({
1572
+ schemaUid: i,
1573
+ attestationUid: r
1574
+ });
1575
+ }
1576
+ return n;
1577
+ } catch {
1578
+ return [];
1579
+ }
1580
+ }
1581
+ function ci(e, n) {
1582
+ let r = n.toLowerCase(), i = e.logs?.filter((e) => e.address && e.address.toLowerCase() === r);
1583
+ if (!i?.length) return [];
1584
+ try {
1585
+ let e = Ke({
1586
+ abi: t,
1587
+ eventName: "SeedPublished",
1588
+ logs: i,
1589
+ strict: !1
1590
+ })[0];
1591
+ if (!e) return [];
1592
+ let n = e.args?.returnedDataFromEAS;
1593
+ return !n || n === "0x" ? [] : Ue([{ type: "bytes32[]" }], n)[0] ?? [];
1594
+ } catch {
1595
+ return [];
1596
+ }
1597
+ }
1598
+ function li(e, t, n) {
1599
+ if (!n.length) return [];
1600
+ let r = ci(e, t), i = n.length;
1601
+ if (r.length < i) return [];
1602
+ let a = [];
1603
+ for (let e = 0; e < i; e++) {
1604
+ let t = r[e], i = n[e]?.schema;
1605
+ t && K(t) !== W && i && a.push({
1606
+ schemaUid: i,
1607
+ attestationUid: t
1608
+ });
1609
+ }
1610
+ return a;
1611
+ }
1612
+ function ui(e) {
1613
+ let t = si(e.receipt, e.useModularExecutor);
1614
+ if (t.length) return t;
1615
+ let n = v(e.receipt, e.easContractAddress);
1616
+ return n.length ? n.map((e) => ({
1617
+ schemaUid: e.schemaUid,
1618
+ attestationUid: e.uid
1619
+ })) : e.useModularExecutor ? [] : li(e.receipt, e.contractAddressForEvents, e.listOfAttestations ?? []);
1620
+ }
1621
+ //#endregion
1622
+ //#region src/services/publish/helpers/receiptAttestationMs.ts
1623
+ async function q(e) {
1624
+ let t = e?.blockNumber;
1625
+ return t == null ? Date.now() : await y(t) ?? Date.now();
1626
+ }
1627
+ //#endregion
1628
+ //#region src/services/publish/actors/publishRequestNormalize.ts
1629
+ var di = 64, J = (e) => {
1630
+ if (e == null) return "0x" + "0".repeat(di);
1631
+ if (typeof e == "string") return "0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(di, "0").slice(-64);
1632
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
1633
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e);
1634
+ return "0x" + Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("").padStart(di, "0").slice(-64);
1635
+ }
1636
+ return "0x" + "0".repeat(di);
1637
+ }, fi = (e) => {
1638
+ if (e == null || typeof e == "string" && (e === "" || e === "0x")) return "0x";
1639
+ if (typeof e == "string") {
1640
+ let t = (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0");
1641
+ return "0x" + (t.length % 2 == 1 ? "0" + t : t);
1642
+ }
1643
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
1644
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e);
1645
+ return "0x" + Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
1646
+ }
1647
+ return "0x";
1648
+ };
1649
+ function pi(e) {
1650
+ let t = new Set(e.map((e) => e?.localId).filter((e) => !!e));
1651
+ return e.some((e) => (e?.listOfAttestations ?? []).some((e) => {
1652
+ let n = e;
1653
+ return n._unresolvedValue && t.has(n._unresolvedValue) ? !0 : Array.isArray(n._rawListIdsForResolve) ? n._rawListIdsForResolve.some((e) => e && t.has(String(e).trim())) : !1;
1654
+ }));
1655
+ }
1656
+ function mi(e, t) {
1657
+ return (e ?? []).filter((e) => e.publishLocalId && t.has(e.publishLocalId));
1658
+ }
1659
+ var hi = {
1660
+ recipient: ct,
1661
+ expirationTime: BigInt(0),
1662
+ revocable: !0,
1663
+ refUID: W,
1664
+ data: W,
1665
+ value: BigInt(0)
1666
+ };
1667
+ function gi(e) {
1668
+ let t = (e?.listOfAttestations ?? []).map((e) => {
1669
+ let t = Array.isArray(e?.data) ? e.data : [];
1670
+ return {
1671
+ schema: J(e?.schema),
1672
+ data: t.map((e) => ({
1673
+ ...e,
1674
+ refUID: J(e?.refUID),
1675
+ data: fi(e?.data),
1676
+ expirationTime: e?.expirationTime == null ? BigInt(0) : BigInt(e.expirationTime),
1677
+ value: e?.value == null ? BigInt(0) : BigInt(e.value)
1678
+ })),
1679
+ ...typeof e?._propertyName == "string" && e._propertyName !== "" ? { _propertyName: e._propertyName } : {},
1680
+ ...typeof e?._propertyNameForSchema == "string" && e._propertyNameForSchema !== "" ? { _propertyNameForSchema: e._propertyNameForSchema } : {}
1681
+ };
1682
+ }), n = (e?.propertiesToUpdate ?? []).map((e) => ({
1683
+ ...e,
1684
+ propertySchemaUid: J(e?.propertySchemaUid)
1685
+ }));
1686
+ return {
1687
+ ...e,
1688
+ seedUid: J(e?.seedUid),
1689
+ seedSchemaUid: J(e?.seedSchemaUid),
1690
+ versionUid: J(e?.versionUid),
1691
+ versionSchemaUid: J(e?.versionSchemaUid),
1692
+ listOfAttestations: t,
1693
+ propertiesToUpdate: n
1694
+ };
1695
+ }
1696
+ function _i(e, t) {
1697
+ for (let n of e) for (let e of n?.propertiesToUpdate ?? []) {
1698
+ let n = e?.publishLocalId, r = J(e?.propertySchemaUid);
1699
+ if (!n || !r) continue;
1700
+ let i = t.get(n);
1701
+ if (!i?.listOfAttestations) continue;
1702
+ let a = i.listOfAttestations.find((e) => J(e?.schema)?.toLowerCase() === r?.toLowerCase());
1703
+ a && (!Array.isArray(a.data) || a.data.length === 0) && (a.data = [{
1704
+ ...hi,
1705
+ refUID: W
1706
+ }]);
1707
+ }
1708
+ }
1709
+ //#endregion
1710
+ //#region src/services/arweaveL1Finalize/enqueue.ts
1711
+ var vi = "pending_l1";
1712
+ async function yi(e) {
1713
+ let { useArweaveBundler: t } = T();
1714
+ if (!t) return;
1715
+ let n = e.arweaveTransactions ?? [], r = e.publishUploads ?? [];
1716
+ if (n.length === 0 || n.length !== r.length) return;
1717
+ let i = O.getAppDb();
1718
+ if (!i) return;
1719
+ let a = Date.now();
1720
+ for (let e = 0; e < n.length; e++) {
1721
+ let t = n[e], o = r[e];
1722
+ if (!o) continue;
1723
+ let s = t.transaction?.id;
1724
+ if (s && typeof s == "string") try {
1725
+ await i.insert(xe).values({
1726
+ seedLocalId: o.seedLocalId,
1727
+ dataItemId: s,
1728
+ versionLocalId: o.versionLocalId ?? null,
1729
+ itemPropertyName: o.itemPropertyName ?? null,
1730
+ phase: vi,
1731
+ createdAt: a,
1732
+ updatedAt: a
1733
+ }).onConflictDoNothing();
1734
+ } catch {}
1735
+ }
1736
+ }
1737
+ //#endregion
1738
+ //#region src/helpers/ensureManagedAccountEasConfigured.ts
1739
+ var bi = "Could not verify or set the EAS contract address on your publishing account on Optimism Sepolia.", xi = "ManagedAccount EAS pointer does not match publish config. Configure EAS with the user’s ManagedAccount wallet before automation publish (session keys cannot call setEas).";
1740
+ function Si(e) {
1741
+ return e.toLowerCase();
1742
+ }
1743
+ function Ci(e) {
1744
+ let { easContractAddress: t } = T(), n = Si(t);
1745
+ if (!n || n === Si(qe)) throw new E("Publish config is missing a valid easContractAddress.", "MANAGED_ACCOUNT_SET_EAS_FAILED", e);
1746
+ return n;
1747
+ }
1748
+ async function wi(e) {
1749
+ try {
1750
+ let t = await te(e);
1751
+ return Si(typeof t == "string" ? t : String(t));
1752
+ } catch (t) {
1753
+ throw new E(bi, "MANAGED_ACCOUNT_SET_EAS_FAILED", e, t);
1754
+ }
1755
+ }
1756
+ async function Ti(e) {
1757
+ let t = Ci(e);
1758
+ if (await wi(e) !== t) throw new E(xi, "MANAGED_ACCOUNT_SET_EAS_FAILED", e);
1759
+ }
1760
+ async function Ei(e, t) {
1761
+ let n = w(t) ? t.txSender : x(t) ? t : (() => {
1762
+ throw Error("@seedprotocol/publish: ensureManagedAccountEasConfigured requires PublishWallet or SeedTxSender");
1763
+ })(), r = Ci(e);
1764
+ if (await wi(e) !== r) try {
1765
+ let { easContractAddress: t } = T(), r = d(e, t), i = await n.sendTransaction(r);
1766
+ await l(i.transactionHash);
1767
+ } catch (t) {
1768
+ throw new E(bi, "MANAGED_ACCOUNT_SET_EAS_FAILED", e, t);
1769
+ }
1770
+ }
1771
+ //#endregion
1772
+ //#region src/services/publish/actors/createAttestations.ts
1773
+ var Di = L("seedProtocol:services:publish:actors");
1774
+ function Oi(e) {
1775
+ return !!e && /^0x[0-9a-fA-F]{40}$/.test(e.trim());
1776
+ }
1777
+ function ki(e) {
1778
+ let { useModularExecutor: t, publisherAddress: n, modularAccountModuleContract: r, managedAddress: i, routeToExecutorModule: a } = e;
1779
+ if (t) {
1780
+ if (!i) throw Error("resolvePublishRouting: managedAddress is required when useModularExecutor is true");
1781
+ let e = r?.trim();
1782
+ if (a) {
1783
+ if (!Oi(e)) throw Error("resolvePublishRouting: modularAccountModuleContract is required when routeToExecutorModule is true");
1784
+ return {
1785
+ txTargetAddress: e,
1786
+ contractAddressForEvents: e
1787
+ };
1788
+ }
1789
+ return {
1790
+ txTargetAddress: i,
1791
+ contractAddressForEvents: e || i
1792
+ };
1793
+ }
1794
+ return {
1795
+ txTargetAddress: n,
1796
+ contractAddressForEvents: n
1797
+ };
1798
+ }
1799
+ async function Ai(e) {
1800
+ let { receipt: t, seedLocalId: n, versionSchemaUid: r, contractAddressForEvents: i, listOfAttestationsCount: a, useModularExecutor: o, publisherAddress: s } = e;
1801
+ if (!n) return;
1802
+ let c = oi(t, r, o) ?? ii(t, i, a, o).versionUid, l = c ? J(c) : void 0;
1803
+ if (!l || l === W) return;
1804
+ let u = await q(t);
1805
+ await Be({
1806
+ seedLocalId: n,
1807
+ versionUid: l,
1808
+ publisher: s,
1809
+ attestationCreatedAt: u
1810
+ });
1811
+ }
1812
+ function ji(e, t) {
1813
+ return !e || !t ? !1 : J(e).toLowerCase() === J(t).toLowerCase();
1814
+ }
1815
+ function Mi(e, t, n) {
1816
+ return !n || t >= e.length ? t : ji(e[t]?.schemaUid, n) ? t + 1 : t;
1817
+ }
1818
+ async function Ni(e) {
1819
+ let { receipt: t, normalizedRequests: n, useModularExecutor: r, contractAddressForEvents: i } = e, { easContractAddress: a } = T(), o = ui({
1820
+ receipt: t,
1821
+ useModularExecutor: r,
1822
+ easContractAddress: a,
1823
+ contractAddressForEvents: i,
1824
+ listOfAttestations: n.flatMap((e) => e.listOfAttestations ?? [])
1825
+ });
1826
+ if (!o.length) {
1827
+ Di("persistPropertyMetadataUidsFromContractReceipt: no property attestation pairs");
1828
+ return;
1829
+ }
1830
+ let s = await q(t), c = 0;
1831
+ for (let e of n) {
1832
+ let n = e.listOfAttestations ?? [];
1833
+ if ((!e.seedUid || J(e.seedUid) === W) && (c = Mi(o, c, e.seedSchemaUid)), c = Mi(o, c, e.versionSchemaUid), !n.length) continue;
1834
+ let a = n.length, l = o.slice(c, c + a);
1835
+ if (c += a, !l.length) continue;
1836
+ let u = Math.min(l.length, a), d = e.versionUid && J(e.versionUid) !== W ? J(e.versionUid) : void 0;
1837
+ d ||= oi(t, e.versionSchemaUid, r) ?? ii(t, i, a, r).versionUid, await be({
1838
+ seedLocalId: e.localId,
1839
+ attestationCreatedAtMs: s ?? null,
1840
+ versionUid: d && J(d) !== W ? J(d) : null,
1841
+ pairs: l.slice(0, u).map((e, t) => ({
1842
+ schemaUid: e.schemaUid,
1843
+ attestationUid: e.attestationUid,
1844
+ propertyName: typeof n[t]?._propertyName == "string" && n[t]._propertyName !== "" ? n[t]._propertyName : void 0
1845
+ }))
1846
+ });
1847
+ }
1848
+ }
1849
+ var Pi = I(async ({ input: { context: e } }) => {
1850
+ let { address: t, account: n, wallet: r } = e, i = e.arweaveTransactions ?? [], a = e.publishUploads ?? [], { item: o } = e, { modularAccountModuleContract: s, useModularExecutor: c } = T();
1851
+ if (!t || typeof t != "string" || !t.trim()) throw Error("No wallet address for publish. Connect a wallet and try again.");
1852
+ if (!r && !n) throw Error("Wallet session is missing. Reconnect your wallet and retry the publish.");
1853
+ if (!c && !await u(t)) throw Error("EOA publishing must use the direct EAS path (multiPublish requires a deployed publisher contract). If you see this, attestation routing is misconfigured.");
1854
+ if (!o?.seedLocalId) throw Error("Attestation recovery failed: Item data is missing. Delete this publish record and try a full publish from the beginning.");
1855
+ if (typeof o.getPublishUploads != "function" && (o = await Wt(o.seedLocalId)), i.length !== a.length) throw Error("Attestation recovery failed: Arweave transaction data is missing or incomplete. Delete this publish record and try a full publish from the beginning.");
1856
+ let d = ki({
1857
+ useModularExecutor: !1,
1858
+ publisherAddress: t
1859
+ }), p = Xr(e), h = !1;
1860
+ await Ht(o, p, { managedAddress: t });
1861
+ let g = i.map((e, t) => {
1862
+ let n = e.transaction?.id;
1863
+ if (!n || typeof n != "string") throw Error("Attestation recovery failed: Arweave transaction data did not survive restore. Delete this publish record and try a full publish from the beginning.");
1864
+ let r = a[t];
1865
+ if (!r) throw Error("Publish upload index mismatch");
1866
+ return {
1867
+ ...r,
1868
+ txId: n
1869
+ };
1870
+ });
1871
+ await ni(g.map((e) => e.txId));
1872
+ let _ = await o.getPublishPayload(g, { publishMode: e.publishMode ?? "patch" }), v = Array.isArray(_) ? _ : [_];
1873
+ if (c) {
1874
+ let e = p?.signer?.address, n = !1;
1875
+ if (t && e) {
1876
+ let { isAutomationSessionActive: r } = await import("./ensureAutomationSessionKey-DEH7nwUc.js").then((e) => e.n);
1877
+ n = await r(t, e);
1878
+ }
1879
+ if (n) {
1880
+ let e = s?.trim();
1881
+ if (!Oi(e)) throw Error("@seedprotocol/publish: automation publish requires PublishConfig.modularAccountModuleContract (executor module). Session keys are module-only and cannot call the ManagedAccount directly.");
1882
+ d = ki({
1883
+ useModularExecutor: c,
1884
+ publisherAddress: t,
1885
+ modularAccountModuleContract: e,
1886
+ managedAddress: t,
1887
+ routeToExecutorModule: !0
1888
+ }), h = !0, await Gr(t);
1889
+ } else {
1890
+ let e = await Lr();
1891
+ if (!e.ok) throw e.error;
1892
+ d = ki({
1893
+ useModularExecutor: c,
1894
+ publisherAddress: t,
1895
+ modularAccountModuleContract: s,
1896
+ managedAddress: e.managedAddress
1897
+ });
1898
+ let { ensureModularPublishBootstrap: n } = await import("./ensureModularPublishBootstrap-Btih5xbB.js").then((e) => e.n), { fromThirdwebAccount: r } = await import("./config-CPBd5C_b.js").then((e) => e.c);
1899
+ p = r(await n(e.managedAddress));
1900
+ }
1901
+ } else await Ei(t, p);
1902
+ let ee = async (e) => {
1903
+ let n = d.txTargetAddress;
1904
+ if (!h) return p.txSender.sendTransaction(m(n, e, 5000000n));
1905
+ let r = f(n, e, 5000000n);
1906
+ return await Yr({
1907
+ managedAddress: t,
1908
+ tx: r,
1909
+ action: "multiPublish via the executor module"
1910
+ }), p.txSender.sendTransaction(r);
1911
+ }, te = v.length > 1 && pi(v), y, b = null, x = [];
1912
+ if (te) {
1913
+ let e = structuredClone(v), n = {};
1914
+ for (let r = 0; r < e.length; r++) {
1915
+ e = await Fe(e, n);
1916
+ let i = e[r], a = /* @__PURE__ */ new Set([i.localId]), o = gi({
1917
+ ...i,
1918
+ propertiesToUpdate: mi(i.propertiesToUpdate, a)
1919
+ }), s = /* @__PURE__ */ new Map([[o.localId, o]]);
1920
+ _i([o], s);
1921
+ let u = await ee([o]), f = await l(u.transactionHash);
1922
+ if (!f) throw Error("Failed to send transaction");
1923
+ b = f;
1924
+ let p = o?.listOfAttestations?.length ?? 0;
1925
+ for (let e of si(f, c)) e.attestationUid && x.push(e.attestationUid);
1926
+ await Ai({
1927
+ receipt: f,
1928
+ seedLocalId: i.localId,
1929
+ versionSchemaUid: o.versionSchemaUid,
1930
+ contractAddressForEvents: d.contractAddressForEvents,
1931
+ listOfAttestationsCount: p,
1932
+ useModularExecutor: c,
1933
+ publisherAddress: t
1934
+ });
1935
+ let m = !o.seedUid || J(o.seedUid) === W, h = o?.seedSchemaUid;
1936
+ if (m) {
1937
+ let t = ri(f, h, c) ?? ai(f, d.contractAddressForEvents, p, c);
1938
+ t && (n[i.localId] = t, e[r] = {
1939
+ ...e[r],
1940
+ seedUid: t
1941
+ }, x.push(t));
1942
+ }
1943
+ await Ni({
1944
+ receipt: f,
1945
+ normalizedRequests: [o],
1946
+ useModularExecutor: c,
1947
+ contractAddressForEvents: d.contractAddressForEvents
1948
+ });
1949
+ }
1950
+ for (let t of e) {
1951
+ let e = t?.localId, r = t?.seedUid;
1952
+ e && r && J(r) !== W && (n[e] = J(r));
1953
+ }
1954
+ y = (await Fe(structuredClone(v), n)).map((e) => gi({
1955
+ ...e,
1956
+ seedUid: n[e.localId] ?? e.seedUid
1957
+ }));
1958
+ } else {
1959
+ let e = v.map((e) => gi(e));
1960
+ _i(e, new Map(e.map((e) => [e?.localId, e])));
1961
+ let n = Array.isArray(_) ? e : [e[0]], r = await ee(n), i = await l(r.transactionHash);
1962
+ if (!i) throw Error("Failed to send transaction");
1963
+ b = i;
1964
+ for (let e of si(i, c)) e.attestationUid && x.push(e.attestationUid);
1965
+ let a = e.find((e) => e?.localId === o.seedLocalId) ?? e[0];
1966
+ await Ai({
1967
+ receipt: i,
1968
+ seedLocalId: a?.localId,
1969
+ versionSchemaUid: a?.versionSchemaUid,
1970
+ contractAddressForEvents: d.contractAddressForEvents,
1971
+ listOfAttestationsCount: a?.listOfAttestations?.length ?? 0,
1972
+ useModularExecutor: c,
1973
+ publisherAddress: t
1974
+ }), await Ni({
1975
+ receipt: i,
1976
+ normalizedRequests: n,
1977
+ useModularExecutor: c,
1978
+ contractAddressForEvents: d.contractAddressForEvents
1979
+ });
1980
+ let s = e[0], u = s?.seedUid, f = u === W || !u, p = s?.listOfAttestations?.length ?? 0, m = s?.seedSchemaUid, h = f ? ri(i, m, c) ?? ai(i, d.contractAddressForEvents, p, c) : void 0;
1981
+ h && x.push(h), y = h && e.length > 0 ? [{
1982
+ ...e[0],
1983
+ seedUid: h
1984
+ }, ...e.slice(1)] : e;
1985
+ }
1986
+ ei(o, y);
1987
+ let ne = o, S = y.find((e) => e?.localId === o.seedLocalId)?.seedUid;
1988
+ S && S !== W && await ti(ne, t, b ? await q(b) : void 0), Di("requestData", _), yi(e);
1989
+ try {
1990
+ let { clearHtmlEmbeddedImageCoPublishRows: e } = await import("@seedprotocol/sdk");
1991
+ await e(o.seedLocalId);
1992
+ } catch {}
1993
+ let { collectPublishedBatch: re } = await import("./collectBatchUids-CnIe9jUB.js").then((e) => e.t), C = y.find((e) => e?.localId === o.seedLocalId) ?? y[0];
1994
+ for (let e of y) e?.seedUid && x.push(String(e.seedUid)), e?.versionUid && x.push(String(e.versionUid));
1995
+ return {
1996
+ easPayload: _,
1997
+ publishedBatch: C?.seedUid ? re({
1998
+ seedUid: String(C.seedUid),
1999
+ versionUid: C.versionUid ? String(C.versionUid) : void 0,
2000
+ extraUids: x
2001
+ }) : null
2002
+ };
2003
+ }), Fi = L("seedProtocol:services:publish:verifyAttestations"), Ii = "0x" + "0".repeat(64), Li = 64, Ri = (e) => e == null ? "0x" + "0".repeat(Li) : typeof e == "string" ? "0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(Li, "0").slice(-64) : "0x" + "0".repeat(Li), zi = 5e3, Bi = 6;
2004
+ async function Vi({ normalizedRequests: e, item: t }) {
2005
+ let n = t.seedLocalId;
2006
+ for (let t of e) {
2007
+ if (t.listOfAttestations.length === 0 || t.versionUid === Ii) continue;
2008
+ let e = t.listOfAttestations.map((e) => Ri(e.schema).toLowerCase()), r = [], i;
2009
+ for (let e = 1; e <= Bi; e++) try {
2010
+ e > 1 && await new Promise((e) => setTimeout(e, zi)), r = await we({ versionUids: [t.versionUid] });
2011
+ break;
2012
+ } catch (t) {
2013
+ if (i = t, Fi("verifyAttestations attempt %d failed:", e, t), e === Bi) throw Fi("verifyAttestations: giving up after %d attempts", Bi), i;
2014
+ }
2015
+ let a = r.map((e) => e.schemaId ? Ri(e.schemaId).toLowerCase() : "").filter(Boolean), o = new Set(a);
2016
+ if (e.filter((e) => !o.has(e)).length > 0) throw new ge(`Publish verification failed: Seed and Version attestations were created, but property/metadata attestations are missing or incomplete. Expected ${e.length} property attestations for schema(s) ${e.join(", ")}; found ${a.length}. Use PublishManager.retryAttestations('${n}') to retry.`, n, e, a, "METADATA_PROPERTIES_MISSING");
2017
+ }
2018
+ }
2019
+ //#endregion
2020
+ //#region src/services/publish/actors/createAttestationsDirectToEas.ts
2021
+ var Hi = L("seedProtocol:services:publish:createAttestationsDirectToEas"), Ui = 64, Y = (e) => {
2022
+ if (e == null) return "0x" + "0".repeat(Ui);
2023
+ if (typeof e == "string") return "0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(Ui, "0").slice(-64);
2024
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
2025
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e);
2026
+ return "0x" + Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("").padStart(Ui, "0").slice(-64);
2027
+ }
2028
+ return "0x" + "0".repeat(Ui);
2029
+ }, Wi = (e) => {
2030
+ if (e == null || typeof e == "string" && (e === "" || e === "0x")) return "0x";
2031
+ if (typeof e == "string") {
2032
+ let t = (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0");
2033
+ return "0x" + (t.length % 2 == 1 ? "0" + t : t);
2034
+ }
2035
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
2036
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e);
2037
+ return "0x" + Array.from(t).map((e) => e.toString(16).padStart(2, "0")).join("");
2038
+ }
2039
+ return "0x";
2040
+ }, Gi = async (e) => {
2041
+ let t;
2042
+ try {
2043
+ t = await A.find({ seedLocalId: e });
2044
+ } catch {}
2045
+ return t || new Promise((t) => {
2046
+ let n = setInterval(() => {
2047
+ try {
2048
+ A.find({ seedLocalId: e }).then((e) => {
2049
+ e && (clearInterval(n), t(e));
2050
+ });
2051
+ } catch {}
2052
+ }, 200);
2053
+ });
2054
+ }, Ki = I(async ({ input: { context: e, event: t } }) => {
2055
+ let { address: n, account: r, wallet: s } = e, c = e.arweaveTransactions ?? [], u = e.publishUploads ?? [], { item: d } = e;
2056
+ if (!n || typeof n != "string" || !n.trim()) throw Error("No wallet address for publish. Connect a wallet and try again.");
2057
+ if (!s && !r) throw Error("Wallet session is missing. Reconnect your wallet and retry the publish.");
2058
+ if (!d?.seedLocalId) throw Error("Attestation recovery failed: Item data is missing. Delete this publish record and try a full publish from the beginning.");
2059
+ if (typeof d.getPublishUploads != "function" && (d = await Gi(d.seedLocalId)), c.length !== u.length) throw Error("Attestation recovery failed: Arweave transaction data is missing or incomplete. Delete this publish record and try a full publish from the beginning.");
2060
+ let f = Xr(e), p = f.txSender;
2061
+ await Ht(d, f, { managedAddress: n });
2062
+ let m = c.map((e, t) => {
2063
+ let n = e.transaction?.id;
2064
+ if (!n || typeof n != "string") throw Error("Attestation recovery failed: Arweave transaction data did not survive restore. Delete this publish record and try a full publish from the beginning.");
2065
+ let r = u[t];
2066
+ if (!r) throw Error("Publish upload index mismatch");
2067
+ return {
2068
+ ...r,
2069
+ txId: n
2070
+ };
2071
+ });
2072
+ await ni(m.map((e) => e.txId));
2073
+ let h = await d.getPublishPayload(m, { publishMode: e.publishMode ?? "patch" }), g = (Array.isArray(h) ? h : [h]).map((e) => {
2074
+ let t = (e?.listOfAttestations ?? []).map((e) => {
2075
+ let t = Array.isArray(e?.data) ? e.data : [];
2076
+ return {
2077
+ schema: Y(e?.schema),
2078
+ data: t.map((e) => ({
2079
+ ...e,
2080
+ refUID: Y(e?.refUID),
2081
+ data: Wi(e?.data)
2082
+ })),
2083
+ ...typeof e?._propertyName == "string" && e._propertyName !== "" ? { _propertyName: e._propertyName } : {},
2084
+ ...typeof e?._propertyNameForSchema == "string" && e._propertyNameForSchema !== "" ? { _propertyNameForSchema: e._propertyNameForSchema } : {}
2085
+ };
2086
+ }), n = (e?.propertiesToUpdate ?? []).map((e) => ({
2087
+ ...e,
2088
+ propertySchemaUid: Y(e?.propertySchemaUid)
2089
+ }));
2090
+ return {
2091
+ ...e,
2092
+ seedUid: Y(e?.seedUid),
2093
+ seedSchemaUid: Y(e?.seedSchemaUid),
2094
+ versionUid: Y(e?.versionUid),
2095
+ versionSchemaUid: Y(e?.versionSchemaUid),
2096
+ listOfAttestations: t,
2097
+ propertiesToUpdate: n
2098
+ };
2099
+ }), ee = new Map(g.map((e) => [e.localId, e])), te = {
2100
+ recipient: ct,
2101
+ expirationTime: BigInt(0),
2102
+ revocable: !0,
2103
+ refUID: _,
2104
+ data: _,
2105
+ value: BigInt(0)
2106
+ };
2107
+ for (let e of g) for (let t of e.propertiesToUpdate ?? []) {
2108
+ let e = t.publishLocalId, n = Y(t.propertySchemaUid);
2109
+ if (!e || !n) continue;
2110
+ let r = ee.get(e);
2111
+ if (!r?.listOfAttestations) continue;
2112
+ let i = r.listOfAttestations.find((e) => Y(e?.schema)?.toLowerCase() === n?.toLowerCase());
2113
+ i && (!Array.isArray(i.data) || i.data.length === 0) && (i.data = [{
2114
+ ...te,
2115
+ refUID: _
2116
+ }]);
2117
+ }
2118
+ let y = Date.now(), b = [];
2119
+ for (let e = 0; e < g.length; e++) {
2120
+ let t = g[e], r = t.seedUid, s = t.versionUid;
2121
+ if (r === _) {
2122
+ let e = o({
2123
+ schema: t.seedSchemaUid,
2124
+ data: {
2125
+ refUID: _,
2126
+ data: i(t.seedSchemaUid),
2127
+ revocable: t.seedIsRevocable
2128
+ }
2129
+ }), n = await p.sendTransaction(e), a = await l(n.transactionHash);
2130
+ if (!a) throw Error("Failed to create Seed attestation");
2131
+ y = await q(a);
2132
+ let { easContractAddress: s } = T(), c = ue(a, s);
2133
+ if (!c || c === _) throw Error("Failed to get Seed UID from attestation receipt");
2134
+ r = c, t.seedUid = c, b.push(c), Hi("created Seed attestation", r);
2135
+ } else r !== _ && b.push(r);
2136
+ if (r !== _ && s === _) {
2137
+ let e = o({
2138
+ schema: t.versionSchemaUid,
2139
+ data: {
2140
+ refUID: r,
2141
+ data: i(t.versionSchemaUid),
2142
+ revocable: !0
2143
+ }
2144
+ }), a = await p.sendTransaction(e), c = await l(a.transactionHash);
2145
+ if (!c) throw Error("Failed to create Version attestation");
2146
+ y = await q(c);
2147
+ let { easContractAddress: u } = T(), d = ue(c, u);
2148
+ if (!d || d === _) throw Error("Failed to get Version UID from attestation receipt");
2149
+ s = d, t.versionUid = d, b.push(d), await Be({
2150
+ seedLocalId: t.localId,
2151
+ versionUid: d,
2152
+ publisher: n,
2153
+ attestationCreatedAt: y
2154
+ }), Hi("created Version attestation", s);
2155
+ } else s !== _ && b.push(s);
2156
+ for (let e of t.listOfAttestations) for (let t of e.data) t.refUID = s;
2157
+ for (let e of t.propertiesToUpdate ?? []) {
2158
+ let t = ee.get(e.publishLocalId);
2159
+ if (!t?.listOfAttestations) continue;
2160
+ let n = Y(e.propertySchemaUid), a = t.listOfAttestations.find((e) => Y(e?.schema)?.toLowerCase() === n?.toLowerCase());
2161
+ a?.data?.[0] && (a.data[0].data = i(r));
2162
+ }
2163
+ let c = t.listOfAttestations.map((e) => ({
2164
+ schema: e.schema,
2165
+ data: e.data.map((e) => ({
2166
+ recipient: e.recipient ?? ct,
2167
+ expirationTime: e.expirationTime ?? 0n,
2168
+ revocable: e.revocable ?? !0,
2169
+ refUID: e.refUID ?? _,
2170
+ data: e.data ?? "0x",
2171
+ value: e.value ?? 0n
2172
+ }))
2173
+ }));
2174
+ if (c.length > 0) {
2175
+ let n = a(c), r = await p.sendTransaction(n), i = await l(r.transactionHash);
2176
+ if (!i) throw Error("Failed to create property attestations");
2177
+ y = await q(i), Hi("created property attestations for request", e);
2178
+ let { easContractAddress: o } = T(), u = v(i, o);
2179
+ for (let e of u) e.uid && b.push(e.uid);
2180
+ let d = t.listOfAttestations, f = u.length === d.length;
2181
+ await be({
2182
+ seedLocalId: t.localId,
2183
+ attestationCreatedAtMs: y ?? null,
2184
+ versionUid: s === _ ? null : s,
2185
+ pairs: u.map((e, t) => ({
2186
+ schemaUid: e.schemaUid,
2187
+ attestationUid: e.uid,
2188
+ propertyName: f && typeof d[t]?._propertyName == "string" && d[t]._propertyName !== "" ? d[t]._propertyName : void 0
2189
+ }))
2190
+ });
2191
+ }
2192
+ }
2193
+ ei(d, g);
2194
+ let x = d;
2195
+ g[0]?.seedUid && g[0].seedUid !== _ && await ti(x, n, y);
2196
+ try {
2197
+ await Vi({
2198
+ normalizedRequests: g,
2199
+ item: d
2200
+ });
2201
+ } catch (e) {
2202
+ throw e instanceof ge || Hi("verifyAttestations failed (non-verification error):", e), e;
2203
+ }
2204
+ Hi("direct EAS publish complete"), yi(e);
2205
+ try {
2206
+ let { clearHtmlEmbeddedImageCoPublishRows: e } = await import("@seedprotocol/sdk");
2207
+ await e(d.seedLocalId);
2208
+ } catch {}
2209
+ let { collectPublishedBatch: ne } = await import("./collectBatchUids-CnIe9jUB.js").then((e) => e.t), S = g.find((e) => e?.localId === d.seedLocalId) ?? g[0];
2210
+ return {
2211
+ easPayload: h,
2212
+ publishedBatch: S?.seedUid ? ne({
2213
+ seedUid: String(S.seedUid),
2214
+ versionUid: S.versionUid ? String(S.versionUid) : void 0,
2215
+ extraUids: b
2216
+ }) : null
2217
+ };
2218
+ }), qi = async (e) => {
2219
+ let t;
2220
+ try {
2221
+ t = await A.find({ seedLocalId: e });
2222
+ } catch {}
2223
+ return t || new Promise((t) => {
2224
+ let n = setInterval(() => {
2225
+ A.find({ seedLocalId: e }).then((e) => {
2226
+ e && (clearInterval(n), t(e));
2227
+ }).catch(() => {});
2228
+ }, 200);
2229
+ });
2230
+ };
2231
+ async function Ji(e) {
2232
+ let t = typeof e.getPublishUploads == "function" ? e : await qi(e.seedLocalId);
2233
+ return await je(t);
2234
+ }
2235
+ //#endregion
2236
+ //#region src/services/publish/actors/checking.ts
2237
+ var X = /* @__PURE__ */ new Set();
2238
+ async function Yi(e) {
2239
+ let t = T();
2240
+ return t.useDirectEas ? "directEas" : t.useModularExecutor || await u(e) ? "multiPublish" : "directEas";
2241
+ }
2242
+ var Xi = F(({ sendBack: e, input: { context: t } }) => {
2243
+ let { item: n, account: r, wallet: i, publishMode: a, address: o } = t;
2244
+ return (async () => {
2245
+ if (!await ke(n)) {
2246
+ e({ type: "notOwner" });
2247
+ return;
2248
+ }
2249
+ if (X.has(n.seedLocalId)) {
2250
+ e({ type: "redundantPublishProcess" });
2251
+ return;
2252
+ }
2253
+ X.add(n.seedLocalId);
2254
+ try {
2255
+ let t = i ?? r;
2256
+ t && await Ht(n, t, { managedAddress: typeof o == "string" ? o : void 0 });
2257
+ let s = await Ve(n, [], { publishMode: a ?? "patch" });
2258
+ if (!s.isValid) {
2259
+ X.delete(n.seedLocalId), e({
2260
+ type: "validationFailed",
2261
+ errors: s.errors
2262
+ });
2263
+ return;
2264
+ }
2265
+ if (!o || typeof o != "string" || !o.trim()) {
2266
+ X.delete(n.seedLocalId), e({
2267
+ type: "validationFailed",
2268
+ errors: [{ message: "No publisher address for publish. Connect a wallet and try again." }]
2269
+ });
2270
+ return;
2271
+ }
2272
+ let c;
2273
+ try {
2274
+ c = await Yi(o.trim());
2275
+ } catch (t) {
2276
+ X.delete(n.seedLocalId), e({
2277
+ type: "checkingFailed",
2278
+ error: Error("Could not verify whether the publisher is a deployed contract on Optimism Sepolia. Check your RPC connection and retry.", { cause: t })
2279
+ });
2280
+ return;
2281
+ }
2282
+ let l = await Ji(n), u = T().useArweaveBundler, d = { attestationStrategy: c };
2283
+ e(l ? u ? {
2284
+ type: "validPublishProcessBundler",
2285
+ ...d
2286
+ } : {
2287
+ type: "validPublishProcess",
2288
+ ...d
2289
+ } : {
2290
+ type: "skipArweave",
2291
+ ...d
2292
+ });
2293
+ } catch (t) {
2294
+ X.delete(n.seedLocalId), console.error("[checking] failed", t), e({
2295
+ type: "checkingFailed",
2296
+ error: t instanceof Error ? t : Error(String(t))
2297
+ });
2298
+ }
2299
+ })().catch((t) => {
2300
+ X.delete(n.seedLocalId), console.error("[checking] unhandled rejection", t), e({
2301
+ type: "checkingFailed",
2302
+ error: t instanceof Error ? t : Error(String(t))
2303
+ });
2304
+ }), () => {
2305
+ X.delete(n.seedLocalId);
2306
+ };
2307
+ }), { SUCCESS: Zi, FAILURE: Z } = oe;
2308
+ function Qi(e) {
2309
+ let t = e.attestationStrategy;
2310
+ return t === "directEas" || t !== "multiPublish" && T().useDirectEas;
2311
+ }
2312
+ function $i(e) {
2313
+ let t = e.attestationStrategy;
2314
+ return t === "multiPublish" || t !== "directEas" && !T().useDirectEas;
2315
+ }
2316
+ function Q(e) {
2317
+ let t = e;
2318
+ return t.error ?? t.data;
2319
+ }
2320
+ var ea = ft({
2321
+ types: {
2322
+ context: {},
2323
+ input: {}
2324
+ },
2325
+ actors: {
2326
+ createArweaveTransactions: qt,
2327
+ createArweaveTransactionsPhase2: Jt,
2328
+ createArweaveDataItems: Fn,
2329
+ createArweaveDataItemsPhase2: Ln,
2330
+ sendReimbursementRequest: Wn,
2331
+ pollForConfirmation: Gn,
2332
+ uploadData: qn,
2333
+ uploadViaBundler: Qn,
2334
+ createAttestations: Pi,
2335
+ createAttestationsDirectToEas: Ki,
2336
+ checking: Xi,
2337
+ preparingHtmlEmbedded: Yt,
2338
+ rewritingHtmlEmbedded: Zt
2339
+ },
2340
+ actions: {
2341
+ handleError: ({ event: e }) => {
2342
+ let t = Q(e);
2343
+ t == null ? console.error("Unknown error (full event):", e) : console.error(t);
2344
+ },
2345
+ assignErrorCreatingArweaveTransactions: P({
2346
+ error: ({ event: e }) => Q(e),
2347
+ errorStep: () => "creatingArweaveTransactions"
2348
+ }),
2349
+ assignErrorCreatingArweaveDataItems: P({
2350
+ error: ({ event: e }) => Q(e),
2351
+ errorStep: () => "creatingArweaveDataItems"
2352
+ }),
2353
+ assignErrorSendingReimbursementRequest: P({
2354
+ error: ({ event: e }) => Q(e),
2355
+ errorStep: () => "sendingReimbursementRequest"
2356
+ }),
2357
+ assignErrorPollingForConfirmation: P({
2358
+ error: ({ event: e }) => Q(e),
2359
+ errorStep: () => "pollingForConfirmation"
2360
+ }),
2361
+ assignErrorUploadingData: P({
2362
+ error: ({ event: e }) => Q(e),
2363
+ errorStep: () => "uploadingData"
2364
+ }),
2365
+ assignErrorPreparingHtmlEmbedded: P({
2366
+ error: ({ event: e }) => Q(e),
2367
+ errorStep: () => "preparingHtmlEmbedded"
2368
+ }),
2369
+ assignErrorRewritingHtmlEmbedded: P({
2370
+ error: ({ event: e }) => Q(e),
2371
+ errorStep: () => "rewritingHtmlEmbedded"
2372
+ }),
2373
+ assignErrorCreatingArweaveTransactionsPhase2: P({
2374
+ error: ({ event: e }) => Q(e),
2375
+ errorStep: () => "creatingArweaveTransactionsPhase2"
2376
+ }),
2377
+ assignErrorUploadingDataPhase2: P({
2378
+ error: ({ event: e }) => Q(e),
2379
+ errorStep: () => "uploadingDataPhase2"
2380
+ }),
2381
+ assignErrorUploadingViaBundler: P({
2382
+ error: ({ event: e }) => Q(e),
2383
+ errorStep: () => "uploadingViaBundler"
2384
+ }),
2385
+ assignErrorCreatingArweaveDataItemsPhase2: P({
2386
+ error: ({ event: e }) => Q(e),
2387
+ errorStep: () => "creatingArweaveDataItemsPhase2"
2388
+ }),
2389
+ assignErrorUploadingViaBundlerPhase2: P({
2390
+ error: ({ event: e }) => Q(e),
2391
+ errorStep: () => "uploadingViaBundlerPhase2"
2392
+ }),
2393
+ assignErrorCreatingAttestations: P({
2394
+ error: ({ event: e }) => Q(e),
2395
+ errorStep: () => "creatingAttestations"
2396
+ }),
2397
+ assignErrorCreatingAttestationsDirectToEas: P({
2398
+ error: ({ event: e }) => Q(e),
2399
+ errorStep: () => "creatingAttestationsDirectToEas"
2400
+ }),
2401
+ assignAccountFromRetry: P({
2402
+ wallet: ({ event: e }) => {
2403
+ let t = e;
2404
+ return t.wallet ?? t.account;
2405
+ },
2406
+ account: ({ event: e }) => {
2407
+ let t = e;
2408
+ return t.wallet ?? t.account;
2409
+ }
2410
+ }),
2411
+ assignErrorNotOwner: P({
2412
+ error: () => /* @__PURE__ */ Error("Item is read-only: you do not own this item. Only the publisher can publish."),
2413
+ errorStep: () => "checking"
2414
+ }),
2415
+ assignErrorValidationFailed: P({
2416
+ error: ({ event: e }) => {
2417
+ let t = e.errors ?? [], n = t.length > 0 ? `Validation failed (${t.length} error${t.length === 1 ? "" : "s"}):\n${t.map((e) => e.message).join("\n")}` : "Validation failed", r = Error(n);
2418
+ return r.validationErrors = t, r;
2419
+ },
2420
+ errorStep: () => "checking"
2421
+ }),
2422
+ assignErrorCheckingFailed: P({
2423
+ error: ({ event: e }) => {
2424
+ let t = e.error;
2425
+ return t instanceof Error ? t : Error(String(t ?? "Publish check failed"));
2426
+ },
2427
+ errorStep: () => "checking"
2428
+ })
2429
+ }
2430
+ }).createMachine({
2431
+ id: "publish",
2432
+ initial: "checking",
2433
+ context: ({ input: e }) => e,
2434
+ states: {
2435
+ checking: {
2436
+ on: {
2437
+ notOwner: {
2438
+ target: Z,
2439
+ actions: ["assignErrorNotOwner", "handleError"]
2440
+ },
2441
+ validationFailed: {
2442
+ target: Z,
2443
+ actions: ["assignErrorValidationFailed", "handleError"]
2444
+ },
2445
+ redundantPublishProcess: { target: "stopping" },
2446
+ checkingFailed: {
2447
+ target: Z,
2448
+ actions: ["assignErrorCheckingFailed", "handleError"]
2449
+ },
2450
+ validPublishProcess: {
2451
+ target: "preparingHtmlEmbedded",
2452
+ actions: P({ attestationStrategy: ({ event: e }) => e.attestationStrategy })
2453
+ },
2454
+ validPublishProcessBundler: {
2455
+ target: "preparingHtmlEmbedded",
2456
+ actions: P({ attestationStrategy: ({ event: e }) => e.attestationStrategy })
2457
+ },
2458
+ skipArweave: [{
2459
+ guard: ({ context: e }) => Qi(e),
2460
+ target: "creatingAttestationsDirectToEas",
2461
+ actions: P({
2462
+ arweaveTransactions: () => [],
2463
+ publishUploads: () => [],
2464
+ attestationStrategy: ({ event: e }) => e.attestationStrategy
2465
+ })
2466
+ }, {
2467
+ guard: ({ context: e }) => $i(e),
2468
+ target: "creatingAttestations",
2469
+ actions: P({
2470
+ arweaveTransactions: () => [],
2471
+ publishUploads: () => [],
2472
+ attestationStrategy: ({ event: e }) => e.attestationStrategy
2473
+ })
2474
+ }]
2475
+ },
2476
+ invoke: {
2477
+ src: "checking",
2478
+ input: ({ context: e }) => ({ context: e })
2479
+ }
2480
+ },
2481
+ preparingHtmlEmbedded: { invoke: {
2482
+ src: "preparingHtmlEmbedded",
2483
+ input: ({ context: e }) => ({ context: e }),
2484
+ onDone: [{
2485
+ guard: () => T().useArweaveBundler,
2486
+ target: "creatingArweaveDataItems",
2487
+ actions: P({ htmlEmbeddedDeferredHtmlSeedLocalIds: ({ event: e }) => e.output.deferredHtmlSeedLocalIds })
2488
+ }, {
2489
+ target: "creatingArweaveTransactions",
2490
+ actions: P({ htmlEmbeddedDeferredHtmlSeedLocalIds: ({ event: e }) => e.output.deferredHtmlSeedLocalIds })
2491
+ }],
2492
+ onError: {
2493
+ target: Z,
2494
+ actions: ["assignErrorPreparingHtmlEmbedded", "handleError"]
2495
+ }
2496
+ } },
2497
+ creatingArweaveTransactions: { invoke: {
2498
+ src: "createArweaveTransactions",
2499
+ input: ({ context: e, event: t }) => ({
2500
+ context: e,
2501
+ event: t
2502
+ }),
2503
+ onDone: {
2504
+ target: "sendingReimbursementRequest",
2505
+ actions: P({
2506
+ arweaveTransactions: ({ event: e }) => e.output.arweaveTransactions,
2507
+ publishUploads: ({ event: e }) => e.output.publishUploads
2508
+ })
2509
+ },
2510
+ onError: {
2511
+ target: "failure",
2512
+ actions: ["assignErrorCreatingArweaveTransactions", "handleError"]
2513
+ }
2514
+ } },
2515
+ creatingArweaveDataItems: { invoke: {
2516
+ src: "createArweaveDataItems",
2517
+ input: ({ context: e, event: t }) => ({
2518
+ context: e,
2519
+ event: t
2520
+ }),
2521
+ onDone: {
2522
+ target: "uploadingViaBundler",
2523
+ actions: P({
2524
+ arweaveTransactions: ({ event: e }) => e.output.arweaveTransactions,
2525
+ publishUploads: ({ event: e }) => e.output.publishUploads,
2526
+ signedDataItems: ({ event: e }) => e.output.signedDataItems
2527
+ })
2528
+ },
2529
+ onError: {
2530
+ target: "failure",
2531
+ actions: ["assignErrorCreatingArweaveDataItems", "handleError"]
2532
+ }
2533
+ } },
2534
+ sendingReimbursementRequest: { invoke: {
2535
+ src: "sendReimbursementRequest",
2536
+ input: ({ context: e, event: t }) => ({
2537
+ context: e,
2538
+ event: t
2539
+ }),
2540
+ onDone: {
2541
+ target: "pollingForConfirmation",
2542
+ actions: P({
2543
+ requestResponse: ({ event: e }) => e.output,
2544
+ reimbursementTransactionId: ({ event: e }) => e.output.transactionId
2545
+ })
2546
+ },
2547
+ onError: {
2548
+ target: "failure",
2549
+ actions: ["assignErrorSendingReimbursementRequest", "handleError"]
2550
+ }
2551
+ } },
2552
+ pollingForConfirmation: { invoke: {
2553
+ src: "pollForConfirmation",
2554
+ input: ({ context: e, event: t }) => ({
2555
+ context: e,
2556
+ event: t
2557
+ }),
2558
+ onDone: {
2559
+ target: "uploadingData",
2560
+ actions: P({ reimbursementConfirmed: !0 })
2561
+ },
2562
+ onError: {
2563
+ target: "failure",
2564
+ actions: ["assignErrorPollingForConfirmation", "handleError"]
2565
+ }
2566
+ } },
2567
+ uploadingViaBundler: {
2568
+ on: {
2569
+ uploadComplete: [
2570
+ {
2571
+ guard: ({ context: e }) => Qi(e),
2572
+ target: "creatingAttestationsDirectToEas",
2573
+ actions: P({
2574
+ completionPercentage: 100,
2575
+ signedDataItems: () => void 0,
2576
+ arweaveUploadData: () => void 0
2577
+ })
2578
+ },
2579
+ {
2580
+ guard: (e) => (e.context?.htmlEmbeddedDeferredHtmlSeedLocalIds?.length ?? 0) > 0,
2581
+ target: "rewritingHtmlEmbedded",
2582
+ actions: P({
2583
+ htmlEmbeddedPhase1PublishUploads: ({ context: e }) => e.publishUploads ?? [],
2584
+ htmlEmbeddedPhase1ArweaveTransactions: ({ context: e }) => e.arweaveTransactions ?? [],
2585
+ signedDataItems: () => void 0,
2586
+ arweaveUploadData: () => void 0
2587
+ })
2588
+ },
2589
+ {
2590
+ guard: ({ context: e }) => $i(e),
2591
+ target: "creatingAttestations",
2592
+ actions: P({
2593
+ completionPercentage: 100,
2594
+ signedDataItems: () => void 0,
2595
+ arweaveUploadData: () => void 0
2596
+ })
2597
+ }
2598
+ ],
2599
+ uploadError: {
2600
+ target: "failure",
2601
+ actions: ["assignErrorUploadingViaBundler", "handleError"]
2602
+ }
2603
+ },
2604
+ invoke: {
2605
+ src: "uploadViaBundler",
2606
+ input: ({ context: e }) => ({ context: e })
2607
+ }
2608
+ },
2609
+ creatingArweaveDataItemsPhase2: { invoke: {
2610
+ src: "createArweaveDataItemsPhase2",
2611
+ input: ({ context: e, event: t }) => ({
2612
+ context: e,
2613
+ event: t
2614
+ }),
2615
+ onDone: {
2616
+ target: "uploadingViaBundlerPhase2",
2617
+ actions: P({
2618
+ arweaveTransactions: ({ event: e }) => e.output.arweaveTransactions,
2619
+ publishUploads: ({ event: e }) => e.output.publishUploads,
2620
+ signedDataItems: ({ event: e }) => e.output.signedDataItems,
2621
+ uploaderState: () => void 0,
2622
+ currentTransactionIndex: () => void 0
2623
+ })
2624
+ },
2625
+ onError: {
2626
+ target: Z,
2627
+ actions: ["assignErrorCreatingArweaveDataItemsPhase2", "handleError"]
2628
+ }
2629
+ } },
2630
+ uploadingViaBundlerPhase2: {
2631
+ on: {
2632
+ uploadComplete: [{
2633
+ guard: ({ context: e }) => Qi(e),
2634
+ target: "creatingAttestationsDirectToEas",
2635
+ actions: P({
2636
+ completionPercentage: 100,
2637
+ signedDataItems: () => void 0,
2638
+ arweaveUploadData: () => void 0
2639
+ })
2640
+ }, {
2641
+ guard: ({ context: e }) => $i(e),
2642
+ target: "creatingAttestations",
2643
+ actions: P({
2644
+ completionPercentage: 100,
2645
+ signedDataItems: () => void 0,
2646
+ arweaveUploadData: () => void 0,
2647
+ publishUploads: ({ context: e }) => [...e.htmlEmbeddedPhase1PublishUploads ?? [], ...e.publishUploads ?? []],
2648
+ arweaveTransactions: ({ context: e }) => [...e.htmlEmbeddedPhase1ArweaveTransactions ?? [], ...e.arweaveTransactions ?? []]
2649
+ })
2650
+ }],
2651
+ uploadError: {
2652
+ target: Z,
2653
+ actions: ["assignErrorUploadingViaBundlerPhase2", "handleError"]
2654
+ }
2655
+ },
2656
+ invoke: {
2657
+ src: "uploadViaBundler",
2658
+ input: ({ context: e }) => ({ context: e })
2659
+ }
2660
+ },
2661
+ uploadingData: {
2662
+ on: {
2663
+ updatePercentage: { actions: P({
2664
+ completionPercentage: ({ event: e }) => e.completionPercentage,
2665
+ uploaderState: ({ event: e }) => e.uploaderState,
2666
+ currentTransactionIndex: ({ event: e }) => e.currentTransactionIndex
2667
+ }) },
2668
+ uploadComplete: [
2669
+ {
2670
+ guard: ({ context: e }) => Qi(e),
2671
+ target: "creatingAttestationsDirectToEas",
2672
+ actions: P({ completionPercentage: 100 })
2673
+ },
2674
+ {
2675
+ guard: (e) => (e.context?.htmlEmbeddedDeferredHtmlSeedLocalIds?.length ?? 0) > 0,
2676
+ target: "rewritingHtmlEmbedded",
2677
+ actions: P({
2678
+ htmlEmbeddedPhase1PublishUploads: ({ context: e }) => e.publishUploads ?? [],
2679
+ htmlEmbeddedPhase1ArweaveTransactions: ({ context: e }) => e.arweaveTransactions ?? []
2680
+ })
2681
+ },
2682
+ {
2683
+ guard: ({ context: e }) => $i(e),
2684
+ target: "creatingAttestations",
2685
+ actions: P({ completionPercentage: 100 })
2686
+ }
2687
+ ],
2688
+ uploadError: {
2689
+ target: "failure",
2690
+ actions: ["assignErrorUploadingData", "handleError"]
2691
+ }
2692
+ },
2693
+ invoke: {
2694
+ src: "uploadData",
2695
+ input: ({ context: e }) => ({ context: e })
2696
+ }
2697
+ },
2698
+ rewritingHtmlEmbedded: { invoke: {
2699
+ src: "rewritingHtmlEmbedded",
2700
+ input: ({ context: e }) => ({ context: e }),
2701
+ onDone: [{
2702
+ guard: () => !T().useArweaveBundler,
2703
+ target: "creatingArweaveTransactionsPhase2"
2704
+ }, {
2705
+ guard: () => T().useArweaveBundler,
2706
+ target: "creatingArweaveDataItemsPhase2"
2707
+ }],
2708
+ onError: {
2709
+ target: Z,
2710
+ actions: ["assignErrorRewritingHtmlEmbedded", "handleError"]
2711
+ }
2712
+ } },
2713
+ creatingArweaveTransactionsPhase2: { invoke: {
2714
+ src: "createArweaveTransactionsPhase2",
2715
+ input: ({ context: e, event: t }) => ({
2716
+ context: e,
2717
+ event: t
2718
+ }),
2719
+ onDone: {
2720
+ target: "uploadingDataPhase2",
2721
+ actions: P({
2722
+ arweaveTransactions: ({ event: e }) => e.output.arweaveTransactions,
2723
+ publishUploads: ({ event: e }) => e.output.publishUploads,
2724
+ uploaderState: () => void 0,
2725
+ currentTransactionIndex: () => void 0
2726
+ })
2727
+ },
2728
+ onError: {
2729
+ target: Z,
2730
+ actions: ["assignErrorCreatingArweaveTransactionsPhase2", "handleError"]
2731
+ }
2732
+ } },
2733
+ uploadingDataPhase2: {
2734
+ on: {
2735
+ updatePercentage: { actions: P({
2736
+ completionPercentage: ({ event: e }) => e.completionPercentage,
2737
+ uploaderState: ({ event: e }) => e.uploaderState,
2738
+ currentTransactionIndex: ({ event: e }) => e.currentTransactionIndex
2739
+ }) },
2740
+ uploadComplete: [{
2741
+ guard: ({ context: e }) => Qi(e),
2742
+ target: "creatingAttestationsDirectToEas",
2743
+ actions: P({ completionPercentage: 100 })
2744
+ }, {
2745
+ guard: ({ context: e }) => $i(e),
2746
+ target: "creatingAttestations",
2747
+ actions: P({
2748
+ completionPercentage: 100,
2749
+ publishUploads: ({ context: e }) => [...e.htmlEmbeddedPhase1PublishUploads ?? [], ...e.publishUploads ?? []],
2750
+ arweaveTransactions: ({ context: e }) => [...e.htmlEmbeddedPhase1ArweaveTransactions ?? [], ...e.arweaveTransactions ?? []]
2751
+ })
2752
+ }],
2753
+ uploadError: {
2754
+ target: Z,
2755
+ actions: ["assignErrorUploadingDataPhase2", "handleError"]
2756
+ }
2757
+ },
2758
+ invoke: {
2759
+ src: "uploadData",
2760
+ input: ({ context: e }) => ({ context: e })
2761
+ }
2762
+ },
2763
+ creatingAttestations: { invoke: {
2764
+ src: "createAttestations",
2765
+ input: ({ context: e, event: t }) => ({
2766
+ context: e,
2767
+ event: t
2768
+ }),
2769
+ onDone: {
2770
+ target: Zi,
2771
+ actions: P({
2772
+ easPayload: ({ event: e }) => e.output?.easPayload,
2773
+ publishedBatch: ({ event: e }) => e.output?.publishedBatch ?? null
2774
+ })
2775
+ },
2776
+ onError: {
2777
+ target: "attestationFailureRecoverable",
2778
+ actions: ["assignErrorCreatingAttestations", "handleError"]
2779
+ }
2780
+ } },
2781
+ attestationFailureRecoverable: { on: { retry: {
2782
+ target: "creatingAttestations",
2783
+ actions: ["assignAccountFromRetry"]
2784
+ } } },
2785
+ creatingAttestationsDirectToEas: { invoke: {
2786
+ src: "createAttestationsDirectToEas",
2787
+ input: ({ context: e, event: t }) => ({
2788
+ context: e,
2789
+ event: t
2790
+ }),
2791
+ onDone: {
2792
+ target: Zi,
2793
+ actions: P({
2794
+ easPayload: ({ event: e }) => e.output?.easPayload,
2795
+ publishedBatch: ({ event: e }) => e.output?.publishedBatch ?? null
2796
+ })
2797
+ },
2798
+ onError: {
2799
+ target: "attestationFailureRecoverableDirectToEas",
2800
+ actions: ["assignErrorCreatingAttestationsDirectToEas", "handleError"]
2801
+ }
2802
+ } },
2803
+ attestationFailureRecoverableDirectToEas: { on: { retry: {
2804
+ target: "creatingAttestationsDirectToEas",
2805
+ actions: ["assignAccountFromRetry"]
2806
+ } } },
2807
+ stopping: {
2808
+ entry: ({ context: e }) => {
2809
+ console.log(`Actor for ${e.item?.seedLocalId} stopped`);
2810
+ },
2811
+ type: "final"
2812
+ },
2813
+ [Zi]: {
2814
+ entry: ({ context: e }) => {
2815
+ let t = e.publishedBatch, n = e.onPublished;
2816
+ if (!n || !t?.seedUid) return;
2817
+ let r = e.item?.seedLocalId;
2818
+ r && Promise.resolve(n({
2819
+ seedLocalId: r,
2820
+ seedUid: t.seedUid,
2821
+ versionUid: t.versionUid,
2822
+ attestationUids: t.attestationUids
2823
+ })).catch((e) => {
2824
+ console.warn("[publish] onPublished callback failed:", e);
2825
+ });
2826
+ },
2827
+ type: "final"
2828
+ },
2829
+ [Z]: {
2830
+ entry: ({ context: e }) => {},
2831
+ type: "final"
2832
+ }
2833
+ }
2834
+ }), ta = P(({ context: e, event: t }) => {
2835
+ let n = t, r = n.publishProcesses ?? /* @__PURE__ */ new Map(), i = n.subscriptions ?? /* @__PURE__ */ new Map();
2836
+ return {
2837
+ publishProcesses: new Map(r),
2838
+ subscriptions: new Map(i)
2839
+ };
2840
+ }), na = null;
2841
+ function ra(e) {
2842
+ na = e;
2843
+ }
2844
+ function ia() {
2845
+ return na;
2846
+ }
2847
+ //#endregion
2848
+ //#region src/services/publishManager/actors/subscribe.ts
2849
+ var aa = L("seedProtocol:services:PublishManager:actors:subscribe");
2850
+ function oa(e) {
2851
+ let t = e.value;
2852
+ return typeof t == "string" ? t : t && typeof t == "object" ? Object.keys(t)[0] ?? "" : "";
2853
+ }
2854
+ function sa(e) {
2855
+ return ce.includes(e);
2856
+ }
2857
+ var ca = F(({ receive: e, input: { publishProcess: t, seedLocalId: n } }) => {
2858
+ let r = ia(), i = null, a = () => {
2859
+ i != null && (clearInterval(i), i = null);
2860
+ }, o = (e) => {
2861
+ let o = oa(e);
2862
+ sa(o) && i == null && r ? i = setInterval(() => {
2863
+ try {
2864
+ let e = t.getSnapshot();
2865
+ if (e.status === "done") {
2866
+ a();
2867
+ return;
2868
+ }
2869
+ if (!sa(oa(e))) {
2870
+ a();
2871
+ return;
2872
+ }
2873
+ } catch {
2874
+ return;
2875
+ }
2876
+ r?.savePublish(n, t);
2877
+ }, ne) : sa(o) || a();
2878
+ }, s = t.subscribe(async (e) => {
2879
+ aa("Publish state:", e.value), r && (e.status === "done" ? (a(), r.savePublish(n, t, { triggerPublishDone: !0 })) : (r.savePublish(n, t), o(e)));
2880
+ });
2881
+ e(({ type: e }) => {
2882
+ e === "UNSUBSCRIBE" && (aa("Received UNSUBSCRIBE event"), a(), s.unsubscribe(), r?.removeSubscription(n));
2883
+ });
2884
+ }), la = /* @__PURE__ */ new Map(), ua = 1;
2885
+ function da(e) {
2886
+ let t = ua++;
2887
+ return la.set(t, e), t;
2888
+ }
2889
+ function fa(e, t) {
2890
+ if (e == null) return;
2891
+ let n = la.get(e);
2892
+ n && (la.delete(e), n(t));
2893
+ }
2894
+ //#endregion
2895
+ //#region src/services/publishManager/actions/createPublish.ts
2896
+ function pa(e) {
2897
+ if (e) {
2898
+ if (w(e)) return e;
2899
+ if (C(e)) {
2900
+ let t = de();
2901
+ if (t && t.signer.address.toLowerCase() === e.address.toLowerCase()) return t;
2902
+ throw Error("@seedprotocol/publish: createPublish requires a PublishWallet (signer + txSender). Use fromEthersWallet, fromEip1193Provider, or fromThirdwebAccount.");
2903
+ }
2904
+ throw Error("@seedprotocol/publish: createPublish account must be a PublishWallet. Thirdweb Account must be wrapped with fromThirdwebAccount from @seedprotocol/publish/thirdweb.");
2905
+ }
2906
+ }
2907
+ function ma(e) {
2908
+ if (e) {
2909
+ if (e instanceof N.Wallet) return e;
2910
+ if (w(e)) return e.signer;
2911
+ if (C(e)) return e;
2912
+ }
2913
+ }
2914
+ var ha = dt(({ event: e, enqueue: t }) => {
2915
+ let { item: n, address: r, account: i, options: a, createToken: o } = e;
2916
+ if (!(r != null && typeof r == "string" && r.trim().length > 0)) {
2917
+ console.warn("[createPublish] No valid wallet address; skipping spawn."), fa(o, void 0);
2918
+ return;
2919
+ }
2920
+ t.assign(({ context: e, spawn: t }) => {
2921
+ let { publishProcesses: s } = e;
2922
+ if (s && s.has(n.seedLocalId)) return console.warn(`Publish process with seedLocalId "${n.seedLocalId}" already exists.`), fa(o, void 0), e;
2923
+ let c = typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `run_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`, l = T(), u = [...l.arweaveUploadTags ?? [], ...a?.arweaveUploadTags ?? []], d = pa(i) ?? de() ?? void 0, f = t(ea, { input: {
2924
+ item: n,
2925
+ address: r,
2926
+ wallet: d,
2927
+ account: d,
2928
+ modelName: n.modelName,
2929
+ schemaId: n.schemaUid,
2930
+ signDataItems: a?.signDataItems,
2931
+ dataItemSigner: ma(a?.dataItemSigner),
2932
+ signArweaveTransactions: a?.signArweaveTransactions,
2933
+ arweaveJwk: a?.arweaveJwk,
2934
+ publishMode: a?.publishMode ?? "patch",
2935
+ publishRunId: c,
2936
+ arweaveUploadTags: u.length ? u : void 0,
2937
+ htmlEmbeddedDataUriPolicy: a?.htmlEmbeddedDataUriPolicy ?? l.htmlEmbeddedDataUriPolicy ?? "materialize",
2938
+ onPublished: a?.onPublished ?? l.onPublished
2939
+ } });
2940
+ s.set(n.seedLocalId, f);
2941
+ let p = new Map(e.settledPublishes);
2942
+ return p.delete(n.seedLocalId), fa(o, f), {
2943
+ ...e,
2944
+ publishProcesses: s,
2945
+ settledPublishes: p
2946
+ };
2947
+ }), t.assign(({ context: e, spawn: t }) => {
2948
+ let { subscriptions: r, publishProcesses: i } = e, a = i.get(n.seedLocalId);
2949
+ if (!a) return console.warn(`Publish process with seedLocalId "${n.seedLocalId}" does not exist.`), e;
2950
+ if (r.has(n.seedLocalId)) return console.warn(`Subscription with seedLocalId "${n.seedLocalId}" already exists.`), e;
2951
+ let o = t(ca, { input: {
2952
+ publishProcess: a,
2953
+ seedLocalId: n.seedLocalId
2954
+ } });
2955
+ return r.set(n.seedLocalId, o), {
2956
+ ...e,
2957
+ subscriptions: new Map(r)
2958
+ };
2959
+ });
2960
+ }), ga = ({ context: e, event: t }) => {
2961
+ let { seedLocalId: n, account: r } = t, i = e.publishProcesses.get(n);
2962
+ if (!i) {
2963
+ console.warn(`Publish process with seedLocalId "${n}" does not exist.`);
2964
+ return;
2965
+ }
2966
+ let a = r == null ? de() ?? void 0 : w(r) ? r : void 0;
2967
+ r != null && !a && console.warn("[retryAttestations] account must be a PublishWallet. Use fromThirdwebAccount / fromEip1193Provider / fromEthersWallet."), i.send({
2968
+ type: "retry",
2969
+ account: a,
2970
+ wallet: a
2971
+ });
2972
+ };
2973
+ //#endregion
2974
+ //#region src/services/publishManager/actions/stopScopedOrStandaloneChild.ts
2975
+ function _a(e, t, n) {
2976
+ t._parent === e ? n.stopChild(t) : t.stop();
2977
+ }
2978
+ //#endregion
2979
+ //#region src/services/publishManager/actors/savePublish.ts
2980
+ var va = L("seedProtocol:services:PublishManager:actors:savePublish"), ya = /* @__PURE__ */ new Map();
2981
+ function ba(e, t) {
2982
+ let n = (ya.get(e) ?? Promise.resolve()).then(t);
2983
+ return ya.set(e, n.catch(() => {})), n;
2984
+ }
2985
+ function xa(e) {
2986
+ return e === "completed" || e === "failed" || e === "interrupted";
2987
+ }
2988
+ function Sa(e) {
2989
+ return e.status === "done" ? e.value === "success" ? "completed" : e.value === "failure" ? "failed" : "completed" : "in_progress";
2990
+ }
2991
+ var Ca = 500, wa = 2e3;
2992
+ function Ta(e) {
2993
+ return JSON.stringify(e, (e, t) => typeof t == "bigint" ? t.toString() : t);
2994
+ }
2995
+ function Ea(e) {
2996
+ if (typeof e != "object" || !e) return;
2997
+ let t = e, n = t.snapshot, r = (t.context ?? n?.context)?.publishRunId;
2998
+ return typeof r == "string" && r.length > 0 ? r : void 0;
2999
+ }
3000
+ function Da(e, t) {
3001
+ if (!e?.error || t !== "failed" && t !== "in_progress") return {};
3002
+ let n = e.error, r = n == null ? void 0 : (n instanceof Error ? n.message : String(n)).slice(0, Ca), i = e.errorStep, a;
3003
+ if (n instanceof Error && n.stack) a = n.stack.slice(0, wa);
3004
+ else if (typeof n == "object" && n) try {
3005
+ a = JSON.stringify(n).slice(0, wa);
3006
+ } catch {
3007
+ a = String(n).slice(0, wa);
3008
+ }
3009
+ else n != null && (a = String(n).slice(0, wa));
3010
+ return {
3011
+ errorMessage: r ?? void 0,
3012
+ errorStep: i,
3013
+ errorDetails: a
3014
+ };
3015
+ }
3016
+ function Oa(e) {
3017
+ return ba(e, async () => {
3018
+ let t = O.getAppDb();
3019
+ if (!t) {
3020
+ va("markInProgressPublishInterrupted: DB not ready, skipping");
3021
+ return;
3022
+ }
3023
+ let n = await t.select().from(j).where(pt(R(j.seedLocalId, e), R(j.status, "in_progress"))).orderBy(mt(j.updatedAt)).limit(1);
3024
+ if (n.length === 0) return;
3025
+ let r = Date.now();
3026
+ await t.update(j).set({
3027
+ status: "interrupted",
3028
+ completedAt: r,
3029
+ updatedAt: r,
3030
+ errorMessage: null,
3031
+ errorStep: null,
3032
+ errorDetails: null
3033
+ }).where(R(j.id, n[0].id));
3034
+ });
3035
+ }
3036
+ var ka = F(({ sendBack: e, input: { persistedSnapshot: t, seedLocalId: n, triggerPublishDone: r } }) => {
3037
+ va("savePublish seedLocalId", n);
3038
+ let i = t;
3039
+ ba(n, async () => {
3040
+ let a = O.getAppDb();
3041
+ if (!a) {
3042
+ va("savePublish: DB not ready, skipping"), e({
3043
+ type: "SAVE_PUBLISH_DONE",
3044
+ seedLocalId: n,
3045
+ triggerPublishDone: r
3046
+ });
3047
+ return;
3048
+ }
3049
+ let o = await a.select().from(j).where(pt(R(j.seedLocalId, n), R(j.status, "in_progress"))).orderBy(mt(j.updatedAt)).limit(1), s = typeof t == "string" ? t : Ta(t), c = Sa(i), l = Date.now(), u = Da(i.context, c);
3050
+ if (o.length > 0) {
3051
+ let e = o[0];
3052
+ await a.update(j).set({
3053
+ persistedSnapshot: s,
3054
+ status: c,
3055
+ updatedAt: l,
3056
+ ...i.status === "done" && c !== "in_progress" ? { completedAt: l } : {},
3057
+ ...u
3058
+ }).where(R(j.id, e.id));
3059
+ } else {
3060
+ let e = Ea(i);
3061
+ if (e != null && c === "in_progress" && i.status !== "done") {
3062
+ let t = (await a.select().from(j).where(R(j.seedLocalId, n)).orderBy(mt(j.startedAt)).limit(1))[0];
3063
+ if (t && xa(t.status)) try {
3064
+ if (Ea(JSON.parse(t.persistedSnapshot)) === e) {
3065
+ va("savePublish: skip stale insert — same publishRunId as latest terminal row", n, e);
3066
+ return;
3067
+ }
3068
+ } catch {}
3069
+ }
3070
+ let t = i.context?.item, r = i.context?.modelName ?? t?.modelName ?? "", o = i.context?.schemaId ?? t?.schemaId;
3071
+ await a.insert(j).values({
3072
+ seedLocalId: n,
3073
+ modelName: r,
3074
+ schemaId: o ?? null,
3075
+ status: c,
3076
+ startedAt: l,
3077
+ persistedSnapshot: s,
3078
+ createdAt: l,
3079
+ updatedAt: l,
3080
+ ...u
3081
+ });
3082
+ }
3083
+ }).then(() => {
3084
+ e({
3085
+ type: "SAVE_PUBLISH_DONE",
3086
+ seedLocalId: n,
3087
+ triggerPublishDone: r
3088
+ });
3089
+ }).catch((t) => {
3090
+ va("savePublish error", t), e({
3091
+ type: "SAVE_PUBLISH_DONE",
3092
+ seedLocalId: n,
3093
+ triggerPublishDone: r
3094
+ });
3095
+ });
3096
+ }), Aa = dt(({ context: e, event: t, enqueue: n, self: r }) => {
3097
+ let { publishProcesses: i, subscriptions: a } = e, { seedLocalId: o } = t;
3098
+ Oa(o).catch((e) => {
3099
+ console.warn(`[stopPublish] Failed to mark publish_processes row interrupted for "${o}":`, e);
3100
+ });
3101
+ let s = i.get(o);
3102
+ if (!s) {
3103
+ console.warn(`Publish process with seedLocalId "${o}" does not exist.`);
3104
+ return;
3105
+ }
3106
+ _a(r, s, n);
3107
+ let c = a.get(o);
3108
+ c && _a(r, c, n);
3109
+ let l = new Map(i);
3110
+ l.delete(o);
3111
+ let u = new Map(a);
3112
+ u.delete(o), n.assign({
3113
+ publishProcesses: l,
3114
+ subscriptions: u
3115
+ });
3116
+ }), ja = L("seedProtocol:PublishManager:index"), Ma = dt(({ context: e, enqueue: t, self: n }) => {
3117
+ ja("Stopping all actors..."), e.publishProcesses.forEach((e) => {
3118
+ _a(n, e, t);
3119
+ }), e.subscriptions.forEach((e) => {
3120
+ _a(n, e, t);
3121
+ }), t.assign({
3122
+ publishProcesses: /* @__PURE__ */ new Map(),
3123
+ subscriptions: /* @__PURE__ */ new Map()
3124
+ });
3125
+ }), Na = dt(({ context: e, event: t, enqueue: n }) => {
3126
+ let { seedLocalId: r } = t, i = e.publishProcesses.get(r);
3127
+ if (!i) {
3128
+ console.warn(`Publish process with seedLocalId "${r}" does not exist.`);
3129
+ return;
3130
+ }
3131
+ n.stopChild(i);
3132
+ let a = e.subscriptions.get(r);
3133
+ a && n.stopChild(a);
3134
+ let o = new Map(e.publishProcesses);
3135
+ o.delete(r);
3136
+ let s = new Map(e.subscriptions);
3137
+ s.delete(r), n.assign({
3138
+ publishProcesses: o,
3139
+ subscriptions: s
3140
+ });
3141
+ }), Pa = P(({ context: e, event: t }) => {
3142
+ let { subscriptions: n } = e, { seedLocalId: r, newSubscription: i } = t;
3143
+ return i && n.set(r, i), { subscriptions: new Map(n) };
3144
+ }), Fa = ["signedDataItems", "arweaveUploadData"];
3145
+ function Ia(e) {
3146
+ if (typeof e != "object" || !e) return e;
3147
+ let t = { ...e };
3148
+ for (let e of Fa) delete t[e];
3149
+ return t;
3150
+ }
3151
+ function La(e) {
3152
+ if (typeof e != "object" || !e) return e;
3153
+ let t = e, n = { ...t };
3154
+ t.context != null && typeof t.context == "object" && (n.context = Ia(t.context));
3155
+ let r = t.snapshot;
3156
+ if (typeof r == "object" && r) {
3157
+ let e = r, t = { ...e };
3158
+ e.context != null && typeof e.context == "object" && (t.context = Ia(e.context)), n.snapshot = t;
3159
+ }
3160
+ return n;
3161
+ }
3162
+ function Ra(e) {
3163
+ try {
3164
+ return La(e.getPersistedSnapshot?.() ?? e.getSnapshot());
3165
+ } catch {
3166
+ let t = e.getSnapshot(), n = t.context;
3167
+ if (!n?.item) return La(t);
3168
+ let r = n.item;
3169
+ return La({
3170
+ ...t,
3171
+ context: {
3172
+ ...n,
3173
+ item: {
3174
+ seedLocalId: r.seedLocalId,
3175
+ modelName: r.modelName,
3176
+ schemaId: r.schemaId
3177
+ }
3178
+ }
3179
+ });
3180
+ }
3181
+ }
3182
+ var za = P(({ context: e, event: t, spawn: n }) => {
3183
+ let { publishProcesses: r } = e, { seedLocalId: i, publishProcess: a, triggerPublishDone: o } = t;
3184
+ if (!a) return e;
3185
+ let s = new Map(r);
3186
+ s.set(i, a);
3187
+ let c = Ra(a);
3188
+ return n(ka, {
3189
+ id: `savePublish_${i}_${Date.now()}`,
3190
+ input: {
3191
+ persistedSnapshot: c,
3192
+ seedLocalId: i,
3193
+ triggerPublishDone: o
3194
+ }
3195
+ }), { publishProcesses: s };
3196
+ }), Ba = P(({ context: e, event: t }) => {
3197
+ let { publishProcesses: n, subscriptions: r, settledPublishes: i } = e, a = t.seedLocalId, o = r.get(a);
3198
+ o && o.send({ type: "UNSUBSCRIBE" });
3199
+ let s = n.get(a), c = new Map(n);
3200
+ c.delete(a);
3201
+ let l = new Map(r);
3202
+ l.delete(a);
3203
+ let u = new Map(i);
3204
+ return s && u.set(a, s), {
3205
+ publishProcesses: c,
3206
+ subscriptions: l,
3207
+ settledPublishes: u
3208
+ };
3209
+ }), Va = P(({ context: e, event: t }) => {
3210
+ let { subscriptions: n } = e, r = t.seedLocalId, i = new Map(n);
3211
+ return i.delete(r), { subscriptions: i };
3212
+ }), Ha = 6e4, Ua = 2e3;
3213
+ function Wa(e, t) {
3214
+ let n = typeof process < "u" ? process.env[e] : void 0;
3215
+ if (n == null || n === "") return t;
3216
+ let r = Number(n);
3217
+ return Number.isFinite(r) && r >= 0 ? r : t;
3218
+ }
3219
+ async function Ga(e, t) {
3220
+ let n = Date.now() + e;
3221
+ for (; Date.now() < n;) {
3222
+ try {
3223
+ if (O.isAppDbReady() && O.getAppDb()) return !0;
3224
+ } catch {}
3225
+ await new Promise((e) => setTimeout(e, t));
3226
+ }
3227
+ return !1;
3228
+ }
3229
+ function Ka(e) {
3230
+ let t = e.value;
3231
+ return typeof t == "string" ? t : t && typeof t == "object" ? Object.keys(t)[0] ?? "" : "";
3232
+ }
3233
+ function qa(e) {
3234
+ let t = Ka(e);
3235
+ if (t === "pollingForConfirmation" && (!e.context?.reimbursementTransactionId || !e.context?.requestResponse)) return !1;
3236
+ if (t === "uploadingData") {
3237
+ let t = e.context?.arweaveTransactions, n = e.context?.publishUploads;
3238
+ if (!Array.isArray(t) || t.length === 0 || !Array.isArray(n)) return !1;
3239
+ }
3240
+ return !0;
3241
+ }
3242
+ function Ja(e) {
3243
+ return typeof e == "object" && !!e && "xstate$$type" in e && e.xstate$$type === 1 && typeof e.id == "string";
3244
+ }
3245
+ function Ya(e, t, n) {
3246
+ e.context = e.context ?? {};
3247
+ let r = e.context.item;
3248
+ if (Ja(r)) {
3249
+ e.context.item = {
3250
+ seedLocalId: t,
3251
+ modelName: e.context.modelName ?? n.modelName ?? "",
3252
+ schemaId: e.context.schemaId ?? n.schemaId ?? void 0
3253
+ };
3254
+ return;
3255
+ }
3256
+ e.context.item = {
3257
+ ...typeof r == "object" && r && !Array.isArray(r) ? r : {},
3258
+ seedLocalId: t,
3259
+ modelName: r?.modelName ?? e.context.modelName ?? n.modelName ?? "",
3260
+ schemaId: r?.schemaId ?? e.context.schemaId ?? n.schemaId ?? void 0
3261
+ };
3262
+ }
3263
+ var Xa = F(({ sendBack: e, input: { context: t } }) => {
3264
+ let n = async () => {
3265
+ let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
3266
+ if (!await Ga(Wa("SEED_PUBLISH_RESTORE_WAIT_MS", Ha), Wa("SEED_PUBLISH_RESTORE_POLL_MS", Ua))) return {
3267
+ newPublishProcesses: e,
3268
+ newSubscriptions: t
3269
+ };
3270
+ let n = O.getAppDb();
3271
+ if (!n) return {
3272
+ newPublishProcesses: e,
3273
+ newSubscriptions: t
3274
+ };
3275
+ let r = await n.select().from(j).where(R(j.status, "in_progress")), i = /* @__PURE__ */ new Map(), a = [...r].sort((e, t) => (t.updatedAt ?? t.createdAt ?? 0) - (e.updatedAt ?? e.createdAt ?? 0));
3276
+ for (let e of a) i.has(e.seedLocalId) || i.set(e.seedLocalId, e);
3277
+ let o = Array.from(i.values());
3278
+ for (let n of o) {
3279
+ let r;
3280
+ try {
3281
+ r = JSON.parse(n.persistedSnapshot);
3282
+ } catch {
3283
+ continue;
3284
+ }
3285
+ if (r.status === "done") continue;
3286
+ let i = r.context?.item?.seedLocalId ?? n.seedLocalId;
3287
+ if (!i || !qa(r)) continue;
3288
+ Ya(r, i, n);
3289
+ let a = ut(ea, {
3290
+ snapshot: r,
3291
+ input: void 0
3292
+ }), o = ut(ca, { input: {
3293
+ publishProcess: a,
3294
+ seedLocalId: i
3295
+ } });
3296
+ e.set(i, a), t.set(i, o), a.start(), o.start();
3297
+ }
3298
+ return {
3299
+ newPublishProcesses: e,
3300
+ newSubscriptions: t
3301
+ };
3302
+ }, r = () => ({
3303
+ newPublishProcesses: /* @__PURE__ */ new Map(),
3304
+ newSubscriptions: /* @__PURE__ */ new Map()
3305
+ });
3306
+ n().then((t) => {
3307
+ let { newPublishProcesses: n, newSubscriptions: i } = t ?? r();
3308
+ e({
3309
+ type: "RESTORE_FROM_DB_DONE",
3310
+ publishProcesses: n,
3311
+ subscriptions: i
3312
+ });
3313
+ }).catch(() => {
3314
+ let { newPublishProcesses: t, newSubscriptions: n } = r();
3315
+ e({
3316
+ type: "RESTORE_FROM_DB_DONE",
3317
+ publishProcesses: t,
3318
+ subscriptions: n
3319
+ });
3320
+ });
3321
+ }), Za = P(({ context: e, event: t }) => ({ pendingCreates: [...e.pendingCreates ?? [], t] })), Qa = dt(({ context: e, enqueue: t }) => {
3322
+ let n = e.pendingCreates ?? [];
3323
+ if (n.length !== 0) {
3324
+ t.assign({ pendingCreates: [] });
3325
+ for (let e of n) t.raise(e);
3326
+ }
3327
+ }), $a = L("seedProtocol:PublishManager:index"), eo = ft({
3328
+ types: {
3329
+ context: {},
3330
+ input: {},
3331
+ events: {}
3332
+ },
3333
+ actors: { restoreFromDb: Xa },
3334
+ actions: {
3335
+ assignRestoreFromDb: ta,
3336
+ createPublish: ha,
3337
+ queueCreatePublish: Za,
3338
+ drainPendingCreates: Qa,
3339
+ addSubscription: Pa,
3340
+ requestSavePublish: za,
3341
+ publishDone: Ba,
3342
+ removeSubscription: Va,
3343
+ retryAttestations: ga,
3344
+ stopPublish: Aa,
3345
+ stopAll: Ma,
3346
+ query: Na
3347
+ }
3348
+ }).createMachine({
3349
+ id: "publishManager",
3350
+ initial: "restoreFromDb",
3351
+ context: {
3352
+ publishProcesses: /* @__PURE__ */ new Map(),
3353
+ subscriptions: /* @__PURE__ */ new Map(),
3354
+ pendingCreates: [],
3355
+ settledPublishes: /* @__PURE__ */ new Map()
3356
+ },
3357
+ states: {
3358
+ restoreFromDb: {
3359
+ on: {
3360
+ RESTORE_FROM_DB_DONE: {
3361
+ target: "active",
3362
+ actions: ["assignRestoreFromDb"]
3363
+ },
3364
+ CREATE_PUBLISH: { actions: ["queueCreatePublish"] }
3365
+ },
3366
+ invoke: {
3367
+ src: "restoreFromDb",
3368
+ input: ({ context: e }) => ({ context: e })
3369
+ }
3370
+ },
3371
+ active: {
3372
+ entry: "drainPendingCreates",
3373
+ on: {
3374
+ CREATE_PUBLISH: { actions: ["createPublish"] },
3375
+ ADD_SUBSCRIPTION: { actions: ["addSubscription"] },
3376
+ REQUEST_SAVE_PUBLISH: { actions: ["requestSavePublish"] },
3377
+ SAVE_PUBLISH_DONE: [{
3378
+ guard: ({ event: e }) => e.triggerPublishDone === !0,
3379
+ actions: ["publishDone"]
3380
+ }],
3381
+ PUBLISH_DONE: { actions: ["publishDone"] },
3382
+ REMOVE_SUBSCRIPTION: { actions: ["removeSubscription"] },
3383
+ RETRY_ATTESTATIONS: { actions: ["retryAttestations"] },
3384
+ STOP_PUBLISH: { actions: ["stopPublish"] },
3385
+ QUERY: { actions: ["query"] },
3386
+ STOP_ALL: { actions: ["stopAll"] }
3387
+ }
3388
+ }
3389
+ }
3390
+ }), $ = ut(eo, { input: {
3391
+ publishProcesses: /* @__PURE__ */ new Map(),
3392
+ subscriptions: /* @__PURE__ */ new Map(),
3393
+ pendingCreates: [],
3394
+ settledPublishes: /* @__PURE__ */ new Map()
3395
+ } }), to = !1;
3396
+ function no() {
3397
+ if (!to) {
3398
+ try {
3399
+ $.start();
3400
+ } catch (e) {
3401
+ let t = e instanceof Error ? e.message : String(e);
3402
+ if (!/already started/i.test(t)) throw e;
3403
+ }
3404
+ to = !0;
3405
+ }
3406
+ }
3407
+ ra({
3408
+ savePublish: (e, t, n) => {
3409
+ $.send({
3410
+ type: "REQUEST_SAVE_PUBLISH",
3411
+ seedLocalId: e,
3412
+ publishProcess: t,
3413
+ triggerPublishDone: n?.triggerPublishDone
3414
+ });
3415
+ },
3416
+ onPublishDone: (e) => {
3417
+ $.send({
3418
+ type: "PUBLISH_DONE",
3419
+ seedLocalId: e
3420
+ });
3421
+ },
3422
+ removeSubscription: (e) => {
3423
+ $.send({
3424
+ type: "REMOVE_SUBSCRIPTION",
3425
+ seedLocalId: e
3426
+ });
3427
+ }
3428
+ });
3429
+ var ro = $.subscribe((e) => {
3430
+ $a("PublishManager snapshot:", e);
3431
+ });
3432
+ typeof document < "u" && (no(), window.addEventListener("load", () => {
3433
+ $a("PublishManager started");
3434
+ }), window.addEventListener("beforeunload", () => {
3435
+ ro.unsubscribe(), $.stop();
3436
+ }));
3437
+ var io = {
3438
+ getService: () => $,
3439
+ ready: () => (no(), $.getSnapshot().value === "active" ? Promise.resolve() : new Promise((e) => {
3440
+ let t = $.subscribe((n) => {
3441
+ n.value === "active" && (t.unsubscribe(), e());
3442
+ });
3443
+ $.getSnapshot().value === "active" && (t.unsubscribe(), e());
3444
+ })),
3445
+ createPublish: (e, t, n, r) => new Promise((i) => {
3446
+ let a = da(i);
3447
+ $.send({
3448
+ type: "CREATE_PUBLISH",
3449
+ item: e,
3450
+ address: t,
3451
+ account: n,
3452
+ options: r,
3453
+ createToken: a
3454
+ });
3455
+ }),
3456
+ retryAttestations: (e, t) => $.send({
3457
+ type: "RETRY_ATTESTATIONS",
3458
+ seedLocalId: e,
3459
+ account: t
3460
+ }),
3461
+ stopPublish: (e) => $.send({
3462
+ type: "STOP_PUBLISH",
3463
+ seedLocalId: e
3464
+ }),
3465
+ query: (e) => $.send({
3466
+ type: "QUERY",
3467
+ seedLocalId: e
3468
+ }),
3469
+ stopAll: () => $.send({ type: "STOP_ALL" }),
3470
+ getPublish: (e) => {
3471
+ let t = $.getSnapshot().context;
3472
+ return t.publishProcesses.get(e) ?? t.settledPublishes.get(e);
3473
+ },
3474
+ savePublish: (e, t) => $.send({
3475
+ type: "REQUEST_SAVE_PUBLISH",
3476
+ seedLocalId: e,
3477
+ publishProcess: t
3478
+ }),
3479
+ addSubscription: (e, t) => $.send({
3480
+ type: "ADD_SUBSCRIPTION",
3481
+ seedLocalId: e,
3482
+ newSubscription: t
3483
+ }),
3484
+ removeSubscription: (e) => $.send({
3485
+ type: "REMOVE_SUBSCRIPTION",
3486
+ seedLocalId: e
3487
+ })
3488
+ };
3489
+ //#endregion
3490
+ //#region src/helpers/approvedTargetsForAutomationPublish.ts
3491
+ function ao() {
3492
+ let e = T().modularAccountModuleContract?.trim();
3493
+ if (!e || !/^0x[0-9a-fA-F]{40}$/.test(e)) throw Error("@seedprotocol/publish: automation session keys require PublishConfig.modularAccountModuleContract (executor module only). Do not use defaultApprovedTargetsForModularPublish for server-held keys.");
3494
+ return [e.toLowerCase()];
3495
+ }
3496
+ //#endregion
3497
+ //#region src/helpers/automationSessionKeyPermissions.ts
3498
+ var oo = "publish,revoke";
3499
+ function so(e) {
3500
+ let t = {
3501
+ approvedTargets: ao(),
3502
+ nativeTokenLimitPerTransaction: 0
3503
+ };
3504
+ return typeof e?.expiresAt == "number" && e.expiresAt > 0 && (t.expiresAt = Math.trunc(e.expiresAt)), t;
3505
+ }
3506
+ function co(e, t = oo) {
3507
+ let n = `${[...e.approvedTargets].map((e) => e.toLowerCase()).sort().join(",")}|${e.nativeTokenLimitPerTransaction}|${e.expiresAt ?? 0}|${t.trim()}`;
3508
+ return Ze(Qe(n));
3509
+ }
3510
+ function lo(e) {
3511
+ let t = {
3512
+ approvedTargets: e.approvedTargets,
3513
+ nativeTokenLimitPerTransaction: e.nativeTokenLimitPerTransaction
3514
+ };
3515
+ return e.expiresAt != null && e.expiresAt > 0 ? {
3516
+ ...t,
3517
+ permissionEndTimestamp: /* @__PURE__ */ new Date(e.expiresAt * 1e3)
3518
+ } : t;
3519
+ }
3520
+ //#endregion
3521
+ //#region src/services/publishAuthorization/index.ts
3522
+ var uo = "0x0000000000000000000000000000000000000000", fo = !0, po = "0x0000000000000000000000000000000000000000";
3523
+ function mo(e) {
3524
+ if (w(e)) return e.txSender;
3525
+ if (x(e)) return e;
3526
+ throw Error("@seedprotocol/publish: publish authorization write APIs require a PublishWallet or SeedTxSender");
3527
+ }
3528
+ async function ho(e, t) {
3529
+ let n = await e.sendTransaction(t);
3530
+ return l(n.transactionHash);
3531
+ }
3532
+ function go(e, t) {
3533
+ let n = t.trim();
3534
+ if (!/^0x[0-9a-fA-F]{40}$/.test(n)) throw Error(`@seedprotocol/publish: ${e} must be a valid address`);
3535
+ return n;
3536
+ }
3537
+ function _o() {
3538
+ return st.getSchemaUID(xt, uo, fo);
3539
+ }
3540
+ async function vo(e) {
3541
+ let t = mo(e), n = _o();
3542
+ return await B(n) || (await ho(t, Pt({
3543
+ schema: xt,
3544
+ resolverAddress: uo,
3545
+ revocable: fo
3546
+ })), await ho(t, It({
3547
+ schemaUid: n,
3548
+ schemaName: Ct
3549
+ }))), n;
3550
+ }
3551
+ function yo(e) {
3552
+ return new ot(xt).encodeData([
3553
+ {
3554
+ name: "identity",
3555
+ value: e.identity,
3556
+ type: "address"
3557
+ },
3558
+ {
3559
+ name: "sessionKey",
3560
+ value: e.sessionKey,
3561
+ type: "address"
3562
+ },
3563
+ {
3564
+ name: "app",
3565
+ value: e.app,
3566
+ type: "address"
3567
+ },
3568
+ {
3569
+ name: "scopes",
3570
+ value: e.scopes,
3571
+ type: "string"
3572
+ },
3573
+ {
3574
+ name: "grantedAt",
3575
+ value: e.grantedAt,
3576
+ type: "uint64"
3577
+ },
3578
+ {
3579
+ name: "expiresAt",
3580
+ value: e.expiresAt,
3581
+ type: "uint64"
3582
+ },
3583
+ {
3584
+ name: "permissionsHash",
3585
+ value: jt(e.permissionsHash),
3586
+ type: "bytes32"
3587
+ }
3588
+ ]);
3589
+ }
3590
+ async function bo(e) {
3591
+ let t = mo(e.wallet), n = e.ensureSchema === !1 ? _o() : await vo(e.wallet), r = go("identity", e.identity), i = go("sessionKey", e.sessionKey), a = e.app?.trim() ? go("app", e.app) : po, s = e.grantedAt ?? Math.floor(Date.now() / 1e3), c = typeof e.expiresAt == "number" && e.expiresAt > 0 ? Math.trunc(e.expiresAt) : 0, l = e.scopes ?? Tt, u = jt(e.permissionsHash ?? co(so({ expiresAt: c > 0 ? c : void 0 }), l === Tt ? "publish,revoke" : l));
3592
+ if (u === lt) throw Error("@seedprotocol/publish: attestPublishAuthorization requires a non-zero permissionsHash");
3593
+ let d = typeof e.expirationTime == "number" && e.expirationTime > 0 ? e.expirationTime : c > 0 ? c : s + bt, f = yo({
3594
+ identity: r,
3595
+ sessionKey: i,
3596
+ app: a,
3597
+ scopes: l,
3598
+ grantedAt: s,
3599
+ expiresAt: c,
3600
+ permissionsHash: u
3601
+ }), p = await ho(t, o({
3602
+ schema: n,
3603
+ data: {
3604
+ recipient: i,
3605
+ expirationTime: BigInt(d),
3606
+ revocable: !0,
3607
+ refUID: lt,
3608
+ data: f,
3609
+ value: 0n
3610
+ }
3611
+ }));
3612
+ if (!p) throw Error("@seedprotocol/publish: attestPublishAuthorization failed — no receipt");
3613
+ let { easContractAddress: m } = T(), h = ue(p, m);
3614
+ if (!h || !At(h)) throw Error("@seedprotocol/publish: attestPublishAuthorization failed — could not parse attestation UID");
3615
+ return {
3616
+ uid: h,
3617
+ schemaUid: n,
3618
+ permissionsHash: u,
3619
+ grantedAt: s,
3620
+ expiresAt: c,
3621
+ expirationTime: d
3622
+ };
3623
+ }
3624
+ async function xo(e) {
3625
+ let t = mo(e.wallet), n = e.schemaUid ?? _o(), r = jt(e.uid);
3626
+ if (!At(r)) throw Error("@seedprotocol/publish: revokePublishAuthorization requires a valid attestation uid");
3627
+ if (!await ho(t, p([{
3628
+ schema: n,
3629
+ data: [{ uid: r }]
3630
+ }]))) throw Error("@seedprotocol/publish: revokePublishAuthorization failed — no receipt");
3631
+ }
3632
+ async function So(e) {
3633
+ let t = (await kt({
3634
+ identities: e.identities,
3635
+ excludeRevoked: !1
3636
+ })).find((t) => t.id?.toLowerCase() === e.uid.toLowerCase());
3637
+ if (!t) return null;
3638
+ let n = Ot(t.decodedDataJson ?? "[]"), r = typeof t.expirationTime == "number" ? t.expirationTime : typeof t.expirationTime == "string" ? Number(t.expirationTime) : null;
3639
+ return {
3640
+ uid: t.id,
3641
+ decoded: n,
3642
+ assess: Dt({
3643
+ decoded: n,
3644
+ expirationTime: r
3645
+ }),
3646
+ expirationTime: r
3647
+ };
3648
+ }
3649
+ //#endregion
3650
+ export { Mt as $, vr as A, fr as B, Lr as C, gr as D, pr as E, rr as F, or as G, $n as H, lr as I, Ht as J, hn as K, Tr as L, yr as M, xr as N, hr as O, Cr as P, z as Q, ur as R, Mr as S, Dr as T, cr as U, ir as V, sr as W, B as X, It as Y, Pt as Z, Ti as _, bo as a, Rr as b, _o as c, so as d, Nt as et, co as f, ea as g, io as h, So as i, _r as j, mr as k, xo as l, ao as m, wt as n, yo as o, lo as p, jn as q, Et as r, vo as s, St as t, oo as u, Ei as v, Ir as w, Yr as x, Gr as y, dr as z };
3651
+
3652
+ //# sourceMappingURL=publishAuthorization-DqhhCAhd.js.map