定制 raphaelcangucu/laravel-crypto-address-validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

raphaelcangucu/laravel-crypto-address-validator

最新稳定版本:v1.3.0

Composer 安装命令:

composer require raphaelcangucu/laravel-crypto-address-validator

包简介

Laravel package for validating cryptocurrency wallet addresses across multiple coins

README 文档

README

Latest Version on Packagist Tests Total Downloads

A Laravel package for validating cryptocurrency wallet addresses across multiple blockchains. Built on top of the multicoin-address-validator library.

Features

  • 25+ Cryptocurrencies Supported: Bitcoin, Ethereum, Cardano, Solana, XRP, Litecoin, Bitcoin Cash, and many more
  • Network Support: Mainnet, testnet, and stagenet validation
  • Laravel Integration: Service provider, facade, and dependency injection support
  • Flexible Configuration: Customizable validation rules and options
  • High Performance: Optimized for speed and accuracy
  • Comprehensive Testing: 100% test coverage with extensive test suite

Supported Cryptocurrencies

Bitcoin (BTC), Ethereum (ETH), Cardano (ADA), Solana (SOL), XRP, Litecoin (LTC), Bitcoin Cash (BCH), Monero (XMR), TRON (TRX), Polkadot (DOT), Dogecoin (DOGE), Chainlink (LINK), Polygon (MATIC), Avalanche (AVAX), Cosmos (ATOM), Tezos (XTZ), VeChain (VET), Algorand (ALGO), Hedera (HBAR), NEAR Protocol (NEAR), Filecoin (FIL), The Graph (GRT), Stellar (XLM), EOS, IOTA, and all ERC-20 tokens.

Installation

You can install the package via composer:

composer require raphaelcangucu/laravel-crypto-address-validator

The package will automatically register its service provider.

You can publish the config file with:

php artisan vendor:publish --tag="crypto-address-validator-config"

This is the contents of the published config file:

<?php

// config for CryptoAddressValidator
return [
    /*
    |--------------------------------------------------------------------------
    | Default Currency
    |--------------------------------------------------------------------------
    |
    | The default currency to use when validating addresses if no currency
    | is specified. This can be either a currency symbol (e.g., 'btc') or
    | the full currency name (e.g., 'bitcoin').
    |
    */
    'default_currency' => 'btc',

    /*
    |--------------------------------------------------------------------------
    | Default Network Type
    |--------------------------------------------------------------------------
    |
    | The default network type to use for validation. Options include:
    | 'prod' (mainnet), 'testnet', 'stagenet' (for supported currencies)
    |
    */
    'default_network_type' => 'prod',

    /*
    |--------------------------------------------------------------------------
    | Strict Mode
    |--------------------------------------------------------------------------
    |
    | When enabled, strict mode will enforce additional validation rules
    | such as EIP-55 checksum validation for Ethereum addresses.
    | When disabled, the validator is more permissive.
    |
    */
    'strict_mode' => false,
];

Usage

Facade Usage

use CryptoAddressValidator\Facades\CryptoAddressValidator;

// Validate a Bitcoin address
$isValid = CryptoAddressValidator::validate('1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2', 'btc');
// Returns: true

// Validate an Ethereum address
$isValid = CryptoAddressValidator::validate('0x742d35Cc6339C4532CE58b5D3Ea8d5A8d6F6395C', 'eth');
// Returns: true

// Validate with options
$isValid = CryptoAddressValidator::validate(
    'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx',
    'btc',
    ['networkType' => 'testnet']
);
// Returns: true

// Get all supported currencies
$currencies = CryptoAddressValidator::getCurrencies();

// Find a specific currency
$currency = CryptoAddressValidator::findCurrency('btc');
// Returns: ['symbol' => 'btc', 'name' => 'Bitcoin', ...]

// Check if a currency is supported
$isSupported = CryptoAddressValidator::isSupported('btc');
// Returns: true

Dependency Injection

