sacco

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: MIT Imports: 21 Imported by: 1

README

sacco.go Go Report Card

Go implementation of Sacco, our cryptographic library that allows easy creation, signing and sending of Cosmos Network transactions


Right now, sacco.go is considered alpha software, contributions welcome!

Sacco.go can:

  1. create HD wallets

  2. import HD wallets from mnemonic words (BIP-39 compliant) with a specific derivation path (BIP-44 compliant)

  3. sign transactions

Documentation

Overview

Package sacco is a pure Go package that allows you to easily perform some operations related to the Cosmos network ecosystem: https://cosmos.network.

Right now, sacco.go is considered alpha software, contributions welcome!

Sacco.go can:

1. create HD wallets

2. import HD wallets from mnemonic words (BIP-39 compliant) with a specific derivation path (BIP-44 compliant)

3. sign transactions

Index

Constants

View Source
const CosmosDerivationPath string = "m/44'/118'/0'/0/0"

CosmosDerivationPath is the standard BIP44 derivation path for Cosmos

Variables

View Source
var ErrComponentNaN = func(component string, err error) error {
	return fmt.Errorf("derivation component \"%s\" not a number: %w", component, err)
}

ErrComponentNaN happens when a component of a derivation path isn't a number.

View Source
var ErrCouldNotBech32 = func(err error) error {
	return fmt.Errorf("could not convert public key to bech32: %w", err)
}

ErrCouldNotNeuter happens when converting a public key to bech32 is impossible.

View Source
var ErrCouldNotNeuter = func(err error) error {
	return fmt.Errorf("could not derive neutered public key: %w", err)
}

ErrCouldNotNeuter happens when neutering a key is not possible.

View Source
var ErrDerivationPathFirstCharNotM = fmt.Errorf("derivation path invalid, first character isn't 'm'")

ErrDerivationPathFirstCharNotM happens whenever the derivation path string doesn't begin with "m".

View Source
var ErrDerivationPathShort = fmt.Errorf("derivation path string too short")

ErrDerivationPathShort represents an error that happens when the derivation path is too short.

View Source
var ErrKeyGeneration = func(err error) error {
	return fmt.Errorf("cannot derive key: %w", err)
}

ErrKeyGeneration represents an error thrown when there was some kind of error while generating a key.

Functions

func GenerateMnemonic

func GenerateMnemonic() (string, error)

GenerateMnemonic generates a new random mnemonic sequence.

Types

type AccountData

type AccountData struct {
	Result AccountDataResult `json:"result"`
}

AccountData holds informations about the account number and sequence number of a Cosmos account.

type AccountDataResult

type AccountDataResult struct {
	Value AccountDataValue `json:"value"`
}

AccountDataResult is a wrapper struct for a call to auth/accounts/{address} LCD REST endpoint.

type AccountDataValue

type AccountDataValue struct {
	Address       string `json:"address"`
	AccountNumber int64  `json:"account_number"`
	Sequence      int64  `json:"sequence"`
}

AccountDataValue represents the real data obtained by calling /auth/accounts/{address} LCD REST endpoint.

type Coin

type Coin struct {
	Denom  string `json:"denom"`
	Amount string `json:"amount"`
}

Coin is an entity describing a token, with a specific denomination and amount.

type Coins

type Coins []Coin

Coins is a set of Coin.

type Error

type Error struct {
	Error string `json:"error,omitempty"`
}

Error represents a JSON encoded error message sent whenever something goes wrong during the handler processing.

type Fee

type Fee struct {
	Amount []Coin `json:"amount"`
	Gas    string `json:"gas"`
}

Fee represents the fee needed for a Cosmos request, with both an amount in Coins and a Gas quantity.

type NodeInfo

type NodeInfo struct {
	Info struct {
		Network string `json:"network"`
	} `json:"node_info"`
}

NodeInfo is the LCD REST response to a /node_info request, and contains the Network attribute (chain ID).

type SigPubKey

type SigPubKey struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

SigPubKey represents the public key used to create a Signature.

type Signature

type Signature struct {
	SigPubKey SigPubKey `json:"pub_key"`
	Signature string    `json:"signature"`
}

Signature is an object holding a cryptographic signature and the public key associated with it.

type SignedTransactionPayload

type SignedTransactionPayload TransactionPayload

SignedTransactionPayload is a TransactionPayload which has been signed by wallet.Sign().

type TransactionPayload

