Skip to content

BTG #4

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

Open
wants to merge 100 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
a1f81e6
prepare for laravel
androzd Nov 9, 2017
9d18b2c
update readme
androzd Nov 9, 2017
2f4f8c3
Merge pull request #1 from androzd/master
codeator Nov 9, 2017
bab19ab
fix name
androzd Nov 9, 2017
a1b781a
Merge pull request #2 from androzd/master
codeator Nov 9, 2017
747bc15
DOGE
androzd Nov 9, 2017
8895aae
Merge pull request #3 from androzd/master
codeator Nov 9, 2017
872e441
update DOGE
androzd Nov 9, 2017
0f87558
fix LTC
androzd Nov 9, 2017
75ab264
Merge pull request #4 from androzd/master
codeator Nov 9, 2017
a95e8cf
Update LTC.php
codeator Nov 9, 2017
912a4cd
fix
androzd Nov 9, 2017
ff73c5b
fix
androzd Nov 9, 2017
124149a
Merge branch 'master' into master
codeator Nov 9, 2017
448f6cf
Merge branch 'master' into master
codeator Nov 9, 2017
f0f08ab
Merge pull request #5 from androzd/master
codeator Nov 9, 2017
dba52ac
temporary hack with ETH validation
androzd Nov 10, 2017
6ba19c3
Merge pull request #6 from androzd/master
codeator Nov 10, 2017
0686ec8
allow LTC address started with 3
androzd Dec 4, 2017
f8897ac
Merge pull request #7 from androzd/master
codeator Dec 4, 2017
a8061b2
fix M addresses, add tests
androzd Mar 6, 2018
5d8416b
Merge pull request #8 from androzd/master
codeator Mar 6, 2018
d7bc82c
add ZEC-t validation
androzd Mar 20, 2018
ad4f9c9
Merge pull request #9 from androzd/master
codeator Mar 20, 2018
57cc697
BCH has same format as BTC
androzd May 15, 2018
0d9ff40
merge with old bch validator
androzd May 15, 2018
f73ecec
Merge pull request #10 from androzd/master
codeator May 15, 2018
cb812a9
Implement parts of bitwasp/bech32 for BTC & LTC bech32 address valida…
sonofliberty Nov 13, 2019
3fc4b7e
Merge pull request #11 from sonofliberty/master
codeator Nov 13, 2019
053723d
add and edit multiple validators
androzd Mar 27, 2020
41e13c9
Merge pull request #13 from androzd/master
codeator Mar 27, 2020
1429b98
XRP address validation
androzd Mar 27, 2020
980b55c
add more tests
androzd Mar 28, 2020
1aaf50d
Merge pull request #14 from androzd/master
androzd May 2, 2020
31a0585
TRX validation
androzd Apr 16, 2021
d4d3ca7
Merge pull request #16 from androzd/master
androzd Apr 16, 2021
80bf102
cardano address validator
androzd Apr 16, 2021
35a00bc
add tests
androzd Apr 16, 2021
aec1f91
Merge pull request #17 from androzd/master
androzd Apr 16, 2021
bc61311
Type base58 addresses validation fix.
asovetnikov Aug 18, 2021
3bb02e7
Merge pull request #18 from asovetnikov/master
androzd Aug 18, 2021
9d4b6f0
add license
dancer-st Aug 22, 2022
9ebe705
Merge pull request #22 from dancer-st/license
androzd Aug 23, 2022
ec9b98a
tests
androzd Sep 5, 2022
eb26fcd
Merge pull request #23 from androzd/master
androzd Sep 5, 2022
e254979
Add ADA Testnet validation, fix ADA Mainnet validation
androzd Sep 21, 2022
b7f324b
Merge pull request #24 from androzd/master
androzd Sep 21, 2022
75a27b3
Update README.md
mehrshaddarzi Mar 23, 2023
be678ec
contracts
LiquidCats Apr 21, 2023
604540e
enum
LiquidCats Apr 21, 2023
413410b
utils
LiquidCats Apr 21, 2023
ef557da
exceptions
LiquidCats Apr 21, 2023
03e3f23
config
LiquidCats Apr 21, 2023
0e7f468
clean up
LiquidCats Apr 21, 2023
136309e
clean up
LiquidCats Apr 21, 2023
fd3e2c9
validation drivers
LiquidCats Apr 21, 2023
d14f22c
driver config
LiquidCats Apr 21, 2023
53fb5b9
validator
LiquidCats Apr 21, 2023
4d09228
provider
LiquidCats Apr 21, 2023
c1391f9
extend requirements
LiquidCats Apr 24, 2023
453207d
adjust config
LiquidCats Apr 24, 2023
03dab50
provide tests
LiquidCats Apr 24, 2023
0b59cc8
fix after testing
LiquidCats Apr 24, 2023
cb0b916
update read me
LiquidCats Apr 24, 2023
42289f4
remove unused
LiquidCats Apr 24, 2023
44a56b9
Merge pull request #25 from mehrshaddarzi/patch-1
androzd May 12, 2023
d904002
fix configs
LiquidCats May 17, 2023
6d092e9
fix configs
LiquidCats May 22, 2023
c4e4255
make not strict driver
LiquidCats May 22, 2023
827b8d1
tests
LiquidCats May 22, 2023
5e5af51
remove unused
LiquidCats May 22, 2023
8e3aad0
Merge branch 'master' into improve-codebase-using-some-internal-stuff
LiquidCats May 30, 2023
6675c95
Merge pull request #26 from LiquidCats/improve-codebase-using-some-in…
androzd Jun 13, 2023
7e21106
add new driver
LiquidCats Jun 29, 2023
5b2054a
aad testnet
LiquidCats Jun 29, 2023
1d87ebb
code style
LiquidCats Jun 29, 2023
b2c1bb6
Merge pull request #27 from LiquidCats/add-cbor-driver
androzd Jun 29, 2023
14265b4
update cbor to make compatible with laravel 10
LiquidCats Jun 29, 2023
2bbf327
Merge pull request #28 from LiquidCats/fix-add-cbor-driver
androzd Jun 30, 2023
1f2df04
lower case addresses
LiquidCats Jun 30, 2023
58007f3
make validation softer for BCH
LiquidCats Jun 30, 2023
3aa9112
test coverage
LiquidCats Jun 30, 2023
7e6fde1
Merge pull request #29 from LiquidCats/soften-validation-for-btc-bch
androzd Jun 30, 2023
06b1c07
fix
LiquidCats Jul 3, 2023
40bdd30
Merge pull request #30 from LiquidCats/fix-btc
androzd Jul 3, 2023
234ba12
fix typo
LiquidCats Jul 3, 2023
6007822
Merge pull request #31 from LiquidCats/fix-typo
androzd Jul 3, 2023
7b2df60
add GH action with tests
LiquidCats Jul 4, 2023
c4b41f4
remove composer validation
LiquidCats Jul 4, 2023
097cca2
add php version
LiquidCats Jul 4, 2023
c020cc9
Merge pull request #32 from LiquidCats/actions
androzd Jul 4, 2023
928b049
feature: long p-address support
Aug 29, 2023
af4c1cc
Merge pull request #1 from LiquidCats/feature/bch-long-p-addresses-su…
LiquidCats Aug 29, 2023
4f54897
Merge pull request #33 from LiquidCats/master
androzd Aug 29, 2023
25e3538
feature(validators): add bech32m support
LiquidCats Nov 1, 2023
a014b76
Merge pull request #35 from LiquidCats/feature/add-bech32m-addresses-…
androzd Nov 6, 2023
280ae94
Fix LTC testnet address validation
romikring Nov 6, 2023
bf85d0d
Merge pull request #36 from romikring/ltc-patch
androzd Nov 6, 2023
ebf2a27
fix: driver config construction from cache
Nov 30, 2023
fa4e7fa
Merge pull request #37 from alexeyvy/master
androzd Dec 1, 2023
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
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Unit Tests

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: shivammathur/setup-php@master
with:
php-version: '8.2'

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: composer test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
vendor
.idea
.idea
.phpunit.result.cache
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Merkeleon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@
Easy to use PHP Bitcoin and Litecoin address validator.
One day I will add other crypto currencies. Or how about you? :)

