@fileverse/api 0.0.20 → 0.0.21

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,29 +1438,19 @@ var init_pimlico_utils = __esm({
1438
1438
  version: "0.7"
1439
1439
  }
1440
1440
  });
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
- };
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
+ });
1457
1450
  getSmartAccountClient = async (signer, authToken, portalAddress) => {
1458
- console.log("[pimlico] signerToSmartAccount start");
1459
1451
  const smartAccount = await signerToSmartAccount(signer);
1460
- console.log("[pimlico] creating pimlico client");
1461
1452
  const pimlicoClient = getPimlicoClient(authToken, portalAddress, smartAccount.address);
1462
- console.log("[pimlico] creating smart account client");
1463
- const result = createSmartAccountClient({
1453
+ return createSmartAccountClient({
1464
1454
  account: smartAccount,
1465
1455
  chain: CHAIN,
1466
1456
  paymaster: pimlicoClient,
@@ -1478,8 +1468,6 @@ var init_pimlico_utils = __esm({
1478
1468
  estimateFeesPerGas: async () => (await pimlicoClient.getUserOperationGasPrice()).fast
1479
1469
  }
1480
1470
  });
1481
- console.log("[pimlico] smart account client created");
1482
- return result;
1483
1471
  };
1484
1472
  getNonce = () => hexToBigInt(
1485
1473
  toHex(toBytes(generatePrivateKey()).slice(0, 24), {
@@ -1523,17 +1511,13 @@ var init_smart_agent = __esm({
1523
1511
  MAX_CALL_GAS_LIMIT = 5e5;
1524
1512
  authOptions = { namespace: "proxy", segment: "ACCESS", scheme: "pimlico" };
1525
1513
  async initializeAgentClient(keyMaterial) {
1526
- console.log("[agent] creating account from key");
1527
1514
  const agentAccount = privateKeyToAccount(toHex2(keyMaterial));
1528
- console.log("[agent] getting auth token");
1529
1515
  const authToken = await this.authTokenProvider.getAuthToken(STATIC_CONFIG.PROXY_SERVER_DID, this.authOptions);
1530
- console.log("[agent] getting smart account client");
1531
1516
  const smartAccountClient = await getSmartAccountClient(
1532
1517
  agentAccount,
1533
1518
  authToken,
1534
1519
  this.authTokenProvider.portalAddress
1535
1520
  );
1536
- console.log("[agent] smart account client ready");
1537
1521
  this.smartAccountAgent = smartAccountClient;
1538
1522
  }
1539
1523
  getSmartAccountAgent() {
@@ -1573,19 +1557,17 @@ var init_smart_agent = __esm({
1573
1557
  ]);
1574
1558
  }
1575
1559
  async sendUserOperation(request, customGasLimit) {
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;
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
+ }
1589
1571
  }
1590
1572
  async executeUserOperationRequest(request, timeout, customGasLimit) {
1591
1573
  const userOpHash = await this.sendUserOperation(request, customGasLimit);
@@ -3038,38 +3020,44 @@ var init_eventProcessor = __esm({
3038
3020
  if (!file2) throw new Error(`File ${fileId} not found`);
3039
3021
  if (file2.isDeleted === 1) {
3040
3022
  logger.info(`File ${fileId} is deleted, skipping create submit`);
3041
- return null;
3023
+ return;
3042
3024
  }
3043
3025
  console.log("Submitting new file op");
3044
3026
  const result = await handleNewFileOp(fileId);
3045
3027
  console.log("New file op submitted");
3028
+ await EventsModel.setEventPendingOp(event._id, result.userOpHash, {
3029
+ metadata: result.metadata
3030
+ });
3046
3031
  logger.info(`File ${file2.ddocId} create op submitted (hash: ${result.userOpHash})`);
3047
- return { userOpHash: result.userOpHash, pendingPayload: { metadata: result.metadata } };
3032
+ break;
3048
3033
  }
3049
3034
  case "update": {
3050
3035
  const file2 = await FilesModel.findByIdExcludingDeleted(fileId);
3051
- if (!file2) return null;
3052
- if (file2.localVersion <= file2.onchainVersion) return null;
3036
+ if (!file2) return;
3037
+ if (file2.localVersion <= file2.onchainVersion) return;
3053
3038
  const result = await submitUpdateFileOp(fileId);
3039
+ await EventsModel.setEventPendingOp(event._id, result.userOpHash, {
3040
+ metadata: result.metadata,
3041
+ localVersion: file2.localVersion
3042
+ });
3054
3043
  logger.info(`File ${file2.ddocId} update op submitted (hash: ${result.userOpHash})`);
3055
- return {
3056
- userOpHash: result.userOpHash,
3057
- pendingPayload: { metadata: result.metadata, localVersion: file2.localVersion }
3058
- };
3044
+ break;
3059
3045
  }
3060
3046
  case "delete": {
3061
3047
  const file2 = await FilesModel.findByIdIncludingDeleted(fileId);
3062
- if (!file2) return null;
3048
+ if (!file2) return;
3063
3049
  if (file2.isDeleted === 1 && file2.syncStatus === "synced") {
3064
3050
  logger.info(`File ${fileId} deletion already synced, skipping`);
3065
- return null;
3051
+ return;
3066
3052
  }
3067
3053
  if (file2.onChainFileId === null || file2.onChainFileId === void 0) {
3068
- return { noOp: true, fileId, portalAddress: file2.portalAddress };
3054
+ await FilesModel.update(fileId, { syncStatus: "synced", isDeleted: 1 }, file2.portalAddress);
3055
+ return;
3069
3056
  }
3070
3057
  const result = await submitDeleteFileOp(fileId);
3058
+ await EventsModel.setEventPendingOp(event._id, result.userOpHash, {});
3071
3059
  logger.info(`File ${file2.ddocId} delete op submitted (hash: ${result.userOpHash})`);
3072
- return { userOpHash: result.userOpHash, pendingPayload: {} };
3060
+ break;
3073
3061
  }
3074
3062
  default:
3075
3063
  throw new Error(`Unknown event type: ${type}`);
@@ -3825,12 +3813,7 @@ import hkdf from "futoin-hkdf";
3825
3813
  import tweetnacl2 from "tweetnacl";
3826
3814
  import { fromUint8Array as fromUint8Array4, toUint8Array as toUint8Array5 } from "js-base64";
3827
3815
  var deriveKeyFromAg2Hash = async (pass, salt) => {
3828
- const key = await getArgon2idHash(pass, salt, void 0, {
3829
- t: 2,
3830
- m: 4096,
3831
- p: 8,
3832
- dkLen: 32
3833
- });
3816
+ const key = await getArgon2idHash(pass, salt);
3834
3817
  return hkdf(Buffer.from(key), tweetnacl2.secretbox.keyLength, {
3835
3818
  info: Buffer.from("encryptionKey")
3836
3819
  });