Last active
October 13, 2021 15:43
-
-
Save jasonpaulos/47166d44c13e4efb18c7a1a09f4ac969 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// test compatibility with ethereum signatures | |
t.Run("eth_compatibility", func(t *testing.T) { | |
/* | |
pip install eth-keys pycryptodome | |
from eth_keys import keys | |
pk = keys.PrivateKey(b"\xb2\\}\xb3\x1f\xee\xd9\x12''\xbf\t9\xdcv\x9a\x96VK-\xe4\xc4rm\x03[6\xec\xf1\xe5\xb3d") | |
msg=b"hello from ethereum" | |
print("msg: '{}'".format(msg.decode())) | |
signature = pk.sign_msg(msg) | |
print("v:", signature.v) | |
print("r:", signature.r.to_bytes(32, byteorder="big").hex()) | |
print("s:", signature.s.to_bytes(32, byteorder="big").hex()) | |
print("addr:", pk.public_key.to_address()) | |
*/ | |
progText := `byte "hello from ethereum" // msg | |
keccak256 | |
int 0 // v | |
byte 0x745e8f55ac6189ee89ed707c36694868e3903988fbf776c8096c45da2e60c638 // r | |
byte 0x30c8e4a9b5d2eb53ddc6294587dd00bed8afe2c45dd72f6b4cf752e46d5ba681 // s | |
ecdsa_pk_recover Secp256k1 | |
concat // convert public key X and Y to ethereum addr | |
keccak256 | |
substring 12 32 | |
byte 0x5ce9454909639d2d17a3f753ce7d93fa0b9ab12e // addr | |
== | |
` | |
testAccepts(t, progText, 5) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment