auth

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: GPL-3.0 Imports: 28 Imported by: 0

README

Auth Module

Table of Contents

Overview

The auth module is responsible for specifying the base transaction and account types for an application. It contains the ante handler, where all basic transaction validity checks (signatures, nonces, auxiliary fields) are performed, and exposes the account keeper, which allows other modules to read, write, and modify accounts.

Gas and Fees

Fees serve two purposes for an operator of the network.

Fees limit the growth of the state stored by every full node and allow for general purpose censorship of transactions of little economic value. Fees are best suited as an anti-spam mechanism where validators are disinterested in the use of the network and identities of users.

Since Heimdall doesn't support custom contract or code for any transaction, it uses fixed cost transactions. For fixed cost transactions, the validator can top up their accounts on the Ethereum chain and get tokens on Heimdall using the Topup module.

Types

Besides accounts (specified in State), the types exposed by the auth module are StdSignature, the combination of an optional public key and a cryptographic signature as a byte array, StdTx, a struct that implements the sdk.Tx interface using StdSignature, and StdSignDoc, a replay-prevention structure for StdTx which transaction senders must sign over.

StdSignature

A StdSignature is the types of a byte array.

// StdSignature represents a sig
type StdSignature []byte
StdTx

A StdTx is a struct that implements the sdk.Tx interface, and is likely to be generic enough to serve the purposes of many types of transactions.

type StdTx struct {
        Msg       sdk.Msg      `json:"msg" yaml:"msg"`
        Signature StdSignature `json:"signature" yaml:"signature"`
        Memo      string       `json:"memo" yaml:"memo"`
}
StdSignDoc

A StdSignDoc is a replay-prevention structure to be signed over, which ensures that any submitted transaction (which is simply a signature over a particular byte string) will only be executable once on a Heimdall.

// StdSignDoc is replay-prevention structure.
// It includes the result of msg.GetSignBytes(),
// as well as the ChainID (prevent cross chain replay)
// and the Sequence numbers for each signature (prevent
// inchain replay and enforce tx ordering per account).
type StdSignDoc struct {
    ChainID       string          `json:"chain_id" yaml:"chain_id"`
    AccountNumber uint64          `json:"account_number" yaml:"account_number"`
    Sequence      uint64          `json:"sequence" yaml:"sequence"`
    Msg           json.RawMessage `json:"msg" yaml:"msg"`
    Memo          string          `json:"memo" yaml:"memo"`
}
Account

It manages addresses, coins and nonce for transactions. It also signs and validates transactions.

type BaseAccount struct {
        Address types.HeimdallAddress `json:"address" yaml:"address"`
        Coins types.Coins `json:"coins" yaml:"coins"`
        PubKey crypto.PubKey `json:"public_key" yaml:"public_key"`
        AccountNumber uint64 `json:"account_number" yaml:"account_number"`
        Sequence uint64 `json:"sequence" yaml:"sequence"`
}
Parameters

The auth module contains the following parameters:

Key Type Default value
MaxMemoCharacters uint64 256
TxSigLimit uint64 7
TxSizeCostPerByte uint64 10
SigVerifyCostED25519 uint64 590
SigVerifyCostSecp256k1 uint64 1000
DefaultMaxTxGas uint64 1000000
DefaultTxFees string "1000000000000000"

Query Commands

One can run the following query command from the auth module.

  • account - Query account details of a given address
  • params - Query auth module parameters

To know your account details, run the following command:

heimdalld show-account

Expected response:

