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
- Variables
- func GenerateMnemonic() (string, error)
- type AccountData
- type AccountDataResult
- type AccountDataValue
- type Coin
- type Coins
- type Error
- type Fee
- type NodeInfo
- type SigPubKey
- type Signature
- type SignedTransactionPayload
- type TransactionPayload
- type TransactionSignature
- type TxBody
- type TxMode
- type TxResponse
- type Wallet
- func (w Wallet) Export() (string, error)
- func (w Wallet) ExportWithPrivateKey() (string, error)
- func (w Wallet) Sign(tx TransactionPayload, chainID, accountNumber, sequenceNumber string) (SignedTransactionPayload, error)
- func (w *Wallet) SignAndBroadcast(tx TransactionPayload, lcdEndpoint string, txMode TxMode) (string, error)
Constants ¶
const CosmosDerivationPath string = "m/44'/118'/0'/0/0"
CosmosDerivationPath is the standard BIP44 derivation path for Cosmos
Variables ¶
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.
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.
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.
var ErrDerivationPathFirstCharNotM = fmt.Errorf("derivation path invalid, first character isn't 'm'")
ErrDerivationPathFirstCharNotM happens whenever the derivation path string doesn't begin with "m".
var ErrDerivationPathShort = fmt.Errorf("derivation path string too short")
ErrDerivationPathShort represents an error that happens when the derivation path is too short.
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 ¶
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 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 ¶
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 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" )
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 ¶
FromMnemonic returns a new Wallet instance given a human-readable part, mnemonic and path.
func (Wallet) Export ¶
Export creates a JSON representation of w. Export does not include the private key in the JSON representation.
func (Wallet) ExportWithPrivateKey ¶
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.