Giter Club home page Giter Club logo

crypto-address-validator's Introduction

@swyftx/api-crypto-address-validator

Simple wallet address validator for validating Bitcoin and 130 (and counting) other altcoin addresses in Node.js and browser.

Forked from ognus/wallet-address-validator which was forked from ryanralph/altcoin-address.

Did you know? This package is under active development by Swyftx. Swyftx allows you to buy and sell Bitcoin, Etherium, Ripple and many more assets using Australian Dollars. Buy Bitcoin in Australia

File size is ~189.4 kB (minifed and gzipped - ~69.7% smaller).

Installation

Yarn

yarn add @swyftx/api-crypto-address-validator

NPM

npm install @swyftx/api-crypto-address-validator

Browser

<script src="wallet-address-validator.min.js"></script>

Minified Packed Frontend

import walletAddressValidatorMinJs from '@swyftx/api-crypto-address-validator/dist/wallet-address-validator.min.js'

API

validate (address [, currency = 'bitcoin'[, networkType = 'prod' [, addressType = ['all']]])
Parameters
  • address - Wallet address to validate.
  • currency - Optional. Currency name or symbol, e.g. 'bitcoin' (default), 'litecoin' or 'LTC'
  • networkType - Optional. Use 'prod' (default) to enforce standard address, 'testnet' to enforce testnet address and 'both' to enforce nothing.
  • addressType - Optional. Specifies what version of the address should be validated. Defaults to 'legacy', but can be changed on a per asset basis.

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

Supported crypto currencies

  • 0x/zrx '0x' or 'zrx'
  • Aave/lend 'Aave' or 'lend'
  • AdEx/adx 'AdEx' or 'adx'
  • aelf/ELF 'aelf' or 'ELF'
  • Aeternity/ae 'Aeternity' or 'ae'
  • Algorand/algo 'Algorand' or 'algo'
  • Aragon/ant 'Aragon' or 'ant'
  • Ardor/ardr 'Ardor' or 'ardr'
  • Augur/rep 'Augur' or 'rep'
  • AuroraCoin/aur 'AuroraCoin' or 'aur'
  • Australian Dollars/aud 'Australian Dollars' or 'aud'
  • Bancor/bnt 'Bancor' or 'bnt'
  • Bankex/bkx 'Bankex' or 'bkx'
  • BasicAttentionToken/bat 'BasicAttentionToken' or 'bat'
  • BeaverCoin/bvc 'BeaverCoin' or 'bvc'
  • BinanceCoin/bnb 'BinanceCoin' or 'bnb'
  • BioCoin/bio 'BioCoin' or 'bio'
  • Bitcoin/btc 'Bitcoin' or 'btc'
  • Bitcoin Diamond/bcd 'Bitcoin Diamond' or 'bcd'
  • BitcoinCash/bcc 'BitcoinCash' or 'bcc'
  • BitcoinCash/bch 'BitcoinCash' or 'bch'
  • BitcoinGold/btg 'BitcoinGold' or 'btg'
  • BitcoinPrivate/btcp 'BitcoinPrivate' or 'btcp'
  • BitcoinZ/btcz 'BitcoinZ' or 'btcz'
  • Bitquence/bqx 'Bitquence' or 'bqx'
  • Bitshares/bts 'Bitshares' or 'bts'
  • BitTorrent/btt 'BitTorrent' or 'btt'
  • Blockstack/stx 'Blockstack' or 'stx'
  • Callisto/clo 'Callisto' or 'clo'
  • Cardano/ada 'Cardano' or 'ada'
  • Chainlink/link 'Chainlink' or 'link'
  • Civic/cvc 'Civic' or 'cvc'
  • Cosmos/atom 'Cosmos' or 'atom'
  • Dash/dash 'Dash' or 'dash'
  • Decentraland/MANA 'Decentraland' or 'MANA'
  • Decred/dcr 'Decred' or 'dcr'
  • Dent/dent 'Dent' or 'dent'
  • DigiByte/dgb 'DigiByte' or 'dgb'
  • District0x/dnt 'District0x' or 'dnt'
  • DogeCoin/doge 'DogeCoin' or 'doge'
  • Enigma/eng 'Enigma' or 'eng'
  • Enjin Coin/enj 'Enjin Coin' or 'enj'
  • EOS/eos 'EOS' or 'eos'
  • Ethereum/eth 'Ethereum' or 'eth'
  • EthereumClassic/etc 'EthereumClassic' or 'etc'
  • EtherZero/etz 'EtherZero' or 'etz'
  • ETHOS/ethos 'ETHOS' or 'ethos'
  • Expanse/exp 'Expanse' or 'exp'
  • FreiCoin/frc 'FreiCoin' or 'frc'
  • FunFair/fun 'FunFair' or 'fun'
  • GameCredits/game 'GameCredits' or 'game'
  • GarliCoin/grlc 'GarliCoin' or 'grlc'
  • Gnosis/gno 'Gnosis' or 'gno'
  • Golem/gnt 'Golem' or 'gnt'
  • Golem/gnt 'Golem' or 'gnt'
  • Hedera Hashgraph/hbar 'Hedera Hashgraph' or 'hbar'
  • Holo/HOT 'Holo' or 'HOT'
  • Horizen/zen 'Horizen' or 'zen'
  • Hush/hush 'Hush' or 'hush'
  • ICON/icx 'ICON' or 'icx'
  • iExec RLC/RLC 'iExec RLC' or 'RLC'
  • iExec RLC/rlc 'iExec RLC' or 'rlc'
  • Internet of Services/IOST 'Internet of Services' or 'IOST'
  • Iota/iota 'Iota' or 'iota'
  • Komodo/kmd 'Komodo' or 'kmd'
  • Lisk/lsk 'Lisk' or 'lsk'
  • LiteCoin/ltc 'LiteCoin' or 'ltc'
  • Matchpool/gup 'Matchpool' or 'gup'
  • MegaCoin/mec 'MegaCoin' or 'mec'
  • Melon/mln 'Melon' or 'mln'
  • Metal/mtl 'Metal' or 'mtl'
  • Monacao/mco 'Monacao' or 'mco'
  • MonaCoin/mona 'MonaCoin' or 'mona'
  • Monero/xmr 'Monero' or 'xmr'
  • NameCoin/nmc 'NameCoin' or 'nmc'
  • Nano/nano 'Nano' or 'nano'
  • NEM/xem 'NEM' or 'xem'
  • Neo/neo 'Neo' or 'neo'
  • NeoGas/gas 'NeoGas' or 'gas'
  • Nexus/nxs 'Nexus' or 'nxs'
  • Numeraire/nmr 'Numeraire' or 'nmr'
  • Odyssey/ocn 'Odyssey' or 'ocn'
  • OmiseGO/omg 'OmiseGO' or 'omg'
  • Ontology/ont 'Ontology' or 'ont'
  • Ontology Gas/ong 'Ontology Gas' or 'ong'
  • Paxos Standard Token/pax 'Paxos Standard Token' or 'pax'
  • PeerCoin/ppc 'PeerCoin' or 'ppc'
  • PIVX/pivx 'PIVX' or 'pivx'
  • Polymath/poly 'Polymath' or 'poly'
  • Populous/ppt 'Populous' or 'ppt'
  • PowerLedger/powr 'PowerLedger' or 'powr'
  • PrimeCoin/xpm 'PrimeCoin' or 'xpm'
  • ProtoShares/pts 'ProtoShares' or 'pts'
  • Pundi X/npxs 'Pundi X' or 'npxs'
  • Qtum/qtum 'Qtum' or 'qtum'
  • RaiBlocks/xrb 'RaiBlocks' or 'xrb'
  • Ravencoin/rvn 'Ravencoin' or 'rvn'
  • RipioCreditNetwork/rcn 'RipioCreditNetwork' or 'rcn'
  • Ripple/xrp 'Ripple' or 'xrp'
  • Salt/salt 'Salt' or 'salt'
  • Siacoin/sc 'Siacoin' or 'sc'
  • SnowGem/sng 'SnowGem' or 'sng'
  • SolarCoin/slr 'SolarCoin' or 'slr'
  • Status/snt 'Status' or 'snt'
  • STEEM/steem 'STEEM' or 'steem'
  • Stellar Lumens/xlm 'Stellar Lumens' or 'xlm'
  • Storj/storj 'Storj' or 'storj'
  • Storm/storm 'Storm' or 'storm'
  • Stratis/strat 'Stratis' or 'strat'
  • Substratum/sub 'Substratum' or 'sub'
  • Swarm City/swt 'Swarm City' or 'swt'
  • Syscoin/sys 'Syscoin' or 'sys'
  • TenX/pay 'TenX' or 'pay'
  • Tether/usdt 'Tether' or 'usdt'
  • Tezos/XTZ 'Tezos' or 'XTZ'
  • THETA/theta 'THETA' or 'theta'
  • Tron/trx 'Tron' or 'trx'
  • TrueUSD/tusd 'TrueUSD' or 'tusd'
  • USD Coin/usdc 'USD Coin' or 'usdc'
  • VeChain/vet 'VeChain' or 'vet'
  • Verge/xvg 'Verge' or 'xvg'
  • VertCoin/vtc 'VertCoin' or 'vtc'
  • Viberate/vib 'Viberate' or 'vib'
  • VoteCoin/vot 'VoteCoin' or 'vot'
  • WaltonChain/wtc 'WaltonChain' or 'wtc'
  • Waves/waves 'Waves' or 'waves'
  • Wings/wings 'Wings' or 'wings'
  • ZCash/zec 'ZCash' or 'zec'
  • ZClassic/zcl 'ZClassic' or 'zcl'
  • ZenCash/zen 'ZenCash' or 'zen'
  • Zilliqa/zil 'Zilliqa' or 'zil'

Usage example

Node

const WAValidator = require('@swyftx/api-crypto-address-validator')

const valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'BTC')

