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