Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_save_and_load_from_private_key_file(self):
sign_key_save = SigningKey.from_credentials("alice", "password", ScryptParams())
sign_key_save.save_private_key(TEST_FILE_PATH)
sign_key_load = SigningKey.from_private_key(TEST_FILE_PATH)
self.assertEqual(sign_key_save.sk, sign_key_load.sk)
def test_from_credentials(self):
sign_key = SigningKey.from_credentials("alice", "password", ScryptParams())
verify_key = VerifyingKey(sign_key.pubkey)
self.assertEqual(verify_key.vk, sign_key.vk)
"""
# Create Client from endpoint string in Duniter format
client = Client(BMAS_ENDPOINT)
# Get the node summary infos to test the connection
response = await client(bma.node.summary)
print(response)
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
# prompt hidden user entry
password = getpass.getpass("Enter your password: ")
# create key from credentials
key = SigningKey.from_credentials(salt, password)
pubkey_from = key.pubkey
# prompt entry
pubkey_to = input("Enter certified pubkey: ")
# capture current block to get version and currency and blockstamp
current_block = await client(bma.blockchain.current)
# create our Identity document to sign the Certification document
identity = await get_identity_document(client, current_block, pubkey_to)
if identity is None:
print("Identity not found for pubkey {0}".format(pubkey_to))
# Close client aiohttp session
await client.close()
sys.exit(1)
# you'll have to use one of your private keys instead
PRIVATE_KEYS_FILE_PATH = os.path.join(home_path, ".duniter_account_private_keys.txt")
################################################
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
# prompt hidden user entry
password = getpass.getpass("Enter your password: ")
# prompt public key
pubkey = input("Enter your public key: ")
# init signer instance
signer = SigningKey.from_credentials(salt, password)
# check public key
if signer.pubkey != pubkey:
print("Bad credentials!")
sys.exit(1)
# save private keys in a file (json format)
signer.save_private_key(PRIVATE_KEYS_FILE_PATH)
# document saved
print("Private keys for public key %s saved in %s" % (pubkey, PRIVATE_KEYS_FILE_PATH))
# load private keys from file
loaded_signer = SigningKey.from_private_key(PRIVATE_KEYS_FILE_PATH) # type: SigningKey
# check public key from file
# you'll have to use one of your private keys instead
PRIVATE_KEY_FILE_PATH = os.path.join(home_path, ".duniter_account_wif_v1.duniterkey")
################################################
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
# prompt hidden user entry
password = getpass.getpass("Enter your password: ")
# prompt public key
pubkey = input("Enter your public key: ")
# init signer instance
signer = SigningKey.from_credentials(salt, password)
# check public key
if signer.pubkey != pubkey:
print("Bad credentials!")
sys.exit(1)
# save private key in a file (WIF v1 format)
signer.save_wif_file(PRIVATE_KEY_FILE_PATH)
# document saved
print(
"Private key for public key %s saved in %s" % (signer.pubkey, PRIVATE_KEY_FILE_PATH)
)
try:
# load private keys from file
# CONFIG #######################################
CLEARTEXT_AA_MESSAGE_PATH = "/tmp/duniter_cleartext_aa_message.txt"
################################################
if __name__ == "__main__":
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
# prompt hidden user entry
password = getpass.getpass("Enter your password: ")
# init SigningKey instance
signing_key = SigningKey.from_credentials(salt, password)
# Enter the multi-line message (stop with Ctrl-D below last line to end)
print("Enter your message (Ctrl-D below last line to end):")
message = sys.stdin.read()
print("Message signed by puplic key : {pubkey}".format(pubkey=signing_key.pubkey))
comment = "generated by Duniterpy {0}".format(__version__)
# Dash escape the message and sign it
aa_cleartext_message = AsciiArmor.create(
message, None, [signing_key], None, signatures_comment=comment
)
# Save cleartext ascii armor message in a file
with open(CLEARTEXT_AA_MESSAGE_PATH, "w") as file_handler:
file_handler.write(aa_cleartext_message)
def get_signed_raw_revocation_document(
identity: Identity, salt: str, password: str
) -> str:
"""
Generate account revocation document for given identity
:param identity: Self Certification of the identity
:param salt: Salt
:param password: Password
:rtype: str
"""
revocation = Revocation(PROTOCOL_VERSION, identity.currency, identity, "")
key = SigningKey.from_credentials(salt, password)
revocation.sign([key])
return revocation.signed_raw()