CrypocurrencyAddressValidation

我要开发同款
匿名用户2021年12月24日
36阅读
开发技术Python
所属分类Web3、开源货币/比特币
授权协议MIT License

作品详情

CryptocurrencyAddressValidationBTC,LTC,XMR

ThisisaPythonclasswhichperformsstrongvalidationofdifferentcryptocurrencyaddresses,chains,andtickersymbols.Itwillensurethatthedataprovidedcalculatestoacorrectvalue,andissyntacticallysafetouse.Segwitcompatible

ValidationLevelsLength-EnsurethegivenaddressistheexpectedlengthCharacterSet-EnsurethatonlytheexpectedcharactersareusedintheaddressCharacterPosition-EnsurethatcertainkeycharactersareintheirexpectedpositionsintheaddressCryptographic-Deconstructtheaddressintoitslogicalcomponents,andvalidatethatitparsed,andanychecksumsorsignaturesarecorrect

ThislibraryperformsLevels1through4forallsupportedcoinsandaddressformats

SupportedAddressFormatsBTC/LTC:P2PKH,P2SH,Bech32XMR:StandardAddress,Subaddress,IntegratedAddressStructure

Thislibraryhastwodependencies: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")Disclaimers

Iborrowed/modifiedcodefromtheseprojects:

Base58decoding:https://github.com/keis/base58P2PKHvalidation:https://bit.ly/2DSVAXcBech32Validation:https://bit.ly/2Eaw40NXMRValidation:https://github.com/monero-project

Pleasetestthroughlybeforeusingthisinaproductionenvironment.Therearenowarranties,guarantees,orstringsattachedwhenusingthissoftware

FutureWorkIntegratethebase58modulecodeintothelibraryitselfNamespacetheXMR,LTC,andBTCfunctions&classesConsolidateXMRandBTCbase58functionsMakethisintoa"real"PythonmoduleandpublishtoPyPI
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论