type TransactionPayload struct {
	Message    []json.RawMessage `json:"msg"`
	Fee        Fee               `json:"fee"`
	Signatures []Signature       `json:"signatures"`
	Memo       string            `json:"memo"`
}

TransactionPayload is the body of a Cosmos transaction.

type TransactionSignature

type TransactionSignature struct {
	AccountNumber string            `json:"account_number" yaml:"account_number"`
	ChainID       string            `json:"chain_id" yaml:"chain_id"`
	Fee           Fee               `json:"fee" yaml:"fee"`
	Sequence      string            `json:"sequence" yaml:"sequence"`
	Memo          string            `json:"memo" yaml:"memo"`
	Msgs          []json.RawMessage `json:"msgs" yaml:"msgs"`
}

TransactionSignature is a Transaction with AccountNumber, ChainID (Network) and sequence number, ready to be signed with a wallet's private key.

type TxBody

type TxBody struct {
	Tx   SignedTransactionPayload `json:"tx"`
	Mode string                   `json:"mode"`
}

TxBody represents the body of a Cosmos transaction signed and ready to be sent over the LCD REST service.

type TxMode

type TxMode string

TxMode identifies when an LCD should replies to a client after a transaction broadcast.

const (
	// ModeAsync waits for the tx to pass/fail CheckTx
	ModeAsync TxMode = "async"

	// ModeSync doesn't wait for pass/fail CheckTx and send and return tx immediately
	ModeSync TxMode = "sync"

	// ModeBlock waits for the tx to pass/fail CheckTx, DeliverTx, and be committed in a block (not recommended, slow)
	ModeBlock TxMode = "block"
)

func (TxMode) String

func (txm TxMode) String() string

String implements the stringer interface for TxMode.

type TxResponse

type TxResponse struct {
	Height    string                   `json:"height"`
	TxHash    string                   `json:"txhash"`
	Code      uint32                   `json:"code,omitempty"`
	Data      string                   `json:"data,omitempty"`
	RawLog    string                   `json:"raw_log,omitempty"`
	Logs      sdkTypes.ABCIMessageLogs `json:"logs,omitempty"`
	Info      string                   `json:"info,omitempty"`
	GasWanted string                   `json:"gas_wanted,omitempty"`
	GasUsed   string                   `json:"gas_used,omitempty"`
	Codespace string                   `json:"codespace,omitempty"`
	Tx        sdkTypes.Tx              `json:"tx,omitempty"`
	Timestamp string                   `json:"timestamp,omitempty"`

	// DEPRECATED: Remove in the next next major release in favor of using the
	// ABCIMessageLog.Events field.
	Events sdkTypes.StringEvents `json:"events,omitempty"`
}

TxResponse represents whatever data the LCD REST service returns to atomicwallet after a transaction gets forwarded to it.

type Wallet

type Wallet struct {
	PublicKey       string `json:"public_key,omitempty"`
	PublicKeyBech32 string `json:"public_key_bech_32,omitempty"`
	PrivateKey      string `json:"private_key,omitempty"`
	Path            string `json:"path,omitempty"`
	HRP             string `json:"hrp,omitempty"`
	Address         string `json:"address,omitempty"`
	// contains filtered or unexported fields
}

Wallet is a facility used to manipulate private and public keys associated to a BIP-32 mnemonic.

func FromMnemonic

func FromMnemonic(hrp, mnemonic, path string) (*Wallet, error)

FromMnemonic returns a new Wallet instance given a human-readable part, mnemonic and path.

func (Wallet) Export

func (w Wallet) Export() (string, error)

Export creates a JSON representation of w. Export does not include the private key in the JSON representation.

func (Wallet) ExportWithPrivateKey

func (w Wallet) ExportWithPrivateKey() (string, error)

ExportWithPrivateKey creates a JSON representation of w. ExportWithPrivateKey includes the private key in the JSON representation.

func (Wallet) Sign

func (w Wallet) Sign(tx TransactionPayload, chainID, accountNumber, sequenceNumber string) (SignedTransactionPayload, error)

Sign signs tx with given chainID, accountNumber and sequenceNumber, with w's private key. The resulting computation must be enclosed in a Transaction struct to be sent over the wire to a Cosmos LCD.

func (*Wallet) SignAndBroadcast

func (w *Wallet) SignAndBroadcast(tx TransactionPayload, lcdEndpoint string, txMode TxMode) (string, error)

SignAndBroadcast signs tx and broadcast it to the LCD specified by lcdEndpoint.

Jump to

Keyboard shortcuts

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