bedrock-ts-sdk 0.0.5 → 0.0.7

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/README.md CHANGED
@@ -109,7 +109,7 @@ const signature = await wallet.signMessage({ message: 'Bedrock.im' });
109
109
  const client = await BedrockClient.fromSignature(
110
110
  signature,
111
111
  window.ethereum,
112
- { apiServer: 'https://api2.aleph.im' }
112
+ { apiServer: 'https://poc-aleph-ccn.reza.dev' }
113
113
  );
114
114
  ```
115
115
 
@@ -132,6 +132,19 @@ const files = await client.files.uploadFiles([
132
132
  ]);
133
133
  ```
134
134
 
135
+ #### Edit Files
136
+
137
+ ```typescript
138
+ const [file] = await client.files.uploadFiles([
139
+ {
140
+ name: 'document.txt',
141
+ path: '/documents/document.txt',
142
+ content: fileBuffer, // Buffer or File
143
+ },
144
+ ]);
145
+
146
+ const editedFile = await client.files.editFileContent(file, editedFileBuffer);
147
+ ```
135
148
  #### List Files
136
149
 
137
150
  ```typescript
@@ -414,13 +427,13 @@ Bedrock uses a dual encryption approach:
414
427
  ```typescript
415
428
  const client = await BedrockClient.fromPrivateKey(privateKey, {
416
429
  channel: 'MY_CUSTOM_CHANNEL', // Default: 'bedrock'
417
- apiServer: 'https://api2.aleph.im', // Default: 'https://api2.aleph.im'
430
+ apiServer: 'https://poc-aleph-ccn.reza.dev', // Default: 'https://poc-aleph-ccn.reza.dev'
418
431
  });
419
432
  ```
420
433
 
421
434
  **Configuration Options:**
422
435
  - `channel`: Aleph channel for data isolation (default: `'bedrock'`)
423
- - `apiServer`: Aleph API server URL (default: `'https://api2.aleph.im'`)
436
+ - `apiServer`: Aleph API server URL (default: `'https://poc-aleph-ccn.reza.dev'`)
424
437
 
425
438
  ## Development
426
439
 
package/dist/index.d.mts CHANGED
@@ -80,7 +80,9 @@ declare class BedrockCore {
80
80
  * @param provider - EIP-1193 provider (for MetaMask/Rabby)
81
81
  * @param config - Optional configuration
82
82
  */
83
- static fromSignature(signatureHash: string, provider: any, config?: BedrockCoreConfig): Promise<BedrockCore>;
83
+ static fromSignature(signatureHash: string, provider: any, config?: BedrockCoreConfig & {
84
+ providerSignature?: string;
85
+ }): Promise<BedrockCore>;
84
86
  /**
85
87
  * Create BedrockCore from a private key (for testing/CLI)
86
88
  * @param privateKey - Ethereum private key (hex string with or without 0x prefix)
@@ -674,6 +676,7 @@ declare class FileService {
674
676
  * @returns Array of uploaded file info
675
677
  */
676
678
  uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
679
+ editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
677
680
  /**
678
681
  * Download and decrypt a file
679
682
  * @param fileInfo - File information
package/dist/index.d.ts CHANGED
@@ -80,7 +80,9 @@ declare class BedrockCore {
80
80
  * @param provider - EIP-1193 provider (for MetaMask/Rabby)
81
81
  * @param config - Optional configuration
82
82
  */
83
- static fromSignature(signatureHash: string, provider: any, config?: BedrockCoreConfig): Promise<BedrockCore>;
83
+ static fromSignature(signatureHash: string, provider: any, config?: BedrockCoreConfig & {
84
+ providerSignature?: string;
85
+ }): Promise<BedrockCore>;
84
86
  /**
85
87
  * Create BedrockCore from a private key (for testing/CLI)
86
88
  * @param privateKey - Ethereum private key (hex string with or without 0x prefix)
@@ -674,6 +676,7 @@ declare class FileService {
674
676
  * @returns Array of uploaded file info
675
677
  */
676
678
  uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
679
+ editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
677
680
  /**
678
681
  * Download and decrypt a file
679
682
  * @param fileInfo - File information
package/dist/index.js CHANGED
@@ -286,7 +286,7 @@ var import_client = require("@aleph-sdk/client");
286
286
  var import_message = require("@aleph-sdk/message");
287
287
  var import_zod2 = require("zod");
288
288
  var AlephService = class {
289
- constructor(account, channel = ALEPH_GENERAL_CHANNEL, apiServer = "https://api2.aleph.im") {
289
+ constructor(account, channel = ALEPH_GENERAL_CHANNEL, apiServer = "https://poc-aleph-ccn.reza.dev") {
290
290
  this.account = account;
291
291
  this.channel = channel;
292
292
  this.subAccountClient = new import_client.AuthenticatedAlephHttpClient(account, apiServer);
@@ -480,7 +480,7 @@ var BedrockCore = class _BedrockCore {
480
480
  try {
481
481
  const cfg = {
482
482
  channel: config?.channel || ALEPH_GENERAL_CHANNEL,
483
- apiServer: config?.apiServer || "https://api2.aleph.im"
483
+ apiServer: config?.apiServer || "https://poc-aleph-ccn.reza.dev"
484
484
  };
485
485
  const privateKey = import_web3.default.utils.sha3(signatureHash);
486
486
  if (!privateKey) {
@@ -494,8 +494,14 @@ var BedrockCore = class _BedrockCore {
494
494
  } else {
495
495
  throw new AuthenticationError("window.ethereum not available");
496
496
  }
497
+ } else if (config?.providerSignature === void 0) {
498
+ throw new AuthenticationError("Invalid provider");
497
499
  } else {
498
- mainAccount = await (0, import_ethereum.getAccountFromProvider)(provider);
500
+ const externalWalletPrivateKey = import_web3.default.utils.sha3(config.providerSignature);
501
+ if (externalWalletPrivateKey === void 0) {
502
+ throw new AuthenticationError("Failed to derive private key from signature");
503
+ }
504
+ mainAccount = (0, import_ethereum.importAccountFromPrivateKey)(externalWalletPrivateKey);
499
505
  }
500
506
  const subAccount = (0, import_ethereum.importAccountFromPrivateKey)(privateKey);
501
507
  await _BedrockCore.setupSecurityPermissions(mainAccount, subAccount, cfg);
@@ -514,7 +520,7 @@ var BedrockCore = class _BedrockCore {
514
520
  try {
515
521
  const cfg = {
516
522
  channel: config?.channel || ALEPH_GENERAL_CHANNEL,
517
- apiServer: config?.apiServer || "https://api2.aleph.im"
523
+ apiServer: config?.apiServer || "https://poc-aleph-ccn.reza.dev"
518
524
  };
519
525
  const key = privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`;
