1111![ PHP] ( https://img.shields.io/badge/PHP-%5E8.1-blue?logo=php )
1212![ Laravel] ( https://img.shields.io/badge/Laravel-%5E9.0-ff2d20?logo=laravel )
1313
14- ---
15- ## ⚡ Upgrade Guide: v1.2.1 → v2.0.0
16- > is release introduces user-specific certificates, health checks, and enhanced chain verification.
17-
18- ## 1️⃣ Update Package
19- ``` bash
20- composer update ronald-ph/laravel-blockchain
21- ```
22-
23- ## 2️⃣ Publish Updated Config & Migrations
24- ``` bash
25- php artisan vendor:publish --tag=blockchain-config
26- php artisan vendor:publish --tag=blockchain-migrations
27- php artisan migrate
28- ```
29-
30- ## 3️⃣ Generate or Migrate Keys
31- ``` bash
32- php artisan blockchain:generate-keys --password=yourpassword
33- ```
3414
35- ### Set in .env:
36- ``` env
37- BLOCKCHAIN_PRIVATE_KEY_PASSWORD=yourpassword
38- ```
39-
40- ## 4️⃣ User Certificates (Optional)
41- ``` php
42- $block = Blockchain::createBlock(
43- 'users',
44- $user->id,
45- $user->only('id', 'name', 'email'),
46- $user->id,
47- request()->file('certificate')
48- );
49- ```
50- v2.0.0 supports ** user-specific PEM certificates** .
5115## 🚀 Features
5216
5317- ✅ ** Immutable blockchain records** for any Eloquent model
@@ -102,6 +66,26 @@ Set the private key password in your `.env` file:
10266BLOCKCHAIN_PRIVATE_KEY_PASSWORD=yourpassword
10367```
10468
69+ ### ⚡ Upgrade from v1.2.1 to v2.0.0
70+
71+ This release introduces user-specific certificates, health checks, and enhanced chain verification.
72+
73+ Update the package:
74+
75+ ``` bash
76+ composer update ronald-ph/laravel-blockchain
77+ ```
78+
79+ Republish config and migrations if needed:
80+
81+ ``` bash
82+ php artisan vendor:publish --tag=blockchain-config --force
83+ php artisan vendor:publish --tag=blockchain-migrations --force
84+ php artisan migrate
85+ ```
86+
87+ Regenerate keys if necessary and set the password in ` .env ` .
88+
10589## ⚙️ Configuration
10690
10791The configuration file is located at ` config/blockchain.php ` . Key settings include:
@@ -123,22 +107,11 @@ return [
123107];
124108```
125109
126- ## 🔑 Generate Keys
127-
128- Generate RSA key pair for signing blockchain blocks:
110+ To enable Merkle root verification, set ` 'with_blockchain_root' => true ` and generate master keys:
129111
130112``` bash
131- # Generate 2048-bit keys with password
132- php artisan blockchain:generate-keys --password=yourpassword
133-
134- # Generate 4096-bit keys
135- php artisan blockchain:generate-keys --bits=4096
136- ```
137-
138- Don't forget to set your password in ` .env ` :
139-
140- ``` env
141- BLOCKCHAIN_PRIVATE_KEY_PASSWORD=yourpassword
113+ openssl genrsa -out master_private.pem 4096
114+ openssl rsa -in master_private.pem -pubout -out master_public.pem
142115```
143116
144117## Usage
@@ -150,8 +123,8 @@ use RonaldPH\LaravelBlockchain\Facades\Blockchain;
150123
151124// Create a user
152125$user = User::create([
153- 'name' => 'John Doe ',
154- 'email' => 'john @example.com',
126+ 'name' => 'Juan Dela Cruz ',
127+ 'email' => 'juan @example.com',
155128]);
156129
157130// Create blockchain record
@@ -172,35 +145,33 @@ public function store(Request $request)
172145{
173146 $request->validate([
174147 'email' => 'required|email',
175- 'private_key' => 'required| file', // Optional for user-specific certificates
176- 'private_key_password' => 'required| string',
148+ 'private_key' => 'file', // Optional for user-specific certificates
149+ 'private_key_password' => 'string', // Optional for user-specific certificates
177150 ]);
178151
179152 $user = User::create([
180153 'email' => $request->email,
181154 ]);
182155
183- // Create block with uploaded private key ( user-specific certificate)
156+ // Create block with optional user-specific private key
184157 $block = Blockchain::createBlock(
185158 'users',
186159 $user->id,
187160 json_encode($user->only('id', 'email', 'created_at')),
188- $request->file('private_key'), // Optional: null for default certificate
189- $request->private_key_password
161+ Auth::user()->id, // Optional: user ID
162+ $request->file('private_key'), // Optional: user-specific key
163+ $request->private_key_password // Optional: password
190164 );
191165
192- return response()->json([
193- 'user' => $user,
194- 'block' => $block,
195- ]);
166+ return response()->json(['user' => $user, 'block' => $block]);
196167}
197168```
198169
199170### 🔄 Update & Chain Blocks
200171
201172``` php
202173// Update user
203- $user->update(['email' => 'newemail @example.com']);
174+ $user->update(['email' => 'juan @example.com']);
204175
205176// Create new blockchain block for the update
206177$block = Blockchain::createBlock(
@@ -244,7 +215,7 @@ $user = User::find($userId);
244215
245216$result = Blockchain::verifyData(
246217 'users',
247- $userId ,
218+ $user->id ,
248219 $user->only('id', 'email', 'updated_at')
249220);
250221
@@ -279,26 +250,6 @@ $result = Blockchain::setPublicKey('/path/to/public.pem')
279250 ->verifyBlock($blockHash);
280251```
281252
282- ### 🔸 User-Specific Certificates
283-
284- ``` php
285- // Create block with user-specific certificate
286- $block = Blockchain::createBlock(
287- 'users',
288- $userId,
289- $data,
290- $userId, // User ID for certificate lookup
291- null // No file upload, uses stored certificate
292- );
293-
294- // Update a user's certificate
295- Blockchain::updateModelCertificate(
296- $userId,
297- file_get_contents('/path/to/private.pem'),
298- file_get_contents('/path/to/public.pem')
299- );
300- ```
301-
302253## 🧰 Artisan Commands
303254
304255### Generate Keys
@@ -501,39 +452,6 @@ $certificate = Blockchain::updateModelCertificate(
501452$userCertificate = Blockchain::getModelCertificate($userId);
502453```
503454
504- ### 🔸 Merkle Root Verification
505-
506- Enable Merkle root verification in your config:
507-
508- ``` php
509- 'with_blockchain_root' => true,
510- 'master_private_key' => 'master_private.pem',
511- 'master_public_key' => 'master_public.pem',
512- 'master_private_key_password' => env('BLOCKCHAIN_MASTER_PRIVATE_KEY_PASSWORD'),
513- ```
514-
515- Generate master keys for Merkle root signing:
516-
517- ``` bash
518- # Generate master keys (separate from regular keys)
519- openssl genrsa -out master_private.pem 4096
520- openssl rsa -in master_private.pem -pubout -out master_public.pem
521- ```
522-
523- ## 🌐 API Endpoints Example
524-
525- ``` php
526- Route::prefix('blockchain')->group(function () {
527- Route::post('/users', [UserController::class, 'store']);
528- Route::post('/verify/block/{hash}', [BlockchainController::class, 'verifyBlock']);
529- Route::get('/verify/chain/{table}/{id}', [BlockchainController::class, 'verifyChain']);
530- Route::get('/history/{table}/{id}', [BlockchainController::class, 'getHistory']);
531- Route::get('/health', function () {
532- return Artisan::call('blockchain:health --json');
533- });
534- });
535- ```
536-
537455## ⚙️ How It Works
538456
5394571 . ** Block Creation** : When you create a block, the package:
0 commit comments