Skip to content

Commit 960db34

Browse files
committed
feat(release): 🚀 Laravel Blockchain v2.0.0 — major upgrade with user-specific certificates, Merkle root verification, and health monitoring
- Introduced user-specific PEM certificate support for per-user signing - Added blockchain health monitoring with blockchain:health command - Enhanced chain verification and fork detection logic - Added Merkle root signing and verification for hierarchical integrity - Improved BlockchainManager structure for clarity and maintainability - Updated README with installation, upgrade guide, and usage examples - Strengthened RSA key handling and password-based encryption flow - Improved configuration flexibility for keys, hashes, and auto-verification
1 parent 19aeb67 commit 960db34

17 files changed

+1387
-236
lines changed

‎README.md‎

Lines changed: 261 additions & 38 deletions
Large diffs are not rendered by default.

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@
4747
},
4848
"minimum-stability": "stable",
4949
"prefer-stable": true,
50-
"version": "1.2.1"
50+
"version": "2.0.0"
5151
}

‎config/blockchain.php‎

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
<?php
22

33
return [
4+
45
/*
56
|--------------------------------------------------------------------------
6-
| Blockchain Table Name
7+
| Blockchain Ledger Table
78
|--------------------------------------------------------------------------
89
|
9-
| The name of the table that will store blockchain ledger records.
10+
| The table that stores blockchain ledger entries.
11+
| You can override this in .env via BLOCKCHAIN_TABLE_NAME.
1012
|
1113
*/
1214
'table_name' => env('BLOCKCHAIN_TABLE_NAME', 'blockchain_ledgers'),
1315

1416
/*
1517
|--------------------------------------------------------------------------
16-
| Hash Algorithm
18+
| Hashing Algorithm
1719
|--------------------------------------------------------------------------
1820
|
19-
| The hashing algorithm to use for block hashing.
20-
| Supported: 'sha256', 'sha512', 'md5' (not recommended)
21+
| The algorithm used to generate block hashes.
22+
| Supported: 'sha256', 'sha512', 'md5' (md5 not recommended).
2123
|
2224
*/
2325
'hash_algorithm' => env('BLOCKCHAIN_HASH_ALGORITHM', 'sha256'),
@@ -27,18 +29,18 @@
2729
| Signature Algorithm
2830
|--------------------------------------------------------------------------
2931
|
30-
| The OpenSSL signature algorithm to use.
31-
| Supported: OPENSSL_ALGO_SHA256, OPENSSL_ALGO_SHA512
32+
| OpenSSL algorithm used for signing blockchain data.
33+
| Options: OPENSSL_ALGO_SHA256, OPENSSL_ALGO_SHA512.
3234
|
3335
*/
3436
'signature_algorithm' => OPENSSL_ALGO_SHA256,
3537

3638
/*
3739
|--------------------------------------------------------------------------
38-
| Keys Storage Path
40+
| Keys Storage Directory
3941
|--------------------------------------------------------------------------
4042
|
41-
| The path where cryptographic keys are stored.
43+
| The default location for blockchain keys (private/public).
4244
|
4345
*/
4446
'keys_path' => storage_path('blockchain/keys'),
@@ -48,27 +50,30 @@
4850
| Default Private Key
4951
|--------------------------------------------------------------------------
5052
|
51-
| Path to the default private key file (relative to keys_path).
53+
| File name of the default private key relative to keys_path.
54+
| Used if no user certificate is assigned.
5255
|
5356
*/
54-
'private_key' => env('BLOCKCHAIN_PRIVATE_KEY', 'private.pem'),
57+
'private_key' => env('BLOCKCHAIN_PRIVATE_KEY', 'private4.pem'),
5558

5659
/*
5760
|--------------------------------------------------------------------------
5861
| Default Public Key
5962
|--------------------------------------------------------------------------
6063
|
61-
| Path to the default public key file (relative to keys_path).
64+
| File name of the default public key relative to keys_path.
65+
| Used to verify blockchain data without user certificate.
6266
|
6367
*/
64-
'public_key' => env('BLOCKCHAIN_PUBLIC_KEY', 'public.pem'),
68+
'public_key' => env('BLOCKCHAIN_PUBLIC_KEY', 'public4.pem'),
6569

6670
/*
6771
|--------------------------------------------------------------------------
6872
| Private Key Password
6973
|--------------------------------------------------------------------------
7074
|
71-
| Password for the private key encryption.
75+
| Password for the default private key if encrypted.
76+
| Can be set in .env as BLOCKCHAIN_PRIVATE_KEY_PASSWORD.
7277
|
7378
*/
7479
'private_key_password' => env('BLOCKCHAIN_PRIVATE_KEY_PASSWORD', null),
@@ -78,18 +83,43 @@
7883
| Genesis Block Hash
7984
|--------------------------------------------------------------------------
8085
|
81-
| The hash used for the genesis block (first block in chain).
86+
| Initial block hash for the blockchain.
8287
|
8388
*/
8489
'genesis_hash' => '00000',
8590

8691
/*
8792
|--------------------------------------------------------------------------
88-
| Auto Verify Chain
93+
| Save Algorithm Metadata
94+
|--------------------------------------------------------------------------
95+
|
96+
| Whether each block stores its hashing algorithm.
97+
| Useful if you might change system default in the future.
98+
|
99+
*/
100+
'save_algorithm' => false,
101+
102+
/*
103+
|--------------------------------------------------------------------------
104+
| Automatic Chain Verification
89105
|--------------------------------------------------------------------------
90106
|
91-
| Automatically verify the blockchain integrity before creating new blocks.
107+
| If true, verifies the chain integrity before adding a new block.
92108
|
93109
*/
94-
'auto_verify' => env('BLOCKCHAIN_AUTO_VERIFY', false),
95-
];
110+
'auto_verify' => env('BLOCKCHAIN_AUTO_VERIFY', true),
111+
112+
/*
113+
|--------------------------------------------------------------------------
114+
| Blockchain Root Configuration
115+
|--------------------------------------------------------------------------
116+
|
117+
| Enable Merkle root signing with a master key pair.
118+
|
119+
*/
120+
'with_blockchain_root' => env('WITH_BLOCKCHAIN_ROOT', false),
121+
'master_private_key' => env('MASTER_PRIVATE_KEY', null),
122+
'master_private_key_password' => env('MASTER_PRIVATE_KEY_PASSWORD', null),
123+
'master_public_key' => env('MASTER_PUBLIC_KEY', null),
124+
125+
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('blockchain_default_certificates', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('public_key_path');
14+
$table->string('private_key_path');
15+
$table->integer('status')->max(2)->default(1);
16+
$table->timestamps();
17+
});
18+
}
19+
20+
public function down(): void
21+
{
22+
Schema::dropIfExists('model_has_certificates');
23+
}
24+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('blockchain_roots', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('table_name');
14+
$table->unsignedBigInteger('record_id')->nullable();
15+
$table->string('merkle_root')->nullable();
16+
$table->text('signature'); // signed by master key
17+
$table->timestamps();
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::dropIfExists('blockchain_roots');
24+
}
25+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('model_has_certificates', function (Blueprint $table) {
12+
$table->id();
13+
$table->unsignedBigInteger('user_id')->index();
14+
$table->string('certificate_path'); // example: storage/app/certificates/user1.pem
15+
$table->integer('status')->max(2)->default(1);
16+
$table->timestamps();
17+
18+
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
19+
});
20+
}
21+
22+
public function down(): void
23+
{
24+
Schema::dropIfExists('model_has_certificates');
25+
}
26+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
public function up(): void
10+
{
11+
Schema::create('blockchain_ledgers', function (Blueprint $table) {
12+
$table->id();
13+
$table->string('nonce')->nullable();
14+
$table->unsignedBigInteger('user_id')->nullable();
15+
$table->string('table_name')->index();
16+
$table->unsignedBigInteger('record_id')->index();
17+
$table->json('data')->nullable();
18+
$table->string('data_hash', 64);
19+
$table->string('previous_hash', 64);
20+
$table->string('block_hash', 64)->unique();
21+
$table->text('signature');
22+
$table->boolean('with_user_certificate')->default(false);
23+
$table->unsignedBigInteger('certificate_id')->nullable();
24+
$table->unsignedBigInteger('default_certificate_id')->nullable();
25+
$table->string('algorithm')->nullable();
26+
$table->timestamps();
27+
28+
$table->index(['table_name', 'record_id']);
29+
30+
$table->foreign('user_id')->references('id')->on('users');
31+
$table->foreign('certificate_id')->references('id')->on('model_has_certificates');
32+
$table->foreign('default_certificate_id')->references('id')->on('blockchain_default_certificates');
33+
});
34+
}
35+
36+
public function down(): void
37+
{
38+
Schema::dropIfExists('blockchain_ledgers');
39+
}
40+
};

‎database/migrations/create_blockchain_ledgers_table.php‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)