Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proof of concept to checked for invalid private key on PrivateKeyFromBase58 #234

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pikomonde
Copy link
Contributor

@pikomonde pikomonde commented Jul 30, 2024

fix #232

@Almazatun
Copy link

Almazatun commented Jul 30, 2024

@pikomonde Why did you create a pull request with tests before that did not fix the issue ) ?

@pikomonde
Copy link
Contributor Author

It should still be on draft

@pikomonde pikomonde marked this pull request as draft July 30, 2024 18:06
@pikomonde pikomonde changed the title create unit test and docs for PrivateKeyFromBase58 and MustPrivateKeyFromBase58 proof of concept to checked for PrivateKeyFromBase58 Jul 30, 2024
@pikomonde pikomonde changed the title proof of concept to checked for PrivateKeyFromBase58 proof of concept to checked for invalid private key on PrivateKeyFromBase58 Jul 30, 2024
@gagliardetto
Copy link
Owner

gagliardetto commented Jan 16, 2025

I added some checks here:

solana-go/keys.go

Lines 59 to 81 in f829a21

func PrivateKeyFromBase58(privkey string) (PrivateKey, error) {
res, err := base58.Decode(privkey)
if err != nil {
return nil, err
}
// validate
if _, err := ValidatePrivateKey(res); err != nil {
return nil, err
}
return res, nil
}
func ValidatePrivateKey(b []byte) (bool, error) {
if len(b) != ed25519.PrivateKeySize {
return false, fmt.Errorf("invalid private key size, expected %v, got %d", ed25519.PrivateKeySize, len(b))
}
// check if the public key is on the ed25519 curve
pub := ed25519.PrivateKey(b).Public().(ed25519.PublicKey)
if !IsOnCurve(pub) {
return false, errors.New("the corresponding public key is NOT on the ed25519 curve")
}
return true, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not return err when pass random str or invalid privateKey to func PrivateKeyFromBase58
3 participants