@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.
@@ -1438,19 +1438,29 @@ var init_pimlico_utils = __esm({
1438
1438
  version: "0.7"
1439
1439
  }
1440
1440
  });
1441
- signerToSmartAccount = async (signer) => await toSafeSmartAccount({
1442
- client: getPublicClient(),
1443
- owners: [signer],
1444
- entryPoint: {
1445
- address: entryPoint07Address,
1446
- version: "0.7"
1447
- },
1448
- version: "1.4.1"
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
- return createSmartAccountClient({
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
- try {
1561
- const smartAccountAgent = this.getSmartAccountAgent();
1562
- const callData = await this.getCallData(request);
1563
- return await smartAccountAgent.sendUserOperation({
1564
- callData,
1565
- callGasLimit: BigInt(customGasLimit || this.MAX_CALL_GAS_LIMIT),
1566
- nonce: getNonce()
1567
- });
1568
- } catch (error48) {
1569
- throw error48;
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);
@@ -2136,9 +2154,9 @@ var init_aes = __esm({
2136
2154
  const nonceLen = EMPTY_BLOCK.slice();
2137
2155
  const view = createView(nonceLen);
2138
2156
  view.setBigUint64(8, BigInt(nonce.length * 8), false);
2139
- const g = ghash.create(authKey).update(nonce).update(nonceLen);
2140
- g.digestInto(counter);
2141
- g.destroy();
2157
+ const g2 = ghash.create(authKey).update(nonce).update(nonceLen);
2158
+ g2.digestInto(counter);
2159
+ g2.destroy();
2142
2160
  }
2143
2161
  const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
2144
2162
  return { xk, authKey, counter, tagMask };
@@ -2494,9 +2512,50 @@ var init_file_utils = __esm({
2494
2512
  }
2495
2513
  });
2496
2514
 
2515
+ // src/sdk/dom-globals.ts
2516
+ function captureDOMGlobals() {
2517
+ if (savedGlobals) return;
2518
+ savedGlobals = {};
2519
+ for (const key of DOM_KEYS) {
2520
+ savedGlobals[key] = g[key];
2521
+ }
2522
+ }
2523
+ function removeDOMGlobals() {
2524
+ delete g.window;
2525
+ delete g.document;
2526
+ }
2527
+ function restoreDOMGlobals() {
2528
+ if (!savedGlobals) return;
2529
+ Object.assign(g, savedGlobals);
2530
+ }
2531
+ var DOM_KEYS, g, savedGlobals;
2532
+ var init_dom_globals = __esm({
2533
+ "src/sdk/dom-globals.ts"() {
2534
+ "use strict";
2535
+ init_esm_shims();
2536
+ DOM_KEYS = [
2537
+ "window",
2538
+ "document",
2539
+ "navigator",
2540
+ "Node",
2541
+ "HTMLElement",
2542
+ "Text",
2543
+ "DOMParser",
2544
+ "Element",
2545
+ "DocumentFragment",
2546
+ "getComputedStyle",
2547
+ "MutationObserver",
2548
+ "Range"
2549
+ ];
2550
+ g = globalThis;
2551
+ savedGlobals = null;
2552
+ }
2553
+ });
2554
+
2497
2555
  // src/sdk/file-manager.ts
2498
2556
  import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
2499
2557
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
2558
+ import { markdownToYjs } from "@fileverse/content-processor";
2500
2559
  var FileManager;
2501
2560
  var init_file_manager = __esm({
2502
2561
  "src/sdk/file-manager.ts"() {
@@ -2505,6 +2564,7 @@ var init_file_manager = __esm({
2505
2564
  init_file_utils();
2506
2565
  init_constants();
2507
2566
  init_constants2();
2567
+ init_dom_globals();
2508
2568
  init_infra();
2509
2569
  FileManager = class {
2510
2570
  keyStore;
@@ -2513,30 +2573,12 @@ var init_file_manager = __esm({
2513
2573
  this.keyStore = keyStore;
2514
2574
  this.agentClient = agentClient;
2515
2575
  }
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
- };
2576
+ convertMarkdown(content) {
2577
+ restoreDOMGlobals();
2532
2578
  try {
2533
- const { markdownToYjs } = await import("@fileverse/content-processor");
2534
2579
  return markdownToYjs(content);
2535
2580
  } finally {
2536
- for (const [key, value] of Object.entries(saved)) {
2537
- if (value === void 0) delete g[key];
2538
- else g[key] = value;
2539
- }
2581
+ removeDOMGlobals();
2540
2582
  }
2541
2583
  }
2542
2584
  createLocks(key, encryptedSecretKey, commentKey) {
@@ -2582,7 +2624,7 @@ var init_file_manager = __esm({
2582
2624
  const nonce = toUint8Array3(file2.linkKeyNonce);
2583
2625
  const secretKey = toUint8Array3(file2.secretKey);
2584
2626
  console.log("Got encrypted secret key, nonce, and secret key");
2585
- const yJSContent = await this.convertMarkdown(file2.content);
2627
+ const yJSContent = this.convertMarkdown(file2.content);
2586
2628
  console.log("Generated yjs content");
2587
2629
  const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
2588
2630
  console.log("Generated encrypted content file");
@@ -2642,7 +2684,7 @@ var init_file_manager = __esm({
2642
2684
  const encryptedSecretKey = file2.linkKey;
2643
2685
  const nonce = toUint8Array3(file2.linkKeyNonce);
2644
2686
  const secretKey = toUint8Array3(file2.secretKey);
2645
- const yjsContent = await this.convertMarkdown(file2.content);
2687
+ const yjsContent = this.convertMarkdown(file2.content);
2646
2688
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2647
2689
  const commentKey = toUint8Array3(file2.commentKey);
2648
2690
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -2691,7 +2733,7 @@ var init_file_manager = __esm({
2691
2733
  const nonce = toUint8Array3(file2.linkKeyNonce);
2692
2734
  const secretKey = toUint8Array3(file2.secretKey);
2693
2735
  logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
2694
- const yjsContent = await this.convertMarkdown(file2.content);
2736
+ const yjsContent = this.convertMarkdown(file2.content);
2695
2737
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2696
2738
  const commentKey = toUint8Array3(file2.commentKey);
2697
2739
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -18257,6 +18299,11 @@ function createMcpServer(config3) {
18257
18299
  registerTools(server, client);
18258
18300
  return server;
18259
18301
  }
18302
+
18303
+ // src/cloudflare.ts
18304
+ init_dom_globals();
18305
+ captureDOMGlobals();
18306
+ removeDOMGlobals();
18260
18307
  export {
18261
18308
  ApiKeysModel,
18262
18309
  EventsModel,