@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/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);
@@ -2890,6 +2908,7 @@ var init_file_utils = __esm({
2890
2908
  // src/sdk/file-manager.ts
2891
2909
  import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
2892
2910
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
2911
+ import { markdownToYjs } from "@fileverse/content-processor";
2893
2912
  var FileManager;
2894
2913
  var init_file_manager = __esm({
2895
2914
  "src/sdk/file-manager.ts"() {
@@ -2906,32 +2925,6 @@ var init_file_manager = __esm({
2906
2925
  this.keyStore = keyStore;
2907
2926
  this.agentClient = agentClient;
2908
2927
  }
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
- };
2925
- try {
2926
- const { markdownToYjs } = await import("@fileverse/content-processor");
2927
- return markdownToYjs(content);
2928
- } finally {
2929
- for (const [key, value] of Object.entries(saved)) {
2930
- if (value === void 0) delete g[key];
2931
- else g[key] = value;
2932
- }
2933
- }
2934
- }
2935
2928
  createLocks(key, encryptedSecretKey, commentKey) {
2936
2929
  const appLock = {
2937
2930
  lockedFileKey: this.keyStore.encryptData(toUint8Array3(key)),
@@ -2975,7 +2968,7 @@ var init_file_manager = __esm({
2975
2968
  const nonce = toUint8Array3(file2.linkKeyNonce);
2976
2969
  const secretKey = toUint8Array3(file2.secretKey);
2977
2970
  console.log("Got encrypted secret key, nonce, and secret key");
2978
- const yJSContent = await this.convertMarkdown(file2.content);
2971
+ const yJSContent = markdownToYjs(file2.content);
2979
2972
  console.log("Generated yjs content");
2980
2973
  const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
2981
2974
  console.log("Generated encrypted content file");
@@ -3035,7 +3028,7 @@ var init_file_manager = __esm({
3035
3028
  const encryptedSecretKey = file2.linkKey;
3036
3029
  const nonce = toUint8Array3(file2.linkKeyNonce);
3037
3030
  const secretKey = toUint8Array3(file2.secretKey);
3038
- const yjsContent = await this.convertMarkdown(file2.content);
3031
+ const yjsContent = markdownToYjs(file2.content);
3039
3032
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
3040
3033
  const commentKey = toUint8Array3(file2.commentKey);
3041
3034
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -3084,7 +3077,7 @@ var init_file_manager = __esm({
3084
3077
  const nonce = toUint8Array3(file2.linkKeyNonce);
3085
3078
  const secretKey = toUint8Array3(file2.secretKey);
3086
3079
  logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
3087
- const yjsContent = await this.convertMarkdown(file2.content);
3080
+ const yjsContent = markdownToYjs(file2.content);
3088
3081
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
3089
3082
  const commentKey = toUint8Array3(file2.commentKey);
3090
3083
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
@@ -3844,30 +3837,17 @@ init_esm_shims();
3844
3837
  // src/cli/fetch-api-key.ts
3845
3838
  init_esm_shims();
3846
3839
  init_constants();
3847
- import axios from "axios";
3848
3840
  import { toUint8Array as toUint8Array5 } from "js-base64";
3849
3841
  import { sha256 } from "viem";
3850
3842
  var fetchApiKeyData = async (apiKey) => {
3851
3843
  try {
3852
3844
  const keyHash = sha256(toUint8Array5(apiKey));
3853
3845
  const fullUrl = BASE_CONFIG.API_URL + `api-access/${keyHash}`;
3854
- const response = await axios.get(fullUrl);
3855
- const { encryptedKeyMaterial, encryptedAppMaterial, id } = response.data;
3846
+ const response = await fetch(fullUrl);
3847
+ const { encryptedKeyMaterial, encryptedAppMaterial, id } = await response.json();
3856
3848
  return { encryptedKeyMaterial, encryptedAppMaterial, id };
3857
3849
  } catch (error48) {
3858
- if (axios.isAxiosError(error48)) {
3859
- if (error48.response?.status === 401) {
3860
- throw new Error("Invalid API key");
3861
- }
3862
- if (error48.response?.status === 404) {
3863
- throw new Error("API key not found");
3864
- }
3865
- if (error48.code === "ECONNREFUSED") {
3866
- throw new Error(`Cannot connect to server at ${BASE_CONFIG.API_URL}`);
3867
- }
3868
- throw new Error(`Server error: ${error48.response?.data?.message || error48.message}`);
3869
- }
3870
- throw error48;
3850
+ throw new Error(`Server error: ${error48.message}`);
3871
3851
  }
3872
3852
  };
3873
3853