bedrock-ts-sdk 0.0.1

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.
@@ -0,0 +1,1212 @@
1
+ import { ETHAccount } from '@aleph-sdk/ethereum';
2
+ export { ETHAccount } from '@aleph-sdk/ethereum';
3
+ import { PrivateKey } from 'eciesjs';
4
+ import { AuthenticatedAlephHttpClient } from '@aleph-sdk/client';
5
+ export { AlephHttpClient, AuthenticatedAlephHttpClient } from '@aleph-sdk/client';
6
+ import { StoreMessage, ForgetMessage, AggregateMessage, PostMessage } from '@aleph-sdk/message';
7
+ import { z } from 'zod';
8
+ export { Account } from '@aleph-sdk/account';
9
+
10
+ /**
11
+ * Low-level Aleph SDK wrapper (matches Bedrock implementation)
12
+ */
13
+ declare class AlephService {
14
+ private subAccountClient;
15
+ private account;
16
+ private channel;
17
+ constructor(account: ETHAccount, channel?: string, apiServer?: string);
18
+ /**
19
+ * Get the account address
20
+ */
21
+ getAddress(): string;
22
+ /**
23
+ * Get the account's public key
24
+ */
25
+ getPublicKey(): string;
26
+ /**
27
+ * Get the underlying Aleph client
28
+ */
29
+ getClient(): AuthenticatedAlephHttpClient;
30
+ /**
31
+ * Get the account
32
+ */
33
+ getAccount(): ETHAccount;
34
+ /**
35
+ * Upload a file to Aleph storage
36
+ * @param fileObject - File content as Buffer or File
37
+ * @returns Store message
38
+ */
39
+ uploadFile(fileObject: Buffer | File): Promise<StoreMessage>;
40
+ /**
41
+ * Download a file from Aleph storage
42
+ * @param storeHash - The STORE message item_hash
43
+ * @returns File content as ArrayBuffer
44
+ */
45
+ downloadFile(storeHash: string): Promise<ArrayBuffer>;
46
+ /**
47
+ * Delete files from Aleph storage
48
+ * @param itemHashes - Array of item hashes to forget
49
+ * @returns Forget message
50
+ */
51
+ deleteFiles(itemHashes: string[]): Promise<ForgetMessage>;
52
+ createAggregate<T extends Record<string, unknown>>(key: string, content: T): Promise<AggregateMessage<T>>;
53
+ fetchAggregate<T extends z.ZodTypeAny>(key: string, schema: T, owner?: string): Promise<z.TypeOf<T>>;
54
+ updateAggregate<S extends z.ZodTypeAny, T extends z.infer<S>>(key: string, schema: S, update_content: (content: T) => Promise<T>): Promise<AggregateMessage<T>>;
55
+ createPost<T extends Record<string, unknown>>(type: string, content: T): Promise<PostMessage<T>>;
56
+ fetchPosts<T extends z.ZodTypeAny>(type: string, schema: T, addresses?: string[], hashes?: string[]): Promise<z.TypeOf<T>[]>;
57
+ fetchPost<T extends z.ZodTypeAny>(type: string, schema: T, addresses: string[] | undefined, hash: string): Promise<z.TypeOf<T>>;
58
+ updatePost<S extends z.ZodTypeAny, T extends z.infer<S>>(type: string, hash: string, addresses: string[], schema: S, update_content: (content: T) => Promise<T>): Promise<PostMessage<T>>;
59
+ }
60
+
61
+ /**
62
+ * Configuration for BedrockCore
63
+ */
64
+ interface BedrockCoreConfig {
65
+ channel?: string;
66
+ apiServer?: string;
67
+ }
68
+ /**
69
+ * Core Bedrock functionality: authentication, sub-accounts, encryption key derivation
70
+ */
71
+ declare class BedrockCore {
72
+ private mainAccount;
73
+ private subAccount;
74
+ private alephService;
75
+ private encryptionPrivateKey;
76
+ private constructor();
77
+ /**
78
+ * Initialize from signature hash (matches Bedrock app pattern)
79
+ * @param signatureHash - Signature hash from wallet
80
+ * @param provider - EIP-1193 provider (for MetaMask/Rabby)
81
+ * @param config - Optional configuration
82
+ */
83
+ static fromSignature(signatureHash: string, provider: any, config?: BedrockCoreConfig): Promise<BedrockCore>;
84
+ /**
85
+ * Create BedrockCore from a private key (for testing/CLI)
86
+ * @param privateKey - Ethereum private key (hex string with or without 0x prefix)
87
+ * @param config - Optional configuration
88
+ */
89
+ static fromPrivateKey(privateKey: string, config?: BedrockCoreConfig): Promise<BedrockCore>;
90
+ /**
91
+ * Create BedrockCore from a wallet provider (e.g., MetaMask)
92
+ * This will automatically request signature from the user
93
+ * @param provider - EIP-1193 provider
94
+ * @param config - Optional configuration
95
+ */
96
+ static fromProvider(provider: any, config?: BedrockCoreConfig): Promise<BedrockCore>;
97
+ /**
98
+ * Get the main account
99
+ */
100
+ getMainAccount(): ETHAccount;
101
+ /**
102
+ * Get the sub-account
103
+ */
104
+ getSubAccount(): ETHAccount;
105
+ /**
106
+ * Get the AlephService instance
107
+ */
108
+ getAlephService(): AlephService;
109
+ /**
110
+ * Get the encryption key
111
+ */
112
+ getEncryptionKey(): Buffer;
113
+ /**
114
+ * Get the encryption private key
115
+ */
116
+ getEncryptionPrivateKey(): PrivateKey;
117
+ /**
118
+ * Get the main account's address
119
+ */
120
+ getMainAddress(): string;
121
+ /**
122
+ * Get the sub-account's address
123
+ */
124
+ getSubAddress(): string;
125
+ /**
126
+ * Get the main account's public key
127
+ */
128
+ getPublicKey(): string;
129
+ /**
130
+ * Get the sub-account's private key (as hex string)
131
+ */
132
+ getSubAccountPrivateKey(): string;
133
+ /**
134
+ * Setup security permissions (matches Bedrock app pattern)
135
+ */
136
+ private static setupSecurityPermissions;
137
+ }
138
+
139
+ declare const BEDROCK_MESSAGE = "Bedrock.im";
140
+ declare const SECURITY_AGGREGATE_KEY = "security";
141
+ declare const ALEPH_GENERAL_CHANNEL = "BEDROCK_STORAGE";
142
+ declare const AGGREGATE_KEYS: {
143
+ readonly FILE_ENTRIES: "bedrock_file_entries";
144
+ readonly CONTACTS: "bedrock_contacts";
145
+ readonly KNOWLEDGE_BASES: "bedrock_knowledge_bases";
146
+ readonly CREDITS: "credits";
147
+ };
148
+ declare const POST_TYPES: {
149
+ readonly FILE: "bedrock_file";
150
+ readonly PUBLIC_FILE: "bedrock_public_file";
151
+ };
152
+ /**
153
+ * 64-character hex string (32 bytes)
154
+ */
155
+ declare const HexString64Schema: z.ZodString;
156
+ /**
157
+ * 32-character hex string (16 bytes)
158
+ */
159
+ declare const HexString32Schema: z.ZodString;
160
+ /**
161
+ * ISO 8601 datetime string
162
+ */
163
+ declare const DatetimeSchema: z.ZodString;
164
+ /**
165
+ * Ethereum address
166
+ */
167
+ declare const AddressSchema: z.ZodString;
168
+ /**
169
+ * File entry in the file index aggregate
170
+ */
171
+ declare const FileEntrySchema: z.ZodObject<{
172
+ path: z.ZodString;
173
+ post_hash: z.ZodString;
174
+ shared_with: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
175
+ }, "strip", z.ZodTypeAny, {
176
+ path: string;
177
+ post_hash: string;
178
+ shared_with: string[];
179
+ }, {
180
+ path: string;
181
+ post_hash: string;
182
+ shared_with?: string[] | undefined;
183
+ }>;
184
+ type FileEntry = z.infer<typeof FileEntrySchema>;
185
+ /**
186
+ * File metadata stored in POST messages
187
+ */
188
+ declare const FileMetaEncryptedSchema: z.ZodObject<{
189
+ name: z.ZodString;
190
+ path: z.ZodString;
191
+ key: z.ZodString;
192
+ iv: z.ZodString;
193
+ store_hash: z.ZodString;
194
+ size: z.ZodString;
195
+ created_at: z.ZodString;
196
+ deleted_at: z.ZodNullable<z.ZodString>;
197
+ shared_keys: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
198
+ key: z.ZodString;
199
+ iv: z.ZodString;
200
+ }, "strip", z.ZodTypeAny, {
201
+ key: string;
202
+ iv: string;
203
+ }, {
204
+ key: string;
205
+ iv: string;
206
+ }>>>;
207
+ }, "strip", z.ZodTypeAny, {
208
+ path: string;
209
+ name: string;
210
+ key: string;
211
+ iv: string;
212
+ store_hash: string;
213
+ size: string;
214
+ created_at: string;
215
+ deleted_at: string | null;
216
+ shared_keys: Record<string, {
217
+ key: string;
218
+ iv: string;
219
+ }>;
220
+ }, {
221
+ path: string;
222
+ name: string;
223
+ key: string;
224
+ iv: string;
225
+ store_hash: string;
226
+ size: string;
227
+ created_at: string;
228
+ deleted_at: string | null;
229
+ shared_keys?: Record<string, {
230
+ key: string;
231
+ iv: string;
232
+ }> | undefined;
233
+ }>;
234
+ type FileMetaEncrypted = z.infer<typeof FileMetaEncryptedSchema>;
235
+ /**
236
+ * Decrypted file metadata
237
+ */
238
+ declare const FileMetaSchema: z.ZodObject<{
239
+ name: z.ZodString;
240
+ path: z.ZodString;
241
+ key: z.ZodString;
242
+ iv: z.ZodString;
243
+ store_hash: z.ZodString;
244
+ size: z.ZodNumber;
245
+ created_at: z.ZodString;
246
+ deleted_at: z.ZodNullable<z.ZodString>;
247
+ shared_keys: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
248
+ key: z.ZodString;
249
+ iv: z.ZodString;
250
+ }, "strip", z.ZodTypeAny, {
251
+ key: string;
252
+ iv: string;
253
+ }, {
254
+ key: string;
255
+ iv: string;
256
+ }>>>;
257
+ }, "strip", z.ZodTypeAny, {
258
+ path: string;
259
+ name: string;
260
+ key: string;
261
+ iv: string;
262
+ store_hash: string;
263
+ size: number;
264
+ created_at: string;
265
+ deleted_at: string | null;
266
+ shared_keys: Record<string, {
267
+ key: string;
268
+ iv: string;
269
+ }>;
270
+ }, {
271
+ path: string;
272
+ name: string;
273
+ key: string;
274
+ iv: string;
275
+ store_hash: string;
276
+ size: number;
277
+ created_at: string;
278
+ deleted_at: string | null;
279
+ shared_keys?: Record<string, {
280
+ key: string;
281
+ iv: string;
282
+ }> | undefined;
283
+ }>;
284
+ type FileMeta = z.infer<typeof FileMetaSchema>;
285
+ /**
286
+ * Combined file entry and metadata
287
+ */
288
+ type FileFullInfo = FileEntry & FileMeta;
289
+ /**
290
+ * Public file metadata (unencrypted, accessible by anyone)
291
+ */
292
+ declare const PublicFileMetaSchema: z.ZodObject<{
293
+ name: z.ZodString;
294
+ size: z.ZodNumber;
295
+ created_at: z.ZodString;
296
+ store_hash: z.ZodString;
297
+ username: z.ZodString;
298
+ }, "strip", z.ZodTypeAny, {
299
+ name: string;
300
+ store_hash: string;
301
+ size: number;
302
+ created_at: string;
303
+ username: string;
304
+ }, {
305
+ name: string;
306
+ store_hash: string;
307
+ size: number;
308
+ created_at: string;
309
+ username: string;
310
+ }>;
311
+ type PublicFileMeta = z.infer<typeof PublicFileMetaSchema>;
312
+ /**
313
+ * Contact information
314
+ */
315
+ declare const ContactSchema: z.ZodObject<{
316
+ name: z.ZodString;
317
+ address: z.ZodString;
318
+ public_key: z.ZodString;
319
+ }, "strip", z.ZodTypeAny, {
320
+ name: string;
321
+ address: string;
322
+ public_key: string;
323
+ }, {
324
+ name: string;
325
+ address: string;
326
+ public_key: string;
327
+ }>;
328
+ type Contact = z.infer<typeof ContactSchema>;
329
+ /**
330
+ * Contacts aggregate
331
+ */
332
+ declare const ContactsAggregateSchema: z.ZodObject<{
333
+ contacts: z.ZodDefault<z.ZodArray<z.ZodObject<{
334
+ name: z.ZodString;
335
+ address: z.ZodString;
336
+ public_key: z.ZodString;
337
+ }, "strip", z.ZodTypeAny, {
338
+ name: string;
339
+ address: string;
340
+ public_key: string;
341
+ }, {
342
+ name: string;
343
+ address: string;
344
+ public_key: string;
345
+ }>, "many">>;
346
+ }, "strip", z.ZodTypeAny, {
347
+ contacts: {
348
+ name: string;
349
+ address: string;
350
+ public_key: string;
351
+ }[];
352
+ }, {
353
+ contacts?: {
354
+ name: string;
355
+ address: string;
356
+ public_key: string;
357
+ }[] | undefined;
358
+ }>;
359
+ type ContactsAggregate = z.infer<typeof ContactsAggregateSchema>;
360
+ /**
361
+ * Knowledge base configuration
362
+ */
363
+ declare const KnowledgeBaseSchema: z.ZodObject<{
364
+ name: z.ZodString;
365
+ file_paths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
366
+ created_at: z.ZodString;
367
+ updated_at: z.ZodString;
368
+ }, "strip", z.ZodTypeAny, {
369
+ name: string;
370
+ created_at: string;
371
+ file_paths: string[];
372
+ updated_at: string;
373
+ }, {
374
+ name: string;
375
+ created_at: string;
376
+ updated_at: string;
377
+ file_paths?: string[] | undefined;
378
+ }>;
379
+ type KnowledgeBase = z.infer<typeof KnowledgeBaseSchema>;
380
+ /**
381
+ * Knowledge bases aggregate
382
+ */
383
+ declare const KnowledgeBasesAggregateSchema: z.ZodObject<{
384
+ knowledge_bases: z.ZodDefault<z.ZodArray<z.ZodObject<{
385
+ name: z.ZodString;
386
+ file_paths: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
387
+ created_at: z.ZodString;
388
+ updated_at: z.ZodString;
389
+ }, "strip", z.ZodTypeAny, {
390
+ name: string;
391
+ created_at: string;
392
+ file_paths: string[];
393
+ updated_at: string;
394
+ }, {
395
+ name: string;
396
+ created_at: string;
397
+ updated_at: string;
398
+ file_paths?: string[] | undefined;
399
+ }>, "many">>;
400
+ }, "strip", z.ZodTypeAny, {
401
+ knowledge_bases: {
402
+ name: string;
403
+ created_at: string;
404
+ file_paths: string[];
405
+ updated_at: string;
406
+ }[];
407
+ }, {
408
+ knowledge_bases?: {
409
+ name: string;
410
+ created_at: string;
411
+ updated_at: string;
412
+ file_paths?: string[] | undefined;
413
+ }[] | undefined;
414
+ }>;
415
+ type KnowledgeBasesAggregate = z.infer<typeof KnowledgeBasesAggregateSchema>;
416
+ /**
417
+ * Credit transaction record
418
+ */
419
+ declare const CreditTransactionSchema: z.ZodObject<{
420
+ id: z.ZodString;
421
+ amount: z.ZodNumber;
422
+ type: z.ZodEnum<["top_up", "deduct"]>;
423
+ timestamp: z.ZodNumber;
424
+ description: z.ZodString;
425
+ txHash: z.ZodOptional<z.ZodString>;
426
+ }, "strip", z.ZodTypeAny, {
427
+ type: "top_up" | "deduct";
428
+ id: string;
429
+ amount: number;
430
+ timestamp: number;
431
+ description: string;
432
+ txHash?: string | undefined;
433
+ }, {
434
+ type: "top_up" | "deduct";
435
+ id: string;
436
+ amount: number;
437
+ timestamp: number;
438
+ description: string;
439
+ txHash?: string | undefined;
440
+ }>;
441
+ type CreditTransaction = z.infer<typeof CreditTransactionSchema>;
442
+ /**
443
+ * User credit data
444
+ */
445
+ declare const UserCreditSchema: z.ZodObject<{
446
+ balance: z.ZodDefault<z.ZodNumber>;
447
+ transactions: z.ZodDefault<z.ZodArray<z.ZodObject<{
448
+ id: z.ZodString;
449
+ amount: z.ZodNumber;
450
+ type: z.ZodEnum<["top_up", "deduct"]>;
451
+ timestamp: z.ZodNumber;
452
+ description: z.ZodString;
453
+ txHash: z.ZodOptional<z.ZodString>;
454
+ }, "strip", z.ZodTypeAny, {
455
+ type: "top_up" | "deduct";
456
+ id: string;
457
+ amount: number;
458
+ timestamp: number;
459
+ description: string;
460
+ txHash?: string | undefined;
461
+ }, {
462
+ type: "top_up" | "deduct";
463
+ id: string;
464
+ amount: number;
465
+ timestamp: number;
466
+ description: string;
467
+ txHash?: string | undefined;
468
+ }>, "many">>;
469
+ }, "strip", z.ZodTypeAny, {
470
+ balance: number;
471
+ transactions: {
472
+ type: "top_up" | "deduct";
473
+ id: string;
474
+ amount: number;
475
+ timestamp: number;
476
+ description: string;
477
+ txHash?: string | undefined;
478
+ }[];
479
+ }, {
480
+ balance?: number | undefined;
481
+ transactions?: {
482
+ type: "top_up" | "deduct";
483
+ id: string;
484
+ amount: number;
485
+ timestamp: number;
486
+ description: string;
487
+ txHash?: string | undefined;
488
+ }[] | undefined;
489
+ }>;
490
+ type UserCredit = z.infer<typeof UserCreditSchema>;
491
+ /**
492
+ * Credit aggregate (backend-managed)
493
+ */
494
+ declare const CreditAggregateSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
495
+ balance: z.ZodDefault<z.ZodNumber>;
496
+ transactions: z.ZodDefault<z.ZodArray<z.ZodObject<{
497
+ id: z.ZodString;
498
+ amount: z.ZodNumber;
499
+ type: z.ZodEnum<["top_up", "deduct"]>;
500
+ timestamp: z.ZodNumber;
501
+ description: z.ZodString;
502
+ txHash: z.ZodOptional<z.ZodString>;
503
+ }, "strip", z.ZodTypeAny, {
504
+ type: "top_up" | "deduct";
505
+ id: string;
506
+ amount: number;
507
+ timestamp: number;
508
+ description: string;
509
+ txHash?: string | undefined;
510
+ }, {
511
+ type: "top_up" | "deduct";
512
+ id: string;
513
+ amount: number;
514
+ timestamp: number;
515
+ description: string;
516
+ txHash?: string | undefined;
517
+ }>, "many">>;
518
+ }, "strip", z.ZodTypeAny, {
519
+ balance: number;
520
+ transactions: {
521
+ type: "top_up" | "deduct";
522
+ id: string;
523
+ amount: number;
524
+ timestamp: number;
525
+ description: string;
526
+ txHash?: string | undefined;
527
+ }[];
528
+ }, {
529
+ balance?: number | undefined;
530
+ transactions?: {
531
+ type: "top_up" | "deduct";
532
+ id: string;
533
+ amount: number;
534
+ timestamp: number;
535
+ description: string;
536
+ txHash?: string | undefined;
537
+ }[] | undefined;
538
+ }>>;
539
+ type CreditAggregate = z.infer<typeof CreditAggregateSchema>;
540
+ /**
541
+ * File entries aggregate
542
+ */
543
+ declare const FileEntriesAggregateSchema: z.ZodObject<{
544
+ files: z.ZodDefault<z.ZodArray<z.ZodObject<{
545
+ path: z.ZodString;
546
+ post_hash: z.ZodString;
547
+ shared_with: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
548
+ }, "strip", z.ZodTypeAny, {
549
+ path: string;
550
+ post_hash: string;
551
+ shared_with: string[];
552
+ }, {
553
+ path: string;
554
+ post_hash: string;
555
+ shared_with?: string[] | undefined;
556
+ }>, "many">>;
557
+ }, "strip", z.ZodTypeAny, {
558
+ files: {
559
+ path: string;
560
+ post_hash: string;
561
+ shared_with: string[];
562
+ }[];
563
+ }, {
564
+ files?: {
565
+ path: string;
566
+ post_hash: string;
567
+ shared_with?: string[] | undefined;
568
+ }[] | undefined;
569
+ }>;
570
+ /**
571
+ * Sub-account authorization in security aggregate
572
+ */
573
+ declare const SecurityAggregateSchema: z.ZodObject<{
574
+ authorizations: z.ZodArray<z.ZodObject<{
575
+ address: z.ZodString;
576
+ chain: z.ZodString;
577
+ channels: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
578
+ post_types: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
579
+ aggregate_keys: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
580
+ }, "strip", z.ZodTypeAny, {
581
+ address: string;
582
+ chain: string;
583
+ channels?: string[] | undefined;
584
+ post_types?: string[] | undefined;
585
+ aggregate_keys?: string[] | undefined;
586
+ }, {
587
+ address: string;
588
+ chain: string;
589
+ channels?: string[] | undefined;
590
+ post_types?: string[] | undefined;
591
+ aggregate_keys?: string[] | undefined;
592
+ }>, "many">;
593
+ }, "strip", z.ZodTypeAny, {
594
+ authorizations: {
595
+ address: string;
596
+ chain: string;
597
+ channels?: string[] | undefined;
598
+ post_types?: string[] | undefined;
599
+ aggregate_keys?: string[] | undefined;
600
+ }[];
601
+ }, {
602
+ authorizations: {
603
+ address: string;
604
+ chain: string;
605
+ channels?: string[] | undefined;
606
+ post_types?: string[] | undefined;
607
+ aggregate_keys?: string[] | undefined;
608
+ }[];
609
+ }>;
610
+ type SecurityAggregate = z.infer<typeof SecurityAggregateSchema>;
611
+ /**
612
+ * Aleph POST message content
613
+ */
614
+ interface AlephPostContent<T = unknown> {
615
+ time: number;
616
+ type: string;
617
+ ref?: string;
618
+ content: T;
619
+ }
620
+ /**
621
+ * Aleph AGGREGATE content
622
+ */
623
+ interface AlephAggregateContent<T = unknown> {
624
+ key: string;
625
+ content: T;
626
+ }
627
+ /**
628
+ * Aleph STORE message
629
+ */
630
+ interface AlephStoreMessage {
631
+ item_hash: string;
632
+ size: number;
633
+ }
634
+ /**
635
+ * Generic Aleph message response
636
+ */
637
+ interface AlephMessage {
638
+ chain: string;
639
+ item_hash: string;
640
+ sender: string;
641
+ type: string;
642
+ channel: string;
643
+ confirmed: boolean;
644
+ content: unknown;
645
+ item_content: string;
646
+ item_type: string;
647
+ signature: string;
648
+ size: number;
649
+ time: number;
650
+ }
651
+
652
+ /**
653
+ * File input type for uploads
654
+ */
655
+ interface FileInput {
656
+ name: string;
657
+ path: string;
658
+ content: Buffer | File;
659
+ }
660
+ /**
661
+ * File service for managing encrypted files
662
+ */
663
+ declare class FileService {
664
+ private core;
665
+ constructor(core: BedrockCore);
666
+ /**
667
+ * Initialize file entries aggregate if it doesn't exist
668
+ */
669
+ setup(): Promise<void>;
670
+ /**
671
+ * Upload files with encryption
672
+ * @param files - Array of files to upload
673
+ * @param directoryPath - Optional directory path prefix
674
+ * @returns Array of uploaded file info
675
+ */
676
+ uploadFiles(files: FileInput[], directoryPath?: string): Promise<FileFullInfo[]>;
677
+ /**
678
+ * Download and decrypt a file
679
+ * @param fileInfo - File information
680
+ * @returns Decrypted file buffer
681
+ */
682
+ downloadFile(fileInfo: FileFullInfo): Promise<Buffer>;
683
+ /**
684
+ * Fetch all file entries
685
+ */
686
+ fetchFileEntries(): Promise<FileEntry[]>;
687
+ /**
688
+ * Fetch file metadata from entries
689
+ * @param entries - File entries
690
+ * @param owner - Optional owner address
691
+ * @returns Array of full file info
692
+ */
693
+ fetchFilesMetaFromEntries(entries: FileEntry[], owner?: string): Promise<FileFullInfo[]>;
694
+ /**
695
+ * List all files
696
+ * @param includeDeleted - Include soft-deleted files
697
+ */
698
+ listFiles(includeDeleted?: boolean): Promise<FileFullInfo[]>;
699
+ /**
700
+ * Get a file by path
701
+ * @param path - File path
702
+ */
703
+ getFile(path: string): Promise<FileFullInfo>;
704
+ /**
705
+ * Soft delete files
706
+ * @param filePaths - Paths of files to delete
707
+ * @param deletionDate - Optional deletion date
708
+ */
709
+ softDeleteFiles(filePaths: string[], deletionDate?: Date): Promise<void>;
710
+ /**
711
+ * Restore soft-deleted files
712
+ * @param filePaths - Paths of files to restore
713
+ */
714
+ restoreFiles(filePaths: string[]): Promise<void>;
715
+ /**
716
+ * Hard delete files (permanently remove from Aleph)
717
+ * @param filePaths - Paths of files to delete
718
+ */
719
+ hardDeleteFiles(filePaths: string[]): Promise<void>;
720
+ /**
721
+ * Move/rename files
722
+ * @param moves - Array of {oldPath, newPath} objects
723
+ */
724
+ moveFiles(moves: Array<{
725
+ oldPath: string;
726
+ newPath: string;
727
+ }>): Promise<void>;
728
+ /**
729
+ * Duplicate a file
730
+ * @param sourcePath - Source file path
731
+ * @param newPath - New file path
732
+ */
733
+ duplicateFile(sourcePath: string, newPath: string): Promise<FileFullInfo>;
734
+ /**
735
+ * Share a file with a contact
736
+ * @param filePath - File path
737
+ * @param contactPublicKey - Contact's public key
738
+ */
739
+ shareFile(filePath: string, contactPublicKey: string): Promise<void>;
740
+ /**
741
+ * Unshare a file with a contact
742
+ * @param filePath - File path
743
+ * @param contactPublicKey - Contact's public key
744
+ */
745
+ unshareFile(filePath: string, contactPublicKey: string): Promise<void>;
746
+ /**
747
+ * Share a file publicly (unencrypted, anyone can access)
748
+ * @param fileInfo - File to share publicly
749
+ * @param username - Username for attribution
750
+ * @returns Public post hash for sharing
751
+ */
752
+ shareFilePublicly(fileInfo: FileFullInfo, username: string): Promise<string>;
753
+ /**
754
+ * Fetch public file metadata (static - no auth required)
755
+ * @param postHash - Public post hash
756
+ * @returns Public file metadata or null if not found
757
+ */
758
+ static fetchPublicFileMeta(postHash: string): Promise<PublicFileMeta | null>;
759
+ /**
760
+ * Download public file (static - no auth required)
761
+ * @param storeHash - Store hash from public metadata
762
+ * @returns File content as ArrayBuffer
763
+ */
764
+ static downloadPublicFile(storeHash: string): Promise<ArrayBuffer>;
765
+ private saveFileEntries;
766
+ private encryptFileMeta;
767
+ private decryptFileMeta;
768
+ }
769
+
770
+ /**
771
+ * Contact service for managing contacts and shared files
772
+ */
773
+ declare class ContactService {
774
+ private core;
775
+ private fileService;
776
+ constructor(core: BedrockCore, fileService: FileService);
777
+ /**
778
+ * Initialize contacts aggregate if it doesn't exist
779
+ */
780
+ setup(): Promise<void>;
781
+ /**
782
+ * Fetch all contacts
783
+ */
784
+ listContacts(): Promise<Contact[]>;
785
+ /**
786
+ * Get a contact by public key
787
+ * @param publicKey - Contact's public key
788
+ */
789
+ getContact(publicKey: string): Promise<Contact>;
790
+ /**
791
+ * Get a contact by address
792
+ * @param address - Contact's Ethereum address
793
+ */
794
+ getContactByAddress(address: string): Promise<Contact>;
795
+ /**
796
+ * Add a new contact
797
+ * @param name - Contact name
798
+ * @param address - Contact's Ethereum address
799
+ * @param publicKey - Contact's public key (hex string)
800
+ */
801
+ addContact(name: string, address: string, publicKey: string): Promise<Contact>;
802
+ /**
803
+ * Remove a contact
804
+ * @param publicKey - Contact's public key
805
+ */
806
+ removeContact(publicKey: string): Promise<void>;
807
+ /**
808
+ * Update a contact's name
809
+ * @param publicKey - Contact's public key
810
+ * @param newName - New name for the contact
811
+ */
812
+ updateContactName(publicKey: string, newName: string): Promise<Contact>;
813
+ /**
814
+ * Fetch files shared by a contact
815
+ * @param publicKey - Contact's public key
816
+ */
817
+ getSharedFiles(publicKey: string): Promise<FileFullInfo[]>;
818
+ /**
819
+ * Fetch files that a contact has shared with the current user
820
+ * @param publicKey - Contact's public key
821
+ * @returns Files shared by the contact with current user
822
+ */
823
+ fetchFilesSharedByContact(publicKey: string): Promise<FileFullInfo[]>;
824
+ /**
825
+ * Share a file with a contact
826
+ * @param filePath - Path of the file to share
827
+ * @param publicKey - Contact's public key
828
+ */
829
+ shareFileWithContact(filePath: string, publicKey: string): Promise<void>;
830
+ /**
831
+ * Unshare a file with a contact
832
+ * @param filePath - Path of the file to unshare
833
+ * @param publicKey - Contact's public key
834
+ */
835
+ unshareFileWithContact(filePath: string, publicKey: string): Promise<void>;
836
+ }
837
+
838
+ /**
839
+ * Knowledge base service for organizing files into collections
840
+ */
841
+ declare class KnowledgeBaseService {
842
+ private core;
843
+ constructor(core: BedrockCore);
844
+ /**
845
+ * Initialize knowledge bases aggregate if it doesn't exist
846
+ */
847
+ setup(): Promise<void>;
848
+ /**
849
+ * Fetch all knowledge bases
850
+ */
851
+ listKnowledgeBases(): Promise<KnowledgeBase[]>;
852
+ /**
853
+ * Get a knowledge base by name
854
+ * @param name - Knowledge base name
855
+ */
856
+ getKnowledgeBase(name: string): Promise<KnowledgeBase>;
857
+ /**
858
+ * Create a new knowledge base
859
+ * @param name - Knowledge base name
860
+ * @param filePaths - Optional initial file paths
861
+ */
862
+ createKnowledgeBase(name: string, filePaths?: string[]): Promise<KnowledgeBase>;
863
+ /**
864
+ * Delete a knowledge base
865
+ * @param name - Knowledge base name
866
+ */
867
+ deleteKnowledgeBase(name: string): Promise<void>;
868
+ /**
869
+ * Rename a knowledge base
870
+ * @param oldName - Current name
871
+ * @param newName - New name
872
+ */
873
+ renameKnowledgeBase(oldName: string, newName: string): Promise<KnowledgeBase>;
874
+ /**
875
+ * Set the files in a knowledge base (replaces all existing files)
876
+ * @param name - Knowledge base name
877
+ * @param filePaths - File paths
878
+ */
879
+ setFiles(name: string, filePaths: string[]): Promise<KnowledgeBase>;
880
+ /**
881
+ * Add files to a knowledge base
882
+ * @param name - Knowledge base name
883
+ * @param filePaths - File paths to add
884
+ */
885
+ addFiles(name: string, filePaths: string[]): Promise<KnowledgeBase>;
886
+ /**
887
+ * Remove files from a knowledge base
888
+ * @param name - Knowledge base name
889
+ * @param filePaths - File paths to remove
890
+ */
891
+ removeFiles(name: string, filePaths: string[]): Promise<KnowledgeBase>;
892
+ /**
893
+ * Clear all files from a knowledge base
894
+ * @param name - Knowledge base name
895
+ */
896
+ clearFiles(name: string): Promise<KnowledgeBase>;
897
+ }
898
+
899
+ /**
900
+ * Service for managing user credits (read-only, backend-managed)
901
+ */
902
+ declare class CreditService {
903
+ private core;
904
+ private static readonly BACKEND_ADDRESS;
905
+ constructor(core: BedrockCore);
906
+ /**
907
+ * Get user's credit balance and transaction history
908
+ * @returns User credit data with balance and transactions
909
+ */
910
+ getCreditBalance(): Promise<UserCredit>;
911
+ }
912
+
913
+ /**
914
+ * Main Bedrock SDK client
915
+ *
916
+ * @example
917
+ * ```typescript
918
+ * // Initialize from private key
919
+ * const client = await BedrockClient.fromPrivateKey('0x...');
920
+ *
921
+ * // Initialize from wallet provider (MetaMask, etc.)
922
+ * const client = await BedrockClient.fromProvider(window.ethereum);
923
+ *
924
+ * // Upload files
925
+ * const files = await client.files.uploadFiles([
926
+ * { name: 'doc.txt', path: 'documents/doc.txt', content: buffer }
927
+ * ]);
928
+ *
929
+ * // List files
930
+ * const allFiles = await client.files.listFiles();
931
+ *
932
+ * // Add contact
933
+ * await client.contacts.addContact('Alice', '0x...', 'publicKey');
934
+ *
935
+ * // Create knowledge base
936
+ * await client.knowledgeBases.createKnowledgeBase('My Documents');
937
+ *
938
+ * // Check credit balance
939
+ * const balance = await client.credits.getCreditBalance();
940
+ *
941
+ * // Share file publicly
942
+ * const publicHash = await client.files.shareFilePublicly(file, 'username');
943
+ * const meta = await FileService.fetchPublicFileMeta(publicHash);
944
+ * const content = await FileService.downloadPublicFile(meta.store_hash);
945
+ *
946
+ * // Get files shared by contact
947
+ * const sharedFiles = await client.contacts.fetchFilesSharedByContact(contactPubKey);
948
+ * ```
949
+ */
950
+ declare class BedrockClient {
951
+ private core;
952
+ /**
953
+ * File operations service
954
+ */
955
+ readonly files: FileService;
956
+ /**
957
+ * Contact management service
958
+ */
959
+ readonly contacts: ContactService;
960
+ /**
961
+ * Knowledge base management service
962
+ */
963
+ readonly knowledgeBases: KnowledgeBaseService;
964
+ /**
965
+ * Credit management service
966
+ */
967
+ readonly credits: CreditService;
968
+ private constructor();
969
+ /**
970
+ * Create BedrockClient from a private key
971
+ *
972
+ * @param privateKey - Ethereum private key (hex string with or without 0x prefix)
973
+ * @param config - Optional configuration
974
+ * @returns Initialized BedrockClient
975
+ *
976
+ * @example
977
+ * ```typescript
978
+ * const client = await BedrockClient.fromPrivateKey('0xabc123...');
979
+ * ```
980
+ */
981
+ static fromPrivateKey(privateKey: string, config?: BedrockCoreConfig): Promise<BedrockClient>;
982
+ /**
983
+ * Create BedrockClient from a wallet provider (e.g., MetaMask)
984
+ *
985
+ * @param provider - EIP-1193 provider
986
+ * @param config - Optional configuration
987
+ * @returns Initialized BedrockClient
988
+ *
989
+ * @example
990
+ * ```typescript
991
+ * const client = await BedrockClient.fromProvider(window.ethereum);
992
+ * ```
993
+ */
994
+ static fromProvider(provider: any, config?: BedrockCoreConfig): Promise<BedrockClient>;
995
+ /**
996
+ * Create BedrockClient from a signature hash
997
+ *
998
+ * @param signatureHash - Signature hash from wallet
999
+ * @param provider - EIP-1193 provider
1000
+ * @param config - Optional configuration
1001
+ * @returns Initialized BedrockClient
1002
+ *
1003
+ * @example
1004
+ * ```typescript
1005
+ * const signature = await wallet.signMessage({ message: 'Bedrock.im' });
1006
+ * const client = await BedrockClient.fromSignature(signature, window.ethereum);
1007
+ * ```
1008
+ */
1009
+ static fromSignature(signatureHash: string, provider: any, config?: BedrockCoreConfig): Promise<BedrockClient>;
1010
+ /**
1011
+ * Get the main account address
1012
+ */
1013
+ getMainAddress(): string;
1014
+ /**
1015
+ * Get the sub-account address
1016
+ */
1017
+ getSubAddress(): string;
1018
+ /**
1019
+ * Get the account's public key
1020
+ */
1021
+ getPublicKey(): string;
1022
+ /**
1023
+ * Get the encryption key (32 bytes derived from signature)
1024
+ */
1025
+ getEncryptionKey(): Buffer;
1026
+ /**
1027
+ * Reset all data (files, contacts, knowledge bases)
1028
+ * WARNING: This will delete all user data from Aleph
1029
+ */
1030
+ resetAllData(): Promise<void>;
1031
+ /**
1032
+ * Reset all files
1033
+ * WARNING: This will delete all files from Aleph
1034
+ */
1035
+ resetFiles(): Promise<void>;
1036
+ /**
1037
+ * Reset all contacts
1038
+ * WARNING: This will delete all contacts
1039
+ */
1040
+ resetContacts(): Promise<void>;
1041
+ /**
1042
+ * Reset all knowledge bases
1043
+ * WARNING: This will delete all knowledge bases
1044
+ */
1045
+ resetKnowledgeBases(): Promise<void>;
1046
+ /**
1047
+ * Setup all services (create aggregates if they don't exist)
1048
+ */
1049
+ private setup;
1050
+ }
1051
+
1052
+ /**
1053
+ * Universal crypto utilities that work in both Node.js and browser
1054
+ */
1055
+ declare class CryptoUtils {
1056
+ static isBrowser: boolean;
1057
+ /**
1058
+ * Get crypto implementation (Node.js or browser)
1059
+ */
1060
+ static getCrypto(): any;
1061
+ /**
1062
+ * Generate random bytes
1063
+ */
1064
+ static getRandomBytes(length: number): Uint8Array;
1065
+ /**
1066
+ * Convert buffer to hex string
1067
+ */
1068
+ static bufferToHex(buffer: Buffer | Uint8Array): string;
1069
+ /**
1070
+ * Convert hex string to buffer
1071
+ */
1072
+ static hexToBuffer(hex: string): Buffer;
1073
+ /**
1074
+ * Hash using SHA-256
1075
+ */
1076
+ static sha256(data: string | Buffer): Promise<Buffer>;
1077
+ }
1078
+ /**
1079
+ * Encryption service for AES-256-CBC and ECIES operations
1080
+ */
1081
+ declare class EncryptionService {
1082
+ /**
1083
+ * Generate a random encryption key (32 bytes for AES-256)
1084
+ */
1085
+ static generateKey(): Buffer;
1086
+ /**
1087
+ * Generate a random initialization vector (16 bytes for AES)
1088
+ */
1089
+ static generateIv(): Buffer;
1090
+ /**
1091
+ * Encrypt data using AES-256-CBC
1092
+ * @param data - Data to encrypt
1093
+ * @param key - 32-byte encryption key
1094
+ * @param iv - 16-byte initialization vector
1095
+ * @returns Hex-encoded encrypted data
1096
+ */
1097
+ static encrypt(data: string, key: Buffer, iv: Buffer): Promise<string>;
1098
+ /**
1099
+ * Decrypt data using AES-256-CBC
1100
+ * @param encryptedData - Hex-encoded encrypted data
1101
+ * @param key - 32-byte encryption key
1102
+ * @param iv - 16-byte initialization vector
1103
+ * @returns Decrypted string
1104
+ */
1105
+ static decrypt(encryptedData: string, key: Buffer, iv: Buffer): Promise<string>;
1106
+ /**
1107
+ * Encrypt file buffer using AES-256-CBC
1108
+ * @param fileBuffer - File data as Buffer or ArrayBuffer
1109
+ * @param key - 32-byte encryption key
1110
+ * @param iv - 16-byte initialization vector
1111
+ * @returns Encrypted file buffer
1112
+ */
1113
+ static encryptFile(fileBuffer: Buffer | ArrayBuffer, key: Buffer, iv: Buffer): Promise<Buffer>;
1114
+ /**
1115
+ * Decrypt file buffer using AES-256-CBC
1116
+ * @param encryptedBuffer - Encrypted file data
1117
+ * @param key - 32-byte encryption key
1118
+ * @param iv - 16-byte initialization vector
1119
+ * @returns Decrypted file buffer
1120
+ */
1121
+ static decryptFile(encryptedBuffer: Buffer | ArrayBuffer, key: Buffer, iv: Buffer): Promise<Buffer>;
1122
+ /**
1123
+ * Encrypt data using ECIES (Elliptic Curve Integrated Encryption Scheme)
1124
+ * @param data - Data to encrypt
1125
+ * @param publicKey - Recipient's public key (hex or Buffer)
1126
+ * @returns Hex-encoded encrypted data
1127
+ */
1128
+ static encryptEcies(data: string, publicKey: string | Buffer): string;
1129
+ /**
1130
+ * Decrypt data using ECIES
1131
+ * @param encryptedData - Hex-encoded encrypted data
1132
+ * @param privateKey - Recipient's private key (hex or Buffer)
1133
+ * @returns Decrypted string
1134
+ */
1135
+ static decryptEcies(encryptedData: string, privateKey: string | Buffer): string;
1136
+ /**
1137
+ * Hash data using SHA-256
1138
+ */
1139
+ static hash(data: string | Buffer): Promise<string>;
1140
+ private static encryptNode;
1141
+ private static decryptNode;
1142
+ private static encryptFileNode;
1143
+ private static decryptFileNode;
1144
+ private static encryptBrowser;
1145
+ private static decryptBrowser;
1146
+ private static encryptFileBrowser;
1147
+ private static decryptFileBrowser;
1148
+ }
1149
+
1150
+ /**
1151
+ * Base error class for Bedrock SDK
1152
+ */
1153
+ declare class BedrockError extends Error {
1154
+ code?: string | undefined;
1155
+ constructor(message: string, code?: string | undefined);
1156
+ }
1157
+ /**
1158
+ * Authentication/authorization errors
1159
+ */
1160
+ declare class AuthenticationError extends BedrockError {
1161
+ constructor(message: string);
1162
+ }
1163
+ /**
1164
+ * Encryption/decryption errors
1165
+ */
1166
+ declare class EncryptionError extends BedrockError {
1167
+ constructor(message: string);
1168
+ }
1169
+ /**
1170
+ * File operation errors
1171
+ */
1172
+ declare class FileError extends BedrockError {
1173
+ constructor(message: string);
1174
+ }
1175
+ /**
1176
+ * File not found error
1177
+ */
1178
+ declare class FileNotFoundError extends FileError {
1179
+ constructor(path: string);
1180
+ }
1181
+ /**
1182
+ * Contact-related errors
1183
+ */
1184
+ declare class ContactError extends BedrockError {
1185
+ constructor(message: string);
1186
+ }
1187
+ /**
1188
+ * Knowledge base errors
1189
+ */
1190
+ declare class KnowledgeBaseError extends BedrockError {
1191
+ constructor(message: string);
1192
+ }
1193
+ /**
1194
+ * Credit-related errors
1195
+ */
1196
+ declare class CreditError extends BedrockError {
1197
+ constructor(message: string);
1198
+ }
1199
+ /**
1200
+ * Network/Aleph API errors
1201
+ */
1202
+ declare class NetworkError extends BedrockError {
1203
+ constructor(message: string);
1204
+ }
1205
+ /**
1206
+ * Validation errors
1207
+ */
1208
+ declare class ValidationError extends BedrockError {
1209
+ constructor(message: string);
1210
+ }
1211
+
1212
+ export { AGGREGATE_KEYS, ALEPH_GENERAL_CHANNEL, AddressSchema, type AlephAggregateContent, type AlephMessage, type AlephPostContent, AlephService, type AlephStoreMessage, AuthenticationError, BEDROCK_MESSAGE, BedrockClient, BedrockCore, type BedrockCoreConfig, BedrockError, type Contact, ContactError, ContactSchema, ContactService, type ContactsAggregate, ContactsAggregateSchema, type CreditAggregate, CreditAggregateSchema, CreditError, CreditService, type CreditTransaction, CreditTransactionSchema, CryptoUtils, DatetimeSchema, EncryptionError, EncryptionService, FileEntriesAggregateSchema, type FileEntry, FileEntrySchema, FileError, type FileFullInfo, type FileInput, type FileMeta, type FileMetaEncrypted, FileMetaEncryptedSchema, FileMetaSchema, FileNotFoundError, FileService, HexString32Schema, HexString64Schema, type KnowledgeBase, KnowledgeBaseError, KnowledgeBaseSchema, KnowledgeBaseService, type KnowledgeBasesAggregate, KnowledgeBasesAggregateSchema, NetworkError, POST_TYPES, type PublicFileMeta, PublicFileMetaSchema, SECURITY_AGGREGATE_KEY, type SecurityAggregate, SecurityAggregateSchema, type UserCredit, UserCreditSchema, ValidationError };