Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Oct 10, 2023
1 parent 1e0d1ad commit 0b235f7
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crypto/ecdsa/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ import (
"github.com/google/uuid"
)

// WriteKey writes the private key to the given path
// The key is encrypted using the given password
// This function will create the directory if it doesn't exist
// If there's an existing file at the given path, it will be overwritten
func WriteKey(path string, privateKey *ecdsa.PrivateKey, password string) error {
UUID, err := uuid.NewRandom()
if err != nil {
return err
}

// We are using https://github.com/ethereum/go-ethereum/blob/master/accounts/keystore/key.go#L41
// to store the keys which requires us to have random UUID for encryption
key := &keystore.Key{
Id: UUID,
Address: crypto.PubkeyToAddress(privateKey.PublicKey),
Expand Down

0 comments on commit 0b235f7

Please sign in to comment.