@fileverse/api 0.0.21 → 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.
- package/dist/cli/index.js +30 -34
- package/dist/cli/index.js.map +1 -1
- package/dist/commands/index.js +16 -126
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +112 -330
- package/dist/index.js.map +1 -1
- package/dist/worker.js +85 -258
- package/dist/worker.js.map +1 -1
- package/package.json +6 -5
- package/dist/cloudflare.js +0 -18259
- package/dist/cloudflare.js.map +0 -1
package/dist/commands/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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', '
|
|
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,55 +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);
|
|
1566
|
-
return hkdf(Buffer.from(key), tweetnacl2.secretbox.keyLength, {
|
|
1567
|
-
info: Buffer.from("encryptionKey")
|
|
1568
|
-
});
|
|
1569
|
-
};
|
|
1570
|
-
var getExistingEncryptionMaterial = async (existingEncryptedSecretKey, existingNonce, docId) => {
|
|
1571
|
-
const derivedKey = await deriveKeyFromAg2Hash(docId, toUint8Array5(existingNonce));
|
|
1572
|
-
const secretKey = tweetnacl2.secretbox.open(
|
|
1573
|
-
toUint8Array5(existingEncryptedSecretKey),
|
|
1574
|
-
toUint8Array5(existingNonce),
|
|
1575
|
-
derivedKey
|
|
1576
|
-
);
|
|
1577
|
-
return {
|
|
1578
|
-
encryptedSecretKey: existingEncryptedSecretKey,
|
|
1579
|
-
nonce: toUint8Array5(existingNonce),
|
|
1580
|
-
secretKey,
|
|
1581
|
-
derivedKey: new Uint8Array(derivedKey)
|
|
1582
|
-
};
|
|
1583
|
-
};
|
|
1584
|
-
var getNaclSecretKey = async (ddocId) => {
|
|
1585
|
-
const { secretKey } = tweetnacl2.box.keyPair();
|
|
1586
|
-
const nonce = tweetnacl2.randomBytes(tweetnacl2.secretbox.nonceLength);
|
|
1587
|
-
const derivedKey = await deriveKeyFromAg2Hash(ddocId, nonce);
|
|
1588
|
-
const encryptedSecretKey = fromUint8Array4(tweetnacl2.secretbox(secretKey, nonce, derivedKey), true);
|
|
1589
|
-
return { nonce, encryptedSecretKey, secretKey, derivedKey: new Uint8Array(derivedKey) };
|
|
1590
|
-
};
|
|
1591
|
-
var generateLinkKeyMaterial = async (params) => {
|
|
1592
|
-
if (params.linkKeyNonce && params.linkKey) {
|
|
1593
|
-
const { encryptedSecretKey: encryptedSecretKey2, nonce: nonce2, secretKey: secretKey2, derivedKey: derivedKey2 } = await getExistingEncryptionMaterial(
|
|
1594
|
-
params.linkKey,
|
|
1595
|
-
params.linkKeyNonce,
|
|
1596
|
-
params.ddocId
|
|
1597
|
-
);
|
|
1598
|
-
if (secretKey2) return { encryptedSecretKey: encryptedSecretKey2, nonce: nonce2, secretKey: secretKey2, derivedKey: derivedKey2 };
|
|
1599
|
-
}
|
|
1600
|
-
const { secretKey, nonce, encryptedSecretKey, derivedKey } = await getNaclSecretKey(params.ddocId);
|
|
1601
|
-
return { secretKey, nonce, encryptedSecretKey, derivedKey };
|
|
1602
|
-
};
|
|
1603
|
-
|
|
1604
|
-
// src/domain/file/index.ts
|
|
1605
1504
|
async function listFiles(params) {
|
|
1606
1505
|
const { limit, skip, portalAddress } = params;
|
|
1607
1506
|
const effectiveLimit = limit || DEFAULT_LIST_LIMIT;
|
|
@@ -1654,20 +1553,11 @@ var createFile = async (input) => {
|
|
|
1654
1553
|
throw new Error("title, content, and portalAddress are required");
|
|
1655
1554
|
}
|
|
1656
1555
|
const ddocId = generate();
|
|
1657
|
-
const { encryptedSecretKey, nonce, secretKey, derivedKey } = await generateLinkKeyMaterial({
|
|
1658
|
-
ddocId,
|
|
1659
|
-
linkKey: void 0,
|
|
1660
|
-
linkKeyNonce: void 0
|
|
1661
|
-
});
|
|
1662
1556
|
const file = await FilesModel.create({
|
|
1663
1557
|
title: input.title,
|
|
1664
1558
|
content: input.content,
|
|
1665
1559
|
ddocId,
|
|
1666
|
-
portalAddress: input.portalAddress
|
|
1667
|
-
linkKey: encryptedSecretKey,
|
|
1668
|
-
linkKeyNonce: fromUint8Array5(nonce),
|
|
1669
|
-
derivedKey: fromUint8Array5(derivedKey),
|
|
1670
|
-
secretKey: fromUint8Array5(secretKey)
|
|
1560
|
+
portalAddress: input.portalAddress
|
|
1671
1561
|
});
|
|
1672
1562
|
await EventsModel.create({ type: "create", fileId: file._id, portalAddress: file.portalAddress });
|
|
1673
1563
|
return file;
|