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

chore::> Derive public key from private key using crypto package #594

Merged
merged 6 commits into from
Oct 2, 2024
25 changes: 20 additions & 5 deletions account/keystore.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type MemKeystore struct {
// NewMemKeystore initializes and returns a new instance of MemKeystore.
//
// Parameters:
// none
//
// none
//
// Returns:
// - *MemKeystore: a pointer to MemKeystore.
func NewMemKeystore() *MemKeystore {
Expand All @@ -38,14 +40,21 @@ func NewMemKeystore() *MemKeystore {
// SetNewMemKeystore returns a new instance of MemKeystore and sets the given public key and private key in it.
//
// Parameters:
// - pub: a string representing the public key
// - priv: a pointer to a big.Int representing the private key
// Returns:
// - *MemKeystore: a pointer to the newly created MemKeystore instance
func SetNewMemKeystore(pub string, priv *big.Int) *MemKeystore {
// - error: if any error occurs during conversion
func SetNewMemKeystore(priv *big.Int) (*MemKeystore, error) {
PsychoPunkSage marked this conversation as resolved.
Show resolved Hide resolved
ks := NewMemKeystore()

pubX, _, err := curve.Curve.PrivateToPoint(priv)
if err != nil {
return nil, err
}

pub := utils.BigIntToFelt(pubX).String()
ks.Put(pub, priv)
return ks
return ks, nil
}

// Put stores the given key in the keystore for the specified sender address.
Expand Down Expand Up @@ -126,7 +135,9 @@ func sign(ctx context.Context, msgHash *big.Int, key *big.Int) (x *big.Int, y *b
// GetRandomKeys gets a random set of pub-priv keys.
// Note: This should be used for testing purposes only, do NOT send real funds to these addresses.
// Parameters:
// none
//
// none
//
// Returns:
// - *MemKeystore: a pointer to a MemKeystore instance
// - *felt.Felt: a pointer to a public key as a felt.Felt
Expand Down Expand Up @@ -156,3 +167,7 @@ func GetRandomKeys() (*MemKeystore, *felt.Felt, *felt.Felt) {

return ks, pubFelt, privFelt
}

// func derivePublicKeyFromPrivateKey(priv *big.Int) (*ecdsa.PublicKey, error) {
// privBytes := priv.Bytes()
// }
Loading