Skip to content

Commit

Permalink
modify the way addresses work slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed May 20, 2017
1 parent c51a174 commit 4578934
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions blockchain/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,27 @@ var (
)

// Address represents a wallet that can be a recipient in a transaction.
type Address [AddrLen]byte
type Address struct {
X, Y *big.Int
}

// Marshal converts an Address to a byte slice.
func (a Address) Marshal() []byte {
buf := make([]byte, AddrLen)
for i, b := range a {
buf[i] = b
}
buf = append(buf, a.X.Bytes()...)
buf = append(buf, a.Y.Bytes()...)
return buf
}

// Key returns the ECDSA public key representation of the address.
func (a Address) Key() *ecdsa.PublicKey {
return &ecdsa.PublicKey{
Curve: curve,
X: a.X,
Y: a.X,
}
}

// Wallet represents a wallet that we have the ability to sign for.
type Wallet interface {
Public() Address
Expand All @@ -53,23 +63,7 @@ func (w *wallet) key() *ecdsa.PrivateKey {

// Public returns the public key as byte array, or address, of the wallet.
func (w *wallet) Public() Address {
addr := Address{}
x := w.PublicKey.X.Bytes()
y := w.PublicKey.Y.Bytes()

if len(x) != CoordLen || len(y) != CoordLen {
// Invalid wallet
return NilAddr
}

for i, b := range x {
addr[i] = b
}
for i, b := range y {
addr[CoordLen+i] = b
}

return addr
return Address{X: w.PublicKey.X, Y: w.PublicKey.Y}
}

// Sign returns a signature of the digest.
Expand Down

0 comments on commit 4578934

Please sign in to comment.