bedrock-ts-sdk 0.0.6 → 0.0.8
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 +3 -3
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +48 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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://
|
|
112
|
+
{ apiServer: 'https://poc-aleph-ccn.reza.dev' }
|
|
113
113
|
);
|
|
114
114
|
```
|
|
115
115
|
|
|
@@ -427,13 +427,13 @@ Bedrock uses a dual encryption approach:
|
|
|
427
427
|
```typescript
|
|
428
428
|
const client = await BedrockClient.fromPrivateKey(privateKey, {
|
|
429
429
|
channel: 'MY_CUSTOM_CHANNEL', // Default: 'bedrock'
|
|
430
|
-
apiServer: 'https://
|
|
430
|
+
apiServer: 'https://poc-aleph-ccn.reza.dev', // Default: 'https://poc-aleph-ccn.reza.dev'
|
|
431
431
|
});
|
|
432
432
|
```
|
|
433
433
|
|
|
434
434
|
**Configuration Options:**
|
|
435
435
|
- `channel`: Aleph channel for data isolation (default: `'bedrock'`)
|
|
436
|
-
- `apiServer`: Aleph API server URL (default: `'https://
|
|
436
|
+
- `apiServer`: Aleph API server URL (default: `'https://poc-aleph-ccn.reza.dev'`)
|
|
437
437
|
|
|
438
438
|
## Development
|
|
439
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
|
|
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)
|
|
@@ -672,6 +674,7 @@ declare class FileService {
|
|
|
672
674
|
* @param files - Array of files to upload
|
|
673
675
|
* @param directoryPath - Optional directory path prefix
|
|
674
676
|
* @returns Array of uploaded file info
|
|
677
|
+
* @throws FileConflictError if any file path conflicts with non-trashed file
|
|
675
678
|
*/
|
|
676
679
|
uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
|
|
677
680
|
editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
|
|
@@ -711,6 +714,7 @@ declare class FileService {
|
|
|
711
714
|
/**
|
|
712
715
|
* Restore soft-deleted files
|
|
713
716
|
* @param filePaths - Paths of files to restore
|
|
717
|
+
* @throws FileConflictError if any file path conflicts with non-trashed file
|
|
714
718
|
*/
|
|
715
719
|
restoreFiles(filePaths: string[]): Promise<void>;
|
|
716
720
|
/**
|
|
@@ -721,6 +725,7 @@ declare class FileService {
|
|
|
721
725
|
/**
|
|
722
726
|
* Move/rename files
|
|
723
727
|
* @param moves - Array of {oldPath, newPath} objects
|
|
728
|
+
* @throws FileConflictError if any newPath conflicts with non-trashed file
|
|
724
729
|
*/
|
|
725
730
|
moveFiles(moves: Array<{
|
|
726
731
|
oldPath: string;
|
|
@@ -763,6 +768,12 @@ declare class FileService {
|
|
|
763
768
|
* @returns File content as ArrayBuffer
|
|
764
769
|
*/
|
|
765
770
|
static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
|
|
771
|
+
/**
|
|
772
|
+
* Check for path conflicts with non-trashed files
|
|
773
|
+
* @param paths - Paths to check
|
|
774
|
+
* @throws FileConflictError on first conflict
|
|
775
|
+
*/
|
|
776
|
+
private checkPathConflicts;
|
|
766
777
|
private saveFileEntries;
|
|
767
778
|
private encryptFileMeta;
|
|
768
779
|
private decryptFileMeta;
|
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
|
|
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)
|
|
@@ -672,6 +674,7 @@ declare class FileService {
|
|
|
672
674
|
* @param files - Array of files to upload
|
|
673
675
|
* @param directoryPath - Optional directory path prefix
|
|
674
676
|
* @returns Array of uploaded file info
|
|
677
|
+
* @throws FileConflictError if any file path conflicts with non-trashed file
|
|
675
678
|
*/
|
|
676
679
|
uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
|
|
677
680
|
editFileContent(fileInfo: FileFullInfo, newContent: Buffer): Promise<FileFullInfo>;
|
|
@@ -711,6 +714,7 @@ declare class FileService {
|
|
|
711
714
|
/**
|
|
712
715
|
* Restore soft-deleted files
|
|
713
716
|
* @param filePaths - Paths of files to restore
|
|
717
|
+
* @throws FileConflictError if any file path conflicts with non-trashed file
|
|
714
718
|
*/
|
|
715
719
|
restoreFiles(filePaths: string[]): Promise<void>;
|
|
716
720
|
/**
|
|
@@ -721,6 +725,7 @@ declare class FileService {
|
|
|
721
725
|
/**
|
|
722
726
|
* Move/rename files
|
|
723
727
|
* @param moves - Array of {oldPath, newPath} objects
|
|
728
|
+
* @throws FileConflictError if any newPath conflicts with non-trashed file
|
|
724
729
|
*/
|
|
725
730
|
moveFiles(moves: Array<{
|
|
726
731
|
oldPath: string;
|
|
@@ -763,6 +768,12 @@ declare class FileService {
|
|
|
763
768
|
* @returns File content as ArrayBuffer
|
|
764
769
|
*/
|
|
765
770
|
static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
|
|
771
|
+
/**
|
|
772
|
+
* Check for path conflicts with non-trashed files
|
|
773
|
+
* @param paths - Paths to check
|
|
774
|
+
* @throws FileConflictError on first conflict
|
|
775
|
+
*/
|
|
776
|
+
private checkPathConflicts;
|
|
766
777
|
private saveFileEntries;
|
|
767
778
|
private encryptFileMeta;
|
|
768
779
|
private decryptFileMeta;
|
package/dist/index.js
CHANGED
|
@@ -121,6 +121,14 @@ var FileNotFoundError = class _FileNotFoundError extends FileError {
|
|
|
121
121
|
Object.setPrototypeOf(this, _FileNotFoundError.prototype);
|
|
122
122
|
}
|
|
123
123
|
};
|
|
124
|
+
var FileConflictError = class _FileConflictError extends FileError {
|
|
125
|
+
constructor(path) {
|
|
126
|
+
super(`File path conflict: ${path} already exists`);
|
|
127
|
+
this.name = "FileConflictError";
|
|
128
|
+
this.code = "FILE_CONFLICT";
|
|
129
|
+
Object.setPrototypeOf(this, _FileConflictError.prototype);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
124
132
|
var ContactError = class _ContactError extends BedrockError {
|
|
125
133
|
constructor(message) {
|
|
126
134
|
super(message, "CONTACT_ERROR");
|
|
@@ -286,7 +294,7 @@ var import_client = require("@aleph-sdk/client");
|
|
|
286
294
|
var import_message = require("@aleph-sdk/message");
|
|
287
295
|
var import_zod2 = require("zod");
|
|
288
296
|
var AlephService = class {
|
|
289
|
-
constructor(account, channel = ALEPH_GENERAL_CHANNEL, apiServer = "https://
|
|
297
|
+
constructor(account, channel = ALEPH_GENERAL_CHANNEL, apiServer = "https://poc-aleph-ccn.reza.dev") {
|
|
290
298
|
this.account = account;
|
|
291
299
|
this.channel = channel;
|
|
292
300
|
this.subAccountClient = new import_client.AuthenticatedAlephHttpClient(account, apiServer);
|
|
@@ -480,7 +488,7 @@ var BedrockCore = class _BedrockCore {
|
|
|
480
488
|
try {
|
|
481
489
|
const cfg = {
|
|
482
490
|
channel: config?.channel || ALEPH_GENERAL_CHANNEL,
|
|
483
|
-
apiServer: config?.apiServer || "https://
|
|
491
|
+
apiServer: config?.apiServer || "https://poc-aleph-ccn.reza.dev"
|
|
484
492
|
};
|
|
485
493
|
const privateKey = import_web3.default.utils.sha3(signatureHash);
|
|
486
494
|
if (!privateKey) {
|
|
@@ -494,8 +502,14 @@ var BedrockCore = class _BedrockCore {
|
|
|
494
502
|
} else {
|
|
495
503
|
throw new AuthenticationError("window.ethereum not available");
|
|
496
504
|
}
|
|
505
|
+
} else if (config?.providerSignature === void 0) {
|
|
506
|
+
throw new AuthenticationError("Invalid provider");
|
|
497
507
|
} else {
|
|
498
|
-
|
|
508
|
+
const externalWalletPrivateKey = import_web3.default.utils.sha3(config.providerSignature);
|
|
509
|
+
if (externalWalletPrivateKey === void 0) {
|
|
510
|
+
throw new AuthenticationError("Failed to derive private key from signature");
|
|
511
|
+
}
|
|
512
|
+
mainAccount = (0, import_ethereum.importAccountFromPrivateKey)(externalWalletPrivateKey);
|
|
499
513
|
}
|
|
500
514
|
const subAccount = (0, import_ethereum.importAccountFromPrivateKey)(privateKey);
|
|
501
515
|
await _BedrockCore.setupSecurityPermissions(mainAccount, subAccount, cfg);
|
|
@@ -514,7 +528,7 @@ var BedrockCore = class _BedrockCore {
|
|
|
514
528
|
try {
|
|
515
529
|
const cfg = {
|
|
516
530
|
channel: config?.channel || ALEPH_GENERAL_CHANNEL,
|
|
517
|
-
apiServer: config?.apiServer || "https://
|
|
531
|
+
apiServer: config?.apiServer || "https://poc-aleph-ccn.reza.dev"
|
|
518
532
|
};
|
|
519
533
|
const key = privateKey.startsWith("0x") ? privateKey : `0x${privateKey}`;
|
|
520
534
|
const mainAccount = (0, import_ethereum.importAccountFromPrivateKey)(key);
|
|
@@ -938,21 +952,16 @@ var FileService = class {
|
|
|
938
952
|
* @param files - Array of files to upload
|
|
939
953
|
* @param directoryPath - Optional directory path prefix
|
|
940
954
|
* @returns Array of uploaded file info
|
|
955
|
+
* @throws FileConflictError if any file path conflicts with non-trashed file
|
|
941
956
|
*/
|
|
942
957
|
async uploadFiles(files, directoryPath = "") {
|
|
943
958
|
const aleph = this.core.getAlephService();
|
|
944
959
|
const publicKey = this.core.getPublicKey();
|
|
945
960
|
const uploadedFiles = [];
|
|
946
|
-
const
|
|
947
|
-
|
|
948
|
-
const filterIn = !existingFiles.some(
|
|
949
|
-
(existingFile) => !existingFile.deleted_at && existingFile.path === (directoryPath ? `${directoryPath}${file.path}` : file.path)
|
|
950
|
-
);
|
|
951
|
-
console.log(`Keeping ${file} in ? ${filterIn ? "yes" : "no"}`);
|
|
952
|
-
return filterIn;
|
|
953
|
-
});
|
|
961
|
+
const fullPaths = files.map((f) => directoryPath ? `${directoryPath}${f.path}` : f.path);
|
|
962
|
+
await this.checkPathConflicts(fullPaths);
|
|
954
963
|
try {
|
|
955
|
-
for (const file of
|
|
964
|
+
for (const file of files) {
|
|
956
965
|
const key = EncryptionService.generateKey();
|
|
957
966
|
const iv = EncryptionService.generateIv();
|
|
958
967
|
let fileBuffer;
|
|
@@ -1152,9 +1161,11 @@ var FileService = class {
|
|
|
1152
1161
|
/**
|
|
1153
1162
|
* Restore soft-deleted files
|
|
1154
1163
|
* @param filePaths - Paths of files to restore
|
|
1164
|
+
* @throws FileConflictError if any file path conflicts with non-trashed file
|
|
1155
1165
|
*/
|
|
1156
1166
|
async restoreFiles(filePaths) {
|
|
1157
1167
|
const aleph = this.core.getAlephService();
|
|
1168
|
+
await this.checkPathConflicts(filePaths);
|
|
1158
1169
|
try {
|
|
1159
1170
|
for (const path of filePaths) {
|
|
1160
1171
|
const file = await this.getFile(path);
|
|
@@ -1199,10 +1210,18 @@ var FileService = class {
|
|
|
1199
1210
|
/**
|
|
1200
1211
|
* Move/rename files
|
|
1201
1212
|
* @param moves - Array of {oldPath, newPath} objects
|
|
1213
|
+
* @throws FileConflictError if any newPath conflicts with non-trashed file
|
|
1202
1214
|
*/
|
|
1203
1215
|
async moveFiles(moves) {
|
|
1204
1216
|
const aleph = this.core.getAlephService();
|
|
1205
1217
|
const publicKey = this.core.getPublicKey();
|
|
1218
|
+
const existingFiles = await this.listFiles(false);
|
|
1219
|
+
const existingPaths = new Set(existingFiles.map((f) => f.path));
|
|
1220
|
+
for (const { oldPath, newPath } of moves) {
|
|
1221
|
+
if (existingPaths.has(newPath) && newPath !== oldPath) {
|
|
1222
|
+
throw new FileConflictError(newPath);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1206
1225
|
try {
|
|
1207
1226
|
for (const { oldPath, newPath } of moves) {
|
|
1208
1227
|
const file = await this.getFile(oldPath);
|
|
@@ -1352,7 +1371,7 @@ var FileService = class {
|
|
|
1352
1371
|
*/
|
|
1353
1372
|
static async fetchPublicFileMeta(postHash) {
|
|
1354
1373
|
try {
|
|
1355
|
-
const client = new import_client3.AlephHttpClient("https://
|
|
1374
|
+
const client = new import_client3.AlephHttpClient("https://poc-aleph-ccn.reza.dev");
|
|
1356
1375
|
const post = await client.getPost({
|
|
1357
1376
|
channels: [ALEPH_GENERAL_CHANNEL],
|
|
1358
1377
|
types: [POST_TYPES.PUBLIC_FILE],
|
|
@@ -1370,7 +1389,7 @@ var FileService = class {
|
|
|
1370
1389
|
*/
|
|
1371
1390
|
static async downloadPublicFile(storeHash) {
|
|
1372
1391
|
try {
|
|
1373
|
-
const client = new import_client3.AlephHttpClient("https://
|
|
1392
|
+
const client = new import_client3.AlephHttpClient("https://poc-aleph-ccn.reza.dev");
|
|
1374
1393
|
return await client.downloadFile(storeHash);
|
|
1375
1394
|
} catch (error) {
|
|
1376
1395
|
throw new FileError(`Failed to download public file: ${error.message}`);
|
|
@@ -1379,6 +1398,20 @@ var FileService = class {
|
|
|
1379
1398
|
// ============================================================================
|
|
1380
1399
|
// Private helper methods
|
|
1381
1400
|
// ============================================================================
|
|
1401
|
+
/**
|
|
1402
|
+
* Check for path conflicts with non-trashed files
|
|
1403
|
+
* @param paths - Paths to check
|
|
1404
|
+
* @throws FileConflictError on first conflict
|
|
1405
|
+
*/
|
|
1406
|
+
async checkPathConflicts(paths) {
|
|
1407
|
+
const existingFiles = await this.listFiles(false);
|
|
1408
|
+
const existingPaths = new Set(existingFiles.map((f) => f.path));
|
|
1409
|
+
for (const path of paths) {
|
|
1410
|
+
if (existingPaths.has(path)) {
|
|
1411
|
+
throw new FileConflictError(path);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1382
1415
|
async saveFileEntries(files) {
|
|
1383
1416
|
const aleph = this.core.getAlephService();
|
|
1384
1417
|
const publicKey = this.core.getPublicKey();
|