@fileverse/api 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +10 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +95 -48
- package/dist/cloudflare.js.map +1 -1
- package/dist/commands/index.js +10 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +69 -48
- package/dist/index.js.map +1 -1
- package/dist/worker.js +69 -48
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -1672,19 +1672,29 @@ var init_pimlico_utils = __esm({
|
|
|
1672
1672
|
version: "0.7"
|
|
1673
1673
|
}
|
|
1674
1674
|
});
|
|
1675
|
-
signerToSmartAccount = async (signer) =>
|
|
1676
|
-
client
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1675
|
+
signerToSmartAccount = async (signer) => {
|
|
1676
|
+
console.log("[pimlico] creating public client");
|
|
1677
|
+
const client = getPublicClient();
|
|
1678
|
+
console.log("[pimlico] calling toSafeSmartAccount");
|
|
1679
|
+
const account = await toSafeSmartAccount({
|
|
1680
|
+
client,
|
|
1681
|
+
owners: [signer],
|
|
1682
|
+
entryPoint: {
|
|
1683
|
+
address: entryPoint07Address,
|
|
1684
|
+
version: "0.7"
|
|
1685
|
+
},
|
|
1686
|
+
version: "1.4.1"
|
|
1687
|
+
});
|
|
1688
|
+
console.log("[pimlico] safe smart account created");
|
|
1689
|
+
return account;
|
|
1690
|
+
};
|
|
1684
1691
|
getSmartAccountClient = async (signer, authToken, portalAddress) => {
|
|
1692
|
+
console.log("[pimlico] signerToSmartAccount start");
|
|
1685
1693
|
const smartAccount = await signerToSmartAccount(signer);
|
|
1694
|
+
console.log("[pimlico] creating pimlico client");
|
|
1686
1695
|
const pimlicoClient = getPimlicoClient(authToken, portalAddress, smartAccount.address);
|
|
1687
|
-
|
|
1696
|
+
console.log("[pimlico] creating smart account client");
|
|
1697
|
+
const result = createSmartAccountClient({
|
|
1688
1698
|
account: smartAccount,
|
|
1689
1699
|
chain: CHAIN,
|
|
1690
1700
|
paymaster: pimlicoClient,
|
|
@@ -1702,6 +1712,8 @@ var init_pimlico_utils = __esm({
|
|
|
1702
1712
|
estimateFeesPerGas: async () => (await pimlicoClient.getUserOperationGasPrice()).fast
|
|
1703
1713
|
}
|
|
1704
1714
|
});
|
|
1715
|
+
console.log("[pimlico] smart account client created");
|
|
1716
|
+
return result;
|
|
1705
1717
|
};
|
|
1706
1718
|
getNonce = () => hexToBigInt(
|
|
1707
1719
|
toHex(toBytes(generatePrivateKey()).slice(0, 24), {
|
|
@@ -1737,13 +1749,17 @@ var init_smart_agent = __esm({
|
|
|
1737
1749
|
MAX_CALL_GAS_LIMIT = 5e5;
|
|
1738
1750
|
authOptions = { namespace: "proxy", segment: "ACCESS", scheme: "pimlico" };
|
|
1739
1751
|
async initializeAgentClient(keyMaterial) {
|
|
1752
|
+
console.log("[agent] creating account from key");
|
|
1740
1753
|
const agentAccount = privateKeyToAccount(toHex2(keyMaterial));
|
|
1754
|
+
console.log("[agent] getting auth token");
|
|
1741
1755
|
const authToken = await this.authTokenProvider.getAuthToken(STATIC_CONFIG.PROXY_SERVER_DID, this.authOptions);
|
|
1756
|
+
console.log("[agent] getting smart account client");
|
|
1742
1757
|
const smartAccountClient = await getSmartAccountClient(
|
|
1743
1758
|
agentAccount,
|
|
1744
1759
|
authToken,
|
|
1745
1760
|
this.authTokenProvider.portalAddress
|
|
1746
1761
|
);
|
|
1762
|
+
console.log("[agent] smart account client ready");
|
|
1747
1763
|
this.smartAccountAgent = smartAccountClient;
|
|
1748
1764
|
}
|
|
1749
1765
|
getSmartAccountAgent() {
|
|
@@ -1783,17 +1799,19 @@ var init_smart_agent = __esm({
|
|
|
1783
1799
|
]);
|
|
1784
1800
|
}
|
|
1785
1801
|
async sendUserOperation(request, customGasLimit) {
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
}
|
|
1802
|
+
const smartAccountAgent = this.getSmartAccountAgent();
|
|
1803
|
+
console.log("[agent] encoding call data");
|
|
1804
|
+
const callData = await this.getCallData(request);
|
|
1805
|
+
console.log("[agent] generating nonce");
|
|
1806
|
+
const nonce = getNonce();
|
|
1807
|
+
console.log("[agent] sending user operation");
|
|
1808
|
+
const hash = await smartAccountAgent.sendUserOperation({
|
|
1809
|
+
callData,
|
|
1810
|
+
callGasLimit: BigInt(customGasLimit || this.MAX_CALL_GAS_LIMIT),
|
|
1811
|
+
nonce
|
|
1812
|
+
});
|
|
1813
|
+
console.log("[agent] user operation sent");
|
|
1814
|
+
return hash;
|
|
1797
1815
|
}
|
|
1798
1816
|
async executeUserOperationRequest(request, timeout, customGasLimit) {
|
|
1799
1817
|
const userOpHash = await this.sendUserOperation(request, customGasLimit);
|
|
@@ -2362,9 +2380,9 @@ var init_aes = __esm({
|
|
|
2362
2380
|
const nonceLen = EMPTY_BLOCK.slice();
|
|
2363
2381
|
const view = createView(nonceLen);
|
|
2364
2382
|
view.setBigUint64(8, BigInt(nonce.length * 8), false);
|
|
2365
|
-
const
|
|
2366
|
-
|
|
2367
|
-
|
|
2383
|
+
const g2 = ghash.create(authKey).update(nonce).update(nonceLen);
|
|
2384
|
+
g2.digestInto(counter);
|
|
2385
|
+
g2.destroy();
|
|
2368
2386
|
}
|
|
2369
2387
|
const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
|
|
2370
2388
|
return { xk, authKey, counter, tagMask };
|
|
@@ -2720,9 +2738,29 @@ var init_file_utils = __esm({
|
|
|
2720
2738
|
}
|
|
2721
2739
|
});
|
|
2722
2740
|
|
|
2741
|
+
// src/sdk/dom-globals.ts
|
|
2742
|
+
function removeDOMGlobals() {
|
|
2743
|
+
delete g.window;
|
|
2744
|
+
delete g.document;
|
|
2745
|
+
}
|
|
2746
|
+
function restoreDOMGlobals() {
|
|
2747
|
+
if (!savedGlobals) return;
|
|
2748
|
+
Object.assign(g, savedGlobals);
|
|
2749
|
+
}
|
|
2750
|
+
var g, savedGlobals;
|
|
2751
|
+
var init_dom_globals = __esm({
|
|
2752
|
+
"src/sdk/dom-globals.ts"() {
|
|
2753
|
+
"use strict";
|
|
2754
|
+
init_esm_shims();
|
|
2755
|
+
g = globalThis;
|
|
2756
|
+
savedGlobals = null;
|
|
2757
|
+
}
|
|
2758
|
+
});
|
|
2759
|
+
|
|
2723
2760
|
// src/sdk/file-manager.ts
|
|
2724
2761
|
import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
|
|
2725
2762
|
import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
|
|
2763
|
+
import { markdownToYjs } from "@fileverse/content-processor";
|
|
2726
2764
|
var FileManager;
|
|
2727
2765
|
var init_file_manager = __esm({
|
|
2728
2766
|
"src/sdk/file-manager.ts"() {
|
|
@@ -2731,6 +2769,7 @@ var init_file_manager = __esm({
|
|
|
2731
2769
|
init_file_utils();
|
|
2732
2770
|
init_constants();
|
|
2733
2771
|
init_constants3();
|
|
2772
|
+
init_dom_globals();
|
|
2734
2773
|
init_infra();
|
|
2735
2774
|
FileManager = class {
|
|
2736
2775
|
keyStore;
|
|
@@ -2739,30 +2778,12 @@ var init_file_manager = __esm({
|
|
|
2739
2778
|
this.keyStore = keyStore;
|
|
2740
2779
|
this.agentClient = agentClient;
|
|
2741
2780
|
}
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
const saved = {
|
|
2745
|
-
window: g.window,
|
|
2746
|
-
navigator: g.navigator,
|
|
2747
|
-
document: g.document,
|
|
2748
|
-
Node: g.Node,
|
|
2749
|
-
HTMLElement: g.HTMLElement,
|
|
2750
|
-
Text: g.Text,
|
|
2751
|
-
DOMParser: g.DOMParser,
|
|
2752
|
-
Element: g.Element,
|
|
2753
|
-
DocumentFragment: g.DocumentFragment,
|
|
2754
|
-
getComputedStyle: g.getComputedStyle,
|
|
2755
|
-
MutationObserver: g.MutationObserver,
|
|
2756
|
-
Range: g.Range
|
|
2757
|
-
};
|
|
2781
|
+
convertMarkdown(content) {
|
|
2782
|
+
restoreDOMGlobals();
|
|
2758
2783
|
try {
|
|
2759
|
-
const { markdownToYjs } = await import("@fileverse/content-processor");
|
|
2760
2784
|
return markdownToYjs(content);
|
|
2761
2785
|
} finally {
|
|
2762
|
-
|
|
2763
|
-
if (value === void 0) delete g[key];
|
|
2764
|
-
else g[key] = value;
|
|
2765
|
-
}
|
|
2786
|
+
removeDOMGlobals();
|
|
2766
2787
|
}
|
|
2767
2788
|
}
|
|
2768
2789
|
createLocks(key, encryptedSecretKey, commentKey) {
|
|
@@ -2808,7 +2829,7 @@ var init_file_manager = __esm({
|
|
|
2808
2829
|
const nonce = toUint8Array3(file.linkKeyNonce);
|
|
2809
2830
|
const secretKey = toUint8Array3(file.secretKey);
|
|
2810
2831
|
console.log("Got encrypted secret key, nonce, and secret key");
|
|
2811
|
-
const yJSContent =
|
|
2832
|
+
const yJSContent = this.convertMarkdown(file.content);
|
|
2812
2833
|
console.log("Generated yjs content");
|
|
2813
2834
|
const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
|
|
2814
2835
|
console.log("Generated encrypted content file");
|
|
@@ -2868,7 +2889,7 @@ var init_file_manager = __esm({
|
|
|
2868
2889
|
const encryptedSecretKey = file.linkKey;
|
|
2869
2890
|
const nonce = toUint8Array3(file.linkKeyNonce);
|
|
2870
2891
|
const secretKey = toUint8Array3(file.secretKey);
|
|
2871
|
-
const yjsContent =
|
|
2892
|
+
const yjsContent = this.convertMarkdown(file.content);
|
|
2872
2893
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2873
2894
|
const commentKey = toUint8Array3(file.commentKey);
|
|
2874
2895
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
@@ -2917,7 +2938,7 @@ var init_file_manager = __esm({
|
|
|
2917
2938
|
const nonce = toUint8Array3(file.linkKeyNonce);
|
|
2918
2939
|
const secretKey = toUint8Array3(file.secretKey);
|
|
2919
2940
|
logger.debug(`Generating encrypted content file for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2920
|
-
const yjsContent =
|
|
2941
|
+
const yjsContent = this.convertMarkdown(file.content);
|
|
2921
2942
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2922
2943
|
const commentKey = toUint8Array3(file.commentKey);
|
|
2923
2944
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|