@seedprotocol/publish 0.4.17 → 0.4.20

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 (71) hide show
  1. package/README.md +6 -0
  2. package/dist/config.d.ts +40 -3
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/errors.d.ts +27 -0
  5. package/dist/errors.d.ts.map +1 -1
  6. package/dist/helpers/arweave.d.ts +3 -2
  7. package/dist/helpers/arweave.d.ts.map +1 -1
  8. package/dist/helpers/arweave.test.d.ts +2 -0
  9. package/dist/helpers/arweave.test.d.ts.map +1 -0
  10. package/dist/helpers/constants.d.ts +6 -0
  11. package/dist/helpers/constants.d.ts.map +1 -1
  12. package/dist/helpers/debugPublishIngest.d.ts +2 -0
  13. package/dist/helpers/debugPublishIngest.d.ts.map +1 -0
  14. package/dist/helpers/ensureExecutorModule.d.ts +15 -0
  15. package/dist/helpers/ensureExecutorModule.d.ts.map +1 -0
  16. package/dist/helpers/ensureManagedAccountReady.d.ts +36 -0
  17. package/dist/helpers/ensureManagedAccountReady.d.ts.map +1 -0
  18. package/dist/helpers/ensureManagedAccountReady.test.d.ts +2 -0
  19. package/dist/helpers/ensureManagedAccountReady.test.d.ts.map +1 -0
  20. package/dist/helpers/ensureSmartWalletThenPublish.d.ts +11 -1
  21. package/dist/helpers/ensureSmartWalletThenPublish.d.ts.map +1 -1
  22. package/dist/helpers/publishDisplayHelpers.d.ts +22 -0
  23. package/dist/helpers/publishDisplayHelpers.d.ts.map +1 -1
  24. package/dist/hooks/useArweaveL1Finalize.d.ts +23 -0
  25. package/dist/hooks/useArweaveL1Finalize.d.ts.map +1 -0
  26. package/dist/hooks/useItemPublishStatus.d.ts +8 -0
  27. package/dist/hooks/useItemPublishStatus.d.ts.map +1 -1
  28. package/dist/hooks/usePublishProcess.d.ts.map +1 -1
  29. package/dist/index-BfABV7U1.js +4840 -0
  30. package/dist/index-BfABV7U1.js.map +1 -0
  31. package/dist/index-DhVUuOO3.js +4824 -0
  32. package/dist/index-DhVUuOO3.js.map +1 -0
  33. package/dist/index-P7oBN4Yu.js +4785 -0
  34. package/dist/index-P7oBN4Yu.js.map +1 -0
  35. package/dist/index.d.ts +11 -4
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +110 -4338
  38. package/dist/index.js.map +1 -1
  39. package/dist/react/ConnectButton.d.ts.map +1 -1
  40. package/dist/react/PublishModeButtons.d.ts +15 -0
  41. package/dist/react/PublishModeButtons.d.ts.map +1 -0
  42. package/dist/services/PublishManager/actions/createPublish.d.ts.map +1 -1
  43. package/dist/services/PublishManager/actions/stopAll.d.ts +2 -1
  44. package/dist/services/PublishManager/actions/stopAll.d.ts.map +1 -1
  45. package/dist/services/PublishManager/actors/savePublish.d.ts.map +1 -1
  46. package/dist/services/PublishManager/actors/subscribe.d.ts.map +1 -1
  47. package/dist/services/arweaveL1Finalize/enqueue.d.ts +7 -0
  48. package/dist/services/arweaveL1Finalize/enqueue.d.ts.map +1 -0
  49. package/dist/services/arweaveL1Finalize/worker.d.ts +3 -0
  50. package/dist/services/arweaveL1Finalize/worker.d.ts.map +1 -0
  51. package/dist/services/publish/actors/checking.d.ts.map +1 -1
  52. package/dist/services/publish/actors/createArweaveDataItems.d.ts.map +1 -1
  53. package/dist/services/publish/actors/createArweaveTransactions.d.ts.map +1 -1
  54. package/dist/services/publish/actors/createAttestations.d.ts.map +1 -1
  55. package/dist/services/publish/actors/createAttestationsDirectToEas.d.ts.map +1 -1
  56. package/dist/services/publish/actors/persistSeedUid.d.ts +4 -2
  57. package/dist/services/publish/actors/persistSeedUid.d.ts.map +1 -1
  58. package/dist/services/publish/actors/publishRequestNormalize.d.ts +13 -0
  59. package/dist/services/publish/actors/publishRequestNormalize.d.ts.map +1 -0
  60. package/dist/services/publish/helpers/getPublishUploadData.d.ts +8 -2
  61. package/dist/services/publish/helpers/getPublishUploadData.d.ts.map +1 -1
  62. package/dist/services/upload/uploadMachine.d.ts +1 -1
  63. package/dist/types.d.ts +19 -2
  64. package/dist/types.d.ts.map +1 -1
  65. package/dist/worker-BxY09Tmw.js +73 -0
  66. package/dist/worker-BxY09Tmw.js.map +1 -0
  67. package/dist/worker-Ce8qDQKc.js +73 -0
  68. package/dist/worker-Ce8qDQKc.js.map +1 -0
  69. package/dist/worker-F-UKvyIU.js +73 -0
  70. package/dist/worker-F-UKvyIU.js.map +1 -0
  71. package/package.json +5 -5
