ThisisaPythonclasswhichperformsstrongvalidationofdifferentcryptocurrencyaddresses,chains,andtickersymbols.Itwillensurethatthedataprovidedcalculatestoacorrectvalue,andissyntacticallysafetouse.Segwitcompatible
ValidationLevelsLength-EnsurethegivenaddressistheexpectedlengthCharacterSet-EnsurethatonlytheexpectedcharactersareusedintheaddressCharacterPosition-EnsurethatcertainkeycharactersareintheirexpectedpositionsintheaddressCryptographic-Deconstructtheaddressintoitslogicalcomponents,andvalidatethatitparsed,andanychecksumsorsignaturesarecorrectThislibraryperformsLevels1through4forallsupportedcoinsandaddressformats
SupportedAddressFormatsBTC/LTC:P2PKH,P2SH,Bech32XMR:StandardAddress,Subaddress,IntegratedAddressStructureThislibraryhastwodependencies:pysha3andbase58.Youusethislibrarybyimportingandcallingstaticmethodsinthetop-levelValidationclass.Cointickers,chains,andnamesarecase-insensitive.AllfunctionsreturnabooleanTrue/Falseanswer.
classValidation:@staticmethoddefis_btc_chain(chain):...@staticmethoddefis_xmr_chain(chain):...@staticmethoddefis_coin_ticker(coin):...@staticmethoddefis_coin_name(name):...@staticmethoddefis_address(coin,address):...@staticmethoddefis_btc_address(address):...@staticmethoddefis_ltc_address(address):...@staticmethoddefis_xmr_address(address,label=None):...Usage:fromValidationimportValidationifValidation.is_coin_ticker("BTC"):print("Valid")ifValidation.is_btc_chain("testnet"):print("Valid")ifValidation.is_xmr_chain("stagenet"):print("Valid")ifValidation.is_coin_name("lITeCoiN"):print("Valid")ifValidation.is_address("BTC","3FkenCiXpSLqD8L79intRNXUgjRoH9sjXa"):print("Valid")ifValidation.is_address("BTC","bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq"):print("Valid")ifValidation.is_address("LTC","LS78aoGtfuGCZ777x3Hmr6tcoW3WaYynx9"):print("Valid")ifValidation.is_address("XMR","46E5ekYrZd5UCcmNuYEX24FRjWVMgZ1ob79cRViyfvLFZjfyMhPDvbuCe54FqLQvVCgRKP4UUMMW5fy3ZhVQhD1JLLufBtu"):print("Valid")DisclaimersIborrowed/modifiedcodefromtheseprojects:
Base58decoding:https://github.com/keis/base58P2PKHvalidation:https://bit.ly/2DSVAXcBech32Validation:https://bit.ly/2Eaw40NXMRValidation:https://github.com/monero-projectPleasetestthroughlybeforeusingthisinaproductionenvironment.Therearenowarranties,guarantees,orstringsattachedwhenusingthissoftware
FutureWorkIntegratethebase58modulecodeintothelibraryitselfNamespacetheXMR,LTC,andBTCfunctions&classesConsolidateXMRandBTCbase58functionsMakethisintoa"real"PythonmoduleandpublishtoPyPI
评论