altcoin.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2022 The MMGen Project <mmgen@tuta.io>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. """
  19. altcoin.py - Coin constants for Bitcoin-derived altcoins
  20. """
  21. # Sources:
  22. # lb: https://github.com/libbitcoin/libbitcoin/wiki/Altcoin-Version-Mappings
  23. # pc: https://github.com/richardkiss/pycoin/blob/master/pycoin/networks/legacy_networks.py
  24. # vg: https://github.com/exploitagency/vanitygen-plus/blob/master/keyconv.c
  25. # wn: https://walletgenerator.net
  26. # cc: https://www.cryptocompare.com/api/data/coinlist/ (names,symbols only)
  27. # BIP44
  28. # https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
  29. # BIP44 registered coin types: https://github.com/satoshilabs/slips/blob/master/slip-0044.md
  30. # WIP:
  31. # NSR: 149/191 c/u, 63/('S'), 64/('S'|'T')
  32. # NBT: 150/191 c/u, 25/('B'), 26/('B')
  33. import sys
  34. def msg(s):
  35. sys.stderr.write(s+'\n')
  36. def test_equal(desc,a,b,*cdata):
  37. if type(a) == int:
  38. a = hex(a)
  39. b = hex(b)
  40. (network,coin,e,b_desc,verbose) = cdata
  41. if verbose:
  42. msg(f' {desc:20}: {a!r}')
  43. if a != b:
  44. raise ValueError(
  45. '{}s for {} {} do not match:\n CoinInfo: {}\n {}: {}'.format(
  46. desc.capitalize(),
  47. coin.upper(),
  48. network,
  49. a,
  50. b_desc,
  51. b ))
  52. from collections import namedtuple
  53. ce = namedtuple('CoinInfoEntry',
  54. ['name','symbol','wif_ver_num','p2pkh_info','p2sh_info','has_segwit','trust_level'])
  55. class CoinInfo(object):
  56. coin_constants = {}
  57. coin_constants['mainnet'] = (
  58. # Trust levels: -1=disabled 0=untested 1=low 2=med 3=high 4=very high (no warn) 5=unconditional
  59. # Trust levels apply to key/address generation only.
  60. # Non core-coin fork coins (i.e. BCG) must be disabled here to prevent generation from
  61. # incorrect scrambled seed.
  62. ce('Bitcoin', 'BTC', 0x80, (0x00,'1'), (0x05,'3'), True, 5),
  63. ce('BitcoinCashNode', 'BCH', 0x80, (0x00,'1'), (0x05,'3'), False, 5),
  64. ce('BitcoinGold', 'BCG', 0x80, (0x00,'1'), (0x05,'3'), True, -1),
  65. ce('2GiveCoin', '2GIVE', 0xa7, (0x27,('G','H')), None, False, 0),
  66. ce('42Coin', '42', 0x88, (0x08,'4'), None, False, 1),
  67. ce('ACoin', 'ACOIN', 0xe6, (0x17,'A'), None, False, 0),
  68. ce('Alphacoin', 'ALF', 0xd2, (0x52,('Z','a')), None, False, 0),
  69. ce('Anoncoin', 'ANC', 0x97, (0x17,'A'), None, False, 1),
  70. ce('Apexcoin', 'APEX', 0x97, (0x17,'A'), None, False, 0),
  71. ce('Aquariuscoin', 'ARCO', 0x97, (0x17,'A'), None, False, 0),
  72. ce('Argentum', 'ARG', 0x97, (0x17,'A'), (0x05,'3'), False, 1),
  73. ce('AsiaCoin', 'AC', 0x97, (0x17,'A'), (0x08,'4'), False, 1),
  74. ce('Auroracoin', 'AUR', 0x97, (0x17,'A'), None, False, 1),
  75. ce('BBQcoin', 'BQC', 0xd5, (0x55,'b'), None, False, 1),
  76. ce('BitcoinDark', 'BTCD', 0xbc, (0x3c,'R'), (0x55,'b'), False, 1),
  77. ce('BitcoinFast', 'BCF', 0xe0, (0x60,('f','g')), None, False, 0),
  78. ce('BitQuark', 'BTQ', 0xba, (0x3a,'Q'), None, False, 0),
  79. ce('Blackcoin', 'BLK', 0x99, (0x19,'B'), (0x55,'b'), False, 1),
  80. ce('BlackmoonCrypto', 'BMC', 0x83, (0x03,'2'), None, False, 0),
  81. ce('BlockCat', 'CAT', 0x95, (0x15,'9'), None, False, 0),
  82. ce('CanadaECoin', 'CDN', 0x9c, (0x1c,'C'), (0x05,'3'), False, 1),
  83. ce('CannabisCoin', 'CANN', 0x9c, (0x1c,'C'), None, False, 0),
  84. ce('CannaCoin', 'CCN', 0x9c, (0x1c,'C'), (0x05,'3'), False, 1),
  85. ce('Capricoin', 'CPC', 0x9c, (0x1c,'C'), None, False, 0),
  86. ce('CashCoin', 'CASH', 0xa2, (0x22,('E','F')), None, False, 0),
  87. ce('CashOut', 'CSH', 0xa2, (0x22,('E','F')), None, False, 0),
  88. ce('ChainCoin', 'CHC', 0x9c, (0x1c,'C'), None, False, 0),
  89. ce('Clams', 'CLAM', 0x85, (0x89,'x'), (0x0d,'6'), False, 1),
  90. ce('CoinMagi', 'XMG', 0x94, (0x14,'9'), None, False, 0),
  91. ce('Condensate', 'RAIN', 0xbc, (0x3c,'R'), None, False, 0),
  92. ce('CryptoBullion', 'CBX', 0x8b, (0x0b,'5'), None, False, 0),
  93. ce('Cryptonite', 'XCN', 0x80, (0x1c,'C'), None, False, 0),
  94. ce('CryptoPennies', 'CRPS', 0xc2, (0x42,'T'), None, False, 0),
  95. ce('Dash', 'DASH', 0xcc, (0x4c,'X'), (0x10,'7'), False, 1),
  96. ce('Decred', 'DCR', 0x22de, (0x073f,'D'), (0x071a,'D'), False, 1),
  97. ce('DeepOnion', 'ONION', 0x9f, (0x1f,'D'), None, False, 1),
  98. ce('Defcoin', 'DFC', 0x9e, (0x1e,'D'), (0x05,'3'), False, 1),
  99. ce('Devcoin', 'DVC', 0x80, (0x00,'1'), None, False, 1),
  100. ce('DigiByte', 'DGB', 0x80, (0x1e,'D'), (0x05,'3'), False, 1),
  101. ce('DigiCoin', 'DGC', 0x9e, (0x1e,'D'), (0x05,'3'), False, 1),
  102. ce('DogecoinDark', 'DOGED', 0x9e, (0x1e,'D'), (0x21,'E'), False, 1),
  103. ce('Dogecoin', 'DOGE', 0x9e, (0x1e,'D'), (0x16,('9','A')), False, 2),
  104. ce('DopeCoin', 'DOPE', 0x88, (0x08,'4'), (0x05,'3'), False, 1),
  105. ce('EGulden', 'EFL', 0xb0, (0x30,'L'), (0x05,'3'), False, 1),
  106. ce('Emerald', 'EMD', 0xa2, (0x22,('E','F')), None, False, 0),
  107. ce('Emercoin', 'EMC', 0x80, (0x21,'E'), (0x5c,'e'), False, 2),
  108. ce('EnergyCoin', 'ENRG', 0xdc, (0x5c,'e'), None, False, 0),
  109. ce('Espers', 'ESP', 0xa1, (0x21,'E'), None, False, 0),
  110. ce('Faircoin', 'FAI', 0xdf, (0x5f,'f'), (0x24,'F'), False, 1),
  111. ce('Fastcoin', 'FST', 0xe0, (0x60,('f','g')), None, False, 0),
  112. ce('Feathercoin', 'FTC', 0x8e, (0x0e,('6','7')), (0x05,'3'), False, 2),
  113. ce('Fibre', 'FIBRE', 0xa3, (0x23,'F'), None, False, 0),
  114. ce('FlorinCoin', 'FLO', 0xb0, (0x23,'F'), None, False, 0),
  115. ce('Fluttercoin', 'FLT', 0xa3, (0x23,'F'), None, False, 0),
  116. ce('Fuel2Coin', 'FC2', 0x80, (0x24,'F'), None, False, 0),
  117. ce('Fujicoin', 'FJC', 0xa4, (0x24,'F'), None, False, 0),
  118. ce('Fujinto', 'NTO', 0xa4, (0x24,'F'), None, False, 0),
  119. ce('GlobalBoost', 'BSTY', 0xa6, (0x26,'G'), None, False, 0),
  120. ce('GlobalCurrencyReserve', 'GCR', 0x9a, (0x26,'G'), (0x61,'g'), False, 1),
  121. ce('GoldenBird', 'XGB', 0xaf, (0x2f,('K','L')), None, False, 0),
  122. ce('Goodcoin', 'GOOD', 0xa6, (0x26,'G'), None, False, 0),
  123. ce('GridcoinResearch', 'GRC', 0xbe, (0x3e,('R','S')), None, False, 1),
  124. ce('Gulden', 'NLG', 0xa6, (0x26,'G'), None, False, 1),
  125. ce('Guncoin', 'GUN', 0xa7, (0x27,('G','H')), None, False, 1),
  126. ce('HamRadioCoin', 'HAM', 0x80, (0x00,'1'), None, False, 1),
  127. ce('HTML5Coin', 'HTML5', 0xa8, (0x28,'H'), None, False, 0),
  128. ce('HyperStake', 'HYP', 0xf5, (0x75,'p'), None, False, 0),
  129. ce('iCash', 'ICASH', 0xcc, (0x66,'i'), None, False, 0),
  130. ce('ImperiumCoin', 'IPC', 0xb0, (0x30,'L'), None, False, 0),
  131. ce('IncaKoin', 'NKA', 0xb5, (0x35,'N'), None, False, 0),
  132. ce('Influxcoin', 'INFX', 0xe6, (0x66,'i'), None, False, 0),
  133. ce('InPay', 'INPAY', 0xb7, (0x37,'P'), None, False, 0),
  134. # ce('iXcoin', 'IXC', 0x80, (0x8a,'x'), None, False, 1),
  135. ce('Judgecoin', 'JUDGE', 0xab, (0x2b,'J'), None, False, 0),
  136. ce('Jumbucks', 'JBS', 0xab, (0x2b,'J'), (0x69,'j'), False, 2),
  137. ce('Lanacoin', 'LANA', 0xb0, (0x30,'L'), None, False, 0),
  138. ce('Latium', 'LAT', 0x80, (0x17,'A'), None, False, 0),
  139. ce('Litecoin', 'LTC', 0xb0, (0x30,'L'), (0x32,'M'), True, 5), # old p2sh: 0x05
  140. ce('LiteDoge', 'LDOGE', 0xab, (0x5a,'d'), None, False, 0),
  141. ce('LomoCoin', 'LMC', 0xb0, (0x30,'L'), None, False, 0),
  142. ce('Marscoin', 'MARS', 0xb2, (0x32,'M'), None, False, 0),
  143. ce('MarsCoin', 'MRS', 0xb2, (0x32,'M'), None, False, 0),
  144. ce('MartexCoin', 'MXT', 0xb2, (0x32,'M'), None, False, 0),
  145. ce('MasterCar', 'MCAR', 0xe6, (0x17,'A'), None, False, 0),
  146. ce('MazaCoin', 'MZC', 0xe0, (0x32,'M'), (0x09,('4','5')), False, 2),
  147. ce('MegaCoin', 'MEC', 0xb2, (0x32,'M'), None, False, 1),
  148. ce('MintCoin', 'MINT', 0xb3, (0x33,'M'), None, False, 0),
  149. ce('Mobius', 'MOBI', 0x80, (0x00,'1'), None, False, 0),
  150. ce('MonaCoin', 'MONA', 0xb0, (0x32,'M'), (0x05,'3'), False, 1),
  151. ce('MonetaryUnit', 'MUE', 0x8f, (0x0f,'7'), (0x09,('4','5')), False, 1),
  152. ce('MoonCoin', 'MOON', 0x83, (0x03,'2'), None, False, 0),
  153. ce('MyriadCoin', 'MYR', 0xb2, (0x32,'M'), (0x09,('4','5')), False, 1),
  154. ce('Myriadcoin', 'MYRIAD', 0xb2, (0x32,'M'), None, False, 1),
  155. ce('Namecoin', 'NMC', 0xb4, (0x34,('M','N')), (0x0d,'6'), False, 1),
  156. ce('Neoscoin', 'NEOS', 0xef, (0x3f,'S'), (0xbc,'2'), False, 1),
  157. ce('NevaCoin', 'NEVA', 0xb1, (0x35,'N'), None, False, 0),
  158. ce('Novacoin', 'NVC', 0x88, (0x08,'4'), (0x14,'9'), False, 1),
  159. ce('OKCash', 'OK', 0xb7, (0x37,'P'), (0x1c,'C'), False, 1),
  160. ce('Omnicoin', 'OMC', 0xf3, (0x73,'o'), None, False, 1),
  161. ce('Omni', 'OMNI', 0xf3, (0x73,'o'), None, False, 0),
  162. ce('Onix', 'ONX', 0x80, (0x8a,'x'), None, False, 0),
  163. ce('PandaCoin', 'PND', 0xb7, (0x37,'P'), (0x16,('9','A')), False, 1),
  164. ce('ParkByte', 'PKB', 0xb7, (0x37,'P'), (0x1c,'C'), False, 1),
  165. ce('Particl', 'PART', 0x6c, (0x38,'P'), None, False, 0),
  166. ce('Paycoin', 'CON', 0xb7, (0x37,'P'), None, False, 1),
  167. ce('Peercoin', 'PPC', 0xb7, (0x37,'P'), (0x75,'p'), False, 1),
  168. ce('PesetaCoin', 'PTC', 0xaf, (0x2f,('K','L')), None, False, 1),
  169. ce('PhoenixCoin', 'PXC', 0xb8, (0x38,'P'), None, False, 0),
  170. ce('PinkCoin', 'PINK', 0x83, (0x03,'2'), None, False, 1),
  171. ce('PIVX', 'PIVX', 0xd4, (0x1e,'D'), None, False, 0),
  172. ce('PokeChain', 'XPOKE', 0x9c, (0x1c,'C'), None, False, 0),
  173. ce('Potcoin', 'POT', 0xb7, (0x37,'P'), (0x05,'3'), False, 1),
  174. ce('Primecoin', 'XPM', 0x97, (0x17,'A'), (0x53,'a'), False, 1),
  175. ce('Quark', 'QRK', 0xba, (0x3a,'Q'), None, False, 0),
  176. ce('ReddCoin', 'RDD', 0xbd, (0x3d,'R'), None, False, 1),
  177. ce('Riecoin', 'RIC', 0x80, (0x3c,'R'), (0x05,'3'), False, 2),
  178. ce('Rimbit', 'RBT', 0xbc, (0x3c,'R'), None, False, 0),
  179. ce('Rubycoin', 'RBY', 0xbd, (0x3d,'R'), (0x55,'b'), False, 1),
  180. ce('ShadowCash', 'SDC', 0xbf, (0x3f,'S'), (0x7d,'s'), False, 1),
  181. ce('Sibcoin', 'SIB', 0x80, (0x3f,'S'), None, False, 0),
  182. ce('SixEleven', '611', 0x80, (0x34,('M','N')), None, False, 0),
  183. ce('SmileyCoin', 'SMLY', 0x99, (0x19,'B'), None, False, 0),
  184. ce('Songcoin', 'SONG', 0xbf, (0x3f,'S'), None, False, 0),
  185. ce('Spreadcoin', 'SPR', 0xbf, (0x3f,'S'), None, False, 1),
  186. ce('Startcoin', 'START', 0xfd, (0x7d,'s'), (0x05,'3'), False, 1),
  187. ce('StealthCoin', 'XST', 0xbe, (0x3e,('R','S')), None, False, 0),
  188. ce('SwagBucks', 'BUCKS', 0x99, (0x3f,'S'), None, False, 0),
  189. ce('SysCoin', 'SYS', 0x80, (0x00,'1'), None, False, 0),
  190. ce('TajCoin', 'TAJ', 0x6f, (0x41,'T'), None, False, 0),
  191. ce('Templecoin', 'TPC', 0xc1, (0x41,'T'), (0x05,'3'), False, 1),
  192. ce('Terracoin', 'TRC', 0x80, (0x00,'1'), None, False, 0),
  193. ce('Titcoin', 'TIT', 0x80, (0x00,'1'), None, False, 0),
  194. ce('TittieCoin', 'TTC', 0xc1, (0x41,'T'), None, False, 0),
  195. ce('Transfer', 'TX', 0x99, (0x42,'T'), None, False, 0),
  196. ce('Unobtanium', 'UNO', 0xe0, (0x82,'u'), (0x1e,'D'), False, 2),
  197. ce('Vcash', 'XVC', 0xc7, (0x47,'V'), None, False, 0),
  198. ce('Vertcoin', 'VTC', 0xc7, (0x47,'V'), (0x05,'3'), False, 1),
  199. ce('Viacoin', 'VIA', 0xc7, (0x47,'V'), (0x21,'E'), False, 2),
  200. ce('VpnCoin', 'VPN', 0xc7, (0x47,'V'), (0x05,'3'), False, 1),
  201. ce('WankCoin', 'WKC', 0x80, (0x00,'1'), None, False, 1),
  202. ce('WashingtonCoin', 'WASH', 0xc9, (0x49,'W'), None, False, 0),
  203. ce('WeAreSatoshi', 'WSX', 0x97, (0x87,'w'), None, False, 0),
  204. ce('WisdomCoin', 'WISC', 0x87, (0x49,'W'), None, False, 0),
  205. ce('WorldCoin', 'WDC', 0xc9, (0x49,'W'), None, False, 1),
  206. ce('XRealEstateDevcoin', 'XRED', 0x80, (0x00,'1'), None, False, 0),
  207. ce('ZetaCoin', 'ZET', 0xe0, (0x50,'Z'), None, False, 0),
  208. ce('ZiftrCoin', 'ZRC', 0xd0, (0x50,'Z'), (0x05,'3'), False, 1),
  209. ce('ZLiteQubit', 'ZLQ', 0xe0, (0x26,'G'), None, False, 0),
  210. ce('Zoomcoin', 'ZOOM', 0xe7, (0x67,'i'), (0x5c,'e'), False, 1),
  211. )
  212. coin_constants['testnet'] = (
  213. ce('Bitcoin', 'BTC', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, 5),
  214. ce('BitcoinCashNode','BCH',0xef, (0x6f,('m','n')), (0xc4,'2'), True, 5),
  215. ce('BitcoinGold', 'BCG', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, -1),
  216. ce('Dash', 'DASH', 0xef, (0x8c,'y'), (0x13,('8','9')), False, 1),
  217. ce('Decred', 'DCR', 0x230e, (0x0f21,'T'), (0x0e6c,'S'), False, 1),
  218. ce('Dogecoin', 'DOGE', 0xf1, (0x71,'n'), (0xc4,'2'), False, 2),
  219. ce('Feathercoin', 'FTC', 0xc1, (0x41,'T'), (0xc4,'2'), False, 2),
  220. ce('Viacoin', 'VIA', 0xff, (0x7f,'t'), (0xc4,'2'), False, 2),
  221. ce('Emercoin', 'EMC', 0xef, (0x6f,('m','n')), (0xc4,'2'), False, 2),
  222. ce('Litecoin', 'LTC', 0xef, (0x6f,('m','n')), (0x3a,'Q'), True, 5), # old p2sh: 0xc4
  223. )
  224. coin_sources = (
  225. ('BTC', 'https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp'),
  226. ('EMC', 'https://github.com/emercoin/emercoin/blob/master/src/chainparams.cpp'), # checked mn,tn
  227. ('LTC', 'https://github.com/litecoin-project/litecoin/blob/master-0.10/src/chainparams.cpp'),
  228. ('DOGE', 'https://github.com/dogecoin/dogecoin/blob/master/src/chainparams.cpp'),
  229. ('RDD', 'https://github.com/reddcoin-project/reddcoin/blob/master/src/base58.h'),
  230. ('DASH', 'https://github.com/dashpay/dash/blob/master/src/chainparams.cpp'),
  231. ('PPC', 'https://github.com/belovachap/peercoin/blob/master/src/base58.h'),
  232. ('NMC', 'https://github.com/domob1812/namecore/blob/master/src/chainparams.cpp'),
  233. ('FTC', 'https://github.com/FeatherCoin/Feathercoin/blob/master-0.8/src/base58.h'),
  234. ('BLK', 'https://github.com/rat4/blackcoin/blob/master/src/chainparams.cpp'),
  235. ('NSR', 'https://nubits.com/nushares/introduction'),
  236. ('NBT', 'https://bitbucket.org/JordanLeePeershares/nubit/NuBit / src /base58.h'),
  237. ('MZC', 'https://github.com/MazaCoin/MazaCoin/blob/master/src/chainparams.cpp'),
  238. ('VIA', 'https://github.com/viacoin/viacoin/blob/master/src/chainparams.cpp'),
  239. ('RBY', 'https://github.com/rubycoinorg/rubycoin/blob/master/src/base58.h'),
  240. ('GRS', 'https://github.com/GroestlCoin/groestlcoin/blob/master/src/groestlcoin.cpp'),
  241. ('DGC', 'https://github.com/DGCDev/digitalcoin/blob/master/src/chainparams.cpp'),
  242. ('CCN', 'https://github.com/Cannacoin-Project/Cannacoin/blob/Proof-of-Stake/src/base58.h'),
  243. ('DGB', 'https://github.com/digibyte/digibyte/blob/master/src/chainparams.cpp'),
  244. ('MONA', 'https://github.com/monacoinproject/monacoin/blob/master-0.10/src/chainparams.cpp'),
  245. ('CLAM', 'https://github.com/nochowderforyou/clams/blob/master/src/chainparams.cpp'),
  246. ('XPM', 'https://github.com/primecoin/primecoin/blob/master/src/base58.h'),
  247. ('NEOS', 'https://github.com/bellacoin/neoscoin/blob/master/src/chainparams.cpp'),
  248. ('JBS', 'https://github.com/jyap808/jumbucks/blob/master/src/base58.h'),
  249. ('ZRC', 'https://github.com/ZiftrCOIN/ziftrcoin/blob/master/src/chainparams.cpp'),
  250. ('VTC', 'https://github.com/vertcoin/vertcoin/blob/master/src/base58.h'),
  251. ('NXT', 'https://bitbucket.org/JeanLucPicard/nxt/src and unofficial at https://github.com/Blackcomb/nxt'),
  252. ('MUE', 'https://github.com/MonetaryUnit/MUE-Src/blob/master/src/chainparams.cpp'),
  253. ('ZOOM', 'https://github.com/zoom-c/zoom/blob/master/src/base58.h'),
  254. ('VPN', 'https://github.com/Bit-Net/VpnCoin/blob/master/src/base58.h'),
  255. ('CDN', 'https://github.com/ThisIsOurCoin/canadaecoin/blob/master/src/base58.h'),
  256. ('SDC', 'https://github.com/ShadowProject/shadow/blob/master/src/chainparams.cpp'),
  257. ('PKB', 'https://github.com/parkbyte/ParkByte/blob/master/src/base58.h'),
  258. ('PND', 'https://github.com/coinkeeper/2015-04-19_21-22_pandacoin/blob/master/src/base58.h'),
  259. ('START', 'https://github.com/startcoin-project/startcoin/blob/master/src/base58.h'),
  260. ('GCR', 'https://github.com/globalcurrencyreserve/gcr/blob/master/src/chainparams.cpp'),
  261. ('NVC', 'https://github.com/novacoin-project/novacoin/blob/master/src/base58.h'),
  262. ('AC', 'https://github.com/AsiaCoin/AsiaCoinFix/blob/master/src/base58.h'),
  263. ('BTCD', 'https://github.com/jl777/btcd/blob/master/src/base58.h'),
  264. ('DOPE', 'https://github.com/dopecoin-dev/DopeCoinV3/blob/master/src/base58.h'),
  265. ('TPC', 'https://github.com/9cat/templecoin/blob/templecoin/src/base58.h'),
  266. ('OK', 'https://github.com/okcashpro/okcash/blob/master/src/chainparams.cpp'),
  267. ('DOGED', 'https://github.com/doged/dogedsource/blob/master/src/base58.h'),
  268. ('EFL', 'https://github.com/Electronic-Gulden-Foundation/egulden/blob/master/src/base58.h'),
  269. ('POT', 'https://github.com/potcoin/Potcoin/blob/master/src/base58.h'),
  270. )
  271. # Sources (see above) that are in agreement for these coins
  272. # No check for segwit, p2sh check skipped if source doesn't support it
  273. cross_checks = {
  274. '2GIVE': ['wn'],
  275. '42': ['vg','wn'],
  276. '611': ['wn'],
  277. 'AC': ['lb','vg'],
  278. 'ACOIN': ['wn'],
  279. 'ALF': ['wn'],
  280. 'ANC': ['vg','wn'],
  281. 'APEX': ['wn'],
  282. 'ARCO': ['wn'],
  283. 'ARG': ['pc'],
  284. 'AUR': ['vg','wn'],
  285. 'BCH': ['wn'],
  286. 'BLK': ['lb','vg','wn'],
  287. 'BQC': ['vg','wn'],
  288. 'BSTY': ['wn'],
  289. 'BTC': ['lb','vg','wn'],
  290. 'BTCD': ['lb','vg','wn'],
  291. 'BUCKS': ['wn'],
  292. 'CASH': ['wn'],
  293. 'CBX': ['wn'],
  294. 'CCN': ['lb','vg','wn'],
  295. 'CDN': ['lb','vg','wn'],
  296. 'CHC': ['wn'],
  297. 'CLAM': ['lb','vg'],
  298. 'CON': ['vg','wn'],
  299. 'CPC': ['wn'],
  300. 'DASH': ['lb','pc','vg','wn'],
  301. 'DCR': ['pc'],
  302. 'DFC': ['pc'],
  303. 'DGB': ['lb','vg'],
  304. 'DGC': ['lb','vg','wn'],
  305. 'DOGE': ['lb','pc','vg','wn'],
  306. 'DOGED': ['lb','vg','wn'],
  307. 'DOPE': ['lb','vg'],
  308. 'DVC': ['vg','wn'],
  309. 'EFL': ['lb','vg','wn'],
  310. 'EMC': ['vg'],
  311. 'EMD': ['wn'],
  312. 'ESP': ['wn'],
  313. 'FAI': ['pc'],
  314. 'FC2': ['wn'],
  315. 'FIBRE': ['wn'],
  316. 'FJC': ['wn'],
  317. 'FLO': ['wn'],
  318. 'FLT': ['wn'],
  319. 'FST': ['wn'],
  320. 'FTC': ['lb','pc','vg','wn'],
  321. 'GCR': ['lb','vg'],
  322. 'GOOD': ['wn'],
  323. 'GRC': ['vg','wn'],
  324. 'GUN': ['vg','wn'],
  325. 'HAM': ['vg','wn'],
  326. 'HTML5': ['wn'],
  327. 'HYP': ['wn'],
  328. 'ICASH': ['wn'],
  329. 'INFX': ['wn'],
  330. 'IPC': ['wn'],
  331. 'JBS': ['lb','pc','vg','wn'],
  332. 'JUDGE': ['wn'],
  333. 'LANA': ['wn'],
  334. 'LAT': ['wn'],
  335. 'LDOGE': ['wn'],
  336. 'LMC': ['wn'],
  337. 'LTC': ['lb','vg','wn'],
  338. 'MARS': ['wn'],
  339. 'MEC': ['pc','wn'],
  340. 'MINT': ['wn'],
  341. 'MOBI': ['wn'],
  342. 'MONA': ['lb','vg'],
  343. 'MOON': ['wn'],
  344. 'MUE': ['lb','vg'],
  345. 'MXT': ['wn'],
  346. 'MYR': ['pc'],
  347. 'MYRIAD': ['vg','wn'],
  348. 'MZC': ['lb','pc','vg','wn'],
  349. 'NEOS': ['lb','vg'],
  350. 'NEVA': ['wn'],
  351. 'NKA': ['wn'],
  352. 'NLG': ['vg','wn'],
  353. 'NMC': ['lb','vg'],
  354. 'NVC': ['lb','vg','wn'],
  355. 'OK': ['lb','vg'],
  356. 'OMC': ['vg','wn'],
  357. 'ONION': ['vg','wn'],
  358. 'PART': ['wn'],
  359. 'PINK': ['vg','wn'],
  360. 'PIVX': ['wn'],
  361. 'PKB': ['lb','vg','wn'],
  362. 'PND': ['lb','vg','wn'],
  363. 'POT': ['lb','vg','wn'],
  364. 'PPC': ['lb','vg','wn'],
  365. 'PTC': ['vg','wn'],
  366. 'PXC': ['wn'],
  367. 'QRK': ['wn'],
  368. 'RAIN': ['wn'],
  369. 'RBT': ['wn'],
  370. 'RBY': ['lb','vg'],
  371. 'RDD': ['vg','wn'],
  372. 'RIC': ['pc','vg','wn'],
  373. 'SDC': ['lb','vg'],
  374. 'SIB': ['wn'],
  375. 'SMLY': ['wn'],
  376. 'SONG': ['wn'],
  377. 'SPR': ['vg','wn'],
  378. 'START': ['lb','vg'],
  379. 'SYS': ['wn'],
  380. 'TAJ': ['wn'],
  381. 'TIT': ['wn'],
  382. 'TPC': ['lb','vg'],
  383. 'TRC': ['wn'],
  384. 'TTC': ['wn'],
  385. 'TX': ['wn'],
  386. 'UNO': ['pc','vg','wn'],
  387. 'VIA': ['lb','pc','vg','wn'],
  388. 'VPN': ['lb','vg'],
  389. 'VTC': ['lb','vg','wn'],
  390. 'WDC': ['vg','wn'],
  391. 'WISC': ['wn'],
  392. 'WKC': ['vg','wn'],
  393. 'WSX': ['wn'],
  394. 'XCN': ['wn'],
  395. 'XGB': ['wn'],
  396. 'XPM': ['lb','vg','wn'],
  397. 'XST': ['wn'],
  398. 'XVC': ['wn'],
  399. 'ZET': ['wn'],
  400. 'ZOOM': ['lb','vg'],
  401. 'ZRC': ['lb','vg']
  402. }
  403. @classmethod
  404. def verify_leading_symbols(cls,quiet=False,verbose=False):
  405. for network in ('mainnet','testnet'):
  406. for coin in [e.symbol for e in cls.coin_constants[network]]:
  407. e = cls.get_entry(coin,network)
  408. cdata = (network,coin,e,'Computed value',verbose)
  409. if not quiet:
  410. msg(f'{coin} {network}')
  411. vn_info = e.p2pkh_info
  412. ret = cls.find_addr_leading_symbol(vn_info[0])
  413. test_equal('P2PKH leading symbol',vn_info[1],ret,*cdata)
  414. vn_info = e.p2sh_info
  415. if vn_info:
  416. ret = cls.find_addr_leading_symbol(vn_info[0])
  417. test_equal('P2SH leading symbol',vn_info[1],ret,*cdata)
  418. @classmethod
  419. def verify_core_coin_data(cls,quiet=False,verbose=False):
  420. from mmgen.protocol import CoinProtocol,init_proto
  421. for network in ('mainnet','testnet'):
  422. for coin in CoinProtocol.core_coins:
  423. e = cls.get_entry(coin,network)
  424. if e:
  425. proto = init_proto(coin,testnet=network=='testnet')
  426. cdata = (network,coin,e,type(proto).__name__,verbose)
  427. if not quiet:
  428. msg(f'Verifying {coin.upper()} {network}')
  429. if coin != 'bch': # TODO
  430. test_equal('coin name',e.name,proto.name,*cdata)
  431. if e.trust_level != -1:
  432. test_equal('Trust level',e.trust_level,CoinProtocol.coins[coin].trust_level,*cdata)
  433. test_equal(
  434. 'WIF version number',
  435. e.wif_ver_num,
  436. int.from_bytes(bytes.fromhex(proto.wif_ver_num['std']),'big'),
  437. *cdata )
  438. test_equal(
  439. 'P2PKH version number',
  440. e.p2pkh_info[0],
  441. int.from_bytes(proto.addr_fmt_to_ver_bytes('p2pkh'),'big'),
  442. *cdata )
  443. test_equal(
  444. 'P2SH version number',
  445. e.p2sh_info[0],
  446. int.from_bytes(proto.addr_fmt_to_ver_bytes('p2sh'),'big'),
  447. *cdata )
  448. @classmethod
  449. def get_supported_coins(cls,network):
  450. return [e for e in cls.coin_constants[network] if e.trust_level != -1]
  451. @classmethod
  452. def get_entry(cls,coin,network):
  453. try:
  454. idx = [e.symbol for e in cls.coin_constants[network]].index(coin.upper())
  455. except:
  456. return None
  457. return cls.coin_constants[network][idx]
  458. # Data is one of the coin_constants lists above. Normalize ints to hex of correct width, add
  459. # missing leading letters, set trust level from external_tests.
  460. # Insert a coin entry from outside source, set version info leading letters to '?' and trust level
  461. # to 0, then run CoinInfo.fix_table(data). 'has_segwit' field is updated manually for now.
  462. @classmethod
  463. def fix_table(cls,data):
  464. import re
  465. def myhex(n):
  466. return '0x{:0{}x}'.format(n,2 if n < 256 else 4)
  467. def fix_ver_info(e,k):
  468. e[k] = list(e[k])
  469. e[k][0] = myhex(e[k][0])
  470. s1 = cls.find_addr_leading_symbol(int(e[k][0][2:],16))
  471. m = f'Fixing leading address letter for coin {e["symbol"]} ({e[k][1]!r} --> {s1})'
  472. if e[k][1] != '?':
  473. assert s1 == e[k][1], f'First letters do not match! {m}'
  474. else:
  475. msg(m)
  476. e[k][1] = s1
  477. e[k] = tuple(e[k])
  478. old_sym = None
  479. for sym in sorted([e.symbol for e in data]):
  480. if sym == old_sym:
  481. msg(f'{sym!r}: duplicate coin symbol in data!')
  482. sys.exit(2)
  483. old_sym = sym
  484. tt = cls.create_trust_table()
  485. name_w = max(len(e.name) for e in data)
  486. fs = '\t({:%s} {:10} {:7} {:17} {:17} {:6} {}),' % (name_w+3)
  487. for e in data:
  488. e = e._asdict()
  489. e['wif_ver_num'] = myhex(e['wif_ver_num'])
  490. sym,trust = e['symbol'],e['trust_level']
  491. fix_ver_info(e,'p2pkh_info')
  492. if type(e['p2sh_info']) == tuple:
  493. fix_ver_info(e,'p2sh_info')
  494. for k in e.keys():
  495. e[k] = repr(e[k])
  496. e[k] = re.sub(r"'0x(..)'",r'0x\1',e[k])
  497. e[k] = re.sub(r"'0x(....)'",r'0x\1',e[k])
  498. e[k] = re.sub(r' ',r'',e[k]) + ('',',')[k != 'trust_level']
  499. if trust != -1:
  500. if sym in tt:
  501. src = tt[sym]
  502. if src != trust:
  503. msg(f'Updating trust for coin {sym!r}: {trust} -> {src}')
  504. e['trust_level'] = src
  505. else:
  506. if trust != 0:
  507. msg(f'Downgrading trust for coin {sym!r}: {trust} -> 0')
  508. e['trust_level'] = 0
  509. if sym in cls.cross_checks:
  510. if int(e['trust_level']) == 0 and len(cls.cross_checks[sym]) > 1:
  511. msg(f'Upgrading trust for coin {sym!r}: {e["trust_level"]} -> 1')
  512. e['trust_level'] = 1
  513. print(fs.format(*e.values()))
  514. msg(f'Processed {len(data)} entries')
  515. @classmethod
  516. def find_addr_leading_symbol(cls,ver_num,verbose=False):
  517. if ver_num == 0:
  518. return '1'
  519. def phash2addr(ver_num,pk_hash):
  520. from mmgen.protocol import _b58chk_encode
  521. bl = ver_num.bit_length()
  522. ver_bytes = int.to_bytes(ver_num,bl//8 + bool(bl%8),'big')
  523. return _b58chk_encode(ver_bytes + pk_hash)
  524. low = phash2addr(ver_num,b'\x00'*20)
  525. high = phash2addr(ver_num,b'\xff'*20)
  526. if verbose:
  527. print('low address: ' + low)
  528. print('high address: ' + high)
  529. l1,h1 = low[0],high[0]
  530. return (l1,h1) if l1 != h1 else l1
  531. @classmethod
  532. def print_symbols(cls,include_names=False,reverse=False):
  533. for e in cls.coin_constants['mainnet']:
  534. if reverse:
  535. print(f'{e.symbol:6} {e.name}')
  536. else:
  537. name_w = max(len(e.name) for e in cls.coin_constants['mainnet'])
  538. print((f'{e.name:{name_w}} ' if include_names else '') + e.symbol)
  539. @classmethod
  540. def create_trust_table(cls):
  541. tt = {}
  542. mn = cls.external_tests['mainnet']
  543. for ext_prog in mn:
  544. assert len(set(mn[ext_prog])) == len(mn[ext_prog]), f'Duplicate entry in {ext_prog!r}!'
  545. for coin in mn[ext_prog]:
  546. if coin in tt:
  547. tt[coin] += 1
  548. else:
  549. tt[coin] = 1
  550. for k in cls.trust_override:
  551. tt[k] = cls.trust_override[k]
  552. return tt
  553. trust_override = {'BTC':3,'BCH':3,'LTC':3,'DASH':1,'EMC':2}
  554. @classmethod
  555. def get_test_support(cls,coin,addr_type,network,tool=None,verbose=False):
  556. """
  557. If requested tool supports coin/addr_type/network triplet, return tool name.
  558. If 'tool' is None, return tool that supports coin/addr_type/network triplet.
  559. Return None on failure.
  560. """
  561. tool_arg = tool
  562. all_tools = [tool] if tool else list(cls.external_tests[network].keys())
  563. coin = coin.upper()
  564. for tool in all_tools:
  565. if coin in cls.external_tests[network][tool]:
  566. break
  567. else:
  568. if verbose:
  569. m1 = 'Requested tool {t!r} does not support coin {c} on network {n}'
  570. m2 = 'No test tool found for coin {c} on network {n}'
  571. msg((m1 if tool_arg else m2).format(t=tool,c=coin,n=network))
  572. return None
  573. if addr_type == 'zcash_z':
  574. if tool_arg in (None,'zcash-mini'):
  575. return 'zcash-mini'
  576. else:
  577. if verbose:
  578. msg(f"Address type {addr_type!r} supported only by tool 'zcash-mini'")
  579. return None
  580. try:
  581. assert (
  582. cls.external_tests_blacklist[addr_type][tool] == True
  583. or coin in cls.external_tests_blacklist[addr_type][tool] )
  584. except:
  585. pass
  586. else:
  587. if verbose:
  588. msg(f'Tool {tool!r} blacklisted for coin {coin}, addr_type {addr_type!r}')
  589. return None
  590. if tool_arg: # skip whitelists
  591. return tool
  592. if addr_type in ('segwit','bech32'):
  593. st = cls.external_tests_segwit_whitelist
  594. if addr_type in st and coin in st[addr_type]:
  595. return tool
  596. else:
  597. if verbose:
  598. m1 = 'Requested tool {t!r} does not support coin {c}, addr_type {a!r}, on network {n}'
  599. m2 = 'No test tool found supporting coin {c}, addr_type {a!r}, on network {n}'
  600. msg((m1 if tool_arg else m2).format(t=tool,c=coin,n=network,a=addr_type))
  601. return None
  602. return tool
  603. external_tests = {
  604. 'mainnet': {
  605. # List in order of preference.
  606. # If 'tool' is not specified, the first tool supporting the coin will be selected.
  607. 'pycoin': (
  608. 'DASH', # only compressed
  609. 'BCH',
  610. 'BTC','LTC','VIA','FTC','DOGE','MEC',
  611. 'JBS','MZC','RIC','DFC','FAI','ARG','ZEC','DCR'),
  612. 'keyconv': (
  613. 'BCH',
  614. # broken: PIVX
  615. '42','AC','AIB','ANC','ARS','ATMOS','AUR','BLK','BQC','BTC','TEST','BTCD','CCC','CCN','CDN',
  616. 'CLAM','CNC','CNOTE','CON','CRW','DEEPONION','DGB','DGC','DMD','DOGED','DOGE','DOPE',
  617. 'DVC','EFL','EMC','EXCL','FAIR','FLOZ','FTC','GAME','GAP','GCR','GRC','GRS','GUN','HAM','HODL',
  618. 'IXC','JBS','LBRY','LEAF','LTC','MMC','MONA','MUE','MYRIAD','MZC','NEOS','NLG','NMC','NVC',
  619. 'NYAN','OK','OMC','PIGGY','PINK','PKB','PND','POT','PPC','PTC','PTS','QTUM','RBY','RDD',
  620. 'RIC','SCA','SDC','SKC','SPR','START','SXC','TPC','UIS','UNO','VIA','VPN','VTC','WDC','WKC',
  621. 'WUBS', 'XC', 'XPM', 'YAC', 'ZOOM', 'ZRC'),
  622. 'ethkey': ('ETH','ETC'),
  623. 'zcash-mini': ('ZEC',),
  624. 'moneropy': ('XMR',),
  625. },
  626. 'testnet': {
  627. 'pycoin': {
  628. 'DASH':'tDASH', # only compressed
  629. 'BCH':'XTN',
  630. 'BTC':'XTN','LTC':'XLT','VIA':'TVI','FTC':'FTX','DOGE':'XDT','DCR':'DCRT'
  631. },
  632. 'ethkey': {},
  633. 'keyconv': {}
  634. }
  635. }
  636. external_tests_segwit_whitelist = {
  637. # Whitelists apply to the *first* tool in cls.external_tests supporting the given coin/addr_type.
  638. # They're ignored if specific tool is requested.
  639. 'segwit': ('BTC',), # LTC Segwit broken on pycoin: uses old fmt
  640. 'bech32': ('BTC','LTC'),
  641. 'compressed': (
  642. 'BTC','LTC','VIA','FTC','DOGE','DASH','MEC','MYR','UNO',
  643. 'JBS','MZC','RIC','DFC','FAI','ARG','ZEC','DCR','ZEC'
  644. ),
  645. }
  646. external_tests_blacklist = {
  647. # Unconditionally block testing of the given coin/addr_type with given tool, or all coins if True
  648. 'legacy': { 'pycoin': ('DASH',) },
  649. 'segwit': { 'pycoin': ('LTC',), 'keyconv': True },
  650. 'bech32': { 'keyconv': True },
  651. }
  652. if __name__ == '__main__':
  653. quiet = '--quiet' in sys.argv
  654. verbose = '--verbose' in sys.argv
  655. if verbose:
  656. quiet = False
  657. msg('Checking CoinInfo WIF/P2PKH/P2SH version numbers and trust levels against protocol.py')
  658. CoinInfo.verify_core_coin_data(quiet=quiet,verbose=verbose)
  659. msg('Checking CoinInfo address leading symbols')
  660. CoinInfo.verify_leading_symbols(quiet=quiet,verbose=verbose)