wallet

package
v0.0.0-...-86ff07d Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Wallet

type Wallet struct {
	PrivateKey *ecdsa.PrivateKey `json:"private_key"`
	PublicKey  *ecdsa.PublicKey  `json:"public_key"`
}

func NewWallet

func NewWallet() (*Wallet, error)

NewWallet creates and returns a new wallet with a randomly generated private key using elliptic curve P-256.

func NewWalletFromPrivateKeyHex

func NewWalletFromPrivateKeyHex(privateKeyHex string) *Wallet

NewWalletFromPrivateKeyHex creates a new wallet from a hexadecimal private key string.

func (*Wallet) GetAddress

func (w *Wallet) GetAddress() string

GetAddress generates a unique address for the wallet by: 1. Taking the public key (without "0x" prefix) 2. Computing its SHA256 hash 3. Converting hash to hex string 4. Taking last 40 chars and prepending ADDRESS_PREFIX

func (*Wallet) GetPrivateKeyHex

func (w *Wallet) GetPrivateKeyHex() string

GetPrivateKeyHex returns the private key as a hexadecimal string prefixed with "0x"

func (*Wallet) GetPublicKeyHex

func (w *Wallet) GetPublicKeyHex() string

GetPublicKeyHex returns the public key as a hexadecimal string prefixed with "0x", concatenating the X and Y coordinates of the public key point on the curve

func (*Wallet) GetSignedTransaction

func (w *Wallet) GetSignedTransaction(unsignedTxn blockchain.Transaction) (*blockchain.Transaction, error)

GetSignedTxn takes an unsigned transaction and returns a signed copy of it. It does this by: 1. Marshaling the transaction to JSON and computing its SHA256 hash 2. Signing the hash with the wallet's private key using ECDSA 3. Creating a new transaction with the same fields plus signature and public key 4. Returns pointer to signed transaction and any error that occurred

Jump to

Keyboard shortcuts

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