use CryptoAddressValidator\CryptoAddressValidator;

class PaymentController extends Controller
{
    public function validateAddress(CryptoAddressValidator $validator, Request $request)
    {
        $address = $request->input('address');
        $currency = $request->input('currency');
        
        if ($validator->validate($address, $currency)) {
            return response()->json(['valid' => true]);
        }
        
        return response()->json(['valid' => false, 'message' => 'Invalid address']);
    }
}

Validation in Form Requests

use CryptoAddressValidator\Facades\CryptoAddressValidator;
use Illuminate\Foundation\Http\FormRequest;

class PaymentRequest extends FormRequest
{
    public function rules()
    {
        return [
            'address' => [
                'required',
                'string',
                function ($attribute, $value, $fail) {
                    if (!CryptoAddressValidator::validate($value, $this->currency)) {
                        $fail('The '.$attribute.' is not a valid cryptocurrency address.');
                    }
                },
            ],
            'currency' => 'required|string',
        ];
    }
}

Custom Validation Rule

You can create a custom validation rule:

use CryptoAddressValidator\Facades\CryptoAddressValidator;
use Illuminate\Contracts\Validation\Rule;

class CryptoAddress implements Rule
{
    protected $currency;
    protected $options;

    public function __construct($currency, $options = [])
    {
        $this->currency = $currency;
        $this->options = $options;
    }

    public function passes($attribute, $value)
    {
        return CryptoAddressValidator::validate($value, $this->currency, $this->options);
    }

    public function message()
    {
        return 'The :attribute must be a valid ' . strtoupper($this->currency) . ' address.';
    }
}

Usage:

$request->validate([
    'btc_address' => ['required', new CryptoAddress('btc')],
    'eth_address' => ['required', new CryptoAddress('eth')],
    'testnet_address' => ['required', new CryptoAddress('btc', ['networkType' => 'testnet'])],
]);

Advanced Usage

Validation Options

// Validate with specific network
CryptoAddressValidator::validate($address, 'btc', [
    'networkType' => 'testnet' // 'prod', 'testnet', 'stagenet'
]);

// Ethereum with strict checksum validation
CryptoAddressValidator::validate($address, 'eth', [
    'validateChecksum' => true
]);

// Custom validation options
CryptoAddressValidator::validate($address, 'xrp', [
    'validateTag' => true
]);

Getting Currency Information

// Get all supported currencies
$currencies = CryptoAddressValidator::getCurrencies();
/*
Returns array like:
[
    [
        'symbol' => 'btc',
        'name' => 'Bitcoin',
        'networkTypes' => ['prod', 'testnet']
    ],
    // ... more currencies
]
*/

// Find specific currency
$bitcoin = CryptoAddressValidator::findCurrency('bitcoin');
$ethereum = CryptoAddressValidator::findCurrency('eth');

// Check support
$isSupported = CryptoAddressValidator::isSupported('btc'); // true
$isSupported = CryptoAddressValidator::isSupported('unknown'); // false

Access Underlying Validator

// Get the underlying multicoin validator instance
$validator = CryptoAddressValidator::getValidator();

// Use advanced features directly
$result = $validator->validateWithDetails($address, $currency);

Testing

composer test

Performance

The package is optimized for high performance:

  • Fast validation: Uses native cryptocurrency validation algorithms
  • No external dependencies: All validation is done locally
  • Minimal dependencies: Built on a lightweight foundation
  • Memory efficient: Low memory footprint even with large validation sets

Error Handling

The package handles errors gracefully:

try {
    $isValid = CryptoAddressValidator::validate($address, $currency);
} catch (\Exception $e) {
    // Handle validation errors
    Log::error('Address validation failed: ' . $e->getMessage());
    $isValid = false;
}

Security

  • Input validation: All inputs are properly validated and sanitized
  • No external API calls: All validation is done locally for security and performance
  • Safe error handling: Errors don't expose sensitive information

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 11.53k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固