@the_library/public 1.0.0
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 +2298 -0
- package/assets/branding/data-pond.png +0 -0
- package/assets/branding/dsafe-logo.png +0 -0
- package/assets/branding/founder-photo.jpg +0 -0
- package/assets/branding/icon_transparent.png +0 -0
- package/assets/branding/library-favicon.png +0 -0
- package/assets/branding/pond-enterprise-logo.jpg +0 -0
- package/assets/branding/pond-enterprise-logo.svg +27 -0
- package/dist/branding/index.d.ts +48 -0
- package/dist/branding/index.js +67 -0
- package/dist/branding/index.js.map +1 -0
- package/dist/chunk-2HFOWE5R.js +296 -0
- package/dist/chunk-2HFOWE5R.js.map +1 -0
- package/dist/chunk-3L6LH2XK.js +465 -0
- package/dist/chunk-3L6LH2XK.js.map +1 -0
- package/dist/chunk-4CWVFPBN.js +28 -0
- package/dist/chunk-4CWVFPBN.js.map +1 -0
- package/dist/chunk-AGHPATVL.js +65 -0
- package/dist/chunk-AGHPATVL.js.map +1 -0
- package/dist/chunk-JDUYLUDJ.js +4835 -0
- package/dist/chunk-JDUYLUDJ.js.map +1 -0
- package/dist/chunk-OEZK7IX7.js +77 -0
- package/dist/chunk-OEZK7IX7.js.map +1 -0
- package/dist/chunk-PUYDAUCI.js +2873 -0
- package/dist/chunk-PUYDAUCI.js.map +1 -0
- package/dist/chunk-WHWMTS7D.js +99 -0
- package/dist/chunk-WHWMTS7D.js.map +1 -0
- package/dist/chunk-Y7RS6RTM.js +342 -0
- package/dist/chunk-Y7RS6RTM.js.map +1 -0
- package/dist/chunk-ZEZGI2TP.js +197 -0
- package/dist/chunk-ZEZGI2TP.js.map +1 -0
- package/dist/core-dao-core-logo-VDT2I5IW.svg +33 -0
- package/dist/downloader/dl2-sw.js +199 -0
- package/dist/downloader/dl2-sw.js.map +1 -0
- package/dist/downloader/file-worker-v2.js +258 -0
- package/dist/downloader/file-worker-v2.js.map +1 -0
- package/dist/downloader/index.d.ts +45 -0
- package/dist/downloader/index.js +538 -0
- package/dist/downloader/index.js.map +1 -0
- package/dist/downloader/mu-worker-v2.js +197 -0
- package/dist/downloader/mu-worker-v2.js.map +1 -0
- package/dist/downloader/react.d.ts +19 -0
- package/dist/downloader/react.js +32 -0
- package/dist/downloader/react.js.map +1 -0
- package/dist/downloader/solid.d.ts +21 -0
- package/dist/downloader/solid.js +19 -0
- package/dist/downloader/solid.js.map +1 -0
- package/dist/downloader/sw.d.ts +22 -0
- package/dist/downloader/sw.js +119 -0
- package/dist/downloader/sw.js.map +1 -0
- package/dist/downloader/vue.d.ts +23 -0
- package/dist/downloader/vue.js +19 -0
- package/dist/downloader/vue.js.map +1 -0
- package/dist/level-state-J3pj64Tr.d.ts +15 -0
- package/dist/models/astro.d.ts +47 -0
- package/dist/models/astro.js +44 -0
- package/dist/models/astro.js.map +1 -0
- package/dist/models/index.d.ts +244 -0
- package/dist/models/index.js +340 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/models.d.ts +524 -0
- package/dist/models/models.js +46 -0
- package/dist/models/models.js.map +1 -0
- package/dist/models/models_v2.global.js +1 -0
- package/dist/models/patch-worker.js +543 -0
- package/dist/models/patch-worker.js.map +1 -0
- package/dist/models/react.d.ts +43 -0
- package/dist/models/react.js +73 -0
- package/dist/models/react.js.map +1 -0
- package/dist/models/solid.d.ts +73 -0
- package/dist/models/solid.js +95 -0
- package/dist/models/solid.js.map +1 -0
- package/dist/models/vue.d.ts +51 -0
- package/dist/models/vue.js +98 -0
- package/dist/models/vue.js.map +1 -0
- package/dist/orm-BvkX0aBT.d.ts +507 -0
- package/dist/session-vqOnyxga.d.ts +184 -0
- package/dist/state-BTsp-E4v.d.ts +111 -0
- package/dist/types-Dn0EFMO_.d.ts +293 -0
- package/dist/types-Xb8Ta9tZ.d.ts +155 -0
- package/dist/web3/index.d.ts +820 -0
- package/dist/web3/index.js +1020 -0
- package/dist/web3/index.js.map +1 -0
- package/dist/web3/registry.d.ts +145 -0
- package/dist/web3/registry.js +23 -0
- package/dist/web3/registry.js.map +1 -0
- package/dist/web3/vue.d.ts +174 -0
- package/dist/web3/vue.js +391 -0
- package/dist/web3/vue.js.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,1020 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_CHAIN_ID,
|
|
3
|
+
EVM_CHAINS,
|
|
4
|
+
EventBus,
|
|
5
|
+
EventName,
|
|
6
|
+
EvmClient,
|
|
7
|
+
MetaMaskConnector,
|
|
8
|
+
PrivateKeyConnector,
|
|
9
|
+
SubscriptionClient,
|
|
10
|
+
WalletError,
|
|
11
|
+
WalletEvents,
|
|
12
|
+
WalletState,
|
|
13
|
+
WalletUxError,
|
|
14
|
+
addressFromPrivateKey,
|
|
15
|
+
addressRegistryAbi,
|
|
16
|
+
allRegisteredAccounts,
|
|
17
|
+
createEvmClient,
|
|
18
|
+
createMetaMaskConnector,
|
|
19
|
+
createPrivateKeyConnector,
|
|
20
|
+
createPrivateKeyWalletClient,
|
|
21
|
+
createSessionStore,
|
|
22
|
+
cursorStore,
|
|
23
|
+
deserializeCursor,
|
|
24
|
+
emptyCursor,
|
|
25
|
+
getCachedEmail,
|
|
26
|
+
getChain,
|
|
27
|
+
getConnector,
|
|
28
|
+
getDecryptedPrivateKey,
|
|
29
|
+
getEventBus,
|
|
30
|
+
getEvmClient,
|
|
31
|
+
getPrivateKey,
|
|
32
|
+
getReadClient,
|
|
33
|
+
getReadyEvmClient,
|
|
34
|
+
getRegisteredConnectors,
|
|
35
|
+
getSubscriptionClient,
|
|
36
|
+
hasAnyPrivateKey,
|
|
37
|
+
hasEncryptedPrivateKey,
|
|
38
|
+
hasPrivateKey,
|
|
39
|
+
hasUnsavedPatches,
|
|
40
|
+
loadNetworkInfos,
|
|
41
|
+
loadProject,
|
|
42
|
+
loadProjects,
|
|
43
|
+
normalizeError,
|
|
44
|
+
projectLocale,
|
|
45
|
+
pythAbi,
|
|
46
|
+
readOnlyClients,
|
|
47
|
+
readOnlyStagingClients,
|
|
48
|
+
registerConnector,
|
|
49
|
+
restoreAccountSave,
|
|
50
|
+
serializeCursor,
|
|
51
|
+
sessionStore,
|
|
52
|
+
setCachedEmail,
|
|
53
|
+
storeEncryptedPrivateKey,
|
|
54
|
+
storePrivateKey,
|
|
55
|
+
stringToBytes4,
|
|
56
|
+
syncAccount,
|
|
57
|
+
toViemChain
|
|
58
|
+
} from "../chunk-PUYDAUCI.js";
|
|
59
|
+
import {
|
|
60
|
+
CACHE_DURATION_MS,
|
|
61
|
+
NodeFileCacheStorage,
|
|
62
|
+
RegistryAddressLoader,
|
|
63
|
+
addressLoader,
|
|
64
|
+
createNodeFileCacheStorage,
|
|
65
|
+
getContractAbi,
|
|
66
|
+
getRegistryBaseUrl,
|
|
67
|
+
setRegistryBaseUrl,
|
|
68
|
+
sidecarUrlsFromManifest
|
|
69
|
+
} from "../chunk-3L6LH2XK.js";
|
|
70
|
+
import {
|
|
71
|
+
getNbPatches
|
|
72
|
+
} from "../chunk-ZEZGI2TP.js";
|
|
73
|
+
|
|
74
|
+
// src/web3/client/types.ts
|
|
75
|
+
var LibraryOwnership = /* @__PURE__ */ ((LibraryOwnership2) => {
|
|
76
|
+
LibraryOwnership2[LibraryOwnership2["Public"] = 0] = "Public";
|
|
77
|
+
LibraryOwnership2[LibraryOwnership2["Private"] = 1] = "Private";
|
|
78
|
+
return LibraryOwnership2;
|
|
79
|
+
})(LibraryOwnership || {});
|
|
80
|
+
var PreferredFormat = /* @__PURE__ */ ((PreferredFormat2) => {
|
|
81
|
+
PreferredFormat2[PreferredFormat2["MARC21"] = 0] = "MARC21";
|
|
82
|
+
PreferredFormat2[PreferredFormat2["UNIMARC"] = 1] = "UNIMARC";
|
|
83
|
+
PreferredFormat2[PreferredFormat2["MARCXML"] = 2] = "MARCXML";
|
|
84
|
+
PreferredFormat2[PreferredFormat2["DublinCore"] = 3] = "DublinCore";
|
|
85
|
+
PreferredFormat2[PreferredFormat2["MODS"] = 4] = "MODS";
|
|
86
|
+
PreferredFormat2[PreferredFormat2["BIBFRAME"] = 5] = "BIBFRAME";
|
|
87
|
+
PreferredFormat2[PreferredFormat2["ONIX"] = 6] = "ONIX";
|
|
88
|
+
PreferredFormat2[PreferredFormat2["OPDS"] = 7] = "OPDS";
|
|
89
|
+
PreferredFormat2[PreferredFormat2["InternetArchive"] = 8] = "InternetArchive";
|
|
90
|
+
PreferredFormat2[PreferredFormat2["HathiTrust"] = 9] = "HathiTrust";
|
|
91
|
+
PreferredFormat2[PreferredFormat2["EAD"] = 10] = "EAD";
|
|
92
|
+
PreferredFormat2[PreferredFormat2["Other"] = 11] = "Other";
|
|
93
|
+
return PreferredFormat2;
|
|
94
|
+
})(PreferredFormat || {});
|
|
95
|
+
|
|
96
|
+
// src/web3/client/EvmWriteClient.ts
|
|
97
|
+
import {
|
|
98
|
+
parseEther
|
|
99
|
+
} from "viem";
|
|
100
|
+
var EvmWriteClient = class {
|
|
101
|
+
constructor(wallet, readonlyApi, walletClient, account) {
|
|
102
|
+
this.wallet = wallet;
|
|
103
|
+
this.readonly = readonlyApi;
|
|
104
|
+
this.config = readonlyApi.config;
|
|
105
|
+
this.environment = readonlyApi.environment;
|
|
106
|
+
this.chain = readonlyApi.chain;
|
|
107
|
+
this.publicClient = readonlyApi.publicClient;
|
|
108
|
+
this._account = account;
|
|
109
|
+
this.writeOnly = {
|
|
110
|
+
factory: this.createFactoryWriteAPI(walletClient),
|
|
111
|
+
subscriptionManager: this.createSubscriptionManagerWriteAPI(walletClient),
|
|
112
|
+
addressRegistry: this.createAddressRegistryWriteAPI(walletClient),
|
|
113
|
+
libraryRegistryStorage: this.createLibraryRegistryStorageWriteAPI(walletClient),
|
|
114
|
+
publicLibraryStorage: this.createPublicLibraryStorageWriteAPI(walletClient)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
get factory() {
|
|
118
|
+
return this.writeOnly.factory;
|
|
119
|
+
}
|
|
120
|
+
get subscriptionManager() {
|
|
121
|
+
return this.writeOnly.subscriptionManager;
|
|
122
|
+
}
|
|
123
|
+
get addressRegistry() {
|
|
124
|
+
return this.writeOnly.addressRegistry;
|
|
125
|
+
}
|
|
126
|
+
get libraryRegistryStorage() {
|
|
127
|
+
return this.writeOnly.libraryRegistryStorage;
|
|
128
|
+
}
|
|
129
|
+
get publicLibraryStorage() {
|
|
130
|
+
return this.writeOnly.publicLibraryStorage;
|
|
131
|
+
}
|
|
132
|
+
getChainId() {
|
|
133
|
+
return this.readonly.chainId;
|
|
134
|
+
}
|
|
135
|
+
account() {
|
|
136
|
+
return this._account;
|
|
137
|
+
}
|
|
138
|
+
getNormalizedAddress(address) {
|
|
139
|
+
return address.toLowerCase();
|
|
140
|
+
}
|
|
141
|
+
requireAbi(contractName) {
|
|
142
|
+
const abi = addressLoader.getAbi(this.readonly.chainId, contractName, this.environment);
|
|
143
|
+
if (!abi) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`[EvmWriteClient] Registry ABI for '${contractName}' on chain ${this.readonly.chainId} is not loaded. The AddressRegistry may be offline, incomplete, or the chain has not finished syncing. Write operations are blocked until the registry is ready.`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return abi;
|
|
149
|
+
}
|
|
150
|
+
// Was duplicated identically inside createFactoryWriteAPI and
|
|
151
|
+
// createSubscriptionManagerWriteAPI as a local closure each — hoisted here
|
|
152
|
+
// once consolidation made the duplication visible in one file.
|
|
153
|
+
getFactoryAddress() {
|
|
154
|
+
const dynamic = addressLoader.getAddress(this.readonly.chainId, "factory", this.environment);
|
|
155
|
+
if (!dynamic) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Factory address not resolved for chain ${this.readonly.chainId} (${this.environment}) \u2014 await client.ready before writing.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
return dynamic;
|
|
161
|
+
}
|
|
162
|
+
// AddressRegistry's own ABI is static (see requireAbi's comment on EvmClient's
|
|
163
|
+
// bootstrap exception) and so is its address per environment — mirrors
|
|
164
|
+
// EvmClient's private activeRegistryAddress getter.
|
|
165
|
+
getRegistryAddress() {
|
|
166
|
+
const address = this.environment === "staging" && this.config.addresses?.stagingAddressRegistry ? this.config.addresses.stagingAddressRegistry : this.config.addresses?.addressRegistry;
|
|
167
|
+
if (!address) {
|
|
168
|
+
throw new Error(`AddressRegistry address not configured for chain ${this.readonly.chainId} (${this.environment})`);
|
|
169
|
+
}
|
|
170
|
+
return address;
|
|
171
|
+
}
|
|
172
|
+
createFactoryWriteAPI(walletClient) {
|
|
173
|
+
const pushPythPrice = async () => {
|
|
174
|
+
if (!this.config.main) return;
|
|
175
|
+
const { price } = this.config;
|
|
176
|
+
if (price.stable) return;
|
|
177
|
+
const { pythOracle, usdPriceId } = price;
|
|
178
|
+
if (!pythOracle || !usdPriceId) return;
|
|
179
|
+
const res = await fetch(
|
|
180
|
+
`https://hermes.pyth.network/v2/updates/price/latest?ids[]=${usdPriceId}&encoding=hex`
|
|
181
|
+
);
|
|
182
|
+
if (!res.ok) throw new Error(`Hermes price fetch failed: ${res.status}`);
|
|
183
|
+
const data = await res.json();
|
|
184
|
+
const hexItems = data.binary?.data ?? [];
|
|
185
|
+
if (hexItems.length === 0) throw new Error("No price update data from Hermes");
|
|
186
|
+
const updateData = hexItems.map((h) => `0x${h}`);
|
|
187
|
+
const fee = await this.publicClient.readContract({
|
|
188
|
+
address: pythOracle,
|
|
189
|
+
abi: pythAbi,
|
|
190
|
+
functionName: "getUpdateFee",
|
|
191
|
+
args: [updateData]
|
|
192
|
+
});
|
|
193
|
+
const account = walletClient.account;
|
|
194
|
+
const hash = await walletClient.writeContract({
|
|
195
|
+
address: pythOracle,
|
|
196
|
+
abi: pythAbi,
|
|
197
|
+
functionName: "updatePriceFeeds",
|
|
198
|
+
args: [updateData],
|
|
199
|
+
account,
|
|
200
|
+
chain: this.chain,
|
|
201
|
+
value: fee
|
|
202
|
+
});
|
|
203
|
+
await this.publicClient.waitForTransactionReceipt({ hash });
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
donateToProject: async (projectId, lang, amount, options) => {
|
|
207
|
+
try {
|
|
208
|
+
const account = walletClient.account;
|
|
209
|
+
if (!account) {
|
|
210
|
+
throw new Error("No account connected to wallet");
|
|
211
|
+
}
|
|
212
|
+
const address = this.getFactoryAddress();
|
|
213
|
+
const votes = BigInt(Math.round(amount));
|
|
214
|
+
const hash = await walletClient.writeContract({
|
|
215
|
+
address,
|
|
216
|
+
abi: this.requireAbi("Factory"),
|
|
217
|
+
functionName: "voteForProject",
|
|
218
|
+
args: [projectId, stringToBytes4(lang), votes],
|
|
219
|
+
account,
|
|
220
|
+
chain: this.chain,
|
|
221
|
+
gas: options?.gasLimit
|
|
222
|
+
});
|
|
223
|
+
options?.onAccepted?.(hash);
|
|
224
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
225
|
+
if (typeof window !== "undefined") {
|
|
226
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
227
|
+
}
|
|
228
|
+
return receipt;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw normalizeError(error);
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
register: async (country, language, paymentValue, options) => {
|
|
234
|
+
try {
|
|
235
|
+
const account = walletClient.account;
|
|
236
|
+
if (!account) {
|
|
237
|
+
throw new Error("No account connected to wallet");
|
|
238
|
+
}
|
|
239
|
+
await walletClient.getAddresses();
|
|
240
|
+
const address = this.getFactoryAddress();
|
|
241
|
+
const valueInWei = parseEther(String(paymentValue));
|
|
242
|
+
await pushPythPrice();
|
|
243
|
+
const hash = await walletClient.writeContract({
|
|
244
|
+
address,
|
|
245
|
+
abi: this.requireAbi("Factory"),
|
|
246
|
+
functionName: "register",
|
|
247
|
+
args: [country, language, 0n],
|
|
248
|
+
account,
|
|
249
|
+
chain: this.chain,
|
|
250
|
+
value: valueInWei,
|
|
251
|
+
gas: options?.gasLimit
|
|
252
|
+
});
|
|
253
|
+
options?.onAccepted?.(hash);
|
|
254
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
255
|
+
if (typeof window !== "undefined") {
|
|
256
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
257
|
+
}
|
|
258
|
+
return receipt;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
throw normalizeError(error);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
unregister: async (options) => {
|
|
264
|
+
try {
|
|
265
|
+
const account = walletClient.account;
|
|
266
|
+
if (!account) {
|
|
267
|
+
throw new Error("No account connected to wallet");
|
|
268
|
+
}
|
|
269
|
+
const address = this.getFactoryAddress();
|
|
270
|
+
const hash = await walletClient.writeContract({
|
|
271
|
+
address,
|
|
272
|
+
abi: this.requireAbi("Factory"),
|
|
273
|
+
functionName: "unregister",
|
|
274
|
+
args: [],
|
|
275
|
+
account,
|
|
276
|
+
chain: this.chain,
|
|
277
|
+
gas: options?.gasLimit
|
|
278
|
+
});
|
|
279
|
+
options?.onAccepted?.(hash);
|
|
280
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
281
|
+
if (typeof window !== "undefined") {
|
|
282
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
283
|
+
}
|
|
284
|
+
return receipt;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
throw normalizeError(error);
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
save: async (patches, level, indexes, text, options) => {
|
|
290
|
+
try {
|
|
291
|
+
const account = walletClient.account;
|
|
292
|
+
if (!account) {
|
|
293
|
+
throw new Error("No account connected to wallet");
|
|
294
|
+
}
|
|
295
|
+
const address = this.getFactoryAddress();
|
|
296
|
+
const hash = await walletClient.writeContract({
|
|
297
|
+
address,
|
|
298
|
+
abi: this.requireAbi("Factory"),
|
|
299
|
+
functionName: "save",
|
|
300
|
+
args: [patches, level, indexes, text],
|
|
301
|
+
account,
|
|
302
|
+
chain: this.chain,
|
|
303
|
+
gas: options?.gasLimit
|
|
304
|
+
});
|
|
305
|
+
options?.onAccepted?.(hash);
|
|
306
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
307
|
+
if (typeof window !== "undefined") {
|
|
308
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
309
|
+
}
|
|
310
|
+
return receipt;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
throw normalizeError(error);
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
createProject: async (lang, uri, publicationDate, name, headline, arweaveAddressLogo, arweaveAddressBanner, descriptionMarkdown, minimumFundingBeforeStartWork, maximumFunding, tags, complexity, options) => {
|
|
316
|
+
try {
|
|
317
|
+
const account = walletClient.account;
|
|
318
|
+
if (!account) {
|
|
319
|
+
throw new Error("No account connected to wallet");
|
|
320
|
+
}
|
|
321
|
+
const address = this.getFactoryAddress();
|
|
322
|
+
const hash = await walletClient.writeContract({
|
|
323
|
+
address,
|
|
324
|
+
abi: this.requireAbi("Factory"),
|
|
325
|
+
functionName: "createProject",
|
|
326
|
+
args: [
|
|
327
|
+
stringToBytes4(lang),
|
|
328
|
+
uri,
|
|
329
|
+
publicationDate,
|
|
330
|
+
name,
|
|
331
|
+
headline,
|
|
332
|
+
arweaveAddressLogo,
|
|
333
|
+
arweaveAddressBanner,
|
|
334
|
+
descriptionMarkdown,
|
|
335
|
+
minimumFundingBeforeStartWork,
|
|
336
|
+
maximumFunding,
|
|
337
|
+
tags,
|
|
338
|
+
complexity
|
|
339
|
+
],
|
|
340
|
+
account,
|
|
341
|
+
chain: this.chain,
|
|
342
|
+
gas: options?.gasLimit
|
|
343
|
+
});
|
|
344
|
+
options?.onAccepted?.(hash);
|
|
345
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
346
|
+
if (typeof window !== "undefined") {
|
|
347
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
348
|
+
}
|
|
349
|
+
return receipt;
|
|
350
|
+
} catch (error) {
|
|
351
|
+
throw normalizeError(error);
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
registerStripe: async (country, language, paymentIntentId, votes, signature, options) => {
|
|
355
|
+
try {
|
|
356
|
+
const account = walletClient.account;
|
|
357
|
+
if (!account) throw new Error("No account connected to wallet");
|
|
358
|
+
const address = this.getFactoryAddress();
|
|
359
|
+
const hash = await walletClient.writeContract({
|
|
360
|
+
address,
|
|
361
|
+
abi: this.requireAbi("Factory"),
|
|
362
|
+
functionName: "registerStripe",
|
|
363
|
+
args: [country, language, paymentIntentId, votes, 0, signature],
|
|
364
|
+
account,
|
|
365
|
+
chain: this.chain,
|
|
366
|
+
gas: options?.gasLimit
|
|
367
|
+
});
|
|
368
|
+
options?.onAccepted?.(hash);
|
|
369
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
370
|
+
if (typeof window !== "undefined") {
|
|
371
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
372
|
+
}
|
|
373
|
+
return receipt;
|
|
374
|
+
} catch (error) {
|
|
375
|
+
throw normalizeError(error);
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
fundStripe: async (paymentIntentId, votes, signature, options) => {
|
|
379
|
+
try {
|
|
380
|
+
const account = walletClient.account;
|
|
381
|
+
if (!account) throw new Error("No account connected to wallet");
|
|
382
|
+
const address = this.getFactoryAddress();
|
|
383
|
+
const hash = await walletClient.writeContract({
|
|
384
|
+
address,
|
|
385
|
+
abi: this.requireAbi("Factory"),
|
|
386
|
+
functionName: "fundStripe",
|
|
387
|
+
args: [paymentIntentId, votes, signature],
|
|
388
|
+
account,
|
|
389
|
+
chain: this.chain,
|
|
390
|
+
gas: options?.gasLimit
|
|
391
|
+
});
|
|
392
|
+
options?.onAccepted?.(hash);
|
|
393
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
394
|
+
if (typeof window !== "undefined") {
|
|
395
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
396
|
+
}
|
|
397
|
+
return receipt;
|
|
398
|
+
} catch (error) {
|
|
399
|
+
throw normalizeError(error);
|
|
400
|
+
}
|
|
401
|
+
},
|
|
402
|
+
addProjectVersion: async (projectId, lang, publicationDate, uri, name, headline, arweaveAddressLogo, arweaveAddressBanner, descriptionMarkdown, minimumFundingBeforeStartWork, maximumFunding, tags, status, complexity, options) => {
|
|
403
|
+
try {
|
|
404
|
+
const account = walletClient.account;
|
|
405
|
+
if (!account) {
|
|
406
|
+
throw new Error("No account connected to wallet");
|
|
407
|
+
}
|
|
408
|
+
const address = this.getFactoryAddress();
|
|
409
|
+
const hash = await walletClient.writeContract({
|
|
410
|
+
address,
|
|
411
|
+
abi: this.requireAbi("Factory"),
|
|
412
|
+
functionName: "addProjectVersion",
|
|
413
|
+
args: [
|
|
414
|
+
BigInt(projectId),
|
|
415
|
+
stringToBytes4(lang),
|
|
416
|
+
publicationDate,
|
|
417
|
+
uri,
|
|
418
|
+
name,
|
|
419
|
+
headline,
|
|
420
|
+
arweaveAddressLogo,
|
|
421
|
+
arweaveAddressBanner,
|
|
422
|
+
descriptionMarkdown,
|
|
423
|
+
minimumFundingBeforeStartWork,
|
|
424
|
+
maximumFunding,
|
|
425
|
+
tags,
|
|
426
|
+
status,
|
|
427
|
+
complexity
|
|
428
|
+
],
|
|
429
|
+
account,
|
|
430
|
+
chain: this.chain,
|
|
431
|
+
gas: options?.gasLimit
|
|
432
|
+
});
|
|
433
|
+
options?.onAccepted?.(hash);
|
|
434
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
435
|
+
if (typeof window !== "undefined") {
|
|
436
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
437
|
+
}
|
|
438
|
+
return receipt;
|
|
439
|
+
} catch (error) {
|
|
440
|
+
throw normalizeError(error);
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
deleteProject: async (projectId, lang, options) => {
|
|
444
|
+
try {
|
|
445
|
+
const account = walletClient.account;
|
|
446
|
+
if (!account) {
|
|
447
|
+
throw new Error("No account connected to wallet");
|
|
448
|
+
}
|
|
449
|
+
const address = this.getFactoryAddress();
|
|
450
|
+
const hash = await walletClient.writeContract({
|
|
451
|
+
address,
|
|
452
|
+
abi: this.requireAbi("Factory"),
|
|
453
|
+
functionName: "deleteProject",
|
|
454
|
+
args: [projectId, stringToBytes4(lang)],
|
|
455
|
+
account,
|
|
456
|
+
chain: this.chain,
|
|
457
|
+
gas: options?.gasLimit
|
|
458
|
+
});
|
|
459
|
+
options?.onAccepted?.(hash);
|
|
460
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
461
|
+
if (typeof window !== "undefined") {
|
|
462
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
463
|
+
}
|
|
464
|
+
return receipt;
|
|
465
|
+
} catch (error) {
|
|
466
|
+
throw normalizeError(error);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
createSubscriptionManagerWriteAPI(walletClient) {
|
|
472
|
+
return {
|
|
473
|
+
subscribeTo: async (subscriber, target, options) => {
|
|
474
|
+
try {
|
|
475
|
+
const account = walletClient.account;
|
|
476
|
+
if (!account) {
|
|
477
|
+
throw new Error("No account connected to wallet");
|
|
478
|
+
}
|
|
479
|
+
const targetUsername = await this.readonly.bouncerStorage.userIdToUsername(target);
|
|
480
|
+
if (!targetUsername) {
|
|
481
|
+
throw new Error(`Target user ID ${target} not registered (no username found)`);
|
|
482
|
+
}
|
|
483
|
+
const address = this.getFactoryAddress();
|
|
484
|
+
const hash = await walletClient.writeContract({
|
|
485
|
+
address,
|
|
486
|
+
abi: this.requireAbi("Factory"),
|
|
487
|
+
functionName: "subscribeTo",
|
|
488
|
+
args: [targetUsername],
|
|
489
|
+
account,
|
|
490
|
+
chain: this.chain,
|
|
491
|
+
gas: options?.gasLimit
|
|
492
|
+
});
|
|
493
|
+
options?.onAccepted?.(hash);
|
|
494
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
495
|
+
if (typeof window !== "undefined") {
|
|
496
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
497
|
+
}
|
|
498
|
+
return receipt;
|
|
499
|
+
} catch (error) {
|
|
500
|
+
throw normalizeError(error);
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
unsubscribeFrom: async (subscriber, target, options) => {
|
|
504
|
+
try {
|
|
505
|
+
const account = walletClient.account;
|
|
506
|
+
if (!account) {
|
|
507
|
+
throw new Error("No account connected to wallet");
|
|
508
|
+
}
|
|
509
|
+
const targetUsername = await this.readonly.bouncerStorage.userIdToUsername(target);
|
|
510
|
+
if (!targetUsername) {
|
|
511
|
+
throw new Error(`Target user ID ${target} not registered (no username found)`);
|
|
512
|
+
}
|
|
513
|
+
const address = this.getFactoryAddress();
|
|
514
|
+
const hash = await walletClient.writeContract({
|
|
515
|
+
address,
|
|
516
|
+
abi: this.requireAbi("Factory"),
|
|
517
|
+
functionName: "unsubscribeFrom",
|
|
518
|
+
args: [targetUsername],
|
|
519
|
+
account,
|
|
520
|
+
chain: this.chain,
|
|
521
|
+
gas: options?.gasLimit
|
|
522
|
+
});
|
|
523
|
+
options?.onAccepted?.(hash);
|
|
524
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
525
|
+
if (typeof window !== "undefined") {
|
|
526
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
527
|
+
}
|
|
528
|
+
return receipt;
|
|
529
|
+
} catch (error) {
|
|
530
|
+
throw normalizeError(error);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
createAddressRegistryWriteAPI(walletClient) {
|
|
536
|
+
return {
|
|
537
|
+
addData: async (key, value, options) => {
|
|
538
|
+
try {
|
|
539
|
+
const account = walletClient.account;
|
|
540
|
+
if (!account) {
|
|
541
|
+
throw new Error("No account connected to wallet");
|
|
542
|
+
}
|
|
543
|
+
const address = this.getRegistryAddress();
|
|
544
|
+
const hash = await walletClient.writeContract({
|
|
545
|
+
address,
|
|
546
|
+
abi: addressRegistryAbi,
|
|
547
|
+
functionName: "addData",
|
|
548
|
+
args: [key, value],
|
|
549
|
+
account,
|
|
550
|
+
chain: this.chain,
|
|
551
|
+
gas: options?.gasLimit
|
|
552
|
+
});
|
|
553
|
+
options?.onAccepted?.(hash);
|
|
554
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
555
|
+
if (typeof window !== "undefined") {
|
|
556
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
557
|
+
}
|
|
558
|
+
return receipt;
|
|
559
|
+
} catch (error) {
|
|
560
|
+
throw normalizeError(error);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
getLibraryRegistryStorageAddress() {
|
|
566
|
+
const dynamic = addressLoader.getAddress(this.readonly.chainId, "libraryRegistryStorage", this.environment);
|
|
567
|
+
if (!dynamic) {
|
|
568
|
+
throw new Error(
|
|
569
|
+
`LibraryRegistryStorage address not resolved for chain ${this.readonly.chainId} (${this.environment}) \u2014 await client.ready before writing.`
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return dynamic;
|
|
573
|
+
}
|
|
574
|
+
createLibraryRegistryStorageWriteAPI(walletClient) {
|
|
575
|
+
const executeWrite = async (functionName, args, options) => {
|
|
576
|
+
try {
|
|
577
|
+
const account = walletClient.account;
|
|
578
|
+
if (!account) throw new Error("No account connected to wallet");
|
|
579
|
+
const address = this.getLibraryRegistryStorageAddress();
|
|
580
|
+
const hash = await walletClient.writeContract({
|
|
581
|
+
address,
|
|
582
|
+
abi: this.requireAbi("LibraryRegistryStorage"),
|
|
583
|
+
functionName,
|
|
584
|
+
args,
|
|
585
|
+
account,
|
|
586
|
+
chain: this.chain,
|
|
587
|
+
gas: options?.gasLimit
|
|
588
|
+
});
|
|
589
|
+
options?.onAccepted?.(hash);
|
|
590
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
591
|
+
if (typeof window !== "undefined") {
|
|
592
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
593
|
+
}
|
|
594
|
+
return receipt;
|
|
595
|
+
} catch (error) {
|
|
596
|
+
throw normalizeError(error);
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
return {
|
|
600
|
+
addUnverifiedCollection: (input, options) => executeWrite("addUnverifiedCollection", [input], options),
|
|
601
|
+
verifyCollection: (id, options) => executeWrite("verifyCollection", [id], options),
|
|
602
|
+
rejectCollection: (id, options) => executeWrite("rejectCollection", [id], options),
|
|
603
|
+
updateCollectionStats: (id, initialBookCount, dSafeBookCount, options) => executeWrite("updateCollectionStats", [id, BigInt(initialBookCount), BigInt(dSafeBookCount)], options),
|
|
604
|
+
setImportStatus: (id, status, options) => executeWrite("setImportStatus", [id, status], options),
|
|
605
|
+
setPublished: (id, isPublished, options) => executeWrite("setPublished", [id, isPublished], options),
|
|
606
|
+
setCollectionPublicLibrary: (id, publicLibraryId, options) => executeWrite("setCollectionPublicLibrary", [id, BigInt(publicLibraryId)], options),
|
|
607
|
+
setPublicLibraryStorage: (storageAddr, options) => executeWrite("setPublicLibraryStorage", [storageAddr], options)
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
getPublicLibraryStorageAddress() {
|
|
611
|
+
const dynamic = addressLoader.getAddress(this.readonly.chainId, "publicLibraryStorage", this.environment);
|
|
612
|
+
if (!dynamic) {
|
|
613
|
+
throw new Error(
|
|
614
|
+
`PublicLibraryStorage address not resolved for chain ${this.readonly.chainId} (${this.environment}) \u2014 await client.ready before writing.`
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
return dynamic;
|
|
618
|
+
}
|
|
619
|
+
createPublicLibraryStorageWriteAPI(walletClient) {
|
|
620
|
+
const executeWrite = async (functionName, args, options) => {
|
|
621
|
+
try {
|
|
622
|
+
const account = walletClient.account;
|
|
623
|
+
if (!account) throw new Error("No account connected to wallet");
|
|
624
|
+
const address = this.getPublicLibraryStorageAddress();
|
|
625
|
+
const hash = await walletClient.writeContract({
|
|
626
|
+
address,
|
|
627
|
+
abi: this.requireAbi("PublicLibraryStorage"),
|
|
628
|
+
functionName,
|
|
629
|
+
args,
|
|
630
|
+
account,
|
|
631
|
+
chain: this.chain,
|
|
632
|
+
gas: options?.gasLimit
|
|
633
|
+
});
|
|
634
|
+
options?.onAccepted?.(hash);
|
|
635
|
+
const receipt = await this.publicClient.waitForTransactionReceipt({ hash });
|
|
636
|
+
if (typeof window !== "undefined") {
|
|
637
|
+
window.dispatchEvent(new Event("wallet_transaction_accepted"));
|
|
638
|
+
}
|
|
639
|
+
return receipt;
|
|
640
|
+
} catch (error) {
|
|
641
|
+
throw normalizeError(error);
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
return {
|
|
645
|
+
addPublicLibrary: (input, options) => executeWrite("addPublicLibrary", [input], options),
|
|
646
|
+
updatePublicLibrary: (id, input, options) => executeWrite("updatePublicLibrary", [BigInt(id), input], options)
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// src/web3/session/writeClient.ts
|
|
652
|
+
async function createWriteClient(connector, chainId, environment = "production") {
|
|
653
|
+
const evmConnector = connector;
|
|
654
|
+
if (typeof evmConnector.getWalletClient !== "function") {
|
|
655
|
+
throw new Error(`Connector '${connector.type}' does not support EVM write operations`);
|
|
656
|
+
}
|
|
657
|
+
const accounts = await connector.getAccounts();
|
|
658
|
+
const account = accounts[0];
|
|
659
|
+
if (!account) {
|
|
660
|
+
throw new Error(`No account available for wallet '${connector.type}' \u2014 connect() first`);
|
|
661
|
+
}
|
|
662
|
+
const evmClient = await getReadyEvmClient(chainId, environment);
|
|
663
|
+
const walletClient = await evmConnector.getWalletClient(chainId);
|
|
664
|
+
return new EvmWriteClient(connector.type, evmClient, walletClient, account);
|
|
665
|
+
}
|
|
666
|
+
async function createPrivateKeyWriteClient(chainId, privateKey, environment = "production") {
|
|
667
|
+
const evmClient = await getReadyEvmClient(chainId, environment);
|
|
668
|
+
const walletClient = createPrivateKeyWalletClient(chainId, privateKey);
|
|
669
|
+
const account = addressFromPrivateKey(privateKey);
|
|
670
|
+
return new EvmWriteClient("private_key", evmClient, walletClient, account);
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// src/web3/session/mutations.ts
|
|
674
|
+
import { serializePatches, getLevel } from "@the_library/public/models";
|
|
675
|
+
var running = { lastRun: 0, running: false };
|
|
676
|
+
var resetTransactionState = () => {
|
|
677
|
+
running.running = false;
|
|
678
|
+
running.lastRun = 0;
|
|
679
|
+
};
|
|
680
|
+
var checkRunning = () => {
|
|
681
|
+
if (running.running && Date.now() - running.lastRun < 1e3 * 60) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
running.lastRun = Date.now();
|
|
685
|
+
running.running = true;
|
|
686
|
+
return true;
|
|
687
|
+
};
|
|
688
|
+
var handleWriteOperationErrors = (wallet, chainId, e) => {
|
|
689
|
+
console.error(`[session/mutations] error while transaction wallet=${wallet} chainId=${chainId}`, e);
|
|
690
|
+
resetTransactionState();
|
|
691
|
+
const isUserRejection = normalizeError(e).code === "USER_REJECTED";
|
|
692
|
+
WalletEvents.emitWalletError({
|
|
693
|
+
wallet,
|
|
694
|
+
chainId,
|
|
695
|
+
timestamp: Date.now(),
|
|
696
|
+
reason: isUserRejection ? "USER_REJECTED" /* USER_REJECTED */ : e?.code ?? "UNKNOWN_ERROR" /* UNKNOWN_ERROR */,
|
|
697
|
+
args: e
|
|
698
|
+
});
|
|
699
|
+
};
|
|
700
|
+
var transactionStarted = (wallet, chainId) => {
|
|
701
|
+
WalletEvents.emitWalletStateEvent({ wallet, chainId, event: "TRANSACTION_STARTED" /* TRANSACTION_STARTED */, timestamp: Date.now() });
|
|
702
|
+
};
|
|
703
|
+
var transactionDone = (wallet, chainId) => {
|
|
704
|
+
WalletEvents.emitWalletStateEvent({ wallet, chainId, event: "TRANSACTION_DONE" /* TRANSACTION_DONE */, timestamp: Date.now() });
|
|
705
|
+
};
|
|
706
|
+
var preTransaction = async (wallet, chainId) => {
|
|
707
|
+
if (!checkRunning()) {
|
|
708
|
+
console.log("[session/mutations] preTransaction skipped \u2014 another transaction is running, wait 1min");
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
return true;
|
|
712
|
+
};
|
|
713
|
+
var postTransaction = async (wallet, chainId, account) => {
|
|
714
|
+
running.running = false;
|
|
715
|
+
running.lastRun = 0;
|
|
716
|
+
WalletEvents.emitWalletStateEvent({
|
|
717
|
+
wallet,
|
|
718
|
+
chainId,
|
|
719
|
+
event: "UPDATING_STATE_STARTED" /* UPDATING_STATE_STARTED */,
|
|
720
|
+
functionName: "syncAccount",
|
|
721
|
+
timestamp: Date.now()
|
|
722
|
+
});
|
|
723
|
+
try {
|
|
724
|
+
await syncAccount(account, chainId, wallet, "production", true);
|
|
725
|
+
} catch (e) {
|
|
726
|
+
WalletEvents.emitWalletStateEvent({
|
|
727
|
+
wallet,
|
|
728
|
+
chainId,
|
|
729
|
+
event: "UPDATING_STATE_FAILED" /* UPDATING_STATE_FAILED */,
|
|
730
|
+
functionName: "syncAccount",
|
|
731
|
+
timestamp: Date.now()
|
|
732
|
+
});
|
|
733
|
+
console.error(e);
|
|
734
|
+
return false;
|
|
735
|
+
}
|
|
736
|
+
WalletEvents.emitWalletStateEvent({
|
|
737
|
+
wallet,
|
|
738
|
+
chainId,
|
|
739
|
+
event: "UPDATING_STATE_DONE" /* UPDATING_STATE_DONE */,
|
|
740
|
+
functionName: "syncAccount",
|
|
741
|
+
timestamp: Date.now()
|
|
742
|
+
});
|
|
743
|
+
return true;
|
|
744
|
+
};
|
|
745
|
+
async function getWriteClient(wallet, chainId) {
|
|
746
|
+
const connector = getConnector(wallet);
|
|
747
|
+
if (!connector) {
|
|
748
|
+
throw new Error(`No connector registered for wallet '${wallet}' \u2014 bootstrapWebSDK() must run first`);
|
|
749
|
+
}
|
|
750
|
+
return createWriteClient(connector, chainId);
|
|
751
|
+
}
|
|
752
|
+
async function runWriteOperation(wallet, chainId, account, fn, afterWrite) {
|
|
753
|
+
if (!await preTransaction(wallet, chainId)) return false;
|
|
754
|
+
transactionStarted(wallet, chainId);
|
|
755
|
+
try {
|
|
756
|
+
const client = await getWriteClient(wallet, chainId);
|
|
757
|
+
await fn(client);
|
|
758
|
+
} catch (e) {
|
|
759
|
+
handleWriteOperationErrors(wallet, chainId, e);
|
|
760
|
+
throw e;
|
|
761
|
+
}
|
|
762
|
+
transactionDone(wallet, chainId);
|
|
763
|
+
afterWrite?.();
|
|
764
|
+
return postTransaction(wallet, chainId, account);
|
|
765
|
+
}
|
|
766
|
+
var writeOperations = {
|
|
767
|
+
register: (wallet, chainId, account, amount) => {
|
|
768
|
+
const userGeo = typeof window !== "undefined" ? window.__userGeo : void 0;
|
|
769
|
+
let countryCode;
|
|
770
|
+
let languageCode;
|
|
771
|
+
if (userGeo?.location && userGeo?.locale) {
|
|
772
|
+
countryCode = userGeo.location.toUpperCase();
|
|
773
|
+
languageCode = userGeo.locale.split("-")[0];
|
|
774
|
+
} else {
|
|
775
|
+
const defaultLanguage = "en";
|
|
776
|
+
const defaultCountry = "";
|
|
777
|
+
const hasNavigator = typeof navigator !== "undefined";
|
|
778
|
+
const parts = hasNavigator ? navigator.language.split("-") : [defaultLanguage];
|
|
779
|
+
languageCode = parts[0];
|
|
780
|
+
countryCode = parts.length > 1 ? parts[1].toUpperCase() : defaultCountry;
|
|
781
|
+
}
|
|
782
|
+
return runWriteOperation(
|
|
783
|
+
wallet,
|
|
784
|
+
chainId,
|
|
785
|
+
account,
|
|
786
|
+
(client) => client.factory.register(countryCode, languageCode, amount, { value: amount })
|
|
787
|
+
);
|
|
788
|
+
},
|
|
789
|
+
retire: (wallet, chainId, account, options) => runWriteOperation(wallet, chainId, account, (client) => client.factory.unregister(options)),
|
|
790
|
+
vote: (wallet, chainId, account, projectId, lang, amount, options) => runWriteOperation(wallet, chainId, account, (client) => client.factory.donateToProject(projectId, lang, amount, options)),
|
|
791
|
+
save: (wallet, chainId, account, compressedActions, textIndexes, textData, level, options) => runWriteOperation(
|
|
792
|
+
wallet,
|
|
793
|
+
chainId,
|
|
794
|
+
account,
|
|
795
|
+
(client) => client.factory.save(compressedActions, level, textIndexes, textData, options),
|
|
796
|
+
() => {
|
|
797
|
+
if (!options?.skipCounterUpdate) {
|
|
798
|
+
const { lastPatchIndex } = sessionStore.lastSyncCounters(account, chainId);
|
|
799
|
+
sessionStore.setLastSavedPatchIndex(account, chainId, lastPatchIndex + compressedActions.length);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
),
|
|
803
|
+
// postTransaction's syncAccount() refresh also runs SubscriptionClient.syncSince()
|
|
804
|
+
// (session/sync.ts) — the graph change from these two writes is picked up
|
|
805
|
+
// automatically, no bespoke "refresh subscriptions" step needed (spec §4.7/§15.8).
|
|
806
|
+
subscribe: (wallet, chainId, account, subscriber, target) => runWriteOperation(wallet, chainId, account, (client) => client.subscriptionManager.subscribeTo(subscriber, target)),
|
|
807
|
+
unsubscribe: (wallet, chainId, account, subscriber, target) => runWriteOperation(wallet, chainId, account, (client) => client.subscriptionManager.unsubscribeFrom(subscriber, target))
|
|
808
|
+
};
|
|
809
|
+
async function saveMyLevel(wallet, chainId, account, options) {
|
|
810
|
+
const { lastPatchIndex } = sessionStore.lastSyncCounters(account, chainId);
|
|
811
|
+
const nbPatches = await getNbPatches("mine");
|
|
812
|
+
if (nbPatches <= lastPatchIndex) return false;
|
|
813
|
+
const payload = await serializePatches(lastPatchIndex, nbPatches);
|
|
814
|
+
const level = getLevel("mine").level;
|
|
815
|
+
return writeOperations.save(wallet, chainId, account, payload.patches, payload.textIndex, payload.textData, level, options);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// src/web3/wallet/browsers.ts
|
|
819
|
+
var Browser = /* @__PURE__ */ ((Browser2) => {
|
|
820
|
+
Browser2["chromium"] = "chromium";
|
|
821
|
+
Browser2["firefox"] = "firefox";
|
|
822
|
+
Browser2["safari"] = "safari";
|
|
823
|
+
Browser2["edge"] = "edge";
|
|
824
|
+
Browser2["opera"] = "opera";
|
|
825
|
+
Browser2["brave"] = "brave";
|
|
826
|
+
Browser2["vivaldi"] = "vivaldi";
|
|
827
|
+
Browser2["yandex"] = "yandex";
|
|
828
|
+
Browser2["palemoon"] = "palemoon";
|
|
829
|
+
return Browser2;
|
|
830
|
+
})(Browser || {});
|
|
831
|
+
var Platform = /* @__PURE__ */ ((Platform2) => {
|
|
832
|
+
Platform2["android"] = "android";
|
|
833
|
+
Platform2["ios"] = "ios";
|
|
834
|
+
Platform2["browsers"] = "browsers";
|
|
835
|
+
return Platform2;
|
|
836
|
+
})(Platform || {});
|
|
837
|
+
var parseUserAgent = (userAgent = typeof navigator !== "undefined" ? navigator.userAgent : "") => {
|
|
838
|
+
const ua = userAgent.toLowerCase();
|
|
839
|
+
let browser;
|
|
840
|
+
if (ua.includes("yabrowser") || ua.includes("yandex")) {
|
|
841
|
+
browser = "yandex" /* yandex */;
|
|
842
|
+
} else if (ua.includes("brave")) {
|
|
843
|
+
browser = "brave" /* brave */;
|
|
844
|
+
} else if (ua.includes("vivaldi")) {
|
|
845
|
+
browser = "vivaldi" /* vivaldi */;
|
|
846
|
+
} else if (ua.includes("palemoon")) {
|
|
847
|
+
browser = "palemoon" /* palemoon */;
|
|
848
|
+
} else if (ua.includes("edg/") || ua.includes("edge/")) {
|
|
849
|
+
browser = "edge" /* edge */;
|
|
850
|
+
} else if (ua.includes("opr/") || ua.includes("opera/")) {
|
|
851
|
+
browser = "opera" /* opera */;
|
|
852
|
+
} else if (ua.includes("firefox/")) {
|
|
853
|
+
browser = "firefox" /* firefox */;
|
|
854
|
+
} else if (ua.includes("safari/") && !ua.includes("chrome/")) {
|
|
855
|
+
browser = "safari" /* safari */;
|
|
856
|
+
} else if (ua.includes("chrome/") || ua.includes("chromium/")) {
|
|
857
|
+
browser = "chromium" /* chromium */;
|
|
858
|
+
} else {
|
|
859
|
+
browser = "chromium" /* chromium */;
|
|
860
|
+
}
|
|
861
|
+
let platform;
|
|
862
|
+
if (ua.includes("android")) {
|
|
863
|
+
platform = "android" /* android */;
|
|
864
|
+
} else if (ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod")) {
|
|
865
|
+
platform = "ios" /* ios */;
|
|
866
|
+
} else {
|
|
867
|
+
platform = "browsers" /* browsers */;
|
|
868
|
+
}
|
|
869
|
+
return {
|
|
870
|
+
browser,
|
|
871
|
+
platform
|
|
872
|
+
};
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/web3/wallet/walletMeta.ts
|
|
876
|
+
var METAMASK_LOGO_BASE64 = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLQogIC0gICAvKgogIC0gICAgKiBDb3B5cmlnaHQgKGMpIDIwMjYgRGF0YVBvbmQgRC1MaWJyYXJ5IFB0eSBMdGQuICgiVGhlIFNhbmN0dWFyeSIpCiAgLSAgICAqIE5vbi1Qcm9maXQgUHVibGljIExpYnJhcnkg4oCUIFRoZSBXb3JsZCBMaWJyYXJ5CiAgLSAgICAqCiAgLSAgICAqIExpY2Vuc2VkIHVuZGVyIHRoZSBELU9wZW4gQ29kZSBTb3ZlcmVpZ24gTGljZW5jZSB2MS4wCiAgLSAgICAqIGh0dHBzOi8vcmVnaXN0cnkud29ybGQuYmlibGlvdGVjaC5jb20vbGljZW5jZQogIC0gICAgKgogIC0gICAgKiBUZWNobmljYWwgR3VhcmRpYW4gKCJUaGUgU2hpZWxkIik6IFBvbmQgRW50ZXJwcmlzZSBQdHkgTHRkLiAoQUNOIDY5NCA3NDcgOTg3KQogIC0gICAgKiBBbGwgbGlhYmlsaXR5IGNsYWltcyBkaXJlY3RlZCB0byBQb25kIEVudGVycHJpc2UgUHR5IEx0ZC4KICAtICAgICogTW9kaWZpY2F0aW9uIGF1dG9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IDE1LjMtMTcuNCA1NC4yaDQ2LjRsMzEuMS40LTIzLjYtNDZ6bTcxIDI2LjQgMy4zLTU3LjcgMTUuMi00MS4xaC02Ny41bDE1IDQxLjEgMy41IDU3LjcgMS4yIDE4LjIuMSA0NC44aDI3LjdsLjItNDQuOHoiIGNsYXNzPSJzdDYiLz4KPC9zdmc+";
|
|
877
|
+
var walletMeta = {
|
|
878
|
+
metamask: {
|
|
879
|
+
displayName: "MetaMask",
|
|
880
|
+
logoUrl: METAMASK_LOGO_BASE64,
|
|
881
|
+
description: "The most popular Ethereum wallet extension",
|
|
882
|
+
website: "https://metamask.io/",
|
|
883
|
+
isInstalled() {
|
|
884
|
+
return typeof window !== "undefined" && typeof window.ethereum !== "undefined" && window.ethereum.isMetaMask;
|
|
885
|
+
},
|
|
886
|
+
isInstallable() {
|
|
887
|
+
try {
|
|
888
|
+
this.getInstallUrl();
|
|
889
|
+
return true;
|
|
890
|
+
} catch {
|
|
891
|
+
return false;
|
|
892
|
+
}
|
|
893
|
+
},
|
|
894
|
+
getInstallUrl(customBrowser) {
|
|
895
|
+
const { browser, platform } = parseUserAgent();
|
|
896
|
+
const targetBrowser = customBrowser || browser;
|
|
897
|
+
switch (platform) {
|
|
898
|
+
case "android" /* android */:
|
|
899
|
+
return "https://play.google.com/store/apps/details?id=io.metamask";
|
|
900
|
+
case "ios" /* ios */:
|
|
901
|
+
return "https://apps.apple.com/us/app/metamask-crypto-wallet/id1438144202";
|
|
902
|
+
case "browsers" /* browsers */:
|
|
903
|
+
switch (targetBrowser) {
|
|
904
|
+
case "chromium" /* chromium */:
|
|
905
|
+
case "brave" /* brave */:
|
|
906
|
+
return "https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn";
|
|
907
|
+
case "firefox" /* firefox */:
|
|
908
|
+
return "https://addons.mozilla.org/en-US/firefox/addon/ether-metamask/";
|
|
909
|
+
case "opera" /* opera */:
|
|
910
|
+
return "https://addons.opera.com/en/extensions/details/metamask/";
|
|
911
|
+
case "edge" /* edge */:
|
|
912
|
+
return "https://microsoftedge.microsoft.com/addons/detail/metamask/ejbalbakoplchlghecdalmeeeajnimhm";
|
|
913
|
+
default:
|
|
914
|
+
throw new Error(`Browser ${targetBrowser} is not supported for installation of MetaMask extension.`);
|
|
915
|
+
}
|
|
916
|
+
default:
|
|
917
|
+
throw new Error(`Platform ${platform} is not supported for MetaMask.`);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
},
|
|
921
|
+
private_key: {
|
|
922
|
+
displayName: "Private Key",
|
|
923
|
+
logoUrl: "",
|
|
924
|
+
description: "Direct embedded wallet using a raw private key",
|
|
925
|
+
website: "",
|
|
926
|
+
isInstalled() {
|
|
927
|
+
return true;
|
|
928
|
+
},
|
|
929
|
+
isInstallable() {
|
|
930
|
+
return false;
|
|
931
|
+
},
|
|
932
|
+
getInstallUrl() {
|
|
933
|
+
return "";
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
// src/web3/index.ts
|
|
939
|
+
import { formatEther, parseEther as parseEther2 } from "viem";
|
|
940
|
+
export {
|
|
941
|
+
Browser,
|
|
942
|
+
CACHE_DURATION_MS,
|
|
943
|
+
DEFAULT_CHAIN_ID,
|
|
944
|
+
EVM_CHAINS,
|
|
945
|
+
EventBus,
|
|
946
|
+
EventName,
|
|
947
|
+
EvmClient,
|
|
948
|
+
EvmWriteClient,
|
|
949
|
+
LibraryOwnership,
|
|
950
|
+
MetaMaskConnector,
|
|
951
|
+
NodeFileCacheStorage,
|
|
952
|
+
Platform,
|
|
953
|
+
PreferredFormat,
|
|
954
|
+
PrivateKeyConnector,
|
|
955
|
+
RegistryAddressLoader,
|
|
956
|
+
SubscriptionClient,
|
|
957
|
+
WalletError,
|
|
958
|
+
WalletEvents,
|
|
959
|
+
WalletState,
|
|
960
|
+
WalletUxError,
|
|
961
|
+
addressFromPrivateKey,
|
|
962
|
+
addressLoader,
|
|
963
|
+
addressRegistryAbi,
|
|
964
|
+
allRegisteredAccounts,
|
|
965
|
+
createEvmClient,
|
|
966
|
+
createMetaMaskConnector,
|
|
967
|
+
createNodeFileCacheStorage,
|
|
968
|
+
createPrivateKeyConnector,
|
|
969
|
+
createPrivateKeyWalletClient,
|
|
970
|
+
createPrivateKeyWriteClient,
|
|
971
|
+
createSessionStore,
|
|
972
|
+
createWriteClient,
|
|
973
|
+
cursorStore,
|
|
974
|
+
deserializeCursor,
|
|
975
|
+
emptyCursor,
|
|
976
|
+
formatEther,
|
|
977
|
+
getCachedEmail,
|
|
978
|
+
getChain,
|
|
979
|
+
getConnector,
|
|
980
|
+
getContractAbi,
|
|
981
|
+
getDecryptedPrivateKey,
|
|
982
|
+
getEventBus,
|
|
983
|
+
getEvmClient,
|
|
984
|
+
getPrivateKey,
|
|
985
|
+
getReadClient,
|
|
986
|
+
getReadyEvmClient,
|
|
987
|
+
getRegisteredConnectors,
|
|
988
|
+
getRegistryBaseUrl,
|
|
989
|
+
getSubscriptionClient,
|
|
990
|
+
handleWriteOperationErrors,
|
|
991
|
+
hasAnyPrivateKey,
|
|
992
|
+
hasEncryptedPrivateKey,
|
|
993
|
+
hasPrivateKey,
|
|
994
|
+
hasUnsavedPatches,
|
|
995
|
+
loadNetworkInfos,
|
|
996
|
+
loadProject,
|
|
997
|
+
loadProjects,
|
|
998
|
+
parseEther2 as parseEther,
|
|
999
|
+
parseUserAgent,
|
|
1000
|
+
projectLocale,
|
|
1001
|
+
pythAbi,
|
|
1002
|
+
readOnlyClients,
|
|
1003
|
+
readOnlyStagingClients,
|
|
1004
|
+
registerConnector,
|
|
1005
|
+
resetTransactionState,
|
|
1006
|
+
restoreAccountSave,
|
|
1007
|
+
saveMyLevel,
|
|
1008
|
+
serializeCursor,
|
|
1009
|
+
sessionStore,
|
|
1010
|
+
setCachedEmail,
|
|
1011
|
+
setRegistryBaseUrl,
|
|
1012
|
+
sidecarUrlsFromManifest,
|
|
1013
|
+
storeEncryptedPrivateKey,
|
|
1014
|
+
storePrivateKey,
|
|
1015
|
+
syncAccount,
|
|
1016
|
+
toViemChain,
|
|
1017
|
+
walletMeta,
|
|
1018
|
+
writeOperations
|
|
1019
|
+
};
|
|
1020
|
+
//# sourceMappingURL=index.js.map
|