Skip to content

Commit

Permalink
Merge pull request #5 from kielabokkie/feature/implement-taproot-addr…
Browse files Browse the repository at this point in the history
…ess-validation

Add support for taproot address validation
  • Loading branch information
kielabokkie authored Dec 23, 2021
2 parents 2e4b522 + 89af139 commit 9520191
Show file tree
Hide file tree
Showing 8 changed files with 832 additions and 348 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4, 8.0]
php: [7.3, 7.4, 8.0, 8.1]

name: PHP ${{ matrix.php }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
.phpunit.result.cache
vendor
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)
[![Total Downloads](https://img.shields.io/packagist/dt/kielabokkie/bitcoin-address-validator.svg?style=flat-square)](https://packagist.org/packages/kielabokkie/bitcoin-address-validator)

Validate legacy, segwit and native segwit (bech32) Bitcoin addresses.
Validate legacy, segwit, native segwit (bech32), and taproot Bitcoin addresses.

## Requirements

* PHP >= 7.1
* PHP >= 7.3

| PHP | Package Version |
| ---- | --------------- |
| 7.x | v1.0 |
| 8.x | v2.0 |
| ---- |-----------------|
| 7.x | v1.0 |
| 8.x | v2.0+ |

Please note that taproot addresses are supported from v2.1 of this package.

## Installation

Expand All @@ -27,13 +29,13 @@ composer require kielabokkie/bitcoin-address-validator

## Usage

First you instantiate the the validator class:
First you instantiate the validator class:

```php
$addressValidator = new \Kielabokkie\Bitcoin\AddressValidator;
```

Validate any kind of address (legacy, segwit and native segwit):
Validate any kind of address (legacy, segwit, native segwit and taproot):

```php
$addressValidator->isValid('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i');
Expand All @@ -57,9 +59,15 @@ Native segwit (bech32) address:
$addressValidator->isBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
```

Taproot (P2TR) address:

```php
$addressValidator->isPayToTaproot('bc1pveaamy78cq5hvl74zmfw52fxyjun3lh7lgt44j03ygx02zyk8lesgk06f6');
```

### Testnet

By default the validator only passes mainnet addresses as valid. If you would like to validate both mainnet and testnet addresses you can use method chaining:
By default, the validator only passes mainnet addresses as valid. If you would like to validate both mainnet and testnet addresses you can use method chaining:

```php
// Both valid
Expand Down Expand Up @@ -91,12 +99,13 @@ composer test
This package is based on the following packages and uses a lot of their code:

* [bitwasp/bech32](https://github.com/Bit-Wasp/bech32) by [@afk11](https://github.com/afk11)
* [brooksyang/bech32m](https://github.com/BrooksYang/bech32m) by [BrooksYang](https://github.com/BrooksYang)
* [linusu/bitcoin-address-validator](https://github.com/LinusU/php-bitcoin-address-validator) by [@LinusU](https://github.com/LinusU)

All credit goes to the original authors.

## Donate

Did this package save you some time or spark joy?
Did this package made you lots of money, save you some time or just sparked joy?

A donation would be much appreciated: `32vtWJSomccxQ6y1tgSwSHXN5PChpdYy27`
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kielabokkie/bitcoin-address-validator",
"description": "Validate legacy, segwit and native segwit (bech32) Bitcoin addresses",
"description": "Validate legacy, segwit, native segwit (bech32) and taproot Bitcoin addresses",
"type": "library",
"keywords": ["bitcoin", "address", "validation", "validator", "bech32", "segwit"],
"license": "MIT",
Expand All @@ -11,11 +11,11 @@
}
],
"require": {
"php": "^7.3|^8.0",
"php": "^7.3|^7.4|^8.0|^8.1",
"ext-bcmath": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.5|^8.0"
"phpunit/phpunit": "^7.5|^8.0|^9.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 9520191

Please sign in to comment.