## Usage
## Installation

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

## Usage

```php
use Murich\PhpCryptocurrencyAddressValidation\Validation\BTC as BTCValidator;
use Merkeleon\PhpCryptocurrencyAddressValidation\Enums\CurrencyEnum;use Merkeleon\PhpCryptocurrencyAddressValidation\Validator;

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

```
22 changes: 18 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
{
"name": "murich/php-cryptocurrency-address-validation",
"name": "merkeleon/php-cryptocurrency-address-validation",
"description": "Cryptocurrency address validation. Currently supports litecoin and bitcoin.",
"authors": [
{
"name": "Andrey Murashkin",
"email": "andrey@phpteam.pro"
}
],
"require": {},
"require": {
"php": "^8.2",
"ext-gmp": "*",
"ext-bcmath": "*",
"laravel/framework": ">=v7.0.0|>=v10.0.0",
"spomky-labs/cbor-php": "^3.0"
},
"scripts": {
"test": "@php vendor/bin/phpunit"
},
"require-dev": {
"phpunit/phpunit": "4.0.*"
"phpunit/phpunit": "~8.0"
},
"autoload": {
"psr-4": {
"Murich\\PhpCryptocurrencyAddressValidation\\": "src"
"Merkeleon\\PhpCryptocurrencyAddressValidation\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
}
}
108 changes: 108 additions & 0 deletions config/address_validation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?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],
),
new DriverConfig(
Drivers\CborDriver::class,
['A' => 33, 'D' => 66],
['2' => 40, '3' => 73],
)
],
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', 'n' => '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'],
),
],
];
7 changes: 3 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="Nacho Test Suite">
<directory suffix=".php">./tests/</directory>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
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'),
]);
}
}
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;
}
19 changes: 19 additions & 0 deletions src/Contracts/Validator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Merkeleon\PhpCryptocurrencyAddressValidation\Contracts;

