Giter Site home page Giter Site logo

0x9090 / crypocurrencyaddressvalidation Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 3.0 37 KB

Python class that performs strong cryptocurrency address validation

License: MIT License

Python 100.00%
python3 bitcoin litecoin monero btc ltc xmr segwit p2pkh p2sh

crypocurrencyaddressvalidation's Introduction

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

crypocurrencyaddressvalidation's People

Contributors

0x9090 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.