
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
crypto_address_validator
Advanced tools
Simple wallet address validator and normalizer for cryptocurrencies addresses in Ruby.
Inspired by vtm9/adequate_crypto_address.
Add this line to your application's Gemfile:
gem 'crypto_address_validator'
Or install it yourself as:
gem install crypto_address_validator
:bitcoin
or 'BTC'
or :btc
or 'BitCoin'
Returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies.
'bitcoin'
or 'BTC'
types: :segwit_v0_keyhash :segwit_v0_scripthash :hash160 :p2sh
'bitcoincash'
or 'BCH'
types: :p2sh :p2pkh :p2pkhtest :p2shtest
'dash'
or 'DASH'
types: :prod :test
'zcash'
or 'ZEC'
types: :prod :test
'ethereum'
or 'ETH'
'ripple'
or 'XRP'
require 'crypto_address_validator'
# BTC
CryptoAddressValidator.valid?('12QeMLzSrB8XH8FvEzPMVoRxVAzTr5XM2y', 'BTC') #=> true
CryptoAddressValidator.valid?('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', :bitcoin, :p2sh) #=> true
# BTC(non SegWit address validation)
CryptoAddressValidator.valid?('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', :bitcoin, [:p2sh, :hash160]) #=> true
# BCH
CryptoAddressValidator.valid?('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :bch) #=> true
CryptoAddressValidator.valid?('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :p2pkhtest) #=> true
# ETH
CryptoAddressValidator.valid?('0xde709f2102306220921060314715629080e2fb77', :ETH) #=> true
CryptoAddressValidator.valid?('de709f2102306220921060314715629080e2fb77', :ethereum) #=> true
require 'crypto_address_validator'
# BCH
CryptoAddressValidator.address('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', 'bch').cash_address #=> "bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf"
CryptoAddressValidator.address('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', 'bch').legacy_address #=> "1LcerwTc1oPsMtByDCNUXFxReZpN1EXHoe"
address_string = 'qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk'
addr = CryptoAddressValidator.address(address_string, 'bch')
addr.prefix #=> "bitcoincash"
addr.type #=> :p2pkh
addr.address #=> "bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk"
# ETH
CryptoAddressValidator.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth').address #=> "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"
class Model < ActiveRecord::Base
attribute :address, :string
attribute :dest_tag, :string
attribute :currency, :string
validate :validate_address_type
validate :validate_destination_tag
def validate_address_type
errors.add(:address, 'invalid address') unless CryptoAddressValidator.valid?(address, currency)
end
# for Ripple
def validate_destination_tag
errors.add(:dest_tag, 'invalid destination tag') if dest_tag.present? && !(dest_tag =~ /\A\d{1,10}\z/)
end
end
# frozen_string_literal: true
# for Rails /config/initializers/crypto_address_validator.rb
module CryptoAddressValidator
class Coin
attr_reader :address
def initialize(address_sring)
@address = address_sring
end
def valid?(_type)
address.present?
end
end
end
CryptoAddressValidator.valid?('addr', :coin) #=> true
Run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
bundle install
bundle exec rake spec
Bug reports and pull requests are welcome on GitHub at https://github.com/sequoir/crypto_address_validator/issues
FAQs
Unknown package
We found that crypto_address_validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.