@fileverse/api 0.0.12 → 0.0.14

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.
@@ -972,13 +972,114 @@ var init_key_store = __esm({
972
972
  }
973
973
  });
974
974
 
975
+ // src/sdk/ucan.ts
976
+ import { sign, extractPublicKeyFromSecretKey } from "@stablelib/ed25519";
977
+ import { toUint8Array } from "js-base64";
978
+ function base58btcEncode(bytes) {
979
+ const digits = [0];
980
+ for (const byte of bytes) {
981
+ let carry = byte;
982
+ for (let j = 0; j < digits.length; j++) {
983
+ carry += digits[j] << 8;
984
+ digits[j] = carry % 58;
985
+ carry = carry / 58 | 0;
986
+ }
987
+ while (carry > 0) {
988
+ digits.push(carry % 58);
989
+ carry = carry / 58 | 0;
990
+ }
991
+ }
992
+ let result = "";
993
+ for (let i = 0; i < bytes.length && bytes[i] === 0; i++) {
994
+ result += BASE58_ALPHABET[0];
995
+ }
996
+ for (let i = digits.length - 1; i >= 0; i--) {
997
+ result += BASE58_ALPHABET[digits[i]];
998
+ }
999
+ return result;
1000
+ }
1001
+ function base64urlEncode(data) {
1002
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
1003
+ let binary = "";
1004
+ for (let i = 0; i < bytes.length; i++) {
1005
+ binary += String.fromCharCode(bytes[i]);
1006
+ }
1007
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
1008
+ }
1009
+ async function buildAndEncode(params) {
1010
+ const {
1011
+ issuer,
1012
+ audience,
1013
+ capabilities = [],
1014
+ lifetimeInSeconds = 30,
1015
+ expiration,
1016
+ notBefore,
1017
+ facts,
1018
+ proofs = []
1019
+ } = params;
1020
+ const currentTime = Math.floor(Date.now() / 1e3);
1021
+ const exp = expiration ?? currentTime + lifetimeInSeconds;
1022
+ const header = { alg: issuer.jwtAlg, typ: "JWT", ucv: "0.8.1" };
1023
+ const att = capabilities.map((cap) => ({
1024
+ with: `${cap.with.scheme}:${cap.with.hierPart}`,
1025
+ can: [cap.can.namespace, ...cap.can.segments].join("/")
1026
+ }));
1027
+ const payload = {
1028
+ iss: issuer.did(),
1029
+ aud: audience,
1030
+ exp,
1031
+ att,
1032
+ prf: proofs
1033
+ };
1034
+ if (notBefore !== void 0) payload.nbf = notBefore;
1035
+ if (facts !== void 0) payload.fct = facts;
1036
+ const encodedHeader = base64urlEncode(JSON.stringify(header));
1037
+ const encodedPayload = base64urlEncode(JSON.stringify(payload));
1038
+ const signedData = `${encodedHeader}.${encodedPayload}`;
1039
+ const sig = await issuer.sign(new TextEncoder().encode(signedData));
1040
+ const signature = base64urlEncode(sig);
1041
+ return `${signedData}.${signature}`;
1042
+ }
1043
+ var BASE58_ALPHABET, EDWARDS_DID_PREFIX, EdKeypair;
1044
+ var init_ucan = __esm({
1045
+ "src/sdk/ucan.ts"() {
1046
+ "use strict";
1047
+ init_esm_shims();
1048
+ BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1049
+ EDWARDS_DID_PREFIX = new Uint8Array([237, 1]);
1050
+ EdKeypair = class _EdKeypair {
1051
+ jwtAlg = "EdDSA";
1052
+ secretKey;
1053
+ publicKey;
1054
+ constructor(secretKey, publicKey) {
1055
+ this.secretKey = secretKey;
1056
+ this.publicKey = publicKey;
1057
+ }
1058
+ static fromSecretKey(key) {
1059
+ const secretKey = toUint8Array(key);
1060
+ const publicKey = extractPublicKeyFromSecretKey(secretKey);
1061
+ return new _EdKeypair(secretKey, publicKey);
1062
+ }
1063
+ did() {
1064
+ const bytes = new Uint8Array(EDWARDS_DID_PREFIX.length + this.publicKey.length);
1065
+ bytes.set(EDWARDS_DID_PREFIX);
1066
+ bytes.set(this.publicKey, EDWARDS_DID_PREFIX.length);
1067
+ return "did:key:z" + base58btcEncode(bytes);
1068
+ }
1069
+ async sign(msg) {
1070
+ return sign(this.secretKey, msg);
1071
+ }
1072
+ };
1073
+ }
1074
+ });
1075
+
975
1076
  // src/sdk/auth-token-provider.ts