@@ -0,0 +1,4840 @@
1
+ import { getGetAdditionalSyncAddresses as An, getAttesterForSeed as vn, getVersionsForSeedUid as Sn, getMetadataAttestationUidsForSeedUid as En, VERSION_SCHEMA_UID_OPTIMISM_SEPOLIA as In, updateSeedRevokedAt as Pn, setGetPublisherForNewSeeds as Un, setRevokeExecutor as Tn, setAdditionalSyncAddresses as Dn, DEFAULT_ARWEAVE_GRAPHQL_URL as xn, client as ft, getSegmentedItemProperties as st, setSchemaUidForModel as He, setSchemaUidForSchemaDefinition as ie, INTERNAL_DATA_TYPES as Cn, getEasSchemaForItemProperty as Rn, getRelatedItemsForPublish as _n, BaseArweaveClient as Ln, Item as se, getCorrectId as Nt, BaseFileManager as j, getUploadPipelineTransactionStatus as Mn, BaseDb as B, arweaveL1FinalizeJobs as De, resolvePublishPayloadValues as ht, getItemPropertiesFromEas as On, updateVersionUid as Bn, itemHasPublishUploadCandidates as Nn, isItemOwned as Ft, validateItemForPublish as Fn, publishProcesses as P, uploadProcesses as kn } from "@seedprotocol/sdk";
2
+ import { prepareContractCall as C, readContract as _, createThirdwebClient as Hn, getContract as V, sendTransaction as k, waitForReceipt as H, parseEventLogs as rt, prepareEvent as Y } from "thirdweb";
3
+ import { createWallet as Ce, inAppWallet as kt } from "thirdweb/wallets";
4
+ import { useActiveAccount as $n, ThirdwebProvider as Vn, ConnectButton as qn, darkTheme as Wn } from "thirdweb/react";
5
+ import { isContractDeployed as Gn } from "thirdweb/utils";
6
+ import { useState as Ae, useRef as Ht, useEffect as te, createContext as jn, useContext as Yn, useMemo as $t } from "react";
7
+ import { optimismSepolia as E } from "thirdweb/chains";
8
+ import K from "debug";
9
+ import { encodeAbiParameters as Vt, decodeAbiParameters as Jn } from "viem";
10
+ import { jsx as me, jsxs as zn } from "react/jsx-runtime";
11
+ import { SeedProvider as Zn, useLiveQuery as ve } from "@seedprotocol/react";
12
+ import { getInstalledModules as Kn, installModule as Qn } from "thirdweb/modules";
13
+ import { SchemaEncoder as Xn, ZERO_BYTES32 as ea, NO_EXPIRATION as ta, SchemaRegistry as $e, ZERO_ADDRESS as Xe } from "@ethereum-attestation-service/eas-sdk";
14
+ import { fromPromise as he, fromCallback as ye, setup as qt, assign as T, enqueueActions as Le, createActor as et } from "xstate";
15
+ import na from "arweave";
16
+ import { ethers as N } from "ethers";
17
+ import { readFile as aa } from "node:fs/promises";
18
+ import { and as sa, eq as Z, desc as fe, notInArray as ra, inArray as oa } from "drizzle-orm";
19
+ import { useSelector as ia } from "@xstate/react";
20
+ async function ca(e) {
21
+ return _({
22
+ contract: e.contract,
23
+ method: [
24
+ "0x8878ed33",
25
+ [
26
+ {
27
+ type: "address",
28
+ name: "_adminSigner"
29
+ },
30
+ {
31
+ type: "bytes",
32
+ name: "_data"
33
+ }
34
+ ],
35
+ [
36
+ {
37
+ type: "address"
38
+ }
39
+ ]
40
+ ],
41
+ params: [e.adminSigner, e.data]
42
+ });
43
+ }
44
+ function da(e) {
45
+ return C({
46
+ contract: e.contract,
47
+ method: [
48
+ "0xd8fd8f44",
49
+ [
50
+ {
51
+ type: "address",
52
+ name: "_admin"
53
+ },
54
+ {
55
+ type: "bytes",
56
+ name: "_data"
57
+ }
58
+ ],
59
+ [
60
+ {
61
+ type: "address"
62
+ }
63
+ ]
64
+ ],
65
+ params: [e.admin, e.data]
66
+ });
67
+ }
68
+ const Wt = "0x4200000000000000000000000000000000000020", la = "0x44d562ac1d7cd77e232978687fea027ace48f719cf1d58c7888e509663bb87fc", Gt = "0x76f47d88bfaf670f5208911181fcdc0e160cb16d", jt = "0x4200000000000000000000000000000000000021", yt = "0xcd8c945872df8e664e55cf8885c85ea3ea8f2148", L = {
69
+ SUCCESS: "success",
70
+ FAILURE: "failure"
71
+ }, ua = [
72
+ "pollingForConfirmation",
73
+ "uploadingData",
74
+ "uploadingViaBundler"
75
+ ], pa = 3e4, ma = K("permaPress:helpers:thirdweb");
76
+ let Ve = null;
77
+ function R() {
78
+ if (!Ve) {
79
+ const { thirdwebClientId: e } = x();
80
+ Ve = Hn({ clientId: e });
81
+ }
82
+ return Ve;
83
+ }
84
+ const Nr = [
85
+ // embeddedWallet(),
86
+ Ce("io.metamask")
87
+ // createWallet("com.coinbase.wallet"),
88
+ // createWallet("me.rainbow"),
89
+ ], Fr = () => {
90
+ const [e, t] = Ae(null);
91
+ return Ce("io.metamask"), Ht(!1), te(() => {
92
+ (async () => {
93
+ })();
94
+ }, []), e;
95
+ }, kr = () => {
96
+ const e = $n(), [t, n] = Ae(null);
97
+ return te(() => {
98
+ !e || !e.address || n(V({
99
+ client: R(),
100
+ chain: E,
101
+ address: e.address
102
+ }));
103
+ }, [e]), t;
104
+ }, Yt = () => {
105
+ const { thirdwebAccountFactoryAddress: e } = x();
106
+ return V({
107
+ client: R(),
108
+ chain: E,
109
+ address: e
110
+ });
111
+ };
112
+ async function Jt(e, t = "0x") {
113
+ const n = Yt();
114
+ return ca({
115
+ contract: n,
116
+ adminSigner: e,
117
+ data: t
118
+ });
119
+ }
120
+ async function Re(e) {
121
+ const t = V({
122
+ client: R(),
123
+ chain: E,
124
+ address: e
125
+ });
126
+ return Gn(t);
127
+ }
128
+ async function gt(e) {
129
+ if (!e)
130
+ return { needsDeploy: !0 };
131
+ if (await Re(e.address))
132
+ return { address: e.address, account: e };
133
+ const n = await Jt(e.address);
134
+ return await Re(n) ? { address: n, account: e } : { needsDeploy: !0 };
135
+ }
136
+ const Hr = [
137
+ Ce("io.metamask"),
138
+ Ce("me.rainbow")
139
+ ], fa = async (e) => {
140
+ const t = Yt(), n = da({
141
+ contract: t,
142
+ admin: e.address,
143
+ data: "0x"
144
+ }), a = await k({
145
+ account: e,
146
+ transaction: n
147
+ });
148
+ ma("createAccountTx result:", a);
149
+ const s = await H({
150
+ client: R(),
151
+ transactionHash: a.transactionHash,
152
+ chain: E
153
+ });
154
+ if (!s)
155
+ throw new Error("Failed to deploy smart wallet");
156
+ return s;
157
+ }, $r = {
158
+ name: "Seed Protocol",
159
+ description: "Seed Protocol",
160
+ url: "https://seedprotocol.io"
161
+ };
162
+ async function ot(e = E) {
163
+ const t = Me();
164
+ await t.autoConnect({ client: R(), chain: e });
165
+ const n = t.getAccount();
166
+ if (!n)
167
+ throw new Error("Failed to get managed account");
168
+ return n.address;
169
+ }
170
+ async function ha() {
171
+ try {
172
+ const e = it();
173
+ return await e.autoConnect({ client: R(), chain: E }), e.getAccount() ?? null;
174
+ } catch {
175
+ return null;
176
+ }
177
+ }
178
+ const Me = () => kt({
179
+ auth: {
180
+ options: [
181
+ "farcaster",
182
+ "email",
183
+ "passkey",
184
+ "phone"
185
+ ]
186
+ },
187
+ executionMode: {
188
+ mode: "EIP4337",
189
+ smartAccount: {
190
+ chain: E,
191
+ factoryAddress: Gt,
192
+ gasless: !0
193
+ }
194
+ }
195
+ // executionMode: {
196
+ // mode: 'EIP4337',
197
+ // smartAccount: {
198
+ // chain: optimismSepolia,
199
+ // factoryAddress: thirdwebAccountFactoryAddress,
200
+ // gasless: true,
201
+ // overrides: {
202
+ // // Custom paymaster that passes through but lets you modify the UserOp
203
+ // paymaster: async (userOp) => {
204
+ // const hexifyBigInts: any = (obj: any) => {
205
+ // if (typeof obj === "bigint") return `0x${obj.toString(16)}`;
206
+ // if (Array.isArray(obj)) return obj.map(hexifyBigInts);
207
+ // if (obj && typeof obj === "object") {
208
+ // return Object.fromEntries(
209
+ // Object.entries(obj).map(([k, v]) => [k, hexifyBigInts(v)])
210
+ // );
211
+ // }
212
+ // return obj;
213
+ // };
214
+ // const chainIdHex = `0x${optimismSepolia.id.toString(16)}`;
215
+ // // Increase callGasLimit before sending to paymaster
216
+ // const modifiedUserOp = hexifyBigInts({
217
+ // ...userOp,
218
+ // callGasLimit: BigInt(8000000), // Double it, or set a fixed value
219
+ // });
220
+ // console.log("[SmartWallet Paymaster]", getPublishConfig().thirdwebClientId);
221
+ // // Call thirdweb's default paymaster endpoint
222
+ // const response = await fetch(
223
+ // `https://${optimismSepolia.id}.bundler.thirdweb.com/v2`,
224
+ // {
225
+ // method: "POST",
226
+ // headers: {
227
+ // "Content-Type": "application/json",
228
+ // "X-Client-Id": getPublishConfig().thirdwebClientId,
229
+ // },
230
+ // body: JSON.stringify({
231
+ // id: 1,
232
+ // jsonrpc: "2.0",
233
+ // method: "pm_sponsorUserOperation",
234
+ // params: [modifiedUserOp, '0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789', chainIdHex],
235
+ // }),
236
+ // }
237
+ // );
238
+ // const data = await response.json();
239
+ // console.log("[SmartWallet Paymaster Response]", data);
240
+ // return {
241
+ // paymasterAndData: data.result.paymasterAndData,
242
+ // preVerificationGas: data.result.preVerificationGas,
243
+ // verificationGasLimit: data.result.verificationGasLimit,
244
+ // callGasLimit: data.result.callGasLimit,
245
+ // };
246
+ // },
247
+ // execute: (accountContract, transaction) => {
248
+ // // Log the gas that was set on the transaction
249
+ // console.log("[SmartWallet Execute]", {
250
+ // gas: transaction.gas,
251
+ // to: transaction.to,
252
+ // dataLength: transaction.data?.length,
253
+ // });
254
+ // // Return the default execute call — don't change behavior,
255
+ // // just observe what's being passed through
256
+ // return prepareContractCall({
257
+ // contract: accountContract,
258
+ // method: "function execute(address, uint256, bytes)",
259
+ // params: [
260
+ // transaction.to ?? "",
261
+ // transaction.value ?? 0n,
262
+ // transaction.data ?? "0x",
263
+ // ],
264
+ // gas: transaction.gas, // Pass through whatever was set
265
+ // });
266
+ // },
267
+ // },
268
+ // }
269
+ // }
270
+ }), it = () => kt({
271
+ auth: {
272
+ options: [
273
+ "farcaster",
274
+ "email",
275
+ "passkey",
276
+ "phone"
277
+ ]
278
+ },
279
+ executionMode: {
280
+ mode: "EIP7702",
281
+ sponsorGas: !0
282
+ }
283
+ }), ya = () => [
284
+ it()
285
+ ], ga = [
286
+ { type: "error", name: "AccessDenied", inputs: [] },
287
+ { type: "error", name: "AlreadyRevoked", inputs: [] },
288
+ { type: "error", name: "InvalidRevocation", inputs: [] },
289
+ { type: "error", name: "InvalidRevocations", inputs: [] },
290
+ { type: "error", name: "InvalidSchema", inputs: [] },
291
+ { type: "error", name: "Irrevocable", inputs: [] },
292
+ { type: "error", name: "NotFound", inputs: [] },
293
+ { type: "error", name: "NotPayable", inputs: [] },
294
+ { type: "error", name: "InsufficientValue", inputs: [] },
295
+ { type: "error", name: "InvalidLength", inputs: [] }
296
+ ], wa = () => Y({
297
+ signature: "event Attested(address indexed recipient, address indexed attester, bytes32 uid, bytes32 indexed schemaUID)"
298
+ }), ba = "0x0000000000000000000000000000000000000000", W = "0x" + "0".repeat(64);
299
+ function wt(e, t, n) {
300
+ const { easContractAddress: a } = x(), s = V({
301
+ client: e,
302
+ chain: t,
303
+ address: a
304
+ });
305
+ return C({
306
+ contract: s,
307
+ method: "function attest((bytes32 schema,(address recipient,uint64 expirationTime,bool revocable,bytes32 refUID,bytes data,uint256 value) data) request) payable returns (bytes32)",
308
+ params: [
309
+ {
310
+ schema: n.schema,
311
+ data: {
312
+ recipient: n.data.recipient ?? ba,
313
+ expirationTime: n.data.expirationTime ?? 0n,
314
+ revocable: n.data.revocable ?? !0,
315
+ refUID: n.data.refUID,
316
+ data: n.data.data,
317
+ value: n.data.value ?? 0n
318
+ }
319
+ }
320
+ ]
321
+ });
322
+ }
323
+ function Aa(e, t, n) {
324
+ const { easContractAddress: a } = x(), s = V({
325
+ client: e,
326
+ chain: t,
327
+ address: a
328
+ });
329
+ return C({
330
+ contract: s,
331
+ method: "function multiAttest((bytes32 schema,(address recipient,uint64 expirationTime,bool revocable,bytes32 refUID,bytes data,uint256 value)[] data)[] requests) payable returns (bytes32[])",
332
+ params: [n]
333
+ });
334
+ }
335
+ function qe(e) {
336
+ return Vt([{ type: "bytes32" }], [e]);
337
+ }
338
+ function bt(e, t) {
339
+ if (!e.logs?.length) return;
340
+ const n = t.toLowerCase(), a = e.logs.filter((s) => s.address && s.address.toLowerCase() === n);
341
+ if (a.length)
342
+ try {
343
+ const o = rt({
344
+ logs: a,
345
+ events: [wa()],
346
+ strict: !1
347
+ })[0]?.args?.uid;
348
+ if (o && o !== W) return o;
349
+ } catch {
350
+ }
351
+ }
352
+ function va(e, t, n) {
353
+ const { easContractAddress: a } = x(), s = V({
354
+ client: e,
355
+ chain: t,
356
+ address: a,
357
+ abi: [...ga]
358
+ });
359
+ return C({
360
+ contract: s,
361
+ method: "function multiRevoke((bytes32 schema,(bytes32 uid,uint256 value)[] data)[] multiRequests) payable",
362
+ params: [
363
+ n.map((r) => ({
364
+ schema: r.schema,
365
+ data: r.data.map((o) => ({
366
+ uid: o.uid,
367
+ value: o.value ?? 0n
368
+ }))
369
+ }))
370
+ ]
371
+ });
372
+ }
373
+ async function Sa(e) {
374
+ const { account: t, attester: n } = e;
375
+ if (!n || t.address.toLowerCase() === n.toLowerCase())
376
+ return t;
377
+ const a = An();
378
+ if (a) {
379
+ const s = await a(), r = n.toLowerCase();
380
+ if (s?.some((o) => o?.toLowerCase() === r))
381
+ throw new Error(
382
+ "Revocation not supported for items published via the modular executor."
383
+ );
384
+ }
385
+ try {
386
+ const s = await Jt(t.address), r = n.toLowerCase(), o = s.toLowerCase();
387
+ if (r === o && await Re(s)) {
388
+ const i = Me();
389
+ await i.autoConnect({
390
+ client: R(),
391
+ chain: E
392
+ });
393
+ const l = i.getAccount();
394
+ if (l)
395
+ return l;
396
+ }
397
+ } catch {
398
+ }
399
+ return t;
400
+ }
401
+ async function Ea(e) {
402
+ const { seedLocalId: t, seedUid: n, seedSchemaUid: a } = e, s = await ha();
403
+ if (!s)
404
+ throw new Error("No wallet connected. Connect a wallet to revoke attestations.");
405
+ const r = await vn({ seedLocalId: t, seedUid: n }), o = await Sa({ account: s, attester: r }), c = R(), [i, l] = await Promise.all([
406
+ Sn(n),
407
+ En(n)
408
+ ]), d = i.map((u) => u.uid), m = /* @__PURE__ */ new Map();
409
+ for (const { uid: u, schemaUid: y } of l) {
410
+ const f = m.get(y) ?? [];
411
+ f.push(u), m.set(y, f);
412
+ }
413
+ const p = [];
414
+ for (const [u, y] of m)
415
+ y.length > 0 && p.push({
416
+ schema: u,
417
+ data: y.map((f) => ({ uid: f }))
418
+ });
419
+ d.length > 0 && p.push({
420
+ schema: In,
421
+ data: d.map((u) => ({ uid: u }))
422
+ }), p.push({
423
+ schema: a,
424
+ data: [{ uid: n }]
425
+ });
426
+ for (const u of p) {
427
+ if (u.data.length === 0) continue;
428
+ const y = va(c, E, [u]);
429
+ try {
430
+ const f = await k({ account: o, transaction: y });
431
+ await H({
432
+ client: c,
433
+ chain: E,
434
+ transactionHash: f.transactionHash
435
+ });
436
+ } catch (f) {
437
+ const b = f instanceof Error ? f.message : String(f);
438
+ if (b.includes("AccessDenied") || b.includes("0x4ca88867"))
439
+ throw new Error(
440
+ "Only the original attester can revoke attestations. Connect the wallet that published this item."
441
+ );
442
+ if (b.includes("AlreadyRevoked"))
443
+ continue;
444
+ throw f;
445
+ }
446
+ }
447
+ const h = Math.floor(Date.now() / 1e3);
448
+ await Pn({ seedLocalId: t, revokedAt: h });
449
+ }
450
+ let ct = null;
451
+ function Ia(e) {
452
+ ct = e;
453
+ }
454
+ function Pa() {
455
+ return ct;
456
+ }
457
+ function zt(e) {
458
+ Ia(e), Un(async () => {
459
+ try {
460
+ return await ot(E);
461
+ } catch {
462
+ return;
463
+ }
464
+ }), Tn(Ea), import("./worker-F-UKvyIU.js").then((t) => {
465
+ t.startArweaveL1FinalizeWorker();
466
+ }), Dn(async () => e.useModularExecutor && e.modularAccountModuleContract ? [e.modularAccountModuleContract] : []);
467
+ }
468
+ const Vr = zt;
469
+ function x() {
470
+ const e = ct;
471
+ if (!e)
472
+ throw new Error(
473
+ "@seedprotocol/publish: Call initPublish() or ensure PublishProvider is mounted with config before using the publish package"
474
+ );
475
+ const t = e.useArweaveBundler ?? !1, n = e.arweaveUploadVerificationBaseUrl ?? e.uploadApiBaseUrl, a = e.arweaveGraphqlUrl ?? xn;
476
+ return {
477
+ ...e,
478
+ thirdwebAccountFactoryAddress: Gt,
479
+ easContractAddress: jt,
480
+ useIntegerLocalIds: e.useIntegerLocalIds ?? !1,
481
+ useDirectEas: e.useDirectEas ?? !1,
482
+ modularAccountModuleData: e.modularAccountModuleData ?? "0x",
483
+ useModularExecutor: e.useModularExecutor ?? !1,
484
+ useArweaveBundler: t,
485
+ arweaveUploadVerificationBaseUrl: n,
486
+ arweaveGraphqlUrl: a,
487
+ autoDeployManagedAccount: e.autoDeployManagedAccount ?? !1
488
+ };
489
+ }
490
+ class Zt extends Error {
491
+ constructor(t, n, a, s, r = "METADATA_PROPERTIES_MISSING") {
492
+ super(t), this.seedLocalId = n, this.expectedSchemas = a, this.foundSchemas = s, this.code = r, this.name = "AttestationVerificationError";
493
+ }
494
+ }
495
+ class Q extends Error {
496
+ constructor(t, n, a, s) {
497
+ super(t), this.code = n, this.managedAddress = a, this.name = "ManagedAccountPublishError", this.underlyingCause = s;
498
+ }
499
+ /** Original error when connection or deployment failed (avoids shadowing `Error.cause`). */
500
+ underlyingCause;
501
+ }
502
+ function At(e) {
503
+ if (e instanceof Q) return !0;
504
+ if (typeof e != "object" || e === null) return !1;
505
+ const t = e;
506
+ return t.name === "ManagedAccountPublishError" && typeof t.code == "string";
507
+ }
508
+ function Ua(e, t = 700) {
509
+ if (e == null) return "";
510
+ if (e instanceof Error) {
511
+ const n = e.cause instanceof Error ? ` | cause: ${e.cause.message}` : "";
512
+ return (e.message + n).slice(0, t);
513
+ }
514
+ if (typeof e == "object") {
515
+ const n = e, a = [];
516
+ if (typeof n.message == "string" && a.push(n.message), typeof n.shortMessage == "string" && a.push(n.shortMessage), typeof n.details == "string" && a.push(n.details), typeof n.reason == "string" && a.push(n.reason), a.length) return a.join(" | ").slice(0, t);
517
+ try {
518
+ return JSON.stringify(e).slice(0, t);
519
+ } catch {
520
+ return String(e).slice(0, t);
521
+ }
522
+ }
523
+ return String(e).slice(0, t);
524
+ }
525
+ function Ta(e) {
526
+ return /Router:\s*function does not exist/i.test(Ua(e));
527
+ }
528
+ const Kt = jn(null);
529
+ function Da() {
530
+ const e = Yn(Kt);
531
+ if (!e)
532
+ throw new Error("usePublishConfig must be used within PublishProvider");
533
+ return e;
534
+ }
535
+ const qr = ({
536
+ children: e,
537
+ config: t,
538
+ queryClient: n,
539
+ queryClientRef: a
540
+ }) => (te(() => {
541
+ t && zt(t);
542
+ }, [t]), /* @__PURE__ */ me(Kt.Provider, { value: t ?? Pa(), children: /* @__PURE__ */ me(Vn, { children: /* @__PURE__ */ me(Zn, { queryClient: n, queryClientRef: a, children: e }) }) })), xa = "The executor module could not be installed on your publishing account on Optimism Sepolia. Reconnect and try again, or contact support if this persists.";
543
+ async function tt(e, t, n) {
544
+ const { modularAccountModuleContract: a } = n;
545
+ if (!a) return;
546
+ const s = V({
547
+ client: R(),
548
+ chain: E,
549
+ address: e
550
+ });
551
+ try {
552
+ const r = await Kn({ contract: s }), o = a.toLowerCase();
553
+ if (r.some(
554
+ (d) => d.implementation?.toLowerCase() === o
555
+ )) return;
556
+ const i = Qn({
557
+ contract: s,
558
+ moduleContract: a,
559
+ data: Vt([{ type: "address" }], [jt])
560
+ }), l = await k({ transaction: i, account: t });
561
+ await H({
562
+ client: R(),
563
+ transactionHash: l.transactionHash,
564
+ chain: E
565
+ });
566
+ } catch (r) {
567
+ if (Ta(r))
568
+ return;
569
+ throw new Q(
570
+ xa,
571
+ "EXECUTOR_MODULE_NOT_INSTALLED",
572
+ e,
573
+ r
574
+ );
575
+ }
576
+ }
577
+ function Se(e) {
578
+ console.error("[ConnectButton] Wallet setup / module install failed:", e), x().onWalletSetupWarning?.(e);
579
+ }
580
+ async function Ca(e, t, n) {
581
+ if (n.modularAccountModuleContract) {
582
+ if (n.useModularExecutor) {
583
+ if (!t) {
584
+ Se(
585
+ new Error(
586
+ "Executor module: managed account address not available yet (managed wallet may still be syncing)."
587
+ )
588
+ );
589
+ return;
590
+ }
591
+ try {
592
+ const a = Me();
593
+ await a.autoConnect({ client: R(), chain: E });
594
+ const s = a.getAccount();
595
+ if (!s) {
596
+ Se(new Error("Executor module: managed wallet has no account"));
597
+ return;
598
+ }
599
+ await tt(t, s, n);
600
+ } catch (a) {
601
+ Se(a);
602
+ }
603
+ return;
604
+ }
605
+ try {
606
+ await tt(e.address, e, n);
607
+ } catch (a) {
608
+ Se(a);
609
+ }
610
+ }
611
+ }
612
+ const Wr = () => {
613
+ const e = Da(), t = async () => {
614
+ console.log("[ConnectButton] Disconnected");
615
+ try {
616
+ await ft.setAddresses([]);
617
+ } catch (a) {
618
+ console.warn("[ConnectButton] Failed to clear seed client addresses:", a);
619
+ }
620
+ }, n = async (a, s) => {
621
+ const r = a.getAccount();
622
+ if (!r) return;
623
+ console.log("[ConnectButton] Connected", r.address);
624
+ const o = /* @__PURE__ */ new Set([r.address.toLowerCase()]);
625
+ let c;
626
+ if (e.useModularExecutor)
627
+ try {
628
+ c = await ot(E), o.add(c.toLowerCase());
629
+ } catch {
630
+ }
631
+ try {
632
+ await ft.setAddresses({ owned: [...o] });
633
+ } catch (i) {
634
+ console.warn("[ConnectButton] Failed to set seed client addresses:", i);
635
+ }
636
+ await Ca(r, c, e);
637
+ };
638
+ return /* @__PURE__ */ me(
639
+ qn,
640
+ {
641
+ client: R(),
642
+ wallets: ya(),
643
+ autoConnect: !0,
644
+ chain: E,
645
+ chains: [E],
646
+ onConnect: n,
647
+ onDisconnect: t,
648
+ theme: Wn({
649
+ colors: {
650
+ primaryButtonBg: "#1D2939",
651
+ primaryButtonText: "#FFFFFF",
652
+ secondaryButtonHoverBg: "#1D2939",
653
+ connectedButtonBg: "#101828",
654
+ connectedButtonBgHover: "#1D2939",
655
+ borderColor: "#344054"
656
+ }
657
+ })
658
+ }
659
+ );
660
+ }, Gr = ({
661
+ value: e,
662
+ onChange: t,
663
+ disabled: n = !1,
664
+ "aria-label": a = "Publish mode"
665
+ }) => {
666
+ const s = {
667
+ display: "inline-flex",
668
+ gap: 8,
669
+ flexWrap: "wrap"
670
+ }, r = (o) => ({
671
+ padding: "8px 14px",
672
+ fontSize: 13,
673
+ borderRadius: 8,
674
+ border: `1px solid ${o ? "#344054" : "#D0D5DD"}`,
675
+ background: o ? "#101828" : "#fff",
676
+ color: o ? "#fff" : "#344054",
677
+ cursor: n ? "not-allowed" : "pointer",
678
+ opacity: n ? 0.6 : 1
679
+ });
680
+ return /* @__PURE__ */ zn("div", { role: "group", "aria-label": a, style: s, children: [
681
+ /* @__PURE__ */ me(
682
+ "button",
683
+ {
684
+ type: "button",
685
+ disabled: n,
686
+ style: r(e === "patch"),
687
+ onClick: () => t("patch"),
688
+ children: "Publish updates"
689
+ }
690
+ ),
691
+ /* @__PURE__ */ me(
692
+ "button",
693
+ {
694
+ type: "button",
695
+ disabled: n,
696
+ style: r(e === "new_version"),
697
+ onClick: () => t("new_version"),
698
+ children: "New version"
699
+ }
700
+ )
701
+ ] });
702
+ }, Ra = [
703
+ {
704
+ inputs: [{ internalType: "bytes32", name: "uid", type: "bytes32" }],
705
+ name: "getSchema",
706
+ outputs: [
707
+ {
708
+ components: [
709
+ { internalType: "bytes32", name: "uid", type: "bytes32" },
710
+ { internalType: "contract ISchemaResolver", name: "resolver", type: "address" },
711
+ { internalType: "bool", name: "revocable", type: "bool" },
712
+ { internalType: "string", name: "schema", type: "string" }
713
+ ],
714
+ internalType: "struct SchemaRecord",
715
+ name: "",
716
+ type: "tuple"
717
+ }
718
+ ],
719
+ stateMutability: "view",
720
+ type: "function"
721
+ },
722
+ {
723
+ inputs: [
724
+ { internalType: "string", name: "schema", type: "string" },
725
+ { internalType: "contract ISchemaResolver", name: "resolver", type: "address" },
726
+ { internalType: "bool", name: "revocable", type: "bool" }
727
+ ],
728
+ name: "register",
729
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
730
+ stateMutability: "nonpayable",
731
+ type: "function"
732
+ }
733
+ ], _a = "0x" + "0".repeat(64);
734
+ function La(e, t) {
735
+ return V({
736
+ client: e,
737
+ chain: t,
738
+ address: Wt,
739
+ abi: Ra
740
+ });
741
+ }
742
+ const Ma = "function getSchema(bytes32 uid) view returns ((bytes32 uid, address resolver, bool revocable, string schema))";
743
+ async function Ee(e, t, n) {
744
+ const a = V({
745
+ client: e,
746
+ chain: t,
747
+ address: Wt
748
+ // No ABI - use string method so thirdweb parses the exact signature and produces correct selector
749
+ }), s = await _({
750
+ contract: a,
751
+ method: Ma,
752
+ params: [n]
753
+ });
754
+ return !s || s.uid === _a ? null : s;
755
+ }
756
+ function We(e, t, n) {
757
+ const a = La(e, t);
758
+ return C({
759
+ contract: a,
760
+ method: "register",
761
+ params: [n.schema, n.resolverAddress, n.revocable]
762
+ });
763
+ }
764
+ const Oa = "0x0000000000000000000000000000000000000000";
765
+ function Ge(e, t, n) {
766
+ const s = new Xn("bytes32 schemaId,string name").encodeData([
767
+ { name: "schemaId", value: n.schemaUid, type: "bytes32" },
768
+ { name: "name", value: n.schemaName, type: "string" }
769
+ ]), { easContractAddress: r } = x(), o = V({
770
+ client: e,
771
+ chain: t,
772
+ address: r
773
+ // No ABI - use string method so thirdweb parses the exact signature
774
+ });
775
+ return C({
776
+ contract: o,
777
+ method: "function attest((bytes32 schema,(address recipient,uint64 expirationTime,bool revocable,bytes32 refUID,bytes data,uint256 value) data) request) payable returns (bytes32)",
778
+ params: [
779
+ {
780
+ schema: la,
781
+ data: {
782
+ recipient: Oa,
783
+ expirationTime: BigInt(ta),
784
+ revocable: !0,
785
+ refUID: ea,
786
+ data: s,
787
+ value: 0n
788
+ }
789
+ }
790
+ ]
791
+ });
792
+ }
793
+ const ce = "0x0000000000000000000000000000000000000000", de = !0;
794
+ function je(e) {
795
+ return e.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
796
+ }
797
+ async function Ba(e) {
798
+ const { itemRelationProperties: t, itemImageProperties: n, itemListProperties: a } = await st(e), s = /* @__PURE__ */ new Set();
799
+ e.modelName && s.add(e.modelName);
800
+ for (const r of t) {
801
+ const o = r.propertyDef?.ref;
802
+ o && s.add(o);
803
+ }
804
+ for (const r of n) {
805
+ const o = r.propertyDef?.dataType;
806
+ o === "File" ? s.add("File") : o === "Html" ? s.add("Html") : s.add("Image");
807
+ }
808
+ for (const r of a) {
809
+ const o = r.propertyDef?.ref;
810
+ o && s.add(o);
811
+ }
812
+ return s;
813
+ }
814
+ async function Oe(e, t, n, a) {
815
+ const { itemBasicProperties: s, itemRelationProperties: r, itemImageProperties: o, itemListProperties: c } = await st(e), i = [
816
+ ...s,
817
+ ...r,
818
+ ...o,
819
+ ...c
820
+ ], l = /* @__PURE__ */ new Set(), d = await Ba(e), m = /* @__PURE__ */ new Set();
821
+ for (const f of d) {
822
+ const b = `bytes32 ${je(f)}`, g = $e.getSchemaUID(
823
+ b,
824
+ ce,
825
+ de
826
+ );
827
+ if (await Ee(n, a, g)) {
828
+ He({ modelName: f, schemaUid: g });
829
+ continue;
830
+ }
831
+ if (m.has(g)) {
832
+ He({ modelName: f, schemaUid: g });
833
+ continue;
834
+ }
835
+ try {
836
+ const v = We(n, a, {
837
+ schema: b,
838
+ resolverAddress: ce,
839
+ revocable: de
840
+ }), I = await k({
841
+ account: t,
842
+ transaction: v
843
+ });
844
+ await H({
845
+ client: n,
846
+ chain: a,
847
+ transactionHash: I.transactionHash
848
+ });
849
+ } catch (v) {
850
+ throw new Error(
851
+ `Failed to register EAS schema for model ${f}: ${v instanceof Error ? v.message : String(v)}`
852
+ );
853
+ }
854
+ try {
855
+ const v = Ge(n, a, {
856
+ schemaUid: g,
857
+ schemaName: je(f)
858
+ }), I = await k({
859
+ account: t,
860
+ transaction: v
861
+ });
862
+ await H({
863
+ client: n,
864
+ chain: a,
865
+ transactionHash: I.transactionHash
866
+ });
867
+ } catch (v) {
868
+ throw new Error(
869
+ `Failed to name EAS schema for model ${f}: ${v instanceof Error ? v.message : String(v)}`
870
+ );
871
+ }
872
+ m.add(g), He({ modelName: f, schemaUid: g });
873
+ }
874
+ const p = "string storage_transaction_id", h = $e.getSchemaUID(
875
+ p,
876
+ ce,
877
+ de
878
+ );
879
+ if (await Ee(n, a, h))
880
+ ie({ text: p, schemaUid: h });
881
+ else if (!l.has(h) && (d.has("Image") || d.has("File") || d.has("Html"))) {
882
+ try {
883
+ const f = We(n, a, {
884
+ schema: p,
885
+ resolverAddress: ce,
886
+ revocable: de
887
+ }), b = await k({ account: t, transaction: f });
888
+ await H({ client: n, chain: a, transactionHash: b.transactionHash });
889
+ const g = Ge(n, a, {
890
+ schemaUid: h,
891
+ schemaName: "storage_transaction_id"
892
+ }), S = await k({ account: t, transaction: g });
893
+ await H({ client: n, chain: a, transactionHash: S.transactionHash });
894
+ } catch (f) {
895
+ throw new Error(
896
+ `Failed to register EAS schema for storageTransactionId: ${f instanceof Error ? f.message : String(f)}`
897
+ );
898
+ }
899
+ l.add(h), ie({ text: p, schemaUid: h });
900
+ }
901
+ for (const f of i) {
902
+ if (!f.propertyDef) continue;
903
+ const b = Cn[f.propertyDef.dataType]?.eas ?? "string", g = f, S = g.storagePropertyName && g.storagePropertyName.length > 0 ? g.storagePropertyName : f.propertyName, v = je(S), I = `${b} ${v}`, D = [
904
+ "string",
905
+ "address",
906
+ "bool",
907
+ "bytes",
908
+ "bytes32",
909
+ "uint8",
910
+ "uint16",
911
+ "uint32",
912
+ "uint64",
913
+ "uint128",
914
+ "uint256"
915
+ ].includes(b) ? b : void 0;
916
+ let w = await Rn({
917
+ schemaUid: f.schemaUid,
918
+ propertyName: S,
919
+ easDataType: D
920
+ });
921
+ if (w) {
922
+ const A = await Ee(n, a, w.id);
923
+ if (A && A.schema === I) {
924
+ ie({ text: I, schemaUid: w.id });
925
+ continue;
926
+ }
927
+ }
928
+ const U = $e.getSchemaUID(I, ce, de);
929
+ if (await Ee(n, a, U)) {
930
+ ie({ text: I, schemaUid: U });
931
+ continue;
932
+ }
933
+ if (l.has(U)) {
934
+ ie({ text: I, schemaUid: U });
935
+ continue;
936
+ }
937
+ try {
938
+ const A = We(n, a, {
939
+ schema: I,
940
+ resolverAddress: ce,
941
+ revocable: de
942
+ }), M = await k({
943
+ account: t,
944
+ transaction: A
945
+ });
946
+ await H({
947
+ client: n,
948
+ chain: a,
949
+ transactionHash: M.transactionHash
950
+ });
951
+ } catch (A) {
952
+ throw new Error(
953
+ `Failed to register EAS schema for property ${f.propertyName}: ${A instanceof Error ? A.message : String(A)}`
954
+ );
955
+ }
956
+ try {
957
+ const A = Ge(n, a, {
958
+ schemaUid: U,
959
+ schemaName: v
960
+ }), M = await k({
961
+ account: t,
962
+ transaction: A
963
+ });
964
+ await H({
965
+ client: n,
966
+ chain: a,
967
+ transactionHash: M.transactionHash
968
+ });
969
+ } catch (A) {
970
+ throw new Error(
971
+ `Failed to name EAS schema for property ${f.propertyName}: ${A instanceof Error ? A.message : String(A)}`
972
+ );
973
+ }
974
+ l.add(U), ie({ text: I, schemaUid: U });
975
+ }
976
+ const y = await _n(e);
977
+ for (const f of y)
978
+ await Oe(f, t, n, a);
979
+ }
980
+ function jr(e = {}) {
981
+ return Y({
982
+ signature: "event AdminUpdated(address indexed signer, bool isAdmin)",
983
+ filters: e
984
+ });
985
+ }
986
+ function Yr() {
987
+ return Y({
988
+ signature: "event Initialized(uint8 version)"
989
+ });
990
+ }
991
+ function Jr(e = {}) {
992
+ return Y({
993
+ signature: "event SignerPermissionsUpdated(address indexed authorizingSigner, address indexed targetSigner, (address signer, uint8 isAdmin, address[] approvedTargets, uint256 nativeTokenLimitPerTransaction, uint128 permissionStartTimestamp, uint128 permissionEndTimestamp, uint128 reqValidityStartTimestamp, uint128 reqValidityEndTimestamp, bytes32 uid) permissions)",
994
+ filters: e
995
+ });
996
+ }
997
+ function zr() {
998
+ return Y({
999
+ signature: "event ContractURIUpdated(string prevURI, string newURI)"
1000
+ });
1001
+ }
1002
+ function Na() {
1003
+ return Y({
1004
+ signature: "event CreatedAttestation((bytes32 schemaUid, bytes32 attestationUid) result)"
1005
+ });
1006
+ }
1007
+ function Zr() {
1008
+ return Y({
1009
+ signature: "event EIP712DomainChanged()"
1010
+ });
1011
+ }
1012
+ function Kr() {
1013
+ return Y({
1014
+ signature: "event Log(string message)"
1015
+ });
1016
+ }
1017
+ function Qr(e = {}) {
1018
+ return Y({
1019
+ signature: "event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
1020
+ filters: e
1021
+ });
1022
+ }
1023
+ function Fa() {
1024
+ return Y({
1025
+ signature: "event SeedPublished(bytes returnedDataFromEAS)"
1026
+ });
1027
+ }
1028
+ async function Xr(e) {
1029
+ return _({
1030
+ contract: e.contract,
1031
+ method: [
1032
+ "0xb0d691fe",
1033
+ [],
1034
+ [
1035
+ {
1036
+ type: "address"
1037
+ }
1038
+ ]
1039
+ ],
1040
+ params: []
1041
+ });
1042
+ }
1043
+ async function eo(e) {
1044
+ return _({
1045
+ contract: e.contract,
1046
+ method: [
1047
+ "0xc45a0155",
1048
+ [],
1049
+ [
1050
+ {
1051
+ type: "address"
1052
+ }
1053
+ ]
1054
+ ],
1055
+ params: []
1056
+ });
1057
+ }
1058
+ async function to(e) {
1059
+ return _({
1060
+ contract: e.contract,
1061
+ method: [
1062
+ "0x8b52d723",
1063
+ [],
1064
+ [
1065
+ {
1066
+ type: "tuple[]",
1067
+ name: "signers",
1068
+ components: [
1069
+ {
1070
+ type: "address",
1071
+ name: "signer"
1072
+ },
1073
+ {
1074
+ type: "address[]",
1075
+ name: "approvedTargets"
1076
+ },
1077
+ {
1078
+ type: "uint256",
1079
+ name: "nativeTokenLimitPerTransaction"
1080
+ },
1081
+ {
1082
+ type: "uint128",
1083
+ name: "startTimestamp"
1084
+ },
1085
+ {
1086
+ type: "uint128",
1087
+ name: "endTimestamp"
1088
+ }
1089
+ ]
1090
+ }
1091
+ ]
1092
+ ],
1093
+ params: []
1094
+ });
1095
+ }
1096
+ async function no(e) {
1097
+ return _({
1098
+ contract: e.contract,
1099
+ method: [
1100
+ "0xe9523c97",
1101
+ [],
1102
+ [
1103
+ {
1104
+ type: "address[]"
1105
+ }
1106
+ ]
1107
+ ],
1108
+ params: []
1109
+ });
1110
+ }
1111
+ async function ao(e) {
1112
+ return _({
1113
+ contract: e.contract,
1114
+ method: [
1115
+ "0x4a00cc48",
1116
+ [],
1117
+ [
1118
+ {
1119
+ type: "tuple[]",
1120
+ components: [
1121
+ {
1122
+ type: "tuple",
1123
+ name: "metadata",
1124
+ components: [
1125
+ {
1126
+ type: "string",
1127
+ name: "name"
1128
+ },
1129
+ {
1130
+ type: "string",
1131
+ name: "metadataURI"
1132
+ },
1133
+ {
1134
+ type: "address",
1135
+ name: "implementation"
1136
+ }
1137
+ ]
1138
+ },
1139
+ {
1140
+ type: "tuple[]",
1141
+ name: "functions",
1142
+ components: [
1143
+ {
1144
+ type: "bytes4",
1145
+ name: "functionSelector"
1146
+ },
1147
+ {
1148
+ type: "string",
1149
+ name: "functionSignature"
1150
+ }
1151
+ ]
1152
+ }
1153
+ ]
1154
+ }
1155
+ ]
1156
+ ],
1157
+ params: []
1158
+ });
1159
+ }
1160
+ async function so(e) {
1161
+ return _({
1162
+ contract: e.contract,
1163
+ method: [
1164
+ "0xd42f2f35",
1165
+ [],
1166
+ [
1167
+ {
1168
+ type: "tuple[]",
1169
+ name: "signers",
1170
+ components: [
1171
+ {
1172
+ type: "address",
1173
+ name: "signer"
1174
+ },
1175
+ {
1176
+ type: "address[]",
1177
+ name: "approvedTargets"
1178
+ },
1179
+ {
1180
+ type: "uint256",
1181
+ name: "nativeTokenLimitPerTransaction"
1182
+ },
1183
+ {
1184
+ type: "uint128",
1185
+ name: "startTimestamp"
1186
+ },
1187
+ {
1188
+ type: "uint128",
1189
+ name: "endTimestamp"
1190
+ }
1191
+ ]
1192
+ }
1193
+ ]
1194
+ ],
1195
+ params: []
1196
+ });
1197
+ }
1198
+ async function ro(e) {
1199
+ return _({
1200
+ contract: e.contract,
1201
+ method: [
1202
+ "0xce0b6013",
1203
+ [
1204
+ {
1205
+ type: "bytes4",
1206
+ name: "_functionSelector"
1207
+ }
1208
+ ],
1209
+ [
1210
+ {
1211
+ type: "address"
1212
+ }
1213
+ ]
1214
+ ],
1215
+ params: [e.functionSelector]
1216
+ });
1217
+ }
1218
+ async function oo(e) {
1219
+ return _({
1220
+ contract: e.contract,
1221
+ method: [
1222
+ "0xd087d288",
1223
+ [],
1224
+ [
1225
+ {
1226
+ type: "uint256"
1227
+ }
1228
+ ]
1229
+ ],
1230
+ params: []
1231
+ });
1232
+ }
1233
+ async function io(e) {
1234
+ return _({
1235
+ contract: e.contract,
1236
+ method: [
1237
+ "0xf15d424e",
1238
+ [
1239
+ {
1240
+ type: "address",
1241
+ name: "signer"
1242
+ }
1243
+ ],
1244
+ [
1245
+ {
1246
+ type: "tuple",
1247
+ components: [
1248
+ {
1249
+ type: "address",
1250
+ name: "signer"
1251
+ },
1252
+ {
1253
+ type: "address[]",
1254
+ name: "approvedTargets"
1255
+ },
1256
+ {
1257
+ type: "uint256",
1258
+ name: "nativeTokenLimitPerTransaction"
1259
+ },
1260
+ {
1261
+ type: "uint128",
1262
+ name: "startTimestamp"
1263
+ },
1264
+ {
1265
+ type: "uint128",
1266
+ name: "endTimestamp"
1267
+ }
1268
+ ]
1269
+ }
1270
+ ]
1271
+ ],
1272
+ params: [e.signer]
1273
+ });
1274
+ }
1275
+ async function co(e) {
1276
+ return _({
1277
+ contract: e.contract,
1278
+ method: [
1279
+ "0x7dff5a79",
1280
+ [
1281
+ {
1282
+ type: "address",
1283
+ name: "signer"
1284
+ }
1285
+ ],
1286
+ [
1287
+ {
1288
+ type: "bool"
1289
+ }
1290
+ ]
1291
+ ],
1292
+ params: [e.signer]
1293
+ });
1294
+ }
1295
+ async function lo(e) {
1296
+ return _({
1297
+ contract: e.contract,
1298
+ method: [
1299
+ "0x24d7806c",
1300
+ [
1301
+ {
1302
+ type: "address",
1303
+ name: "_account"
1304
+ }
1305
+ ],
1306
+ [
1307
+ {
1308
+ type: "bool"
1309
+ }
1310
+ ]
1311
+ ],
1312
+ params: [e.account]
1313
+ });
1314
+ }
1315
+ async function uo(e) {
1316
+ return _({
1317
+ contract: e.contract,
1318
+ method: [
1319
+ "0x1dd756c5",
1320
+ [
1321
+ {
1322
+ type: "address",
1323
+ name: "_signer"
1324
+ },
1325
+ {
1326
+ type: "tuple",
1327
+ name: "_userOp",
1328
+ components: [
1329
+ {
1330
+ type: "address",
1331
+ name: "sender"
1332
+ },
1333
+ {
1334
+ type: "uint256",
1335
+ name: "nonce"
1336
+ },
1337
+ {
1338
+ type: "bytes",
1339
+ name: "initCode"
1340
+ },
1341
+ {
1342
+ type: "bytes",
1343
+ name: "callData"
1344
+ },
1345
+ {
1346
+ type: "uint256",
1347
+ name: "callGasLimit"
1348
+ },
1349
+ {
1350
+ type: "uint256",
1351
+ name: "verificationGasLimit"
1352
+ },
1353
+ {
1354
+ type: "uint256",
1355
+ name: "preVerificationGas"
1356
+ },
1357
+ {
1358
+ type: "uint256",
1359
+ name: "maxFeePerGas"
1360
+ },
1361
+ {
1362
+ type: "uint256",
1363
+ name: "maxPriorityFeePerGas"
1364
+ },
1365
+ {
1366
+ type: "bytes",
1367
+ name: "paymasterAndData"
1368
+ },
1369
+ {
1370
+ type: "bytes",
1371
+ name: "signature"
1372
+ }
1373
+ ]
1374
+ }
1375
+ ],
1376
+ [
1377
+ {
1378
+ type: "bool"
1379
+ }
1380
+ ]
1381
+ ],
1382
+ params: [e.signer, e.userOp]
1383
+ });
1384
+ }
1385
+ async function po(e) {
1386
+ return _({
1387
+ contract: e.contract,
1388
+ method: [
1389
+ "0xa9082d84",
1390
+ [
1391
+ {
1392
+ type: "tuple",
1393
+ name: "req",
1394
+ components: [
1395
+ {
1396
+ type: "address",
1397
+ name: "signer"
1398
+ },
1399
+ {
1400
+ type: "uint8",
1401
+ name: "isAdmin"
1402
+ },
1403
+ {
1404
+ type: "address[]",
1405
+ name: "approvedTargets"
1406
+ },
1407
+ {
1408
+ type: "uint256",
1409
+ name: "nativeTokenLimitPerTransaction"
1410
+ },
1411
+ {
1412
+ type: "uint128",
1413
+ name: "permissionStartTimestamp"
1414
+ },
1415
+ {
1416
+ type: "uint128",
1417
+ name: "permissionEndTimestamp"
1418
+ },
1419
+ {
1420
+ type: "uint128",
1421
+ name: "reqValidityStartTimestamp"
1422
+ },
1423
+ {
1424
+ type: "uint128",
1425
+ name: "reqValidityEndTimestamp"
1426
+ },
1427
+ {
1428
+ type: "bytes32",
1429
+ name: "uid"
1430
+ }
1431
+ ]
1432
+ },
1433
+ {
1434
+ type: "bytes",
1435
+ name: "signature"
1436
+ }
1437
+ ],
1438
+ [
1439
+ {
1440
+ type: "bool",
1441
+ name: "success"
1442
+ },
1443
+ {
1444
+ type: "address",
1445
+ name: "signer"
1446
+ }
1447
+ ]
1448
+ ],
1449
+ params: [e.req, e.signature]
1450
+ });
1451
+ }
1452
+ async function mo(e) {
1453
+ return _({
1454
+ contract: e.contract,
1455
+ method: [
1456
+ "0xe8a3d485",
1457
+ [],
1458
+ [
1459
+ {
1460
+ type: "string"
1461
+ }
1462
+ ]
1463
+ ],
1464
+ params: []
1465
+ });
1466
+ }
1467
+ async function fo(e) {
1468
+ return _({
1469
+ contract: e.contract,
1470
+ method: [
1471
+ "0x399b77da",
1472
+ [
1473
+ {
1474
+ type: "bytes32",
1475
+ name: "_hash"
1476
+ }
1477
+ ],
1478
+ [
1479
+ {
1480
+ type: "bytes32"
1481
+ }
1482
+ ]
1483
+ ],
1484
+ params: [e.hash]
1485
+ });
1486
+ }
1487
+ async function ho(e) {
1488
+ return _({
1489
+ contract: e.contract,
1490
+ method: [
1491
+ "0x1626ba7e",
1492
+ [
1493
+ {
1494
+ type: "bytes32",
1495
+ name: "_hash"
1496
+ },
1497
+ {
1498
+ type: "bytes",
1499
+ name: "_signature"
1500
+ }
1501
+ ],
1502
+ [
1503
+ {
1504
+ type: "bytes4",
1505
+ name: "magicValue"
1506
+ }
1507
+ ]
1508
+ ],
1509
+ params: [e.hash, e.signature]
1510
+ });
1511
+ }
1512
+ async function yo(e) {
1513
+ return _({
1514
+ contract: e.contract,
1515
+ method: [
1516
+ "0x01ffc9a7",
1517
+ [
1518
+ {
1519
+ type: "bytes4",
1520
+ name: "interfaceId"
1521
+ }
1522
+ ],
1523
+ [
1524
+ {
1525
+ type: "bool"
1526
+ }
1527
+ ]
1528
+ ],
1529
+ params: [e.interfaceId]
1530
+ });
1531
+ }
1532
+ async function go(e) {
1533
+ return _({
1534
+ contract: e.contract,
1535
+ method: [
1536
+ "0x84b0196e",
1537
+ [],
1538
+ [
1539
+ {
1540
+ type: "bytes1",
1541
+ name: "fields"
1542
+ },
1543
+ {
1544
+ type: "string",
1545
+ name: "name"
1546
+ },
1547
+ {
1548
+ type: "string",
1549
+ name: "version"
1550
+ },
1551
+ {
1552
+ type: "uint256",
1553
+ name: "chainId"
1554
+ },
1555
+ {
1556
+ type: "address",
1557
+ name: "verifyingContract"
1558
+ },
1559
+ {
1560
+ type: "bytes32",
1561
+ name: "salt"
1562
+ },
1563
+ {
1564
+ type: "uint256[]",
1565
+ name: "extensions"
1566
+ }
1567
+ ]
1568
+ ],
1569
+ params: []
1570
+ });
1571
+ }
1572
+ async function wo(e) {
1573
+ return _({
1574
+ contract: e.contract,
1575
+ method: [
1576
+ "0xd5f5127d",
1577
+ [],
1578
+ [
1579
+ {
1580
+ type: "address"
1581
+ }
1582
+ ]
1583
+ ],
1584
+ params: []
1585
+ });
1586
+ }
1587
+ async function bo(e) {
1588
+ return _({
1589
+ contract: e.contract,
1590
+ method: [
1591
+ "0x8da5cb5b",
1592
+ [],
1593
+ [
1594
+ {
1595
+ type: "address"
1596
+ }
1597
+ ]
1598
+ ],
1599
+ params: []
1600
+ });
1601
+ }
1602
+ function Ao(e) {
1603
+ return C({
1604
+ contract: e.contract,
1605
+ method: [
1606
+ "0xd1f57894",
1607
+ [
1608
+ {
1609
+ type: "address",
1610
+ name: "_defaultAdmin"
1611
+ },
1612
+ {
1613
+ type: "bytes",
1614
+ name: "_data"
1615
+ }
1616
+ ],
1617
+ []
1618
+ ],
1619
+ params: [e.defaultAdmin, e.data]
1620
+ });
1621
+ }
1622
+ function vo(e) {
1623
+ return C({
1624
+ contract: e.contract,
1625
+ method: [
1626
+ "0xac9650d8",
1627
+ [
1628
+ {
1629
+ type: "bytes[]",
1630
+ name: "data"
1631
+ }
1632
+ ],
1633
+ [
1634
+ {
1635
+ type: "bytes[]",
1636
+ name: "results"
1637
+ }
1638
+ ]
1639
+ ],
1640
+ params: [e.data]
1641
+ });
1642
+ }
1643
+ function So(e) {
1644
+ return C({
1645
+ contract: e.contract,
1646
+ method: [
1647
+ "0xb76464d5",
1648
+ [
1649
+ {
1650
+ type: "address",
1651
+ name: "_entrypointOverride"
1652
+ }
1653
+ ],
1654
+ []
1655
+ ],
1656
+ params: [e.entrypointOverride]
1657
+ });
1658
+ }
1659
+ function Eo(e) {
1660
+ return C({
1661
+ contract: e.contract,
1662
+ method: [
1663
+ "0x5892e236",
1664
+ [
1665
+ {
1666
+ type: "tuple",
1667
+ name: "_req",
1668
+ components: [
1669
+ {
1670
+ type: "address",
1671
+ name: "signer"
1672
+ },
1673
+ {
1674
+ type: "uint8",
1675
+ name: "isAdmin"
1676
+ },
1677
+ {
1678
+ type: "address[]",
1679
+ name: "approvedTargets"
1680
+ },
1681
+ {
1682
+ type: "uint256",
1683
+ name: "nativeTokenLimitPerTransaction"
1684
+ },
1685
+ {
1686
+ type: "uint128",
1687
+ name: "permissionStartTimestamp"
1688
+ },
1689
+ {
1690
+ type: "uint128",
1691
+ name: "permissionEndTimestamp"
1692
+ },
1693
+ {
1694
+ type: "uint128",
1695
+ name: "reqValidityStartTimestamp"
1696
+ },
1697
+ {
1698
+ type: "uint128",
1699
+ name: "reqValidityEndTimestamp"
1700
+ },
1701
+ {
1702
+ type: "bytes32",
1703
+ name: "uid"
1704
+ }
1705
+ ]
1706
+ },
1707
+ {
1708
+ type: "bytes",
1709
+ name: "_signature"
1710
+ }
1711
+ ],
1712
+ []
1713
+ ],
1714
+ params: [e.req, e.signature]
1715
+ });
1716
+ }
1717
+ function Io(e) {
1718
+ return C({
1719
+ contract: e.contract,
1720
+ method: [
1721
+ "0x3a871cdd",
1722
+ [
1723
+ {
1724
+ type: "tuple",
1725
+ name: "userOp",
1726
+ components: [
1727
+ {
1728
+ type: "address",
1729
+ name: "sender"
1730
+ },
1731
+ {
1732
+ type: "uint256",
1733
+ name: "nonce"
1734
+ },
1735
+ {
1736
+ type: "bytes",
1737
+ name: "initCode"
1738
+ },
1739
+ {
1740
+ type: "bytes",
1741
+ name: "callData"
1742
+ },
1743
+ {
1744
+ type: "uint256",
1745
+ name: "callGasLimit"
1746
+ },
1747
+ {
1748
+ type: "uint256",
1749
+ name: "verificationGasLimit"
1750
+ },
1751
+ {
1752
+ type: "uint256",
1753
+ name: "preVerificationGas"
1754
+ },
1755
+ {
1756
+ type: "uint256",
1757
+ name: "maxFeePerGas"
1758
+ },
1759
+ {
1760
+ type: "uint256",
1761
+ name: "maxPriorityFeePerGas"
1762
+ },
1763
+ {
1764
+ type: "bytes",
1765
+ name: "paymasterAndData"
1766
+ },
1767
+ {
1768
+ type: "bytes",
1769
+ name: "signature"
1770
+ }
1771
+ ]
1772
+ },
1773
+ {
1774
+ type: "bytes32",
1775
+ name: "userOpHash"
1776
+ },
1777
+ {
1778
+ type: "uint256",
1779
+ name: "missingAccountFunds"
1780
+ }
1781
+ ],
1782
+ [
1783
+ {
1784
+ type: "uint256",
1785
+ name: "validationData"
1786
+ }
1787
+ ]
1788
+ ],
1789
+ params: [e.userOp, e.userOpHash, e.missingAccountFunds]
1790
+ });
1791
+ }
1792
+ function Po(e) {
1793
+ return C({
1794
+ contract: e.contract,
1795
+ method: [
1796
+ "0x4a58db19",
1797
+ [],
1798
+ []
1799
+ ],
1800
+ params: []
1801
+ });
1802
+ }
1803
+ function Uo(e) {
1804
+ return C({
1805
+ contract: e.contract,
1806
+ method: [
1807
+ "0xb61d27f6",
1808
+ [
1809
+ {
1810
+ type: "address",
1811
+ name: "_target"
1812
+ },
1813
+ {
1814
+ type: "uint256",
1815
+ name: "_value"
1816
+ },
1817
+ {
1818
+ type: "bytes",
1819
+ name: "_calldata"
1820
+ }
1821
+ ],
1822
+ []
1823
+ ],
1824
+ params: [e.target, e.value, e.calldata]
1825
+ });
1826
+ }
1827
+ function To(e) {
1828
+ return C({
1829
+ contract: e.contract,
1830
+ method: [
1831
+ "0x47e1da2a",
1832
+ [
1833
+ {
1834
+ type: "address[]",
1835
+ name: "_target"
1836
+ },
1837
+ {
1838
+ type: "uint256[]",
1839
+ name: "_value"
1840
+ },
1841
+ {
1842
+ type: "bytes[]",
1843
+ name: "_calldata"
1844
+ }
1845
+ ],
1846
+ []
1847
+ ],
1848
+ params: [e.target, e.value, e.calldata]
1849
+ });
1850
+ }
1851
+ function Do(e) {
1852
+ return C({
1853
+ contract: e.contract,
1854
+ method: [
1855
+ "0xbc197c81",
1856
+ [
1857
+ {
1858
+ type: "address"
1859
+ },
1860
+ {
1861
+ type: "address"
1862
+ },
1863
+ {
1864
+ type: "uint256[]"
1865
+ },
1866
+ {
1867
+ type: "uint256[]"
1868
+ },
1869
+ {
1870
+ type: "bytes"
1871
+ }
1872
+ ],
1873
+ [
1874
+ {
1875
+ type: "bytes4"
1876
+ }
1877
+ ]
1878
+ ],
1879
+ params: [e.arg_0, e.arg_1, e.arg_2, e.arg_3, e.arg_4]
1880
+ });
1881
+ }
1882
+ function xo(e) {
1883
+ return C({
1884
+ contract: e.contract,
1885
+ method: [
1886
+ "0xf23a6e61",
1887
+ [
1888
+ {
1889
+ type: "address"
1890
+ },
1891
+ {
1892
+ type: "address"
1893
+ },
1894
+ {
1895
+ type: "uint256"
1896
+ },
1897
+ {
1898
+ type: "uint256"
1899
+ },
1900
+ {
1901
+ type: "bytes"
1902
+ }
1903
+ ],
1904
+ [
1905
+ {
1906
+ type: "bytes4"
1907
+ }
1908
+ ]
1909
+ ],
1910
+ params: [e.arg_0, e.arg_1, e.arg_2, e.arg_3, e.arg_4]
1911
+ });
1912
+ }
1913
+ function Co(e) {
1914
+ return C({
1915
+ contract: e.contract,
1916
+ method: [
1917
+ "0x150b7a02",
1918
+ [
1919
+ {
1920
+ type: "address"
1921
+ },
1922
+ {
1923
+ type: "address"
1924
+ },
1925
+ {
1926
+ type: "uint256"
1927
+ },
1928
+ {
1929
+ type: "bytes"
1930
+ }
1931
+ ],
1932
+ [
1933
+ {
1934
+ type: "bytes4"
1935
+ }
1936
+ ]
1937
+ ],
1938
+ params: [e.arg_0, e.arg_1, e.arg_2, e.arg_3]
1939
+ });
1940
+ }
1941
+ function Ro(e) {
1942
+ return C({
1943
+ contract: e.contract,
1944
+ method: [
1945
+ "0x938e3d7b",
1946
+ [
1947
+ {
1948
+ type: "string",
1949
+ name: "_uri"
1950
+ }
1951
+ ],
1952
+ []
1953
+ ],
1954
+ params: [e.uri]
1955
+ });
1956
+ }
1957
+ function _o(e) {
1958
+ return C({
1959
+ contract: e.contract,
1960
+ method: [
1961
+ "0x4d44560d",
1962
+ [
1963
+ {
1964
+ type: "address",
1965
+ name: "withdrawAddress"
1966
+ },
1967
+ {
1968
+ type: "uint256",
1969
+ name: "amount"
1970
+ }
1971
+ ],
1972
+ []
1973
+ ],
1974
+ params: [e.withdrawAddress, e.amount]
1975
+ });
1976
+ }
1977
+ function Lo(e) {
1978
+ return C({
1979
+ contract: e.contract,
1980
+ method: [
1981
+ "0x6240d6d9",
1982
+ [
1983
+ {
1984
+ type: "bytes32",
1985
+ name: "schemaUid"
1986
+ },
1987
+ {
1988
+ type: "bool",
1989
+ name: "revocable"
1990
+ }
1991
+ ],
1992
+ [
1993
+ {
1994
+ type: "bytes32"
1995
+ }
1996
+ ]
1997
+ ],
1998
+ params: [e.schemaUid, e.revocable]
1999
+ });
2000
+ }
2001
+ function Mo(e) {
2002
+ return C({
2003
+ contract: e.contract,
2004
+ method: [
2005
+ "0x13e0c263",
2006
+ [
2007
+ {
2008
+ type: "bytes32",
2009
+ name: "seedUid"
2010
+ },
2011
+ {
2012
+ type: "bytes32",
2013
+ name: "versionSchemaUid"
2014
+ }
2015
+ ],
2016
+ [
2017
+ {
2018
+ type: "bytes32"
2019
+ }
2020
+ ]
2021
+ ],
2022
+ params: [e.seedUid, e.versionSchemaUid]
2023
+ });
2024
+ }
2025
+ function vt(e) {
2026
+ return C({
2027
+ contract: e.contract,
2028
+ method: [
2029
+ "0x31e19cb8",
2030
+ [
2031
+ {
2032
+ type: "tuple[]",
2033
+ name: "requests",
2034
+ components: [
2035
+ {
2036
+ type: "string",
2037
+ name: "localId"
2038
+ },
2039
+ {
2040
+ type: "bytes32",
2041
+ name: "seedUid"
2042
+ },
2043
+ {
2044
+ type: "bytes32",
2045
+ name: "seedSchemaUid"
2046
+ },
2047
+ {
2048
+ type: "bytes32",
2049
+ name: "versionUid"
2050
+ },
2051
+ {
2052
+ type: "bytes32",
2053
+ name: "versionSchemaUid"
2054
+ },
2055
+ {
2056
+ type: "bool",
2057
+ name: "seedIsRevocable"
2058
+ },
2059
+ {
2060
+ type: "tuple[]",
2061
+ name: "listOfAttestations",
2062
+ components: [
2063
+ {
2064
+ type: "bytes32",
2065
+ name: "schema"
2066
+ },
2067
+ {
2068
+ type: "tuple[]",
2069
+ name: "data",
2070
+ components: [
2071
+ {
2072
+ type: "address",
2073
+ name: "recipient"
2074
+ },
2075
+ {
2076
+ type: "uint64",
2077
+ name: "expirationTime"
2078
+ },
2079
+ {
2080
+ type: "bool",
2081
+ name: "revocable"
2082
+ },
2083
+ {
2084
+ type: "bytes32",
2085
+ name: "refUID"
2086
+ },
2087
+ {
2088
+ type: "bytes",
2089
+ name: "data"
2090
+ },
2091
+ {
2092
+ type: "uint256",
2093
+ name: "value"
2094
+ }
2095
+ ]
2096
+ }
2097
+ ]
2098
+ },
2099
+ {
2100
+ type: "tuple[]",
2101
+ name: "propertiesToUpdate",
2102
+ components: [
2103
+ {
2104
+ type: "string",
2105
+ name: "publishLocalId"
2106
+ },
2107
+ {
2108
+ type: "bytes32",
2109
+ name: "propertySchemaUid"
2110
+ }
2111
+ ]
2112
+ }
2113
+ ]
2114
+ }
2115
+ ],
2116
+ [
2117
+ {
2118
+ type: "bytes32[]"
2119
+ }
2120
+ ]
2121
+ ],
2122
+ params: [e.requests]
2123
+ });
2124
+ }
2125
+ function Oo(e) {
2126
+ return C({
2127
+ contract: e.contract,
2128
+ method: [
2129
+ "0xd688e801",
2130
+ [
2131
+ {
2132
+ type: "tuple[]",
2133
+ name: "requests",
2134
+ components: [
2135
+ { type: "uint256", name: "localIdIndex" },
2136
+ { type: "bytes32", name: "seedUid" },
2137
+ { type: "bytes32", name: "seedSchemaUid" },
2138
+ { type: "bytes32", name: "versionUid" },
2139
+ { type: "bytes32", name: "versionSchemaUid" },
2140
+ { type: "bool", name: "seedIsRevocable" },
2141
+ {
2142
+ type: "tuple[]",
2143
+ name: "listOfAttestations",
2144
+ components: [
2145
+ { type: "bytes32", name: "schema" },
2146
+ {
2147
+ type: "tuple[]",
2148
+ name: "data",
2149
+ components: [
2150
+ { type: "address", name: "recipient" },
2151
+ { type: "uint64", name: "expirationTime" },
2152
+ { type: "bool", name: "revocable" },
2153
+ { type: "bytes32", name: "refUID" },
2154
+ { type: "bytes", name: "data" },
2155
+ { type: "uint256", name: "value" }
2156
+ ]
2157
+ }
2158
+ ]
2159
+ },
2160
+ {
2161
+ type: "tuple[]",
2162
+ name: "propertiesToUpdate",
2163
+ components: [
2164
+ { type: "uint256", name: "publishLocalIdIndex" },
2165
+ { type: "bytes32", name: "propertySchemaUid" }
2166
+ ]
2167
+ }
2168
+ ]
2169
+ }
2170
+ ],
2171
+ [{ type: "bytes32[]" }]
2172
+ ],
2173
+ params: [e.requests]
2174
+ });
2175
+ }
2176
+ function Bo(e) {
2177
+ return C({
2178
+ contract: e.contract,
2179
+ method: [
2180
+ "0xb71308c5",
2181
+ [
2182
+ {
2183
+ type: "tuple",
2184
+ name: "request",
2185
+ components: [
2186
+ {
2187
+ type: "string",
2188
+ name: "localId"
2189
+ },
2190
+ {
2191
+ type: "bytes32",
2192
+ name: "seedUid"
2193
+ },
2194
+ {
2195
+ type: "bytes32",
2196
+ name: "seedSchemaUid"
2197
+ },
2198
+ {
2199
+ type: "bytes32",
2200
+ name: "versionUid"
2201
+ },
2202
+ {
2203
+ type: "bytes32",
2204
+ name: "versionSchemaUid"
2205
+ },
2206
+ {
2207
+ type: "bool",
2208
+ name: "seedIsRevocable"
2209
+ },
2210
+ {
2211
+ type: "tuple[]",
2212
+ name: "listOfAttestations",
2213
+ components: [
2214
+ {
2215
+ type: "bytes32",
2216
+ name: "schema"
2217
+ },
2218
+ {
2219
+ type: "tuple[]",
2220
+ name: "data",
2221
+ components: [
2222
+ {
2223
+ type: "address",
2224
+ name: "recipient"
2225
+ },
2226
+ {
2227
+ type: "uint64",
2228
+ name: "expirationTime"
2229
+ },
2230
+ {
2231
+ type: "bool",
2232
+ name: "revocable"
2233
+ },
2234
+ {
2235
+ type: "bytes32",
2236
+ name: "refUID"
2237
+ },
2238
+ {
2239
+ type: "bytes",
2240
+ name: "data"
2241
+ },
2242
+ {
2243
+ type: "uint256",
2244
+ name: "value"
2245
+ }
2246
+ ]
2247
+ }
2248
+ ]
2249
+ },
2250
+ {
2251
+ type: "tuple[]",
2252
+ name: "propertiesToUpdate",
2253
+ components: [
2254
+ {
2255
+ type: "string",
2256
+ name: "publishLocalId"
2257
+ },
2258
+ {
2259
+ type: "bytes32",
2260
+ name: "propertySchemaUid"
2261
+ }
2262
+ ]
2263
+ }
2264
+ ]
2265
+ }
2266
+ ],
2267
+ [
2268
+ {
2269
+ type: "bytes32"
2270
+ },
2271
+ {
2272
+ type: "bytes32"
2273
+ }
2274
+ ]
2275
+ ],
2276
+ params: [e.request]
2277
+ });
2278
+ }
2279
+ function No(e) {
2280
+ return C({
2281
+ contract: e.contract,
2282
+ method: [
2283
+ "0x715018a6",
2284
+ [],
2285
+ []
2286
+ ],
2287
+ params: []
2288
+ });
2289
+ }
2290
+ function Fo(e) {
2291
+ return C({
2292
+ contract: e.contract,
2293
+ method: [
2294
+ "0xb90b6e0d",
2295
+ [
2296
+ {
2297
+ type: "address",
2298
+ name: "_eas"
2299
+ }
2300
+ ],
2301
+ [
2302
+ {
2303
+ type: "string"
2304
+ }
2305
+ ]
2306
+ ],
2307
+ params: [e.eas]
2308
+ });
2309
+ }
2310
+ function ko(e) {
2311
+ return C({
2312
+ contract: e.contract,
2313
+ method: [
2314
+ "0xf2fde38b",
2315
+ [
2316
+ {
2317
+ type: "address",
2318
+ name: "newOwner"
2319
+ }
2320
+ ],
2321
+ []
2322
+ ],
2323
+ params: [e.newOwner]
2324
+ });
2325
+ }
2326
+ const _e = () => {
2327
+ const e = Ln.getHost(), t = na;
2328
+ return Object.keys(t).includes("default") && t.default ? t.default.init({
2329
+ host: e,
2330
+ protocol: "https"
2331
+ }) : t.init({
2332
+ host: e,
2333
+ protocol: "https"
2334
+ });
2335
+ }, $ = "0x" + "0".repeat(64), dt = async (e) => {
2336
+ let t;
2337
+ try {
2338
+ t = await se.find({ seedLocalId: e });
2339
+ } catch {
2340
+ }
2341
+ return t || new Promise((n) => {
2342
+ const a = setInterval(() => {
2343
+ try {
2344
+ se.find({ seedLocalId: e }).then((s) => {
2345
+ s && (clearInterval(a), n(s));
2346
+ });
2347
+ } catch {
2348
+ }
2349
+ }, 200);
2350
+ });
2351
+ };
2352
+ function ka(e) {
2353
+ if (!e || typeof e != "object") return;
2354
+ const t = e;
2355
+ if (Array.isArray(t.data_root))
2356
+ return {
2357
+ data_root: new Uint8Array(t.data_root),
2358
+ chunks: (t.chunks ?? []).map((n) => ({ ...n, dataHash: new Uint8Array(n.dataHash ?? []) })),
2359
+ proofs: (t.proofs ?? []).map((n) => ({ ...n, proof: new Uint8Array(n.proof ?? []) }))
2360
+ };
2361
+ }
2362
+ function Ha(e) {
2363
+ return {
2364
+ data_root: Array.from(e.data_root),
2365
+ chunks: e.chunks.map((t) => ({ ...t, dataHash: Array.from(t.dataHash) })),
2366
+ proofs: e.proofs.map((t) => ({ ...t, proof: Array.from(t.proof) }))
2367
+ };
2368
+ }
2369
+ const $a = he(
2370
+ async ({ input: { context: e } }) => {
2371
+ let { item: t } = e;
2372
+ t.getPublishUploads || (t = await dt(t.seedLocalId));
2373
+ let n;
2374
+ e.arweaveUploadTags?.length && (n = { arweaveUploadTags: e.arweaveUploadTags });
2375
+ const a = await t.getPublishUploads(n), s = x(), r = e.signArweaveTransactions ?? s.signArweaveTransactions, o = e.arweaveJwk ?? s.arweaveJwk, c = a.map((m) => ({
2376
+ versionLocalId: m.versionLocalId,
2377
+ itemPropertyName: m.itemPropertyName,
2378
+ transactionJson: m.transactionToSign.toJSON()
2379
+ }));
2380
+ let i;
2381
+ if (r)
2382
+ i = await r(c);
2383
+ else if (o) {
2384
+ const m = _e(), p = o;
2385
+ i = [];
2386
+ for (const h of c) {
2387
+ const u = m.transactions.fromRaw(h.transactionJson);
2388
+ u.data && u.data.byteLength > 0 && !u.chunks && await u.prepareChunks(u.data), await m.transactions.sign(u, p);
2389
+ const y = u.toJSON();
2390
+ i.push({
2391
+ transaction: {
2392
+ ...y,
2393
+ chunks: u.chunks ? Ha(u.chunks) : void 0
2394
+ },
2395
+ versionId: h.versionLocalId,
2396
+ modelName: h.itemPropertyName
2397
+ });
2398
+ }
2399
+ } else
2400
+ throw new Error(
2401
+ "Arweave signing not configured. Provide signArweaveTransactions or arweaveJwk at createPublish or in PublishProvider config."
2402
+ );
2403
+ const l = _e();
2404
+ return {
2405
+ arweaveTransactions: i.map((m) => {
2406
+ const { chunks: p, ...h } = m.transaction, u = { ...h }, y = ka(p);
2407
+ return y && (u.chunks = y), {
2408
+ transaction: l.transactions.fromRaw(u),
2409
+ versionId: m.versionId,
2410
+ modelName: m.modelName
2411
+ };
2412
+ }),
2413
+ publishUploads: a
2414
+ };
2415
+ }
2416
+ ), Qt = (e, t, n) => {
2417
+ const a = [];
2418
+ return e && a.push({ name: "Content-SHA-256", value: e }), t && a.push({ name: "Content-Type", value: t }), n?.length && a.push(...n), a;
2419
+ }, Xt = async (e) => {
2420
+ const t = e instanceof Uint8Array ? new Uint8Array(e) : new Uint8Array(e), n = await crypto.subtle.digest("SHA-256", t);
2421
+ return Array.from(new Uint8Array(n)).map((a) => a.toString(16).padStart(2, "0")).join("");
2422
+ }, Va = {
2423
+ png: "image/png",
2424
+ jpg: "image/jpeg",
2425
+ jpeg: "image/jpeg",
2426
+ gif: "image/gif",
2427
+ webp: "image/webp",
2428
+ svg: "image/svg+xml",
2429
+ html: "text/html",
2430
+ htm: "text/html",
2431
+ json: "application/json",
2432
+ txt: "text/plain"
2433
+ }, en = (e) => {
2434
+ const t = e.split(".").pop()?.toLowerCase();
2435
+ return t ? Va[t] : void 0;
2436
+ }, nt = async (e) => typeof Blob < "u" && e instanceof Blob ? new Uint8Array(await e.arrayBuffer()) : new Uint8Array(e), qa = (e) => {
2437
+ switch (e) {
2438
+ case "Image":
2439
+ return j.getFilesPath("images");
2440
+ case "File":
2441
+ return j.getFilesPath("files");
2442
+ case "Html":
2443
+ return j.getFilesPath("html");
2444
+ case "Json":
2445
+ return j.getFilesPath("json");
2446
+ default:
2447
+ return j.getFilesPath("images");
2448
+ }
2449
+ }, Wa = async (e, t, n, a) => {
2450
+ const s = a?.arweaveUploadTags, r = e.itemProperty, o = [];
2451
+ for (const h of e.childProperties) {
2452
+ const u = h.localStoragePath;
2453
+ !u || u.endsWith("undefined") || !await j.pathExists(u) || o.push({
2454
+ propertyName: h.propertyName,
2455
+ localStoragePath: u
2456
+ });
2457
+ }
2458
+ let c;
2459
+ if ((!o || o.length === 0) && n?.localStoragePath) {
2460
+ const h = n.localStoragePath;
2461
+ if (h && !h.endsWith("undefined") && await j.pathExists(h))
2462
+ try {
2463
+ const y = await j.readFileAsBuffer(h);
2464
+ c = await nt(y);
2465
+ } catch {
2466
+ const y = await j.getFs();
2467
+ c = await nt(y.readFileSync(h));
2468
+ }
2469
+ }
2470
+ if (o.length > 0) {
2471
+ const h = "===FILE_SEPARATOR===";
2472
+ let u = "";
2473
+ const y = await j.getFs();
2474
+ for (const f of o) {
2475
+ let b;
2476
+ try {
2477
+ b = await y.promises.readFile(f.localStoragePath);
2478
+ } catch {
2479
+ b = y.readFileSync(f.localStoragePath);
2480
+ }
2481
+ u += `${h}${f.propertyName}${h}${b}`;
2482
+ }
2483
+ c = typeof document < "u" ? new TextEncoder().encode(u) : new Uint8Array(Buffer.from(u));
2484
+ }
2485
+ if (!c) return t;
2486
+ const i = new Uint8Array(c), l = await Xt(i);
2487
+ let d;
2488
+ o.length === 0 && n?.localStoragePath ? d = en(n.localStoragePath) : o.length > 0 && (d = "application/octet-stream");
2489
+ const m = n ? n.localId : r.localId, p = n ? n.propertyName : r.propertyName;
2490
+ return t.push({
2491
+ data: i,
2492
+ contentHash: l,
2493
+ contentType: d,
2494
+ tags: Qt(l, d, s),
2495
+ itemPropertyName: p,
2496
+ itemPropertyLocalId: m,
2497
+ seedLocalId: r.seedLocalId,
2498
+ versionLocalId: r.versionLocalId
2499
+ }), t;
2500
+ }, Ga = async (e, t) => {
2501
+ const n = [], a = t?.arweaveUploadTags;
2502
+ for (const s of e) {
2503
+ const r = s.getService().getSnapshot(), o = "context" in r ? r.context : null;
2504
+ if (!o) continue;
2505
+ const c = o.propertyValue, i = o.refResolvedValue;
2506
+ if (!i) continue;
2507
+ const { localId: l } = Nt(c ?? "");
2508
+ if (!l) continue;
2509
+ const d = s.propertyDef?.refValueType ?? s.propertyDef?.dataType ?? "Image", p = `${qa(d)}/${i}`;
2510
+ if (!await j.pathExists(p)) continue;
2511
+ const u = await j.readFileAsBuffer(p), y = await nt(u), f = await Xt(y), b = en(i);
2512
+ n.push({
2513
+ data: y,
2514
+ contentHash: f,
2515
+ contentType: b,
2516
+ tags: Qt(f, b, a),
2517
+ itemPropertyName: s.propertyName,
2518
+ itemPropertyLocalId: s.localId,
2519
+ seedLocalId: l,
2520
+ versionLocalId: s.versionLocalId
2521
+ });
2522
+ }
2523
+ return n;
2524
+ }, tn = async (e, t = [], n, a) => {
2525
+ const { itemUploadProperties: s, itemRelationProperties: r, itemImageProperties: o } = await st(e);
2526
+ for (const i of s)
2527
+ t = await Wa(
2528
+ i,
2529
+ t,
2530
+ n,
2531
+ a
2532
+ );
2533
+ const c = await Ga(o, a);
2534
+ t.push(...c);
2535
+ for (const i of r) {
2536
+ const l = i.getService().getSnapshot(), d = "context" in l ? l.context : null;
2537
+ if (!d) continue;
2538
+ const m = d.propertyValue;
2539
+ if (!m || i.uid) continue;
2540
+ const { localId: p, uid: h } = Nt(m), u = await se.find({ seedLocalId: p, seedUid: h });
2541
+ if (!u)
2542
+ throw new Error(`No relatedItem found for ${i.propertyName}`);
2543
+ t = await tn(u, t, i, a);
2544
+ }
2545
+ return t;
2546
+ }, lt = 3, ae = 65, St = new TextEncoder().encode("seed-recovery"), Ye = 32, ja = 0xffffffffffffffffn;
2547
+ function Ya(e, t, n) {
2548
+ const a = N.solidityPackedKeccak256(
2549
+ ["uint256", "address", "uint64"],
2550
+ [BigInt(t), e, n & ja]
2551
+ );
2552
+ return N.getBytes(a);
2553
+ }
2554
+ function Et(e) {
2555
+ if (e.length === 0) return new Uint8Array([0]);
2556
+ if (e.length !== Ye)
2557
+ throw new Error(`ANS-104 target/anchor must be empty or ${Ye} bytes, got ${e.length}`);
2558
+ const t = new Uint8Array(1 + Ye);
2559
+ return t[0] = 1, t.set(e, 1), t;
2560
+ }
2561
+ function Ja(e) {
2562
+ return e != null && typeof e == "object" && "privateKey" in e && typeof e.privateKey == "string";
2563
+ }
2564
+ function za(e, t, n) {
2565
+ let s = e >= 0 ? e << 1 : ~e << 1 | 1, r = n;
2566
+ do {
2567
+ const o = s & 127;
2568
+ s >>>= 7, t[r++] = s ? o | 128 : o;
2569
+ } while (s);
2570
+ return r - n;
2571
+ }
2572
+ const ut = (e) => {
2573
+ if (!e?.length) return new Uint8Array(0);
2574
+ const t = new TextEncoder(), n = new Uint8Array(16), a = [], s = (i) => {
2575
+ const l = za(i, n, 0);
2576
+ a.push(n.slice(0, l));
2577
+ };
2578
+ s(e.length);
2579
+ for (const i of e) {
2580
+ const l = t.encode(i.name), d = t.encode(i.value);
2581
+ s(l.length), a.push(l), s(d.length), a.push(d);
2582
+ }
2583
+ s(0);
2584
+ const r = a.reduce((i, l) => i + l.length, 0), o = new Uint8Array(r);
2585
+ let c = 0;
2586
+ for (const i of a)
2587
+ o.set(i, c), c += i.length;
2588
+ return o;
2589
+ }, It = (e) => {
2590
+ const t = new Uint8Array(8), n = new DataView(t.buffer);
2591
+ return n.setUint32(0, e & 4294967295, !0), n.setUint32(4, Math.floor(e / 4294967296), !0), t;
2592
+ };
2593
+ async function we(e) {
2594
+ return new Uint8Array(
2595
+ await crypto.subtle.digest("SHA-384", e)
2596
+ );
2597
+ }
2598
+ function Ie(e, t) {
2599
+ const n = new Uint8Array(e.length + t.length);
2600
+ return n.set(e, 0), n.set(t, e.length), n;
2601
+ }
2602
+ async function nn(e) {
2603
+ const t = new TextEncoder();
2604
+ if (Array.isArray(e)) {
2605
+ const r = Ie(t.encode("list"), t.encode(e.length.toString()));
2606
+ let o = await we(r);
2607
+ for (const c of e) {
2608
+ const i = await nn(c);
2609
+ o = await we(Ie(o, i));
2610
+ }
2611
+ return o;
2612
+ }
2613
+ const n = Ie(t.encode("blob"), t.encode(e.byteLength.toString())), a = await we(n), s = await we(e);
2614
+ return we(Ie(a, s));
2615
+ }
2616
+ async function pt(e, t, n, a, s) {
2617
+ const r = new TextEncoder();
2618
+ return nn([
2619
+ r.encode("dataitem"),
2620
+ r.encode("1"),
2621
+ r.encode(lt.toString()),
2622
+ e,
2623
+ t,
2624
+ n,
2625
+ a,
2626
+ s
2627
+ ]);
2628
+ }
2629
+ function an(e, t, n, a, s) {
2630
+ const r = ut(t), o = It(t.length), c = It(r.length), i = Et(a), l = Et(s), d = [
2631
+ e,
2632
+ i,
2633
+ l,
2634
+ o,
2635
+ c,
2636
+ r,
2637
+ n
2638
+ ], m = d.reduce((u, y) => u + y.length, 0), p = new Uint8Array(m);
2639
+ let h = 0;
2640
+ for (const u of d)
2641
+ p.set(u, h), h += u.length;
2642
+ return p;
2643
+ }
2644
+ async function sn(e, t) {
2645
+ const n = new Uint8Array(2);
2646
+ new DataView(n.buffer).setUint16(0, lt, !0);
2647
+ const a = 2 + ae + t.length, s = new Uint8Array(a);
2648
+ s.set(n, 0), s.set(e, 2), s.set(t, 2 + ae);
2649
+ const r = await crypto.subtle.digest("SHA-256", new Uint8Array(e));
2650
+ return { id: ts(new Uint8Array(r)), raw: s };
2651
+ }
2652
+ const Za = async (e, t, n, a = new Uint8Array(0)) => {
2653
+ const s = N.SigningKey.computePublicKey(t.privateKey, !1), r = N.getBytes(s), o = ut(n), c = new Uint8Array(0), i = await pt(
2654
+ r,
2655
+ c,
2656
+ a,
2657
+ o,
2658
+ e
2659
+ ), l = N.getBytes(await t.signMessage(i)), d = an(r, n, e, c, a);
2660
+ return sn(l, d);
2661
+ }, Ka = async (e, t, n, a = new Uint8Array(0)) => {
2662
+ const s = N.hexlify(St), r = await t.signMessage({
2663
+ message: { raw: s }
2664
+ }), o = N.hashMessage(St), c = N.SigningKey.recoverPublicKey(o, r), i = N.getBytes(c), l = ut(n), d = new Uint8Array(0), m = await pt(
2665
+ i,
2666
+ d,
2667
+ a,
2668
+ l,
2669
+ e
2670
+ ), p = N.hexlify(m), h = await t.signMessage({
2671
+ message: { raw: p }
2672
+ }), u = N.getBytes(h), y = an(i, n, e, d, a);
2673
+ return sn(u, y);
2674
+ }, mt = 65;
2675
+ function Qa(e) {
2676
+ const t = 2 + ae + mt;
2677
+ if (e.length < t + 1) return null;
2678
+ const n = e[t];
2679
+ if (n !== 0 && n !== 1) return null;
2680
+ const a = n === 1;
2681
+ if (a && e.length < t + 33) return null;
2682
+ let s = t + (a ? 33 : 1);
2683
+ if (e.length < s + 1) return null;
2684
+ const r = e[s];
2685
+ if (r !== 0 && r !== 1) return null;
2686
+ const o = r === 1;
2687
+ return o && e.length < s + 33 ? null : s + (o ? 33 : 1);
2688
+ }
2689
+ function Xa(e) {
2690
+ const t = Qa(e);
2691
+ if (t == null) return null;
2692
+ const n = 2 + ae + mt, a = e[n] === 1, s = a ? e.slice(n + 1, n + 33) : new Uint8Array(0), r = n + (a ? 33 : 1), c = e[r] === 1 ? e.slice(r + 1, r + 33) : new Uint8Array(0);
2693
+ return { rawTarget: s, rawAnchor: c, tagsStart: t };
2694
+ }
2695
+ async function es(e) {
2696
+ const t = Xa(e);
2697
+ if (t == null) return !1;
2698
+ const { rawTarget: n, rawAnchor: a, tagsStart: s } = t, r = s + 16;
2699
+ if (e.length < r) return !1;
2700
+ const o = new DataView(e.buffer, e.byteOffset, e.byteLength);
2701
+ if (o.getUint16(0, !0) !== lt) return !1;
2702
+ const i = e.slice(2, 2 + ae), l = e.slice(2 + ae, 2 + ae + mt), d = Number(
2703
+ o.getUint32(s + 8, !0) + o.getUint32(s + 12, !0) * 4294967296
2704
+ ), m = s + 16 + d;
2705
+ if (e.length < m) return !1;
2706
+ const p = e.slice(s + 16, m), h = e.slice(m);
2707
+ try {
2708
+ const u = await pt(
2709
+ l,
2710
+ n,
2711
+ a,
2712
+ p,
2713
+ h
2714
+ ), y = N.hashMessage(u), f = N.hexlify(i), b = N.SigningKey.recoverPublicKey(y, f), g = N.getBytes(b);
2715
+ return g.length === l.length && g.every((S, v) => S === l[v]);
2716
+ } catch {
2717
+ return !1;
2718
+ }
2719
+ }
2720
+ const ts = (e) => {
2721
+ let t = "";
2722
+ for (const n of e)
2723
+ t += String.fromCharCode(n);
2724
+ return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
2725
+ }, ns = K("seedProtocol:createArweaveDataItems"), as = he(
2726
+ async ({ input: { context: e } }) => {
2727
+ let { item: t } = e;
2728
+ t.getPublishUploads || (t = await dt(t.seedLocalId));
2729
+ let n;
2730
+ e.arweaveUploadTags?.length && (n = { arweaveUploadTags: e.arweaveUploadTags });
2731
+ const a = await tn(t, [], void 0, n), s = x(), r = e.signDataItems ?? s.signDataItems, o = e.dataItemSigner ?? s.dataItemSigner;
2732
+ let c, i;
2733
+ if (r)
2734
+ c = (await r(a)).map((m) => ({
2735
+ transaction: { id: m.transaction.id },
2736
+ versionId: m.versionId,
2737
+ modelName: m.modelName
2738
+ }));
2739
+ else if (o) {
2740
+ const d = o, m = [], p = Date.now(), h = d.address;
2741
+ for (let u = 0; u < a.length; u++) {
2742
+ const y = a[u], f = y.tags, b = new Uint8Array(8);
2743
+ crypto.getRandomValues(b);
2744
+ const g = (new DataView(b.buffer).getBigUint64(0, !1) ^ BigInt(u)) & 0xffffffffffffffffn, S = Ya(h, p, g), v = Ja(d) ? await Za(y.data, d, f, S) : await Ka(y.data, d, f, S);
2745
+ if (!await es(v.raw))
2746
+ throw ns("DataItem verification failed: id=%s modelName=%s", v.id, y.itemPropertyName), new Error(
2747
+ `DataItem signature verification failed for ${y.itemPropertyName}. The signing key may not match the owner, or the payload may have been modified.`
2748
+ );
2749
+ m.push(v);
2750
+ }
2751
+ i = m, c = m.map((u, y) => ({
2752
+ transaction: { id: u.id },
2753
+ versionId: a[y]?.versionLocalId,
2754
+ modelName: a[y]?.itemPropertyName
2755
+ }));
2756
+ } else
2757
+ throw new Error(
2758
+ "@seedprotocol/publish: useArweaveBundler requires signDataItems or dataItemSigner (pass at createPublish or in PublishProvider config)"
2759
+ );
2760
+ const l = a.map((d) => ({
2761
+ itemPropertyName: d.itemPropertyName,
2762
+ itemPropertyLocalId: d.itemPropertyLocalId,
2763
+ seedLocalId: d.seedLocalId,
2764
+ versionLocalId: d.versionLocalId,
2765
+ transactionToSign: null
2766
+ }));
2767
+ return {
2768
+ arweaveTransactions: c,
2769
+ publishUploads: l,
2770
+ arweaveUploadData: a,
2771
+ signedDataItems: i
2772
+ };
2773
+ }
2774
+ ), Pt = 8192;
2775
+ function ss(e) {
2776
+ const t = new Uint8Array(e);
2777
+ let n = "";
2778
+ for (let a = 0; a < t.length; a += Pt) {
2779
+ const s = t.subarray(a, Math.min(a + Pt, t.length));
2780
+ n += String.fromCharCode.apply(null, s);
2781
+ }
2782
+ return btoa(n);
2783
+ }
2784
+ async function rs(e) {
2785
+ const t = [];
2786
+ for (const [n, a] of e.entries()) {
2787
+ const s = a;
2788
+ if (typeof s == "object" && s !== null && "arrayBuffer" in s) {
2789
+ const r = await s.arrayBuffer(), o = ss(r), c = s;
2790
+ t.push({
2791
+ name: n,
2792
+ value: o,
2793
+ encoding: "base64",
2794
+ filename: c.name || void 0
2795
+ });
2796
+ } else
2797
+ t.push({ name: n, value: String(a) });
2798
+ }
2799
+ return t;
2800
+ }
2801
+ function os(e, t, n) {
2802
+ const a = ["Upload server returned ", String(e)], s = t && typeof t == "object" && "message" in t ? String(t.message) : t && typeof t == "object" && "error" in t ? String(t.error) : null;
2803
+ return s ? a.push(`: ${s}`) : n && a.push(` (${n})`), a.join("");
2804
+ }
2805
+ function is(e) {
2806
+ if (!e)
2807
+ return "Upload server unavailable. Please try again or check your connection.";
2808
+ const t = e.toLowerCase();
2809
+ 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.";
2810
+ }
2811
+ async function cs(e, t, n) {
2812
+ const a = typeof window < "u" ? window.Main : void 0;
2813
+ if (a?.uploadArweaveStart) {
2814
+ const o = await rs(t);
2815
+ return a.uploadArweaveStart(e, o);
2816
+ }
2817
+ const s = await fetch(e, {
2818
+ method: "POST",
2819
+ body: t
2820
+ }), r = await s.json().catch(() => ({}));
2821
+ return { status: s.status, body: r };
2822
+ }
2823
+ const ds = he(
2824
+ async ({ input: { context: e, event: t } }) => {
2825
+ const { arweaveTransactions: n = [], transactionKeys: a, reimbursementTransactionId: s } = e;
2826
+ if (s)
2827
+ return {
2828
+ transactionId: s
2829
+ };
2830
+ const r = n.map(({ transaction: p }) => p), o = new FormData();
2831
+ for (const p of r) {
2832
+ let { data: h, chunks: u, ...y } = p;
2833
+ const f = h instanceof Blob ? h : new Blob([h]);
2834
+ o.append(`${p.id}-data`, f, `${p.id}-data`);
2835
+ const b = new Blob([JSON.stringify(u)], { type: "application/json" });
2836
+ o.append(`${p.id}-chunks`, b, `${p.id}-chunks`);
2837
+ const g = new Blob([JSON.stringify(y)], { type: "application/json" });
2838
+ o.append(`${p.id}-json`, g, `${p.id}-json`);
2839
+ }
2840
+ const { uploadApiBaseUrl: c } = x(), i = `${c}/api/upload/arweave/start`, { status: l, body: d, message: m } = await cs(
2841
+ i,
2842
+ o
2843
+ );
2844
+ if (l >= 300 || l < 200) {
2845
+ const p = l === 0 ? m : null;
2846
+ p && console.error("[upload]", p);
2847
+ const h = l === 0 ? is(p) : os(l, d, a);
2848
+ throw new Error(h);
2849
+ }
2850
+ return d;
2851
+ }
2852
+ ), ls = he(async ({ input: { context: e, event: t } }) => {
2853
+ const { requestResponse: n, reimbursementTransactionId: a } = e;
2854
+ if (!n)
2855
+ throw new Error("No request response");
2856
+ if (!a)
2857
+ throw new Error("No reimbursement transaction id");
2858
+ const s = _e();
2859
+ await new Promise((o, c) => {
2860
+ const i = setInterval(async () => {
2861
+ let l;
2862
+ try {
2863
+ l = await s.transactions.getStatus(a);
2864
+ } catch {
2865
+ return;
2866
+ }
2867
+ l && l.confirmed && (clearInterval(i), o());
2868
+ }, 5e3);
2869
+ });
2870
+ }), ne = K("seedProtocol:services:publish:actors");
2871
+ function us(e) {
2872
+ if (e instanceof Uint8Array) return e;
2873
+ if (e instanceof ArrayBuffer) return new Uint8Array(e);
2874
+ throw new Error("Transaction data must be Uint8Array or ArrayBuffer for upload resume");
2875
+ }
2876
+ const ps = ye(
2877
+ ({ sendBack: e, input: t }) => {
2878
+ const n = t.context, s = (n.arweaveTransactions ?? []).map(({ transaction: l }) => l), r = _e(), o = n.uploaderState && typeof n.currentTransactionIndex == "number", c = o ? n.currentTransactionIndex : 0;
2879
+ (async () => {
2880
+ const l = s.length;
2881
+ for (let d = c; d < l; d++) {
2882
+ const m = s[d];
2883
+ if (!m) continue;
2884
+ const p = r.transactions.fromRaw(m);
2885
+ if (!await r.transactions.verify(p))
2886
+ throw new Error("Transaction verification failed");
2887
+ let u;
2888
+ const y = n.uploaderState;
2889
+ if (o && d === c && y) {
2890
+ const f = p.data, b = f instanceof Uint8Array ? f : us(f);
2891
+ u = await r.transactions.getUploader(y, b);
2892
+ } else
2893
+ u = await r.transactions.getUploader(p, p.data);
2894
+ for (; !u.isComplete; ) {
2895
+ ne("uploading chunk"), ne(`uploader.pctComplete: ${u.pctComplete}`), ne(`uploader.uploadedChunks: ${u.uploadedChunks}`), ne(`uploader.totalChunks: ${u.totalChunks}`), ne(u.lastResponseError), ne(u.lastResponseStatus);
2896
+ try {
2897
+ await u.uploadChunk();
2898
+ const f = Math.trunc((d + u.pctComplete / 100) / l * 100);
2899
+ e({
2900
+ type: "updatePercentage",
2901
+ completionPercentage: f,
2902
+ uploaderState: u.toJSON(),
2903
+ currentTransactionIndex: d
2904
+ }), ne(`${u.pctComplete}% complete, ${u.uploadedChunks}/${u.totalChunks}`);
2905
+ } catch (f) {
2906
+ ne(f);
2907
+ }
2908
+ }
2909
+ }
2910
+ return "done";
2911
+ })().then((l) => {
2912
+ e({ type: "uploadComplete", result: l });
2913
+ }).catch((l) => {
2914
+ e({ type: "uploadError", error: l });
2915
+ });
2916
+ }
2917
+ ), ms = ye(
2918
+ ({ sendBack: e, input: { context: t } }) => {
2919
+ const { signedDataItems: n } = t, { uploadApiBaseUrl: a, useArweaveBundler: s } = x();
2920
+ if (!s || !a) {
2921
+ e({
2922
+ type: "uploadError",
2923
+ error: new Error(
2924
+ "Arweave bundler not configured. Set useArweaveBundler and uploadApiBaseUrl."
2925
+ )
2926
+ });
2927
+ return;
2928
+ }
2929
+ const r = `${a.replace(/\/$/, "")}/api/upload/arweave/batch`;
2930
+ if (!n || n.length === 0) {
2931
+ e({ type: "uploadComplete", result: "done" });
2932
+ return;
2933
+ }
2934
+ (async () => {
2935
+ const c = async (f) => {
2936
+ const b = f;
2937
+ if (b.raw != null && (b.raw instanceof Uint8Array || Buffer.isBuffer(b.raw)))
2938
+ return Buffer.from(b.raw);
2939
+ if (typeof b.getRaw == "function") {
2940
+ const g = b.getRaw();
2941
+ return g instanceof Promise ? g : Buffer.from(g);
2942
+ }
2943
+ if (b.filename != null)
2944
+ return aa(b.filename);
2945
+ throw new Error("Cannot get raw bytes from DataItem");
2946
+ }, i = await Promise.all(
2947
+ n.map((f) => c(f))
2948
+ ), l = i.length;
2949
+ let d = 4;
2950
+ for (const f of i)
2951
+ d += 4 + f.length;
2952
+ const m = Buffer.alloc(d);
2953
+ let p = 0;
2954
+ m.writeUInt32BE(l, p), p += 4;
2955
+ for (const f of i)
2956
+ m.writeUInt32BE(f.length, p), p += 4, f.copy(m, p), p += f.length;
2957
+ const h = await fetch(r, {
2958
+ method: "POST",
2959
+ headers: { "Content-Type": "application/octet-stream" },
2960
+ body: m
2961
+ });
2962
+ if (!h.ok)
2963
+ throw new Error(`Batch upload failed: ${h.status}`);
2964
+ const u = await h.json().catch(() => ({})), y = typeof u.failed == "number" ? u.failed : 0;
2965
+ if (y > 0) {
2966
+ const f = u.total ?? "?", b = u.succeeded ?? 0;
2967
+ throw new Error(
2968
+ `Arweave batch upload failed: ${y} of ${f} item(s) failed (${b} succeeded)`
2969
+ );
2970
+ }
2971
+ })().then(() => e({ type: "uploadComplete", result: "done" })).catch((c) => e({ type: "uploadError", error: c }));
2972
+ }
2973
+ ), rn = "Could not connect the managed publishing account on Optimism Sepolia. Reconnect with the same sign-in method and try again.", fs = "Your publishing smart account is not deployed on Optimism Sepolia yet. Complete wallet setup, enable autoDeployManagedAccount in config if appropriate, then try again.", hs = "The managed account could not be confirmed on Optimism Sepolia after deployment. Wait a moment and retry, or check your network connection.", on = "Automatic deployment of the managed publishing account failed on Optimism Sepolia. Retry or deploy the account through your wallet provider.";
2974
+ async function Ut() {
2975
+ const { useModularExecutor: e } = x();
2976
+ if (!e)
2977
+ return { kind: "skip" };
2978
+ let t;
2979
+ try {
2980
+ t = await ot(E);
2981
+ } catch (a) {
2982
+ return { kind: "unavailable", cause: a };
2983
+ }
2984
+ return await Re(t) ? { kind: "ready", managedAddress: t } : { kind: "not_deployed", managedAddress: t };
2985
+ }
2986
+ async function cn() {
2987
+ const e = Me();
2988
+ await e.autoConnect({ client: R(), chain: E });
2989
+ const t = e.getAccount();
2990
+ if (!t)
2991
+ throw new Q(rn, "MANAGED_ACCOUNT_UNAVAILABLE");
2992
+ return t;
2993
+ }
2994
+ async function ys() {
2995
+ const e = await cn();
2996
+ try {
2997
+ await fa(e);
2998
+ } catch (t) {
2999
+ throw new Q(on, "MANAGED_ACCOUNT_NOT_DEPLOYED", e.address, t);
3000
+ }
3001
+ }
3002
+ async function dn() {
3003
+ const e = x();
3004
+ if (!e.useModularExecutor)
3005
+ throw new Error("runModularExecutorPublishPrep: useModularExecutor is false");
3006
+ let t = await Ut();
3007
+ if (t.kind === "unavailable")
3008
+ return {
3009
+ ok: !1,
3010
+ error: new Q(rn, "MANAGED_ACCOUNT_UNAVAILABLE", void 0, t.cause)
3011
+ };
3012
+ if (t.kind === "not_deployed")
3013
+ if (e.autoDeployManagedAccount) {
3014
+ try {
3015
+ await ys();
3016
+ } catch (n) {
3017
+ return { ok: !1, error: At(n) ? n : new Q(on, "MANAGED_ACCOUNT_NOT_DEPLOYED", t.managedAddress, n) };
3018
+ }
3019
+ if (t = await Ut(), t.kind !== "ready")
3020
+ return {
3021
+ ok: !1,
3022
+ error: new Q(
3023
+ hs,
3024
+ "MANAGED_ACCOUNT_NOT_DEPLOYED",
3025
+ t.kind === "not_deployed" ? t.managedAddress : void 0
3026
+ )
3027
+ };
3028
+ } else
3029
+ return {
3030
+ ok: !1,
3031
+ error: new Q(fs, "MANAGED_ACCOUNT_NOT_DEPLOYED", t.managedAddress)
3032
+ };
3033
+ if (t.kind === "ready") {
3034
+ if (e.modularAccountModuleContract)
3035
+ try {
3036
+ const n = await cn();
3037
+ await tt(t.managedAddress, n, e);
3038
+ } catch (n) {
3039
+ return At(n) ? { ok: !1, error: n } : {
3040
+ ok: !1,
3041
+ error: new Q(
3042
+ "Executor module setup failed on Optimism Sepolia.",
3043
+ "EXECUTOR_MODULE_NOT_INSTALLED",
3044
+ t.managedAddress,
3045
+ n
3046
+ )
3047
+ };
3048
+ }
3049
+ return { ok: !0, managedAddress: t.managedAddress };
3050
+ }
3051
+ throw new Error("runModularExecutorPublishPrep: unexpected readiness state");
3052
+ }
3053
+ const gs = K("seedProtocol:services:publish:actors:persistSeedUid"), Tt = "0x" + "0".repeat(64), ws = 15e3;
3054
+ function ln(e, t) {
3055
+ const n = e.seedLocalId, a = n ? t.find((r) => r?.localId === n) : void 0, s = a?.seedUid && a.seedUid !== Tt ? a.seedUid : t[0]?.seedUid;
3056
+ s && s !== Tt && (e.seedUid = s);
3057
+ }
3058
+ async function un(e, t) {
3059
+ const n = e.persistSeedUid;
3060
+ if (typeof n != "function") return;
3061
+ const a = new Promise(
3062
+ (s, r) => setTimeout(() => r(new Error("persistSeedUid timed out")), ws)
3063
+ );
3064
+ try {
3065
+ await Promise.race([n.call(e, t), a]);
3066
+ } catch (s) {
3067
+ gs("persistSeedUid failed (attestations already on-chain):", s);
3068
+ }
3069
+ }
3070
+ async function pn(e) {
3071
+ if (e.length === 0) return;
3072
+ const { arweaveUploadVerificationBaseUrl: t } = x(), n = await Promise.all(
3073
+ e.map(
3074
+ (a) => Mn(t, a)
3075
+ )
3076
+ );
3077
+ for (let a = 0; a < e.length; a++) {
3078
+ const s = e[a], r = n[a];
3079
+ if (r) {
3080
+ if (r.status === 404)
3081
+ throw new Error(
3082
+ `Arweave transaction ${s} not found. Upload may have failed. Delete this publish record and try again.`
3083
+ );
3084
+ if (r.status !== 200)
3085
+ throw new Error(
3086
+ `Arweave transaction ${s} is not yet available from the upload service (status: ${r.status}). Wait and retry.`
3087
+ );
3088
+ }
3089
+ }
3090
+ }
3091
+ function bs() {
3092
+ return Y({
3093
+ signature: "event CreatedAttestation((bytes32 schemaUid, bytes32 attestationUid) result)"
3094
+ });
3095
+ }
3096
+ function As() {
3097
+ return Y({
3098
+ signature: "event SeedPublished(bytes32 seedUid, bytes32 versionUid)"
3099
+ });
3100
+ }
3101
+ function xe(e) {
3102
+ return e == null || e === "" ? $ : ("0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(64, "0").slice(-64)).toLowerCase();
3103
+ }
3104
+ function Dt(e, t, n) {
3105
+ if (!t || !e.logs?.length) return;
3106
+ const a = xe(t);
3107
+ if (a === $) return;
3108
+ const s = n ? bs : Na;
3109
+ try {
3110
+ const r = rt({
3111
+ logs: e.logs,
3112
+ events: [s()],
3113
+ strict: !1
3114
+ });
3115
+ for (const o of r) {
3116
+ const c = o?.args?.result;
3117
+ if (c?.attestationUid && xe(c.schemaUid) === a) {
3118
+ const i = c.attestationUid;
3119
+ return i && xe(i) !== $ ? i : void 0;
3120
+ }
3121
+ }
3122
+ } catch {
3123
+ }
3124
+ }
3125
+ function xt(e, t, n, a) {
3126
+ const s = t.toLowerCase(), r = e.logs?.filter((o) => o.address && o.address.toLowerCase() === s);
3127
+ if (r?.length)
3128
+ try {
3129
+ const i = rt({
3130
+ logs: r,
3131
+ events: [(a ? As : Fa)()],
3132
+ strict: !1
3133
+ })[0];
3134
+ if (!i) return;
3135
+ if (a) {
3136
+ const f = i.args?.seedUid;
3137
+ return f && xe(f) !== $ ? f : void 0;
3138
+ }
3139
+ const d = i.args?.returnedDataFromEAS;
3140
+ if (!d || d === "0x") return;
3141
+ const p = Jn([{ type: "bytes32[]" }], d)[0];
3142
+ if (!p?.length) return;
3143
+ const u = p[n];
3144
+ return u && u !== $ ? u : p.length === 1 && p[0] && p[0] !== $ ? p[0] : void 0;
3145
+ } catch {
3146
+ return;
3147
+ }
3148
+ }
3149
+ const le = 64, G = (e) => {
3150
+ if (e == null) return "0x" + "0".repeat(le);
3151
+ if (typeof e == "string")
3152
+ return "0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(le, "0").slice(-le);
3153
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
3154
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e);
3155
+ return "0x" + Array.from(t).map((a) => a.toString(16).padStart(2, "0")).join("").padStart(le, "0").slice(-le);
3156
+ }
3157
+ return "0x" + "0".repeat(le);
3158
+ }, vs = (e) => {
3159
+ if (e == null || typeof e == "string" && (e === "" || e === "0x")) return "0x";
3160
+ if (typeof e == "string") {
3161
+ const n = (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0");
3162
+ return "0x" + (n.length % 2 === 1 ? "0" + n : n);
3163
+ }
3164
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
3165
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e);
3166
+ return "0x" + Array.from(t).map((n) => n.toString(16).padStart(2, "0")).join("");
3167
+ }
3168
+ return "0x";
3169
+ };
3170
+ function Ss(e) {
3171
+ const t = new Set(
3172
+ e.map((n) => n?.localId).filter((n) => !!n)
3173
+ );
3174
+ return e.some(
3175
+ (n) => (n?.listOfAttestations ?? []).some((a) => {
3176
+ const s = a;
3177
+ return s._unresolvedValue && t.has(s._unresolvedValue) ? !0 : Array.isArray(s._rawListIdsForResolve) ? s._rawListIdsForResolve.some((r) => r && t.has(String(r).trim())) : !1;
3178
+ })
3179
+ );
3180
+ }
3181
+ function Es(e, t) {
3182
+ return (e ?? []).filter(
3183
+ (n) => n.publishLocalId && t.has(n.publishLocalId)
3184
+ );
3185
+ }
3186
+ const Is = {
3187
+ recipient: Xe,
3188
+ expirationTime: BigInt(0),
3189
+ revocable: !0,
3190
+ refUID: $,
3191
+ data: $,
3192
+ value: BigInt(0)
3193
+ };
3194
+ function Je(e) {
3195
+ const t = (e?.listOfAttestations ?? []).map((a) => {
3196
+ const s = Array.isArray(a?.data) ? a.data : [];
3197
+ return {
3198
+ schema: G(a?.schema),
3199
+ data: s.map((r) => ({
3200
+ ...r,
3201
+ refUID: G(r?.refUID),
3202
+ data: vs(r?.data),
3203
+ expirationTime: r?.expirationTime != null ? BigInt(r.expirationTime) : BigInt(0),
3204
+ value: r?.value != null ? BigInt(r.value) : BigInt(0)
3205
+ }))
3206
+ };
3207
+ }), n = (e?.propertiesToUpdate ?? []).map((a) => ({
3208
+ ...a,
3209
+ propertySchemaUid: G(a?.propertySchemaUid)
3210
+ }));
3211
+ return {
3212
+ ...e,
3213
+ seedUid: G(e?.seedUid),
3214
+ seedSchemaUid: G(e?.seedSchemaUid),
3215
+ versionUid: G(e?.versionUid),
3216
+ versionSchemaUid: G(e?.versionSchemaUid),
3217
+ listOfAttestations: t,
3218
+ propertiesToUpdate: n
3219
+ };
3220
+ }
3221
+ function Ct(e, t) {
3222
+ for (const n of e)
3223
+ for (const a of n?.propertiesToUpdate ?? []) {
3224
+ const s = a?.publishLocalId, r = G(a?.propertySchemaUid);
3225
+ if (!s || !r) continue;
3226
+ const o = t.get(s);
3227
+ if (!o?.listOfAttestations) continue;
3228
+ const c = o.listOfAttestations.find(
3229
+ (i) => G(i?.schema)?.toLowerCase() === r?.toLowerCase()
3230
+ );
3231
+ c && (!Array.isArray(c.data) || c.data.length === 0) && (c.data = [{ ...Is, refUID: $ }]);
3232
+ }
3233
+ }
3234
+ const Ps = "pending_l1";
3235
+ async function mn(e) {
3236
+ const { useArweaveBundler: t } = x();
3237
+ if (!t) return;
3238
+ const n = e.arweaveTransactions ?? [], a = e.publishUploads ?? [];
3239
+ if (n.length === 0 || n.length !== a.length) return;
3240
+ const s = B.getAppDb();
3241
+ if (!s) return;
3242
+ const r = Date.now();
3243
+ for (let o = 0; o < n.length; o++) {
3244
+ const c = n[o], i = a[o];
3245
+ if (!i) continue;
3246
+ const l = c.transaction?.id;
3247
+ if (!(!l || typeof l != "string"))
3248
+ try {
3249
+ await s.insert(De).values({
3250
+ seedLocalId: i.seedLocalId,
3251
+ dataItemId: l,
3252
+ versionLocalId: i.versionLocalId ?? null,
3253
+ itemPropertyName: i.itemPropertyName ?? null,
3254
+ phase: Ps,
3255
+ createdAt: r,
3256
+ updatedAt: r
3257
+ }).onConflictDoNothing();
3258
+ } catch {
3259
+ }
3260
+ }
3261
+ }
3262
+ const Us = K("seedProtocol:services:publish:actors"), Ts = he(
3263
+ async ({ input: { context: e, event: t } }) => {
3264
+ const { address: n, account: a } = e, s = e.arweaveTransactions ?? [], r = e.publishUploads ?? [];
3265
+ let { item: o } = e;
3266
+ const { modularAccountModuleContract: c, useModularExecutor: i } = x();
3267
+ if (!n || typeof n != "string" || !n.trim())
3268
+ throw new Error("No wallet address for publish. Connect a wallet and try again.");
3269
+ if (!a)
3270
+ throw new Error("Wallet session is missing. Reconnect your wallet and retry the publish.");
3271
+ if (!o?.seedLocalId)
3272
+ throw new Error(
3273
+ "Attestation recovery failed: Item data is missing. Delete this publish record and try a full publish from the beginning."
3274
+ );
3275
+ typeof o.getPublishUploads != "function" && (o = await dt(o.seedLocalId));
3276
+ const d = s.length, m = r.length;
3277
+ if (d !== m)
3278
+ throw new Error(
3279
+ "Attestation recovery failed: Arweave transaction data is missing or incomplete. Delete this publish record and try a full publish from the beginning."
3280
+ );
3281
+ const p = V({
3282
+ client: R(),
3283
+ chain: E,
3284
+ address: n
3285
+ });
3286
+ let h = i && c ? V({
3287
+ client: R(),
3288
+ chain: E,
3289
+ address: c
3290
+ }) : p;
3291
+ await Oe(o, a, R(), E);
3292
+ const u = s.map(
3293
+ (w, U) => {
3294
+ const A = w.transaction?.id;
3295
+ if (!A || typeof A != "string")
3296
+ throw new Error(
3297
+ "Attestation recovery failed: Arweave transaction data did not survive restore. Delete this publish record and try a full publish from the beginning."
3298
+ );
3299
+ const M = r[U];
3300
+ if (!M) throw new Error("Publish upload index mismatch");
3301
+ return { ...M, txId: A };
3302
+ }
3303
+ );
3304
+ await pn(u.map((w) => w.txId));
3305
+ let y;
3306
+ try {
3307
+ y = await o.getPublishPayload(u, { publishMode: e.publishMode ?? "patch" });
3308
+ } catch (w) {
3309
+ throw w;
3310
+ }
3311
+ const f = Array.isArray(y) ? y : [y];
3312
+ let b = a;
3313
+ if (i) {
3314
+ const w = await dn();
3315
+ if (!w.ok)
3316
+ throw w.error;
3317
+ h = V({
3318
+ client: R(),
3319
+ chain: E,
3320
+ address: yt
3321
+ });
3322
+ const U = it();
3323
+ await U.autoConnect({ client: R(), chain: E });
3324
+ const F = U.getAccount();
3325
+ if (!F)
3326
+ throw new Error("Failed to get modular account");
3327
+ b = F;
3328
+ }
3329
+ const g = i ? yt : n, S = f.length > 1 && Ss(f);
3330
+ let v;
3331
+ if (S) {
3332
+ let w = structuredClone(f);
3333
+ const U = {};
3334
+ for (let A = 0; A < w.length; A++) {
3335
+ w = await ht(w, U);
3336
+ const M = w[A], X = /* @__PURE__ */ new Set([M.localId]), ge = {
3337
+ ...M,
3338
+ propertiesToUpdate: Es(M.propertiesToUpdate, X)
3339
+ }, J = Je(ge), Be = /* @__PURE__ */ new Map([[J.localId, J]]);
3340
+ Ct([J], Be);
3341
+ const Ne = {
3342
+ ...vt({
3343
+ contract: h,
3344
+ requests: [J]
3345
+ }),
3346
+ gas: 5000000n
3347
+ }, Fe = await k({
3348
+ account: b,
3349
+ transaction: await Promise.resolve(Ne)
3350
+ }), re = await H({
3351
+ client: R(),
3352
+ chain: E,
3353
+ transactionHash: Fe.transactionHash
3354
+ });
3355
+ if (!re)
3356
+ throw new Error("Failed to send transaction");
3357
+ const oe = !J.seedUid || G(J.seedUid) === $, wn = J?.listOfAttestations?.length ?? 0, bn = J?.seedSchemaUid;
3358
+ if (oe) {
3359
+ const ke = Dt(re, bn, i) ?? xt(
3360
+ re,
3361
+ g,
3362
+ wn,
3363
+ i
3364
+ );
3365
+ ke && (U[M.localId] = ke, w[A] = { ...w[A], seedUid: ke });
3366
+ }
3367
+ }
3368
+ for (const A of w) {
3369
+ const M = A?.localId, X = A?.seedUid;
3370
+ M && X && G(X) !== $ && (U[M] = G(X));
3371
+ }
3372
+ v = (await ht(structuredClone(f), U)).map(
3373
+ (A) => Je({
3374
+ ...A,
3375
+ seedUid: U[A.localId] ?? A.seedUid
3376
+ })
3377
+ );
3378
+ } else {
3379
+ const w = f.map((oe) => Je(oe)), U = new Map(w.map((oe) => [oe?.localId, oe]));
3380
+ Ct(w, U);
3381
+ const F = Array.isArray(y) ? w : [w[0]], A = {
3382
+ ...vt({
3383
+ contract: h,
3384
+ requests: F
3385
+ }),
3386
+ gas: 5000000n
3387
+ }, M = await k({
3388
+ account: b,
3389
+ transaction: await Promise.resolve(A)
3390
+ }), X = await H({
3391
+ client: R(),
3392
+ chain: E,
3393
+ transactionHash: M.transactionHash
3394
+ });
3395
+ if (!X)
3396
+ throw new Error("Failed to send transaction");
3397
+ const ge = w[0], J = ge?.seedUid, Be = J === $ || !J, Ne = ge?.listOfAttestations?.length ?? 0, Fe = ge?.seedSchemaUid, re = Be ? Dt(X, Fe, i) ?? xt(
3398
+ X,
3399
+ g,
3400
+ Ne,
3401
+ i
3402
+ ) : void 0;
3403
+ v = re && w.length > 0 ? [{ ...w[0], seedUid: re }, ...w.slice(1)] : w;
3404
+ }
3405
+ ln(o, v);
3406
+ const I = o, D = v.find((w) => w?.localId === o.seedLocalId)?.seedUid;
3407
+ return D && D !== $ && await un(I, n), Us("requestData", y), mn(e), { easPayload: y };
3408
+ }
3409
+ ), Rt = K("seedProtocol:services:publish:verifyAttestations"), Ds = "0x" + "0".repeat(64), Pe = 64, _t = (e) => e == null ? "0x" + "0".repeat(Pe) : typeof e == "string" ? "0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(Pe, "0").slice(-Pe) : "0x" + "0".repeat(Pe), xs = 5e3, ze = 6;
3410
+ async function Cs({
3411
+ normalizedRequests: e,
3412
+ item: t
3413
+ }) {
3414
+ const n = t.seedLocalId;
3415
+ for (const a of e) {
3416
+ if (a.listOfAttestations.length === 0 || a.versionUid === Ds) continue;
3417
+ const s = a.listOfAttestations.map(
3418
+ (d) => _t(d.schema).toLowerCase()
3419
+ );
3420
+ let r = [], o;
3421
+ for (let d = 1; d <= ze; d++)
3422
+ try {
3423
+ d > 1 && await new Promise((m) => setTimeout(m, xs)), r = await On({
3424
+ versionUids: [a.versionUid]
3425
+ });
3426
+ break;
3427
+ } catch (m) {
3428
+ if (o = m, Rt("verifyAttestations attempt %d failed:", d, m), d === ze)
3429
+ throw Rt("verifyAttestations: giving up after %d attempts", ze), o;
3430
+ }
3431
+ const c = r.map((d) => d.schemaId ? _t(d.schemaId).toLowerCase() : "").filter(Boolean), i = new Set(c);
3432
+ if (s.filter((d) => !i.has(d)).length > 0)
3433
+ throw new Zt(
3434
+ `Publish verification failed: Seed and Version attestations were created, but property/metadata attestations are missing or incomplete. Expected ${s.length} property attestations for schema(s) ${s.join(", ")}; found ${c.length}. Use PublishManager.retryAttestations('${n}') to retry.`,
3435
+ n,
3436
+ s,
3437
+ c,
3438
+ "METADATA_PROPERTIES_MISSING"
3439
+ );
3440
+ }
3441
+ }
3442
+ const be = K("seedProtocol:services:publish:createAttestationsDirectToEas"), ue = 64, z = (e) => {
3443
+ if (e == null) return "0x" + "0".repeat(ue);
3444
+ if (typeof e == "string")
3445
+ return "0x" + (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0").padStart(ue, "0").slice(-ue);
3446
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
3447
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e);
3448
+ return "0x" + Array.from(t).map((a) => a.toString(16).padStart(2, "0")).join("").padStart(ue, "0").slice(-ue);
3449
+ }
3450
+ return "0x" + "0".repeat(ue);
3451
+ }, Rs = (e) => {
3452
+ if (e == null || typeof e == "string" && (e === "" || e === "0x")) return "0x";
3453
+ if (typeof e == "string") {
3454
+ const n = (e.startsWith("0x") ? e.slice(2) : e).replace(/[^0-9a-fA-F]/g, "0");
3455
+ return "0x" + (n.length % 2 === 1 ? "0" + n : n);
3456
+ }
3457
+ if (e instanceof Uint8Array || typeof ArrayBuffer < "u" && e instanceof ArrayBuffer) {
3458
+ const t = e instanceof Uint8Array ? e : new Uint8Array(e);
3459
+ return "0x" + Array.from(t).map((n) => n.toString(16).padStart(2, "0")).join("");
3460
+ }
3461
+ return "0x";
3462
+ }, _s = async (e) => {
3463
+ let t;
3464
+ try {
3465
+ t = await se.find({ seedLocalId: e });
3466
+ } catch {
3467
+ }
3468
+ return t || new Promise((n) => {
3469
+ const a = setInterval(() => {
3470
+ try {
3471
+ se.find({ seedLocalId: e }).then((s) => {
3472
+ s && (clearInterval(a), n(s));
3473
+ });
3474
+ } catch {
3475
+ }
3476
+ }, 200);
3477
+ });
3478
+ }, Ls = he(
3479
+ async ({ input: { context: e, event: t } }) => {
3480
+ const { address: n, account: a } = e, s = e.arweaveTransactions ?? [], r = e.publishUploads ?? [];
3481
+ let { item: o } = e;
3482
+ if (!n || typeof n != "string" || !n.trim())
3483
+ throw new Error("No wallet address for publish. Connect a wallet and try again.");
3484
+ if (!a)
3485
+ throw new Error("Wallet session is missing. Reconnect your wallet and retry the publish.");
3486
+ if (!o?.seedLocalId)
3487
+ throw new Error(
3488
+ "Attestation recovery failed: Item data is missing. Delete this publish record and try a full publish from the beginning."
3489
+ );
3490
+ typeof o.getPublishUploads != "function" && (o = await _s(o.seedLocalId));
3491
+ const i = s.length, l = r.length;
3492
+ if (i !== l)
3493
+ throw new Error(
3494
+ "Attestation recovery failed: Arweave transaction data is missing or incomplete. Delete this publish record and try a full publish from the beginning."
3495
+ );
3496
+ await Oe(o, a, R(), E);
3497
+ const d = s.map(
3498
+ (g, S) => {
3499
+ const I = g.transaction?.id;
3500
+ if (!I || typeof I != "string")
3501
+ throw new Error(
3502
+ "Attestation recovery failed: Arweave transaction data did not survive restore. Delete this publish record and try a full publish from the beginning."
3503
+ );
3504
+ const q = r[S];
3505
+ if (!q) throw new Error("Publish upload index mismatch");
3506
+ return { ...q, txId: I };
3507
+ }
3508
+ );
3509
+ await pn(d.map((g) => g.txId));
3510
+ const m = await o.getPublishPayload(d, { publishMode: e.publishMode ?? "patch" }), h = (Array.isArray(m) ? m : [m]).map((g) => {
3511
+ const S = (g?.listOfAttestations ?? []).map((I) => {
3512
+ const q = Array.isArray(I?.data) ? I.data : [];
3513
+ return {
3514
+ schema: z(I?.schema),
3515
+ data: q.map((D) => ({
3516
+ ...D,
3517
+ refUID: z(D?.refUID),
3518
+ data: Rs(D?.data)
3519
+ }))
3520
+ };
3521
+ }), v = (g?.propertiesToUpdate ?? []).map((I) => ({
3522
+ ...I,
3523
+ propertySchemaUid: z(I?.propertySchemaUid)
3524
+ }));
3525
+ return {
3526
+ ...g,
3527
+ seedUid: z(g?.seedUid),
3528
+ seedSchemaUid: z(g?.seedSchemaUid),
3529
+ versionUid: z(g?.versionUid),
3530
+ versionSchemaUid: z(g?.versionSchemaUid),
3531
+ listOfAttestations: S,
3532
+ propertiesToUpdate: v
3533
+ };
3534
+ }), u = new Map(h.map((g) => [g.localId, g])), y = {
3535
+ recipient: Xe,
3536
+ expirationTime: BigInt(0),
3537
+ revocable: !0,
3538
+ refUID: W,
3539
+ data: W,
3540
+ value: BigInt(0)
3541
+ };
3542
+ for (const g of h)
3543
+ for (const S of g.propertiesToUpdate ?? []) {
3544
+ const v = S.publishLocalId, I = z(S.propertySchemaUid);
3545
+ if (!v || !I) continue;
3546
+ const q = u.get(v);
3547
+ if (!q?.listOfAttestations) continue;
3548
+ const D = q.listOfAttestations.find(
3549
+ (w) => z(w?.schema)?.toLowerCase() === I?.toLowerCase()
3550
+ );
3551
+ D && (!Array.isArray(D.data) || D.data.length === 0) && (D.data = [{ ...y, refUID: W }]);
3552
+ }
3553
+ const f = R();
3554
+ for (let g = 0; g < h.length; g++) {
3555
+ const S = h[g];
3556
+ let v = S.seedUid, I = S.versionUid;
3557
+ if (v === W) {
3558
+ const D = wt(f, E, {
3559
+ schema: S.seedSchemaUid,
3560
+ data: {
3561
+ refUID: W,
3562
+ data: qe(S.seedSchemaUid),
3563
+ revocable: S.seedIsRevocable
3564
+ }
3565
+ }), w = await k({ account: a, transaction: D }), U = await H({
3566
+ client: f,
3567
+ chain: E,
3568
+ transactionHash: w.transactionHash
3569
+ });
3570
+ if (!U) throw new Error("Failed to create Seed attestation");
3571
+ const { easContractAddress: F } = x(), A = bt(U, F);
3572
+ if (!A || A === W)
3573
+ throw new Error("Failed to get Seed UID from attestation receipt");
3574
+ v = A, S.seedUid = A, be("created Seed attestation", v);
3575
+ }
3576
+ if (v !== W && I === W) {
3577
+ const D = wt(f, E, {
3578
+ schema: S.versionSchemaUid,
3579
+ data: {
3580
+ refUID: v,
3581
+ data: qe(S.versionSchemaUid),
3582
+ revocable: !0
3583
+ }
3584
+ }), w = await k({ account: a, transaction: D }), U = await H({
3585
+ client: f,
3586
+ chain: E,
3587
+ transactionHash: w.transactionHash
3588
+ });
3589
+ if (!U) throw new Error("Failed to create Version attestation");
3590
+ const { easContractAddress: F } = x(), A = bt(U, F);
3591
+ if (!A || A === W)
3592
+ throw new Error("Failed to get Version UID from attestation receipt");
3593
+ I = A, S.versionUid = A, await Bn({
3594
+ seedLocalId: S.localId,
3595
+ versionUid: A,
3596
+ publisher: n
3597
+ }), be("created Version attestation", I);
3598
+ }
3599
+ for (const D of S.listOfAttestations)
3600
+ for (const w of D.data)
3601
+ w.refUID = I;
3602
+ for (const D of S.propertiesToUpdate ?? []) {
3603
+ const w = u.get(D.publishLocalId);
3604
+ if (!w?.listOfAttestations) continue;
3605
+ const U = z(D.propertySchemaUid), F = w.listOfAttestations.find(
3606
+ (A) => z(A?.schema)?.toLowerCase() === U?.toLowerCase()
3607
+ );
3608
+ F?.data?.[0] && (F.data[0].data = qe(v));
3609
+ }
3610
+ const q = S.listOfAttestations.map((D) => ({
3611
+ schema: D.schema,
3612
+ data: D.data.map((w) => ({
3613
+ recipient: w.recipient ?? Xe,
3614
+ expirationTime: w.expirationTime ?? 0n,
3615
+ revocable: w.revocable ?? !0,
3616
+ refUID: w.refUID ?? W,
3617
+ data: w.data ?? "0x",
3618
+ value: w.value ?? 0n
3619
+ }))
3620
+ }));
3621
+ if (q.length > 0) {
3622
+ const D = Aa(f, E, q), w = await k({ account: a, transaction: D });
3623
+ if (!await H({
3624
+ client: f,
3625
+ chain: E,
3626
+ transactionHash: w.transactionHash
3627
+ })) throw new Error("Failed to create property attestations");
3628
+ be("created property attestations for request", g);
3629
+ }
3630
+ }
3631
+ ln(o, h);
3632
+ const b = o;
3633
+ h[0]?.seedUid && h[0].seedUid !== W && await un(b, n);
3634
+ try {
3635
+ await Cs({ normalizedRequests: h, item: o });
3636
+ } catch (g) {
3637
+ throw g instanceof Zt || be("verifyAttestations failed (non-verification error):", g), g;
3638
+ }
3639
+ return be("direct EAS publish complete"), mn(e), { easPayload: m };
3640
+ }
3641
+ ), Ms = async (e) => {
3642
+ let t;
3643
+ try {
3644
+ t = await se.find({ seedLocalId: e });
3645
+ } catch {
3646
+ }
3647
+ return t || new Promise((n) => {
3648
+ const a = setInterval(() => {
3649
+ se.find({ seedLocalId: e }).then((s) => {
3650
+ s && (clearInterval(a), n(s));
3651
+ }).catch(() => {
3652
+ });
3653
+ }, 200);
3654
+ });
3655
+ };
3656
+ async function Os(e) {
3657
+ const n = typeof e.getPublishUploads == "function" ? e : await Ms(e.seedLocalId);
3658
+ return await Nn(n);
3659
+ }
3660
+ const pe = /* @__PURE__ */ new Set(), Bs = ye(({ sendBack: e, input: { context: t } }) => {
3661
+ const { item: n, account: a, publishMode: s } = t;
3662
+ return (async () => {
3663
+ if (!await Ft(n)) {
3664
+ e({ type: "notOwner" });
3665
+ return;
3666
+ }
3667
+ if (pe.has(n.seedLocalId)) {
3668
+ e({
3669
+ type: "redundantPublishProcess"
3670
+ });
3671
+ return;
3672
+ }
3673
+ pe.add(n.seedLocalId);
3674
+ try {
3675
+ a && await Oe(n, a, R(), E);
3676
+ const c = await Fn(n, [], {
3677
+ publishMode: s ?? "patch"
3678
+ });
3679
+ if (!c.isValid) {
3680
+ pe.delete(n.seedLocalId), e({ type: "validationFailed", errors: c.errors });
3681
+ return;
3682
+ }
3683
+ if (await Os(n)) {
3684
+ const l = x().useArweaveBundler;
3685
+ e({ type: l ? "validPublishProcessBundler" : "validPublishProcess" });
3686
+ } else
3687
+ e({ type: "skipArweave" });
3688
+ } catch (c) {
3689
+ pe.delete(n.seedLocalId), console.error("[checking] itemNeedsArweaveUpload failed", c), e({ type: "skipArweave" });
3690
+ }
3691
+ })().catch(() => {
3692
+ pe.delete(n.seedLocalId), e({ type: "validPublishProcess" });
3693
+ }), () => {
3694
+ pe.delete(n.seedLocalId);
3695
+ };
3696
+ }), {
3697
+ SUCCESS: Ze,
3698
+ FAILURE: Ke
3699
+ } = L;
3700
+ function ee(e) {
3701
+ const t = e;
3702
+ return t.error ?? t.data;
3703
+ }
3704
+ const fn = qt({
3705
+ types: {
3706
+ context: {},
3707
+ input: {}
3708
+ },
3709
+ actors: {
3710
+ createArweaveTransactions: $a,
3711
+ createArweaveDataItems: as,
3712
+ sendReimbursementRequest: ds,
3713
+ pollForConfirmation: ls,
3714
+ uploadData: ps,
3715
+ uploadViaBundler: ms,
3716
+ createAttestations: Ts,
3717
+ createAttestationsDirectToEas: Ls,
3718
+ checking: Bs
3719
+ },
3720
+ actions: {
3721
+ /** Log error; error/errorStep are assigned per transition. Supports both event.error (custom events) and event.data (XState fromPromise invoke errors). */
3722
+ handleError: ({ event: e }) => {
3723
+ const t = ee(e);
3724
+ t != null ? console.error(t) : console.error("Unknown error (full event):", e);
3725
+ },
3726
+ assignErrorCreatingArweaveTransactions: T({
3727
+ error: ({ event: e }) => ee(e),
3728
+ errorStep: () => "creatingArweaveTransactions"
3729
+ }),
3730
+ assignErrorCreatingArweaveDataItems: T({
3731
+ error: ({ event: e }) => ee(e),
3732
+ errorStep: () => "creatingArweaveDataItems"
3733
+ }),
3734
+ assignErrorSendingReimbursementRequest: T({
3735
+ error: ({ event: e }) => ee(e),
3736
+ errorStep: () => "sendingReimbursementRequest"
3737
+ }),
3738
+ assignErrorPollingForConfirmation: T({
3739
+ error: ({ event: e }) => ee(e),
3740
+ errorStep: () => "pollingForConfirmation"
3741
+ }),
3742
+ assignErrorUploadingData: T({
3743
+ error: ({ event: e }) => ee(e),
3744
+ errorStep: () => "uploadingData"
3745
+ }),
3746
+ assignErrorUploadingViaBundler: T({
3747
+ error: ({ event: e }) => ee(e),
3748
+ errorStep: () => "uploadingViaBundler"
3749
+ }),
3750
+ assignErrorCreatingAttestations: T({
3751
+ error: ({ event: e }) => ee(e),
3752
+ errorStep: () => "creatingAttestations"
3753
+ }),
3754
+ assignErrorCreatingAttestationsDirectToEas: T({
3755
+ error: ({ event: e }) => ee(e),
3756
+ errorStep: () => "creatingAttestationsDirectToEas"
3757
+ }),
3758
+ assignAccountFromRetry: T({
3759
+ account: ({ event: e }) => e.account
3760
+ }),
3761
+ assignErrorNotOwner: T({
3762
+ error: () => new Error("Item is read-only: you do not own this item. Only the publisher can publish."),
3763
+ errorStep: () => "checking"
3764
+ }),
3765
+ assignErrorValidationFailed: T({
3766
+ error: ({ event: e }) => {
3767
+ const n = e.errors ?? [], a = n.length > 0 ? `Validation failed (${n.length} error${n.length === 1 ? "" : "s"}):
3768
+ ${n.map((r) => r.message).join(`
3769
+ `)}` : "Validation failed", s = new Error(a);
3770
+ return s.validationErrors = n, s;
3771
+ },
3772
+ errorStep: () => "checking"
3773
+ })
3774
+ }
3775
+ }).createMachine({
3776
+ id: "publish",
3777
+ initial: "checking",
3778
+ context: ({ input: e }) => e,
3779
+ states: {
3780
+ checking: {
3781
+ on: {
3782
+ notOwner: {
3783
+ target: Ke,
3784
+ actions: ["assignErrorNotOwner", "handleError"]
3785
+ },
3786
+ validationFailed: {
3787
+ target: Ke,
3788
+ actions: ["assignErrorValidationFailed", "handleError"]
3789
+ },
3790
+ redundantPublishProcess: {
3791
+ target: "stopping"
3792
+ },
3793
+ validPublishProcess: {
3794
+ target: "creatingArweaveTransactions"
3795
+ },
3796
+ validPublishProcessBundler: {
3797
+ target: "creatingArweaveDataItems"
3798
+ },
3799
+ skipArweave: [
3800
+ {
3801
+ guard: () => x().useDirectEas,
3802
+ target: "creatingAttestationsDirectToEas",
3803
+ actions: T({
3804
+ arweaveTransactions: () => [],
3805
+ publishUploads: () => []
3806
+ })
3807
+ },
3808
+ {
3809
+ guard: () => !x().useDirectEas,
3810
+ target: "creatingAttestations",
3811
+ actions: T({
3812
+ arweaveTransactions: () => [],
3813
+ publishUploads: () => []
3814
+ })
3815
+ }
3816
+ ]
3817
+ },
3818
+ invoke: {
3819
+ src: "checking",
3820
+ input: ({ context: e }) => ({ context: e })
3821
+ }
3822
+ },
3823
+ creatingArweaveTransactions: {
3824
+ invoke: {
3825
+ src: "createArweaveTransactions",
3826
+ input: ({ context: e, event: t }) => ({ context: e, event: t }),
3827
+ onDone: {
3828
+ target: "sendingReimbursementRequest",
3829
+ actions: T({
3830
+ arweaveTransactions: ({ event: e }) => e.output.arweaveTransactions,
3831
+ publishUploads: ({ event: e }) => e.output.publishUploads
3832
+ })
3833
+ },
3834
+ onError: {
3835
+ target: "failure",
3836
+ actions: ["assignErrorCreatingArweaveTransactions", "handleError"]
3837
+ }
3838
+ }
3839
+ },
3840
+ creatingArweaveDataItems: {
3841
+ invoke: {
3842
+ src: "createArweaveDataItems",
3843
+ input: ({ context: e, event: t }) => ({ context: e, event: t }),
3844
+ onDone: {
3845
+ target: "uploadingViaBundler",
3846
+ actions: T({
3847
+ arweaveTransactions: ({ event: e }) => e.output.arweaveTransactions,
3848
+ publishUploads: ({ event: e }) => e.output.publishUploads,
3849
+ arweaveUploadData: ({ event: e }) => e.output.arweaveUploadData,
3850
+ signedDataItems: ({ event: e }) => e.output.signedDataItems
3851
+ })
3852
+ },
3853
+ onError: {
3854
+ target: "failure",
3855
+ actions: ["assignErrorCreatingArweaveDataItems", "handleError"]
3856
+ }
3857
+ }
3858
+ },
3859
+ sendingReimbursementRequest: {
3860
+ invoke: {
3861
+ src: "sendReimbursementRequest",
3862
+ input: ({ context: e, event: t }) => ({ context: e, event: t }),
3863
+ onDone: {
3864
+ target: "pollingForConfirmation",
3865
+ actions: T({
3866
+ requestResponse: ({ event: e }) => e.output,
3867
+ reimbursementTransactionId: ({ event: e }) => e.output.transactionId
3868
+ })
3869
+ },
3870
+ onError: {
3871
+ target: "failure",
3872
+ actions: ["assignErrorSendingReimbursementRequest", "handleError"]
3873
+ }
3874
+ }
3875
+ },
3876
+ pollingForConfirmation: {
3877
+ invoke: {
3878
+ src: "pollForConfirmation",
3879
+ input: ({ context: e, event: t }) => ({ context: e, event: t }),
3880
+ onDone: {
3881
+ target: "uploadingData",
3882
+ actions: T({
3883
+ reimbursementConfirmed: !0
3884
+ })
3885
+ },
3886
+ onError: {
3887
+ target: "failure",
3888
+ actions: ["assignErrorPollingForConfirmation", "handleError"]
3889
+ }
3890
+ }
3891
+ },
3892
+ uploadingViaBundler: {
3893
+ on: {
3894
+ uploadComplete: [
3895
+ {
3896
+ guard: () => x().useDirectEas,
3897
+ target: "creatingAttestationsDirectToEas",
3898
+ actions: T({
3899
+ completionPercentage: 100
3900
+ })
3901
+ },
3902
+ {
3903
+ guard: () => !x().useDirectEas,
3904
+ target: "creatingAttestations",
3905
+ actions: T({
3906
+ completionPercentage: 100
3907
+ })
3908
+ }
3909
+ ],
3910
+ uploadError: {
3911
+ target: "failure",
3912
+ actions: ["assignErrorUploadingViaBundler", "handleError"]
3913
+ }
3914
+ },
3915
+ invoke: {
3916
+ src: "uploadViaBundler",
3917
+ input: ({ context: e }) => ({ context: e })
3918
+ }
3919
+ },
3920
+ uploadingData: {
3921
+ on: {
3922
+ updatePercentage: {
3923
+ actions: T({
3924
+ completionPercentage: ({ event: e }) => e.completionPercentage,
3925
+ uploaderState: ({ event: e }) => e.uploaderState,
3926
+ currentTransactionIndex: ({ event: e }) => e.currentTransactionIndex
3927
+ })
3928
+ },
3929
+ uploadComplete: [
3930
+ {
3931
+ guard: () => x().useDirectEas,
3932
+ target: "creatingAttestationsDirectToEas",
3933
+ actions: T({
3934
+ completionPercentage: 100
3935
+ })
3936
+ },
3937
+ {
3938
+ guard: () => !x().useDirectEas,
3939
+ target: "creatingAttestations",
3940
+ actions: T({
3941
+ completionPercentage: 100
3942
+ })
3943
+ }
3944
+ ],
3945
+ uploadError: {
3946
+ target: "failure",
3947
+ actions: ["assignErrorUploadingData", "handleError"]
3948
+ }
3949
+ },
3950
+ invoke: {
3951
+ src: "uploadData",
3952
+ input: ({ context: e }) => ({ context: e })
3953
+ }
3954
+ },
3955
+ creatingAttestations: {
3956
+ invoke: {
3957
+ src: "createAttestations",
3958
+ input: ({ context: e, event: t }) => ({ context: e, event: t }),
3959
+ onDone: {
3960
+ target: Ze,
3961
+ actions: T({
3962
+ easPayload: ({ event: e }) => e.output?.easPayload
3963
+ })
3964
+ },
3965
+ onError: {
3966
+ target: "attestationFailureRecoverable",
3967
+ actions: ["assignErrorCreatingAttestations", "handleError"]
3968
+ }
3969
+ }
3970
+ },
3971
+ attestationFailureRecoverable: {
3972
+ on: {
3973
+ retry: {
3974
+ target: "creatingAttestations",
3975
+ actions: ["assignAccountFromRetry"]
3976
+ }
3977
+ }
3978
+ },
3979
+ creatingAttestationsDirectToEas: {
3980
+ invoke: {
3981
+ src: "createAttestationsDirectToEas",
3982
+ input: ({ context: e, event: t }) => ({ context: e, event: t }),
3983
+ onDone: {
3984
+ target: Ze,
3985
+ actions: T({
3986
+ easPayload: ({ event: e }) => e.output?.easPayload
3987
+ })
3988
+ },
3989
+ onError: {
3990
+ target: "attestationFailureRecoverableDirectToEas",
3991
+ actions: ["assignErrorCreatingAttestationsDirectToEas", "handleError"]
3992
+ }
3993
+ }
3994
+ },
3995
+ attestationFailureRecoverableDirectToEas: {
3996
+ on: {
3997
+ retry: {
3998
+ target: "creatingAttestationsDirectToEas",
3999
+ actions: ["assignAccountFromRetry"]
4000
+ }
4001
+ }
4002
+ },
4003
+ stopping: {
4004
+ entry: ({ context: e }) => {
4005
+ console.log(`Actor for ${e.item?.seedLocalId} stopped`);
4006
+ },
4007
+ type: "final"
4008
+ },
4009
+ [Ze]: {
4010
+ type: "final"
4011
+ },
4012
+ [Ke]: {
4013
+ type: "final"
4014
+ }
4015
+ }
4016
+ }), Ns = T(({ context: e, event: t }) => {
4017
+ const n = t, a = n.publishProcesses ?? /* @__PURE__ */ new Map(), s = n.subscriptions ?? /* @__PURE__ */ new Map();
4018
+ return {
4019
+ publishProcesses: new Map(a),
4020
+ subscriptions: new Map(
4021
+ s
4022
+ )
4023
+ };
4024
+ });
4025
+ let hn = null;
4026
+ function Fs(e) {
4027
+ hn = e;
4028
+ }
4029
+ function ks() {
4030
+ return hn;
4031
+ }
4032
+ const Lt = K("seedProtocol:services:PublishManager:actors:subscribe");
4033
+ function Mt(e) {
4034
+ const t = e.value;
4035
+ return typeof t == "string" ? t : t && typeof t == "object" ? Object.keys(t)[0] ?? "" : "";
4036
+ }
4037
+ function Qe(e) {
4038
+ return ua.includes(e);
4039
+ }
4040
+ const yn = ye(
4041
+ ({ receive: e, input: { publishProcess: t, seedLocalId: n } }) => {
4042
+ const a = ks();
4043
+ let s = null;
4044
+ const r = () => {
4045
+ s != null && (clearInterval(s), s = null);
4046
+ }, o = (i) => {
4047
+ const l = Mt(i);
4048
+ Qe(l) && s == null && a ? s = setInterval(() => {
4049
+ try {
4050
+ const d = t.getSnapshot();
4051
+ if (d.status === "done") {
4052
+ r();
4053
+ return;
4054
+ }
4055
+ const m = Mt(d);
4056
+ if (!Qe(m)) {
4057
+ r();
4058
+ return;
4059
+ }
4060
+ } catch {
4061
+ return;
4062
+ }
4063
+ a?.savePublish(n, t);
4064
+ }, pa) : Qe(l) || r();
4065
+ }, c = t.subscribe(async (i) => {
4066
+ Lt("Publish state:", i.value), a && (i.status === "done" ? (r(), a.savePublish(n, t, { triggerPublishDone: !0 })) : (a.savePublish(n, t), o(i)));
4067
+ });
4068
+ e(({ type: i }) => {
4069
+ i === "UNSUBSCRIBE" && (Lt("Received UNSUBSCRIBE event"), r(), c.unsubscribe(), a?.removeSubscription(n));
4070
+ });
4071
+ }
4072
+ ), Hs = Le(({ event: e, enqueue: t }) => {
4073
+ const n = e, { item: a, address: s, account: r, options: o } = n;
4074
+ if (!(s != null && typeof s == "string" && s.trim().length > 0)) {
4075
+ console.warn("[createPublish] No valid wallet address; skipping spawn.");
4076
+ return;
4077
+ }
4078
+ t.assign(({ context: i, spawn: l }) => {
4079
+ const { publishProcesses: d } = i;
4080
+ if (d && d.has(a.seedLocalId))
4081
+ return console.warn(`Publish process with seedLocalId "${a.seedLocalId}" already exists.`), i;
4082
+ const m = typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `run_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`, h = [
4083
+ ...x().arweaveUploadTags ?? [],
4084
+ ...o?.arweaveUploadTags ?? []
4085
+ ], u = l(fn, {
4086
+ input: {
4087
+ item: a,
4088
+ address: s,
4089
+ account: r,
4090
+ modelName: a.modelName,
4091
+ schemaId: a.schemaUid,
4092
+ signDataItems: o?.signDataItems,
4093
+ dataItemSigner: o?.dataItemSigner,
4094
+ signArweaveTransactions: o?.signArweaveTransactions,
4095
+ arweaveJwk: o?.arweaveJwk,
4096
+ publishMode: o?.publishMode ?? "patch",
4097
+ publishRunId: m,
4098
+ arweaveUploadTags: h.length ? h : void 0
4099
+ }
4100
+ });
4101
+ return d.set(a.seedLocalId, u), {
4102
+ publishProcesses: new Map(d)
4103
+ };
4104
+ }), t.assign(({ context: i, spawn: l }) => {
4105
+ const { subscriptions: d, publishProcesses: m } = i, p = m.get(a.seedLocalId);
4106
+ if (!p)
4107
+ return console.warn(`Publish process with seedLocalId "${a.seedLocalId}" does not exist.`), i;
4108
+ if (d && d.has(a.seedLocalId))
4109
+ return console.warn(`Subscription with seedLocalId "${a.seedLocalId}" already exists.`), i;
4110
+ const h = l(yn, {
4111
+ input: { publishProcess: p, seedLocalId: a.seedLocalId }
4112
+ });
4113
+ return d.set(a.seedLocalId, h), {
4114
+ subscriptions: new Map(d)
4115
+ };
4116
+ });
4117
+ }), $s = ({
4118
+ context: e,
4119
+ event: t
4120
+ }) => {
4121
+ const n = t, { seedLocalId: a, account: s } = n, r = e.publishProcesses.get(a);
4122
+ if (!r) {
4123
+ console.warn(`Publish process with seedLocalId "${a}" does not exist.`);
4124
+ return;
4125
+ }
4126
+ r.send({ type: "retry", account: s });
4127
+ }, Vs = Le(({ context: e, event: t, enqueue: n }) => {
4128
+ const { publishProcesses: a, subscriptions: s } = e, { seedLocalId: r } = t, o = a.get(r);
4129
+ if (!o) {
4130
+ console.warn(`Publish process with seedLocalId "${r}" does not exist.`);
4131
+ return;
4132
+ }
4133
+ n.stopChild(o);
4134
+ const c = s.get(r);
4135
+ c && n.stopChild(c);
4136
+ const i = new Map(a);
4137
+ i.delete(r);
4138
+ const l = new Map(s);
4139
+ l.delete(r), n.assign({
4140
+ publishProcesses: i,
4141
+ subscriptions: l
4142
+ });
4143
+ }), qs = K("seedProtocol:PublishManager:index"), Ws = Le(({ context: e, enqueue: t }) => {
4144
+ qs("Stopping all actors..."), e.publishProcesses.forEach((n) => {
4145
+ t.stopChild(n);
4146
+ }), e.subscriptions.forEach((n) => {
4147
+ t.stopChild(n);
4148
+ }), t.assign({
4149
+ publishProcesses: /* @__PURE__ */ new Map(),
4150
+ subscriptions: /* @__PURE__ */ new Map()
4151
+ });
4152
+ }), Gs = Le(({ context: e, event: t, enqueue: n }) => {
4153
+ const { seedLocalId: a } = t, s = e.publishProcesses.get(a);
4154
+ if (!s) {
4155
+ console.warn(`Publish process with seedLocalId "${a}" does not exist.`);
4156
+ return;
4157
+ }
4158
+ n.stopChild(s);
4159
+ const r = e.subscriptions.get(a);
4160
+ r && n.stopChild(r);
4161
+ const o = new Map(e.publishProcesses);
4162
+ o.delete(a);
4163
+ const c = new Map(e.subscriptions);
4164
+ c.delete(a), n.assign({
4165
+ publishProcesses: o,
4166
+ subscriptions: c
4167
+ });
4168
+ }), js = T(({ context: e, event: t }) => {
4169
+ const { subscriptions: n } = e, { seedLocalId: a, newSubscription: s } = t;
4170
+ return s && n.set(a, s), {
4171
+ subscriptions: new Map(n)
4172
+ };
4173
+ }), Ue = K("seedProtocol:services:PublishManager:actors:savePublish"), Ot = /* @__PURE__ */ new Map();
4174
+ function Ys(e, t) {
4175
+ const a = (Ot.get(e) ?? Promise.resolve()).then(t);
4176
+ return Ot.set(e, a.catch(() => {
4177
+ })), a;
4178
+ }
4179
+ function Js(e) {
4180
+ return e.status === "done" ? e.value === "success" ? "completed" : e.value === "failure" ? "failed" : "completed" : "in_progress";
4181
+ }
4182
+ const zs = 500, Te = 2e3;
4183
+ function Zs(e) {
4184
+ return JSON.stringify(e, (t, n) => typeof n == "bigint" ? n.toString() : n);
4185
+ }
4186
+ function Bt(e) {
4187
+ if (e == null || typeof e != "object") return;
4188
+ const t = e, n = t.snapshot, s = (t.context ?? n?.context)?.publishRunId;
4189
+ return typeof s == "string" && s.length > 0 ? s : void 0;
4190
+ }
4191
+ function Ks(e, t) {
4192
+ if (!e?.error) return {};
4193
+ if (t !== "failed" && t !== "in_progress") return {};
4194
+ const n = e.error, a = n != null ? (n instanceof Error ? n.message : String(n)).slice(0, zs) : void 0, s = e.errorStep;
4195
+ let r;
4196
+ if (n instanceof Error && n.stack)
4197
+ r = n.stack.slice(0, Te);
4198
+ else if (n != null && typeof n == "object")
4199
+ try {
4200
+ r = JSON.stringify(n).slice(0, Te);
4201
+ } catch {
4202
+ r = String(n).slice(0, Te);
4203
+ }
4204
+ else n != null && (r = String(n).slice(0, Te));
4205
+ return { errorMessage: a ?? void 0, errorStep: s, errorDetails: r };
4206
+ }
4207
+ const Qs = ye(({ sendBack: e, input: { persistedSnapshot: t, seedLocalId: n, triggerPublishDone: a } }) => {
4208
+ Ue("savePublish seedLocalId", n);
4209
+ const s = t;
4210
+ Ys(n, async () => {
4211
+ const o = B.getAppDb();
4212
+ if (!o) {
4213
+ Ue("savePublish: DB not ready, skipping"), e({ type: "SAVE_PUBLISH_DONE", seedLocalId: n, triggerPublishDone: a });
4214
+ return;
4215
+ }
4216
+ const c = await o.select().from(P).where(sa(Z(P.seedLocalId, n), Z(P.status, "in_progress"))).orderBy(fe(P.updatedAt)).limit(1), i = typeof t == "string" ? t : Zs(t), l = Js(s), d = Date.now(), m = Ks(s.context, l);
4217
+ if (c.length > 0) {
4218
+ const p = c[0];
4219
+ await o.update(P).set({
4220
+ persistedSnapshot: i,
4221
+ status: l,
4222
+ updatedAt: d,
4223
+ ...s.status === "done" && l !== "in_progress" ? { completedAt: d } : {},
4224
+ ...m
4225
+ }).where(Z(P.id, p.id));
4226
+ } else {
4227
+ const p = Bt(s);
4228
+ if (p != null && l === "in_progress" && s.status !== "done") {
4229
+ const b = (await o.select().from(P).where(Z(P.seedLocalId, n)).orderBy(fe(P.startedAt)).limit(1))[0];
4230
+ if (b && (b.status === "completed" || b.status === "failed"))
4231
+ try {
4232
+ const g = JSON.parse(b.persistedSnapshot);
4233
+ if (Bt(g) === p) {
4234
+ Ue(
4235
+ "savePublish: skip stale insert — same publishRunId as latest terminal row",
4236
+ n,
4237
+ p
4238
+ );
4239
+ return;
4240
+ }
4241
+ } catch {
4242
+ }
4243
+ }
4244
+ const h = s.context?.item, u = s.context?.modelName ?? h?.modelName ?? "", y = s.context?.schemaId ?? h?.schemaId;
4245
+ await o.insert(P).values({
4246
+ seedLocalId: n,
4247
+ modelName: u,
4248
+ schemaId: y ?? null,
4249
+ status: l,
4250
+ startedAt: d,
4251
+ persistedSnapshot: i,
4252
+ createdAt: d,
4253
+ updatedAt: d,
4254
+ ...m
4255
+ });
4256
+ }
4257
+ }).then(() => {
4258
+ e({ type: "SAVE_PUBLISH_DONE", seedLocalId: n, triggerPublishDone: a });
4259
+ }).catch((o) => {
4260
+ Ue("savePublish error", o), e({ type: "SAVE_PUBLISH_DONE", seedLocalId: n, triggerPublishDone: a });
4261
+ });
4262
+ });
4263
+ function Xs(e) {
4264
+ try {
4265
+ return e.getPersistedSnapshot?.() ?? e.getSnapshot();
4266
+ } catch {
4267
+ const t = e.getSnapshot(), n = t.context;
4268
+ if (!n?.item) return t;
4269
+ const a = n.item;
4270
+ return {
4271
+ ...t,
4272
+ context: {
4273
+ ...n,
4274
+ item: {
4275
+ seedLocalId: a.seedLocalId,
4276
+ modelName: a.modelName,
4277
+ schemaId: a.schemaId
4278
+ }
4279
+ }
4280
+ };
4281
+ }
4282
+ }
4283
+ const er = T(({ context: e, event: t, spawn: n }) => {
4284
+ const { publishProcesses: a } = e, { seedLocalId: s, publishProcess: r, triggerPublishDone: o } = t;
4285
+ if (!r)
4286
+ return e;
4287
+ const c = new Map(a);
4288
+ c.set(s, r);
4289
+ const i = Xs(r);
4290
+ return n(Qs, {
4291
+ id: `savePublish_${s}_${Date.now()}`,
4292
+ input: { persistedSnapshot: i, seedLocalId: s, triggerPublishDone: o }
4293
+ }), { publishProcesses: c };
4294
+ }), tr = T(({ context: e, event: t }) => {
4295
+ const { publishProcesses: n, subscriptions: a } = e, s = t.seedLocalId, r = a.get(s);
4296
+ r && r.send({ type: "UNSUBSCRIBE" });
4297
+ const o = new Map(n);
4298
+ o.delete(s);
4299
+ const c = new Map(a);
4300
+ return c.delete(s), {
4301
+ publishProcesses: o,
4302
+ subscriptions: c
4303
+ };
4304
+ }), nr = T(({ context: e, event: t }) => {
4305
+ const { subscriptions: n } = e, a = t.seedLocalId, s = new Map(n);
4306
+ return s.delete(a), {
4307
+ subscriptions: s
4308
+ };
4309
+ }), ar = 6e4, sr = 2e3;
4310
+ async function rr(e) {
4311
+ const t = Date.now() + e;
4312
+ for (; Date.now() < t; ) {
4313
+ if (B.PlatformClass && B.getAppDb()) return !0;
4314
+ await new Promise((n) => setTimeout(n, sr));
4315
+ }
4316
+ return !1;
4317
+ }
4318
+ function or(e) {
4319
+ const t = e.value;
4320
+ return typeof t == "string" ? t : t && typeof t == "object" ? Object.keys(t)[0] ?? "" : "";
4321
+ }
4322
+ function ir(e) {
4323
+ const t = or(e);
4324
+ if (t === "pollingForConfirmation" && (!e.context?.reimbursementTransactionId || !e.context?.requestResponse))
4325
+ return !1;
4326
+ if (t === "uploadingData") {
4327
+ const n = e.context?.arweaveTransactions, a = e.context?.publishUploads;
4328
+ if (!Array.isArray(n) || n.length === 0 || !Array.isArray(a)) return !1;
4329
+ }
4330
+ return !0;
4331
+ }
4332
+ const cr = ye(
4333
+ ({ sendBack: e, input: { context: t } }) => {
4334
+ (async () => {
4335
+ const a = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
4336
+ if (!await rr(ar))
4337
+ return e({ type: "RESTORE_FROM_DB_DONE", publishProcesses: a, subscriptions: s }), { newPublishProcesses: a, newSubscriptions: s };
4338
+ const o = B.getAppDb();
4339
+ if (!o)
4340
+ return e({ type: "RESTORE_FROM_DB_DONE", publishProcesses: a, subscriptions: s }), { newPublishProcesses: a, newSubscriptions: s };
4341
+ const c = await o.select().from(P).where(Z(P.status, "in_progress")), i = /* @__PURE__ */ new Map(), l = [...c].sort(
4342
+ (m, p) => (p.updatedAt ?? p.createdAt ?? 0) - (m.updatedAt ?? m.createdAt ?? 0)
4343
+ );
4344
+ for (const m of l)
4345
+ i.has(m.seedLocalId) || i.set(m.seedLocalId, m);
4346
+ const d = Array.from(i.values());
4347
+ for (const m of d) {
4348
+ let p;
4349
+ try {
4350
+ p = JSON.parse(m.persistedSnapshot);
4351
+ } catch {
4352
+ continue;
4353
+ }
4354
+ if (p.status === "done") continue;
4355
+ const h = p.context?.item?.seedLocalId ?? m.seedLocalId;
4356
+ if (!h || !ir(p)) continue;
4357
+ p.context = p.context ?? {}, p.context.item = {
4358
+ ...p.context.item,
4359
+ seedLocalId: h,
4360
+ modelName: p.context.item?.modelName ?? p.context.modelName ?? m.modelName ?? "",
4361
+ schemaId: p.context.item?.schemaId ?? p.context.schemaId ?? m.schemaId ?? void 0
4362
+ };
4363
+ const u = et(fn, {
4364
+ snapshot: p,
4365
+ input: void 0
4366
+ }), y = et(yn, {
4367
+ input: {
4368
+ publishProcess: u,
4369
+ seedLocalId: h
4370
+ }
4371
+ });
4372
+ a.set(h, u), s.set(h, y), u.start(), y.start();
4373
+ }
4374
+ return { newPublishProcesses: a, newSubscriptions: s };
4375
+ })().then((a) => {
4376
+ if (!a) return;
4377
+ const { newPublishProcesses: s, newSubscriptions: r } = a;
4378
+ e({
4379
+ type: "RESTORE_FROM_DB_DONE",
4380
+ publishProcesses: s,
4381
+ subscriptions: r
4382
+ });
4383
+ });
4384
+ }
4385
+ ), gn = K("seedProtocol:PublishManager:index"), dr = qt({
4386
+ types: {
4387
+ context: {},
4388
+ input: {},
4389
+ events: {}
4390
+ },
4391
+ actors: {
4392
+ restoreFromDb: cr
4393
+ },
4394
+ actions: {
4395
+ assignRestoreFromDb: Ns,
4396
+ createPublish: Hs,
4397
+ addSubscription: js,
4398
+ requestSavePublish: er,
4399
+ publishDone: tr,
4400
+ removeSubscription: nr,
4401
+ retryAttestations: $s,
4402
+ stopPublish: Vs,
4403
+ stopAll: Ws,
4404
+ query: Gs
4405
+ }
4406
+ }).createMachine({
4407
+ id: "publishManager",
4408
+ initial: "restoreFromDb",
4409
+ context: {
4410
+ publishProcesses: /* @__PURE__ */ new Map(),
4411
+ subscriptions: /* @__PURE__ */ new Map()
4412
+ },
4413
+ states: {
4414
+ restoreFromDb: {
4415
+ on: {
4416
+ RESTORE_FROM_DB_DONE: {
4417
+ target: "active",
4418
+ actions: ["assignRestoreFromDb"]
4419
+ }
4420
+ },
4421
+ invoke: {
4422
+ src: "restoreFromDb",
4423
+ input: ({ context: e }) => ({ context: e })
4424
+ }
4425
+ },
4426
+ active: {
4427
+ on: {
4428
+ CREATE_PUBLISH: {
4429
+ actions: ["createPublish"]
4430
+ },
4431
+ ADD_SUBSCRIPTION: {
4432
+ actions: ["addSubscription"]
4433
+ },
4434
+ REQUEST_SAVE_PUBLISH: {
4435
+ actions: ["requestSavePublish"]
4436
+ },
4437
+ SAVE_PUBLISH_DONE: [
4438
+ {
4439
+ guard: ({ event: e }) => e.triggerPublishDone === !0,
4440
+ actions: ["publishDone"]
4441
+ }
4442
+ ],
4443
+ PUBLISH_DONE: {
4444
+ actions: ["publishDone"]
4445
+ },
4446
+ REMOVE_SUBSCRIPTION: {
4447
+ actions: ["removeSubscription"]
4448
+ },
4449
+ RETRY_ATTESTATIONS: {
4450
+ actions: ["retryAttestations"]
4451
+ },
4452
+ STOP_PUBLISH: {
4453
+ actions: ["stopPublish"]
4454
+ },
4455
+ QUERY: {
4456
+ actions: ["query"]
4457
+ },
4458
+ STOP_ALL: {
4459
+ actions: ["stopAll"]
4460
+ }
4461
+ }
4462
+ }
4463
+ }
4464
+ }), O = et(dr, {
4465
+ input: {
4466
+ publishProcesses: /* @__PURE__ */ new Map(),
4467
+ subscriptions: /* @__PURE__ */ new Map()
4468
+ }
4469
+ });
4470
+ Fs({
4471
+ savePublish: (e, t, n) => {
4472
+ O.send({
4473
+ type: "REQUEST_SAVE_PUBLISH",
4474
+ seedLocalId: e,
4475
+ publishProcess: t,
4476
+ triggerPublishDone: n?.triggerPublishDone
4477
+ });
4478
+ },
4479
+ onPublishDone: (e) => {
4480
+ O.send({ type: "PUBLISH_DONE", seedLocalId: e });
4481
+ },
4482
+ removeSubscription: (e) => {
4483
+ O.send({ type: "REMOVE_SUBSCRIPTION", seedLocalId: e });
4484
+ }
4485
+ });
4486
+ const lr = O.subscribe((e) => {
4487
+ gn("PublishManager snapshot:", e);
4488
+ });
4489
+ typeof document < "u" && (O.start(), window.addEventListener("load", () => {
4490
+ gn("PublishManager started");
4491
+ }), window.addEventListener("beforeunload", () => {
4492
+ lr.unsubscribe(), O.stop();
4493
+ }));
4494
+ const at = {
4495
+ getService: () => O,
4496
+ createPublish: (e, t, n, a) => O.send({ type: "CREATE_PUBLISH", item: e, address: t, account: n, options: a }),
4497
+ retryAttestations: (e, t) => O.send({ type: "RETRY_ATTESTATIONS", seedLocalId: e, account: t }),
4498
+ stopPublish: (e) => O.send({ type: "STOP_PUBLISH", seedLocalId: e }),
4499
+ query: (e) => O.send({ type: "QUERY", seedLocalId: e }),
4500
+ stopAll: () => O.send({ type: "STOP_ALL" }),
4501
+ getPublish: (e) => O.getSnapshot().context.publishProcesses.get(e),
4502
+ savePublish: (e, t) => O.send({ type: "REQUEST_SAVE_PUBLISH", seedLocalId: e, publishProcess: t }),
4503
+ addSubscription: (e, t) => O.send({ type: "ADD_SUBSCRIPTION", seedLocalId: e, newSubscription: t }),
4504
+ removeSubscription: (e) => O.send({ type: "REMOVE_SUBSCRIPTION", seedLocalId: e })
4505
+ };
4506
+ function Ho(e) {
4507
+ return e === "creatingAttestationsDirectToEas" ? "creatingAttestations" : e;
4508
+ }
4509
+ function ur(e, t, n) {
4510
+ return e != null ? n : t?.status === "completed" ? L.SUCCESS : t?.status === "failed" ? L.FAILURE : n;
4511
+ }
4512
+ function pr(e) {
4513
+ if (e) {
4514
+ if (e.status === "failed") return L.FAILURE;
4515
+ if (e.status === "completed") return L.SUCCESS;
4516
+ if (e.completedAt != null) {
4517
+ try {
4518
+ const t = JSON.parse(e.persistedSnapshot);
4519
+ if (t.status === "done" && t.value === L.FAILURE)
4520
+ return L.FAILURE;
4521
+ } catch {
4522
+ }
4523
+ return L.SUCCESS;
4524
+ }
4525
+ try {
4526
+ const t = JSON.parse(e.persistedSnapshot);
4527
+ if (t.status === "done") {
4528
+ if (t.value === L.SUCCESS) return L.SUCCESS;
4529
+ if (t.value === L.FAILURE) return L.FAILURE;
4530
+ }
4531
+ if (typeof t.value == "string") return t.value;
4532
+ } catch {
4533
+ return;
4534
+ }
4535
+ }
4536
+ }
4537
+ function mr(e) {
4538
+ return !e || e.status !== "done" ? !1 : e.value === L.SUCCESS || e.value === L.FAILURE;
4539
+ }
4540
+ function fr(e) {
4541
+ const t = at.getService(), n = ia(t, (h) => h?.context?.publishProcesses?.get(e) ?? null), a = Ht(null);
4542
+ te(() => {
4543
+ a.current = null;
4544
+ }, [e]);
4545
+ const [s, r] = Ae(void 0), [o, c] = Ae(null), i = B.getAppDb(), d = ve(
4546
+ e && i ? i.select().from(P).where(Z(P.seedLocalId, e)).orderBy(fe(P.startedAt)).limit(1) : null
4547
+ )?.[0], m = d?.status, p = $t(() => {
4548
+ if (n != null)
4549
+ return s;
4550
+ if (o === "success" || o === "failure")
4551
+ return o;
4552
+ const h = pr(d);
4553
+ return h === L.SUCCESS || h === L.FAILURE ? h : ur(
4554
+ n,
4555
+ m != null ? { status: m } : void 0,
4556
+ s
4557
+ );
4558
+ }, [n, m, s, o, d]);
4559
+ return te(() => {
4560
+ c(null);
4561
+ }, [e]), te(() => {
4562
+ n == null && (m === "completed" ? c("success") : m === "failed" && c("failure"));
4563
+ }, [m, n]), te(() => {
4564
+ n != null && c(null);
4565
+ }, [n]), te(() => {
4566
+ if (!n) {
4567
+ const y = a.current;
4568
+ mr(y) ? (r(y.value), y.value === L.SUCCESS ? c("success") : y.value === L.FAILURE && c("failure")) : r(void 0);
4569
+ return;
4570
+ }
4571
+ const h = n.getSnapshot();
4572
+ a.current = { value: h?.value, status: h.status }, r(h?.value);
4573
+ const u = n.subscribe((y) => {
4574
+ a.current = { value: y?.value, status: y?.status }, r(y?.value);
4575
+ });
4576
+ return () => {
4577
+ u.unsubscribe();
4578
+ };
4579
+ }, [n, e]), {
4580
+ publishProcess: n ?? null,
4581
+ value: p
4582
+ };
4583
+ }
4584
+ function $o(e) {
4585
+ const [t, n] = Ae(!0);
4586
+ return te(() => {
4587
+ if (!e) {
4588
+ n(!1);
4589
+ return;
4590
+ }
4591
+ Ft(e).then(n).catch(() => n(!1));
4592
+ }, [e?.seedLocalId]), t;
4593
+ }
4594
+ function hr(e) {
4595
+ const t = B.getAppDb(), a = ve(
4596
+ e && t ? t.select().from(De).where(Z(De.seedLocalId, e)).orderBy(fe(De.updatedAt)) : null
4597
+ ) ?? [];
4598
+ return $t(() => {
4599
+ const r = a.filter((c) => c.phase === "pending_l1").length, o = a.filter((c) => c.phase === "confirmed").length;
4600
+ return {
4601
+ hasPendingL1: r > 0,
4602
+ pendingCount: r,
4603
+ confirmedCount: o,
4604
+ jobs: a
4605
+ };
4606
+ }, [a]);
4607
+ }
4608
+ function Vo(e) {
4609
+ const { publishProcess: t, value: n } = fr(e ?? ""), a = hr(e), s = B.getAppDb(), o = ve(
4610
+ e && s ? s.select().from(P).where(Z(P.seedLocalId, e)).orderBy(fe(P.startedAt)).limit(1) : null
4611
+ )?.[0], c = !!t || o?.status === "in_progress";
4612
+ return {
4613
+ latestRecord: o,
4614
+ publishProcess: t,
4615
+ isActive: c,
4616
+ publishValue: n,
4617
+ arweaveL1Pending: a.hasPendingL1,
4618
+ arweaveL1Jobs: a.jobs,
4619
+ arweaveL1Summary: a
4620
+ };
4621
+ }
4622
+ function yr() {
4623
+ const e = B.getAppDb();
4624
+ return ve(
4625
+ e ? e.select().from(P).orderBy(fe(P.startedAt)) : null
4626
+ );
4627
+ }
4628
+ function qo() {
4629
+ const e = yr();
4630
+ if (e !== void 0)
4631
+ return e.filter((t) => t.status !== "in_progress").length;
4632
+ }
4633
+ function Wo(e) {
4634
+ const t = B.getAppDb(), n = ve(
4635
+ e != null && t ? t.select().from(P).where(Z(P.id, e)).limit(1) : null
4636
+ ), a = n === void 0;
4637
+ return { record: n && n.length > 0 ? n[0] : null, isLoading: a };
4638
+ }
4639
+ async function Go() {
4640
+ const e = B.getAppDb();
4641
+ e && await e.delete(P).where(ra(P.status, ["in_progress"]));
4642
+ }
4643
+ async function jo() {
4644
+ const e = B.getAppDb();
4645
+ e && await e.delete(P);
4646
+ }
4647
+ async function Yo() {
4648
+ const e = B.getAppDb();
4649
+ e && await e.delete(kn);
4650
+ }
4651
+ async function Jo(e) {
4652
+ const t = B.getAppDb();
4653
+ t && await t.delete(P).where(Z(P.seedLocalId, e));
4654
+ }
4655
+ async function zo(e) {
4656
+ const t = B.getAppDb();
4657
+ t && await t.delete(P).where(Z(P.id, e));
4658
+ }
4659
+ async function Zo(e) {
4660
+ if (e.length === 0) return;
4661
+ const t = B.getAppDb();
4662
+ t && await t.delete(P).where(oa(P.id, e));
4663
+ }
4664
+ function Ko(e) {
4665
+ try {
4666
+ return (JSON.parse(e.persistedSnapshot).context?.arweaveTransactions ?? []).map((a) => a.transaction?.id).filter((a) => typeof a == "string");
4667
+ } catch {
4668
+ return [];
4669
+ }
4670
+ }
4671
+ function Qo(e) {
4672
+ try {
4673
+ return JSON.parse(e.persistedSnapshot).context?.easPayload ?? void 0;
4674
+ } catch {
4675
+ return;
4676
+ }
4677
+ }
4678
+ function Xo(e) {
4679
+ const t = /* @__PURE__ */ new Map();
4680
+ for (let n = 0; n < e.length; n++) {
4681
+ const a = e[n]?.localId;
4682
+ a != null && t.set(a, BigInt(n));
4683
+ }
4684
+ return e.map((n, a) => {
4685
+ const s = (n.propertiesToUpdate ?? []).map((c) => {
4686
+ const i = c.publishLocalId, l = i != null ? t.get(i) : void 0;
4687
+ if (i != null && i !== "" && l === void 0)
4688
+ throw new Error(
4689
+ `publishLocalId "${i}" not found in payload (valid localIds: ${Array.from(t.keys()).join(", ")})`
4690
+ );
4691
+ const { publishLocalId: d, ...m } = c;
4692
+ return {
4693
+ ...m,
4694
+ publishLocalIdIndex: l ?? BigInt(0)
4695
+ };
4696
+ }), { localId: r, ...o } = n;
4697
+ return {
4698
+ ...o,
4699
+ localIdIndex: BigInt(a),
4700
+ propertiesToUpdate: s
4701
+ };
4702
+ });
4703
+ }
4704
+ const gr = "A connected wallet is required for publishing with the modular executor. Connect your wallet and try again.";
4705
+ async function ei(e, t, n, a) {
4706
+ const s = x(), r = await n();
4707
+ if (!r || !r.trim())
4708
+ return { outcome: "no_address" };
4709
+ if (s.useModularExecutor) {
4710
+ if (!t)
4711
+ return {
4712
+ outcome: "managed_not_ready",
4713
+ error: new Q(gr, "MANAGED_ACCOUNT_UNAVAILABLE")
4714
+ };
4715
+ const c = await dn();
4716
+ if (!c.ok)
4717
+ return { outcome: "managed_not_ready", error: c.error };
4718
+ const i = c.managedAddress, l = await gt(t ?? null);
4719
+ return "needsDeploy" in l ? { outcome: "needs_deploy" } : (at.createPublish(e, i, l.account, {
4720
+ dataItemSigner: l.account,
4721
+ ...a
4722
+ }), { outcome: "started" });
4723
+ }
4724
+ const o = await gt(t ?? null);
4725
+ return "address" in o ? (at.createPublish(e, o.address, o.account, {
4726
+ dataItemSigner: o.account,
4727
+ ...a
4728
+ }), { outcome: "started" }) : { outcome: "needs_deploy" };
4729
+ }
4730
+ export {
4731
+ ot as $,
4732
+ Zt as A,
4733
+ _e as B,
4734
+ Wr as C,
4735
+ Ya as D,
4736
+ es as E,
4737
+ Ho as F,
4738
+ pr as G,
4739
+ ur as H,
4740
+ Xo as I,
4741
+ ei as J,
4742
+ tt as K,
4743
+ Ut as L,
4744
+ Q as M,
4745
+ ys as N,
4746
+ dn as O,
4747
+ Gr as P,
4748
+ R as Q,
4749
+ Nr as R,
4750
+ Fr as S,
4751
+ kr as T,
4752
+ Yt as U,
4753
+ Jt as V,
4754
+ Re as W,
4755
+ gt as X,
4756
+ Hr as Y,
4757
+ fa as Z,
4758
+ $r as _,
4759
+ At as a,
4760
+ ha as a0,
4761
+ Me as a1,
4762
+ it as a2,
4763
+ ya as a3,
4764
+ jr as a4,
4765
+ Yr as a5,
4766
+ Jr as a6,
4767
+ zr as a7,
4768
+ Na as a8,
4769
+ Zr as a9,
4770
+ Eo as aA,
4771
+ Io as aB,
4772
+ Po as aC,
4773
+ Uo as aD,
4774
+ To as aE,
4775
+ Do as aF,
4776
+ xo as aG,
4777
+ Co as aH,
4778
+ Ro as aI,
4779
+ _o as aJ,
4780
+ Lo as aK,
4781
+ Mo as aL,
4782
+ vt as aM,
4783
+ Oo as aN,
4784
+ Bo as aO,
4785
+ No as aP,
4786
+ Fo as aQ,
4787
+ ko as aR,
4788
+ Kr as aa,
4789
+ Qr as ab,
4790
+ Fa as ac,
4791
+ Xr as ad,
4792
+ eo as ae,
4793
+ to as af,
4794
+ no as ag,
4795
+ ao as ah,
4796
+ so as ai,
4797
+ ro as aj,
4798
+ oo as ak,
4799
+ io as al,
4800
+ co as am,
4801
+ lo as an,
4802
+ uo as ao,
4803
+ po as ap,
4804
+ mo as aq,
4805
+ fo as ar,
4806
+ ho as as,
4807
+ yo as at,
4808
+ go as au,
4809
+ wo as av,
4810
+ bo as aw,
4811
+ Ao as ax,
4812
+ vo as ay,
4813
+ So as az,
4814
+ Ta as b,
4815
+ Vr as c,
4816
+ qr as d,
4817
+ Oe as e,
4818
+ at as f,
4819
+ x as g,
4820
+ fr as h,
4821
+ zt as i,
4822
+ $o as j,
4823
+ Vo as k,
4824
+ yr as l,
4825
+ qo as m,
4826
+ Wo as n,
4827
+ Go as o,
4828
+ fn as p,
4829
+ jo as q,
4830
+ Yo as r,
4831
+ Ua as s,
4832
+ Jo as t,
4833
+ Da as u,
4834
+ zo as v,
4835
+ Zo as w,
4836
+ Ko as x,
4837
+ Qo as y,
4838
+ hr as z
4839
+ };
4840
+ //# sourceMappingURL=index-BfABV7U1.js.map