-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverify.py
42 lines (28 loc) · 1.02 KB
/
verify.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
37
38
39
40
41
from web3 import Web3
from eth_account.messages import encode_defunct
import random
def signChallenge( challenge ):
w3 = Web3()
#This is the only line you need to modify
sk = "0x5d7d0513d25b385d466ea87ebe0b7c2f69b2300bc32dfe70742db5137f104af9"
acct = w3.eth.account.from_key(sk)
signed_message = w3.eth.account.sign_message( challenge, private_key = acct._private_key )
return acct.address, signed_message.signature
def verifySig():
"""
This is essentially the code that the autograder will use to test signChallenge
We've added it here for testing
"""
challenge_bytes = random.randbytes(32)
challenge = encode_defunct(challenge_bytes)
address, sig = signChallenge( challenge )
w3 = Web3()
return w3.eth.account.recover_message( challenge , signature=sig ) == address
if __name__ == '__main__':
"""
Test your function
"""
if verifySig():
print( f"You passed the challenge!" )
else:
print( f"You failed the challenge!" )