@fileverse/api 0.0.13 → 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.
- package/dist/cli/index.js +20 -8
- package/dist/cli/index.js.map +1 -1
- package/dist/cloudflare.js +145 -47
- package/dist/cloudflare.js.map +1 -1
- package/dist/commands/index.js +21 -9
- package/dist/commands/index.js.map +1 -1
- package/dist/index.js +142 -44
- package/dist/index.js.map +1 -1
- package/dist/worker.js +128 -30
- package/dist/worker.js.map +1 -1
- package/package.json +1 -2
package/dist/cloudflare.js
CHANGED
|
@@ -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
|
-
|
|
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,
|
|
2309
|
+
const derivedKey = await deriveKeyFromAg2Hash(docId, toUint8Array2(existingNonce));
|
|
2210
2310
|
const secretKey = tweetnacl.secretbox.open(
|
|
2211
|
-
|
|
2212
|
-
|
|
2311
|
+
toUint8Array2(existingEncryptedSecretKey),
|
|
2312
|
+
toUint8Array2(existingNonce),
|
|
2213
2313
|
derivedKey
|
|
2214
2314
|
);
|
|
2215
2315
|
return {
|
|
2216
2316
|
encryptedSecretKey: existingEncryptedSecretKey,
|
|
2217
|
-
nonce:
|
|
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
|
-
|
|
2271
|
-
|
|
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(
|
|
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
|
|
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(
|
|
2457
|
-
lockedLinkKey: this.keyStore.encryptData(
|
|
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 } };
|
|
@@ -2491,8 +2591,8 @@ var init_file_manager = __esm({
|
|
|
2491
2591
|
console.log("Submitting add file trx");
|
|
2492
2592
|
logger.debug(`Preparing to add file ${file2.ddocId}`);
|
|
2493
2593
|
const encryptedSecretKey = file2.linkKey;
|
|
2494
|
-
const nonce =
|
|
2495
|
-
const secretKey =
|
|
2594
|
+
const nonce = toUint8Array3(file2.linkKeyNonce);
|
|
2595
|
+
const secretKey = toUint8Array3(file2.secretKey);
|
|
2496
2596
|
console.log("Got encrypted secret key, nonce, and secret key");
|
|
2497
2597
|
const yJSContent = markdownToYjs(file2.content);
|
|
2498
2598
|
console.log("Generated yjs content");
|
|
@@ -2503,7 +2603,7 @@ var init_file_manager = __esm({
|
|
|
2503
2603
|
console.log("Generated comment key");
|
|
2504
2604
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
2505
2605
|
console.log("Built app lock and owner lock");
|
|
2506
|
-
const linkLock = buildLinklock(secretKey,
|
|
2606
|
+
const linkLock = buildLinklock(secretKey, toUint8Array3(key), commentKey);
|
|
2507
2607
|
console.log("Built link lock");
|
|
2508
2608
|
const encryptedTitle = await encryptTitleWithFileKey({
|
|
2509
2609
|
title: file2.title || "Untitled",
|
|
@@ -2552,13 +2652,13 @@ var init_file_manager = __esm({
|
|
|
2552
2652
|
async submitUpdateFile(file2) {
|
|
2553
2653
|
logger.debug(`Submitting update for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2554
2654
|
const encryptedSecretKey = file2.linkKey;
|
|
2555
|
-
const nonce =
|
|
2556
|
-
const secretKey =
|
|
2655
|
+
const nonce = toUint8Array3(file2.linkKeyNonce);
|
|
2656
|
+
const secretKey = toUint8Array3(file2.secretKey);
|
|
2557
2657
|
const yjsContent = markdownToYjs(file2.content);
|
|
2558
2658
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2559
|
-
const commentKey =
|
|
2659
|
+
const commentKey = toUint8Array3(file2.commentKey);
|
|
2560
2660
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
2561
|
-
const linkLock = buildLinklock(secretKey,
|
|
2661
|
+
const linkLock = buildLinklock(secretKey, toUint8Array3(key), commentKey);
|
|
2562
2662
|
const encryptedTitle = await encryptTitleWithFileKey({
|
|
2563
2663
|
title: file2.title || "Untitled",
|
|
2564
2664
|
key
|
|
@@ -2600,14 +2700,14 @@ var init_file_manager = __esm({
|
|
|
2600
2700
|
async updateFile(file2) {
|
|
2601
2701
|
logger.debug(`Updating file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2602
2702
|
const encryptedSecretKey = file2.linkKey;
|
|
2603
|
-
const nonce =
|
|
2604
|
-
const secretKey =
|
|
2703
|
+
const nonce = toUint8Array3(file2.linkKeyNonce);
|
|
2704
|
+
const secretKey = toUint8Array3(file2.secretKey);
|
|
2605
2705
|
logger.debug(`Generating encrypted content file for file ${file2.ddocId} with onChainFileId ${file2.onChainFileId}`);
|
|
2606
2706
|
const yjsContent = markdownToYjs(file2.content);
|
|
2607
2707
|
const { encryptedFile, key } = await createEncryptedContentFile(yjsContent);
|
|
2608
|
-
const commentKey =
|
|
2708
|
+
const commentKey = toUint8Array3(file2.commentKey);
|
|
2609
2709
|
const { appLock, ownerLock } = this.createLocks(key, encryptedSecretKey, commentKey);
|
|
2610
|
-
const linkLock = buildLinklock(secretKey,
|
|
2710
|
+
const linkLock = buildLinklock(secretKey, toUint8Array3(key), commentKey);
|
|
2611
2711
|
const encryptedTitle = await encryptTitleWithFileKey({
|
|
2612
2712
|
title: file2.title || "Untitled",
|
|
2613
2713
|
key
|
|
@@ -2659,11 +2759,10 @@ var init_file_manager = __esm({
|
|
|
2659
2759
|
});
|
|
2660
2760
|
|
|
2661
2761
|
// src/domain/portal/publish.ts
|
|
2662
|
-
import { fromUint8Array as fromUint8Array3, toUint8Array as
|
|
2762
|
+
import { fromUint8Array as fromUint8Array3, toUint8Array as toUint8Array4 } from "js-base64";
|
|
2663
2763
|
import { stringToBytes } from "viem";
|
|
2664
2764
|
import { deriveHKDFKey } from "@fileverse/crypto/kdf";
|
|
2665
2765
|
import { generateKeyPairFromSeed } from "@stablelib/ed25519";
|
|
2666
|
-
import * as ucans2 from "@ucans/ucans";
|
|
2667
2766
|
async function getPortalData(fileId) {
|
|
2668
2767
|
const file2 = await FilesModel.findByIdIncludingDeleted(fileId);
|
|
2669
2768
|
if (!file2) {
|
|
@@ -2695,16 +2794,15 @@ var init_publish = __esm({
|
|
|
2695
2794
|
init_infra();
|
|
2696
2795
|
init_key_store();
|
|
2697
2796
|
init_auth_token_provider();
|
|
2797
|
+
init_ucan();
|
|
2698
2798
|
init_smart_agent();
|
|
2699
2799
|
init_file_manager();
|
|
2700
2800
|
init_config();
|
|
2701
2801
|
init_pimlico_utils();
|
|
2702
2802
|
createFileManager = async (portalSeed, portalAddress, ucanSecret, privateAccountKey) => {
|
|
2703
|
-
const keyPair =
|
|
2704
|
-
exportable: true
|
|
2705
|
-
});
|
|
2803
|
+
const keyPair = EdKeypair.fromSecretKey(fromUint8Array3(ucanSecret));
|
|
2706
2804
|
const authTokenProvider = new AuthTokenProvider(keyPair, portalAddress);
|
|
2707
|
-
const keyStore = new KeyStore(
|
|
2805
|
+
const keyStore = new KeyStore(toUint8Array4(portalSeed), portalAddress, authTokenProvider);
|
|
2708
2806
|
const agentClient = new AgentClient(authTokenProvider);
|
|
2709
2807
|
await agentClient.initializeAgentClient(privateAccountKey);
|
|
2710
2808
|
return new FileManager(keyStore, agentClient);
|
|
@@ -2723,7 +2821,7 @@ var init_publish = __esm({
|
|
|
2723
2821
|
handleExistingFileOp = async (fileId, operation) => {
|
|
2724
2822
|
try {
|
|
2725
2823
|
const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
|
|
2726
|
-
const apiKeySeed =
|
|
2824
|
+
const apiKeySeed = toUint8Array4(apiKey);
|
|
2727
2825
|
const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
|
|
2728
2826
|
const fileManager = await createFileManager(
|
|
2729
2827
|
portalDetails.portalSeed,
|
|
@@ -2740,7 +2838,7 @@ var init_publish = __esm({
|
|
|
2740
2838
|
handleNewFileOp = async (fileId) => {
|
|
2741
2839
|
const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
|
|
2742
2840
|
console.log("Got portal data");
|
|
2743
|
-
const apiKeySeed =
|
|
2841
|
+
const apiKeySeed = toUint8Array4(apiKey);
|
|
2744
2842
|
const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
|
|
2745
2843
|
console.log("Derived collaborator keys");
|
|
2746
2844
|
const fileManager = await createFileManager(
|
|
@@ -2754,7 +2852,7 @@ var init_publish = __esm({
|
|
|
2754
2852
|
};
|
|
2755
2853
|
getProxyAuthParams = async (fileId) => {
|
|
2756
2854
|
const { portalDetails, apiKey } = await getPortalData(fileId);
|
|
2757
|
-
const apiKeySeed =
|
|
2855
|
+
const apiKeySeed = toUint8Array4(apiKey);
|
|
2758
2856
|
const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
|
|
2759
2857
|
const fileManager = await createFileManager(
|
|
2760
2858
|
portalDetails.portalSeed,
|
|
@@ -2766,7 +2864,7 @@ var init_publish = __esm({
|
|
|
2766
2864
|
};
|
|
2767
2865
|
submitUpdateFileOp = async (fileId) => {
|
|
2768
2866
|
const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
|
|
2769
|
-
const apiKeySeed =
|
|
2867
|
+
const apiKeySeed = toUint8Array4(apiKey);
|
|
2770
2868
|
const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
|
|
2771
2869
|
const fileManager = await createFileManager(
|
|
2772
2870
|
portalDetails.portalSeed,
|
|
@@ -2778,7 +2876,7 @@ var init_publish = __esm({
|
|
|
2778
2876
|
};
|
|
2779
2877
|
submitDeleteFileOp = async (fileId) => {
|
|
2780
2878
|
const { file: file2, portalDetails, apiKey } = await getPortalData(fileId);
|
|
2781
|
-
const apiKeySeed =
|
|
2879
|
+
const apiKeySeed = toUint8Array4(apiKey);
|
|
2782
2880
|
const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
|
|
2783
2881
|
const fileManager = await createFileManager(
|
|
2784
2882
|
portalDetails.portalSeed,
|
|
@@ -2790,7 +2888,7 @@ var init_publish = __esm({
|
|
|
2790
2888
|
};
|
|
2791
2889
|
resolveFileOp = async (fileId, userOpHash, eventType) => {
|
|
2792
2890
|
const { portalDetails, apiKey } = await getPortalData(fileId);
|
|
2793
|
-
const apiKeySeed =
|
|
2891
|
+
const apiKeySeed = toUint8Array4(apiKey);
|
|
2794
2892
|
const { privateAccountKey, ucanSecret } = deriveCollaboratorKeys(apiKeySeed);
|
|
2795
2893
|
const fileManager = await createFileManager(
|
|
2796
2894
|
portalDetails.portalSeed,
|
|
@@ -3950,11 +4048,11 @@ init_esm_shims();
|
|
|
3950
4048
|
init_esm_shims();
|
|
3951
4049
|
init_constants();
|
|
3952
4050
|
import axios2 from "axios";
|
|
3953
|
-
import { toUint8Array as
|
|
4051
|
+
import { toUint8Array as toUint8Array5 } from "js-base64";
|
|
3954
4052
|
import { sha256 } from "viem";
|
|
3955
4053
|
var fetchApiKeyData = async (apiKey) => {
|
|
3956
4054
|
try {
|
|
3957
|
-
const keyHash = sha256(
|
|
4055
|
+
const keyHash = sha256(toUint8Array5(apiKey));
|
|
3958
4056
|
const fullUrl = BASE_CONFIG.API_URL + `api-access/${keyHash}`;
|
|
3959
4057
|
const response = await axios2.get(fullUrl);
|
|
3960
4058
|
const { encryptedKeyMaterial, encryptedAppMaterial, id } = response.data;
|
|
@@ -3982,7 +4080,7 @@ init_saveApiKey();
|
|
|
3982
4080
|
init_apikeys_model();
|
|
3983
4081
|
init_infra();
|
|
3984
4082
|
import { deriveHKDFKey as deriveHKDFKey2 } from "@fileverse/crypto/hkdf";
|
|
3985
|
-
import { toUint8Array as
|
|
4083
|
+
import { toUint8Array as toUint8Array6 } from "js-base64";
|
|
3986
4084
|
import { stringToBytes as stringToBytes2 } from "viem";
|
|
3987
4085
|
import { toAESKey as toAESKey2, aesDecrypt } from "@fileverse/crypto/webcrypto";
|
|
3988
4086
|
var SAVED_DATA_ENCRYPTION_KEY_INFO = "SAVED_DATA_ENCRYPTION_KEY";
|
|
@@ -4007,7 +4105,7 @@ async function initializeWithData(data) {
|
|
|
4007
4105
|
}
|
|
4008
4106
|
var getAesKeyFromApiKey = async (apiKey) => {
|
|
4009
4107
|
const rawSecret = deriveHKDFKey2(
|
|
4010
|
-
|
|
4108
|
+
toUint8Array6(apiKey),
|
|
4011
4109
|
new Uint8Array([0]),
|
|
4012
4110
|
stringToBytes2(SAVED_DATA_ENCRYPTION_KEY_INFO)
|
|
4013
4111
|
);
|
|
@@ -4018,7 +4116,7 @@ var bytestToJSON = (bytes) => {
|
|
|
4018
4116
|
};
|
|
4019
4117
|
var decryptSavedData = async (apiKey, encryptedData) => {
|
|
4020
4118
|
const aesKey = await getAesKeyFromApiKey(apiKey);
|
|
4021
|
-
const decryptedBytes = await aesDecrypt(aesKey,
|
|
4119
|
+
const decryptedBytes = await aesDecrypt(aesKey, toUint8Array6(encryptedData));
|
|
4022
4120
|
const data = bytestToJSON(decryptedBytes);
|
|
4023
4121
|
return data;
|
|
4024
4122
|
};
|
|
@@ -4240,7 +4338,7 @@ __export(external_exports, {
|
|
|
4240
4338
|
e164: () => e1642,
|
|
4241
4339
|
email: () => email2,
|
|
4242
4340
|
emoji: () => emoji2,
|
|
4243
|
-
encode: () =>
|
|
4341
|
+
encode: () => encode2,
|
|
4244
4342
|
encodeAsync: () => encodeAsync2,
|
|
4245
4343
|
endsWith: () => _endsWith,
|
|
4246
4344
|
enum: () => _enum2,
|
|
@@ -4614,7 +4712,7 @@ __export(core_exports2, {
|
|
|
4614
4712
|
decode: () => decode,
|
|
4615
4713
|
decodeAsync: () => decodeAsync,
|
|
4616
4714
|
describe: () => describe,
|
|
4617
|
-
encode: () =>
|
|
4715
|
+
encode: () => encode,
|
|
4618
4716
|
encodeAsync: () => encodeAsync,
|
|
4619
4717
|
extractDefs: () => extractDefs,
|
|
4620
4718
|
finalize: () => finalize,
|
|
@@ -5601,7 +5699,7 @@ var _encode = (_Err) => (schema, value, _ctx) => {
|
|
|
5601
5699
|
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
5602
5700
|
return _parse(_Err)(schema, value, ctx);
|
|
5603
5701
|
};
|
|
5604
|
-
var
|
|
5702
|
+
var encode = /* @__PURE__ */ _encode($ZodRealError);
|
|
5605
5703
|
var _decode = (_Err) => (schema, value, _ctx) => {
|
|
5606
5704
|
return _parse(_Err)(schema, value, _ctx);
|
|
5607
5705
|
};
|
|
@@ -16365,7 +16463,7 @@ var parse2 = /* @__PURE__ */ _parse(ZodRealError);
|
|
|
16365
16463
|
var parseAsync2 = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
16366
16464
|
var safeParse2 = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
16367
16465
|
var safeParseAsync2 = /* @__PURE__ */ _safeParseAsync(ZodRealError);
|
|
16368
|
-
var
|
|
16466
|
+
var encode2 = /* @__PURE__ */ _encode(ZodRealError);
|
|
16369
16467
|
var decode2 = /* @__PURE__ */ _decode(ZodRealError);
|
|
16370
16468
|
var encodeAsync2 = /* @__PURE__ */ _encodeAsync(ZodRealError);
|
|
16371
16469
|
var decodeAsync2 = /* @__PURE__ */ _decodeAsync(ZodRealError);
|
|
@@ -16409,7 +16507,7 @@ var ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
|
16409
16507
|
inst.parseAsync = async (data, params) => parseAsync2(inst, data, params, { callee: inst.parseAsync });
|
|
16410
16508
|
inst.safeParseAsync = async (data, params) => safeParseAsync2(inst, data, params);
|
|
16411
16509
|
inst.spa = inst.safeParseAsync;
|
|
16412
|
-
inst.encode = (data, params) =>
|
|
16510
|
+
inst.encode = (data, params) => encode2(inst, data, params);
|
|
16413
16511
|
inst.decode = (data, params) => decode2(inst, data, params);
|
|
16414
16512
|
inst.encodeAsync = async (data, params) => encodeAsync2(inst, data, params);
|
|
16415
16513
|
inst.decodeAsync = async (data, params) => decodeAsync2(inst, data, params);
|