Skip to content

Improve codebase and add Laravel support #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
# Cryptocurrency Address Validation with PHP
# php-cryptocurrency-address-validation

Easy to use Cryptocurrency Address Validation.
Easy to use PHP Bitcoin and Litecoin address validator.
One day I will add other crypto currencies. Or how about you? :)

## Installation

=======
```
composer require merkeleon/php-cryptocurrency-address-validation
```

## Usage

```php
use Merkeleon\PhpCryptocurrencyAddressValidation\Validation;
use Merkeleon\PhpCryptocurrencyAddressValidation\Enums\CurrencyEnum;use Merkeleon\PhpCryptocurrencyAddressValidation\Validator;

$validator = Validation::make('BTC');
var_dump($validator->validate('1QLbGuc3WGKKKpLs4pBp9H6jiQ2MgPkXRp'));
$validator = Validator::make(CurrencyEnum::BITCOIN);
var_dump($validator->isValid('1QLbGuc3WGKKKpLs4pBp9H6jiQ2MgPkXRp'));

```

## List Of Support

1. ADA
2. BCH
3. BNB
4. BSV
5. BTC
6. DASH
7. DOGE
8. ETC
9. ETH
10. LTC
11. NEO
12. TADA
13. TBCH
14. TBTC
15. TRX
16. XRP
17. ZEC


5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
}
],
"require": {
"spomky-labs/cbor-php": "^2.0"
"php": "^8.2",
"ext-gmp": "*",
"ext-bcmath": "*",
"laravel/framework": ">=v7.0.0"
},
"require-dev": {
"phpunit/phpunit": "~8.0"
Expand Down
103 changes: 103 additions & 0 deletions config/address_validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

use Merkeleon\PhpCryptocurrencyAddressValidation\DriverConfig;
use Merkeleon\PhpCryptocurrencyAddressValidation\Drivers;
use Merkeleon\PhpCryptocurrencyAddressValidation\Enums\CurrencyEnum;

return [
CurrencyEnum::BEACON->value => [
new DriverConfig(
Drivers\Bech32Driver::class,
['bnb' => null],
['tbnb' => null]
),
],
CurrencyEnum::BITCOIN_CASH->value => [
new DriverConfig(
Drivers\Base32Driver::class,
['bitcoincash:' => null],
['bchtest:' => null, 'bchreg:' => null,]
),
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['1' => '00', '3' => '05'],
['2' => 'C4', 'm' => '6F']
),
],
CurrencyEnum::BITCOIN->value => [
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['1' => '00', '3' => '05'],
['2' => 'C4', 'm' => '6F']
),
new DriverConfig(
Drivers\Bech32Driver::class,
['bc' => null],
['tb' => null, 'bcrt' => null]
),
],
CurrencyEnum::CARDANO->value => [
new DriverConfig(
Drivers\CardanoDriver::class,
['addr' => null],
['addr_test' => null],
),
],
CurrencyEnum::DASHCOIN->value => [
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['X' => '4C', '7' => '10'],
['y' => '8C', '8' => '13']
),
],
CurrencyEnum::DOGECOIN->value => [
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['D' => '1E', '9' => '16', 'A' => '16'],
['n' => '71', 'm' => '6F', '2' => 'C4',],
),
],
CurrencyEnum::EOS->value => [
new DriverConfig(Drivers\EosDriver::class),
],
CurrencyEnum::ETHEREUM->value => [
new DriverConfig(Drivers\KeccakStrictDriver::class),
],
CurrencyEnum::LITECOIN->value => [
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['L' => '30', 'M' => '32', '3' => '05'],
['m' => '6F', '2' => 'C4', 'Q' => '3A']
),
new DriverConfig(
Drivers\Bech32Driver::class,
['ltc' => null],
['tltc' => null, 'rltc' => null]
)
],
CurrencyEnum::RIPPLE->value => [
new DriverConfig(
Drivers\XrpBase58Driver::class,
['r' => '00']
),
new DriverConfig(
Drivers\XrpXAddressDriver::class,
['X' => null],
['T' => null],
),
],
CurrencyEnum::TRON->value => [
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['T' => '41'],
),
],
CurrencyEnum::ZCASH->value => [
new DriverConfig(
Drivers\DefaultBase58Driver::class,
['t' => '1C'],
),
],
];
17 changes: 17 additions & 0 deletions src/AddressValidationServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Merkeleon\PhpCryptocurrencyAddressValidation;

use Illuminate\Support\ServiceProvider;

class AddressValidationServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->publishes([
__DIR__.'/../config/address_validation.php' => config_path('address_validation.php'),
]);
}
}
185 changes: 0 additions & 185 deletions src/Base58Validation.php

This file was deleted.

11 changes: 11 additions & 0 deletions src/Contracts/Driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Merkeleon\PhpCryptocurrencyAddressValidation\Contracts;

interface Driver
{
public function match(string $address): bool;
public function check(string $address): bool;
}
Loading