All Projects → kielabokkie → bitcoin-address-validator

kielabokkie / bitcoin-address-validator

Licence: MIT license
PHP package to validate legacy, segwit, native segwit (bech32) and taproot Bitcoin addresses

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to bitcoin-address-validator

Bitcoinj
A library for working with Bitcoin
Stars: ✭ 4,162 (+13773.33%)
Mutual labels:  segwit, taproot
btclib
btclib: a python3 library for 'bitcoin cryptography'
Stars: ✭ 60 (+100%)
Mutual labels:  segwit, taproot
Bitcoinaddress
Bitcoin Wallet Address Generator
Stars: ✭ 52 (+73.33%)
Mutual labels:  address
Spoofmac
💼 Change your MAC address for debugging
Stars: ✭ 2,687 (+8856.67%)
Mutual labels:  address
Placepicker
Free Android Map Place Picker alternative using Geocoder instead of Google APIs
Stars: ✭ 126 (+320%)
Mutual labels:  address
Find github email
The warmest start to a cold email
Stars: ✭ 72 (+140%)
Mutual labels:  address
Vanitysearch
Bitcoin Address Prefix Finder
Stars: ✭ 160 (+433.33%)
Mutual labels:  address
Streetmangler
Russian street name database and format converter
Stars: ✭ 34 (+13.33%)
Mutual labels:  address
private-ip
Check if IP address is private.
Stars: ✭ 26 (-13.33%)
Mutual labels:  address
Administrative Divisions Of China
中华人民共和国行政区划:省级(省份直辖市自治区)、 地级(城市)、 县级(区县)、 乡级(乡镇街道)、 村级(村委会居委会) ,中国省市区镇村二级三级四级五级联动地址数据。
Stars: ✭ 11,727 (+38990%)
Mutual labels:  address
Addok
Search engine for address. Only address.
Stars: ✭ 226 (+653.33%)
Mutual labels:  address
Addressgenerator
💰 A macOS app to safely generate cryptocurrency address
Stars: ✭ 109 (+263.33%)
Mutual labels:  address
Neb.js
Stars: ✭ 80 (+166.67%)
Mutual labels:  address
Node Postal
NodeJS bindings to libpostal for fast international address parsing/normalization
Stars: ✭ 165 (+450%)
Mutual labels:  address
Usaddress
🇺🇸 a python library for parsing unstructured address strings into address components
Stars: ✭ 1,165 (+3783.33%)
Mutual labels:  address
Wx selectarea
微信小程序-省市(区)地址选择联动 🌋
Stars: ✭ 251 (+736.67%)
Mutual labels:  address
Ngx Address
A simple address picker in angular.
Stars: ✭ 44 (+46.67%)
Mutual labels:  address
Ship
A simple, handy network addressing multitool with plenty of features
Stars: ✭ 81 (+170%)
Mutual labels:  address
Area Puppeteer
基于 puppeteer 的中国行政区域抓取爬虫
Stars: ✭ 144 (+380%)
Mutual labels:  address
administrative-divisions-of-China-on-Python
中华人民共和国行政区划爬虫,分为省级、地级、县级、乡级、村级,最多五级连动,可通过本项目自行爬取数据也可使用本项目在线接口直接调用。
Stars: ✭ 91 (+203.33%)
Mutual labels:  address

Bitcoin Address Validator

Author Build Packagist Version Software License Total Downloads

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

Requirements

  • PHP >= 7.3
PHP Package Version
7.x v1.0
8.x v2.0+

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

Installation

Install the package via composer:

composer require kielabokkie/bitcoin-address-validator

Usage

First you instantiate the validator class:

$addressValidator = new \Kielabokkie\Bitcoin\AddressValidator;

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

$addressValidator->isValid('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i');

Legacy (P2PKH) address:

$addressValidator->isPayToPublicKeyHash('1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i');

Segwit (P2SH) address:

$addressValidator->isPayToScriptHash('3ALJH9Y951VCGcVZYAdpA3KchoP9McEj1G');

Native segwit (bech32) address:

$addressValidator->isBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');

Taproot (P2TR) address:

$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:

// Both valid
$addressValidator->includeTestnet()->isBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
$addressValidator->includeTestnet()->isBech32('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx');

If you want to validate only testnet addresses you can do that as follows:

// Invalid
$addressValidator->onlyTestnet()->isBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
// Valid
$addressValidator->onlyTestnet()->isBech32('tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx');

Testing

This package is tested against the test data of the official bitcoin/bitcoin repo. If you come across an address that is not validated correctly please open an issue for it.

Run the tests with:

composer test

Credits

This package is based on the following packages and uses a lot of their code:

All credit goes to the original authors.

Donate

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

A donation would be much appreciated: 32vtWJSomccxQ6y1tgSwSHXN5PChpdYy27

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].