{
    "address": "0x68243159a498cf20d945cf3E4250918278BA538E",
    "pub_key": "0x040a9f6879c7cdab7ecc67e157cda15e8b2ddbde107a04bc22d02f50032e393f6360a05e85c7c1ecd201ad30dfb886af12dd02b47e4463f6f0f6f94159dc9f10b8"
}
CLI Commands
heimdallcli query auth account <address> --trust-node
heimdallcli query auth params
REST Endpoints
curl http://localhost:1317/auth/accounts/<address>
curl http://localhost:1317/auth/params

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultFeeInMatic represents default fee in matic
	DefaultFeeInMatic = big.NewInt(10).Exp(big.NewInt(10), big.NewInt(15), nil)

	// DefaultFeeWantedPerTx fee wanted per tx
	DefaultFeeWantedPerTx = sdk.Coins{sdk.Coin{Denom: authTypes.FeeToken, Amount: sdk.NewIntFromBigInt(DefaultFeeInMatic)}}
)

Functions

func DeductFees

func DeductFees(feeCollector FeeCollector, ctx sdk.Context, acc authTypes.Account, fees sdk.Coins) sdk.Result

DeductFees deducts fees from the given account.

NOTE: We could use the CoinKeeper (in addition to the AccountKeeper, because the CoinKeeper doesn't give us accounts), but it seems easier to do this.

func DefaultSigVerificationGasConsumer

func DefaultSigVerificationGasConsumer(
	meter sdk.GasMeter, sig authTypes.StdSignature, params authTypes.Params,
) sdk.Result

DefaultSigVerificationGasConsumer is the default implementation of SignatureVerificationGasConsumer. It consumes gas for signature verification based upon the public key type. The cost is fetched from the given params and is matched by the concrete type.

func ExportGenesis

func ExportGenesis(ctx sdk.Context, ak AccountKeeper) authTypes.GenesisState

ExportGenesis returns a GenesisState for a given context and keeper

func GetSignBytes

func GetSignBytes(ctx sdk.Context, chainID string, stdTx authTypes.StdTx, acc authTypes.Account, genesis bool) []byte

GetSignBytes returns a slice of bytes to sign over for a given transaction and an account.

func GetSignerAcc

func GetSignerAcc(
	ctx sdk.Context,
	ak AccountKeeper,
	addr types.HeimdallAddress,
) (authTypes.Account, sdk.Result)

GetSignerAcc returns an account for a given address that is expected to sign a transaction.

func InitGenesis

func InitGenesis(ctx sdk.Context, ak AccountKeeper, processors []authTypes.AccountProcessor, data authTypes.GenesisState)

InitGenesis - Init store state from genesis data

func NewAnteHandler

func NewAnteHandler(
	ak AccountKeeper,
	chainKeeper chainmanager.Keeper,
	feeCollector FeeCollector,
	contractCaller helper.IContractCaller,
	sigGasConsumer SignatureVerificationGasConsumer,
) sdk.AnteHandler

NewAnteHandler returns an AnteHandler that checks and increments sequence numbers, checks signatures & account numbers, and deducts fees from the first signer.

func NewQuerier

func NewQuerier(keeper AccountKeeper) sdk.Querier

NewQuerier creates a querier for auth REST endpoints

func SetGasMeter

func SetGasMeter(simulate bool, ctx sdk.Context, gasLimit uint64) sdk.Context

SetGasMeter returns a new context with a gas meter set from a given context.

func ValidateMemo

func ValidateMemo(stdTx authTypes.StdTx, params authTypes.Params) sdk.Result

ValidateMemo validates the memo size.

Types

type AccountKeeper

type AccountKeeper struct {
	// contains filtered or unexported fields
}

AccountKeeper encodes/decodes accounts using the go-amino (binary) encoding/decoding library.

func NewAccountKeeper

func NewAccountKeeper(
	cdc *codec.Codec, key sdk.StoreKey, paramstore subspace.Subspace, proto func() types.Account,
) AccountKeeper

NewAccountKeeper returns a new sdk.AccountKeeper that uses go-amino to (binary) encode and decode concrete sdk.Accounts. nolint

func (AccountKeeper) GetAccount

func (ak AccountKeeper) GetAccount(ctx sdk.Context, addr hmTypes.HeimdallAddress) types.Account

GetAccount implements sdk.AccountKeeper.

func (AccountKeeper) GetAllAccounts

func (ak AccountKeeper) GetAllAccounts(ctx sdk.Context) []types.Account

GetAllAccounts returns all accounts in the accountKeeper.

func (AccountKeeper) GetBlockProposer

func (ak AccountKeeper) GetBlockProposer(ctx sdk.Context) (hmTypes.HeimdallAddress, bool)

GetBlockProposer returns block proposer

func (AccountKeeper) GetNextAccountNumber

func (ak AccountKeeper) GetNextAccountNumber(ctx sdk.Context) uint64

GetNextAccountNumber Returns and increments the global account number counter

func (AccountKeeper) GetParams

func (ak AccountKeeper) GetParams(ctx sdk.Context) (params types.Params)

GetParams gets the auth module's parameters.

func (AccountKeeper) GetPubKey

func (ak AccountKeeper) GetPubKey(ctx sdk.Context, addr hmTypes.HeimdallAddress) (crypto.PubKey, sdk.Error)

GetPubKey Returns the PubKey of the account at address

func (AccountKeeper) GetSequence

func (ak AccountKeeper) GetSequence(ctx sdk.Context, addr hmTypes.HeimdallAddress) (uint64, sdk.Error)

GetSequence Returns the Sequence of the account at address

func (AccountKeeper) IterateAccounts

func (ak AccountKeeper) IterateAccounts(ctx sdk.Context, process func(types.Account) (stop bool))

IterateAccounts implements sdk.AccountKeeper.

func (AccountKeeper) Logger

func (ak AccountKeeper) Logger(ctx sdk.Context) log.Logger

Logger returns a module-specific logger.

func (AccountKeeper) NewAccount

func (ak AccountKeeper) NewAccount(ctx sdk.Context, acc types.Account) types.Account

NewAccount creates a new account

func (AccountKeeper) NewAccountWithAddress

func (ak AccountKeeper) NewAccountWithAddress(ctx sdk.Context, addr hmTypes.HeimdallAddress) types.Account

NewAccountWithAddress implements sdk.AccountKeeper.

func (AccountKeeper) RemoveAccount

func (ak AccountKeeper) RemoveAccount(ctx sdk.Context, acc types.Account)

RemoveAccount removes an account for the account mapper store. NOTE: this will cause supply invariant violation if called

func (AccountKeeper) RemoveBlockProposer

func (ak AccountKeeper) RemoveBlockProposer(ctx sdk.Context)

RemoveBlockProposer removes block proposer from store

func (AccountKeeper) SetAccount

func (ak AccountKeeper) SetAccount(ctx sdk.Context, acc types.Account)

SetAccount implements sdk.AccountKeeper allows addition of new accounts

func (AccountKeeper) SetBlockProposer

func (ak AccountKeeper) SetBlockProposer(ctx sdk.Context, addr hmTypes.HeimdallAddress)

SetBlockProposer sets block proposer

func (AccountKeeper) SetParams

func (ak AccountKeeper) SetParams(ctx sdk.Context, params types.Params)

SetParams sets the auth module's parameters.

type AppModule

type AppModule struct {
	AppModuleBasic
	// contains filtered or unexported fields
}

AppModule implements an application module for the auth module.

func NewAppModule

func NewAppModule(accountKeeper AccountKeeper, contractCaller helper.IContractCaller, processors []types.AccountProcessor) AppModule

NewAppModule creates a new AppModule object

func (AppModule) BeginBlock

func (AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock)

BeginBlock returns the begin blocker for the auth module.

func (AppModule) EndBlock

EndBlock returns the end blocker for the auth module. It returns no validator updates.

func (AppModule) ExportGenesis

func (am AppModule) ExportGenesis(ctx sdk.Context) json.RawMessage

ExportGenesis returns the exported genesis state as raw bytes for the auth module.

func (AppModule) GenerateGenesisState added in v0.1.7

func (AppModule) GenerateGenesisState(simState *hmModule.SimulationState)

GenerateGenesisState creates a randomized GenState of the auth module

func (AppModule) InitGenesis

func (am AppModule) InitGenesis(ctx sdk.Context, data json.RawMessage) []abci.ValidatorUpdate

InitGenesis performs genesis initialization for the auth module. It returns no validator updates.

func (AppModule) Name

func (AppModule) Name() string

Name returns the auth module's name.

func (AppModule) NewHandler

func (AppModule) NewHandler() sdk.Handler

NewHandler returns an sdk.Handler for the auth module.

func (AppModule) NewQuerierHandler

func (am AppModule) NewQuerierHandler() sdk.Querier

NewQuerierHandler returns the auth module sdk.Querier.

func (AppModule) ProposalContents added in v0.1.7

func (AppModule) ProposalContents(simState hmModule.SimulationState) []simTypes.WeightedProposalContent

ProposalContents doesn't return any content functions for governance proposals.

func (AppModule) QuerierRoute

func (AppModule) QuerierRoute() string

QuerierRoute returns the auth module's querier route name.

func (AppModule) RandomizedParams added in v0.1.7

func (AppModule) RandomizedParams(r *rand.Rand) []simTypes.ParamChange

RandomizedParams creates randomized auth param changes for the simulator.

func (AppModule) RegisterInvariants

func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry)

