Documentation ¶
Index ¶
- func Base58Decode(encodeddata []byte) []byte
- func Base58Encode(payload []byte) []byte
- func GenerateDoubleHash(payload []byte) []byte
- func GeneratePublicKeyCheckSum(publickeyhash []byte) []byte
- func GeneratePublicKeyHash(publickey []byte) []byte
- func GenerateWalletKeys() (ecdsa.PrivateKey, []byte)
- func Handle(err error)
- func TruncateHash(hash []byte, length int) []byte
- func ValidateWalletAddress(address string) bool
- type Wallet
- type WalletStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base58Decode ¶
A function to decode a Base58 bytes payload into a regular bytes payload
func Base58Encode ¶
A function to encode a bytes payload into a Base58 bytes payload
func GenerateDoubleHash ¶
A function that generates double SHA256 hash of the given payload and returns it as a slice of bytes
func GeneratePublicKeyCheckSum ¶
A function that generates the checksum of the public key hash.
The checksum is obtained by double hashing the hashed public key with SHA256 and truncated to its first 4 bytes. This method is consistent with the methods suggested in the original Bitcoin papers.
func GeneratePublicKeyHash ¶
A function that generates the hash of the public key.
The hash of the public key is generated by double hashing the public key with SHA256 and then truncated to 20 bytes. This equivalent to the Bitcoin method of using SHA256 followed by RIPEMD160 and is equally safe. The RIPEMD160 algorithm was rejected because of its deprecated nature in the golang crypto library along with the fact that truncated SHA2 algortithms are equally safe Hence the choice to use truncated SHA256 over the SHA1 which also outputs 20 bytes.
References:
func GenerateWalletKeys ¶
func GenerateWalletKeys() (ecdsa.PrivateKey, []byte)
A function that generates a pair of keys for the blockchain wallet
The private key is generated from an ECDSA algorithm that uses the secp256r1 curve. The public key is generated by concatentanating the X,Y coordinates returned in the public key embedded within the ECDSA generated private key.
This method of generating cryptographic key pairs creates a pair with 1 in 10^77 chance of collision.
func TruncateHash ¶
A function that truncates a given hash to the given length (in number of bytes) Returns the leftmost bytes of the original hash.
func ValidateWalletAddress ¶
A function that validates a given address by isolating its components and comparing the checksum of the address.
Types ¶
type Wallet ¶
type Wallet struct { PrivateKey ecdsa.PrivateKey // Represetns the Public Key of the Wallet PublicKey []byte // Represents the Private Key of the Wallet }
A structure that represents a wallet to access the blockchain
func NewWallet ¶
func NewWallet() *Wallet
A constructor function that generates and returns a Wallet
func (*Wallet) GenerateAddress ¶
A method of Wallet that generates and returns the address of the wallet as a slice of bytes.
The address generation is done by generating the hash of the public key and the check sum of this public hash and concatentating these with a version. The total hash is then encoded into base58 which creates the address.
type WalletStore ¶
type WalletStore struct {
Wallets map[string]*Wallet // Represents the map of wallet address to wallet pointers
}
A structure that represents a store of wallets
func NewWalletStore ¶
func NewWalletStore() *WalletStore
A constructor function to generate and return a new WalletStore by reading from the walletstore data file.
func (*WalletStore) AddWallet ¶
func (ws *WalletStore) AddWallet() string
A method of WalletStore that adds a new wallet to the store and returns the address of the new Wallet.
func (*WalletStore) FetchWallet ¶
func (ws *WalletStore) FetchWallet(address string) *Wallet
A method of WalletStore that fetches a wallet from the wallet store given a wallet address.
func (*WalletStore) GetAddresses ¶
func (ws *WalletStore) GetAddresses() []string
A method of WalletStore that returns the address of wallets in the WalletStore.
func (*WalletStore) Load ¶
func (ws *WalletStore) Load() error
A method of WalletStore that loads the walletstore file into the current state of the WalletStore
func (*WalletStore) Save ¶
func (ws *WalletStore) Save()
A method of WalletStore that saves the current state of the WalletStore to the walletstore file.