if (valid) {
  console.log('This is a valid address')
} else {
  console.log('Address INVALID')
}
// This will log 'This is a valid address' to the console.
const WAValidator = require('@swyftx/api-crypto-address-validator')

const valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'litecoin', 'testnet')

if (valid) {
  console.log('This is a valid address')
} else {
  console.log('Address INVALID')
}
// As this is a invalid litecoin address 'Address INVALID' will be logged to console.

Browser

<script src="wallet-address-validator.min.js"></script>
// WAValidator is exposed as a global (window.WAValidator)
const valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'bitcoin')

if (valid) {
  alert('This is a valid address')
} else {
  alert('Address INVALID')
}
// This should show a pop up with text 'This is a valid address'.

crypto-address-validator's People

Contributors

adaxi avatar ajoslin avatar cernael avatar defunctzombie avatar dependabot[bot] avatar dominique-blockchain avatar dpominov avatar freewil avatar gusgold avatar hellcatz avatar iddoberger avatar iobaixas avatar martin-key avatar mcuelenaere avatar nixoid avatar nodecode avatar ognus avatar paulsky avatar pavelvoronov avatar r3volut1oner avatar ralphtheninja avatar ryanralph avatar yusufsahinhamza avatar zeppelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

crypto-address-validator's Issues

BitcoinCash Address validation