interface Validator
{
public function isValid(?string $address): bool;

/**
* @param string|null $address
*
* @return void
*
* @throws AddressValidationException
*/
public function validate(?string $address): void;
}
57 changes: 57 additions & 0 deletions src/DriverConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Merkeleon\PhpCryptocurrencyAddressValidation;

use Merkeleon\PhpCryptocurrencyAddressValidation\Drivers\AbstractDriver;
use function class_exists;

/**
* @template T
*/
readonly class DriverConfig
{
/**
* @param class-string<T> $driver
* @param array $mainnet
* @param array $testnet
*/
public function __construct(
private string $driver,
private array $mainnet = [],
private array $testnet = []
)
{
}

public function makeDriver(bool $isMainNet): ?AbstractDriver
{
if (!class_exists($this->driver)) {
return null;
}

return new $this->driver($this->getDriverOptions($isMainNet));

}

private function getDriverOptions(bool $isMainNet): array
{
if ($isMainNet) {
return $this->mainnet;
}

return $this->testnet
?: $this->mainnet
?: [];
}

public static function __set_state(array $state): DriverConfig
{
return new self(
$state['driver'],
$state['mainnet'],
$state['testnet']
);
}
}
14 changes: 14 additions & 0 deletions src/Drivers/AbstractDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Merkeleon\PhpCryptocurrencyAddressValidation\Drivers;

use Merkeleon\PhpCryptocurrencyAddressValidation\Contracts\Driver;

abstract class AbstractDriver implements Driver
{
public function __construct(protected readonly array $options)
{
}
}
Loading