@@ -13,47 +13,48 @@ Payment key is usually used to sign transactions that involve funds transfers, w
13
13
is usually used to sign transactions that involve staking-related activities, e.g. stake address registration,
14
14
delegation. PyCardano provides APIs to create, save, and loads payment keys and stake keys.
15
15
16
- New payment keys and stake keys could be generated using class method `generate() `. Their corresponding
17
- verification (public) key could be created using class method `from_signing_key() `::
16
+ New payment keys and stake keys could be generated using class method
17
+ `generate <../api/pycardano.key.html#pycardano.key.SigningKey.generate >`_. Their corresponding
18
+ verification (public) key could be created using class method
19
+ `from_signing_key <../api/pycardano.key.html#pycardano.key.VerificationKey.from_signing_key >`_::
18
20
19
- from pycardano import PaymentSigningKey, StakeSigningKey, PaymentVerificationKey, StakeVerificationKey
21
+ >>> from pycardano import PaymentSigningKey, StakeSigningKey, PaymentVerificationKey, StakeVerificationKey
22
+
23
+ >>> payment_signing_key = PaymentSigningKey.generate()
24
+ >>> payment_verification_key = PaymentVerificationKey.from_signing_key(payment_signing_key)
20
25
21
- payment_signing_key = PaymentSigningKey.generate()
22
- payment_verification_key = PaymentVerificationKey.from_signing_key(payment_signing_key)
23
-
24
-
25
- stake_signing_key = StakeSigningKey.generate()
26
- stake_verification_key = StakeVerificationKey.from_signing_key(stake_signing_key)
26
+ >>> stake_signing_key = StakeSigningKey.generate()
27
+ >>> stake_verification_key = StakeVerificationKey.from_signing_key(stake_signing_key)
27
28
28
29
29
30
Alternatively, a key pair (signing key + verification key) could be generated together::
30
31
31
- from pycardano import PaymentKeyPair, StakeKeyPair
32
+ >>> from pycardano import PaymentKeyPair, StakeKeyPair
32
33
33
- payment_key_pair = PaymentKeyPair.generate()
34
- payment_signing_key = payment_key_pair.signing_key
35
- payment_verification_key = payment_key_pair.verification_key
34
+ >>> payment_key_pair = PaymentKeyPair.generate()
35
+ >>> payment_signing_key = payment_key_pair.signing_key
36
+ >>> payment_verification_key = payment_key_pair.verification_key
36
37
37
- stake_key_pair = StakeKeyPair.generate()
38
- stake_signing_key = stake_key_pair.signing_key
39
- stake_verification_key = stake_key_pair.verification_key
38
+ >>> stake_key_pair = StakeKeyPair.generate()
39
+ >>> stake_signing_key = stake_key_pair.signing_key
40
+ >>> stake_verification_key = stake_key_pair.verification_key
40
41
41
42
42
43
A key could be saved to and loaded from a file::
43
44
44
- # Save
45
- payment_signing_key.save("payment.skey")
46
- payment_verification_key.save("payment.vkey")
45
+ >>> # Save
46
+ >>> payment_signing_key.save("payment.skey")
47
+ >>> payment_verification_key.save("payment.vkey")
47
48
48
- # Load
49
- payment_signing_key = payment_signing_key.load("payment.skey")
50
- payment_verification_key = payment_verification_key.load("payment.vkey")
49
+ >>> # Load
50
+ >>> payment_signing_key = payment_signing_key.load("payment.skey")
51
+ >>> payment_verification_key = payment_verification_key.load("payment.vkey")
51
52
52
53
Signing keys can sign messages (in bytes)::
53
54
54
- message = b"Hello world!"
55
- print( payment_signing_key.signing_key.sign(b"Hello world!") )
56
- # b'\xf1N\x96\x05\xe8[\xa3"g5\x95\x80\xca\x88\x93&\xefD\xc3\x9fXj{\xaf\x01mna\xa92+z\x08\x9d\x1eG\x9fN\xc2\xb8\xb1\xab\xbf\xee\xf7\xa6\x08\x87\xfa\xeb\x9bGW\xba\xb7\xd8\xb2\xbb\xe0\x9c"\x0b\xe0\x07'
55
+ >>> message = b"Hello world!"
56
+ >>> payment_signing_key.signing_key.sign(b"Hello world!")
57
+ b'\xf1N\x96\x05\xe8[\xa3"g5\x95\x80\xca\x88\x93&\xefD\xc3\x9fXj{\xaf\x01mna\xa92+z\x08\x9d\x1eG\x9fN\xc2\xb8\xb1\xab\xbf\xee\xf7\xa6\x08\x87\xfa\xeb\x9bGW\xba\xb7\xd8\xb2\xbb\xe0\x9c"\x0b\xe0\x07'
57
58
58
59
This guide only covers address keys. There is another category of keys called "Node keys".
59
60
You can learn more about keys `here <https://docs.cardano.org/core-concepts/cardano-keys >`_.
@@ -72,28 +73,28 @@ when creating an address.
72
73
Base address is the most commonly used address type. It is generated from a payment verification key and
73
74
a stake verification key::
74
75
75
- from pycardano import Address, Network
76
+ >>> from pycardano import Address, Network
76
77
77
- base_address = Address(payment_part=payment_verification_key.hash(),
78
- staking_part=stake_verification_key.hash(),
79
- network=Network.TESTNET)
78
+ >>> base_address = Address(payment_part=payment_verification_key.hash(),
79
+ ... staking_part=stake_verification_key.hash(),
80
+ ... network=Network.TESTNET)
80
81
81
- print( base_address)
82
- # addr_test1vr2p8st5t5cxqglyjky7vk98k7jtfhdpvhl4e97cezuhn0cqcexl7
82
+ >>> base_address
83
+ " addr_test1vr2p8st5t5cxqglyjky7vk98k7jtfhdpvhl4e97cezuhn0cqcexl7"
83
84
84
85
An address object could also be created from an address string directly::
85
86
86
- address = Address.from_primitive("addr_test1vr2p8st5t5cxqglyjky7vk98k7jtfhdpvhl4e97cezuhn0cqcexl7")
87
+ >>> address = Address.from_primitive("addr_test1vr2p8st5t5cxqglyjky7vk98k7jtfhdpvhl4e97cezuhn0cqcexl7")
87
88
88
89
89
90
An enterprise address does not have staking functionalities, it is created from a payment verification key only::
90
91
91
- enterprise_address = Address(payment_part=payment_verification_key.hash(),
92
- network=Network.TESTNET)
92
+ >>> enterprise_address = Address(payment_part=payment_verification_key.hash(),
93
+ ... network=Network.TESTNET)
93
94
94
95
95
96
A stake address does not have payment functionalities, it is created from a stake verification key only::
96
97
97
- stake_address = Address(staking_part=payment_verification_key.hash(),
98
- network=Network.TESTNET)
98
+ >>> stake_address = Address(staking_part=payment_verification_key.hash(),
99
+ ... network=Network.TESTNET)
99
100
0 commit comments