bedrock-ts-sdk 0.0.2 → 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 CHANGED
@@ -594,7 +594,7 @@ var BedrockCore = class _BedrockCore {
594
594
  * Get the main account's public key
595
595
  */
596
596
  getPublicKey() {
597
- return this.encryptionPrivateKey.publicKey.toHex();
597
+ return this.encryptionPrivateKey.publicKey.compressed.toString("hex");
598
598
  }
599
599
  /**
600
600
  * Get the sub-account's private key (as hex string)
@@ -654,6 +654,9 @@ var BedrockCore = class _BedrockCore {
654
654
  }
655
655
  };
656
656
 
657
+ // src/services/file-service.ts
658
+ var import_client3 = require("@aleph-sdk/client");
659
+
657
660
  // src/crypto/encryption.ts
658
661
  var import_eciesjs2 = require("eciesjs");
659
662
  var CryptoUtils = class {
@@ -947,7 +950,6 @@ var EncryptionService = class {
947
950
  };
948
951
 
949
952
  // src/services/file-service.ts
950
- var import_client3 = require("@aleph-sdk/client");
951
953
  var FileService = class {
952
954
  constructor(core) {
953
955
  this.core = core;
@@ -989,7 +991,7 @@ var FileService = class {
989
991
  }
990
992
  const encryptedContent = await EncryptionService.encryptFile(fileBuffer, key, iv);
991
993
  const storeResult = await aleph.uploadFile(encryptedContent);
992
- const fullPath = directoryPath ? `${directoryPath}/${file.path}` : file.path;
994
+ const fullPath = directoryPath ? `${directoryPath}${file.path}` : file.path;
993
995
  const createdAt = (/* @__PURE__ */ new Date()).toISOString();
994
996
  const fileMeta = {
995
997
  name: file.name,
@@ -1040,12 +1042,17 @@ var FileService = class {
1040
1042
  */
1041
1043
  async fetchFileEntries() {
1042
1044
  const aleph = this.core.getAlephService();
1045
+ const privateKey = this.core.getSubAccountPrivateKey();
1043
1046
  try {
1044
1047
  const aggregate = await aleph.fetchAggregate(
1045
1048
  AGGREGATE_KEYS.FILE_ENTRIES,
1046
1049
  FileEntriesAggregateSchema
1047
1050
  );
1048
- return aggregate.files;
1051
+ return aggregate.files.map(({ post_hash, path, shared_with }) => ({
1052
+ post_hash,
1053
+ path: EncryptionService.decryptEcies(path, privateKey),
1054
+ shared_with
1055
+ }));
1049
1056
  } catch (error) {
1050
1057
  throw new FileError(`Failed to fetch file entries: ${error.message}`);
1051
1058
  }
@@ -1369,12 +1376,13 @@ var FileService = class {
1369
1376
  // ============================================================================
1370
1377
  async saveFileEntries(files) {
1371
1378
  const aleph = this.core.getAlephService();
1379
+ const publicKey = this.core.getPublicKey();
1372
1380
  await aleph.updateAggregate(
1373
1381
  AGGREGATE_KEYS.FILE_ENTRIES,
1374
1382
  FileEntriesAggregateSchema,
1375
1383
  async (aggregate) => {
1376
1384
  const newEntries = files.map((f) => ({
1377
- path: f.path,
1385
+ path: EncryptionService.encryptEcies(f.path, publicKey),
1378
1386
  post_hash: f.post_hash,
1379
1387
  shared_with: f.shared_with || []
1380
1388
  }));
@@ -1386,15 +1394,17 @@ var FileService = class {
1386
1394
  const key = this.core.getEncryptionKey();
1387
1395
  const iv = EncryptionService.generateIv();
1388
1396
  const publicKey = this.core.getPublicKey();
1397
+ const fileKey = Buffer.from(meta.key, "hex");
1398
+ const fileIv = Buffer.from(meta.iv, "hex");
1389
1399
  return {
1390
1400
  name: await EncryptionService.encrypt(meta.name, key, iv),
1391
- path: EncryptionService.encryptEcies(meta.path, publicKey),
1401
+ path: await EncryptionService.encrypt(meta.path, fileKey, fileIv),
1392
1402
  key: EncryptionService.encryptEcies(meta.key, publicKey),
1393
1403
  iv: EncryptionService.encryptEcies(meta.iv, publicKey),
1394
- store_hash: meta.store_hash,
1404
+ store_hash: await EncryptionService.encrypt(meta.store_hash, fileKey, fileIv),
1395
1405
  size: await EncryptionService.encrypt(meta.size.toString(), key, iv),
1396
1406
  created_at: await EncryptionService.encrypt(meta.created_at, key, iv),
1397
- deleted_at: meta.deleted_at ? await EncryptionService.encrypt(meta.deleted_at, key, iv) : null,
1407
+ deleted_at: await EncryptionService.encrypt(meta.deleted_at ?? "null", fileKey, fileIv),
1398
1408
  shared_keys: meta.shared_keys
1399
1409
  };
1400
1410
  }
@@ -1405,15 +1415,20 @@ var FileService = class {
1405
1415
  if (!privKey) {
1406
1416
  throw new EncryptionError("Private key not available");
1407
1417
  }
1418
+ const decryptedKey = EncryptionService.decryptEcies(encryptedMeta.key, privKey);
1419
+ const decryptedIv = EncryptionService.decryptEcies(encryptedMeta.iv, privKey);
1420
+ const fileKey = Buffer.from(decryptedKey, "hex");
1421
+ const fileIv = Buffer.from(decryptedIv, "hex");
1422
+ const decryptedDeletedAt = await EncryptionService.decrypt(encryptedMeta.deleted_at, fileKey, fileIv);
1408
1423
  return {
1409
1424
  name: await EncryptionService.decrypt(encryptedMeta.name, key, iv),
1410
- path: EncryptionService.decryptEcies(encryptedMeta.path, privKey),
1411
- key: EncryptionService.decryptEcies(encryptedMeta.key, privKey),
1412
- iv: EncryptionService.decryptEcies(encryptedMeta.iv, privKey),
1413
- store_hash: encryptedMeta.store_hash,
1425
+ path: await EncryptionService.decrypt(encryptedMeta.path, fileKey, fileIv),
1426
+ key: decryptedKey,
1427
+ iv: decryptedIv,
1428
+ store_hash: await EncryptionService.decrypt(encryptedMeta.store_hash, fileKey, fileIv),
1414
1429
  size: parseInt(await EncryptionService.decrypt(encryptedMeta.size, key, iv)),
1415
1430
  created_at: await EncryptionService.decrypt(encryptedMeta.created_at, key, iv),
1416
- deleted_at: encryptedMeta.deleted_at ? await EncryptionService.decrypt(encryptedMeta.deleted_at, key, iv) : null,
1431
+ deleted_at: decryptedDeletedAt === "null" ? null : decryptedDeletedAt,
1417
1432
  shared_keys: encryptedMeta.shared_keys || {}
1418
1433
  };
1419
1434
  }