@seedprotocol/publish 0.6.9 → 0.6.10

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