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