Beispiel #1
0
	def test_loadAccount_badPin(self):
		use("dark")

		pin = "abc123"
		address = "DUGvQBxLzQqrNy68asPcU3stWQyzVq8G49".encode()
		privateKey = "123123123"
		base = createBase(pin)

		dumpAccount(base, address, privateKey)

		badPin = "xyz123"
		badBase = createBase(badPin)

		with self.assertRaises(BadPinError) as context:
			loadAccount(badBase)
Beispiel #2
0
def save(param):
	if DATA.account:
		dumpAccount(
			createBase(hidenInput("Enter pin code: ")),
			DATA.account["address"],
			DATA.firstkeys["privateKey"],
			DATA.secondkeys.get("privateKey", None),
			param["<name>"]
		)
Beispiel #3
0
def loadBip39(pin, name="unamed"):
    """
	Decrypt your saved passphrase located in ~/.bip39/<network-name>.

	Argument:
	pin -- a str containing pin code (no limit in digit number) or a password

	Keyword argument:
	name -- the filname you want decrypt
	"""

    filename = os.path.join(HOME, ".bip39", cfg.network, name + ".bip39")
    if os.path.exists(filename):
        with io.open(filename, "rb") as in_:
            tmp = data.unScramble(data.createBase(pin), in_.read())
        return util.unhexlify(tmp).decode("utf-8")
Beispiel #4
0
	def test_scramble_and_unscramble(self):
		# set test data
		pin = "abc123"
		address = "DUGvQBxLzQqrNy68asPcU3stWQyzVq8G49".encode()
		scrambled_result = (
			b"\x06\x06\x0b\x0b\x06\x0f\x0f\r\x0b\x03\x06\x07\x0f\x04\x06\x05\x0f\x02\x0b\x03\x0f"
			b"\x03\x0f\x07\x06\x00\x0f\x01\t\r\t\x04\r\x03\x0f\t\x0b\x0e\r\t\x0b\x0b\t\t\x0f\t"
			b"\x0f\x06\x0b\x0f\x0b\x03\x0f\x01\x0f\x02\x0b\r\x0f\x03\t\x04\x06\x0f\t\x06\t\x01"
		)

		# run test
		base = createBase(pin)
		hexa = hexlify(address)
		scrambled = scramble(base, hexa)
		assert scrambled == scrambled_result

		unscrambled = unScramble(base, scrambled)
		assert hexa == unscrambled
Beispiel #5
0
	def test_dumpAccount_findAccounts_loadAccount(self):
		use("dark")

		pin = "abc123"
		address = "DUGvQBxLzQqrNy68asPcU3stWQyzVq8G49".encode()
		privateKey = "123123123"
		base = createBase(pin)

		orig_accounts = findAccounts()
		orig_accounts.append("unamed")

		dumpAccount(base, address, privateKey)

		accounts = findAccounts()
		assert set(accounts) == set(orig_accounts)

		output = loadAccount(base)
		assert output["address"] == address
		assert output["privateKey"] == privateKey
Beispiel #6
0
def dumpBip39(pin, bip39, name="unamed"):
    """
	Encrypt your passphrase using a pin code and save it on the disk.
	Dumped file are located in ~/.bip39/<network-name>.

	Argument:
	pin -- a str containing pin code (no limit in digit number) or a password
	bip39 -- a str containing passphrase

	Keyword argument:
	name -- the name you want to give
	"""

    bip39 = bip39 if isinstance(bip39, bytes) else bip39.encode("utf-8")
    folder = os.path.join(HOME, ".bip39", cfg.network)
    if not os.path.exists(folder):
        os.makedirs(folder)
    with io.open(os.path.join(folder, name + ".bip39"), "wb") as out:
        out.write(data.scramble(data.createBase(pin), util.hexlify(bip39)))
Beispiel #7
0
def _linkFromSavedAccounts(param):
	choices = findAccounts()
	if not choices:
		sys.stdout.write("    No registered account found...\n")
		return None
	name = chooseItem("Account(s) found:", *choices)
	if not name:
		return None
	try:
		data = loadAccount(createBase(hidenInput("Enter pin code: ")), name)
	except:
		sys.stdout.write("    Bad pin code...\n")
		return None
	DATA.account = rest.GET.api.accounts(address=data["address"]).get("account", {})
	DATA.firstkeys = {
		"publicKey": DATA.account["publicKey"],
		"privateKey": data["privateKey"]
	}
	if "secondPrivateKey" in data:
		DATA.secondkeys = {
			"publicKey": DATA.account["secondPublicKey"],
			"privateKey": data["secondPrivateKey"]
		}
	return data["address"]
Beispiel #8
0
	def test_createBase(self):
		pins = [str('abc123'), b'abc123', u'abc123']
		for pin in pins:
			output = createBase(pin)
			assert output == 'e9a18c42b3d5f607'