Package EOL: This package is archived because of discontinuation of CoinHive.

PHP and Laravel 5 CoinHive API and Captcha

PHP and Laravel 5 CoinHive API and Captcha

Install

Via Composer

composer require kduma/coinhive-api

Usage

$api = new \KDuma\CoinHive\CoinHiveApi(YOUR_SITE_KEY, YOUR_SECRET_KEY);$api->getPayoutStats();$api->getSiteStats();$api->withdrawFromUser($name, $amount);$api->getUserBalance($name);$api->getTopUsers($count = 128);$api->getUsersList($page = null, $count = 4096);$api->createLink($url, $hashes = 256);$api->resetUser($name);$api->resetAllUsers();$api->verifyToken($token, $hashes = 256);

Laravel Usage

Setup

In Laravel 5.5, service provider is automatically discovered. If you don't use package discovery, add the Service Provider to the providers array in config/app.php:

KDuma\CoinHive\Laravel\CoinHiveServiceProvider::class,

Add following entries to your .env file:

COINHIVE_SITE_KEY=<your site key>
COINHIVE_SECRET_KEY=<your secret key>
COINHIVE_DEFAULT_HASHES_COUNT=512

Add following entries to your config\services.php file:

    'coinhive' => [        'default_hashes' => env('COINHIVE_DEFAULT_HASHES_COUNT', 512),        'site_key' => env('COINHIVE_SITE_KEY'),        'secret_key' => env('COINHIVE_SECRET_KEY'),        'use_authedmine_url' => true,    ],

Usage

You can resolve CoinHiveApi::class class:

use KDuma\CoinHive\CoinHiveApi;$api = app(CoinHiveApi::class);$top_users = $api->getTopUsers();

or You can use injection container

use KDuma\CoinHive\CoinHiveApi;Route::get('/api', function (CoinHiveApi $api) {    $top_users = $api->getTopUsers();});

Using CoinHive Proof of Work Captcha with Laravel

In your form, place Captcha field using CoinHiveCaptchaDisplayer class:

{!! resolve(\KDuma\CoinHive\CoinHiveCaptchaDisplayer::class)->display() !!}

You can also specify more options like required_hashes, autostart, whitelabel or disable-elements like the following example:

{!! resolve(\KDuma\CoinHive\CoinHiveCaptchaDisplayer::class)->display(256, [
    'data-autostart' => false,
    'data-whitelabel' => false,
    'data-disable-elements' => "#submit",
]) !!}

To check if the Captcha is valid you can use ValidateCoinHiveCaptchaToken validator:

Route::post('/post', function (\Illuminate\Http\Request $request) {    $request->validate([        'coinhive-captcha-token' => new \KDuma\CoinHive\Laravel\ValidateCoinHiveCaptchaToken()    ]);});

If you need custom required_hashes number, you can pass it in the constructor.