|
1 | 1 | from pycardano.cip.cip8 import sign, verify
|
2 |
| -from pycardano.key import PaymentSigningKey, PaymentVerificationKey |
| 2 | +from pycardano.key import PaymentSigningKey, PaymentVerificationKey, StakeSigningKey, StakeVerificationKey |
3 | 3 | from pycardano.network import Network
|
4 | 4 |
|
5 | 5 | SK = PaymentSigningKey.from_json(
|
|
18 | 18 | }"""
|
19 | 19 | )
|
20 | 20 |
|
| 21 | +STAKE_SK = StakeSigningKey.from_json( |
| 22 | + """{ |
| 23 | + "type": "StakeSigningKeyShelley_ed25519", |
| 24 | + "description": "Stake Signing Key", |
| 25 | + "cborHex": "5820ff3a330df8859e4e5f42a97fcaee73f6a00d0cf864f4bca902bd106d423f02c0" |
| 26 | + }""" |
| 27 | +) |
| 28 | + |
| 29 | +STAKE_VK = StakeVerificationKey.from_json( |
| 30 | + """{ |
| 31 | + "type": "StakeVerificationKeyShelley_ed25519", |
| 32 | + "description": "Stake Verification Key", |
| 33 | + "cborHex": "58205edaa384c658c2bd8945ae389edac0a5bd452d0cfd5d1245e3ecd540030d1e3c" |
| 34 | + }""" |
| 35 | +) |
| 36 | + |
21 | 37 |
|
22 | 38 | def test_verify_message():
|
23 | 39 |
|
@@ -75,6 +91,18 @@ def test_sign_message():
|
75 | 91 | )
|
76 | 92 |
|
77 | 93 |
|
| 94 | +def test_sign_message_with_stake(): |
| 95 | + |
| 96 | + message = "Pycardano is cool." |
| 97 | + signed_message = sign( |
| 98 | + message, signing_key=STAKE_SK, attach_cose_key=False, network=Network.TESTNET |
| 99 | + ) |
| 100 | + assert ( |
| 101 | + signed_message |
| 102 | + == "84584da301276761646472657373581de04828a2dadba97ca9fd0cdc99975899470c219bdc0d828cfa6ddf6d690458205edaa384c658c2bd8945ae389edac0a5bd452d0cfd5d1245e3ecd540030d1e3ca166686173686564f452507963617264616e6f20697320636f6f6c2e5840ba1dd643f0d2e844f0509b1a7161ae4a3650f1d553fcc6e517020c5703acb70dfeea1014f2a1513baefaa2279cb151e8ff2dada6b51269cf33127d3c05829502" |
| 103 | + ) |
| 104 | + |
| 105 | + |
78 | 106 | def test_sign_message_cosy_key_separate():
|
79 | 107 |
|
80 | 108 | message = "Pycardano is cool."
|
@@ -109,3 +137,29 @@ def test_sign_and_verify():
|
109 | 137 | assert verification["verified"]
|
110 | 138 | assert verification["message"] == "Pycardano is cool."
|
111 | 139 | assert verification["signing_address"].payment_part == VK.hash()
|
| 140 | + |
| 141 | + |
| 142 | +def test_sign_and_verify_stake(): |
| 143 | + |
| 144 | + # try first with no cose key attached |
| 145 | + message = "Pycardano is cool." |
| 146 | + signed_message = sign( |
| 147 | + message, signing_key=STAKE_SK, attach_cose_key=False, network=Network.TESTNET |
| 148 | + ) |
| 149 | + |
| 150 | + verification = verify(signed_message) |
| 151 | + assert verification["verified"] |
| 152 | + assert verification["message"] == "Pycardano is cool." |
| 153 | + assert verification["signing_address"].payment_part == None |
| 154 | + assert verification["signing_address"].staking_part == STAKE_VK.hash() |
| 155 | + |
| 156 | + # try again but attach cose key |
| 157 | + signed_message = sign( |
| 158 | + message, signing_key=STAKE_SK, attach_cose_key=True, network=Network.TESTNET |
| 159 | + ) |
| 160 | + |
| 161 | + verification = verify(signed_message) |
| 162 | + assert verification["verified"] |
| 163 | + assert verification["message"] == "Pycardano is cool." |
| 164 | + assert verification["signing_address"].payment_part == None |
| 165 | + assert verification["signing_address"].staking_part == STAKE_VK.hash() |
0 commit comments