RegisterInvariants performs a no-op.

func (AppModule) RegisterStoreDecoder added in v0.1.7

func (AppModule) RegisterStoreDecoder(sdr hmModule.StoreDecoderRegistry)

RegisterStoreDecoder registers a decoder for auth module's types

func (AppModule) Route

func (AppModule) Route() string

Route returns the message routing key for the auth module.

func (AppModule) WeightedOperations added in v0.1.7

WeightedOperations doesn't return any auth module operation.

type AppModuleBasic

type AppModuleBasic struct{}

AppModuleBasic defines the basic application module used by the auth module.

func (AppModuleBasic) DefaultGenesis

func (AppModuleBasic) DefaultGenesis() json.RawMessage

DefaultGenesis returns default genesis state as raw bytes for the auth module.

func (AppModuleBasic) GetQueryCmd

func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command

GetQueryCmd returns the root query command for the auth module.

func (AppModuleBasic) GetTxCmd

func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command

GetTxCmd returns the root tx command for the auth module.

func (AppModuleBasic) Name

func (AppModuleBasic) Name() string

Name returns the auth module's name.

func (AppModuleBasic) RegisterCodec

func (AppModuleBasic) RegisterCodec(cdc *codec.Codec)

RegisterCodec registers the auth module's types for the given codec.

