def test_save_and_load_from_seedhex_file(self):
        sign_key_save = SigningKey.from_credentials("alice", "password",
                                                    ScryptParams())
        sign_key_save.save_seedhex_file(TEST_FILE_PATH)

        sign_key_load = SigningKey.from_seedhex_file(TEST_FILE_PATH)
        self.assertEqual(sign_key_save.sk, sign_key_load.sk)
示例#2
0
def auth_by_auth_file(ctx):
    """
    Uses an authentication file to generate the key
    Authfile can either be:
    * A seed in hexadecimal encoding
    * PubSec format with public and private key in base58 encoding
    """
    file = ctx.obj["AUTH_FILE_PATH"]
    authfile = Path(file)
    if not authfile.is_file():
        message_exit('Error: the file "' + file + '" does not exist')
    filetxt = authfile.open("r").read()

    # two regural expressions for the PubSec format
    regex_pubkey = re.compile(PUBSEC_PUBKEY_PATTERN, re.MULTILINE)
    regex_signkey = re.compile(PUBSEC_SIGNKEY_PATTERN, re.MULTILINE)

    # Seed hexadecimal format
    if re.search(re.compile(SEED_HEX_PATTERN), filetxt):
        return SigningKey.from_seedhex_file(file)
    # PubSec format
    elif re.search(regex_pubkey, filetxt) and re.search(
            regex_signkey, filetxt):
        return SigningKey.from_pubsec_file(file)
    else:
        message_exit("Error: the format of the file is invalid")
    def test_save_and_load_from_seedhex_file(self):
        sign_key_save = SigningKey.from_credentials("alice", "password", ScryptParams())
        sign_key_save.save_seedhex_file(TEST_FILE_PATH)

        sign_key_load = SigningKey.from_seedhex_file(TEST_FILE_PATH)
        self.assertEqual(sign_key_save.sk, sign_key_load.sk)