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