func (AppModuleBasic) RegisterRESTRoutes

func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router)

RegisterRESTRoutes registers the REST routes for the auth module.

func (AppModuleBasic) ValidateGenesis

func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error

ValidateGenesis performs genesis state validation for the auth module.

func (AppModuleBasic) VerifyGenesis

func (AppModuleBasic) VerifyGenesis(map[string]json.RawMessage) error

VerifyGenesis performs verification on auth module state.

type FeeCollector

type FeeCollector interface {
	GetModuleAddress(string) types.HeimdallAddress
	SendCoinsFromAccountToModule(
		sdk.Context,
		types.HeimdallAddress,
		string,
		sdk.Coins,
	) sdk.Error
}

FeeCollector interface for fees collector

type MainTxMsg

type MainTxMsg interface {
	GetTxHash() types.HeimdallHash
	GetLogIndex() uint64
}

MainTxMsg tx hash

type SignatureVerificationGasConsumer

type SignatureVerificationGasConsumer = func(meter sdk.GasMeter, sig authTypes.StdSignature, params authTypes.Params) sdk.Result

SignatureVerificationGasConsumer is the type of function that is used to both consume gas when verifying signatures and also to accept or reject different types of PubKey's. This is where apps can define their own PubKey

Directories

Path Synopsis
client
cli
rest
nolint
nolint
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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