altcoin.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2023 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. from .cfg import gc,Config
  35. from .util import msg
  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, 2),
  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,cfg,quiet=False,verbose=False):
  420. from .protocol import CoinProtocol,init_proto
  421. for network in ('mainnet','testnet'):
  422. for coin in gc.core_coins:
  423. e = cls.get_entry(coin,network)
  424. if e:
  425. proto = init_proto( cfg, coin, network=network )
  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(proto.wif_ver_bytes['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 .proto.btc.common 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,toolname=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. all_tools = [toolname] if toolname else list(cls.external_tests[network].keys())
  562. coin = coin.upper()
  563. for tool in all_tools:
  564. if coin in cls.external_tests[network][tool]:
  565. break
  566. else:
  567. if verbose:
  568. m1 = 'Requested tool {t!r} does not support coin {c} on network {n}'
  569. m2 = 'No test tool found for coin {c} on network {n}'
  570. msg((m1 if toolname else m2).format(t=tool,c=coin,n=network))
  571. return None
  572. if addr_type == 'zcash_z':
  573. if toolname in (None,'zcash-mini'):
  574. return 'zcash-mini'
  575. else:
  576. if verbose:
  577. msg(f"Address type {addr_type!r} supported only by tool 'zcash-mini'")
  578. return None
  579. try:
  580. bl = cls.external_tests_blacklist[addr_type][tool]
  581. except:
  582. pass
  583. else:
  584. if bl == True or coin in bl:
  585. if verbose:
  586. msg(f'Tool {tool!r} blacklisted for coin {coin}, addr_type {addr_type!r}')
  587. return None
  588. if toolname: # skip whitelists
  589. return tool
  590. if addr_type in ('segwit','bech32'):
  591. st = cls.external_tests_segwit_whitelist
  592. if addr_type in st and coin in st[addr_type]:
  593. return tool
  594. else:
  595. if verbose:
  596. m1 = 'Requested tool {t!r} does not support coin {c}, addr_type {a!r}, on network {n}'
  597. m2 = 'No test tool found supporting coin {c}, addr_type {a!r}, on network {n}'
  598. msg((m1 if toolname else m2).format(t=tool,c=coin,n=network,a=addr_type))
  599. return None
  600. return tool
  601. external_tests = {
  602. 'mainnet': {
  603. # List in order of preference.
  604. # If 'tool' is not specified, the first tool supporting the coin will be selected.
  605. 'pycoin': (
  606. 'DASH', # only compressed
  607. 'BCH',
  608. 'BTC','LTC','VIA','FTC','DOGE','MEC',
  609. 'JBS','MZC','RIC','DFC','FAI','ARG','ZEC','DCR'),
  610. 'keyconv': (
  611. 'BCH',
  612. # broken: PIVX
  613. '42','AC','AIB','ANC','ARS','ATMOS','AUR','BLK','BQC','BTC','TEST','BTCD','CCC','CCN','CDN',
  614. 'CLAM','CNC','CNOTE','CON','CRW','DEEPONION','DGB','DGC','DMD','DOGED','DOGE','DOPE',
  615. 'DVC','EFL','EMC','EXCL','FAIR','FLOZ','FTC','GAME','GAP','GCR','GRC','GRS','GUN','HAM','HODL',
  616. 'IXC','JBS','LBRY','LEAF','LTC','MMC','MONA','MUE','MYRIAD','MZC','NEOS','NLG','NMC','NVC',
  617. 'NYAN','OK','OMC','PIGGY','PINK','PKB','PND','POT','PPC','PTC','PTS','QTUM','RBY','RDD',
  618. 'RIC','SCA','SDC','SKC','SPR','START','SXC','TPC','UIS','UNO','VIA','VPN','VTC','WDC','WKC',
  619. 'WUBS', 'XC', 'XPM', 'YAC', 'ZOOM', 'ZRC'),
  620. 'ethkey': ('ETH','ETC'),
  621. 'zcash-mini': ('ZEC',),
  622. 'monero-python': ('XMR',),
  623. },
  624. 'testnet': {
  625. 'pycoin': {
  626. 'DASH':'tDASH', # only compressed
  627. 'BCH':'XTN',
  628. 'BTC':'XTN','LTC':'XLT','VIA':'TVI','FTC':'FTX','DOGE':'XDT','DCR':'DCRT'
  629. },
  630. 'ethkey': {},
  631. 'keyconv': {}
  632. }
  633. }
  634. external_tests_segwit_whitelist = {
  635. # Whitelists apply to the *first* tool in cls.external_tests supporting the given coin/addr_type.
  636. # They're ignored if specific tool is requested.
  637. 'segwit': ('BTC',), # LTC Segwit broken on pycoin: uses old fmt
  638. 'bech32': ('BTC','LTC'),
  639. 'compressed': (
  640. 'BTC','LTC','VIA','FTC','DOGE','DASH','MEC','MYR','UNO',
  641. 'JBS','MZC','RIC','DFC','FAI','ARG','ZEC','DCR','ZEC'
  642. ),
  643. }
  644. external_tests_blacklist = {
  645. # Unconditionally block testing of the given coin/addr_type with given tool, or all coins if True
  646. 'legacy': {},
  647. 'segwit': { 'keyconv': True },
  648. 'bech32': { 'keyconv': True },
  649. }
  650. def init_genonly_altcoins(usr_coin=None,testnet=False):
  651. """
  652. Initialize altcoin protocol class or classes for current network.
  653. If usr_coin is a core coin, initialization is skipped.
  654. If usr_coin has a trust level of -1, an exception is raised.
  655. If usr_coin is None, initializes all coins for current network with trust level >-1.
  656. Returns trust_level of usr_coin, or 0 (untrusted) if usr_coin is None.
  657. """
  658. data = { 'mainnet': (), 'testnet': () }
  659. networks = ['mainnet'] + (['testnet'] if testnet else [])
  660. network = 'testnet' if testnet else 'mainnet'
  661. if usr_coin == None:
  662. for network in networks:
  663. data[network] = CoinInfo.get_supported_coins(network)
  664. trust_level = 0
  665. else:
  666. if usr_coin.lower() in gc.core_coins: # core coin, so return immediately
  667. from .protocol import CoinProtocol
  668. return CoinProtocol.coins[usr_coin.lower()].trust_level
  669. for network in networks:
  670. data[network] = (CoinInfo.get_entry(usr_coin,network),)
  671. cinfo = data[network][0]
  672. if not cinfo:
  673. raise ValueError(f'{usr_coin.upper()!r}: unrecognized coin for network {network.upper()}')
  674. if cinfo.trust_level == -1:
  675. raise ValueError(f'{usr_coin.upper()!r}: unsupported (disabled) coin for network {network.upper()}')
  676. create_altcoin_protos(data)
  677. def create_altcoin_protos(data):
  678. from .protocol import CoinProtocol
  679. from .proto.btc.params import mainnet
  680. def make_proto(e,testnet=False):
  681. proto = ('X_' if e.name[0] in '0123456789' else '') + e.name + ('Testnet' if testnet else '')
  682. if hasattr(CoinProtocol,proto):
  683. return
  684. def num2hexstr(n):
  685. return '{:0{}x}'.format(n,(4,2)[n < 256])
  686. setattr(
  687. CoinProtocol,
  688. proto,
  689. type(
  690. proto,
  691. (mainnet,),
  692. {
  693. 'base_coin': e.symbol,
  694. 'addr_ver_info': dict(
  695. [( num2hexstr(e.p2pkh_info[0]), 'p2pkh' )] +
  696. ([( num2hexstr(e.p2sh_info[0]), 'p2sh' )] if e.p2sh_info else [])
  697. ),
  698. 'wif_ver_num': { 'std': num2hexstr(e.wif_ver_num) },
  699. 'mmtypes': ('L','C','S') if e.has_segwit else ('L','C'),
  700. 'dfl_mmtype': 'L',
  701. 'mmcaps': ('key','addr'),
  702. },
  703. )
  704. )
  705. for e in data['mainnet']:
  706. make_proto(e)
  707. for e in data['testnet']:
  708. make_proto(e,testnet=True)
  709. for e in data['mainnet']:
  710. if e.symbol.lower() in CoinProtocol.coins:
  711. continue
  712. CoinProtocol.coins[e.symbol.lower()] = CoinProtocol.proto_info(
  713. name = 'X_'+e.name if e.name[0] in '0123456789' else e.name,
  714. trust_level = e.trust_level )
  715. if __name__ == '__main__':
  716. opts_data = {
  717. 'text': {
  718. 'desc': f'Check altcoin data',
  719. 'usage':'[opts]',
  720. 'options': '-q, --quiet Be quieter\n-v, --verbose Be more verbose'
  721. }
  722. }
  723. cfg = Config( opts_data=opts_data, need_amt=False )
  724. msg('Checking CoinInfo WIF/P2PKH/P2SH version numbers and trust levels against protocol.py')
  725. CoinInfo.verify_core_coin_data( cfg, cfg.quiet, cfg.verbose )
  726. msg('Checking CoinInfo address leading symbols')
  727. CoinInfo.verify_leading_symbols( cfg.quiet, cfg.verbose )