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

     1  ---
     2  id: tm2-js-signer
     3  ---
     4  
     5  # Overview
     6  
     7  A `Signer` is an interface that abstracts the interaction with a single Secp256k1 key pair. It exposes methods for
     8  signing data, verifying signatures, and getting metadata associated with the key pair, such as the address.
     9  
    10  Currently, the `tm2-js-client` package provides support for two `Signer` implementations:
    11  
    12  - [Key](key.md): a signer that is based on a raw Secp256k1 key pair.
    13  - [Ledger](ledger.md): a signer that is based on a Ledger device, with all interaction flowing through the user's
    14    device.
    15  
    16  ## API
    17  
    18  ### getAddress
    19  
    20  Returns the address associated with the signer's public key
    21  
    22  Returns **Promise<string\>**
    23  
    24  #### Usage
    25  
    26  ```ts
    27  await signer.getAddress();
    28  // "g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq"
    29  ```
    30  
    31  ### getPublicKey
    32  
    33  Returns the signer's Secp256k1-compressed public key
    34  
    35  Returns **Promise<Uint8Array\>**
    36  
    37  #### Usage
    38  
    39  ```ts
    40  await signer.getPublicKey();
    41  // <Uint8Array>
    42  ```
    43  
    44  ### getPrivateKey
    45  
    46  Returns the signer's actual raw private key
    47  
    48  Returns **Promise<Uint8Array\>**
    49  
    50  #### Usage
    51  
    52  ```ts
    53  await signer.getPrivateKey();
    54  // <Uint8Array>
    55  ```
    56  
    57  ### signData
    58  
    59  Generates a data signature for arbitrary input
    60  
    61  #### Parameters
    62  
    63  * `data` **Uint8Array** the data to be signed
    64  
    65  Returns **Promise<Uint8Array\>**
    66  
    67  #### Usage
    68  
    69  ```ts
    70  const dataToSign: Uint8Array = // ...
    71  
    72      await signer.signData(dataToSign);
    73  // <Uint8Array>
    74  ```
    75  
    76  ### verifySignature
    77  
    78  Verifies if the signature matches the provided raw data
    79  
    80  #### Parameters
    81  
    82  * `data` **Uint8Array** the raw data (not-hashed)
    83  * `signature` **Uint8Array** the hashed-data signature
    84  
    85  Returns **Promise<boolean\>**
    86  
    87  #### Usage
    88  
    89  ```ts
    90  const signedData: Uint8Array = // ...
    91  const rawData: Uint8Array = // ...
    92  
    93      await signer.verifySignature(rawData, signedData);
    94  // <Uint8Array>
    95  ```
    96