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