blockchain sandbox: UTXO chain, p2p mining, attacker node
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
package chain
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
type Wallet struct {
|
||||
PrivateKey ed25519.PrivateKey
|
||||
PublicKey ed25519.PublicKey
|
||||
}
|
||||
|
||||
func NewWallet() *Wallet {
|
||||
pub, priv, _ := ed25519.GenerateKey(rand.Reader)
|
||||
return &Wallet{PrivateKey: priv, PublicKey: pub}
|
||||
}
|
||||
|
||||
func (w *Wallet) Address() string {
|
||||
return hex.EncodeToString(w.PublicKey)
|
||||
}
|
||||
|
||||
func (w *Wallet) ShortAddress() string {
|
||||
return w.Address()[:7]
|
||||
}
|
||||
Reference in New Issue
Block a user