@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/index.js CHANGED
@@ -1839,19 +1839,29 @@ var init_pimlico_utils = __esm({
1839
1839
  version: "0.7"
1840
1840
  }
1841
1841
  });
1842
- signerToSmartAccount = async (signer) => await toSafeSmartAccount({
1843
- client: getPublicClient(),
1844
- owners: [signer],
1845
- entryPoint: {
1846
- address: entryPoint07Address,
1847
- version: "0.7"
1848
- },
1849
- version: "1.4.1"
1850
- });
1842
+ signerToSmartAccount = async (signer) => {
1843
+ console.log("[pimlico] creating public client");
1844
+ const client = getPublicClient();
1845
+ console.log("[pimlico] calling toSafeSmartAccount");
1846
+ const account = await toSafeSmartAccount({
1847
+ client,
1848
+ owners: [signer],
1849
+ entryPoint: {
1850
+ address: entryPoint07Address,
1851
+ version: "0.7"
1852
+ },
1853
+ version: "1.4.1"
1854
+ });
1855
+ console.log("[pimlico] safe smart account created");
1856
+ return account;
1857
+ };
1851
1858
  getSmartAccountClient = async (signer, authToken, portalAddress) => {
1859
+ console.log("[pimlico] signerToSmartAccount start");
1852
1860
  const smartAccount = await signerToSmartAccount(signer);
1861
+ console.log("[pimlico] creating pimlico client");
1853
1862
  const pimlicoClient = getPimlicoClient(authToken, portalAddress, smartAccount.address);
1854
- return createSmartAccountClient({
1863
+ console.log("[pimlico] creating smart account client");
1864
+ const result = createSmartAccountClient({
1855
1865
  account: smartAccount,
1856
1866
  chain: CHAIN,
1857
1867
  paymaster: pimlicoClient,
@@ -1869,6 +1879,8 @@ var init_pimlico_utils = __esm({
1869
1879
  estimateFeesPerGas: async () => (await pimlicoClient.getUserOperationGasPrice()).fast
1870
1880
  }
1871
1881
  });
1882
+ console.log("[pimlico] smart account client created");
1883
+ return result;
1872
1884
  };
1873
1885
  getNonce = () => hexToBigInt(
1874
1886
  toHex(toBytes(generatePrivateKey()).slice(0, 24), {
@@ -1904,13 +1916,17 @@ var init_smart_agent = __esm({
1904
1916
  MAX_CALL_GAS_LIMIT = 5e5;
1905
1917
  authOptions = { namespace: "proxy", segment: "ACCESS", scheme: "pimlico" };
1906
1918
  async initializeAgentClient(keyMaterial) {
1919
+ console.log("[agent] creating account from key");
1907
1920
  const agentAccount = privateKeyToAccount(toHex2(keyMaterial));
1921
+ console.log("[agent] getting auth token");
1908
1922
  const authToken = await this.authTokenProvider.getAuthToken(STATIC_CONFIG.PROXY_SERVER_DID, this.authOptions);
1923
+ console.log("[agent] getting smart account client");
1909
1924
  const smartAccountClient = await getSmartAccountClient(
1910
1925
  agentAccount,
1911
1926
  authToken,
1912
1927
  this.authTokenProvider.portalAddress
1913
1928
  );
1929
+ console.log("[agent] smart account client ready");
1914
1930
  this.smartAccountAgent = smartAccountClient;
1915
1931
  }
1916
1932
  getSmartAccountAgent() {
@@ -1950,17 +1966,19 @@ var init_smart_agent = __esm({
1950
1966
  ]);
1951
1967
  }
1952
1968
  async sendUserOperation(request, customGasLimit) {
1953
- try {
1954
- const smartAccountAgent = this.getSmartAccountAgent();
1955
- const callData = await this.getCallData(request);
1956
- return await smartAccountAgent.sendUserOperation({
1957
- callData,
1958
- callGasLimit: BigInt(customGasLimit || this.MAX_CALL_GAS_LIMIT),
1959
- nonce: getNonce()
1960
- });
1961
- } catch (error48) {
1962
- throw error48;
1963
- }
1969
+ const smartAccountAgent = this.getSmartAccountAgent();
1970
+ console.log("[agent] encoding call data");
1971
+ const callData = await this.getCallData(request);
1972
+ console.log("[agent] generating nonce");
1973
+ const nonce = getNonce();
1974
+ console.log("[agent] sending user operation");
1975
+ const hash2 = await smartAccountAgent.sendUserOperation({
1976
+ callData,
1977
+ callGasLimit: BigInt(customGasLimit || this.MAX_CALL_GAS_LIMIT),
1978
+ nonce
1979
+ });
1980
+ console.log("[agent] user operation sent");
1981
+ return hash2;
1964
1982
  }
1965
1983
  async executeUserOperationRequest(request, timeout, customGasLimit) {
1966
1984
  const userOpHash = await this.sendUserOperation(request, customGasLimit);
@@ -2529,9 +2547,9 @@ var init_aes = __esm({
2529
2547
  const nonceLen = EMPTY_BLOCK.slice();
2530
2548
  const view = createView(nonceLen);
2531
2549
  view.setBigUint64(8, BigInt(nonce.length * 8), false);
2532
- const g = ghash.create(authKey).update(nonce).update(nonceLen);
2533
- g.digestInto(counter);
2534
- g.destroy();
2550
+ const g2 = ghash.create(authKey).update(nonce).update(nonceLen);
2551
+ g2.digestInto(counter);
2552
+ g2.destroy();
2535
2553
  }
2536
2554
  const tagMask = ctr32(xk, false, counter, EMPTY_BLOCK);
2537
2555
  return { xk, authKey, counter, tagMask };
@@ -2887,9 +2905,29 @@ var init_file_utils = __esm({
2887
2905
  }
2888
2906
  });
2889
2907
 
2908
+ // src/sdk/dom-globals.ts
2909
+ function removeDOMGlobals() {
2910
+ delete g.window;
2911
+ delete g.document;
2912
+ }
2913
+ function restoreDOMGlobals() {
2914
+ if (!savedGlobals) return;
2915
+ Object.assign(g, savedGlobals);
2916
+ }
2917
+ var g, savedGlobals;
2918
+ var init_dom_globals = __esm({
2919
+ "src/sdk/dom-globals.ts"() {
2920
+ "use strict";
2921
+ init_esm_shims();
2922
+ g = globalThis;
2923
+ savedGlobals = null;
2924
+ }
2925
+ });
2926
+
2890
2927
  // src/sdk/file-manager.ts
2891
2928
  import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
2892
2929
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
2930
+ import { markdownToYjs } from "@fileverse/content-processor";
2893
2931
  var FileManager;
2894
2932
  var init_file_manager = __esm({
2895
2933
  "src/sdk/file-manager.ts"() {
@@ -2898,6 +2936,7 @@ var init_file_manager = __esm({
2898
2936
  init_file_utils();
2899
2937
  init_constants();
2900
2938
  init_constants3();
2939
+ init_dom_globals();
2901
2940
  init_infra();
2902
2941
  FileManager = class {
2903
2942
  keyStore;
@@ -2906,30 +2945,12 @@ var init_file_manager = __esm({
2906
2945
  this.keyStore = keyStore;
2907
2946
  this.agentClient = agentClient;
2908
2947
  }
2909
- async convertMarkdown(content) {
2910
- const g = globalThis;
2911
- const saved = {
2912
- window: g.window,
2913
- navigator: g.navigator,
2914
- document: g.document,
2915
- Node: g.Node,
2916
- HTMLElement: g.HTMLElement,
2917
- Text: g.Text,
2918
- DOMParser: g.DOMParser,
2919
- Element: g.Element,
2920
- DocumentFragment: g.DocumentFragment,
2921
- getComputedStyle: g.getComputedStyle,
2922
- MutationObserver: g.MutationObserver,
2923
- Range: g.Range
2924
- };
2948
+ convertMarkdown(content) {
2949
+ restoreDOMGlobals();
2925
2950
  try {
2926
- const { markdownToYjs } = await import("@fileverse/content-processor");
2927
2951
  return markdownToYjs(content);
2928
2952
  } finally {
2929
- for (const [key, value] of Object.entries(saved)) {
2930
- if (value === void 0) delete g[key];
2931
- else g[key] = value;
2932
- }
2953
+ removeDOMGlobals();
2933
2954
  }
2934
2955
  }
2935
2956
  createLocks(key, encryptedSecretKey, commentKey) {
@@ -2975,7 +2996,7 @@ var init_file_manager = __esm({
2975
2996
  const nonce = toUint8Array3(file2.linkKeyNonce);
2976
2997
  const secretKey = toUint8Array3(file2.secretKey);
2977
2998
  console.log("Got encrypted secret key, nonce, and secret key");
2978
- const yJSContent = await this.convertMarkdown(file2.content);
2999
+ const yJSContent = this.convertMarkdown(file2.content);
2979
3000
  console.log("Generated yjs content");
2980
3001
  const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
2981
3002
  console.log("Generated encrypted content file");
@@ -3035,7 +3056,7 @@ var init_file_manager = __esm({
3035
3056
  const encryptedSecretKey = file2.linkKey;
3036
3057
  const nonce = toUint8Array3(file2.linkKeyNonce);
3037
3058
  const secretKey = toUint8Array3(file2.secretKey);
3038
- const yjsContent = await this.convertMarkdown(file2.content);
3059
+ const yjsContent = this.convertMarkdown(file2.content);
3039
3060
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
3040
3061
  const commentKey = toUint8Array3(file2.commentKey);
3041
3062
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -3084,7 +3105,7 @@ var init_file_manager = __esm({
3084
3105
  const nonce = toUint8Array3(file2.linkKeyNonce);
3085
3106
  const secretKey = toUint8Array3(file2.secretKey);
3086
3107
  logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
3087
- const yjsContent = await this.convertMarkdown(file2.content);
3108
+ const yjsContent = this.convertMarkdown(file2.content);
3088
3109
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
3089
3110
  const commentKey = toUint8Array3(file2.commentKey);
3090
3111
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);