-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
36 lines (28 loc) · 988 Bytes
/
generate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# Generates a wallet address using pycardano.
#
import json
from pycardano import PaymentSigningKey, PaymentVerificationKey, Address, Network
# Generate a new payment signing key
psk = PaymentSigningKey.generate()
# Derive the corresponding payment verification key
pvk = PaymentVerificationKey.from_signing_key(psk)
# Derive the address
address = Address(pvk.hash(), network=Network.TESTNET)
# Create the JSON structure for the secret key
skey_data = {
"type": "PaymentSigningKeyShelley_ed25519",
"description": "Payment Signing Key",
"cborHex": psk.to_primitive().hex()
}
# Save the secret key to a file
with open("payment.skey", "w") as f:
json.dump(skey_data, f, indent=2)
# Save the generated address to a file
with open("payment.addr", "w") as f:
f.write(str(address))
# Print the generated address
print(f"Generated address: {address}")
# Print the secret key file path
print("Secret key saved to payment.skey")
print("Address saved to payment.addr")