wallet

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base58Decode

func Base58Decode(encodeddata []byte) []byte

A function to decode a Base58 bytes payload into a regular bytes payload

func Base58Encode

func Base58Encode(payload []byte) []byte

A function to encode a bytes payload into a Base58 bytes payload

func GenerateDoubleHash

func GenerateDoubleHash(payload []byte) []byte

A function that generates double SHA256 hash of the given payload and returns it as a slice of bytes

func GeneratePublicKeyCheckSum

func GeneratePublicKeyCheckSum(publickeyhash []byte) []byte

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

func GeneratePublicKeyHash(publickey []byte) []byte

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:

https://bitcoin.stackexchange.com/questions/16543/why-was-the-ripemd-160-hash-algorithms-chosen-before-sha-1

https://crypto.stackexchange.com/questions/3153/sha-256-vs-any-256-bits-of-sha-512-which-is-more-secure

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 Handle

func Handle(err error)

A function to handle errors.

func TruncateHash

func TruncateHash(hash []byte, length int) []byte

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

func ValidateWalletAddress(address string) bool

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

func (w *Wallet) GenerateAddress() []byte

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL