mirror of https://github.com/status-im/nim-eth.git
Add equals operator for keys
This commit is contained in:
parent
9d7fc76c7a
commit
6ef16785ce
|
@ -292,6 +292,9 @@ proc getRaw*(pubkey: PublicKey): array[RawPublicKeySize, byte] {.noinit, inline.
|
|||
## Converts public key `pubkey` to serialized form.
|
||||
pubkey.toRaw(result)
|
||||
|
||||
proc `==`*(lhs, rhs: PublicKey): bool =
|
||||
lhs.getRaw == rhs.getRaw
|
||||
|
||||
proc getRawCompressed*(pubkey: PublicKey): array[CompressedPubKeyLength, byte] {.noinit, inline.} =
|
||||
## Converts public key `pubkey` to serialized form.
|
||||
pubkey.toRaw(result, true)
|
||||
|
|
|
@ -15,8 +15,13 @@ import unittest
|
|||
suite "Testing private -> public key conversion":
|
||||
test "Known private to known public keys (test data from Ethereum eth-keys)":
|
||||
for person in [alice, bob, eve]:
|
||||
let privkey = initPrivateKey(person.privkey)
|
||||
let
|
||||
privKey = initPrivateKey(person.privkey)
|
||||
pubKey = privKey.getPublicKey
|
||||
|
||||
let computed_pubkey = $privkey.public_key
|
||||
check:
|
||||
# Compare as strings
|
||||
$pubKey == person.pubkey
|
||||
|
||||
check: computed_pubkey == person.pubkey
|
||||
# Compare as keys
|
||||
pubKey == initPublicKey(person.pubkey)
|
||||
|
|
Loading…
Reference in New Issue