Currently, the validator only supports legacy BitcoinCash addresses. The new 'SLP' or 'Cash' (bitcoincash:xxx) addresses are not supported.

I could create a PR for a standalone BCH validator, and use this project https://github.com/bitcoincashjs/bchaddrjs as a dependency? Similar as the IOTA approach?

What are your thoughts about this?

Support for Polkadot addresses

Hello and thanks for this great package!

It would be cool to add Polkadot and Kusama to the supported networks.
The address format is described here. Looks similar to Bitcoin, but they say "Base-58-check from Bitcoin with some minor modifications", so I don't know if the BTC validator will just work.

Add support to ts type

Hi, let you what type i created to get typescript type

type CryptoAddressValidator = {
  /**
   * @param {string} address Wallet address to validate.
   * @param {string} [currency="bitcoin"] - Optional. Currency name or symbol,
   *  e.g. 'bitcoin' (default), 'litecoin' or 'LTC'
   * @param {string} [networkType="prod"] - Optional. Use 'prod' (default) to enforce standard address,
   *  'testnet' to enforce testnet address and 'both' to enforce nothing.
   * @param {string} [addressType="legacy"] - Optional. Specifies what version of the address should be validated.
   *  Defaults to 'legacy', but can be changed on a per asset basis.
   *
   * @description
   * Simple wallet address validator for validating Bitcoin and other altcoins addresses in Node.js and browser.
   *
   * 0x/zrx '0x' or 'zrx'
   *
   * AdEx/adx 'AdEx' or 'adx'
   *
   * aelf/ELF 'aelf' or 'ELF'
   *
   * Aeternity/ae 'Aeternity' or 'ae'
   *
   * Aragon/ant 'Aragon' or 'ant'
   *
   * Ardor/ardr 'Ardor' or 'ardr'
   *
   * Augur/rep 'Augur' or 'rep'
   *
   * AuroraCoin/aur 'AuroraCoin' or 'aur'
   *
   * Australian Dollars/aud 'Australian Dollars' or 'aud'
   *
   * Bancor/bnt 'Bancor' or 'bnt'
   *
   * Bankex/bkx 'Bankex' or 'bkx'
   *
   * BasicAttentionToken/bat 'BasicAttentionToken' or 'bat'
   *
   * BeaverCoin/bvc 'BeaverCoin' or 'bvc'
   *
   * BinanceCoin/bnb 'BinanceCoin' or 'bnb'
   *
   * BioCoin/bio 'BioCoin' or 'bio'
   *
   * Bitcoin/btc 'Bitcoin' or 'btc'
   *
   * Bitcoin Diamond/bcd 'Bitcoin Diamond' or 'bcd'
   *
   * BitcoinCash/bch 'BitcoinCash' or 'bch'
   *
   * BitcoinCash/bcc 'BitcoinCash' or 'bcc'
   *
   * BitcoinGold/btg 'BitcoinGold' or 'btg'
   *
   * BitcoinPrivate/btcp 'BitcoinPrivate' or 'btcp'
   *
   * BitcoinZ/btcz 'BitcoinZ' or 'btcz'
   *
   * Bitquence/bqx 'Bitquence' or 'bqx'
   *
   * Bitshares/bts 'Bitshares' or 'bts'
   *
   * BitTorrent/btt 'BitTorrent' or 'btt'
   *
   * Callisto/clo 'Callisto' or 'clo'
   *
   * Cardano/ada 'Cardano' or 'ada'
   *
   * Chainlink/link 'Chainlink' or 'link'
   *
   * Civic/cvc 'Civic' or 'cvc'
   *
   * Cosmos/atom 'Cosmos' or 'atom'
   *
   * Dash/dash 'Dash' or 'dash'
   *
   * Decentraland/MANA 'Decentraland' or 'MANA'
   *
   * Decred/dcr 'Decred' or 'dcr'
   *
   * Dent/dent 'Dent' or 'dent'
   *
   * DigiByte/dgb 'DigiByte' or 'dgb'
   *
   * District0x/dnt 'District0x' or 'dnt'
   *
   * DogeCoin/doge 'DogeCoin' or 'doge'
   *
   * Enjin Coin/enj 'Enjin Coin' or 'enj'
   *
   * EOS/eos 'EOS' or 'eos'
   *
   * Ethereum/eth 'Ethereum' or 'eth'
   *
   * EthereumClassic/etc 'EthereumClassic' or 'etc'
   *
   * EtherZero/etz 'EtherZero' or 'etz'
   *
   * ETHOS/ethos 'ETHOS' or 'ethos'
   *
   * Expanse/exp 'Expanse' or 'exp'
   *
   * FreiCoin/frc 'FreiCoin' or 'frc'
   *
   * FunFair/fun 'FunFair' or 'fun'
   *
   * GameCredits/game 'GameCredits' or 'game'
   *
   * GarliCoin/grlc 'GarliCoin' or 'grlc'
   *
   * Gnosis/gno 'Gnosis' or 'gno'
   *
   * Golem/gnt 'Golem' or 'gnt'
   *
   * Golem/gnt 'Golem' or 'gnt'
   *
   * Holo/HOT 'Holo' or 'HOT'
   *
   * Horizen/zen 'Horizen' or 'zen'
   *
   * Hush/hush 'Hush' or 'hush'
   *
   * ICON/icx 'ICON' or 'icx'
   *
   * iExec RLC/RLC 'iExec RLC' or 'RLC'
   *
   * iExec RLC/rlc 'iExec RLC' or 'rlc'
   *
   * Internet of Services/IOST 'Internet of Services' or 'IOST'
   *
   * Iota/iota 'Iota' or 'iota'
   *
   * Komodo/kmd 'Komodo' or 'kmd'
   *
   * Lisk/lsk 'Lisk' or 'lsk'
   *
   * LiteCoin/ltc 'LiteCoin' or 'ltc'
   *
   * Matchpool/gup 'Matchpool' or 'gup'
   *
   * MegaCoin/mec 'MegaCoin' or 'mec'
   *
   * Melon/mln 'Melon' or 'mln'
   *
   * Metal/mtl 'Metal' or 'mtl'
   *
   * Monacao/mco 'Monacao' or 'mco'
   *
   * MonaCoin/mona 'MonaCoin' or 'mona'
   *
   * Monero/xmr 'Monero' or 'xmr'
   *
   * NameCoin/nmc 'NameCoin' or 'nmc'
   *
   * Nano/nano 'Nano' or 'nano'
   *
   * NEM/xem 'NEM' or 'xem'
   *
   * Neo/neo 'Neo' or 'neo'
   *
   * NeoGas/gas 'NeoGas' or 'gas'
   *
   * Nexus/nxs 'Nexus' or 'nxs'
   *
   * Numeraire/nmr 'Numeraire' or 'nmr'
   *
   * Odyssey/ocn 'Odyssey' or 'ocn'
   *
   * OmiseGO/omg 'OmiseGO' or 'omg'
   *
   * Ontology/ont 'Ontology' or 'ont'
   *
   * Paxos Standard Token/pax 'Paxos Standard Token' or 'pax'
   *
   * PeerCoin/ppc 'PeerCoin' or 'ppc'
   *
   * PIVX/pivx 'PIVX' or 'pivx'
   *
   * Polymath/poly 'Polymath' or 'poly'
   *
   * Populous/ppt 'Populous' or 'ppt'
   *
   * PowerLedger/powr 'PowerLedger' or 'powr'
   *
   * PrimeCoin/xpm 'PrimeCoin' or 'xpm'
   *
   * ProtoShares/pts 'ProtoShares' or 'pts'
   *
   * Pundi X/npxs 'Pundi X' or 'npxs'
   *
   * Qtum/qtum 'Qtum' or 'qtum'
   *
   * RaiBlocks/xrb 'RaiBlocks' or 'xrb'
   *
   * Ravencoin/rvn 'Ravencoin' or 'rvn'
   *
   * RipioCreditNetwork/rcn 'RipioCreditNetwork' or 'rcn'
   *
   * Ripple/xrp 'Ripple' or 'xrp'
   *
   * Salt/salt 'Salt' or 'salt'
   *
   * Siacoin/sc 'Siacoin' or 'sc'
   *
   * SnowGem/sng 'SnowGem' or 'sng'
   *
   * SolarCoin/slr 'SolarCoin' or 'slr'
   *
   * Status/snt 'Status' or 'snt'
   *
   * STEEM/steem 'STEEM' or 'steem'
   *
   * Stellar Lumens/xlm 'Stellar Lumens' or 'xlm'
   *
   * Storj/storj 'Storj' or 'storj'
   *
   * Storm/storm 'Storm' or 'storm'
   *
   * Stratis/strat 'Stratis' or 'strat'
   *
   * Substratum/sub 'Substratum' or 'sub'
   *
   * Swarm City/swt 'Swarm City' or 'swt'
   *
   * Syscoin/sys 'Syscoin' or 'sys'
   *
   * TenX/pay 'TenX' or 'pay'
   *
   * Tether/usdt 'Tether' or 'usdt'
   *
   * Tezos/XTZ 'Tezos' or 'XTZ'
   *
   * THETA/theta 'THETA' or 'theta'
   *
   * Tron/trx 'Tron' or 'trx'
   *
   * TrueUSD/tusd 'TrueUSD' or 'tusd'
   *
   * USD Coin/usdc 'USD Coin' or 'usdc'
   *
   * VeChain/vet 'VeChain' or 'vet'
   *
   * Verge/xvg 'Verge' or 'xvg'
   *
   * VertCoin/vtc 'VertCoin' or 'vtc'
   *
   * Viberate/vib 'Viberate' or 'vib'
   *
   * VoteCoin/vot 'VoteCoin' or 'vot'
   *
   * WaltonChain/wtc 'WaltonChain' or 'wtc'
   *
   * Waves/waves 'Waves' or 'waves'
   *
   * Wings/wings 'Wings' or 'wings'
   *
   * ZCash/zec 'ZCash' or 'zec'
   *
   * ZClassic/zcl 'ZClassic' or 'zcl'
   *
   * ZenCash/zen 'ZenCash' or 'zen'
   *
   * Zilliqa/zil 'Zilliqa' or 'zil'
   *
   */
  validate: (
    address: string,
    currency?: string,
    networkType?: 'prod' | 'testnet' | 'both',
    addressType?: string,
  ) => boolean;
}; 

Update jssha

jssha@2 throws a warning on install:

npm WARN deprecated [email protected]: jsSHA versions < 3.0.0 will no longer receive feature updates

Can you update the version? Or I can try to make a request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.