github.com/Finschia/finschia-sdk@v0.49.1/x/auth/atlas/atlas-v0.39.1.md (about) 1 # x/auth 2 3 The `x/auth` module is responsible for specifying the base transaction and 4 account types for an application, as well as AnteHandler and authentication logic. 5 6 ## Usage 7 8 1. Import the module. 9 10 ```go 11 import ( 12 "github.com/Finschia/finschia-sdk/x/auth" 13 ) 14 ``` 15 16 2. Add `AppModuleBasic` to your `ModuleBasics`. 17 18 ```go 19 var ( 20 ModuleBasics = module.NewBasicManager( 21 // ... 22 auth.AppModuleBasic{}, 23 } 24 ) 25 ``` 26 27 3. Create the module's parameter subspace in your application constructor. 28 29 ```go 30 func NewApp(...) *App { 31 // ... 32 app.subspaces[auth.ModuleName] = app.ParamsKeeper.Subspace(auth.DefaultParamspace) 33 } 34 ``` 35 36 4. Create the keeper. 37 38 ```go 39 func NewApp(...) *App { 40 // ... 41 app.AccountKeeper = auth.NewAccountKeeper( 42 app.cdc, keys[auth.StoreKey], app.subspaces[auth.ModuleName], auth.ProtoBaseAccount, 43 ) 44 } 45 ``` 46 47 5. Add the `x/auth` module to the app's `ModuleManager`. 48 49 ```go 50 func NewApp(...) *App { 51 // ... 52 app.mm = module.NewManager( 53 // ... 54 auth.NewAppModule(app.AccountKeeper), 55 // ... 56 ) 57 } 58 ``` 59 60 6. Set the `x/auth` module genesis order. 61 62 ```go 63 func NewApp(...) *App { 64 // ... 65 app.mm.SetOrderInitGenesis(..., auth.ModuleName, ...) 66 } 67 ``` 68 69 7. Add the `x/auth` module to the simulation manager (if you have one set). 70 71 ```go 72 func NewApp(...) *App { 73 // ... 74 app.sm = module.NewSimulationManager( 75 // ... 76 auth.NewAppModule(app.AccountKeeper), 77 // ... 78 ) 79 } 80 81 8. Set the `AnteHandler` if you're using the default provided by `x/auth`. Note, 82 the default `AnteHandler` provided by the `x/auth` module depends on the `x/supply` 83 module. 84 85 ```go 86 func NewApp(...) *App { 87 app.SetAnteHandler(ante.NewAnteHandler( 88 app.AccountKeeper, 89 app.SupplyKeeper, 90 auth.DefaultSigVerificationGasConsumer, 91 )) 92 } 93 ``` 94 95 ### Vesting Accounts 96 97 The `x/auth` modules also defines a few standard vesting account types under the 98 `vesting` sub-package. In order to get your application to automatically support 99 these in terms of encoding and decoding, you must register the types with your 100 application Amino codec. 101 102 Where ever you define the application `Codec`, be sure to register types via: 103 104 ```go 105 import ( 106 "github.com/Finschia/finschia-sdk/x/auth/vesting" 107 ) 108 109 func MakeCodec() *codec.Codec { 110 var cdc = codec.New() 111 112 // ... 113 vesting.RegisterCodec(cdc) 114 // ... 115 116 return cdc 117 } 118 ``` 119 120 ## Genesis 121 122 The `x/auth` module defines its genesis state as follows: 123 124 ```go 125 type GenesisState struct { 126 Params Params `json:"params" yaml:"params"` 127 Accounts exported.GenesisAccounts `json:"accounts" yaml:"accounts"` 128 } 129 ``` 130 131 Which relies on the following types: 132 133 ```go 134 type Account interface { 135 GetAddress() sdk.AccAddress 136 SetAddress(sdk.AccAddress) error 137 GetPubKey() crypto.PubKey 138 SetPubKey(crypto.PubKey) error 139 GetAccountNumber() uint64 140 SetAccountNumber(uint64) error 141 GetSequence() uint64 142 SetSequence(uint64) error 143 GetCoins() sdk.Coins 144 SetCoins(sdk.Coins) error 145 SpendableCoins(blockTime time.Time) sdk.Coins 146 String() string 147 } 148 149 type Params struct { 150 MaxMemoCharacters uint64 `json:"max_memo_characters" yaml:"max_memo_characters"` 151 TxSigLimit uint64 `json:"tx_sig_limit" yaml:"tx_sig_limit"` 152 TxSizeCostPerByte uint64 `json:"tx_size_cost_per_byte" yaml:"tx_size_cost_per_byte"` 153 SigVerifyCostED25519 uint64 `json:"sig_verify_cost_ed25519" yaml:"sig_verify_cost_ed25519"` 154 SigVerifyCostSecp256k1 uint64 `json:"sig_verify_cost_secp256k1" yaml:"sig_verify_cost_secp256k1"` 155 } 156 ``` 157 158 ## Client 159 160 ### CLI 161 162 The `x/auth` module provides various auxiliary CLI commands and a few that are 163 part of the module itself via the `ModuleManager`. The commands that are part of 164 the module itself are defined below: 165 166 1. Query an account. 167 168 ```shell 169 app q auth account [address] [...flags] 170 ``` 171 172 2. Sign an unsigned transaction using a single signature. 173 174 ```shell 175 app tx auth sign [file] 176 ``` 177 178 3. Sign an unsigned transaction using a multisig. 179 180 ```shell 181 app tx auth multisign [file] [name] [[signature]...] 182 ``` 183 184 ### REST 185 186 The `x/auth` module provides various auxiliary REST handlers and a few that are 187 part of the module itself via the `ModuleManager`. The endpoints that are part of 188 the module itself are defined below: 189 190 1. Query an account. 191 192 | Method | Path | 193 | :----- | :----------------------- | 194 | `GET` | `/auth/accounts/{address}` |