@fileverse/api 0.0.17 → 0.0.19
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 +4 -16
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +46 -66
- package/dist/cloudflare.js.map +1 -1
- package/dist/commands/index.js +1 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +46 -66
- package/dist/index.js.map +1 -1
- package/dist/worker.js +43 -50
- package/dist/worker.js.map +1 -1
- package/package.json +1 -2
package/dist/cloudflare.js
CHANGED
|
@@ -1438,19 +1438,29 @@ var init_pimlico_utils = __esm({
|
|
|
1438
1438
|
version: "0.7"
|
|
1439
1439
|
}
|
|
1440
1440
|
});
|
|
1441
|
-
signerToSmartAccount = async (signer) =>
|
|
1442
|
-
client
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1441
|
+
signerToSmartAccount = async (signer) => {
|
|
1442
|
+
console.log("[pimlico] creating public client");
|
|
1443
|
+
const client = getPublicClient();
|
|
1444
|
+
console.log("[pimlico] calling toSafeSmartAccount");
|
|
1445
|
+
const account = await toSafeSmartAccount({
|
|
1446
|
+
client,
|
|
1447
|
+
owners: [signer],
|
|
1448
|
+
entryPoint: {
|
|
1449
|
+
address: entryPoint07Address,
|
|
1450
|
+
version: "0.7"
|
|
1451
|
+
},
|
|
1452
|
+
version: "1.4.1"
|
|
1453
|
+
});
|
|
1454
|
+
console.log("[pimlico] safe smart account created");
|
|
1455
|
+
return account;
|
|
1456
|
+
};
|
|
1450
1457
|
getSmartAccountClient = async (signer, authToken, portalAddress) => {
|
|
1458
|
+
console.log("[pimlico] signerToSmartAccount start");
|
|
1451
1459
|
const smartAccount = await signerToSmartAccount(signer);
|
|
1460
|
+
console.log("[pimlico] creating pimlico client");
|
|
1452
1461
|
const pimlicoClient = getPimlicoClient(authToken, portalAddress, smartAccount.address);
|
|
1453
|
-
|
|
1462
|
+
console.log("[pimlico] creating smart account client");
|
|
1463
|
+
const result = createSmartAccountClient({
|
|
1454
1464
|
account: smartAccount,
|
|
1455
1465
|
chain: CHAIN,
|
|
1456
1466
|
paymaster: pimlicoClient,
|
|
@@ -1468,6 +1478,8 @@ var init_pimlico_utils = __esm({
|
|
|
1468
1478
|
estimateFeesPerGas: async () => (await pimlicoClient.getUserOperationGasPrice()).fast
|
|
1469
1479
|
}
|
|
1470
1480
|
});
|
|
1481
|
+
console.log("[pimlico] smart account client created");
|
|
1482
|
+
return result;
|
|
1471
1483
|
};
|
|
1472
1484
|
getNonce = () => hexToBigInt(
|
|
1473
1485
|
toHex(toBytes(generatePrivateKey()).slice(0, 24), {
|
|
@@ -1511,13 +1523,17 @@ var init_smart_agent = __esm({
|
|
|
1511
1523
|
MAX_CALL_GAS_LIMIT = 5e5;
|
|
1512
1524
|
authOptions = { namespace: "proxy", segment: "ACCESS", scheme: "pimlico" };
|
|
1513
1525
|
async initializeAgentClient(keyMaterial) {
|
|
1526
|
+
console.log("[agent] creating account from key");
|
|
1514
1527
|
const agentAccount = privateKeyToAccount(toHex2(keyMaterial));
|
|
1528
|
+
console.log("[agent] getting auth token");
|
|
1515
1529
|
const authToken = await this.authTokenProvider.getAuthToken(STATIC_CONFIG.PROXY_SERVER_DID, this.authOptions);
|
|
1530
|
+
console.log("[agent] getting smart account client");
|
|
1516
1531
|
const smartAccountClient = await getSmartAccountClient(
|
|
1517
1532
|
agentAccount,
|
|
1518
1533
|
authToken,
|
|
1519
1534
|
this.authTokenProvider.portalAddress
|
|
1520
1535
|
);
|
|
1536
|
+
console.log("[agent] smart account client ready");
|
|
1521
1537
|
this.smartAccountAgent = smartAccountClient;
|
|
1522
1538
|
}
|
|
1523
1539
|
getSmartAccountAgent() {
|
|
@@ -1557,17 +1573,19 @@ var init_smart_agent = __esm({
|
|
|
1557
1573
|
]);
|
|
1558
1574
|
}
|
|
1559
1575
|
async sendUserOperation(request, customGasLimit) {
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1576
|
+
const smartAccountAgent = this.getSmartAccountAgent();
|
|
1577
|
+
console.log("[agent] encoding call data");
|
|
1578
|
+
const callData = await this.getCallData(request);
|
|
1579
|
+
console.log("[agent] generating nonce");
|
|
1580
|
+
const nonce = getNonce();
|
|
1581
|
+
console.log("[agent] sending user operation");
|
|
1582
|
+
const hash2 = await smartAccountAgent.sendUserOperation({
|
|
1583
|
+
callData,
|
|
1584
|
+
callGasLimit: BigInt(customGasLimit || this.MAX_CALL_GAS_LIMIT),
|
|
1585
|
+
nonce
|
|
1586
|
+
});
|
|
1587
|
+
console.log("[agent] user operation sent");
|
|
1588
|
+
return hash2;
|
|
1571
1589
|
}
|
|
1572
1590
|
async executeUserOperationRequest(request, timeout, customGasLimit) {
|
|
1573
1591
|
const userOpHash = await this.sendUserOperation(request, customGasLimit);
|
|
@@ -2497,6 +2515,7 @@ var init_file_utils = __esm({
|
|
|
2497
2515
|
// src/sdk/file-manager.ts
|
|
2498
2516
|
import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
|
|
2499
2517
|
import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
|
|
2518
|
+
import { markdownToYjs } from "@fileverse/content-processor";
|
|
2500
2519
|
var FileManager;
|
|
2501
2520
|
var init_file_manager = __esm({
|
|
2502
2521
|
"src/sdk/file-manager.ts"() {
|
|
@@ -2513,32 +2532,6 @@ var init_file_manager = __esm({
|
|
|
2513
2532
|
this.keyStore = keyStore;
|
|
2514
2533
|
this.agentClient = agentClient;
|
|
2515
2534
|
}
|
|
2516
|
-
async convertMarkdown(content) {
|
|
2517
|
-
const g = globalThis;
|
|
2518
|
-
const saved = {
|
|
2519
|
-
window: g.window,
|
|
2520
|
-
navigator: g.navigator,
|
|
2521
|
-
document: g.document,
|
|
2522
|
-
Node: g.Node,
|
|
2523
|
-
HTMLElement: g.HTMLElement,
|
|
2524
|
-
Text: g.Text,
|
|
2525
|
-
DOMParser: g.DOMParser,
|
|
2526
|
-
Element: g.Element,
|
|
2527
|
-
DocumentFragment: g.DocumentFragment,
|
|
2528
|
-
getComputedStyle: g.getComputedStyle,
|
|
2529
|
-
MutationObserver: g.MutationObserver,
|
|
2530
|
-
Range: g.Range
|
|
2531
|
-
};
|
|
2532
|
-
try {
|
|
2533
|
-
const { markdownToYjs } = await import("@fileverse/content-processor");
|
|
2534
|
-
return markdownToYjs(content);
|
|
2535
|
-
} finally {
|
|
2536
|
-
for (const [key, value] of Object.entries(saved)) {
|
|
2537
|
-
if (value === void 0) delete g[key];
|
|
2538
|
-
else g[key] = value;
|
|
2539
|
-
}
|
|
2540
|
-
}
|
|
2541
|
-
}
|
|
2542
2535
|
createLocks(key, encryptedSecretKey, commentKey) {
|
|
2543
2536
|
const appLock = {
|
|
2544
2537
|
lockedFileKey: this.keyStore.encryptData(toUint8Array3(key)),
|
|
@@ -2582,7 +2575,7 @@ var init_file_manager = __esm({
|
|
|
2582
2575
|
const nonce = toUint8Array3(file2.linkKeyNonce);
|
|
2583
2576
|
const secretKey = toUint8Array3(file2.secretKey);
|
|
2584
2577
|
console.log("Got encrypted secret key, nonce, and secret key");
|
|
2585
|
-
const yJSContent =
|
|
2578
|
+
const yJSContent = markdownToYjs(file2.content);
|
|
2586
2579
|
console.log("Generated yjs content");
|
|
2587
2580
|
const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
|
|
2588
2581
|
console.log("Generated encrypted content file");
|
|
@@ -2642,7 +2635,7 @@ var init_file_manager = __esm({
|
|
|
2642
2635
|
const encryptedSecretKey = file2.linkKey;
|
|
2643
2636
|
const nonce = toUint8Array3(file2.linkKeyNonce);
|
|
2644
2637
|
const secretKey = toUint8Array3(file2.secretKey);
|
|
2645
|
-
const yjsContent =
|
|
2638
|
+
const yjsContent = markdownToYjs(file2.content);
|
|
2646
2639
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2647
2640
|
const commentKey = toUint8Array3(file2.commentKey);
|
|
2648
2641
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
@@ -2691,7 +2684,7 @@ var init_file_manager = __esm({
|
|
|
2691
2684
|
const nonce = toUint8Array3(file2.linkKeyNonce);
|
|
2692
2685
|
const secretKey = toUint8Array3(file2.secretKey);
|
|
2693
2686
|
logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2694
|
-
const yjsContent =
|
|
2687
|
+
const yjsContent = markdownToYjs(file2.content);
|
|
2695
2688
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2696
2689
|
const commentKey = toUint8Array3(file2.commentKey);
|
|
2697
2690
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
@@ -4090,30 +4083,17 @@ init_esm_shims();
|
|
|
4090
4083
|
// src/cli/fetch-api-key.ts
|
|
4091
4084
|
init_esm_shims();
|
|
4092
4085
|
init_constants();
|
|
4093
|
-
import axios from "axios";
|
|
4094
4086
|
import { toUint8Array as toUint8Array6 } from "js-base64";
|
|
4095
4087
|
import { sha256 } from "viem";
|
|
4096
4088
|
var fetchApiKeyData = async (apiKey) => {
|
|
4097
4089
|
try {
|
|
4098
4090
|
const keyHash = sha256(toUint8Array6(apiKey));
|
|
4099
4091
|
const fullUrl = BASE_CONFIG.API_URL + `api-access/${keyHash}`;
|
|
4100
|
-
const response = await
|
|
4101
|
-
const { encryptedKeyMaterial, encryptedAppMaterial, id } = response.
|
|
4092
|
+
const response = await fetch(fullUrl);
|
|
4093
|
+
const { encryptedKeyMaterial, encryptedAppMaterial, id } = await response.json();
|
|
4102
4094
|
return { encryptedKeyMaterial, encryptedAppMaterial, id };
|
|
4103
4095
|
} catch (error48) {
|
|
4104
|
-
|
|
4105
|
-
if (error48.response?.status === 401) {
|
|
4106
|
-
throw new Error("Invalid API key");
|
|
4107
|
-
}
|
|
4108
|
-
if (error48.response?.status === 404) {
|
|
4109
|
-
throw new Error("API key not found");
|
|
4110
|
-
}
|
|
4111
|
-
if (error48.code === "ECONNREFUSED") {
|
|
4112
|
-
throw new Error(`Cannot connect to server at ${BASE_CONFIG.API_URL}`);
|
|
4113
|
-
}
|
|
4114
|
-
throw new Error(`Server error: ${error48.response?.data?.message || error48.message}`);
|
|
4115
|
-
}
|
|
4116
|
-
throw error48;
|
|
4096
|
+
throw new Error(`Server error: ${error48.message}`);
|
|
4117
4097
|
}
|
|
4118
4098
|
};
|
|
4119
4099
|
|