@brightchain/brightchain-lib 0.1.0 → 0.1.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.
- package/README.md +348 -87
- package/package.json +15 -1
- package/src/browser.d.ts +5 -1
- package/src/browser.d.ts.map +1 -1
- package/src/browser.js +10 -2
- package/src/browser.js.map +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.d.ts.map +1 -1
- package/src/index.js +2 -1
- package/src/index.js.map +1 -1
- package/src/lib/blockPaddingTransform.d.ts +2 -2
- package/src/lib/blockPaddingTransform.d.ts.map +1 -1
- package/src/lib/blockPaddingTransform.js +26 -9
- package/src/lib/blockPaddingTransform.js.map +1 -1
- package/src/lib/blocks/base.d.ts +1 -1
- package/src/lib/blocks/base.d.ts.map +1 -1
- package/src/lib/blocks/encryptedBlockFactory.d.ts +2 -2
- package/src/lib/blocks/encryptedBlockFactory.d.ts.map +1 -1
- package/src/lib/blocks/encryptedBlockFactory.js +22 -16
- package/src/lib/blocks/encryptedBlockFactory.js.map +1 -1
- package/src/lib/blocks/ephemeral.d.ts +1 -1
- package/src/lib/blocks/ephemeral.d.ts.map +1 -1
- package/src/lib/blocks/ephemeral.js +8 -5
- package/src/lib/blocks/ephemeral.js.map +1 -1
- package/src/lib/blocks/memoryTuple.d.ts +12 -12
- package/src/lib/blocks/memoryTuple.d.ts.map +1 -1
- package/src/lib/blocks/memoryTuple.js +29 -15
- package/src/lib/blocks/memoryTuple.js.map +1 -1
- package/src/lib/blocks/random.d.ts +9 -13
- package/src/lib/blocks/random.d.ts.map +1 -1
- package/src/lib/blocks/random.js +25 -24
- package/src/lib/blocks/random.js.map +1 -1
- package/src/lib/blocks/rawData.d.ts +1 -5
- package/src/lib/blocks/rawData.d.ts.map +1 -1
- package/src/lib/blocks/rawData.js +8 -8
- package/src/lib/blocks/rawData.js.map +1 -1
- package/src/lib/blocks/whitened.d.ts +12 -12
- package/src/lib/blocks/whitened.d.ts.map +1 -1
- package/src/lib/blocks/whitened.js +32 -20
- package/src/lib/blocks/whitened.js.map +1 -1
- package/src/lib/browserBrightChain.d.ts +30 -0
- package/src/lib/browserBrightChain.d.ts.map +1 -0
- package/src/lib/browserBrightChain.js +82 -0
- package/src/lib/browserBrightChain.js.map +1 -0
- package/src/lib/browserCrypto.d.ts +9 -0
- package/src/lib/browserCrypto.d.ts.map +1 -0
- package/src/lib/browserCrypto.js +34 -0
- package/src/lib/browserCrypto.js.map +1 -0
- package/src/lib/browserKeyring.d.ts +21 -0
- package/src/lib/browserKeyring.d.ts.map +1 -0
- package/src/lib/browserKeyring.js +133 -0
- package/src/lib/browserKeyring.js.map +1 -0
- package/src/lib/browserStream.d.ts +40 -0
- package/src/lib/browserStream.d.ts.map +1 -0
- package/src/lib/browserStream.js +154 -0
- package/src/lib/browserStream.js.map +1 -0
- package/src/lib/cblStream.d.ts +2 -2
- package/src/lib/cblStream.d.ts.map +1 -1
- package/src/lib/cblStream.js +21 -43
- package/src/lib/cblStream.js.map +1 -1
- package/src/lib/enumerations/systemKeyringErrorType.d.ts +2 -1
- package/src/lib/enumerations/systemKeyringErrorType.d.ts.map +1 -1
- package/src/lib/enumerations/systemKeyringErrorType.js +1 -0
- package/src/lib/enumerations/systemKeyringErrorType.js.map +1 -1
- package/src/lib/errors/systemKeyringError.d.ts.map +1 -1
- package/src/lib/errors/systemKeyringError.js +1 -0
- package/src/lib/errors/systemKeyringError.js.map +1 -1
- package/src/lib/interfaces/blocks/base.d.ts +1 -1
- package/src/lib/interfaces/blocks/base.d.ts.map +1 -1
- package/src/lib/interfaces/keyringEntry.d.ts +3 -3
- package/src/lib/interfaces/keyringEntry.d.ts.map +1 -1
- package/src/lib/primeTupleGeneratorStream.d.ts +2 -2
- package/src/lib/primeTupleGeneratorStream.d.ts.map +1 -1
- package/src/lib/primeTupleGeneratorStream.js +19 -9
- package/src/lib/primeTupleGeneratorStream.js.map +1 -1
- package/src/lib/secureHeapStorage.d.ts.map +1 -1
- package/src/lib/secureHeapStorage.js +8 -5
- package/src/lib/secureHeapStorage.js.map +1 -1
- package/src/lib/services/fec.service.js +4 -4
- package/src/lib/services/fec.service.js.map +1 -1
- package/src/lib/services/tuple.service.d.ts +5 -5
- package/src/lib/services/tuple.service.d.ts.map +1 -1
- package/src/lib/services/tuple.service.js +47 -38
- package/src/lib/services/tuple.service.js.map +1 -1
- package/src/lib/systemKeyring.d.ts +3 -11
- package/src/lib/systemKeyring.d.ts.map +1 -1
- package/src/lib/systemKeyring.js +7 -95
- package/src/lib/systemKeyring.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,144 +1,405 @@
|
|
|
1
|
-
#
|
|
1
|
+
# BrightChain Library
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://badge.fury.io/js/%40brightchain%2Fbrightchain-lib)
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
**BrightChain** is a revolutionary cryptographic ecosystem that reimagines digital governance, storage, and communication. At its core, it implements the Owner-Free File System (OFFS) with advanced cryptographic features including ECIES encryption, homomorphic voting capabilities, and brokered anonymity.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
## 🌟 Key Features
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
### 🔐 Unified Cryptographic Architecture
|
|
11
|
+
- **ECIES Integration**: Elliptic Curve Integrated Encryption Scheme for secure messaging and file storage
|
|
12
|
+
- **Homomorphic Encryption**: Paillier keys derived from ECDH keypairs for secure voting and computation
|
|
13
|
+
- **Brokered Anonymity**: Forward Error Correction with quorum-based identity recovery
|
|
10
14
|
|
|
11
|
-
###
|
|
15
|
+
### 📦 Owner-Free File System (OFFS)
|
|
16
|
+
- **Block-based Storage**: Files broken into encrypted blocks with XOR randomization
|
|
17
|
+
- **Deduplication**: SHA-512 based block identification prevents duplicate storage
|
|
18
|
+
- **Distributed Architecture**: Decentralized storage with no single point of failure
|
|
12
19
|
|
|
13
|
-
|
|
20
|
+
### ⚡ Energy-Efficient Design
|
|
21
|
+
- **Joule Currency**: All operations measured in actual energy consumption
|
|
22
|
+
- **Proof of Work Throttling**: Bad actors face increased computational requirements
|
|
23
|
+
- **Sustainable Operations**: Optimized for minimal energy consumption
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
- **ECIES**: Elliptic Curve Integrated Encryption Scheme settings
|
|
17
|
-
- **CHECKSUM**: SHA3 checksum configuration
|
|
18
|
-
- **ENCRYPTION**: Base encryption settings
|
|
19
|
-
- **KEYRING**: Keyring algorithm configuration
|
|
20
|
-
- **UINT sizes**: Standard unsigned integer sizes and max values
|
|
21
|
-
- **VOTING**: Paillier homomorphic encryption for voting
|
|
25
|
+
## 🚀 Quick Start
|
|
22
26
|
|
|
23
|
-
###
|
|
27
|
+
### Installation
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
```bash
|
|
30
|
+
npm install @brightchain/brightchain-lib
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Basic Usage
|
|
26
34
|
|
|
27
|
-
#### CBL (Constituent Block List)
|
|
28
|
-
Constants for managing constituent block lists:
|
|
29
35
|
```typescript
|
|
30
|
-
import {
|
|
36
|
+
import { BrightChain, BlockSize } from '@brightchain/brightchain-lib';
|
|
37
|
+
|
|
38
|
+
// Initialize BrightChain
|
|
39
|
+
const brightChain = new BrightChain(BlockSize.Small);
|
|
40
|
+
|
|
41
|
+
// Store a file
|
|
42
|
+
const fileData = new TextEncoder().encode("Hello, BrightChain!");
|
|
43
|
+
const receipt = await brightChain.storeFile(fileData, "greeting.txt");
|
|
44
|
+
|
|
45
|
+
console.log(`File stored with ID: ${receipt.id}`);
|
|
46
|
+
console.log(`Magnet URL: ${receipt.magnetUrl}`);
|
|
31
47
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
CBL.MIME_TYPE_PATTERN // Regex for valid MIME types
|
|
48
|
+
// Retrieve the file
|
|
49
|
+
const retrievedData = await brightChain.retrieveFile(receipt);
|
|
50
|
+
const retrievedText = new TextDecoder().decode(retrievedData);
|
|
51
|
+
console.log(`Retrieved: ${retrievedText}`);
|
|
37
52
|
```
|
|
38
53
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
## 📚 Core Concepts
|
|
55
|
+
|
|
56
|
+
### Block Types
|
|
57
|
+
|
|
58
|
+
BrightChain supports several block types for different use cases:
|
|
59
|
+
|
|
60
|
+
- **RawDataBlock**: Unencrypted data blocks
|
|
61
|
+
- **EncryptedBlock**: ECIES-encrypted blocks with single or multiple recipients
|
|
62
|
+
- **ConstituentBlockList (CBL)**: Metadata blocks that reference other blocks
|
|
63
|
+
- **EphemeralBlock**: Temporary blocks for processing
|
|
64
|
+
- **WhitenedBlock**: XOR-randomized blocks for anonymization
|
|
65
|
+
|
|
66
|
+
### Block Sizes
|
|
43
67
|
|
|
44
|
-
|
|
68
|
+
```typescript
|
|
69
|
+
import { BlockSize } from '@brightchain/brightchain-lib';
|
|
70
|
+
|
|
71
|
+
// Available block sizes
|
|
72
|
+
BlockSize.Tiny // 1024 bytes
|
|
73
|
+
BlockSize.Small // 8192 bytes
|
|
74
|
+
BlockSize.Medium // 32768 bytes
|
|
75
|
+
BlockSize.Large // 131072 bytes
|
|
76
|
+
BlockSize.Huge // 524288 bytes
|
|
77
|
+
BlockSize.Message // 1024 bytes (alias for Tiny)
|
|
45
78
|
```
|
|
46
79
|
|
|
47
|
-
|
|
48
|
-
|
|
80
|
+
### Encryption Types
|
|
81
|
+
|
|
49
82
|
```typescript
|
|
50
|
-
import {
|
|
83
|
+
import { BlockEncryptionType } from '@brightchain/brightchain-lib';
|
|
51
84
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
TUPLE.RANDOM_BLOCKS_PER_TUPLE // 2
|
|
85
|
+
BlockEncryptionType.None // No encryption
|
|
86
|
+
BlockEncryptionType.SingleRecipient // Single recipient ECIES
|
|
87
|
+
BlockEncryptionType.MultiRecipient // Multiple recipient ECIES
|
|
56
88
|
```
|
|
57
89
|
|
|
58
|
-
|
|
59
|
-
Constants for sealing operations:
|
|
60
|
-
```typescript
|
|
61
|
-
import { SEALING } from 'brightchain-lib';
|
|
90
|
+
## 🔧 Advanced Usage
|
|
62
91
|
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
### Working with Encrypted Blocks
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import {
|
|
96
|
+
EncryptedBlock,
|
|
97
|
+
BlockType,
|
|
98
|
+
BlockDataType,
|
|
99
|
+
BlockSize,
|
|
100
|
+
Member,
|
|
101
|
+
MemberType
|
|
102
|
+
} from '@brightchain/brightchain-lib';
|
|
103
|
+
|
|
104
|
+
// Create a member (user) with cryptographic keys
|
|
105
|
+
const eciesService = ServiceProvider.getInstance().eciesService;
|
|
106
|
+
const member = Member.newMember(
|
|
107
|
+
eciesService,
|
|
108
|
+
MemberType.User,
|
|
109
|
+
'Alice',
|
|
110
|
+
new EmailString('alice@example.com')
|
|
111
|
+
).member;
|
|
112
|
+
|
|
113
|
+
// Create encrypted data
|
|
114
|
+
const plaintext = new TextEncoder().encode("Secret message");
|
|
115
|
+
const encryptedData = await eciesService.encryptSimpleOrSingle(
|
|
116
|
+
true,
|
|
117
|
+
member.publicKey,
|
|
118
|
+
plaintext
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
// Create encrypted block
|
|
122
|
+
const block = await EncryptedBlock.from(
|
|
123
|
+
BlockType.EncryptedOwnedDataBlock,
|
|
124
|
+
BlockDataType.EncryptedData,
|
|
125
|
+
BlockSize.Small,
|
|
126
|
+
encryptedData,
|
|
127
|
+
checksumService.calculateChecksum(encryptedData),
|
|
128
|
+
member
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// Decrypt the block
|
|
132
|
+
const decryptedBlock = await block.decrypt(BlockType.RawDataBlock);
|
|
65
133
|
```
|
|
66
134
|
|
|
67
|
-
|
|
68
|
-
|
|
135
|
+
### Constituent Block Lists (CBL)
|
|
136
|
+
|
|
137
|
+
CBLs are metadata blocks that reference other blocks, enabling complex file structures:
|
|
138
|
+
|
|
69
139
|
```typescript
|
|
70
|
-
import {
|
|
140
|
+
import { ConstituentBlockListBlock, CBLService } from '@brightchain/brightchain-lib';
|
|
141
|
+
|
|
142
|
+
const cblService = ServiceProvider.getInstance().cblService;
|
|
71
143
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
144
|
+
// Calculate capacity for CBL blocks
|
|
145
|
+
const capacity = cblService.calculateCBLAddressCapacity(
|
|
146
|
+
BlockSize.Medium,
|
|
147
|
+
BlockEncryptionType.SingleRecipient
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
console.log(`CBL can hold ${capacity} block references`);
|
|
75
151
|
```
|
|
76
152
|
|
|
77
|
-
|
|
78
|
-
|
|
153
|
+
### Service Provider Pattern
|
|
154
|
+
|
|
155
|
+
BrightChain uses a service provider pattern for dependency injection:
|
|
156
|
+
|
|
79
157
|
```typescript
|
|
80
|
-
import {
|
|
158
|
+
import { ServiceProvider } from '@brightchain/brightchain-lib';
|
|
159
|
+
|
|
160
|
+
// Get service instances
|
|
161
|
+
const provider = ServiceProvider.getInstance();
|
|
162
|
+
const checksumService = provider.checksumService;
|
|
163
|
+
const eciesService = provider.eciesService;
|
|
164
|
+
const blockService = provider.blockService;
|
|
81
165
|
|
|
82
|
-
|
|
83
|
-
|
|
166
|
+
// Calculate checksums
|
|
167
|
+
const data = new Uint8Array([1, 2, 3, 4]);
|
|
168
|
+
const checksum = checksumService.calculateChecksum(data);
|
|
84
169
|
```
|
|
85
170
|
|
|
86
|
-
|
|
171
|
+
## 🏗️ Architecture
|
|
87
172
|
|
|
88
|
-
|
|
89
|
-
```typescript
|
|
90
|
-
import CONSTANTS from 'brightchain-lib';
|
|
173
|
+
### Block Structure
|
|
91
174
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
175
|
+
All blocks follow a layered structure:
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
[Base Header][Layer Headers][Layer Data][Padding]
|
|
179
|
+
```
|
|
95
180
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
181
|
+
**Base Header includes:**
|
|
182
|
+
- Block Type
|
|
183
|
+
- Block Size
|
|
184
|
+
- Data Type
|
|
185
|
+
- Checksum
|
|
186
|
+
- Date Created
|
|
187
|
+
|
|
188
|
+
**Encrypted Block Header adds:**
|
|
189
|
+
- Encryption Type (1 byte)
|
|
190
|
+
- Recipient GUID (16 bytes)
|
|
191
|
+
- Ephemeral Public Key (65 bytes)
|
|
192
|
+
- IV (16 bytes)
|
|
193
|
+
- Auth Tag (16 bytes)
|
|
194
|
+
|
|
195
|
+
### Storage Architecture
|
|
196
|
+
|
|
197
|
+
```mermaid
|
|
198
|
+
graph TD
|
|
199
|
+
A[File Input] --> B[Block Splitter]
|
|
200
|
+
B --> C[XOR with Random Blocks]
|
|
201
|
+
C --> D[Encrypted Blocks]
|
|
202
|
+
D --> E[Block Store]
|
|
203
|
+
E --> F[CBL Creation]
|
|
204
|
+
F --> G[Magnet URL]
|
|
99
205
|
```
|
|
100
206
|
|
|
101
|
-
|
|
207
|
+
## 🔒 Security Features
|
|
208
|
+
|
|
209
|
+
### Brokered Anonymity
|
|
210
|
+
|
|
211
|
+
BrightChain provides privacy through Forward Error Correction:
|
|
212
|
+
|
|
213
|
+
1. **Identity Replacement**: Real identities replaced with FEC datasets
|
|
214
|
+
2. **Quorum Distribution**: Identity shards distributed among trusted agents
|
|
215
|
+
3. **Majority Recovery**: Requires quorum majority to recover identity
|
|
216
|
+
4. **Digital Statute of Limitations**: FEC data expires after predetermined time
|
|
217
|
+
|
|
218
|
+
### Cryptographic Guarantees
|
|
219
|
+
|
|
220
|
+
- **ECIES Security**: Elliptic curve cryptography with AES-256-GCM
|
|
221
|
+
- **Homomorphic Voting**: Paillier encryption for private voting
|
|
222
|
+
- **Block Integrity**: SHA-512 checksums for all blocks
|
|
223
|
+
- **Forward Secrecy**: Temporal key rotation support
|
|
224
|
+
|
|
225
|
+
## 📊 Constants and Configuration
|
|
226
|
+
|
|
227
|
+
### Core Constants
|
|
228
|
+
|
|
102
229
|
```typescript
|
|
103
|
-
import
|
|
230
|
+
import CONSTANTS from '@brightchain/brightchain-lib';
|
|
231
|
+
|
|
232
|
+
// ECIES Configuration
|
|
233
|
+
CONSTANTS.ECIES.CURVE_NAME // 'secp256k1'
|
|
234
|
+
CONSTANTS.ECIES.PUBLIC_KEY_LENGTH // 65 bytes
|
|
235
|
+
CONSTANTS.ECIES.PRIVATE_KEY_LENGTH // 32 bytes
|
|
104
236
|
|
|
105
|
-
//
|
|
106
|
-
|
|
107
|
-
|
|
237
|
+
// Block Configuration
|
|
238
|
+
CONSTANTS.CBL.MAX_FILE_NAME_LENGTH // 255 characters
|
|
239
|
+
CONSTANTS.TUPLE.SIZE // 3 blocks per tuple
|
|
240
|
+
CONSTANTS.FEC.MAX_SHARD_SIZE // 1MB
|
|
241
|
+
|
|
242
|
+
// Encryption Settings
|
|
243
|
+
CONSTANTS.ENCRYPTION.RECIPIENT_ID_SIZE // 16 bytes
|
|
244
|
+
CONSTANTS.ENCRYPTION.ENCRYPTION_TYPE_SIZE // 1 byte
|
|
108
245
|
```
|
|
109
246
|
|
|
110
|
-
|
|
247
|
+
### ECIES Configuration
|
|
248
|
+
|
|
111
249
|
```typescript
|
|
112
|
-
import { EciesConfig } from 'brightchain-lib';
|
|
250
|
+
import { EciesConfig } from '@brightchain/brightchain-lib';
|
|
113
251
|
|
|
114
|
-
// EciesConfig provides a ready-to-use ECIES configuration object
|
|
115
252
|
const config = EciesConfig;
|
|
116
|
-
console.log(config.curveName);
|
|
117
|
-
console.log(config.symmetricAlgorithm);
|
|
253
|
+
console.log(config.curveName); // 'secp256k1'
|
|
254
|
+
console.log(config.symmetricAlgorithm); // 'aes-256-gcm'
|
|
118
255
|
```
|
|
119
256
|
|
|
120
|
-
|
|
257
|
+
## 🧪 Testing
|
|
258
|
+
|
|
259
|
+
### Running Tests
|
|
121
260
|
|
|
122
|
-
|
|
261
|
+
```bash
|
|
262
|
+
# Run all tests
|
|
263
|
+
npm test
|
|
264
|
+
|
|
265
|
+
# Run with specific configuration
|
|
266
|
+
npm run test:dev:16
|
|
267
|
+
|
|
268
|
+
# Run with logging
|
|
269
|
+
npm run test:dev:16:logged
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Test Structure
|
|
273
|
+
|
|
274
|
+
The library includes comprehensive tests:
|
|
275
|
+
|
|
276
|
+
- **Unit Tests**: Individual component testing
|
|
277
|
+
- **Integration Tests**: Service interaction testing
|
|
278
|
+
- **Property Tests**: Cryptographic property verification
|
|
279
|
+
- **System Tests**: End-to-end functionality testing
|
|
280
|
+
|
|
281
|
+
## 🔧 Development
|
|
282
|
+
|
|
283
|
+
### Building
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# Development build
|
|
287
|
+
npm run build:dev
|
|
288
|
+
|
|
289
|
+
# Production build (via Nx)
|
|
290
|
+
npx nx build brightchain-lib
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### Linting
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
# Check code style
|
|
297
|
+
npm run lint
|
|
298
|
+
|
|
299
|
+
# Fix code style issues
|
|
300
|
+
npm run lint:fix
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
## 🌐 Browser Compatibility
|
|
304
|
+
|
|
305
|
+
BrightChain is designed to work in both Node.js and browser environments:
|
|
123
306
|
|
|
124
307
|
```typescript
|
|
125
|
-
//
|
|
126
|
-
import
|
|
308
|
+
// Browser-specific entry point
|
|
309
|
+
import { BrightChain } from '@brightchain/brightchain-lib/browser';
|
|
127
310
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
CONSTANTS.CHECKSUM.ALGORITHM
|
|
131
|
-
CONSTANTS.CBL.MAX_FILE_NAME_LENGTH
|
|
311
|
+
// Node.js entry point
|
|
312
|
+
import { BrightChain } from '@brightchain/brightchain-lib';
|
|
132
313
|
```
|
|
133
314
|
|
|
134
|
-
##
|
|
315
|
+
## 📖 API Reference
|
|
316
|
+
|
|
317
|
+
### Core Classes
|
|
318
|
+
|
|
319
|
+
#### BrightChain
|
|
320
|
+
Main interface for file storage and retrieval.
|
|
321
|
+
|
|
322
|
+
**Methods:**
|
|
323
|
+
- `storeFile(data: Uint8Array, fileName?: string): Promise<FileReceipt>`
|
|
324
|
+
- `retrieveFile(receipt: FileReceipt): Promise<Uint8Array>`
|
|
325
|
+
|
|
326
|
+
#### BaseBlock
|
|
327
|
+
Abstract base class for all block types.
|
|
328
|
+
|
|
329
|
+
**Properties:**
|
|
330
|
+
- `blockSize: BlockSize` - Size category of the block
|
|
331
|
+
- `blockType: BlockType` - Type of block (raw, encrypted, CBL, etc)
|
|
332
|
+
- `idChecksum: ChecksumUint8Array` - Unique identifier
|
|
333
|
+
- `dateCreated: Date` - Creation timestamp
|
|
334
|
+
|
|
335
|
+
**Methods:**
|
|
336
|
+
- `validateAsync(): Promise<void>` - Async validation
|
|
337
|
+
- `validateSync(): void` - Sync validation
|
|
338
|
+
|
|
339
|
+
#### EncryptedBlock
|
|
340
|
+
Encrypted block implementation with ECIES.
|
|
341
|
+
|
|
342
|
+
**Properties:**
|
|
343
|
+
- `encryptionType: BlockEncryptionType` - Single or multi-recipient
|
|
344
|
+
- `recipients: Array<TID>` - List of recipient IDs
|
|
345
|
+
- `recipientWithKey: Member<TID>` - Member with decryption key
|
|
346
|
+
|
|
347
|
+
**Methods:**
|
|
348
|
+
- `decrypt<D>(newBlockType: BlockType): Promise<D>` - Decrypt block
|
|
349
|
+
|
|
350
|
+
### Services
|
|
351
|
+
|
|
352
|
+
#### ChecksumService
|
|
353
|
+
Handles SHA-512 checksum operations.
|
|
354
|
+
|
|
355
|
+
**Methods:**
|
|
356
|
+
- `calculateChecksum(data: Uint8Array): ChecksumUint8Array`
|
|
357
|
+
- `checksumToHexString(checksum: ChecksumUint8Array): ChecksumString`
|
|
358
|
+
|
|
359
|
+
#### ECIESService
|
|
360
|
+
Provides ECIES encryption/decryption.
|
|
361
|
+
|
|
362
|
+
**Methods:**
|
|
363
|
+
- `encryptSimpleOrSingle(simple: boolean, publicKey: Uint8Array, data: Uint8Array): Promise<Uint8Array>`
|
|
364
|
+
- `decryptSimpleOrSingle(simple: boolean, privateKey: Uint8Array, data: Uint8Array): Promise<Uint8Array>`
|
|
365
|
+
|
|
366
|
+
## 🤝 Contributing
|
|
367
|
+
|
|
368
|
+
We welcome contributions! Please see our [Contributing Guide](../CONTRIBUTING.md) for details.
|
|
369
|
+
|
|
370
|
+
### Development Setup
|
|
371
|
+
|
|
372
|
+
1. Clone the repository
|
|
373
|
+
2. Install dependencies: `yarn install`
|
|
374
|
+
3. Run tests: `npm test`
|
|
375
|
+
4. Build: `npm run build:dev`
|
|
376
|
+
|
|
377
|
+
## 📄 License
|
|
378
|
+
|
|
379
|
+
This project is licensed under the MIT License - see the [LICENSE](../LICENSE) file for details.
|
|
380
|
+
|
|
381
|
+
## 🔗 Related Projects
|
|
382
|
+
|
|
383
|
+
- **@digitaldefiance/ecies-lib**: Core cryptographic primitives
|
|
384
|
+
- **@digitaldefiance/i18n-lib**: Internationalization support
|
|
385
|
+
- **brightchain-api**: REST API server
|
|
386
|
+
- **brightchain-react**: React frontend components
|
|
387
|
+
|
|
388
|
+
## 📞 Support
|
|
389
|
+
|
|
390
|
+
- **GitHub Issues**: [Report bugs or request features](https://github.com/Digital-Defiance/BrightChain/issues)
|
|
391
|
+
- **Documentation**: [Full documentation](https://github.com/Digital-Defiance/BrightChain#readme)
|
|
392
|
+
- **Community**: [Join our discussions](https://github.com/Digital-Defiance/BrightChain/discussions)
|
|
135
393
|
|
|
136
|
-
|
|
394
|
+
## 🎯 Roadmap
|
|
137
395
|
|
|
138
|
-
|
|
396
|
+
BrightChain is actively developed with ambitious goals:
|
|
139
397
|
|
|
140
|
-
|
|
398
|
+
- **Phase 1**: Complete Owner-Free File System ✅
|
|
399
|
+
- **Phase 2**: Identity and reputation systems (In Progress)
|
|
400
|
+
- **Phase 3**: Digital contracts and governance
|
|
401
|
+
- **Phase 4**: Global adoption and interplanetary standards
|
|
141
402
|
|
|
142
|
-
|
|
403
|
+
---
|
|
143
404
|
|
|
144
|
-
|
|
405
|
+
**BrightChain** - *Illuminating the future of decentralized digital governance*
|
package/package.json
CHANGED
|
@@ -1,9 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightchain/brightchain-lib",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "BrightChain core library - browser-compatible blockchain storage",
|
|
5
5
|
"main": "src/browser.js",
|
|
6
6
|
"types": "src/browser.d.ts",
|
|
7
|
+
"browser": "src/browser.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"browser": "./src/browser.js",
|
|
11
|
+
"import": "./src/index.js",
|
|
12
|
+
"require": "./src/index.js",
|
|
13
|
+
"types": "./src/browser.d.ts"
|
|
14
|
+
},
|
|
15
|
+
"./browser": {
|
|
16
|
+
"import": "./src/browser.js",
|
|
17
|
+
"require": "./src/browser.js",
|
|
18
|
+
"types": "./src/browser.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
7
21
|
"repository": {
|
|
8
22
|
"type": "git",
|
|
9
23
|
"url": "https://github.com/Digital-Defiance/BrightChain.git",
|
package/src/browser.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './lib/brightChain';
|
|
2
2
|
export * from './lib/enumerations/blockSize';
|
|
3
|
-
export * from './lib/
|
|
3
|
+
export * from './lib/stores/memoryBlockStore';
|
|
4
|
+
export * from './lib/factories/blockStoreFactory';
|
|
5
|
+
export * from './lib/interfaces/storage/blockStore';
|
|
6
|
+
export declare function initializeBrightChain(): void;
|
|
7
|
+
export type { FileReceipt, BlockInfo } from './lib/brightChain';
|
|
4
8
|
//# sourceMappingURL=browser.d.ts.map
|
package/src/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../brightchain-lib/src/browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../brightchain-lib/src/browser.ts"],"names":[],"mappings":"AAGA,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AAGpD,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAGD,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC"}
|
package/src/browser.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// Minimal browser-compatible exports
|
|
3
|
+
// Only exports core functionality that works without Node.js modules
|
|
2
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.initializeBrightChain = initializeBrightChain;
|
|
3
6
|
const tslib_1 = require("tslib");
|
|
4
|
-
// Browser-only exports - no Node.js dependencies
|
|
5
7
|
tslib_1.__exportStar(require("./lib/brightChain"), exports);
|
|
6
8
|
tslib_1.__exportStar(require("./lib/enumerations/blockSize"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./lib/
|
|
9
|
+
tslib_1.__exportStar(require("./lib/stores/memoryBlockStore"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./lib/factories/blockStoreFactory"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./lib/interfaces/storage/blockStore"), exports);
|
|
12
|
+
// Simple browser initialization
|
|
13
|
+
function initializeBrightChain() {
|
|
14
|
+
console.log('BrightChain browser mode initialized');
|
|
15
|
+
}
|
|
8
16
|
//# sourceMappingURL=browser.js.map
|
package/src/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../brightchain-lib/src/browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../brightchain-lib/src/browser.ts"],"names":[],"mappings":";AAAA,qCAAqC;AACrC,qEAAqE;;AASrE,sDAEC;;AATD,4DAAkC;AAClC,uEAA6C;AAC7C,wEAA8C;AAC9C,4EAAkD;AAClD,8EAAoD;AAEpD,gCAAgC;AAChC,SAAgB,qBAAqB;IACnC,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;AACtD,CAAC"}
|
package/src/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
export * from './lib/blocks
|
|
1
|
+
export * from './lib/blocks';
|
|
2
2
|
export * from './lib/brightChain';
|
|
3
3
|
export * from './lib/enumerations/blockSize';
|
|
4
4
|
export * from './lib/factories/blockStoreFactory';
|
|
5
5
|
export * from './lib/interfaces/storage/blockStore';
|
|
6
6
|
export * from './lib/stores/memoryBlockStore';
|
|
7
7
|
export * from './lib/types';
|
|
8
|
+
export * from './lib/init';
|
|
8
9
|
export { default as CONSTANTS, CBL, FEC, TUPLE, SEALING, JWT, SITE } from './lib/constants';
|
|
9
10
|
export { EciesConfig } from './lib/ecies-config';
|
|
10
11
|
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../brightchain-lib/src/index.ts"],"names":[],"mappings":"AACA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../brightchain-lib/src/index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAG3B,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC"}
|
package/src/index.js
CHANGED
|
@@ -3,13 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EciesConfig = exports.SITE = exports.JWT = exports.SEALING = exports.TUPLE = exports.FEC = exports.CBL = exports.CONSTANTS = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
// Browser-compatible exports only
|
|
6
|
-
tslib_1.__exportStar(require("./lib/blocks
|
|
6
|
+
tslib_1.__exportStar(require("./lib/blocks"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./lib/brightChain"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./lib/enumerations/blockSize"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./lib/factories/blockStoreFactory"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./lib/interfaces/storage/blockStore"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./lib/stores/memoryBlockStore"), exports);
|
|
12
12
|
tslib_1.__exportStar(require("./lib/types"), exports);
|
|
13
|
+
tslib_1.__exportStar(require("./lib/init"), exports);
|
|
13
14
|
// Export constants
|
|
14
15
|
var constants_1 = require("./lib/constants");
|
|
15
16
|
Object.defineProperty(exports, "CONSTANTS", { enumerable: true, get: function () { return constants_1.default; } });
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../brightchain-lib/src/index.ts"],"names":[],"mappings":";;;;AAAA,kCAAkC;AAClC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../brightchain-lib/src/index.ts"],"names":[],"mappings":";;;;AAAA,kCAAkC;AAClC,uDAA6B;AAC7B,4DAAkC;AAClC,uEAA6C;AAC7C,4EAAkD;AAClD,8EAAoD;AACpD,wEAA8C;AAC9C,sDAA4B;AAC5B,qDAA2B;AAE3B,mBAAmB;AACnB,6CAA4F;AAAnF,sGAAA,OAAO,OAAa;AAAE,gGAAA,GAAG,OAAA;AAAE,gGAAA,GAAG,OAAA;AAAE,kGAAA,KAAK,OAAA;AAAE,oGAAA,OAAO,OAAA;AAAE,gGAAA,GAAG,OAAA;AAAE,iGAAA,IAAI,OAAA;AAClE,mDAAiD;AAAxC,2GAAA,WAAW,OAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Transform, TransformCallback } from '
|
|
1
|
+
import { Transform, TransformCallback } from './browserStream';
|
|
2
2
|
import { BlockSize } from './enumerations/blockSize';
|
|
3
3
|
declare class BlockPaddingTransform extends Transform {
|
|
4
4
|
private readonly blockSize;
|
|
5
5
|
private buffer;
|
|
6
6
|
constructor(blockSize: BlockSize);
|
|
7
|
-
_transform(chunk:
|
|
7
|
+
_transform(chunk: any, encoding: string, callback: TransformCallback): void;
|
|
8
8
|
_flush(callback: TransformCallback): void;
|
|
9
9
|
}
|
|
10
10
|
export default BlockPaddingTransform;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blockPaddingTransform.d.ts","sourceRoot":"","sources":["../../../../brightchain-lib/src/lib/blockPaddingTransform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"blockPaddingTransform.d.ts","sourceRoot":"","sources":["../../../../brightchain-lib/src/lib/blockPaddingTransform.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,cAAM,qBAAsB,SAAQ,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,MAAM,CAAa;gBAEf,SAAS,EAAE,SAAS;IAMvB,UAAU,CACjB,KAAK,EAAE,GAAG,EACV,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,iBAAiB,GAC1B,IAAI;IA0BE,MAAM,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;CAYnD;AAED,eAAe,qBAAqB,CAAC"}
|