This package implements a Proof of Work (PoW) system for Laravel applications with support for multiple front-end frameworks including Vue.js, React, and Angular.
- Configurable difficulty level for Proof of Work challenges
- Backend API for generating challenges and verifying proofs
- Frontend components for Vue.js, React, and Angular
- Easily integrable with existing Laravel applications
- PHP 7.4+
- Laravel 8.0+
- Node.js and NPM (for frontend components)
- Install the package via Composer:
composer require mohamedahmed01/laravel-pow
- Publish the configuration file:
php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="config"
- Publish the frontend component for your chosen framework:
php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="vue-component"
# Or for React:
# php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="react-component"
# Or for Angular:
# php artisan vendor:publish --provider="Mohamedahmed01\LaravelPow\LaravelPowServiceProvider" --tag="angular-component"
After publishing the configuration file, you can adjust the PoW settings in config/pow.php
:
return [
'difficulty' => env('POW_DIFFICULTY', 4),
'front_end' => env('POW_FRONT_END', 'vue'), // Options: 'vue', 'react', 'angular'
];
You can also set these values in your .env
file:
POW_DIFFICULTY=4
POW_FRONT_END=vue
The package provides two main API endpoints:
GET /api/pow/challenge
- Generates a new challengePOST /api/pow/verify
- Verifies a proof for a given challenge
You can use these endpoints in your application as needed.
- Import the component in your Vue application:
import ProofOfWork from './components/ProofOfWork.vue';
export default {
components: {
ProofOfWork,
},
// ...
}
- Use the component in your template:
<template>
<div>
<proof-of-work></proof-of-work>
</div>
</template>
- Import the component in your React application:
import ProofOfWork from './components/ProofOfWork';
function App() {
return (
<div>
<ProofOfWork />
</div>
);
}
- Import the component in your Angular module:
import { ProofOfWorkComponent } from './components/proof-of-work.component';
@NgModule({
declarations: [ProofOfWorkComponent],
// ...
})
export class AppModule { }
- Use the component in your template:
<app-proof-of-work></app-proof-of-work>
Generates a new Proof of Work challenge.
Response:
{
"challenge": "string",
"difficulty": number
}
Verifies a proof for a given challenge.
Request body:
{
"challenge": "string",
"proof": "string"
}
Response:
{
"status": "success" | "failure"
}
Contributions are welcome! Please feel free to submit a Pull Request.
This package is open-sourced software licensed under the MIT license.