ts_ref_3seed.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, command-line Bitcoin cold storage solution
  4. # Copyright (C)2013-2019 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. ts_ref_3seed.py: Saved and generated reference file tests for 128, 192 and
  20. 256-bit seeds for the test.py test suite
  21. """
  22. from mmgen.globalvars import g
  23. from mmgen.opts import opt
  24. from test.common import *
  25. from test.test_py_d.common import *
  26. from test.test_py_d.ts_base import *
  27. from test.test_py_d.ts_shared import *
  28. from test.test_py_d.ts_wallet import TestSuiteWalletConv
  29. class TestSuiteRef3Seed(TestSuiteBase,TestSuiteShared):
  30. 'saved and generated reference data for 128-, 192- and 256-bit seeds'
  31. networks = ('btc','btc_tn','ltc','ltc_tn')
  32. passthru_opts = ('coin','testnet')
  33. mmtypes = (None,)
  34. tmpdir_nums = [6,7,8]
  35. addr_idx_list_in = '1010,500-501,31-33,1,33,500,1011'
  36. pass_idx_list_in = '1,4,9-11,1100'
  37. chk_data = {
  38. 'refaddrgen_legacy_1': {
  39. 'btc': ('B230 7526 638F 38CB','A9DC 5A13 12CB 1317'),
  40. 'ltc': ('2B23 5E97 848A B961','AEC3 E774 0B21 0202'),
  41. },
  42. 'refaddrgen_segwit_1': {
  43. 'btc': ('9914 6D10 2307 F348','83C8 A6B6 ADA8 25B2'),
  44. 'ltc': ('CC09 A190 B7DF B7CD','0425 7893 C6F1 ECA3'),
  45. },
  46. 'refaddrgen_bech32_1': {
  47. 'btc': ('C529 D686 31AA ACD4','21D0 26AD 3A22 5465'),
  48. 'ltc': ('3DFB CFCC E180 DC9D','8C72 D5C2 07E0 5F7B'),
  49. },
  50. 'refaddrgen_compressed_1': {
  51. 'btc': ('95EB 8CC0 7B3B 7856','16E6 6170 154D 2202'),
  52. 'ltc': ('35D5 8ECA 9A42 46C3','15B3 5492 D3D3 6854'),
  53. },
  54. 'refkeyaddrgen_legacy_1': {
  55. 'btc': ('CF83 32FB 8A8B 08E2','1F67 B73A FF8C 5D15'),
  56. 'ltc': ('1896 A26C 7F14 2D01','FA0E CD4E ADAF DBF4'),
  57. },
  58. 'refkeyaddrgen_compressed_1': {
  59. 'btc': ('E43A FA46 5751 720A','FDEE 8E45 1C0A 02AD'),
  60. 'ltc': ('7603 2FE3 2145 FFAD','3FE0 5A8E 5FBE FF3E'),
  61. },
  62. 'refkeyaddrgen_segwit_1': {
  63. 'btc': ('C13B F717 D4E8 CF59','BB71 175C 5416 19D8'),
  64. 'ltc': ('054B 9794 55B4 5D82','DE85 3CF3 9636 FE2E'),
  65. },
  66. 'refkeyaddrgen_bech32_1': {
  67. 'btc': ('934F 1C33 6C06 B18C','A283 5BAB 7AF3 3EA4'),
  68. 'ltc': ('A6AD DF53 5968 7B6A','9572 43E0 A4DC 0B2E'),
  69. },
  70. 'refpasswdgen_1': 'EB29 DC4F 924B 289F',
  71. 'ref_b32passwdgen_1': '37B6 C218 2ABC 7508',
  72. 'ref_hexpasswdgen_1': '523A F547 0E69 8323',
  73. 'refaddrgen_legacy_2': {
  74. 'btc': ('8C17 A5FA 0470 6E89','764C 66F9 7502 AAEA'),
  75. 'ltc': ('2B77 A009 D5D0 22AD','51D1 979D 0A35 F24B'),
  76. },
  77. 'refaddrgen_compressed_2': {
  78. 'btc': ('2615 8401 2E98 7ECA','A386 EE07 A356 906D'),
  79. 'ltc': ('197C C48C 3C37 AB0F','8DDC 5FE3 BFF9 1226'),
  80. },
  81. 'refaddrgen_segwit_2': {
  82. 'btc': ('91C4 0414 89E4 2089','BF9F C67F ED22 A47B'),
  83. 'ltc': ('8F12 FA7B 9F12 594C','2609 8494 A23C F836'),
  84. },
  85. 'refaddrgen_bech32_2': {
  86. 'btc': ('2AA3 78DF B965 82EB','027B 1C1F 7FB2 D859'),
  87. 'ltc': ('951C 8FB2 FCA5 87D1','4A5D 67E0 8210 FEF2'),
  88. },
  89. 'refkeyaddrgen_legacy_2': {
  90. 'btc': ('9648 5132 B98E 3AD9','1BD3 5A36 D51C 256D'),
  91. 'ltc': ('DBD4 FAB6 7E46 CD07','8822 3FDF FEC0 6A8C'),
  92. },
  93. 'refkeyaddrgen_compressed_2': {
  94. 'btc': ('6D6D 3D35 04FD B9C3','94BF 4BCF 10B2 394B'),
  95. 'ltc': ('F5DA 9D60 6798 C4E9','7918 88DE 9096 DD7A'),
  96. },
  97. 'refkeyaddrgen_segwit_2': {
  98. 'btc': ('C98B DF08 A3D5 204B','7E7F DF50 FE04 6F68'),
  99. 'ltc': ('1829 7FE7 2567 CB91','BE92 D19C 7589 EF30'),
  100. },
  101. 'refkeyaddrgen_bech32_2': {
  102. 'btc': ('4A6B 3762 DF30 9368','12DD 1888 36BA 85F7'),
  103. 'ltc': ('5C12 FDD4 17AB F179','E195 B28C 59C4 C5EC'),
  104. },
  105. 'refpasswdgen_2': 'ADEA 0083 094D 489A',
  106. 'ref_b32passwdgen_2': '2A28 C5C7 36EC 217A',
  107. 'ref_hexpasswdgen_2': 'B11C AC6A 1464 608D',
  108. 'refaddrgen_legacy_3': {
  109. 'btc': ('6FEF 6FB9 7B13 5D91','424E 4326 CFFE 5F51'),
  110. 'ltc': ('AD52 C3FE 8924 AAF0','4EBE 2E85 E969 1B30'),
  111. },
  112. 'refaddrgen_compressed_3': {
  113. 'btc': ('A33C 4FDE F515 F5BC','6C48 AA57 2056 C8C8'),
  114. 'ltc': ('3FC0 8F03 C2D6 BD19','4C0A 49B6 2DD1 1BE0'),
  115. },
  116. 'refaddrgen_segwit_3': {
  117. 'btc': ('06C1 9C87 F25C 4EE6','072C 8B07 2730 CB7A'),
  118. 'ltc': ('63DF E42A 0827 21C3','5DD1 D186 DBE1 59F2'),
  119. },
  120. 'refaddrgen_bech32_3': {
  121. 'btc': ('9D2A D4B6 5117 F02E','0527 9C39 6C1B E39A'),
  122. 'ltc': ('FF1C 7939 5967 AB82','ED3D 8AA4 BED4 0B40'),
  123. },
  124. 'refkeyaddrgen_legacy_3': {
  125. 'btc': ('9F2D D781 1812 8BAD','88CC 5120 9A91 22C2'),
  126. 'ltc': ('B804 978A 8796 3ED4','98B5 AC35 F334 0398'),
  127. },
  128. 'refkeyaddrgen_compressed_3': {
  129. 'btc': ('420A 8EB5 A9E2 7814','F43A CB4A 81F3 F735'),
  130. 'ltc': ('8D1C 781F EB7F 44BC','05F3 5C68 FD31 FCEF'),
  131. },
  132. 'refkeyaddrgen_segwit_3': {
  133. 'btc': ('A447 12C2 DD14 5A9B','C770 7391 C415 21F9'),
  134. 'ltc': ('E8A3 9F6E E164 A521','D3D5 BFDD F5D5 20BD'),
  135. },
  136. 'refkeyaddrgen_bech32_3': {
  137. 'btc': ('D0DD BDE3 87BE 15AE','7552 D70C AAB8 DEAA'),
  138. 'ltc': ('74A0 7DD5 963B 6326','2CDA A007 4B9F E9A5'),
  139. },
  140. 'refpasswdgen_3': '2D6D 8FBA 422E 1315',
  141. 'ref_b32passwdgen_3': 'F6C1 CDFB 97D9 FCAE',
  142. 'ref_hexpasswdgen_3': 'BD4F A0AC 8628 4BE4',
  143. }
  144. cmd_group = (
  145. # reading
  146. ('ref_wallet_chk', ([],'saved reference wallet')),
  147. ('ref_seed_chk', ([],'saved seed file')),
  148. ('ref_hex_chk', ([],'saved mmhex file')),
  149. ('ref_mn_chk', ([],'saved mnemonic file')),
  150. ('ref_hincog_chk', ([],'saved hidden incog reference wallet')),
  151. ('ref_brain_chk', ([],'saved brainwallet')), # in ts_shared
  152. # generating new reference ('abc' brainwallet) files:
  153. ('refwalletgen', ([],'gen new refwallet')),
  154. ('refaddrgen_legacy', (['mmdat',pwfile],'new refwallet addr chksum (uncompressed)')),
  155. ('refaddrgen_compressed', (['mmdat',pwfile],'new refwallet addr chksum (compressed)')),
  156. ('refaddrgen_segwit', (['mmdat',pwfile],'new refwallet addr chksum (segwit)')),
  157. ('refaddrgen_bech32', (['mmdat',pwfile],'new refwallet addr chksum (bech32)')),
  158. ('refkeyaddrgen_legacy', (['mmdat',pwfile],'new refwallet key-addr chksum (uncompressed)')),
  159. ('refkeyaddrgen_compressed', (['mmdat',pwfile],'new refwallet key-addr chksum (compressed)')),
  160. ('refkeyaddrgen_segwit', (['mmdat',pwfile],'new refwallet key-addr chksum (segwit)')),
  161. ('refkeyaddrgen_bech32', (['mmdat',pwfile],'new refwallet key-addr chksum (bech32)')),
  162. ('refpasswdgen', (['mmdat',pwfile],'new refwallet passwd file chksum')),
  163. ('ref_b32passwdgen',(['mmdat',pwfile],'new refwallet passwd file chksum (base32)')),
  164. ('ref_hexpasswdgen',(['mmdat',pwfile],'new refwallet passwd file chksum (base32)')),
  165. )
  166. def __init__(self,trunner,cfgs,spawn):
  167. for k,j in self.cmd_group:
  168. for n in (1,2,3): # 128,192,256 bits
  169. setattr(self,'{}_{}'.format(k,n),getattr(self,k))
  170. if cfgs:
  171. for n in self.tmpdir_nums:
  172. cfgs[str(n)]['addr_idx_list'] = self.addr_idx_list_in
  173. cfgs[str(n)]['pass_idx_list'] = self.pass_idx_list_in
  174. return TestSuiteBase.__init__(self,trunner,cfgs,spawn)
  175. def ref_wallet_chk(self):
  176. wf = joinpath(ref_dir,TestSuiteWalletConv.sources[str(self.seed_len)]['ref_wallet'])
  177. return self.walletchk(wf,pf=None,pw=True,sid=self.seed_id)
  178. def ref_ss_chk(self,ss=None):
  179. wf = joinpath(ref_dir,'{}.{}'.format(self.seed_id,ss.ext))
  180. return self.walletchk(wf,pf=None,desc=ss.desc,sid=self.seed_id)
  181. def ref_seed_chk(self):
  182. from mmgen.seed import SeedFile
  183. return self.ref_ss_chk(ss=SeedFile)
  184. def ref_hex_chk(self):
  185. from mmgen.seed import HexSeedFile
  186. return self.ref_ss_chk(ss=HexSeedFile)
  187. def ref_mn_chk(self):
  188. from mmgen.seed import Mnemonic
  189. return self.ref_ss_chk(ss=Mnemonic)
  190. def ref_hincog_chk(self,desc='hidden incognito data'):
  191. source = TestSuiteWalletConv.sources[str(self.seed_len)]
  192. for wtype,edesc,of_arg in ('hic_wallet','',[]), \
  193. ('hic_wallet_old','(old format)',['-O']):
  194. ic_arg = ['-H{},{}'.format(joinpath(ref_dir,source[wtype]),ref_wallet_incog_offset)]
  195. slarg = ['-l{} '.format(self.seed_len)]
  196. hparg = ['-p1']
  197. if wtype == 'hic_wallet_old' and opt.profile: msg('')
  198. t = self.spawn('mmgen-walletchk',
  199. slarg + hparg + of_arg + ic_arg,
  200. extra_desc=edesc)
  201. t.passphrase(desc,self.wpasswd)
  202. if wtype == 'hic_wallet_old':
  203. t.expect('Is the Seed ID correct? (Y/n): ','\n')
  204. chk = t.expect_getend('Seed ID: ')
  205. t.close()
  206. cmp_or_die(self.seed_id,chk)
  207. ok_msg()
  208. t.skip_ok = True
  209. return t
  210. def brainwalletgen_ref(self):
  211. sl_arg = '-l{}'.format(self.seed_len)
  212. hp_arg = '-p{}'.format(ref_wallet_hash_preset)
  213. label = "test.py ref. wallet (pw '{}', seed len {}) α".format(ref_wallet_brainpass,self.seed_len)
  214. bf = 'ref.mmbrain'
  215. args = ['-d',self.tmpdir,hp_arg,sl_arg,'-ib','-L',label]
  216. self.write_to_tmpfile(bf,ref_wallet_brainpass)
  217. self.write_to_tmpfile(pwfile,self.wpasswd)
  218. t = self.spawn('mmgen-walletconv', args + [self.usr_rand_arg])
  219. t.license()
  220. t.expect('Enter brainwallet: ', ref_wallet_brainpass+'\n')
  221. t.passphrase_new('new MMGen wallet',self.wpasswd)
  222. t.usr_rand(self.usr_rand_chars)
  223. sid = os.path.basename(t.written_to_file('MMGen wallet')).split('-')[0]
  224. cmp_or_die(sid,self.seed_id,desc='Seed ID')
  225. return t
  226. def refwalletgen(self):
  227. return self.brainwalletgen_ref()
  228. def refaddrgen_legacy(self,wf,pf):
  229. return self.addrgen(wf,pf=pf,check_ref=True,mmtype='legacy')
  230. def refaddrgen_compressed(self,wf,pf):
  231. return self.addrgen(wf,pf=pf,check_ref=True,mmtype='compressed')
  232. def refaddrgen_segwit(self,wf,pf):
  233. return self.addrgen(wf,pf=pf,check_ref=True,mmtype='segwit')
  234. def refaddrgen_bech32(self,wf,pf):
  235. return self.addrgen(wf,pf=pf,check_ref=True,mmtype='bech32')
  236. def refkeyaddrgen_legacy(self,wf,pf,mmtype='legacy'):
  237. return self.keyaddrgen(wf,pf,check_ref=True)
  238. def refkeyaddrgen_compressed(self,wf,pf):
  239. return self.keyaddrgen(wf,pf=pf,check_ref=True,mmtype='compressed')
  240. def refkeyaddrgen_segwit(self,wf,pf):
  241. return self.keyaddrgen(wf,pf=pf,check_ref=True,mmtype='segwit')
  242. def refkeyaddrgen_bech32(self,wf,pf):
  243. return self.keyaddrgen(wf,pf=pf,check_ref=True,mmtype='bech32')
  244. def refpasswdgen(self,wf,pf):
  245. return self.addrgen(wf,pf,check_ref=True,ftype='pass',id_str='alice@crypto.org')
  246. def ref_b32passwdgen(self,wf,pf):
  247. ea = ['--base32','--passwd-len','17']
  248. return self.addrgen(wf,pf,check_ref=True,ftype='pass32',id_str='фубар@crypto.org',extra_args=ea)
  249. def ref_hexpasswdgen(self,wf,pf):
  250. ea = ['--hex']
  251. return self.addrgen(wf,pf,check_ref=True,ftype='passhex',id_str='фубар@crypto.org',extra_args=ea)