520
526
  const mainAccount = (0, import_ethereum.importAccountFromPrivateKey)(key);
@@ -943,8 +949,16 @@ var FileService = class {
943
949
  const aleph = this.core.getAlephService();
944
950
  const publicKey = this.core.getPublicKey();
945
951
  const uploadedFiles = [];
952
+ const existingFiles = await this.listFiles();
953
+ const filesToUpload = files.filter((file) => {
954
+ const filterIn = !existingFiles.some(
955
+ (existingFile) => !existingFile.deleted_at && existingFile.path === (directoryPath ? `${directoryPath}${file.path}` : file.path)
956
+ );
957
+ console.log(`Keeping ${file} in ? ${filterIn ? "yes" : "no"}`);
958
+ return filterIn;
959
+ });
946
960
  try {
947
- for (const file of files) {
961
+ for (const file of filesToUpload) {
948
962
  const key = EncryptionService.generateKey();
949
963
  const iv = EncryptionService.generateIv();
950
964
  let fileBuffer;
@@ -985,6 +999,39 @@ var FileService = class {
985
999
  throw new FileError(`Failed to upload files: ${error.message}`);
986
1000
  }
987
1001
  }
1002
+ async editFileContent(fileInfo, newContent) {
1003
+ const aleph = this.core.getAlephService();
1004
+ const privateKey = this.core.getSubAccountPrivateKey();
1005
+ try {
1006
+ const postResult = await aleph.updatePost(
1007
+ POST_TYPES.FILE,
1008
+ fileInfo.post_hash,
1009
+ [aleph.getAddress()],
1010
+ FileMetaEncryptedSchema,
1011
+ async (encryptedMeta) => {
1012
+ const decryptedMeta = await this.decryptFileMeta(encryptedMeta);
1013
+ const encryptedContent = await EncryptionService.encryptFile(
1014
+ newContent,
1015
+ Buffer.from(decryptedMeta.key, "hex"),
1016
+ Buffer.from(decryptedMeta.iv, "hex")
1017
+ );
1018
+ const uploadResult = await aleph.uploadFile(encryptedContent);
1019
+ decryptedMeta.store_hash = uploadResult.item_hash;
1020
+ fileInfo.store_hash = decryptedMeta.store_hash;
1021
+ return await this.encryptFileMeta(decryptedMeta);
1022
+ }
1023
+ );
1024
+ fileInfo.post_hash = postResult.item_hash;
1025
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
1026
+ files: aggregate.files.map(
1027
+ (entry) => fileInfo.path === EncryptionService.decryptEcies(entry.path, privateKey) ? { ...entry, post_hash: fileInfo.post_hash } : entry
1028
+ )
1029
+ }));
1030
+ return fileInfo;
1031
+ } catch (error) {
1032
+ throw new FileError(`Failed to edit file's content: ${error.message}`);
1033
+ }
1034
+ }
988
1035
  /**
989
1036
  * Download and decrypt a file
990
1037
  * @param fileInfo - File information
@@ -1311,7 +1358,7 @@ var FileService = class {
1311
1358
  */
1312
1359
  static async fetchPublicFileMeta(postHash) {
1313
1360
  try {
1314
- const client = new import_client3.AlephHttpClient("https://api2.aleph.im");
1361
+ const client = new import_client3.AlephHttpClient("https://poc-aleph-ccn.reza.dev");
1315
1362
  const post = await client.getPost({
1316
1363
  channels: [ALEPH_GENERAL_CHANNEL],
1317
1364
  types: [POST_TYPES.PUBLIC_FILE],
@@ -1329,7 +1376,7 @@ var FileService = class {
1329
1376
  */
1330
1377
  static async downloadPublicFile(storeHash) {
1331
1378
  try {
1332
- const client = new import_client3.AlephHttpClient("https://api2.aleph.im");
1379
+ const client = new import_client3.AlephHttpClient("https://poc-aleph-ccn.reza.dev");
1333
1380
  return await client.downloadFile(storeHash);
1334
1381
  } catch (error) {
1335
1382
  throw new FileError(`Failed to download public file: ${error.message}`);