All Projects → vtm9 → adequate_crypto_address

vtm9 / adequate_crypto_address

Licence: MIT license
A Ruby Library for dealing with validation cryptocurrency addresses

Programming Languages

ruby
36898 projects - #4 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to adequate crypto address

cashuwallet
Cashu is a cryptocurrency wallet for smartphones. Be your own bank. Accept payments or spend crypto directly from your phone.
Stars: ✭ 35 (+94.44%)
Mutual labels:  ripple, dash, zcash, bitcoincash
wallet-address-validator
Useful library for validation of Bitcoin, Litecoin, Ethereum and other cryptocoin addresses
Stars: ✭ 240 (+1233.33%)
Mutual labels:  ripple, dash, zcash
crypto-trader
Cryptocurrency investing using Dollar Cost Averaging (not limited to dollar)
Stars: ✭ 47 (+161.11%)
Mutual labels:  dash, zcash
gdax bot
gdax_bot - Micro dollar cost averaging for crypto
Stars: ✭ 57 (+216.67%)
Mutual labels:  ltc, bitcoincash
Valets
Command line wallets generator (Bitcoin, Bitcoin cash, Ethereum, Ethereum classic, Dash, Zcash, Dogecoin, Litecoin, Navcoin, Vertcoin, Reddcoin, Emercoin)
Stars: ✭ 46 (+155.56%)
Mutual labels:  dash, zcash
paper-wallet-generator
Paper Wallet Generator for Bitcoin & Altcoins
Stars: ✭ 35 (+94.44%)
Mutual labels:  dash, ltc
payserver
Blockchain micro-service which is working on zigzag.io. It served as unified API for other micro-services to receive and send cryptocurrency assets.
Stars: ✭ 24 (+33.33%)
Mutual labels:  dash, bitcoincash
evian
www.balletcrypto.org/
Stars: ✭ 21 (+16.67%)
Mutual labels:  dash, ltc
Cryptocurrency Cli
💰 Cryptocurrency Portfolio On The Command Line 💰
Stars: ✭ 99 (+450%)
Mutual labels:  ripple, dash
Moneda Cli
Command line to track cryptocurrency prices
Stars: ✭ 114 (+533.33%)
Mutual labels:  ripple, dash
Coinbin.org
₿ A Human–Friendly API Service for Crypto Currency Information.
Stars: ✭ 253 (+1305.56%)
Mutual labels:  ripple
ShapeView
打造万能shape,再也不用写很多xml了,可以当做TextView,Button,EditText等多种控件,方便实用
Stars: ✭ 34 (+88.89%)
Mutual labels:  ripple
ripple-effect-click
Add ripple effect to any element you want when the click action happens ("ripple effect")
Stars: ✭ 15 (-16.67%)
Mutual labels:  ripple
CovidCountyDash.jl
covid-county-dash.herokuapp.com
Stars: ✭ 26 (+44.44%)
Mutual labels:  dash
Coinapi Sdk
SDKs for CoinAPI
Stars: ✭ 238 (+1222.22%)
Mutual labels:  ripple
dash-mantine-components
Plotly Dash components based on Mantine React Components
Stars: ✭ 263 (+1361.11%)
Mutual labels:  dash
Material Ripple
Android L Ripple effect wrapper for Views
Stars: ✭ 2,344 (+12922.22%)
Mutual labels:  ripple
Xrpl Dev Portal
XRP Ledger developer portal with documentation and examples
Stars: ✭ 198 (+1000%)
Mutual labels:  ripple
Kau
An extensive collection of Kotlin Android Utils
Stars: ✭ 182 (+911.11%)
Mutual labels:  ripple
tokencore
The core components of the blockchain wallet backend, support a variety of blockchain address generation and offline signatures
Stars: ✭ 412 (+2188.89%)
Mutual labels:  ltc

AdequateCryptoAddress

Gem Version Build Status Code Climate Coverage Status Downloads Docs License