976
- import * as ucans from "@ucans/ucans";
977
1077
  var AuthTokenProvider;
978
1078
  var init_auth_token_provider = __esm({
979
1079
  "src/sdk/auth-token-provider.ts"() {
980
1080
  "use strict";
981
1081
  init_esm_shims();
1082
+ init_ucan();
982
1083
  AuthTokenProvider = class {
983
1084
  DEFAULT_OPTIONS = {
984
1085
  namespace: "file",
@@ -992,7 +1093,7 @@ var init_auth_token_provider = __esm({
992
1093
  this.portalAddress = portalAddress;
993
1094
  }
994
1095
  async getAuthToken(audienceDid, options = this.DEFAULT_OPTIONS) {
995
- const ucan = await ucans.build({
1096
+ return buildAndEncode({
996
1097
  audience: audienceDid,
997
1098
  issuer: this.keyPair,
998
1099
  lifetimeInSeconds: 7 * 86400,
@@ -1006,7 +1107,6 @@ var init_auth_token_provider = __esm({
1006
1107
  }
1007
1108
  ]
1008
1109
  });
1009
- return ucans.encode(ucan);
1010
1110
  }
1011
1111
  };
1012
1112
  }
@@ -2188,7 +2288,7 @@ import { derivePBKDF2Key, encryptAesCBC } from "@fileverse/crypto/kdf";
2188
2288
  import { secretBoxEncrypt } from "@fileverse/crypto/nacl";
2189
2289
  import hkdf from "futoin-hkdf";
2190
2290
  import tweetnacl from "tweetnacl";
2191
- import { fromUint8Array, toUint8Array } from "js-base64";
2291
+ import { fromUint8Array, toUint8Array as toUint8Array2 } from "js-base64";
2192
2292
  import { toAESKey, aesEncrypt } from "@fileverse/crypto/webcrypto";
2193
2293
  import axios from "axios";
2194
2294
  import { encodeFunctionData, parseEventLogs } from "viem";
@@ -2206,15 +2306,15 @@ var init_file_utils = __esm({
2206
2306
  });
2207
2307
  };
2208
2308
  getExistingEncryptionMaterial = async (existingEncryptedSecretKey, existingNonce, docId) => {
2209
- const derivedKey = await deriveKeyFromAg2Hash(docId, toUint8Array(existingNonce));
2309
+ const derivedKey = await deriveKeyFromAg2Hash(docId, toUint8Array2(existingNonce));
2210
2310
  const secretKey = tweetnacl.secretbox.open(
2211
- toUint8Array(existingEncryptedSecretKey),
2212
- toUint8Array(existingNonce),
2311
+ toUint8Array2(existingEncryptedSecretKey),
2312
+ toUint8Array2(existingNonce),
2213
2313
  derivedKey
2214
2314
  );
2215
2315
  return {
2216
2316
  encryptedSecretKey: existingEncryptedSecretKey,
2217
- nonce: toUint8Array(existingNonce),
2317
+ nonce: toUint8Array2(existingNonce),
2218
2318
  secretKey,
2219
2319
  derivedKey: new Uint8Array(derivedKey)
2220
2320
  };
@@ -2267,8 +2367,8 @@ var init_file_utils = __esm({
2267
2367
  const encryptedBlob = new Blob([ciphertext], { type: file2.type });
2268
2368
  const encryptedBlobWithAuthTagIv = await appendAuthTagIvToBlob(
2269
2369
  encryptedBlob,
2270
- toUint8Array(authTag),
2271
- toUint8Array(iv)
2370
+ toUint8Array2(authTag),
2371
+ toUint8Array2(iv)
2272
2372
  );
2273
2373
  return {
2274
2374
  encryptedFile: new File([encryptedBlobWithAuthTagIv], file2.name),
@@ -2314,7 +2414,7 @@ var init_file_utils = __esm({
2314
2414
  };
2315
2415
  };
2316
2416
  encryptTitleWithFileKey = async (args) => {
2317
- const key = await toAESKey(toUint8Array(args.key));
2417
+ const key = await toAESKey(toUint8Array2(args.key));
2318
2418
  if (!key) throw new Error("Key is undefined");
2319
2419
  const titleBytes = new TextEncoder().encode(args.title);
2320
2420
  const encryptedTitle = await aesEncrypt(key, titleBytes, "base64");
@@ -2432,7 +2532,7 @@ var init_file_utils = __esm({
2432
2532
  });
2433
2533
 
2434
2534
  // src/sdk/file-manager.ts
2435
- import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array2 } from "js-base64";
2535
+ import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
2436
2536
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
2437
2537
  import { markdownToYjs } from "@fileverse/content-processor";
2438
2538
  var FileManager;
@@ -2453,8 +2553,8 @@ var init_file_manager = __esm({
2453
2553
  }
2454
2554
  createLocks(key, encryptedSecretKey, commentKey) {
2455
2555
  const appLock = {
2456
- lockedFileKey: this.keyStore.encryptData(toUint8Array2(key)),
2457
- lockedLinkKey: this.keyStore.encryptData(toUint8Array2(encryptedSecretKey)),
2556
+ lockedFileKey: this.keyStore.encryptData(toUint8Array3(key)),
2557
+ lockedLinkKey: this.keyStore.encryptData(toUint8Array3(encryptedSecretKey)),
2458
2558
  lockedChatKey: this.keyStore.encryptData(commentKey)
2459
2559
  };
2460
2560
  return { appLock, ownerLock: { ...appLock } };
@@ -2488,20 +2588,28 @@ var init_file_manager = __esm({
2488
2588
  return this.agentClient.getAuthParams();
2489
2589
  }
2490
2590
  async submitAddFileTrx(file2) {
2591
+ console.log("Submitting add file trx");
2491
2592
  logger.debug(`Preparing to add file ${file2.ddocId}`);
2492
2593
  const encryptedSecretKey = file2.linkKey;
2493
- const nonce = toUint8Array2(file2.linkKeyNonce);
2494
- const secretKey = toUint8Array2(file2.secretKey);
2594
+ const nonce = toUint8Array3(file2.linkKeyNonce);
2595
+ const secretKey = toUint8Array3(file2.secretKey);
2596
+ console.log("Got encrypted secret key, nonce, and secret key");
2495
2597
  const yJSContent = markdownToYjs(file2.content);
2598
+ console.log("Generated yjs content");
2496
2599
  const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
2600
+ console.log("Generated encrypted content file");
2497
2601
  logger.debug(`Generated encrypted content file for file ${file2.ddocId}`);
2498
2602
  const commentKey = await exportAESKey(await generateAESKey(128));
2603
+ console.log("Generated comment key");
2499
2604
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
2500
- const linkLock = buildLinklock(secretKey, toUint8Array2(key), commentKey);
2605
+ console.log("Built app lock and owner lock");
2606
+ const linkLock = buildLinklock(secretKey, toUint8Array3(key), commentKey);
2607
+ console.log("Built link lock");
2501
2608
  const encryptedTitle = await encryptTitleWithFileKey({
2502
2609
  title: file2.title || "Untitled",
2503
2610
  key
2504
2611
  });
2612
+ console.log("Built encrypted title");
2505
2613
  const metadata = buildFileMetadata({
2506
2614
  encryptedTitle,
2507
2615
  encryptedFileSize: encryptedFile.size,
@@ -2511,11 +2619,15 @@ var init_file_manager = __esm({
2511
2619
  nonce: fromUint8Array2(nonce),
2512
2620
  owner: this.agentClient.getAgentAddress()
2513
2621
  });
2622
+ console.log("Built metadata");
2514
2623
  const authParams = await this.getAuthParams();
2624
+ console.log("Got auth params");
2625
+ console.log("Uploading files to IPFS");
2515
2626
  const { metadataHash, contentHash, gateHash } = await uploadAllFilesToIPFS(
2516
2627
  { metadata, encryptedFile, linkLock, ddocId: file2.ddocId },
2517
2628
  authParams
2518
2629
  );
2630
+ console.log("Uploaded files to IPFS");
2519
2631
  logger.debug(`Uploaded files to IPFS for file ${file2.ddocId}`);
2520
2632
  const callData = prepareCallData({
2521
2633
  metadataHash,
@@ -2524,8 +2636,10 @@ var init_file_manager = __esm({
2524
2636
  appFileId: file2.ddocId,
2525
2637
  fileId: file2.fileId
2526
2638
  });
2639
+ console.log("Prepared call data");
2527
2640
  logger.debug(`Prepared call data for file ${file2.ddocId}`);
2528
2641
  const userOpHash = await this.sendFileOperation(callData);
2642
+ console.log("Submitted user op");
2529
2643
  logger.debug(`Submitted user op for file ${file2.ddocId}`);
2530
2644
  return {
2531
2645
  userOpHash,
@@ -2538,13 +2652,13 @@ var init_file_manager = __esm({
2538
2652
  async submitUpdateFile(file2) {
2539
2653
  logger.debug(`Submitting update for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
2540
2654
  const encryptedSecretKey = file2.linkKey;
2541
- const nonce = toUint8Array2(file2.linkKeyNonce);
2542
- const secretKey = toUint8Array2(file2.secretKey);
2655
+ const nonce = toUint8Array3(file2.linkKeyNonce);
2656
+ const secretKey = toUint8Array3(file2.secretKey);
2543
2657
  const yjsContent = markdownToYjs(file2.content);
2544
2658
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2545
- const commentKey = toUint8Array2(file2.commentKey);
2659
+ const commentKey = toUint8Array3(file2.commentKey);
2546
2660
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
2547
- const linkLock = buildLinklock(secretKey, toUint8Array2(key), commentKey);
2661
+ const linkLock = buildLinklock(secretKey, toUint8Array3(key), commentKey);
2548
2662
  const encryptedTitle = await encryptTitleWithFileKey({
2549
2663
  title: file2.title || "Untitled",
2550
2664
  key
@@ -2586,14 +2700,14 @@ var init_file_manager = __esm({
2586
2700
  async updateFile(file2) {
2587
2701
  logger.debug(`Updating file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
2588
2702
  const encryptedSecretKey = file2.linkKey;
2589
- const nonce = toUint8Array2(file2.linkKeyNonce);
2590
- const secretKey = toUint8Array2(file2.secretKey);
2703
+ const nonce = toUint8Array3(file2.linkKeyNonce);
2704
+ const secretKey = toUint8Array3(file2.secretKey);
2591
2705
  logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
2592
2706
  const yjsContent = markdownToYjs(file2.content);
2593
2707
  const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
2594
- const commentKey = toUint8Array2(file2.commentKey);
2708
+ const commentKey = toUint8Array3(file2.commentKey);
2595
2709
  const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
2596
- const linkLock = buildLinklock(secretKey, toUint8Array2(key), commentKey);
2710
+ const linkLock = buildLinklock(secretKey, toUint8Array3(key), commentKey);
2597
2711
  const encryptedTitle = await encryptTitleWithFileKey({
2598
2712
  title: file2.title || "Untitled",
2599
2713
  key
@@ -2645,11 +2759,10 @@ var init_file_manager = __esm({
2645
2759
  });
2646
2760
 
2647
2761
  // src/domain/portal/publish.ts
2648
- import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array3 } from "js-base64";
2762
+ import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array4 } from "js-base64";
2649
2763
  import { stringToBytes } from "viem";
2650
2764
  import { deriveHKDFKey } from "@fileverse/crypto/kdf";
2651
2765
  import { generateKeyPairFromSeed } from "@stablelib/ed25519";
2652
- import * as ucans2 from "@ucans/ucans";
2653
2766
  async function getPortalData(fileId) {
2654
2767
  const file2 = await FilesModel.findByIdIncludingDeleted(fileId);
2655
2768
  if (!file2) {
@@ -2681,16 +2794,15 @@ var init_publish = __esm({
2681
2794
  init_infra();
2682
2795
  init_key_store();
2683
2796
  init_auth_token_provider();
2797
+ init_ucan();
2684
2798
  init_smart_agent();
2685
2799
  init_file_manager();
2686
2800
  init_config();
2687
2801
  init_pimlico_utils();
2688
2802
  createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
2689
- const keyPair = ucans2.EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret), {
2690
- exportable: true
2691
- });
2803
+ const keyPair = EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret));
2692
2804
  const authTokenProvider = new AuthTokenProvider(keyPair, portalAddress);
2693
- const keyStore = new KeyStore(toUint8Array3(portalSeed), portalAddress, authTokenProvider);
2805
+ const keyStore = new KeyStore(toUint8Array4(portalSeed), portalAddress, authTokenProvider);
2694
2806
  const agentClient = new AgentClient(authTokenProvider);
2695
2807
  await agentClient.initializeAgentClient(privateAccountKey);
2696
2808
  return new FileManager(keyStore, agentClient);
@@ -2709,7 +2821,7 @@ var init_publish = __esm({
2709
2821
  handleExistingFileOp = async (fileId, operation) => {
2710
2822
  try {
2711
2823
  const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
2712
- const apiKeySeed = toUint8Array3(apiKey);
2824
+ const apiKeySeed = toUint8Array4(apiKey);
2713
2825
  const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
2714
2826
  const fileManager = await createFileManager(
2715
2827
  portalDetails.portalSeed,
@@ -2725,19 +2837,22 @@ var init_publish = __esm({
2725
2837
  };
2726
2838
  handleNewFileOp = async (fileId) => {
2727
2839
  const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
2728
- const apiKeySeed = toUint8Array3(apiKey);
2840
+ console.log("Got portal data");
2841
+ const apiKeySeed = toUint8Array4(apiKey);
2729
2842
  const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
2843
+ console.log("Derived collaborator keys");
2730
2844
  const fileManager = await createFileManager(
2731
2845
  portalDetails.portalSeed,
2732
2846
  portalDetails.portalAddress,
2733
2847
  ucanSecret,
2734
2848
  privateAccountKey
2735
2849
  );
2850
+ console.log("Created file manager");
2736
2851
  return fileManager.submitAddFileTrx(file2);
2737
2852
  };
2738
2853
  getProxyAuthParams = async (fileId) => {
2739
2854
  const { portalDetails, apiKey } = await getPortalData(fileId);
2740
- const apiKeySeed = toUint8Array3(apiKey);
2855
+ const apiKeySeed = toUint8Array4(apiKey);
2741
2856
  const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
2742
2857
  const fileManager = await createFileManager(
2743
2858
  portalDetails.portalSeed,
@@ -2749,7 +2864,7 @@ var init_publish = __esm({
2749
2864
  };
2750
2865
  submitUpdateFileOp = async (fileId) => {
2751
2866
  const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
2752
- const apiKeySeed = toUint8Array3(apiKey);
2867
+ const apiKeySeed = toUint8Array4(apiKey);
2753
2868
  const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
2754
2869
  const fileManager = await createFileManager(
2755
2870
  portalDetails.portalSeed,
@@ -2761,7 +2876,7 @@ var init_publish = __esm({
2761
2876
  };
2762
2877
  submitDeleteFileOp = async (fileId) => {
2763
2878
  const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
2764
- const apiKeySeed = toUint8Array3(apiKey);
2879
+ const apiKeySeed = toUint8Array4(apiKey);
2765
2880
  const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
2766
2881
  const fileManager = await createFileManager(
2767
2882
  portalDetails.portalSeed,
@@ -2773,7 +2888,7 @@ var init_publish = __esm({
2773
2888
  };
2774
2889
  resolveFileOp = async (fileId, userOpHash, eventType) => {
2775
2890
  const { portalDetails, apiKey } = await getPortalData(fileId);
2776
- const apiKeySeed = toUint8Array3(apiKey);
2891
+ const apiKeySeed = toUint8Array4(apiKey);
2777
2892
  const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
2778
2893
  const fileManager = await createFileManager(
2779
2894
  portalDetails.portalSeed,
@@ -2930,13 +3045,17 @@ var init_eventProcessor = __esm({
2930
3045
  const { fileId, type } = event;
2931
3046
  switch (type) {
2932
3047
  case "create": {
3048
+ console.log("Starting create event submission");
2933
3049
  const file2 = await FilesModel.findByIdIncludingDeleted(fileId);
3050
+ console.log("File found");
2934
3051
  if (!file2) throw new Error(`File ${fileId} not found`);
2935
3052
  if (file2.isDeleted === 1) {
2936
3053
  logger.info(`File ${fileId} is deleted, skipping create submit`);
2937
3054
  return;
2938
3055
  }
3056
+ console.log("Submitting new file op");
2939
3057
  const result = await handleNewFileOp(fileId);
3058
+ console.log("New file op submitted");
2940
3059
  await EventsModel.setEventPendingOp(event._id, result.userOpHash, {
2941
3060
  linkKey: result.linkKey,
2942
3061
  linkKeyNonce: result.linkKeyNonce,
@@ -3929,11 +4048,11 @@ init_esm_shims();
3929
4048
  init_esm_shims();
3930
4049
  init_constants();
3931
4050
  import axios2 from "axios";
3932
- import { toUint8Array as toUint8Array4 } from "js-base64";
4051
+ import { toUint8Array as toUint8Array5 } from "js-base64";
3933
4052
  import { sha256 } from "viem";
3934
4053
  var fetchApiKeyData = async (apiKey) => {
3935
4054
  try {
3936
- const keyHash = sha256(toUint8Array4(apiKey));
4055
+ const keyHash = sha256(toUint8Array5(apiKey));
3937
4056
  const fullUrl = BASE_CONFIG.API_URL + `api-access/${keyHash}`;
3938
4057
  const response = await axios2.get(fullUrl);
3939
4058
  const { encryptedKeyMaterial, encryptedAppMaterial, id } = response.data;
@@ -3961,7 +4080,7 @@ init_saveApiKey();
3961
4080
  init_apikeys_model();
3962
4081
  init_infra();
3963
4082
  import { deriveHKDFKey as deriveHKDFKey2 } from "@fileverse/crypto/hkdf";
3964
- import { toUint8Array as toUint8Array5 } from "js-base64";
4083
+ import { toUint8Array as toUint8Array6 } from "js-base64";
3965
4084
  import { stringToBytes as stringToBytes2 } from "viem";
3966
4085
  import { toAESKey as toAESKey2, aesDecrypt } from "@fileverse/crypto/webcrypto";
3967
4086
  var SAVED_DATA_ENCRYPTION_KEY_INFO = "SAVED_DATA_ENCRYPTION_KEY";
@@ -3986,7 +4105,7 @@ async function initializeWithData(data) {
3986
4105
  }
3987
4106
  var getAesKeyFromApiKey = async (apiKey) => {
3988
4107
  const rawSecret = deriveHKDFKey2(
3989
- toUint8Array5(apiKey),
4108
+ toUint8Array6(apiKey),
3990
4109
  new Uint8Array([0]),
3991
4110
  stringToBytes2(SAVED_DATA_ENCRYPTION_KEY_INFO)
3992
4111
  );
@@ -3997,7 +4116,7 @@ var bytestToJSON = (bytes) => {
3997
4116
  };
3998
4117
  var decryptSavedData = async (apiKey, encryptedData) => {
3999
4118
  const aesKey = await getAesKeyFromApiKey(apiKey);
4000
- const decryptedBytes = await aesDecrypt(aesKey, toUint8Array5(encryptedData));
4119
+ const decryptedBytes = await aesDecrypt(aesKey, toUint8Array6(encryptedData));
4001
4120
  const data = bytestToJSON(decryptedBytes);
4002
4121
  return data;
4003
4122
  };
@@ -4219,7 +4338,7 @@ __export(external_exports, {
4219
4338
  e164: () => e1642,
4220
4339
  email: () => email2,
4221
4340
  emoji: () => emoji2,
4222
- encode: () => encode3,
4341
+ encode: () => encode2,
4223
4342
  encodeAsync: () => encodeAsync2,
4224
4343
  endsWith: () => _endsWith,
4225
4344
  enum: () => _enum2,
@@ -4593,7 +4712,7 @@ __export(core_exports2, {
4593
4712
  decode: () => decode,
4594
4713
  decodeAsync: () => decodeAsync,
4595
4714
  describe: () => describe,
4596
- encode: () => encode2,
4715
+ encode: () => encode,
4597
4716
  encodeAsync: () => encodeAsync,
4598
4717
  extractDefs: () => extractDefs,
4599
4718
  finalize: () => finalize,
@@ -5580,7 +5699,7 @@ var _encode = (_Err) => (schema, value, _ctx) => {
5580
5699
  const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
5581
5700
  return _parse(_Err)(schema, value, ctx);
5582
5701
  };
5583
- var encode2 = /* @__PURE__ */ _encode($ZodRealError);
5702
+ var encode = /* @__PURE__ */ _encode($ZodRealError);
5584
5703
  var _decode = (_Err) => (schema, value, _ctx) => {
5585
5704
  return _parse(_Err)(schema, value, _ctx);
5586
5705
  };
@@ -16344,7 +16463,7 @@ var parse2 = /* @__PURE__ */ _parse(ZodRealError);
16344
16463
  var parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
16345
16464
  var safeParse2 = /* @__PURE__ */ _safeParse(ZodRealError);
16346
16465
  var safeParseAsync2 = /* @__PURE__ */ _safeParseAsync(ZodRealError);
16347
- var encode3 = /* @__PURE__ */ _encode(ZodRealError);
16466
+ var encode2 = /* @__PURE__ */ _encode(ZodRealError);
16348
16467
  var decode2 = /* @__PURE__ */ _decode(ZodRealError);
16349
16468
  var encodeAsync2 = /* @__PURE__ */ _encodeAsync(ZodRealError);
16350
16469
  var decodeAsync2 = /* @__PURE__ */ _decodeAsync(ZodRealError);
@@ -16388,7 +16507,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
16388
16507
  inst.parseAsync = async (data, params) => parseAsync2(inst, data, params, { callee: inst.parseAsync });
16389
16508
  inst.safeParseAsync = async (data, params) => safeParseAsync2(inst, data, params);
16390
16509
  inst.spa = inst.safeParseAsync;
16391
- inst.encode = (data, params) => encode3(inst, data, params);
16510
+ inst.encode = (data, params) => encode2(inst, data, params);
16392
16511
  inst.decode = (data, params) => decode2(inst, data, params);
16393
16512
  inst.encodeAsync = async (data, params) => encodeAsync2(inst, data, params);
16394
16513
  inst.decodeAsync = async (data, params) => decodeAsync2(inst, data, params);