mirror of
https://github.com/logos-storage/logos-storage-nim-validator.git
synced 2026-01-03 22:13:11 +00:00
replace constantine with blscurve and nimcrypto
reason: slow build times with constantine
This commit is contained in:
parent
d91a89ebeb
commit
19b82c93cb
@ -5,4 +5,6 @@ license = "MIT"
|
||||
|
||||
requires "https://github.com/codex-storage/nim-mysticeti >= 0.1.0 & < 0.2.0"
|
||||
requires "https://github.com/codex-storage/nim-stint-versioned.git >= 1.0.0 & < 2.0.0"
|
||||
requires "https://github.com/mratsim/constantine#bc3845aa492b52f7fef047503b1592e830d1a774"
|
||||
requires "blscurve#de2d3c79264bba18dbea469c8c5c4b3bb3c8bc55"
|
||||
requires "nimcrypto >= 0.6.2 & < 0.7.0"
|
||||
requires "stew#a6e198132097fb544d04959aeb3b839e1408f942"
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
import pkg/constantine/ethereum_bls_signatures
|
||||
import pkg/constantine/csprngs/sysrand
|
||||
import pkg/blscurve
|
||||
import pkg/nimcrypto
|
||||
|
||||
export Signature
|
||||
export blscurve.Signature
|
||||
export blscurve.sign
|
||||
export blscurve.verify
|
||||
|
||||
type
|
||||
Identity* = SecretKey
|
||||
@ -11,21 +13,9 @@ proc random*(_: type Identity, identity: var Identity) =
|
||||
var randomness: array[32, byte]
|
||||
var done = false
|
||||
while not done:
|
||||
doAssert sysrand(randomness)
|
||||
done = deserialize_seckey(identity, randomness) == cttCodecScalar_Success
|
||||
setZero(randomness)
|
||||
doAssert randomBytes(randomness) == randomness.len
|
||||
done = fromBytes(identity, randomness)
|
||||
burnMem(randomness)
|
||||
|
||||
func identifier*(identity: Identity): Identifier =
|
||||
derive_pubkey(result, identity)
|
||||
|
||||
func sign*(identity: Identity, message: openArray[byte]): Signature =
|
||||
sign(result, identity, message)
|
||||
|
||||
func verify*(signature: Signature, identifier: Identifier, message: openArray[byte]): bool =
|
||||
verify(identifier, message, signature) == cttEthBls_Success
|
||||
|
||||
func `==`*(a, b: Identifier): bool =
|
||||
pubkeys_are_equal(a, b)
|
||||
|
||||
func `==`*(a, b: Signature): bool =
|
||||
signatures_are_equal(a, b)
|
||||
doAssert publicFromSecret(result, identity)
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
import std/unittest
|
||||
import pkg/constantine/ethereum_bls_signatures
|
||||
import pkg/blscurve
|
||||
import codexvalidator/signatures
|
||||
import ./examples
|
||||
|
||||
suite "Signature scheme":
|
||||
|
||||
test "uses BLS private key as validator identity":
|
||||
check signatures.Identity is ethereum_bls_signatures.SecretKey
|
||||
check signatures.Identity is blscurve.SecretKey
|
||||
|
||||
test "uses BLS public key as validator identifier":
|
||||
check signatures.Identifier is ethereum_bls_signatures.PublicKey
|
||||
check signatures.Identifier is blscurve.PublicKey
|
||||
|
||||
test "uses BLS signatures":
|
||||
check signatures.Signature is ethereum_bls_signatures.Signature
|
||||
check signatures.Signature is blscurve.Signature
|
||||
|
||||
test "can create a new random identity":
|
||||
var identity1, identity2: Identity
|
||||
@ -24,7 +24,7 @@ suite "Signature scheme":
|
||||
var identity: Identity
|
||||
Identity.random(identity)
|
||||
var publicKey: PublicKey
|
||||
derive_pubkey(publicKey, identity)
|
||||
check publicFromSecret(publicKey, identity)
|
||||
check identity.identifier == publicKey
|
||||
|
||||
test "identity can sign messages":
|
||||
@ -40,5 +40,5 @@ suite "Signature scheme":
|
||||
Identity.random(identity2)
|
||||
let message = seq[byte].example
|
||||
let signature = identity1.sign(message)
|
||||
check signature.verify(identity1.identifier, message)
|
||||
check not signature.verify(identity2.identifier, message)
|
||||
check identity1.identifier.verify(message, signature)
|
||||
check not identity2.identifier.verify(message, signature)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user