Skip to content

Python class that performs strong cryptocurrency address validation

License

Notifications You must be signed in to change notification settings

0x9090/CrypocurrencyAddressValidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Cryptocurrency Address Validation

BTC, LTC, XMR

This is a Python class which performs strong validation of different cryptocurrency addresses, chains, and ticker symbols. It will ensure that the data provided calculates to a correct value, and is syntactically safe to use. Segwit compatible

Validation Levels

  1. Length - Ensure the given address is the expected length
  2. Character Set - Ensure that only the expected characters are used in the address
  3. Character Position - Ensure that certain key characters are in their expected positions in the address
  4. Cryptographic - Deconstruct the address into its logical components, and validate that it parsed, and any checksums or signatures are correct

This library performs Levels 1 through 4 for all supported coins and address formats

Supported Address Formats

  • BTC / LTC: P2PKH, P2SH, Bech32
  • XMR: Standard Address, Subaddress, Integrated Address

Structure

This library has two dependencies: pysha3 and base58. You use this library by importing and calling static methods in the top-level Validation class. Coin tickers, chains, and names are case-insensitive. All functions return a boolean True/False answer.

class Validation:
    @staticmethod
    def is_btc_chain(chain): ...
    
    @staticmethod
    def is_xmr_chain(chain): ...
    
    @staticmethod
    def is_coin_ticker(coin): ...
    
    @staticmethod
    def is_coin_name(name): ...
    
    @staticmethod
    def is_address(coin, address): ...
    
    @staticmethod
    def is_btc_address(address): ...
    
    @staticmethod
    def is_ltc_address(address): ...
    
    @staticmethod
    def is_xmr_address(address, label=None): ...

Usage:

from Validation import Validation

if Validation.is_coin_ticker("BTC"):
    print("Valid")
    
if Validation.is_btc_chain("testnet"):
    print("Valid")
    
if Validation.is_xmr_chain("stagenet"):
    print("Valid")

if Validation.is_coin_name("lITeCoiN"):
    print("Valid")
   
if Validation.is_address("BTC", "3FkenCiXpSLqD8L79intRNXUgjRoH9sjXa"):
    print("Valid")
    
if Validation.is_address("BTC", "bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"):
    print("Valid")

if Validation.is_address("LTC", "LS78aoGtfuGCZ777x3Hmr6tcoW3WaYynx9"):
    print("Valid")

if Validation.is_address("XMR", "46E5ekYrZd5UCcmNuYEX24FRjWVMgZ1ob79cRViyfvLFZjfyMhPDvbuCe54FqLQvVCgRKP4UUMMW5fy3ZhVQhD1JLLufBtu"):
    print("Valid")

Disclaimers

I borrowed / modified code from these projects:

Please test throughly before using this in a production environment. There are no warranties, guarantees, or strings attached when using this software

Future Work

  • Integrate the base58 module code into the library itself
  • Namespace the XMR, LTC, and BTC functions & classes
  • Consolidate XMR and BTC base58 functions
  • Make this into a "real" Python module and publish to PyPI

Releases

No releases published

Packages

No packages published

Languages