@fileverse/api 0.0.10 → 0.0.12
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 +3 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +54 -33
- package/dist/cloudflare.js.map +1 -1
- package/dist/commands/index.js +71 -6
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +54 -33
- package/dist/index.js.map +1 -1
- package/dist/worker.js +29 -58
- package/dist/worker.js.map +1 -1
- package/package.json +2 -2
- package/public/llm.txt +204 -478
package/dist/worker.js
CHANGED
|
@@ -649,7 +649,9 @@ var init_files_model = __esm({
|
|
|
649
649
|
linkKey: fileRaw.linkKey,
|
|
650
650
|
linkKeyNonce: fileRaw.linkKeyNonce,
|
|
651
651
|
commentKey: fileRaw.commentKey,
|
|
652
|
-
link: fileRaw.link
|
|
652
|
+
link: fileRaw.link,
|
|
653
|
+
derivedKey: fileRaw.derivedKey,
|
|
654
|
+
secretKey: fileRaw.secretKey
|
|
653
655
|
};
|
|
654
656
|
}
|
|
655
657
|
static async findAll(portalAddress, limit, skip) {
|
|
@@ -733,10 +735,20 @@ var init_files_model = __esm({
|
|
|
733
735
|
const _id = uuidv7();
|
|
734
736
|
const sql = `
|
|
735
737
|
INSERT INTO ${this.TABLE}
|
|
736
|
-
(_id, title, content, ddocId, portalAddress)
|
|
737
|
-
VALUES (?, ?, ?, ?, ?)
|
|
738
|
+
(_id, title, content, ddocId, portalAddress, linkKey, linkKeyNonce, derivedKey, secretKey)
|
|
739
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
738
740
|
`;
|
|
739
|
-
await QueryBuilder.execute(sql, [
|
|
741
|
+
await QueryBuilder.execute(sql, [
|
|
742
|
+
_id,
|
|
743
|
+
input.title,
|
|
744
|
+
input.content,
|
|
745
|
+
input.ddocId,
|
|
746
|
+
input.portalAddress,
|
|
747
|
+
input.linkKey ?? null,
|
|
748
|
+
input.linkKeyNonce ?? null,
|
|
749
|
+
input.derivedKey ?? null,
|
|
750
|
+
input.secretKey ?? null
|
|
751
|
+
]);
|
|
740
752
|
const created = await this.findById(_id, input.portalAddress);
|
|
741
753
|
if (!created) {
|
|
742
754
|
throw new Error("Failed to create file");
|
|
@@ -2406,50 +2418,13 @@ import { fromUint8Array, toUint8Array } from "js-base64";
|
|
|
2406
2418
|
import { toAESKey, aesEncrypt } from "@fileverse/crypto/webcrypto";
|
|
2407
2419
|
import axios from "axios";
|
|
2408
2420
|
import { encodeFunctionData, parseEventLogs } from "viem";
|
|
2409
|
-
var
|
|
2421
|
+
var jsonToFile, appendAuthTagIvToBlob, encryptFile, getNonceAppendedCipherText, jsonToBytes, buildLinklock, encryptTitleWithFileKey, uploadFileToIPFS, getEditFileTrxCalldata, getAddFileTrxCalldata, prepareCallData, prepareDeleteFileCallData, createEncryptedContentFile, buildFileMetadata, parseFileEventLog, uploadAllFilesToIPFS;
|
|
2410
2422
|
var init_file_utils = __esm({
|
|
2411
2423
|
"src/sdk/file-utils.ts"() {
|
|
2412
2424
|
"use strict";
|
|
2413
2425
|
init_esm_shims();
|
|
2414
2426
|
init_file_encryption();
|
|
2415
2427
|
init_constants3();
|
|
2416
|
-
deriveKeyFromAg2Hash = async (pass, salt) => {
|
|
2417
|
-
const key = await getArgon2idHash(pass, salt);
|
|
2418
|
-
return hkdf(Buffer.from(key), tweetnacl.secretbox.keyLength, {
|
|
2419
|
-
info: Buffer.from("encryptionKey")
|
|
2420
|
-
});
|
|
2421
|
-
};
|
|
2422
|
-
decryptSecretKey = async (docId, nonce, encryptedSecretKey) => {
|
|
2423
|
-
const derivedKey = await deriveKeyFromAg2Hash(docId, toUint8Array(nonce));
|
|
2424
|
-
return tweetnacl.secretbox.open(toUint8Array(encryptedSecretKey), toUint8Array(nonce), derivedKey);
|
|
2425
|
-
};
|
|
2426
|
-
getExistingEncryptionMaterial = async (existingEncryptedSecretKey, existingNonce, docId) => {
|
|
2427
|
-
const secretKey = await decryptSecretKey(docId, existingNonce, existingEncryptedSecretKey);
|
|
2428
|
-
return {
|
|
2429
|
-
encryptedSecretKey: existingEncryptedSecretKey,
|
|
2430
|
-
nonce: toUint8Array(existingNonce),
|
|
2431
|
-
secretKey
|
|
2432
|
-
};
|
|
2433
|
-
};
|
|
2434
|
-
getNaclSecretKey = async (ddocId) => {
|
|
2435
|
-
const { secretKey } = tweetnacl.box.keyPair();
|
|
2436
|
-
const nonce = tweetnacl.randomBytes(tweetnacl.secretbox.nonceLength);
|
|
2437
|
-
const derivedKey = await deriveKeyFromAg2Hash(ddocId, nonce);
|
|
2438
|
-
const encryptedSecretKey = fromUint8Array(tweetnacl.secretbox(secretKey, nonce, derivedKey), true);
|
|
2439
|
-
return { nonce, encryptedSecretKey, secretKey };
|
|
2440
|
-
};
|
|
2441
|
-
generateLinkKeyMaterial = async (params) => {
|
|
2442
|
-
if (params.linkKeyNonce && params.linkKey) {
|
|
2443
|
-
const { encryptedSecretKey: encryptedSecretKey2, nonce: nonce2, secretKey: secretKey2 } = await getExistingEncryptionMaterial(
|
|
2444
|
-
params.linkKey,
|
|
2445
|
-
params.linkKeyNonce,
|
|
2446
|
-
params.ddocId
|
|
2447
|
-
);
|
|
2448
|
-
if (secretKey2) return { encryptedSecretKey: encryptedSecretKey2, nonce: nonce2, secretKey: secretKey2 };
|
|
2449
|
-
}
|
|
2450
|
-
const { secretKey, nonce, encryptedSecretKey } = await getNaclSecretKey(params.ddocId);
|
|
2451
|
-
return { secretKey, nonce, encryptedSecretKey };
|
|
2452
|
-
};
|
|
2453
2428
|
jsonToFile = (json, fileName) => {
|
|
2454
2429
|
const blob = new Blob([JSON.stringify(json)], {
|
|
2455
2430
|
type: "application/json"
|
|
@@ -2701,11 +2676,9 @@ var init_file_manager = __esm({
|
|
|
2701
2676
|
}
|
|
2702
2677
|
async submitAddFileTrx(file) {
|
|
2703
2678
|
logger.debug(`Preparing to add file ${file.ddocId}`);
|
|
2704
|
-
const
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
linkKeyNonce: file.linkKeyNonce
|
|
2708
|
-
});
|
|
2679
|
+
const encryptedSecretKey = file.linkKey;
|
|
2680
|
+
const nonce = toUint8Array2(file.linkKeyNonce);
|
|
2681
|
+
const secretKey = toUint8Array2(file.secretKey);
|
|
2709
2682
|
const yJSContent = markdownToYjs(file.content);
|
|
2710
2683
|
const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
|
|
2711
2684
|
logger.debug(`Generated encrypted content file for file ${file.ddocId}`);
|
|
@@ -2751,11 +2724,9 @@ var init_file_manager = __esm({
|
|
|
2751
2724
|
}
|
|
2752
2725
|
async submitUpdateFile(file) {
|
|
2753
2726
|
logger.debug(`Submitting update for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2754
|
-
const
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
linkKeyNonce: file.linkKeyNonce
|
|
2758
|
-
});
|
|
2727
|
+
const encryptedSecretKey = file.linkKey;
|
|
2728
|
+
const nonce = toUint8Array2(file.linkKeyNonce);
|
|
2729
|
+
const secretKey = toUint8Array2(file.secretKey);
|
|
2759
2730
|
const yjsContent = markdownToYjs(file.content);
|
|
2760
2731
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2761
2732
|
const commentKey = toUint8Array2(file.commentKey);
|
|
@@ -2801,11 +2772,9 @@ var init_file_manager = __esm({
|
|
|
2801
2772
|
}
|
|
2802
2773
|
async updateFile(file) {
|
|
2803
2774
|
logger.debug(`Updating file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2804
|
-
const
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
linkKeyNonce: file.linkKeyNonce
|
|
2808
|
-
});
|
|
2775
|
+
const encryptedSecretKey = file.linkKey;
|
|
2776
|
+
const nonce = toUint8Array2(file.linkKeyNonce);
|
|
2777
|
+
const secretKey = toUint8Array2(file.secretKey);
|
|
2809
2778
|
logger.debug(`Generating encrypted content file for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2810
2779
|
const yjsContent = markdownToYjs(file.content);
|
|
2811
2780
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
@@ -3464,7 +3433,9 @@ CREATE TABLE IF NOT EXISTS files (
|
|
|
3464
3433
|
commentKey TEXT,
|
|
3465
3434
|
linkKey TEXT,
|
|
3466
3435
|
linkKeyNonce TEXT,
|
|
3467
|
-
link TEXT
|
|
3436
|
+
link TEXT,
|
|
3437
|
+
derivedKey TEXT,
|
|
3438
|
+
secretKey TEXT
|
|
3468
3439
|
);
|
|
3469
3440
|
CREATE INDEX IF NOT EXISTS idx_files_createdAt ON files(createdAt);
|
|
3470
3441
|
CREATE INDEX IF NOT EXISTS idx_files_syncStatus ON files(syncStatus);
|