Store public key as a byte array
This commit is contained in:
parent
484d0bbae2
commit
cb1776224e
15
wallet.go
15
wallet.go
|
@ -21,7 +21,7 @@ const walletFile = "wallet.dat"
|
||||||
// Wallet stores private and public keys
|
// Wallet stores private and public keys
|
||||||
type Wallet struct {
|
type Wallet struct {
|
||||||
PrivateKey ecdsa.PrivateKey
|
PrivateKey ecdsa.PrivateKey
|
||||||
PublicKey ecdsa.PublicKey
|
PublicKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wallets stores a collection of wallets
|
// Wallets stores a collection of wallets
|
||||||
|
@ -31,8 +31,7 @@ type Wallets struct {
|
||||||
|
|
||||||
// GetAddress returns wallet address
|
// GetAddress returns wallet address
|
||||||
func (w Wallet) GetAddress() []byte {
|
func (w Wallet) GetAddress() []byte {
|
||||||
pubKey := append(w.PublicKey.X.Bytes(), w.PublicKey.Y.Bytes()...)
|
pubKeyHash := HashPubKey(w.PublicKey)
|
||||||
pubKeyHash := HashPubKey(pubKey)
|
|
||||||
|
|
||||||
versionedPayload := append([]byte{version}, pubKeyHash...)
|
versionedPayload := append([]byte{version}, pubKeyHash...)
|
||||||
checksum := checksum(versionedPayload)
|
checksum := checksum(versionedPayload)
|
||||||
|
@ -51,14 +50,15 @@ func NewWallet() *Wallet {
|
||||||
return &wallet
|
return &wallet
|
||||||
}
|
}
|
||||||
|
|
||||||
func newKeyPair() (ecdsa.PrivateKey, ecdsa.PublicKey) {
|
func newKeyPair() (ecdsa.PrivateKey, []byte) {
|
||||||
curve := elliptic.P256()
|
curve := elliptic.P256()
|
||||||
private, err := ecdsa.GenerateKey(curve, rand.Reader)
|
private, err := ecdsa.GenerateKey(curve, rand.Reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
pubKey := append(private.PublicKey.X.Bytes(), private.PublicKey.Y.Bytes()...)
|
||||||
|
|
||||||
return *private, private.PublicKey
|
return *private, pubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateWallet adds a Wallet to Wallets
|
// CreateWallet adds a Wallet to Wallets
|
||||||
|
@ -124,6 +124,11 @@ func (ws *Wallets) GetAddresses() []string {
|
||||||
return addresses
|
return addresses
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetWallet returns a Wallet by its address
|
||||||
|
func (ws Wallets) GetWallet(address string) Wallet {
|
||||||
|
return *ws.Wallets[address]
|
||||||
|
}
|
||||||
|
|
||||||
// NewWallets creates Wallets and fills it from a file if it exists
|
// NewWallets creates Wallets and fills it from a file if it exists
|
||||||
func NewWallets() (*Wallets, error) {
|
func NewWallets() (*Wallets, error) {
|
||||||
wallets := Wallets{}
|
wallets := Wallets{}
|
||||||
|
|
Loading…
Reference in New Issue