github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/docs/reference/gnoclient/signer.md (about)

     1  ---
     2  id: signer
     3  ---
     4  
     5  # Signer
     6  
     7  `Signer` is an interface that provides functionality for signing transactions.
     8  The signer can be created from a local keybase, or from a bip39 mnemonic phrase.
     9  
    10  Useful types and functions when using the `Signer` can be found below.
    11  
    12  ## type [Signer](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L13-L17>)
    13  
    14  `Signer` provides an interface for signing transactions.
    15  
    16  ```go
    17  type Signer interface {
    18      Sign(SignCfg) (*std.Tx, error) // Signs a transaction and returns a signed tx ready for broadcasting.
    19      Info() keys.Info               // Returns key information, including the address.
    20      Validate() error               // Checks whether the signer is properly configured.
    21  }
    22  ```
    23  
    24  ## type [SignCfg](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L65-L69>)
    25  
    26  `SignCfg` provides the signing configuration, containing the unsigned transaction 
    27  data, account number, and account sequence.
    28  
    29  ```go
    30  type SignCfg struct {
    31      UnsignedTX     std.Tx
    32      SequenceNumber uint64
    33      AccountNumber  uint64
    34  }
    35  ```
    36  
    37  ## type [SignerFromKeybase](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L20-L25>)
    38  
    39  `SignerFromKeybase` represents a signer created from a Keybase.
    40  
    41  ```go
    42  type SignerFromKeybase struct {
    43      Keybase  keys.Keybase // Stores keys in memory or on disk
    44      Account  string       // Account name or bech32 format
    45      Password string       // Password for encryption
    46      ChainID  string       // Chain ID for transaction signing
    47  }
    48  ```
    49  
    50  ### func \(SignerFromKeybase\) [Info](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L56>)
    51  
    52  ```go
    53  func (s SignerFromKeybase) Info() keys.Info
    54  ```
    55  
    56  `Info` gets keypair information.
    57  
    58  ### func \(SignerFromKeybase\) [Sign](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L72>)
    59  
    60  ```go
    61  func (s SignerFromKeybase) Sign(cfg SignCfg) (*std.Tx, error)
    62  ```
    63  
    64  `Sign` implements the Signer interface for SignerFromKeybase.
    65  
    66  ### func \(SignerFromKeybase\) [Validate](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L28>)
    67  
    68  ```go
    69  func (s SignerFromKeybase) Validate() error
    70  ```
    71  
    72  `Validate` checks if the signer is properly configured.
    73  
    74  ## func [SignerFromBip39](<https://github.com/gnolang/gno/blob/master/gno.land/pkg/gnoclient/signer.go#L130>)
    75  
    76  ```go
    77  func SignerFromBip39(mnemonic string, chainID string, passphrase string, account uint32, index uint32) (Signer, error)
    78  ```
    79  
    80  `SignerFromBip39` creates a `Signer` from an in-memory keybase with a single default 
    81  account, derived from the given mnemonic.
    82  This can be useful in scenarios where storing private keys in the filesystem
    83  isn't feasible, or for generating a signer for testing.
    84  
    85  > Using `keys.NewKeyBaseFromDir()` to get a keypair from local storage is 
    86  recommended where possible, as it is more secure.