Skip to content

Commit 20c4511

Browse files
committed
Update keys.go
1 parent 234fbb8 commit 20c4511

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

keys.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,13 @@ func ValidatePrivateKey(b []byte) (bool, error) {
7373
return false, fmt.Errorf("invalid private key size, expected %v, got %d", voied25519.PrivateKeySize, len(b))
7474
}
7575

76-
// check if the public key is on the ed25519 curve
77-
pub := voied25519.PrivateKey(b).Public().(voied25519.PublicKey)
78-
if !IsOnCurve(pub) {
79-
return false, errors.New("the corresponding public key is NOT on the voied25519 curve")
76+
// ed25519 private keys are seed(32) + public(32); ensure they match.
77+
derived := voied25519.NewKeyFromSeed(b[:voied25519.SeedSize])
78+
if !bytes.Equal(derived, b) {
79+
if !IsOnCurve(b[voied25519.SeedSize:]) {
80+
return false, errors.New("invalid private key: seed/public key mismatch (provided public key is NOT on the ed25519 curve)")
81+
}
82+
return false, errors.New("invalid private key: seed/public key mismatch")
8083
}
8184
return true, nil
8285
}

0 commit comments

Comments
 (0)