@fileverse/api 0.0.14 → 0.0.16
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 +0 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +106 -68
- package/dist/cloudflare.js.map +1 -1
- package/dist/commands/index.js +52 -49
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +101 -60
- package/dist/index.js.map +1 -1
- package/dist/worker.js +45 -12
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
package/dist/worker.js
CHANGED
|
@@ -2508,15 +2508,12 @@ var init_file_encryption = __esm({
|
|
|
2508
2508
|
});
|
|
2509
2509
|
|
|
2510
2510
|
// src/sdk/file-utils.ts
|
|
2511
|
-
import { getArgon2idHash } from "@fileverse/crypto/argon";
|
|
2512
2511
|
import { bytesToBase64, generateRandomBytes as generateRandomBytes2 } from "@fileverse/crypto/utils";
|
|
2513
2512
|
import { derivePBKDF2Key, encryptAesCBC } from "@fileverse/crypto/kdf";
|
|
2514
2513
|
import { secretBoxEncrypt } from "@fileverse/crypto/nacl";
|
|
2515
|
-
import hkdf from "futoin-hkdf";
|
|
2516
2514
|
import tweetnacl from "tweetnacl";
|
|
2517
2515
|
import { fromUint8Array, toUint8Array as toUint8Array2 } from "js-base64";
|
|
2518
2516
|
import { toAESKey, aesEncrypt } from "@fileverse/crypto/webcrypto";
|
|
2519
|
-
import axios from "axios";
|
|
2520
2517
|
import { encodeFunctionData, parseEventLogs } from "viem";
|
|
2521
2518
|
var jsonToFile, appendAuthTagIvToBlob, encryptFile, getNonceAppendedCipherText, jsonToBytes, buildLinklock, encryptTitleWithFileKey, uploadFileToIPFS, getEditFileTrxCalldata, getAddFileTrxCalldata, prepareCallData, prepareDeleteFileCallData, createEncryptedContentFile, buildFileMetadata, parseFileEventLog, uploadAllFilesToIPFS;
|
|
2522
2519
|
var init_file_utils = __esm({
|
|
@@ -2615,16 +2612,21 @@ var init_file_utils = __esm({
|
|
|
2615
2612
|
body.append("ipfsType", ipfsType);
|
|
2616
2613
|
body.append("appFileId", appFileId);
|
|
2617
2614
|
body.append("sourceApp", "ddoc");
|
|
2618
|
-
const
|
|
2619
|
-
|
|
2615
|
+
const response = await fetch(UPLOAD_SERVER_URL + "upload", {
|
|
2616
|
+
method: "POST",
|
|
2620
2617
|
headers: {
|
|
2621
2618
|
Authorization: `Bearer ${token}`,
|
|
2622
2619
|
contract: contractAddress,
|
|
2623
2620
|
invoker,
|
|
2624
|
-
chain:
|
|
2625
|
-
}
|
|
2621
|
+
chain: NETWORK_NAME
|
|
2622
|
+
},
|
|
2623
|
+
body
|
|
2626
2624
|
});
|
|
2627
|
-
|
|
2625
|
+
if (!response.ok) {
|
|
2626
|
+
throw new Error(`Upload failed: ${response.status} ${response.statusText}`);
|
|
2627
|
+
}
|
|
2628
|
+
const data = await response.json();
|
|
2629
|
+
return data.ipfsHash;
|
|
2628
2630
|
};
|
|
2629
2631
|
getEditFileTrxCalldata = (args) => {
|
|
2630
2632
|
return encodeFunctionData({
|
|
@@ -2721,7 +2723,6 @@ var init_file_utils = __esm({
|
|
|
2721
2723
|
// src/sdk/file-manager.ts
|
|
2722
2724
|
import { fromUint8Array as fromUint8Array2, toUint8Array as toUint8Array3 } from "js-base64";
|
|
2723
2725
|
import { generateAESKey, exportAESKey } from "@fileverse/crypto/webcrypto";
|
|
2724
|
-
import { markdownToYjs } from "@fileverse/content-processor";
|
|
2725
2726
|
var FileManager;
|
|
2726
2727
|
var init_file_manager = __esm({
|
|
2727
2728
|
"src/sdk/file-manager.ts"() {
|
|
@@ -2738,6 +2739,32 @@ var init_file_manager = __esm({
|
|
|
2738
2739
|
this.keyStore = keyStore;
|
|
2739
2740
|
this.agentClient = agentClient;
|
|
2740
2741
|
}
|
|
2742
|
+
async convertMarkdown(content) {
|
|
2743
|
+
const g = globalThis;
|
|
2744
|
+
const saved = {
|
|
2745
|
+
window: g.window,
|
|
2746
|
+
navigator: g.navigator,
|
|
2747
|
+
document: g.document,
|
|
2748
|
+
Node: g.Node,
|
|
2749
|
+
HTMLElement: g.HTMLElement,
|
|
2750
|
+
Text: g.Text,
|
|
2751
|
+
DOMParser: g.DOMParser,
|
|
2752
|
+
Element: g.Element,
|
|
2753
|
+
DocumentFragment: g.DocumentFragment,
|
|
2754
|
+
getComputedStyle: g.getComputedStyle,
|
|
2755
|
+
MutationObserver: g.MutationObserver,
|
|
2756
|
+
Range: g.Range
|
|
2757
|
+
};
|
|
2758
|
+
try {
|
|
2759
|
+
const { markdownToYjs } = await import("@fileverse/content-processor");
|
|
2760
|
+
return markdownToYjs(content);
|
|
2761
|
+
} finally {
|
|
2762
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
2763
|
+
if (value === void 0) delete g[key];
|
|
2764
|
+
else g[key] = value;
|
|
2765
|
+
}
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2741
2768
|
createLocks(key, encryptedSecretKey, commentKey) {
|
|
2742
2769
|
const appLock = {
|
|
2743
2770
|
lockedFileKey: this.keyStore.encryptData(toUint8Array3(key)),
|
|
@@ -2781,7 +2808,7 @@ var init_file_manager = __esm({
|
|
|
2781
2808
|
const nonce = toUint8Array3(file.linkKeyNonce);
|
|
2782
2809
|
const secretKey = toUint8Array3(file.secretKey);
|
|
2783
2810
|
console.log("Got encrypted secret key, nonce, and secret key");
|
|
2784
|
-
const yJSContent =
|
|
2811
|
+
const yJSContent = await this.convertMarkdown(file.content);
|
|
2785
2812
|
console.log("Generated yjs content");
|
|
2786
2813
|
const { encryptedFile, key } = await createEncryptedContentFile(yJSContent);
|
|
2787
2814
|
console.log("Generated encrypted content file");
|
|
@@ -2841,7 +2868,7 @@ var init_file_manager = __esm({
|
|
|
2841
2868
|
const encryptedSecretKey = file.linkKey;
|
|
2842
2869
|
const nonce = toUint8Array3(file.linkKeyNonce);
|
|
2843
2870
|
const secretKey = toUint8Array3(file.secretKey);
|
|
2844
|
-
const yjsContent =
|
|
2871
|
+
const yjsContent = await this.convertMarkdown(file.content);
|
|
2845
2872
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2846
2873
|
const commentKey = toUint8Array3(file.commentKey);
|
|
2847
2874
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
@@ -2890,7 +2917,7 @@ var init_file_manager = __esm({
|
|
|
2890
2917
|
const nonce = toUint8Array3(file.linkKeyNonce);
|
|
2891
2918
|
const secretKey = toUint8Array3(file.secretKey);
|
|
2892
2919
|
logger.debug(`Generating encrypted content file for file ${file.ddocId} with onChainFileId ${file.onChainFileId}`);
|
|
2893
|
-
const yjsContent =
|
|
2920
|
+
const yjsContent = await this.convertMarkdown(file.content);
|
|
2894
2921
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2895
2922
|
const commentKey = toUint8Array3(file.commentKey);
|
|
2896
2923
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
@@ -2987,11 +3014,17 @@ var init_publish = __esm({
|
|
|
2987
3014
|
init_config();
|
|
2988
3015
|
init_pimlico_utils();
|
|
2989
3016
|
createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
|
|
3017
|
+
console.log("Creating file manager");
|
|
2990
3018
|
const keyPair = EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret));
|
|
3019
|
+
console.log("Created key pair");
|
|
2991
3020
|
const authTokenProvider = new AuthTokenProvider(keyPair, portalAddress);
|
|
3021
|
+
console.log("Created auth token provider");
|
|
2992
3022
|
const keyStore = new KeyStore(toUint8Array4(portalSeed), portalAddress, authTokenProvider);
|
|
3023
|
+
console.log("Created key store");
|
|
2993
3024
|
const agentClient = new AgentClient(authTokenProvider);
|
|
3025
|
+
console.log("Created agent client");
|
|
2994
3026
|
await agentClient.initializeAgentClient(privateAccountKey);
|
|
3027
|
+
console.log("Initialized agent client");
|
|
2995
3028
|
return new FileManager(keyStore, agentClient);
|
|
2996
3029
|
};
|
|
2997
3030
|
executeOperation = async (fileManager, file, operation) => {
|