Simple wallet address validator and normalizer for cryptocurrencies addresses in Ruby.

Inspired by ognus/wallet-address-validator.

Installation

Add this line to your application's Gemfile:

gem 'adequate_crypto_address'

Or install it yourself as:

gem install adequate_crypto_address

Main API

.valid? (address, currency [, type = :prod])
Parameters
  • address - Wallet address to validate.
  • currency - Currency name string or symbol in any case, :bitcoin or 'BTC' or :btc or 'BitCoin'
  • type - Optional. You can enforce validation with specific type. Not all currencies support types.

Returns true if the address (string) is a valid wallet address for the crypto currency specified, see below for supported currencies.

Supported crypto currencies

  • Bitcoin/BTC, 'bitcoin' or 'BTC' types: :segwit_v0_keyhash :segwit_v0_scripthash :hash160 :p2sh
  • BitcoinCash/BCH, 'bitcoincash' or 'BCH' types: :p2sh :p2pkh :p2pkhtest :p2shtest
  • Dash, 'dash' or 'DASH' types: :prod :test
  • Zcash/ZEC, 'zcash' or 'ZEC' types: :prod :test
  • Ethereum/ETH, 'ethereum' or 'ETH'
  • Ripple/XRP, 'ripple' or 'XRP'
  • Toncoin, 'TON'
  • Monero/XRM, 'monero'

Usage

Validation

require 'adequate_crypto_address'
# BTC
AdequateCryptoAddress.valid?('12QeMLzSrB8XH8FvEzPMVoRxVAzTr5XM2y', 'BTC') #=> true
AdequateCryptoAddress.valid?('3NJZLcZEEYBpxYEUGewU4knsQRn1WM5Fkt', :bitcoin, :p2sh) #=> true

# BCH
AdequateCryptoAddress.valid?('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', :bch) #=> true
AdequateCryptoAddress.valid?('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', :BCH, :p2pkhtest) #=> true

# ETH
AdequateCryptoAddress.valid?('0xde709f2102306220921060314715629080e2fb77', :ETH) #=> true
AdequateCryptoAddress.valid?('de709f2102306220921060314715629080e2fb77', :ethereum) #=> true

Normalization

*Not all currencies support this feature.
require 'adequate_crypto_address'

# BCH
AdequateCryptoAddress.address('mmRH4e9WW4ekZUP5HvBScfUyaSUjfQRyvD', 'bch').cash_address #=> "bchtest:qpqtmmfpw79thzq5z7s0spcd87uhn6d34uqqem83hf"
AdequateCryptoAddress.address('bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk', 'bch').legacy_address #=> "1LcerwTc1oPsMtByDCNUXFxReZpN1EXHoe"

address_string = 'qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk'
addr = AdequateCryptoAddress.address(address_string, 'bch')
addr.prefix #=> "bitcoincash"
addr.type #=> :p2pkh
addr.address #=> "bitcoincash:qrtj3rd8524cndt2eew3s6wljqggmne00sgh4kfypk"

# ETH
AdequateCryptoAddress.address('D1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb', 'eth').address #=> "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"

ActiveRecord validation example

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 AdequateCryptoAddress.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

Add your currnecy

# frozen_string_literal: true
# for Rails /config/initializers/adequate_crypto_address.rb
module AdequateCryptoAddress
  class Coin
    attr_reader :address

    def initialize(address_sring)
      @address = address_sring
    end

    def valid?(_type)
      address.present?
    end
  end
end

AdequateCryptoAddress.valid?('addr', :coin) #=> true

Development

Run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

  1. Fork the repo
  2. Grab dependencies: bundle install
  3. Make sure everything is working: bundle exec rake spec
  4. Make your changes
  5. Test your changes
  6. Create a Pull Request
  7. Celebrate!!!!!

Notes

Bug reports and pull requests are welcome on GitHub at https://github.com/vtm9/adequate_crypto_address/issues

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].