mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2025-04-09 03:21:02 +02:00
30 lines
573 B
Go
30 lines
573 B
Go
package ethereum
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
)
|
|
|
|
type Key struct {
|
|
Public string
|
|
Private string
|
|
}
|
|
|
|
func GenerateKeyPair() (Key, error) {
|
|
privateKey, err := crypto.GenerateKey()
|
|
if err != nil {
|
|
return Key{}, err
|
|
}
|
|
privateKeyBytes := crypto.FromECDSA(privateKey)
|
|
|
|
publicKey := privateKey.Public()
|
|
publicKeyECDSA := publicKey.(*ecdsa.PublicKey)
|
|
|
|
return Key{
|
|
Public: crypto.PubkeyToAddress(*publicKeyECDSA).Hex(),
|
|
Private: hexutil.Encode(privateKeyBytes)[2:],
|
|
}, nil
|
|
}
|