Add equals operator for keys

This commit is contained in:
Zahary Karadjov 2020-02-19 11:11:45 +02:00
parent 9d7fc76c7a
commit 6ef16785ce
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
2 changed files with 11 additions and 3 deletions

View File

@ -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)

View File

@ -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)