mirror of
https://github.com/grassrootseconomics/cic-custodial.git
synced 2024-11-29 16:56:47 +01:00
30 lines
573 B
Go
30 lines
573 B
Go
|
package keypair
|
||
|
|
||
|
import (
|
||
|
"crypto/ecdsa"
|
||
|
|
||
|
"github.com/celo-org/celo-blockchain/common/hexutil"
|
||
|
"github.com/celo-org/celo-blockchain/crypto"
|
||
|
)
|
||
|
|
||
|
type Key struct {
|
||
|
Public string
|
||
|
Private string
|
||
|
}
|
||
|
|
||
|
func Generate() (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
|
||
|
}
|