bedrock-ts-sdk 0.0.2 → 0.0.4
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/index.d.mts +10 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +143 -262
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +143 -262
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -188,24 +188,27 @@ var FileMetaEncryptedSchema = import_zod.z.object({
|
|
|
188
188
|
// Encrypted filename
|
|
189
189
|
path: import_zod.z.string(),
|
|
190
190
|
// Encrypted path
|
|
191
|
-
key:
|
|
192
|
-
// Encrypted AES key
|
|
193
|
-
iv:
|
|
194
|
-
// Encrypted IV
|
|
195
|
-
store_hash:
|
|
196
|
-
// Aleph STORE hash
|
|
191
|
+
key: import_zod.z.string(),
|
|
192
|
+
// Encrypted AES key (ECIES encrypted)
|
|
193
|
+
iv: import_zod.z.string(),
|
|
194
|
+
// Encrypted IV (ECIES encrypted)
|
|
195
|
+
store_hash: import_zod.z.string(),
|
|
196
|
+
// Encrypted Aleph STORE hash
|
|
197
197
|
size: import_zod.z.string(),
|
|
198
198
|
// Encrypted size
|
|
199
199
|
created_at: import_zod.z.string(),
|
|
200
200
|
// Encrypted datetime
|
|
201
201
|
deleted_at: import_zod.z.string().nullable(),
|
|
202
202
|
// Encrypted datetime or null
|
|
203
|
-
shared_keys: import_zod.z.record(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
203
|
+
shared_keys: import_zod.z.record(
|
|
204
|
+
import_zod.z.string(),
|
|
205
|
+
import_zod.z.object({
|
|
206
|
+
key: import_zod.z.string(),
|
|
207
|
+
// Encrypted key for recipient
|
|
208
|
+
iv: import_zod.z.string()
|
|
209
|
+
// Encrypted IV for recipient
|
|
210
|
+
})
|
|
211
|
+
).default({})
|
|
209
212
|
});
|
|
210
213
|
var FileMetaSchema = import_zod.z.object({
|
|
211
214
|
name: import_zod.z.string(),
|
|
@@ -216,10 +219,13 @@ var FileMetaSchema = import_zod.z.object({
|
|
|
216
219
|
size: import_zod.z.number(),
|
|
217
220
|
created_at: DatetimeSchema,
|
|
218
221
|
deleted_at: DatetimeSchema.nullable(),
|
|
219
|
-
shared_keys: import_zod.z.record(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
shared_keys: import_zod.z.record(
|
|
223
|
+
import_zod.z.string(),
|
|
224
|
+
import_zod.z.object({
|
|
225
|
+
key: HexString64Schema,
|
|
226
|
+
iv: HexString32Schema
|
|
227
|
+
})
|
|
228
|
+
).default({})
|
|
223
229
|
});
|
|
224
230
|
var PublicFileMetaSchema = import_zod.z.object({
|
|
225
231
|
name: import_zod.z.string(),
|
|
@@ -264,13 +270,15 @@ var FileEntriesAggregateSchema = import_zod.z.object({
|
|
|
264
270
|
files: import_zod.z.array(FileEntrySchema).default([])
|
|
265
271
|
});
|
|
266
272
|
var SecurityAggregateSchema = import_zod.z.object({
|
|
267
|
-
authorizations: import_zod.z.array(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
273
|
+
authorizations: import_zod.z.array(
|
|
274
|
+
import_zod.z.object({
|
|
275
|
+
address: AddressSchema,
|
|
276
|
+
chain: import_zod.z.string(),
|
|
277
|
+
channels: import_zod.z.array(import_zod.z.string()).optional(),
|
|
278
|
+
post_types: import_zod.z.array(import_zod.z.string()).optional(),
|
|
279
|
+
aggregate_keys: import_zod.z.array(import_zod.z.string()).optional()
|
|
280
|
+
})
|
|
281
|
+
)
|
|
274
282
|
});
|
|
275
283
|
|
|
276
284
|
// src/client/aleph-service.ts
|
|
@@ -594,7 +602,7 @@ var BedrockCore = class _BedrockCore {
|
|
|
594
602
|
* Get the main account's public key
|
|
595
603
|
*/
|
|
596
604
|
getPublicKey() {
|
|
597
|
-
return this.encryptionPrivateKey.publicKey.
|
|
605
|
+
return this.encryptionPrivateKey.publicKey.compressed.toString("hex");
|
|
598
606
|
}
|
|
599
607
|
/**
|
|
600
608
|
* Get the sub-account's private key (as hex string)
|
|
@@ -654,6 +662,9 @@ var BedrockCore = class _BedrockCore {
|
|
|
654
662
|
}
|
|
655
663
|
};
|
|
656
664
|
|
|
665
|
+
// src/services/file-service.ts
|
|
666
|
+
var import_client3 = require("@aleph-sdk/client");
|
|
667
|
+
|
|
657
668
|
// src/crypto/encryption.ts
|
|
658
669
|
var import_eciesjs2 = require("eciesjs");
|
|
659
670
|
var CryptoUtils = class {
|
|
@@ -880,74 +891,33 @@ var EncryptionService = class {
|
|
|
880
891
|
// ============================================================================
|
|
881
892
|
static async encryptBrowser(data, key, iv) {
|
|
882
893
|
const crypto = CryptoUtils.getCrypto();
|
|
883
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
884
|
-
"raw",
|
|
885
|
-
key,
|
|
886
|
-
{ name: "AES-CBC" },
|
|
887
|
-
false,
|
|
888
|
-
["encrypt"]
|
|
889
|
-
);
|
|
894
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]);
|
|
890
895
|
const dataBuffer = Buffer.from(data, "utf-8");
|
|
891
|
-
const encrypted = await crypto.subtle.encrypt(
|
|
892
|
-
{ name: "AES-CBC", iv },
|
|
893
|
-
cryptoKey,
|
|
894
|
-
dataBuffer
|
|
895
|
-
);
|
|
896
|
+
const encrypted = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, dataBuffer);
|
|
896
897
|
return CryptoUtils.bufferToHex(Buffer.from(encrypted));
|
|
897
898
|
}
|
|
898
899
|
static async decryptBrowser(encryptedData, key, iv) {
|
|
899
900
|
const crypto = CryptoUtils.getCrypto();
|
|
900
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
901
|
-
"raw",
|
|
902
|
-
key,
|
|
903
|
-
{ name: "AES-CBC" },
|
|
904
|
-
false,
|
|
905
|
-
["decrypt"]
|
|
906
|
-
);
|
|
901
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
|
|
907
902
|
const encryptedBuffer = CryptoUtils.hexToBuffer(encryptedData);
|
|
908
|
-
const decrypted = await crypto.subtle.decrypt(
|
|
909
|
-
{ name: "AES-CBC", iv },
|
|
910
|
-
cryptoKey,
|
|
911
|
-
encryptedBuffer
|
|
912
|
-
);
|
|
903
|
+
const decrypted = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, encryptedBuffer);
|
|
913
904
|
return Buffer.from(decrypted).toString("utf-8");
|
|
914
905
|
}
|
|
915
906
|
static async encryptFileBrowser(buffer, key, iv) {
|
|
916
907
|
const crypto = CryptoUtils.getCrypto();
|
|
917
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
918
|
-
|
|
919
|
-
key,
|
|
920
|
-
{ name: "AES-CBC" },
|
|
921
|
-
false,
|
|
922
|
-
["encrypt"]
|
|
923
|
-
);
|
|
924
|
-
const encrypted = await crypto.subtle.encrypt(
|
|
925
|
-
{ name: "AES-CBC", iv },
|
|
926
|
-
cryptoKey,
|
|
927
|
-
buffer
|
|
928
|
-
);
|
|
908
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]);
|
|
909
|
+
const encrypted = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, buffer);
|
|
929
910
|
return Buffer.from(encrypted);
|
|
930
911
|
}
|
|
931
912
|
static async decryptFileBrowser(buffer, key, iv) {
|
|
932
913
|
const crypto = CryptoUtils.getCrypto();
|
|
933
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
934
|
-
|
|
935
|
-
key,
|
|
936
|
-
{ name: "AES-CBC" },
|
|
937
|
-
false,
|
|
938
|
-
["decrypt"]
|
|
939
|
-
);
|
|
940
|
-
const decrypted = await crypto.subtle.decrypt(
|
|
941
|
-
{ name: "AES-CBC", iv },
|
|
942
|
-
cryptoKey,
|
|
943
|
-
buffer
|
|
944
|
-
);
|
|
914
|
+
const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
|
|
915
|
+
const decrypted = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, buffer);
|
|
945
916
|
return Buffer.from(decrypted);
|
|
946
917
|
}
|
|
947
918
|
};
|
|
948
919
|
|
|
949
920
|
// src/services/file-service.ts
|
|
950
|
-
var import_client3 = require("@aleph-sdk/client");
|
|
951
921
|
var FileService = class {
|
|
952
922
|
constructor(core) {
|
|
953
923
|
this.core = core;
|
|
@@ -958,10 +928,7 @@ var FileService = class {
|
|
|
958
928
|
async setup() {
|
|
959
929
|
const aleph = this.core.getAlephService();
|
|
960
930
|
try {
|
|
961
|
-
await aleph.fetchAggregate(
|
|
962
|
-
AGGREGATE_KEYS.FILE_ENTRIES,
|
|
963
|
-
FileEntriesAggregateSchema
|
|
964
|
-
);
|
|
931
|
+
await aleph.fetchAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema);
|
|
965
932
|
} catch {
|
|
966
933
|
await aleph.createAggregate(AGGREGATE_KEYS.FILE_ENTRIES, { files: [] });
|
|
967
934
|
}
|
|
@@ -989,7 +956,7 @@ var FileService = class {
|
|
|
989
956
|
}
|
|
990
957
|
const encryptedContent = await EncryptionService.encryptFile(fileBuffer, key, iv);
|
|
991
958
|
const storeResult = await aleph.uploadFile(encryptedContent);
|
|
992
|
-
const fullPath = directoryPath ? `${directoryPath}
|
|
959
|
+
const fullPath = directoryPath ? `${directoryPath}${file.path}` : file.path;
|
|
993
960
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
994
961
|
const fileMeta = {
|
|
995
962
|
name: file.name,
|
|
@@ -1040,12 +1007,14 @@ var FileService = class {
|
|
|
1040
1007
|
*/
|
|
1041
1008
|
async fetchFileEntries() {
|
|
1042
1009
|
const aleph = this.core.getAlephService();
|
|
1010
|
+
const privateKey = this.core.getSubAccountPrivateKey();
|
|
1043
1011
|
try {
|
|
1044
|
-
const aggregate = await aleph.fetchAggregate(
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1012
|
+
const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema);
|
|
1013
|
+
return aggregate.files.map(({ post_hash, path, shared_with }) => ({
|
|
1014
|
+
post_hash,
|
|
1015
|
+
path: EncryptionService.decryptEcies(path, privateKey),
|
|
1016
|
+
shared_with
|
|
1017
|
+
}));
|
|
1049
1018
|
} catch (error) {
|
|
1050
1019
|
throw new FileError(`Failed to fetch file entries: ${error.message}`);
|
|
1051
1020
|
}
|
|
@@ -1167,15 +1136,9 @@ var FileService = class {
|
|
|
1167
1136
|
const aleph = this.core.getAlephService();
|
|
1168
1137
|
try {
|
|
1169
1138
|
const files = await Promise.all(filePaths.map((path) => this.getFile(path)));
|
|
1170
|
-
await aleph.updateAggregate(
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
async (aggregate) => ({
|
|
1174
|
-
files: aggregate.files.filter(
|
|
1175
|
-
(entry) => !files.some((f) => f.post_hash === entry.post_hash)
|
|
1176
|
-
)
|
|
1177
|
-
})
|
|
1178
|
-
);
|
|
1139
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1140
|
+
files: aggregate.files.filter((entry) => !files.some((f) => f.post_hash === entry.post_hash))
|
|
1141
|
+
}));
|
|
1179
1142
|
const hashesToForget = files.flatMap((f) => [f.store_hash, f.post_hash]);
|
|
1180
1143
|
await aleph.deleteFiles(hashesToForget);
|
|
1181
1144
|
} catch (error) {
|
|
@@ -1205,15 +1168,11 @@ var FileService = class {
|
|
|
1205
1168
|
}
|
|
1206
1169
|
);
|
|
1207
1170
|
const newEncryptedPath = EncryptionService.encryptEcies(newPath, publicKey);
|
|
1208
|
-
await aleph.updateAggregate(
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
|
|
1214
|
-
)
|
|
1215
|
-
})
|
|
1216
|
-
);
|
|
1171
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1172
|
+
files: aggregate.files.map(
|
|
1173
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
|
|
1174
|
+
)
|
|
1175
|
+
}));
|
|
1217
1176
|
}
|
|
1218
1177
|
} catch (error) {
|
|
1219
1178
|
throw new FileError(`Failed to move files: ${error.message}`);
|
|
@@ -1228,11 +1187,13 @@ var FileService = class {
|
|
|
1228
1187
|
try {
|
|
1229
1188
|
const sourceFile = await this.getFile(sourcePath);
|
|
1230
1189
|
const content = await this.downloadFile(sourceFile);
|
|
1231
|
-
const [newFile] = await this.uploadFiles([
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1190
|
+
const [newFile] = await this.uploadFiles([
|
|
1191
|
+
{
|
|
1192
|
+
name: newPath.split("/").pop() || newPath,
|
|
1193
|
+
path: newPath,
|
|
1194
|
+
content
|
|
1195
|
+
}
|
|
1196
|
+
]);
|
|
1236
1197
|
return newFile;
|
|
1237
1198
|
} catch (error) {
|
|
1238
1199
|
throw new FileError(`Failed to duplicate file: ${error.message}`);
|
|
@@ -1263,15 +1224,11 @@ var FileService = class {
|
|
|
1263
1224
|
return await this.encryptFileMeta(decryptedMeta);
|
|
1264
1225
|
}
|
|
1265
1226
|
);
|
|
1266
|
-
await aleph.updateAggregate(
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])] } : entry
|
|
1272
|
-
)
|
|
1273
|
-
})
|
|
1274
|
-
);
|
|
1227
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1228
|
+
files: aggregate.files.map(
|
|
1229
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])] } : entry
|
|
1230
|
+
)
|
|
1231
|
+
}));
|
|
1275
1232
|
} catch (error) {
|
|
1276
1233
|
throw new FileError(`Failed to share file: ${error.message}`);
|
|
1277
1234
|
}
|
|
@@ -1296,15 +1253,11 @@ var FileService = class {
|
|
|
1296
1253
|
return await this.encryptFileMeta(decryptedMeta);
|
|
1297
1254
|
}
|
|
1298
1255
|
);
|
|
1299
|
-
await aleph.updateAggregate(
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey) } : entry
|
|
1305
|
-
)
|
|
1306
|
-
})
|
|
1307
|
-
);
|
|
1256
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
|
|
1257
|
+
files: aggregate.files.map(
|
|
1258
|
+
(entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey) } : entry
|
|
1259
|
+
)
|
|
1260
|
+
}));
|
|
1308
1261
|
} catch (error) {
|
|
1309
1262
|
throw new FileError(`Failed to unshare file: ${error.message}`);
|
|
1310
1263
|
}
|
|
@@ -1369,51 +1322,51 @@ var FileService = class {
|
|
|
1369
1322
|
// ============================================================================
|
|
1370
1323
|
async saveFileEntries(files) {
|
|
1371
1324
|
const aleph = this.core.getAlephService();
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
return { files: [...aggregate.files, ...newEntries] };
|
|
1382
|
-
}
|
|
1383
|
-
);
|
|
1325
|
+
const publicKey = this.core.getPublicKey();
|
|
1326
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => {
|
|
1327
|
+
const newEntries = files.map((f) => ({
|
|
1328
|
+
path: EncryptionService.encryptEcies(f.path, publicKey),
|
|
1329
|
+
post_hash: f.post_hash,
|
|
1330
|
+
shared_with: f.shared_with || []
|
|
1331
|
+
}));
|
|
1332
|
+
return { files: [...aggregate.files, ...newEntries] };
|
|
1333
|
+
});
|
|
1384
1334
|
}
|
|
1385
1335
|
async encryptFileMeta(meta) {
|
|
1386
|
-
const key = this.core.getEncryptionKey();
|
|
1387
|
-
const iv = EncryptionService.generateIv();
|
|
1388
1336
|
const publicKey = this.core.getPublicKey();
|
|
1337
|
+
const fileKey = Buffer.from(meta.key, "hex");
|
|
1338
|
+
const fileIv = Buffer.from(meta.iv, "hex");
|
|
1389
1339
|
return {
|
|
1390
|
-
name: await EncryptionService.encrypt(meta.name,
|
|
1391
|
-
path: EncryptionService.
|
|
1340
|
+
name: await EncryptionService.encrypt(meta.name, fileKey, fileIv),
|
|
1341
|
+
path: await EncryptionService.encrypt(meta.path, fileKey, fileIv),
|
|
1392
1342
|
key: EncryptionService.encryptEcies(meta.key, publicKey),
|
|
1393
1343
|
iv: EncryptionService.encryptEcies(meta.iv, publicKey),
|
|
1394
|
-
store_hash: meta.store_hash,
|
|
1395
|
-
size: await EncryptionService.encrypt(meta.size.toString(),
|
|
1396
|
-
created_at: await EncryptionService.encrypt(meta.created_at,
|
|
1397
|
-
deleted_at:
|
|
1344
|
+
store_hash: await EncryptionService.encrypt(meta.store_hash, fileKey, fileIv),
|
|
1345
|
+
size: await EncryptionService.encrypt(meta.size.toString(), fileKey, fileIv),
|
|
1346
|
+
created_at: await EncryptionService.encrypt(meta.created_at, fileKey, fileIv),
|
|
1347
|
+
deleted_at: await EncryptionService.encrypt(meta.deleted_at ?? "null", fileKey, fileIv),
|
|
1398
1348
|
shared_keys: meta.shared_keys
|
|
1399
1349
|
};
|
|
1400
1350
|
}
|
|
1401
1351
|
async decryptFileMeta(encryptedMeta, privateKey) {
|
|
1402
|
-
const key = this.core.getEncryptionKey();
|
|
1403
|
-
const iv = EncryptionService.generateIv();
|
|
1404
1352
|
const privKey = privateKey || this.core.getSubAccountPrivateKey();
|
|
1405
1353
|
if (!privKey) {
|
|
1406
1354
|
throw new EncryptionError("Private key not available");
|
|
1407
1355
|
}
|
|
1356
|
+
const decryptedKey = EncryptionService.decryptEcies(encryptedMeta.key, privKey);
|
|
1357
|
+
const decryptedIv = EncryptionService.decryptEcies(encryptedMeta.iv, privKey);
|
|
1358
|
+
const fileKey = Buffer.from(decryptedKey, "hex");
|
|
1359
|
+
const fileIv = Buffer.from(decryptedIv, "hex");
|
|
1360
|
+
const decryptedDeletedAt = await EncryptionService.decrypt(encryptedMeta.deleted_at, fileKey, fileIv);
|
|
1408
1361
|
return {
|
|
1409
|
-
name: await EncryptionService.decrypt(encryptedMeta.name,
|
|
1410
|
-
path: EncryptionService.
|
|
1411
|
-
key:
|
|
1412
|
-
iv:
|
|
1413
|
-
store_hash: encryptedMeta.store_hash,
|
|
1414
|
-
size: parseInt(await EncryptionService.decrypt(encryptedMeta.size,
|
|
1415
|
-
created_at: await EncryptionService.decrypt(encryptedMeta.created_at,
|
|
1416
|
-
deleted_at:
|
|
1362
|
+
name: await EncryptionService.decrypt(encryptedMeta.name, fileKey, fileIv),
|
|
1363
|
+
path: await EncryptionService.decrypt(encryptedMeta.path, fileKey, fileIv),
|
|
1364
|
+
key: decryptedKey,
|
|
1365
|
+
iv: decryptedIv,
|
|
1366
|
+
store_hash: await EncryptionService.decrypt(encryptedMeta.store_hash, fileKey, fileIv),
|
|
1367
|
+
size: Number.parseInt(await EncryptionService.decrypt(encryptedMeta.size, fileKey, fileIv)),
|
|
1368
|
+
created_at: await EncryptionService.decrypt(encryptedMeta.created_at, fileKey, fileIv),
|
|
1369
|
+
deleted_at: decryptedDeletedAt === "null" ? null : decryptedDeletedAt,
|
|
1417
1370
|
shared_keys: encryptedMeta.shared_keys || {}
|
|
1418
1371
|
};
|
|
1419
1372
|
}
|
|
@@ -1431,10 +1384,7 @@ var ContactService = class {
|
|
|
1431
1384
|
async setup() {
|
|
1432
1385
|
const aleph = this.core.getAlephService();
|
|
1433
1386
|
try {
|
|
1434
|
-
await aleph.fetchAggregate(
|
|
1435
|
-
AGGREGATE_KEYS.CONTACTS,
|
|
1436
|
-
ContactsAggregateSchema
|
|
1437
|
-
);
|
|
1387
|
+
await aleph.fetchAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema);
|
|
1438
1388
|
} catch {
|
|
1439
1389
|
await aleph.createAggregate(AGGREGATE_KEYS.CONTACTS, { contacts: [] });
|
|
1440
1390
|
}
|
|
@@ -1445,10 +1395,7 @@ var ContactService = class {
|
|
|
1445
1395
|
async listContacts() {
|
|
1446
1396
|
const aleph = this.core.getAlephService();
|
|
1447
1397
|
try {
|
|
1448
|
-
const aggregate = await aleph.fetchAggregate(
|
|
1449
|
-
AGGREGATE_KEYS.CONTACTS,
|
|
1450
|
-
ContactsAggregateSchema
|
|
1451
|
-
);
|
|
1398
|
+
const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema);
|
|
1452
1399
|
return aggregate.contacts;
|
|
1453
1400
|
} catch (error) {
|
|
1454
1401
|
throw new ContactError(`Failed to fetch contacts: ${error.message}`);
|
|
@@ -1499,13 +1446,9 @@ var ContactService = class {
|
|
|
1499
1446
|
address,
|
|
1500
1447
|
public_key: publicKey
|
|
1501
1448
|
};
|
|
1502
|
-
await aleph.updateAggregate(
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
async (aggregate) => ({
|
|
1506
|
-
contacts: [...aggregate.contacts, newContact]
|
|
1507
|
-
})
|
|
1508
|
-
);
|
|
1449
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
|
|
1450
|
+
contacts: [...aggregate.contacts, newContact]
|
|
1451
|
+
}));
|
|
1509
1452
|
return newContact;
|
|
1510
1453
|
} catch (error) {
|
|
1511
1454
|
if (error instanceof ContactError) {
|
|
@@ -1522,13 +1465,9 @@ var ContactService = class {
|
|
|
1522
1465
|
const aleph = this.core.getAlephService();
|
|
1523
1466
|
try {
|
|
1524
1467
|
await this.getContact(publicKey);
|
|
1525
|
-
await aleph.updateAggregate(
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
async (aggregate) => ({
|
|
1529
|
-
contacts: aggregate.contacts.filter((c) => c.public_key !== publicKey)
|
|
1530
|
-
})
|
|
1531
|
-
);
|
|
1468
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
|
|
1469
|
+
contacts: aggregate.contacts.filter((c) => c.public_key !== publicKey)
|
|
1470
|
+
}));
|
|
1532
1471
|
} catch (error) {
|
|
1533
1472
|
if (error instanceof ContactError) {
|
|
1534
1473
|
throw error;
|
|
@@ -1549,15 +1488,9 @@ var ContactService = class {
|
|
|
1549
1488
|
...existingContact,
|
|
1550
1489
|
name: newName
|
|
1551
1490
|
};
|
|
1552
|
-
await aleph.updateAggregate(
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
async (aggregate) => ({
|
|
1556
|
-
contacts: aggregate.contacts.map(
|
|
1557
|
-
(c) => c.public_key === publicKey ? updatedContact : c
|
|
1558
|
-
)
|
|
1559
|
-
})
|
|
1560
|
-
);
|
|
1491
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
|
|
1492
|
+
contacts: aggregate.contacts.map((c) => c.public_key === publicKey ? updatedContact : c)
|
|
1493
|
+
}));
|
|
1561
1494
|
return updatedContact;
|
|
1562
1495
|
} catch (error) {
|
|
1563
1496
|
if (error instanceof ContactError) {
|
|
@@ -1574,9 +1507,7 @@ var ContactService = class {
|
|
|
1574
1507
|
try {
|
|
1575
1508
|
await this.getContact(publicKey);
|
|
1576
1509
|
const entries = await this.fileService.fetchFileEntries();
|
|
1577
|
-
const sharedEntries = entries.filter(
|
|
1578
|
-
(entry) => entry.shared_with.includes(publicKey)
|
|
1579
|
-
);
|
|
1510
|
+
const sharedEntries = entries.filter((entry) => entry.shared_with.includes(publicKey));
|
|
1580
1511
|
const files = await this.fileService.fetchFilesMetaFromEntries(sharedEntries);
|
|
1581
1512
|
return files;
|
|
1582
1513
|
} catch (error) {
|
|
@@ -1599,9 +1530,7 @@ var ContactService = class {
|
|
|
1599
1530
|
contact.address
|
|
1600
1531
|
// Important: contact's address, not current user's
|
|
1601
1532
|
);
|
|
1602
|
-
const sharedEntries = contactEntries.files.filter(
|
|
1603
|
-
(entry) => entry.shared_with.includes(currentUserPublicKey)
|
|
1604
|
-
);
|
|
1533
|
+
const sharedEntries = contactEntries.files.filter((entry) => entry.shared_with.includes(currentUserPublicKey));
|
|
1605
1534
|
const files = await this.fileService.fetchFilesMetaFromEntries(
|
|
1606
1535
|
sharedEntries,
|
|
1607
1536
|
contact.address
|
|
@@ -1651,10 +1580,7 @@ var KnowledgeBaseService = class {
|
|
|
1651
1580
|
async setup() {
|
|
1652
1581
|
const aleph = this.core.getAlephService();
|
|
1653
1582
|
try {
|
|
1654
|
-
await aleph.fetchAggregate(
|
|
1655
|
-
AGGREGATE_KEYS.KNOWLEDGE_BASES,
|
|
1656
|
-
KnowledgeBasesAggregateSchema
|
|
1657
|
-
);
|
|
1583
|
+
await aleph.fetchAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema);
|
|
1658
1584
|
} catch {
|
|
1659
1585
|
await aleph.createAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, { knowledge_bases: [] });
|
|
1660
1586
|
}
|
|
@@ -1665,10 +1591,7 @@ var KnowledgeBaseService = class {
|
|
|
1665
1591
|
async listKnowledgeBases() {
|
|
1666
1592
|
const aleph = this.core.getAlephService();
|
|
1667
1593
|
try {
|
|
1668
|
-
const aggregate = await aleph.fetchAggregate(
|
|
1669
|
-
AGGREGATE_KEYS.KNOWLEDGE_BASES,
|
|
1670
|
-
KnowledgeBasesAggregateSchema
|
|
1671
|
-
);
|
|
1594
|
+
const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema);
|
|
1672
1595
|
return aggregate.knowledge_bases;
|
|
1673
1596
|
} catch (error) {
|
|
1674
1597
|
throw new KnowledgeBaseError(`Failed to fetch knowledge bases: ${error.message}`);
|
|
@@ -1706,13 +1629,9 @@ var KnowledgeBaseService = class {
|
|
|
1706
1629
|
created_at: now,
|
|
1707
1630
|
updated_at: now
|
|
1708
1631
|
};
|
|
1709
|
-
await aleph.updateAggregate(
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
async (aggregate) => ({
|
|
1713
|
-
knowledge_bases: [...aggregate.knowledge_bases, newKb]
|
|
1714
|
-
})
|
|
1715
|
-
);
|
|
1632
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1633
|
+
knowledge_bases: [...aggregate.knowledge_bases, newKb]
|
|
1634
|
+
}));
|
|
1716
1635
|
return newKb;
|
|
1717
1636
|
} catch (error) {
|
|
1718
1637
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1729,13 +1648,9 @@ var KnowledgeBaseService = class {
|
|
|
1729
1648
|
const aleph = this.core.getAlephService();
|
|
1730
1649
|
try {
|
|
1731
1650
|
await this.getKnowledgeBase(name);
|
|
1732
|
-
await aleph.updateAggregate(
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
async (aggregate) => ({
|
|
1736
|
-
knowledge_bases: aggregate.knowledge_bases.filter((k) => k.name !== name)
|
|
1737
|
-
})
|
|
1738
|
-
);
|
|
1651
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1652
|
+
knowledge_bases: aggregate.knowledge_bases.filter((k) => k.name !== name)
|
|
1653
|
+
}));
|
|
1739
1654
|
} catch (error) {
|
|
1740
1655
|
if (error instanceof KnowledgeBaseError) {
|
|
1741
1656
|
throw error;
|
|
@@ -1761,15 +1676,9 @@ var KnowledgeBaseService = class {
|
|
|
1761
1676
|
name: newName,
|
|
1762
1677
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1763
1678
|
};
|
|
1764
|
-
await aleph.updateAggregate(
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
async (aggregate) => ({
|
|
1768
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1769
|
-
(k) => k.name === oldName ? updatedKb : k
|
|
1770
|
-
)
|
|
1771
|
-
})
|
|
1772
|
-
);
|
|
1679
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1680
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === oldName ? updatedKb : k)
|
|
1681
|
+
}));
|
|
1773
1682
|
return updatedKb;
|
|
1774
1683
|
} catch (error) {
|
|
1775
1684
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1792,15 +1701,9 @@ var KnowledgeBaseService = class {
|
|
|
1792
1701
|
file_paths: filePaths,
|
|
1793
1702
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1794
1703
|
};
|
|
1795
|
-
await aleph.updateAggregate(
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
async (aggregate) => ({
|
|
1799
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1800
|
-
(k) => k.name === name ? updatedKb : k
|
|
1801
|
-
)
|
|
1802
|
-
})
|
|
1803
|
-
);
|
|
1704
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1705
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
|
|
1706
|
+
}));
|
|
1804
1707
|
return updatedKb;
|
|
1805
1708
|
} catch (error) {
|
|
1806
1709
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1824,15 +1727,9 @@ var KnowledgeBaseService = class {
|
|
|
1824
1727
|
file_paths: updatedFilePaths,
|
|
1825
1728
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1826
1729
|
};
|
|
1827
|
-
await aleph.updateAggregate(
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
async (aggregate) => ({
|
|
1831
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1832
|
-
(k) => k.name === name ? updatedKb : k
|
|
1833
|
-
)
|
|
1834
|
-
})
|
|
1835
|
-
);
|
|
1730
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1731
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
|
|
1732
|
+
}));
|
|
1836
1733
|
return updatedKb;
|
|
1837
1734
|
} catch (error) {
|
|
1838
1735
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -1850,23 +1747,15 @@ var KnowledgeBaseService = class {
|
|
|
1850
1747
|
const aleph = this.core.getAlephService();
|
|
1851
1748
|
try {
|
|
1852
1749
|
const existingKb = await this.getKnowledgeBase(name);
|
|
1853
|
-
const updatedFilePaths = existingKb.file_paths.filter(
|
|
1854
|
-
(path) => !filePaths.includes(path)
|
|
1855
|
-
);
|
|
1750
|
+
const updatedFilePaths = existingKb.file_paths.filter((path) => !filePaths.includes(path));
|
|
1856
1751
|
const updatedKb = {
|
|
1857
1752
|
...existingKb,
|
|
1858
1753
|
file_paths: updatedFilePaths,
|
|
1859
1754
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1860
1755
|
};
|
|
1861
|
-
await aleph.updateAggregate(
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
async (aggregate) => ({
|
|
1865
|
-
knowledge_bases: aggregate.knowledge_bases.map(
|
|
1866
|
-
(k) => k.name === name ? updatedKb : k
|
|
1867
|
-
)
|
|
1868
|
-
})
|
|
1869
|
-
);
|
|
1756
|
+
await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
|
|
1757
|
+
knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
|
|
1758
|
+
}));
|
|
1870
1759
|
return updatedKb;
|
|
1871
1760
|
} catch (error) {
|
|
1872
1761
|
if (error instanceof KnowledgeBaseError) {
|
|
@@ -2005,11 +1894,7 @@ var BedrockClient = class _BedrockClient {
|
|
|
2005
1894
|
* WARNING: This will delete all user data from Aleph
|
|
2006
1895
|
*/
|
|
2007
1896
|
async resetAllData() {
|
|
2008
|
-
await Promise.all([
|
|
2009
|
-
this.resetFiles(),
|
|
2010
|
-
this.resetContacts(),
|
|
2011
|
-
this.resetKnowledgeBases()
|
|
2012
|
-
]);
|
|
1897
|
+
await Promise.all([this.resetFiles(), this.resetContacts(), this.resetKnowledgeBases()]);
|
|
2013
1898
|
}
|
|
2014
1899
|
/**
|
|
2015
1900
|
* Reset all files
|
|
@@ -2042,11 +1927,7 @@ var BedrockClient = class _BedrockClient {
|
|
|
2042
1927
|
* Setup all services (create aggregates if they don't exist)
|
|
2043
1928
|
*/
|
|
2044
1929
|
async setup() {
|
|
2045
|
-
await Promise.all([
|
|
2046
|
-
this.files.setup(),
|
|
2047
|
-
this.contacts.setup(),
|
|
2048
|
-
this.knowledgeBases.setup()
|
|
2049
|
-
]);
|
|
1930
|
+
await Promise.all([this.files.setup(), this.contacts.setup(), this.knowledgeBases.setup()]);
|
|
2050
1931
|
}
|
|
2051
1932
|
};
|
|
2052
1933
|
|