@fileverse/api 0.0.20 → 0.0.22

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.
@@ -96,12 +96,7 @@ var init_config = __esm({
96
96
  init_constants();
97
97
  projectEnvPath = path2.join(process.cwd(), "config", ".env");
98
98
  userEnvPath = path2.join(os.homedir(), ".fileverse", ".env");
99
- if (typeof globalThis.process !== "undefined" && typeof globalThis.process.cwd === "function") {
100
- try {
101
- loadConfig(false);
102
- } catch {
103
- }
104
- }
99
+ loadConfig(false);
105
100
  config = {
106
101
  ...STATIC_CONFIG,
107
102
  get SERVICE_NAME() {
@@ -340,9 +335,7 @@ var init_files_model = __esm({
340
335
  linkKey: fileRaw.linkKey,
341
336
  linkKeyNonce: fileRaw.linkKeyNonce,
342
337
  commentKey: fileRaw.commentKey,
343
- link: fileRaw.link,
344
- derivedKey: fileRaw.derivedKey,
345
- secretKey: fileRaw.secretKey
338
+ link: fileRaw.link
346
339
  };
347
340
  }
348
341
  static async findAll(portalAddress, limit, skip) {
@@ -426,20 +419,10 @@ var init_files_model = __esm({
426
419
  const _id = uuidv7();
427
420
  const sql = `
428
421
  INSERT INTO ${this.TABLE}
429
- (_id, title, content, ddocId, portalAddress, linkKey, linkKeyNonce, derivedKey, secretKey)
430
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
422
+ (_id, title, content, ddocId, portalAddress)
423
+ VALUES (?, ?, ?, ?, ?)
431
424
  `;
432
- await QueryBuilder.execute(sql, [
433
- _id,
434
- input.title,
435
- input.content,
436
- input.ddocId,
437
- input.portalAddress,
438
- input.linkKey ?? null,
439
- input.linkKeyNonce ?? null,
440
- input.derivedKey ?? null,
441
- input.secretKey ?? null
442
- ]);
425
+ await QueryBuilder.execute(sql, [_id, input.title, input.content, input.ddocId, input.portalAddress]);
443
426
  const created = await this.findById(_id, input.portalAddress);
444
427
  if (!created) {
445
428
  throw new Error("Failed to create file");
@@ -663,29 +646,6 @@ var init_events_model = __esm({
663
646
  `;
664
647
  await QueryBuilder.execute(sql, [Date.now(), _id]);
665
648
  }
666
- static async markSubmitted(_id) {
667
- const sql = `
668
- UPDATE ${this.TABLE}
669
- SET status = 'submitted',
670
- lockedAt = NULL
671
- WHERE _id = ?
672
- `;
673
- await QueryBuilder.execute(sql, [_id]);
674
- }
675
- static async findNextSubmitted(lockedFileIds) {
676
- const exclusionClause = lockedFileIds.length > 0 ? `AND fileId NOT IN (${lockedFileIds.map(() => "?").join(", ")})` : "";
677
- const sql = `
678
- SELECT * FROM ${this.TABLE}
679
- WHERE status = 'submitted'
680
- AND userOpHash IS NOT NULL
681
- ${exclusionClause}
682
- ORDER BY timestamp ASC
683
- LIMIT 1
684
- `;
685
- const params = [...lockedFileIds];
686
- const row = await QueryBuilder.selectOne(sql, params);
687
- return row ? this.parseEvent(row) : void 0;
688
- }
689
649
  static async markProcessed(_id) {
690
650
  const sql = `
691
651
  UPDATE ${this.TABLE}
@@ -848,24 +808,12 @@ var init_key_store = __esm({
848
808
  }
849
809
  });
850
810
 
851
- // src/sdk/ucan.ts
852
- import { sign, extractPublicKeyFromSecretKey } from "@stablelib/ed25519";
853
- import { toUint8Array } from "js-base64";
854
- var EDWARDS_DID_PREFIX;
855
- var init_ucan = __esm({
856
- "src/sdk/ucan.ts"() {
857
- "use strict";
858
- init_esm_shims();
859
- EDWARDS_DID_PREFIX = new Uint8Array([237, 1]);
860
- }
861
- });
862
-
863
811
  // src/sdk/auth-token-provider.ts
812
+ import * as ucans from "@ucans/ucans";
864
813
  var init_auth_token_provider = __esm({
865
814
  "src/sdk/auth-token-provider.ts"() {
866
815
  "use strict";
867
816
  init_esm_shims();
868
- init_ucan();
869
817
  }
870
818
  });
871
819
 
@@ -952,12 +900,15 @@ var init_file_encryption = __esm({
952
900
  });
953
901
 
954
902
  // src/sdk/file-utils.ts
903
+ import { getArgon2idHash } from "@fileverse/crypto/argon";
955
904
  import { bytesToBase64, generateRandomBytes as generateRandomBytes2 } from "@fileverse/crypto/utils";
956
905
  import { derivePBKDF2Key, encryptAesCBC } from "@fileverse/crypto/kdf";
957
906
  import { secretBoxEncrypt } from "@fileverse/crypto/nacl";
907
+ import hkdf from "futoin-hkdf";
958
908
  import tweetnacl from "tweetnacl";
959
- import { fromUint8Array, toUint8Array as toUint8Array2 } from "js-base64";
909
+ import { fromUint8Array, toUint8Array } from "js-base64";
960
910
  import { toAESKey, aesEncrypt } from "@fileverse/crypto/webcrypto";
911
+ import axios from "axios";
961
912
  import { encodeFunctionData, parseEventLogs } from "viem";
962
913
  var init_file_utils = __esm({
963
914
  "src/sdk/file-utils.ts"() {
@@ -969,7 +920,7 @@ var init_file_utils = __esm({
969
920
  });
970
921
 
971
922
  // src/sdk/file-manager.ts
972
- import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
923
+ import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array2 } from "js-base64";
973
924
  import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
974
925
  import { markdownToYjs } from "@fileverse/content-processor";
975
926
  var init_file_manager = __esm({
@@ -984,10 +935,11 @@ var init_file_manager = __esm({
984
935
  });
985
936
 
986
937
  // src/domain/portal/publish.ts
987
- import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array4 } from "js-base64";
938
+ import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array3 } from "js-base64";
988
939
  import { stringToBytes } from "viem";
989
940
  import { deriveHKDFKey } from "@fileverse/crypto/kdf";
990
941
  import { generateKeyPairFromSeed } from "@stablelib/ed25519";
942
+ import * as ucans2 from "@ucans/ucans";
991
943
  var init_publish = __esm({
992
944
  "src/domain/portal/publish.ts"() {
993
945
  "use strict";
@@ -996,11 +948,9 @@ var init_publish = __esm({
996
948
  init_infra();
997
949
  init_key_store();
998
950
  init_auth_token_provider();
999
- init_ucan();
1000
951
  init_smart_agent();
1001
952
  init_file_manager();
1002
953
  init_config();
1003
- init_pimlico_utils();
1004
954
  }
1005
955
  });
1006
956
 
@@ -1470,9 +1420,7 @@ CREATE TABLE IF NOT EXISTS files (
1470
1420
  commentKey TEXT,
1471
1421
  linkKey TEXT,
1472
1422
  linkKeyNonce TEXT,
1473
- link TEXT,
1474
- derivedKey TEXT,
1475
- secretKey TEXT
1423
+ link TEXT
1476
1424
  );
1477
1425
  CREATE INDEX IF NOT EXISTS idx_files_createdAt ON files(createdAt);
1478
1426
  CREATE INDEX IF NOT EXISTS idx_files_syncStatus ON files(syncStatus);
@@ -1503,7 +1451,7 @@ CREATE TABLE IF NOT EXISTS events (
1503
1451
  type TEXT NOT NULL CHECK (type IN ('create', 'update', 'delete')),
1504
1452
  timestamp BIGINT NOT NULL,
1505
1453
  fileId TEXT NOT NULL,
1506
- status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'submitted', 'processed', 'failed')),
1454
+ status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'processing', 'processed', 'failed')),
1507
1455
  retryCount INTEGER NOT NULL DEFAULT 0,
1508
1456
  lastError TEXT,
1509
1457
  lockedAt BIGINT,
@@ -1553,60 +1501,6 @@ init_esm_shims();
1553
1501
  init_models();
1554
1502
  init_constants2();
1555
1503
  import { generate } from "short-uuid";
1556
- import { fromUint8Array as fromUint8Array5 } from "js-base64";
1557
-
1558
- // src/sdk/link-key-utils.ts
1559
- init_esm_shims();
1560
- import { getArgon2idHash } from "@fileverse/crypto/argon";
1561
- import hkdf from "futoin-hkdf";
1562
- import tweetnacl2 from "tweetnacl";
1563
- import { fromUint8Array as fromUint8Array4, toUint8Array as toUint8Array5 } from "js-base64";
1564
- var deriveKeyFromAg2Hash = async (pass, salt) => {
1565
- const key = await getArgon2idHash(pass, salt, void 0, {
1566
- t: 2,
1567
- m: 4096,
1568
- p: 8,
1569
- dkLen: 32
1570
- });
1571
- return hkdf(Buffer.from(key), tweetnacl2.secretbox.keyLength, {
1572
- info: Buffer.from("encryptionKey")
1573
- });
1574
- };
1575
- var getExistingEncryptionMaterial = async (existingEncryptedSecretKey, existingNonce, docId) => {
1576
- const derivedKey = await deriveKeyFromAg2Hash(docId, toUint8Array5(existingNonce));
1577
- const secretKey = tweetnacl2.secretbox.open(
1578
- toUint8Array5(existingEncryptedSecretKey),
1579
- toUint8Array5(existingNonce),
1580
- derivedKey
1581
- );
1582
- return {
1583
- encryptedSecretKey: existingEncryptedSecretKey,
1584
- nonce: toUint8Array5(existingNonce),
1585
- secretKey,
1586
- derivedKey: new Uint8Array(derivedKey)
1587
- };
1588
- };
1589
- var getNaclSecretKey = async (ddocId) => {
1590
- const { secretKey } = tweetnacl2.box.keyPair();
1591
- const nonce = tweetnacl2.randomBytes(tweetnacl2.secretbox.nonceLength);
1592
- const derivedKey = await deriveKeyFromAg2Hash(ddocId, nonce);
1593
- const encryptedSecretKey = fromUint8Array4(tweetnacl2.secretbox(secretKey, nonce, derivedKey), true);
1594
- return { nonce, encryptedSecretKey, secretKey, derivedKey: new Uint8Array(derivedKey) };
1595
- };
1596
- var generateLinkKeyMaterial = async (params) => {
1597
- if (params.linkKeyNonce && params.linkKey) {
1598
- const { encryptedSecretKey: encryptedSecretKey2, nonce: nonce2, secretKey: secretKey2, derivedKey: derivedKey2 } = await getExistingEncryptionMaterial(
1599
- params.linkKey,
1600
- params.linkKeyNonce,
1601
- params.ddocId
1602
- );
1603
- if (secretKey2) return { encryptedSecretKey: encryptedSecretKey2, nonce: nonce2, secretKey: secretKey2, derivedKey: derivedKey2 };
1604
- }
1605
- const { secretKey, nonce, encryptedSecretKey, derivedKey } = await getNaclSecretKey(params.ddocId);
1606
- return { secretKey, nonce, encryptedSecretKey, derivedKey };
1607
- };
1608
-
1609
- // src/domain/file/index.ts
1610
1504
  async function listFiles(params) {
1611
1505
  const { limit, skip, portalAddress } = params;
1612
1506
  const effectiveLimit = limit || DEFAULT_LIST_LIMIT;
@@ -1659,20 +1553,11 @@ var createFile = async (input) => {
1659
1553
  throw new Error("title, content, and portalAddress are required");
1660
1554
  }
1661
1555
  const ddocId = generate();
1662
- const { encryptedSecretKey, nonce, secretKey, derivedKey } = await generateLinkKeyMaterial({
1663
- ddocId,
1664
- linkKey: void 0,
1665
- linkKeyNonce: void 0
1666
- });
1667
1556
  const file = await FilesModel.create({
1668
1557
  title: input.title,
1669
1558
  content: input.content,
1670
1559
  ddocId,
1671
- portalAddress: input.portalAddress,
1672
- linkKey: encryptedSecretKey,
1673
- linkKeyNonce: fromUint8Array5(nonce),
1674
- derivedKey: fromUint8Array5(derivedKey),
1675
- secretKey: fromUint8Array5(secretKey)
1560
+ portalAddress: input.portalAddress
1676
1561
  });
1677
1562
  await EventsModel.create({ type: "create", fileId: file._id, portalAddress: file.portalAddress });
1678
1563
  return file;