Example #1
0
 def test_7_24bit_7f(self):
     bip39 = BIP39()
     ent = unhexlify(data[6][0])
     mnemonics = bip39.bip39(24, ent)
     # check seed generation
     self.assertEqual(f'{bip39.generate_rootseed(mnemonics, salt).hex()}',
                      data[6][2])
Example #2
0
 def test_11_32bit_80(self):
     bip39 = BIP39()
     ent = unhexlify(data[10][0])
     mnemonics = bip39.bip39(32, ent)
     # check seed generation
     self.assertEqual(f'{bip39.generate_rootseed(mnemonics, salt).hex()}',
                      data[10][2])
Example #3
0
 def test_24_misc(self):
     bip39 = BIP39()
     size = len(data[23][0]) // 2
     ent = unhexlify(data[23][0])
     mnemonics = bip39.bip39(size, ent)
     # check seed generation
     self.assertEqual(f'{bip39.generate_rootseed(mnemonics, salt).hex()}',
                      data[23][2])
Example #4
0
	def __init__(self, seed, fromseed=False, salt=''):
		# Generate BIP 32 master keys
		if fromseed:
			# constructing from BIP39 seed
			self.rootseed = unhexlify(seed)
		else:
			# constructing from an ascii BIP39 mnemonic phrase
			self.rootseed = BIP39().generate_rootseed(seed, salt)
		self.rootnode = self.generate_rootkey(self.rootseed)
		self.master_prv, self.master_chain = self.split_rootkey(self.rootnode)
		self.endianness = 'big'
Example #5
0
def recover():
	data = request.data.decode('UTF-8')
	data = loads(data)
	try:
		bip39 = BIP39()
		seed = bip39.generate_rootseed(data['mnemonics'], data['salt'])
		# FIXME: fix decoding error
		# extract address type
		addr = data["addr"]
		# generate a BIP32 wallet
		prv, pub = gen_keys(seed, addr)
		return dumps({"seed": seed.hex(), "m_xprv": prv, "m_xpub": pub})
	except Exception as error:
		print(f'Could not decode data.\nERROR: {error}')
		return dumps({"seed": "null"})
Example #6
0
def generate():
	data = request.data.decode('UTF-8')
	data = loads(data)
	try:
		bip39 = BIP39()
		# generate mnemonic passphrase
		mnemonics = bip39.bip39(data['bytes'])
		# extract address type
		addr = data['addr']
		# generate BIP32 root seed
		seed = bip39.generate_rootseed(mnemonics, data['passphrase'])
		prv, pub = gen_keys(seed, addr)
		if (prv, pub) == (None, None):
			return dumps({"phrase": "failed"})
		return dumps({"phrase": mnemonics, "seed": seed.hex(), "m_xprv": prv, "m_xpub": pub})
	except Exception as error:
		print(f'Could not generate: ERROR {error}')
		return dumps({"phrase": "failed"})
Example #7
0
	def test_17_misc(self):
		size = len(data[16][0])//2
		ent = unhexlify(data[16][0])
		mnemonics = BIP39().bip39(size, ent)
		self.assertEqual(mnemonics, data[16][1])
Example #8
0
	def test_12_32bit_ff(self):
		ent = unhexlify(data[11][0])
		mnemonics = BIP39().bip39(32, ent)
		self.assertEqual(mnemonics, data[11][1])
Example #9
0
	def test_8_24bit_ff(self):
		ent = unhexlify(data[7][0])
		mnemonics = BIP39().bip39(24, ent)
		self.assertEqual(mnemonics, data[7][1])
Example #10
0
	def test_4_16bit_ff(self):
		ent = unhexlify(data[3][0])
		mnemonics = BIP39().bip39(16, ent)
		self.assertEqual(mnemonics, data[3][1])
Example #11
0
	def test_1_16bit_00(self):
		ent = unhexlify(data[0][0])
		mnemonics = BIP39().bip39(16, ent)
		# check mnemonic generation
		self.assertEqual(mnemonics, data[0][1])