bedrock-ts-sdk 0.0.1 → 0.0.3
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.js +28 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -522,7 +522,7 @@ var BedrockCore = class _BedrockCore {
|
|
|
522
522
|
* Get the main account's public key
|
|
523
523
|
*/
|
|
524
524
|
getPublicKey() {
|
|
525
|
-
return this.
|
|
525
|
+
return this.encryptionPrivateKey.publicKey.compressed.toString("hex");
|
|
526
526
|
}
|
|
527
527
|
/**
|
|
528
528
|
* Get the sub-account's private key (as hex string)
|
|
@@ -582,6 +582,9 @@ var BedrockCore = class _BedrockCore {
|
|
|
582
582
|
}
|
|
583
583
|
};
|
|
584
584
|
|
|
585
|
+
// src/services/file-service.ts
|
|
586
|
+
import { AlephHttpClient } from "@aleph-sdk/client";
|
|
587
|
+
|
|
585
588
|
// src/crypto/encryption.ts
|
|
586
589
|
import { encrypt as eciesEncrypt, decrypt as eciesDecrypt } from "eciesjs";
|
|
587
590
|
var CryptoUtils = class {
|
|
@@ -875,7 +878,6 @@ var EncryptionService = class {
|
|
|
875
878
|
};
|
|
876
879
|
|
|
877
880
|
// src/services/file-service.ts
|
|
878
|
-
import { AlephHttpClient } from "@aleph-sdk/client";
|
|
879
881
|
var FileService = class {
|
|
880
882
|
constructor(core) {
|
|
881
883
|
this.core = core;
|
|
@@ -917,7 +919,7 @@ var FileService = class {
|
|
|
917
919
|
}
|
|
918
920
|
const encryptedContent = await EncryptionService.encryptFile(fileBuffer, key, iv);
|
|
919
921
|
const storeResult = await aleph.uploadFile(encryptedContent);
|
|
920
|
-
const fullPath = directoryPath ? `${directoryPath}
|
|
922
|
+
const fullPath = directoryPath ? `${directoryPath}${file.path}` : file.path;
|
|
921
923
|
const createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
922
924
|
const fileMeta = {
|
|
923
925
|
name: file.name,
|
|
@@ -968,12 +970,17 @@ var FileService = class {
|
|
|
968
970
|
*/
|
|
969
971
|
async fetchFileEntries() {
|
|
970
972
|
const aleph = this.core.getAlephService();
|
|
973
|
+
const privateKey = this.core.getSubAccountPrivateKey();
|
|
971
974
|
try {
|
|
972
975
|
const aggregate = await aleph.fetchAggregate(
|
|
973
976
|
AGGREGATE_KEYS.FILE_ENTRIES,
|
|
974
977
|
FileEntriesAggregateSchema
|
|
975
978
|
);
|
|
976
|
-
return aggregate.files
|
|
979
|
+
return aggregate.files.map(({ post_hash, path, shared_with }) => ({
|
|
980
|
+
post_hash,
|
|
981
|
+
path: EncryptionService.decryptEcies(path, privateKey),
|
|
982
|
+
shared_with
|
|
983
|
+
}));
|
|
977
984
|
} catch (error) {
|
|
978
985
|
throw new FileError(`Failed to fetch file entries: ${error.message}`);
|
|
979
986
|
}
|
|
@@ -1297,12 +1304,13 @@ var FileService = class {
|
|
|
1297
1304
|
// ============================================================================
|
|
1298
1305
|
async saveFileEntries(files) {
|
|
1299
1306
|
const aleph = this.core.getAlephService();
|
|
1307
|
+
const publicKey = this.core.getPublicKey();
|
|
1300
1308
|
await aleph.updateAggregate(
|
|
1301
1309
|
AGGREGATE_KEYS.FILE_ENTRIES,
|
|
1302
1310
|
FileEntriesAggregateSchema,
|
|
1303
1311
|
async (aggregate) => {
|
|
1304
1312
|
const newEntries = files.map((f) => ({
|
|
1305
|
-
path: f.path,
|
|
1313
|
+
path: EncryptionService.encryptEcies(f.path, publicKey),
|
|
1306
1314
|
post_hash: f.post_hash,
|
|
1307
1315
|
shared_with: f.shared_with || []
|
|
1308
1316
|
}));
|
|
@@ -1314,15 +1322,17 @@ var FileService = class {
|
|
|
1314
1322
|
const key = this.core.getEncryptionKey();
|
|
1315
1323
|
const iv = EncryptionService.generateIv();
|
|
1316
1324
|
const publicKey = this.core.getPublicKey();
|
|
1325
|
+
const fileKey = Buffer.from(meta.key, "hex");
|
|
1326
|
+
const fileIv = Buffer.from(meta.iv, "hex");
|
|
1317
1327
|
return {
|
|
1318
1328
|
name: await EncryptionService.encrypt(meta.name, key, iv),
|
|
1319
|
-
path: EncryptionService.
|
|
1329
|
+
path: await EncryptionService.encrypt(meta.path, fileKey, fileIv),
|
|
1320
1330
|
key: EncryptionService.encryptEcies(meta.key, publicKey),
|
|
1321
1331
|
iv: EncryptionService.encryptEcies(meta.iv, publicKey),
|
|
1322
|
-
store_hash: meta.store_hash,
|
|
1332
|
+
store_hash: await EncryptionService.encrypt(meta.store_hash, fileKey, fileIv),
|
|
1323
1333
|
size: await EncryptionService.encrypt(meta.size.toString(), key, iv),
|
|
1324
1334
|
created_at: await EncryptionService.encrypt(meta.created_at, key, iv),
|
|
1325
|
-
deleted_at:
|
|
1335
|
+
deleted_at: await EncryptionService.encrypt(meta.deleted_at ?? "null", fileKey, fileIv),
|
|
1326
1336
|
shared_keys: meta.shared_keys
|
|
1327
1337
|
};
|
|
1328
1338
|
}
|
|
@@ -1333,15 +1343,20 @@ var FileService = class {
|
|
|
1333
1343
|
if (!privKey) {
|
|
1334
1344
|
throw new EncryptionError("Private key not available");
|
|
1335
1345
|
}
|
|
1346
|
+
const decryptedKey = EncryptionService.decryptEcies(encryptedMeta.key, privKey);
|
|
1347
|
+
const decryptedIv = EncryptionService.decryptEcies(encryptedMeta.iv, privKey);
|
|
1348
|
+
const fileKey = Buffer.from(decryptedKey, "hex");
|
|
1349
|
+
const fileIv = Buffer.from(decryptedIv, "hex");
|
|
1350
|
+
const decryptedDeletedAt = await EncryptionService.decrypt(encryptedMeta.deleted_at, fileKey, fileIv);
|
|
1336
1351
|
return {
|
|
1337
1352
|
name: await EncryptionService.decrypt(encryptedMeta.name, key, iv),
|
|
1338
|
-
path: EncryptionService.
|
|
1339
|
-
key:
|
|
1340
|
-
iv:
|
|
1341
|
-
store_hash: encryptedMeta.store_hash,
|
|
1353
|
+
path: await EncryptionService.decrypt(encryptedMeta.path, fileKey, fileIv),
|
|
1354
|
+
key: decryptedKey,
|
|
1355
|
+
iv: decryptedIv,
|
|
1356
|
+
store_hash: await EncryptionService.decrypt(encryptedMeta.store_hash, fileKey, fileIv),
|
|
1342
1357
|
size: parseInt(await EncryptionService.decrypt(encryptedMeta.size, key, iv)),
|
|
1343
1358
|
created_at: await EncryptionService.decrypt(encryptedMeta.created_at, key, iv),
|
|
1344
|
-
deleted_at:
|
|
1359
|
+
deleted_at: decryptedDeletedAt === "null" ? null : decryptedDeletedAt,
|
|
1345
1360
|
shared_keys: encryptedMeta.shared_keys || {}
|
|
1346
1361
|
};
|
|
1347
1362
|
}
|