altcoin.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. from .util import msg
  35. def test_equal(desc,a,b,*cdata):
  36. if type(a) == int:
  37. a = hex(a)
  38. b = hex(b)
  39. (network,coin,e,b_desc,verbose) = cdata
  40. if verbose:
  41. msg(f' {desc:20}: {a!r}')
  42. if a != b:
  43. raise ValueError(
  44. '{}s for {} {} do not match:\n CoinInfo: {}\n {}: {}'.format(
  45. desc.capitalize(),
  46. coin.upper(),
  47. network,
  48. a,
  49. b_desc,
  50. b ))
  51. from collections import namedtuple
  52. ce = namedtuple('CoinInfoEntry',
  53. ['name','symbol','wif_ver_num','p2pkh_info','p2sh_info','has_segwit','trust_level'])
  54. class CoinInfo(object):
  55. coin_constants = {}
  56. coin_constants['mainnet'] = (
  57. # Trust levels: -1=disabled 0=untested 1=low 2=med 3=high 4=very high (no warn) 5=unconditional
  58. # Trust levels apply to key/address generation only.
  59. # Non core-coin fork coins (i.e. BCG) must be disabled here to prevent generation from
  60. # incorrect scrambled seed.
  61. ce('Bitcoin', 'BTC', 0x80, (0x00,'1'), (0x05,'3'), True, 5),
  62. ce('BitcoinCashNode', 'BCH', 0x80, (0x00,'1'), (0x05,'3'), False, 5),
  63. ce('BitcoinGold', 'BCG', 0x80, (0x00,'1'), (0x05,'3'), True, -1),
  64. ce('2GiveCoin', '2GIVE', 0xa7, (0x27,('G','H')), None, False, 0),
  65. ce('42Coin', '42', 0x88, (0x08,'4'), None, False, 1),
  66. ce('ACoin', 'ACOIN', 0xe6, (0x17,'A'), None, False, 0),
  67. ce('Alphacoin', 'ALF', 0xd2, (0x52,('Z','a')), None, False, 0),
  68. ce('Anoncoin', 'ANC', 0x97, (0x17,'A'), None, False, 1),
  69. ce('Apexcoin', 'APEX', 0x97, (0x17,'A'), None, False, 0),
  70. ce('Aquariuscoin', 'ARCO', 0x97, (0x17,'A'), None, False, 0),
  71. ce('Argentum', 'ARG', 0x97, (0x17,'A'), (0x05,'3'), False, 1),
  72. ce('AsiaCoin', 'AC', 0x97, (0x17,'A'), (0x08,'4'), False, 1),
  73. ce('Auroracoin', 'AUR', 0x97, (0x17,'A'), None, False, 1),
  74. ce('BBQcoin', 'BQC', 0xd5, (0x55,'b'), None, False, 1),
  75. ce('BitcoinDark', 'BTCD', 0xbc, (0x3c,'R'), (0x55,'b'), False, 1),
  76. ce('BitcoinFast', 'BCF', 0xe0, (0x60,('f','g')), None, False, 0),
  77. ce('BitQuark', 'BTQ', 0xba, (0x3a,'Q'), None, False, 0),
  78. ce('Blackcoin', 'BLK', 0x99, (0x19,'B'), (0x55,'b'), False, 1),
  79. ce('BlackmoonCrypto', 'BMC', 0x83, (0x03,'2'), None, False, 0),
  80. ce('BlockCat', 'CAT', 0x95, (0x15,'9'), None, False, 0),
  81. ce('CanadaECoin', 'CDN', 0x9c, (0x1c,'C'), (0x05,'3'), False, 1),
  82. ce('CannabisCoin', 'CANN', 0x9c, (0x1c,'C'), None, False, 0),
  83. ce('CannaCoin', 'CCN', 0x9c, (0x1c,'C'), (0x05,'3'), False, 1),
  84. ce('Capricoin', 'CPC', 0x9c, (0x1c,'C'), None, False, 0),
  85. ce('CashCoin', 'CASH', 0xa2, (0x22,('E','F')), None, False, 0),
  86. ce('CashOut', 'CSH', 0xa2, (0x22,('E','F')), None, False, 0),
  87. ce('ChainCoin', 'CHC', 0x9c, (0x1c,'C'), None, False, 0),
  88. ce('Clams', 'CLAM', 0x85, (0x89,'x'), (0x0d,'6'), False, 1),
  89. ce('CoinMagi', 'XMG', 0x94, (0x14,'9'), None, False, 0),
  90. ce('Condensate', 'RAIN', 0xbc, (0x3c,'R'), None, False, 0),
  91. ce('CryptoBullion', 'CBX', 0x8b, (0x0b,'5'), None, False, 0),
  92. ce('Cryptonite', 'XCN', 0x80, (0x1c,'C'), None, False, 0),
  93. ce('CryptoPennies', 'CRPS', 0xc2, (0x42,'T'), None, False, 0),
  94. ce('Dash', 'DASH', 0xcc, (0x4c,'X'), (0x10,'7'), False, 1),
  95. ce('Decred', 'DCR', 0x22de, (0x073f,'D'), (0x071a,'D'), False, 1),
  96. ce('DeepOnion', 'ONION', 0x9f, (0x1f,'D'), None, False, 1),
  97. ce('Defcoin', 'DFC', 0x9e, (0x1e,'D'), (0x05,'3'), False, 1),
  98. ce('Devcoin', 'DVC', 0x80, (0x00,'1'), None, False, 1),
  99. ce('DigiByte', 'DGB', 0x80, (0x1e,'D'), (0x05,'3'), False, 1),
  100. ce('DigiCoin', 'DGC', 0x9e, (0x1e,'D'), (0x05,'3'), False, 1),
  101. ce('DogecoinDark', 'DOGED', 0x9e, (0x1e,'D'), (0x21,'E'), False, 1),
  102. ce('Dogecoin', 'DOGE', 0x9e, (0x1e,'D'), (0x16,('9','A')), False, 2),
  103. ce('DopeCoin', 'DOPE', 0x88, (0x08,'4'), (0x05,'3'), False, 1),
  104. ce('EGulden', 'EFL', 0xb0, (0x30,'L'), (0x05,'3'), False, 1),
  105. ce('Emerald', 'EMD', 0xa2, (0x22,('E','F')), None, False, 0),
  106. ce('Emercoin', 'EMC', 0x80, (0x21,'E'), (0x5c,'e'), False, 2),
  107. ce('EnergyCoin', 'ENRG', 0xdc, (0x5c,'e'), None, False, 0),
  108. ce('Espers', 'ESP', 0xa1, (0x21,'E'), None, False, 0),
  109. ce('Faircoin', 'FAI', 0xdf, (0x5f,'f'), (0x24,'F'), False, 1),
  110. ce('Fastcoin', 'FST', 0xe0, (0x60,('f','g')), None, False, 0),
  111. ce('Feathercoin', 'FTC', 0x8e, (0x0e,('6','7')), (0x05,'3'), False, 2),
  112. ce('Fibre', 'FIBRE', 0xa3, (0x23,'F'), None, False, 0),
  113. ce('FlorinCoin', 'FLO', 0xb0, (0x23,'F'), None, False, 0),
  114. ce('Fluttercoin', 'FLT', 0xa3, (0x23,'F'), None, False, 0),
  115. ce('Fuel2Coin', 'FC2', 0x80, (0x24,'F'), None, False, 0),
  116. ce('Fujicoin', 'FJC', 0xa4, (0x24,'F'), None, False, 0),
  117. ce('Fujinto', 'NTO', 0xa4, (0x24,'F'), None, False, 0),
  118. ce('GlobalBoost', 'BSTY', 0xa6, (0x26,'G'), None, False, 0),
  119. ce('GlobalCurrencyReserve', 'GCR', 0x9a, (0x26,'G'), (0x61,'g'), False, 1),
  120. ce('GoldenBird', 'XGB', 0xaf, (0x2f,('K','L')), None, False, 0),
  121. ce('Goodcoin', 'GOOD', 0xa6, (0x26,'G'), None, False, 0),
  122. ce('GridcoinResearch', 'GRC', 0xbe, (0x3e,('R','S')), None, False, 1),
  123. ce('Gulden', 'NLG', 0xa6, (0x26,'G'), None, False, 1),
  124. ce('Guncoin', 'GUN', 0xa7, (0x27,('G','H')), None, False, 1),
  125. ce('HamRadioCoin', 'HAM', 0x80, (0x00,'1'), None, False, 1),
  126. ce('HTML5Coin', 'HTML5', 0xa8, (0x28,'H'), None, False, 0),
  127. ce('HyperStake', 'HYP', 0xf5, (0x75,'p'), None, False, 0),
  128. ce('iCash', 'ICASH', 0xcc, (0x66,'i'), None, False, 0),
  129. ce('ImperiumCoin', 'IPC', 0xb0, (0x30,'L'), None, False, 0),
  130. ce('IncaKoin', 'NKA', 0xb5, (0x35,'N'), None, False, 0),
  131. ce('Influxcoin', 'INFX', 0xe6, (0x66,'i'), None, False, 0),
  132. ce('InPay', 'INPAY', 0xb7, (0x37,'P'), None, False, 0),
  133. # ce('iXcoin', 'IXC', 0x80, (0x8a,'x'), None, False, 1),
  134. ce('Judgecoin', 'JUDGE', 0xab, (0x2b,'J'), None, False, 0),
  135. ce('Jumbucks', 'JBS', 0xab, (0x2b,'J'), (0x69,'j'), False, 2),
  136. ce('Lanacoin', 'LANA', 0xb0, (0x30,'L'), None, False, 0),
  137. ce('Latium', 'LAT', 0x80, (0x17,'A'), None, False, 0),
  138. ce('Litecoin', 'LTC', 0xb0, (0x30,'L'), (0x32,'M'), True, 5), # old p2sh: 0x05
  139. ce('LiteDoge', 'LDOGE', 0xab, (0x5a,'d'), None, False, 0),
  140. ce('LomoCoin', 'LMC', 0xb0, (0x30,'L'), None, False, 0),
  141. ce('Marscoin', 'MARS', 0xb2, (0x32,'M'), None, False, 0),
  142. ce('MarsCoin', 'MRS', 0xb2, (0x32,'M'), None, False, 0),
  143. ce('MartexCoin', 'MXT', 0xb2, (0x32,'M'), None, False, 0),
  144. ce('MasterCar', 'MCAR', 0xe6, (0x17,'A'), None, False, 0),
  145. ce('MazaCoin', 'MZC', 0xe0, (0x32,'M'), (0x09,('4','5')), False, 2),
  146. ce('MegaCoin', 'MEC', 0xb2, (0x32,'M'), None, False, 1),
  147. ce('MintCoin', 'MINT', 0xb3, (0x33,'M'), None, False, 0),
  148. ce('Mobius', 'MOBI', 0x80, (0x00,'1'), None, False, 0),
  149. ce('MonaCoin', 'MONA', 0xb0, (0x32,'M'), (0x05,'3'), False, 1),
  150. ce('MonetaryUnit', 'MUE', 0x8f, (0x0f,'7'), (0x09,('4','5')), False, 1),
  151. ce('MoonCoin', 'MOON', 0x83, (0x03,'2'), None, False, 0),
  152. ce('MyriadCoin', 'MYR', 0xb2, (0x32,'M'), (0x09,('4','5')), False, 1),
  153. ce('Myriadcoin', 'MYRIAD', 0xb2, (0x32,'M'), None, False, 1),
  154. ce('Namecoin', 'NMC', 0xb4, (0x34,('M','N')), (0x0d,'6'), False, 1),
  155. ce('Neoscoin', 'NEOS', 0xef, (0x3f,'S'), (0xbc,'2'), False, 1),
  156. ce('NevaCoin', 'NEVA', 0xb1, (0x35,'N'), None, False, 0),
  157. ce('Novacoin', 'NVC', 0x88, (0x08,'4'), (0x14,'9'), False, 1),
  158. ce('OKCash', 'OK', 0xb7, (0x37,'P'), (0x1c,'C'), False, 1),
  159. ce('Omnicoin', 'OMC', 0xf3, (0x73,'o'), None, False, 1),
  160. ce('Omni', 'OMNI', 0xf3, (0x73,'o'), None, False, 0),
  161. ce('Onix', 'ONX', 0x80, (0x8a,'x'), None, False, 0),
  162. ce('PandaCoin', 'PND', 0xb7, (0x37,'P'), (0x16,('9','A')), False, 1),
  163. ce('ParkByte', 'PKB', 0xb7, (0x37,'P'), (0x1c,'C'), False, 1),
  164. ce('Particl', 'PART', 0x6c, (0x38,'P'), None, False, 0),
  165. ce('Paycoin', 'CON', 0xb7, (0x37,'P'), None, False, 1),
  166. ce('Peercoin', 'PPC', 0xb7, (0x37,'P'), (0x75,'p'), False, 1),
  167. ce('PesetaCoin', 'PTC', 0xaf, (0x2f,('K','L')), None, False, 1),
  168. ce('PhoenixCoin', 'PXC', 0xb8, (0x38,'P'), None, False, 0),
  169. ce('PinkCoin', 'PINK', 0x83, (0x03,'2'), None, False, 1),
  170. ce('PIVX', 'PIVX', 0xd4, (0x1e,'D'), None, False, 0),
  171. ce('PokeChain', 'XPOKE', 0x9c, (0x1c,'C'), None, False, 0),
  172. ce('Potcoin', 'POT', 0xb7, (0x37,'P'), (0x05,'3'), False, 1),
  173. ce('Primecoin', 'XPM', 0x97, (0x17,'A'), (0x53,'a'), False, 1),
  174. ce('Quark', 'QRK', 0xba, (0x3a,'Q'), None, False, 0),
  175. ce('ReddCoin', 'RDD', 0xbd, (0x3d,'R'), None, False, 1),
  176. ce('Riecoin', 'RIC', 0x80, (0x3c,'R'), (0x05,'3'), False, 2),
  177. ce('Rimbit', 'RBT', 0xbc, (0x3c,'R'), None, False, 0),
  178. ce('Rubycoin', 'RBY', 0xbd, (0x3d,'R'), (0x55,'b'), False, 1),
  179. ce('ShadowCash', 'SDC', 0xbf, (0x3f,'S'), (0x7d,'s'), False, 1),
  180. ce('Sibcoin', 'SIB', 0x80, (0x3f,'S'), None, False, 0),
  181. ce('SixEleven', '611', 0x80, (0x34,('M','N')), None, False, 0),
  182. ce('SmileyCoin', 'SMLY', 0x99, (0x19,'B'), None, False, 0),
  183. ce('Songcoin', 'SONG', 0xbf, (0x3f,'S'), None, False, 0),
  184. ce('Spreadcoin', 'SPR', 0xbf, (0x3f,'S'), None, False, 1),
  185. ce('Startcoin', 'START', 0xfd, (0x7d,'s'), (0x05,'3'), False, 1),
  186. ce('StealthCoin', 'XST', 0xbe, (0x3e,('R','S')), None, False, 0),
  187. ce('SwagBucks', 'BUCKS', 0x99, (0x3f,'S'), None, False, 0),
  188. ce('SysCoin', 'SYS', 0x80, (0x00,'1'), None, False, 0),
  189. ce('TajCoin', 'TAJ', 0x6f, (0x41,'T'), None, False, 0),
  190. ce('Templecoin', 'TPC', 0xc1, (0x41,'T'), (0x05,'3'), False, 1),
  191. ce('Terracoin', 'TRC', 0x80, (0x00,'1'), None, False, 0),
  192. ce('Titcoin', 'TIT', 0x80, (0x00,'1'), None, False, 0),
  193. ce('TittieCoin', 'TTC', 0xc1, (0x41,'T'), None, False, 0),
  194. ce('Transfer', 'TX', 0x99, (0x42,'T'), None, False, 0),
  195. ce('Unobtanium', 'UNO', 0xe0, (0x82,'u'), (0x1e,'D'), False, 2),
  196. ce('Vcash', 'XVC', 0xc7, (0x47,'V'), None, False, 0),
  197. ce('Vertcoin', 'VTC', 0xc7, (0x47,'V'), (0x05,'3'), False, 1),
  198. ce('Viacoin', 'VIA', 0xc7, (0x47,'V'), (0x21,'E'), False, 2),
  199. ce('VpnCoin', 'VPN', 0xc7, (0x47,'V'), (0x05,'3'), False, 1),
  200. ce('WankCoin', 'WKC', 0x80, (0x00,'1'), None, False, 1),
  201. ce('WashingtonCoin', 'WASH', 0xc9, (0x49,'W'), None, False, 0),
  202. ce('WeAreSatoshi', 'WSX', 0x97, (0x87,'w'), None, False, 0),
  203. ce('WisdomCoin', 'WISC', 0x87, (0x49,'W'), None, False, 0),
  204. ce('WorldCoin', 'WDC', 0xc9, (0x49,'W'), None, False, 1),
  205. ce('XRealEstateDevcoin', 'XRED', 0x80, (0x00,'1'), None, False, 0),
  206. ce('ZetaCoin', 'ZET', 0xe0, (0x50,'Z'), None, False, 0),
  207. ce('ZiftrCoin', 'ZRC', 0xd0, (0x50,'Z'), (0x05,'3'), False, 1),
  208. ce('ZLiteQubit', 'ZLQ', 0xe0, (0x26,'G'), None, False, 0),
  209. ce('Zoomcoin', 'ZOOM', 0xe7, (0x67,'i'), (0x5c,'e'), False, 1),
  210. )
  211. coin_constants['testnet'] = (
  212. ce('Bitcoin', 'BTC', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, 5),
  213. ce('BitcoinCashNode','BCH',0xef, (0x6f,('m','n')), (0xc4,'2'), True, 5),
  214. ce('BitcoinGold', 'BCG', 0xef, (0x6f,('m','n')), (0xc4,'2'), True, -1),
  215. ce('Dash', 'DASH', 0xef, (0x8c,'y'), (0x13,('8','9')), False, 1),
  216. ce('Decred', 'DCR', 0x230e, (0x0f21,'T'), (0x0e6c,'S'), False, 1),
  217. ce('Dogecoin', 'DOGE', 0xf1, (0x71,'n'), (0xc4,'2'), False, 2),
  218. ce('Feathercoin', 'FTC', 0xc1, (0x41,'T'), (0xc4,'2'), False, 2),
  219. ce('Viacoin', 'VIA', 0xff, (0x7f,'t'), (0xc4,'2'), False, 2),
  220. ce('Emercoin', 'EMC', 0xef, (0x6f,('m','n')), (0xc4,'2'), False, 2),
  221. ce('Litecoin', 'LTC', 0xef, (0x6f,('m','n')), (0x3a,'Q'), True, 5), # old p2sh: 0xc4
  222. )
  223. coin_sources = (
  224. ('BTC', 'https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp'),
  225. ('EMC', 'https://github.com/emercoin/emercoin/blob/master/src/chainparams.cpp'), # checked mn,tn
  226. ('LTC', 'https://github.com/litecoin-project/litecoin/blob/master-0.10/src/chainparams.cpp'),
  227. ('DOGE', 'https://github.com/dogecoin/dogecoin/blob/master/src/chainparams.cpp'),
  228. ('RDD', 'https://github.com/reddcoin-project/reddcoin/blob/master/src/base58.h'),
  229. ('DASH', 'https://github.com/dashpay/dash/blob/master/src/chainparams.cpp'),
  230. ('PPC', 'https://github.com/belovachap/peercoin/blob/master/src/base58.h'),
  231. ('NMC', 'https://github.com/domob1812/namecore/blob/master/src/chainparams.cpp'),
  232. ('FTC', 'https://github.com/FeatherCoin/Feathercoin/blob/master-0.8/src/base58.h'),
  233. ('BLK', 'https://github.com/rat4/blackcoin/blob/master/src/chainparams.cpp'),
  234. ('NSR', 'https://nubits.com/nushares/introduction'),
  235. ('NBT', 'https://bitbucket.org/JordanLeePeershares/nubit/NuBit / src /base58.h'),
  236. ('MZC', 'https://github.com/MazaCoin/MazaCoin/blob/master/src/chainparams.cpp'),
  237. ('VIA', 'https://github.com/viacoin/viacoin/blob/master/src/chainparams.cpp'),
  238. ('RBY', 'https://github.com/rubycoinorg/rubycoin/blob/master/src/base58.h'),
  239. ('GRS', 'https://github.com/GroestlCoin/groestlcoin/blob/master/src/groestlcoin.cpp'),
  240. ('DGC', 'https://github.com/DGCDev/digitalcoin/blob/master/src/chainparams.cpp'),
  241. ('CCN', 'https://github.com/Cannacoin-Project/Cannacoin/blob/Proof-of-Stake/src/base58.h'),
  242. ('DGB', 'https://github.com/digibyte/digibyte/blob/master/src/chainparams.cpp'),
  243. ('MONA', 'https://github.com/monacoinproject/monacoin/blob/master-0.10/src/chainparams.cpp'),
  244. ('CLAM', 'https://github.com/nochowderforyou/clams/blob/master/src/chainparams.cpp'),
  245. ('XPM', 'https://github.com/primecoin/primecoin/blob/master/src/base58.h'),
  246. ('NEOS', 'https://github.com/bellacoin/neoscoin/blob/master/src/chainparams.cpp'),
  247. ('JBS', 'https://github.com/jyap808/jumbucks/blob/master/src/base58.h'),
  248. ('ZRC', 'https://github.com/ZiftrCOIN/ziftrcoin/blob/master/src/chainparams.cpp'),
  249. ('VTC', 'https://github.com/vertcoin/vertcoin/blob/master/src/base58.h'),
  250. ('NXT', 'https://bitbucket.org/JeanLucPicard/nxt/src and unofficial at https://github.com/Blackcomb/nxt'),
  251. ('MUE', 'https://github.com/MonetaryUnit/MUE-Src/blob/master/src/chainparams.cpp'),
  252. ('ZOOM', 'https://github.com/zoom-c/zoom/blob/master/src/base58.h'),
  253. ('VPN', 'https://github.com/Bit-Net/VpnCoin/blob/master/src/base58.h'),
  254. ('CDN', 'https://github.com/ThisIsOurCoin/canadaecoin/blob/master/src/base58.h'),
  255. ('SDC', 'https://github.com/ShadowProject/shadow/blob/master/src/chainparams.cpp'),
  256. ('PKB', 'https://github.com/parkbyte/ParkByte/blob/master/src/base58.h'),
  257. ('PND', 'https://github.com/coinkeeper/2015-04-19_21-22_pandacoin/blob/master/src/base58.h'),
  258. ('START', 'https://github.com/startcoin-project/startcoin/blob/master/src/base58.h'),
  259. ('GCR', 'https://github.com/globalcurrencyreserve/gcr/blob/master/src/chainparams.cpp'),
  260. ('NVC', 'https://github.com/novacoin-project/novacoin/blob/master/src/base58.h'),
  261. ('AC', 'https://github.com/AsiaCoin/AsiaCoinFix/blob/master/src/base58.h'),
  262. ('BTCD', 'https://github.com/jl777/btcd/blob/master/src/base58.h'),
  263. ('DOPE', 'https://github.com/dopecoin-dev/DopeCoinV3/blob/master/src/base58.h'),
  264. ('TPC', 'https://github.com/9cat/templecoin/blob/templecoin/src/base58.h'),
  265. ('OK', 'https://github.com/okcashpro/okcash/blob/master/src/chainparams.cpp'),
  266. ('DOGED', 'https://github.com/doged/dogedsource/blob/master/src/base58.h'),
  267. ('EFL', 'https://github.com/Electronic-Gulden-Foundation/egulden/blob/master/src/base58.h'),
  268. ('POT', 'https://github.com/potcoin/Potcoin/blob/master/src/base58.h'),
  269. )
  270. # Sources (see above) that are in agreement for these coins
  271. # No check for segwit, p2sh check skipped if source doesn't support it
  272. cross_checks = {
  273. '2GIVE': ['wn'],
  274. '42': ['vg','wn'],
  275. '611': ['wn'],
  276. 'AC': ['lb','vg'],
  277. 'ACOIN': ['wn'],
  278. 'ALF': ['wn'],
  279. 'ANC': ['vg','wn'],
  280. 'APEX': ['wn'],
  281. 'ARCO': ['wn'],
  282. 'ARG': ['pc'],
  283. 'AUR': ['vg','wn'],
  284. 'BCH': ['wn'],
  285. 'BLK': ['lb','vg','wn'],
  286. 'BQC': ['vg','wn'],
  287. 'BSTY': ['wn'],
  288. 'BTC': ['lb','vg','wn'],
  289. 'BTCD': ['lb','vg','wn'],
  290. 'BUCKS': ['wn'],
  291. 'CASH': ['wn'],
  292. 'CBX': ['wn'],
  293. 'CCN': ['lb','vg','wn'],
  294. 'CDN': ['lb','vg','wn'],
  295. 'CHC': ['wn'],
  296. 'CLAM': ['lb','vg'],
  297. 'CON': ['vg','wn'],
  298. 'CPC': ['wn'],
  299. 'DASH': ['lb','pc','vg','wn'],
  300. 'DCR': ['pc'],
  301. 'DFC': ['pc'],
  302. 'DGB': ['lb','vg'],
  303. 'DGC': ['lb','vg','wn'],
  304. 'DOGE': ['lb','pc','vg','wn'],
  305. 'DOGED': ['lb','vg','wn'],
  306. 'DOPE': ['lb','vg'],
  307. 'DVC': ['vg','wn'],
  308. 'EFL': ['lb','vg','wn'],
  309. 'EMC': ['vg'],
  310. 'EMD': ['wn'],
  311. 'ESP': ['wn'],
  312. 'FAI': ['pc'],
  313. 'FC2': ['wn'],
  314. 'FIBRE': ['wn'],
  315. 'FJC': ['wn'],
  316. 'FLO': ['wn'],
  317. 'FLT': ['wn'],
  318. 'FST': ['wn'],
  319. 'FTC': ['lb','pc','vg','wn'],
  320. 'GCR': ['lb','vg'],
  321. 'GOOD': ['wn'],
  322. 'GRC': ['vg','wn'],
  323. 'GUN': ['vg','wn'],
  324. 'HAM': ['vg','wn'],
  325. 'HTML5': ['wn'],
  326. 'HYP': ['wn'],
  327. 'ICASH': ['wn'],
  328. 'INFX': ['wn'],
  329. 'IPC': ['wn'],
  330. 'JBS': ['lb','pc','vg','wn'],
  331. 'JUDGE': ['wn'],
  332. 'LANA': ['wn'],
  333. 'LAT': ['wn'],
  334. 'LDOGE': ['wn'],
  335. 'LMC': ['wn'],
  336. 'LTC': ['lb','vg','wn'],
  337. 'MARS': ['wn'],
  338. 'MEC': ['pc','wn'],
  339. 'MINT': ['wn'],
  340. 'MOBI': ['wn'],
  341. 'MONA': ['lb','vg'],
  342. 'MOON': ['wn'],
  343. 'MUE': ['lb','vg'],
  344. 'MXT': ['wn'],
  345. 'MYR': ['pc'],
  346. 'MYRIAD': ['vg','wn'],
  347. 'MZC': ['lb','pc','vg','wn'],
  348. 'NEOS': ['lb','vg'],
  349. 'NEVA': ['wn'],
  350. 'NKA': ['wn'],
  351. 'NLG': ['vg','wn'],
  352. 'NMC': ['lb','vg'],
  353. 'NVC': ['lb','vg','wn'],
  354. 'OK': ['lb','vg'],
  355. 'OMC': ['vg','wn'],
  356. 'ONION': ['vg','wn'],
  357. 'PART': ['wn'],
  358. 'PINK': ['vg','wn'],
  359. 'PIVX': ['wn'],
  360. 'PKB': ['lb','vg','wn'],
  361. 'PND': ['lb','vg','wn'],
  362. 'POT': ['lb','vg','wn'],
  363. 'PPC': ['lb','vg','wn'],
  364. 'PTC': ['vg','wn'],
  365. 'PXC': ['wn'],
  366. 'QRK': ['wn'],
  367. 'RAIN': ['wn'],
  368. 'RBT': ['wn'],
  369. 'RBY': ['lb','vg'],
  370. 'RDD': ['vg','wn'],
  371. 'RIC': ['pc','vg','wn'],
  372. 'SDC': ['lb','vg'],
  373. 'SIB': ['wn'],
  374. 'SMLY': ['wn'],
  375. 'SONG': ['wn'],
  376. 'SPR': ['vg','wn'],
  377. 'START': ['lb','vg'],
  378. 'SYS': ['wn'],
  379. 'TAJ': ['wn'],
  380. 'TIT': ['wn'],
  381. 'TPC': ['lb','vg'],
  382. 'TRC': ['wn'],
  383. 'TTC': ['wn'],
  384. 'TX': ['wn'],
  385. 'UNO': ['pc','vg','wn'],
  386. 'VIA': ['lb','pc','vg','wn'],
  387. 'VPN': ['lb','vg'],
  388. 'VTC': ['lb','vg','wn'],
  389. 'WDC': ['vg','wn'],
  390. 'WISC': ['wn'],
  391. 'WKC': ['vg','wn'],
  392. 'WSX': ['wn'],
  393. 'XCN': ['wn'],
  394. 'XGB': ['wn'],
  395. 'XPM': ['lb','vg','wn'],
  396. 'XST': ['wn'],
  397. 'XVC': ['wn'],
  398. 'ZET': ['wn'],
  399. 'ZOOM': ['lb','vg'],
  400. 'ZRC': ['lb','vg']
  401. }
  402. @classmethod
  403. def verify_leading_symbols(cls,quiet=False,verbose=False):
  404. for network in ('mainnet','testnet'):
  405. for coin in [e.symbol for e in cls.coin_constants[network]]:
  406. e = cls.get_entry(coin,network)
  407. cdata = (network,coin,e,'Computed value',verbose)
  408. if not quiet:
  409. msg(f'{coin} {network}')
  410. vn_info = e.p2pkh_info
  411. ret = cls.find_addr_leading_symbol(vn_info[0])
  412. test_equal('P2PKH leading symbol',vn_info[1],ret,*cdata)
  413. vn_info = e.p2sh_info
  414. if vn_info:
  415. ret = cls.find_addr_leading_symbol(vn_info[0])
  416. test_equal('P2SH leading symbol',vn_info[1],ret,*cdata)
  417. @classmethod
  418. def verify_core_coin_data(cls,quiet=False,verbose=False):
  419. from .protocol import CoinProtocol,init_proto
  420. from .globalvars import g
  421. for network in ('mainnet','testnet'):
  422. for coin in g.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 .proto.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. 'moneropy': ('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': { 'pycoin': ('DASH',) },
  647. 'segwit': { 'pycoin': ('LTC',), '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. from .globalvars import g
  667. if usr_coin.lower() in g.core_coins: # core coin, so return immediately
  668. from .protocol import CoinProtocol
  669. return CoinProtocol.coins[usr_coin.lower()].trust_level
  670. for network in networks:
  671. data[network] = (CoinInfo.get_entry(usr_coin,network),)
  672. cinfo = data[network][0]
  673. if not cinfo:
  674. raise ValueError(f'{usr_coin.upper()!r}: unrecognized coin for network {network.upper()}')
  675. if cinfo.trust_level == -1:
  676. raise ValueError(f'{usr_coin.upper()!r}: unsupported (disabled) coin for network {network.upper()}')
  677. create_altcoin_protos(data)
  678. def create_altcoin_protos(data):
  679. from .protocol import CoinProtocol
  680. from .proto.btc import mainnet
  681. def make_proto(e,testnet=False):
  682. proto = ('X_' if e.name[0] in '0123456789' else '') + e.name + ('Testnet' if testnet else '')
  683. if hasattr(CoinProtocol,proto):
  684. return
  685. def num2hexstr(n):
  686. return '{:0{}x}'.format(n,(4,2)[n < 256])
  687. setattr(
  688. CoinProtocol,
  689. proto,
  690. type(
  691. proto,
  692. (mainnet,),
  693. {
  694. 'base_coin': e.symbol,
  695. 'addr_ver_bytes': dict(
  696. [( num2hexstr(e.p2pkh_info[0]), 'p2pkh' )] +
  697. ([( num2hexstr(e.p2sh_info[0]), 'p2sh' )] if e.p2sh_info else [])
  698. ),
  699. 'wif_ver_num': { 'std': num2hexstr(e.wif_ver_num) },
  700. 'mmtypes': ('L','C','S') if e.has_segwit else ('L','C'),
  701. 'dfl_mmtype': 'L',
  702. 'mmcaps': ('key','addr'),
  703. },
  704. )
  705. )
  706. for e in data['mainnet']:
  707. make_proto(e)
  708. for e in data['testnet']:
  709. make_proto(e,testnet=True)
  710. for e in data['mainnet']:
  711. if e.symbol.lower() in CoinProtocol.coins:
  712. continue
  713. CoinProtocol.coins[e.symbol.lower()] = CoinProtocol.proto_info(
  714. name = 'X_'+e.name if e.name[0] in '0123456789' else e.name,
  715. trust_level = e.trust_level )
  716. if __name__ == '__main__':
  717. quiet = '--quiet' in sys.argv
  718. verbose = '--verbose' in sys.argv
  719. if verbose:
  720. quiet = False
  721. msg('Checking CoinInfo WIF/P2PKH/P2SH version numbers and trust levels against protocol.py')
  722. CoinInfo.verify_core_coin_data(quiet=quiet,verbose=verbose)
  723. msg('Checking CoinInfo address leading symbols')
  724. CoinInfo.verify_leading_symbols(quiet=quiet,verbose=verbose)