code.vegaprotocol.io/vega@v0.79.0/wallet/service/README.md (about)

     1  # Wallet API
     2  
     3  ## Authentication
     4  
     5  ### Logging in to a wallet
     6  
     7  `POST api/v1/auth/token`
     8  
     9  Logging in to a wallet is done using the wallet name and passphrase. The
    10  operation fails if the wallet not exist, or if the passphrase used is incorrect.
    11  On success, the wallet is loaded, a session is created and a JWT is returned to
    12  the user.
    13  
    14  #### Example
    15  
    16  ##### Request
    17  
    18  ```json
    19  {
    20    "wallet": "your_wallet_name",
    21    "passphrase": "super-secret"
    22  }
    23  ```
    24  
    25  ##### Command
    26  
    27  ```sh
    28  curl -s -XPOST -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/auth/token
    29  ```
    30  
    31  ##### Response
    32  
    33  ```json
    34  {
    35    "token": "abcd.efgh.ijkl"
    36  }
    37  ```
    38  
    39  ### Logging out from a wallet
    40  
    41  `DELETE api/v1/auth/token`
    42  
    43  Using the JWT returned when logging in, the session is recovered and removed
    44  from the service. The wallet can no longer be accessed using the token from this
    45  point on.
    46  
    47  #### Example
    48  
    49  ##### Command
    50  
    51  ```sh
    52  curl -s -XDELETE -H 'Authorization: Bearer abcd.efgh.ijkl' http://127.0.0.1:1789/api/v1/auth/token
    53  ```
    54  
    55  ##### Response
    56  
    57  ```json
    58  {
    59    "success": true
    60  }
    61  ```
    62  
    63  ## Network management
    64  
    65  ### Get current network configuration
    66  
    67  `GET api/v1/network`
    68  
    69  ### Example
    70  
    71  #### Command
    72  
    73  ```sh
    74  curl -s -XPOST -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/network
    75  ```
    76  
    77  #### Response
    78  
    79  ```json
    80  {
    81    "network": {
    82      "name": "mainnet"
    83    }
    84  }
    85  ```
    86  
    87  ## Wallet management
    88  
    89  ### Create a wallet
    90  
    91  `POST api/v1/wallets`
    92  
    93  Creating a wallet is done using a name and passphrase. If a wallet with the same
    94  name already exists, the action is aborted. The new wallets is encrypted (using
    95  the passphrase) and saved to a file on the file system. A session and
    96  accompanying JWT is created, and the JWT is returned to the user.
    97  
    98  #### Example
    99  
   100  ##### Request
   101  
   102  ```json
   103  {
   104    "wallet": "your_wallet_name",
   105    "passphrase": "super-secret"
   106  }
   107  ```
   108  
   109  ##### Command
   110  
   111  ```sh
   112  curl -s -XPOST -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/wallets
   113  ```
   114  
   115  ##### Response
   116  
   117  ```json
   118  {
   119    "token": "abcd.efgh.ijkl"
   120  }
   121  ```
   122  
   123  ### Import a wallet
   124  
   125  `POST api/v1/wallets/import`
   126  
   127  Import a wallet is done using a name, a passphrase, and a recoveryPhrase. If a wallet
   128  with the same name already exists, the action is aborted. The imported wallet is
   129  encrypted (using the passphrase) and saved to a file on the file system. A
   130  session and accompanying JWT is created, and the JWT is returned to the user.
   131  
   132  #### Example
   133  
   134  ##### Request
   135  
   136  ```json
   137  {
   138    "wallet": "your_wallet_name",
   139    "passphrase": "super-secret",
   140    "recoveryPhrase": "my twenty four words recovery phrase"
   141  }
   142  ```
   143  
   144  ##### Command
   145  
   146  ```sh
   147  curl -s -XPOST -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/wallets
   148  ```
   149  
   150  ##### Response
   151  
   152  ```json
   153  {
   154    "token": "abcd.efgh.ijkl"
   155  }
   156  ```
   157  
   158  ## Key management
   159  
   160  ### Generate a key pair
   161  
   162  `POST api/v1/keys`
   163  
   164  **Authentication required.**
   165  
   166  It generates a new key pair into the logged wallet, and returns the generated
   167  public key.
   168  
   169  #### Example
   170  
   171  ##### Request
   172  
   173  ```json
   174  {
   175    "passphrase": "super-secret",
   176    "meta": [
   177      {
   178        "key": "somekey",
   179        "value": "somevalue"
   180      }
   181    ]
   182  }
   183  ```
   184  
   185  ##### Command
   186  
   187  ```sh
   188  curl -s -XPOST -H 'Authorization: Bearer abcd.efgh.ijkl' -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/keys
   189  ```
   190  
   191  ##### Response
   192  
   193  ```json
   194  {
   195    "key": {
   196      "pub": "1122aabb",
   197      "algo": "ed25519",
   198      "tainted": false,
   199      "meta": [
   200        {
   201          "key": "somekey",
   202          "value": "somevalue"
   203        }
   204      ]
   205    }
   206  }
   207  ```
   208  
   209  ### List keys
   210  
   211  `GET api/v1/keys`
   212  
   213  **Authentication required.**
   214  
   215  Users can list all the public keys (with taint status, and metadata) of the
   216  logged wallet.
   217  
   218  #### Example
   219  
   220  ##### Command
   221  
   222  ```sh
   223  curl -s -XGET -H "Authorization: Bearer abcd.efgh.ijkl" http://127.0.0.1:1789/api/v1/keys
   224  ```
   225  
   226  ##### Response
   227  
   228  ```json
   229  {
   230    "keys": [
   231      {
   232        "pub": "1122aabb",
   233        "algo": "ed25519",
   234        "tainted": false,
   235        "meta": [
   236          {
   237            "key": "somekey",
   238            "value": "somevalue"
   239          }
   240        ]
   241      }
   242    ]
   243  }
   244  ```
   245  
   246  ### Describe a key pair
   247  
   248  `GET api/v1/keys/:keyid`
   249  
   250  **Authentication required.**
   251  
   252  Return the information associated the public key `:keyid`, from the logged
   253  wallet. The private key is not returned.
   254  
   255  #### Example
   256  
   257  ##### Command
   258  
   259  ```sh
   260    curl -s -XPUT -H "Authorization: Bearer abcd.efgh.ijkl" -d 'YOUR_REQUEST' http://127.0.0.1:1789api/v1/keys/1122aabb
   261  ```
   262  
   263  ##### Response
   264  
   265  ```json
   266  {
   267    "key": {
   268      "index": 1,
   269      "pub": "1122aabb"
   270    }
   271  }
   272  ```
   273  
   274  ### Taint a key pair
   275  
   276  `PUT api/v1/keys/:keyid/taint`
   277  
   278  **Authentication required.**
   279  
   280  Taint the key pair matching the public key `:keyid`, from the logged wallet. The
   281  key pair must belong to the logged wallet.
   282  
   283  #### Example
   284  
   285  ##### Request
   286  
   287  ```json
   288  {
   289    "passphrase": "super-secret"
   290  }
   291  ```
   292  
   293  ##### Command
   294  
   295  ```sh
   296    curl -s -XPUT -H "Authorization: Bearer abcd.efgh.ijkl" -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/keys/1122aabb/taint
   297  ```
   298  
   299  ##### Response
   300  
   301  ```json
   302  {
   303    "success": true
   304  }
   305  ```
   306  
   307  ### Annotate a key pair
   308  
   309  `PUT api/v1/keys/:keyid/metadata`
   310  
   311  **Authentication required.**
   312  
   313  Annotating a key pair replace the metadata matching the public key `:keyid`,
   314  from the logged wallet. The key pair must belong to the logged wallet.
   315  
   316  #### Example
   317  
   318  ##### Request
   319  
   320  ```json
   321  {
   322    "passphrase": "super-secret",
   323    "meta": [
   324      {
   325        "key": "newkey",
   326        "value": "newvalue"
   327      }
   328    ]
   329  }
   330  ```
   331  
   332  ##### Command
   333  
   334  ```sh
   335    curl -s -XPUT -H "Authorization: Bearer abcd.efgh.ijkl" -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/keys/1122aabb/metadata
   336  ```
   337  
   338  ##### Response
   339  
   340  ```json
   341  {
   342    "success": true
   343  }
   344  ```
   345  
   346  ## Commands
   347  
   348  ### Sign a command
   349  
   350  `POST api/v1/command`
   351  
   352  **Authentication required.**
   353  
   354  Sign a Vega command using the specified key pair, and returns the signed
   355  transaction. The key pair must belong to the logged wallet.
   356  
   357  #### Example
   358  
   359  ##### Request
   360  
   361  ```json
   362  {
   363    "pubKey": "1122aabb",
   364    "propagate": true,
   365    "orderCancellation": {
   366      "marketId": "YESYESYES"
   367    }
   368  }
   369  ```
   370  
   371  ##### Command
   372  
   373  ```sh
   374    curl -s -XPOST -H "Authorization: Bearer abcd.efgh.ijkl" -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/command
   375  ```
   376  
   377  ##### Response
   378  
   379  ```json
   380  {
   381    "transaction": {
   382      "inputData": "dGVzdGRhdG9837420b4b3yb23ybc4o1ui23yEK",
   383      "signature": {
   384        "value": "7f6g9sf8f8s76dfa867fda",
   385        "algo": "vega/ed25519",
   386        "version": 1
   387      },
   388      "from": {
   389        "pubKey": "1122aabb"
   390      },
   391      "version": 1
   392    }
   393  }
   394  ```
   395  
   396  #### Propagate
   397  
   398  In the request payload, when the `propagate` field can be set to true, the
   399  wallet service send the transaction on your behalf to the registered nodes after
   400  signing it successfully.
   401  
   402  ### Sign data
   403  
   404  `POST api/v1/sign`
   405  
   406  **Authentication required.**
   407  
   408  Sign any base64-encoded data using the specified key pair, and returns the
   409  signed transaction. The key pair must belong to the logged wallet.
   410  
   411  #### Example
   412  
   413  ##### Request
   414  
   415  ```json
   416  {
   417    "inputData": "dGVzdGRhdGEK==",
   418    "pubKey": "1122aabb"
   419  }
   420  ```
   421  
   422  ##### Command
   423  
   424  ```sh
   425    curl -s -XPOST -H "Authorization: Bearer abcd.efgh.ijkl" -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/sign
   426  ```
   427  
   428  ##### Response
   429  
   430  ```json
   431  {
   432    "hexSignature": "0xhafdsf86df876af",
   433    "base64Signature": "fad7h34k1jh3g413g=="
   434  }
   435  ```
   436  
   437  ### Verify data
   438  
   439  `POST api/v1/verify`
   440  
   441  Verify any base64-encoded data using the specified public key, and returns the
   442  confirmation.
   443  
   444  #### Example
   445  
   446  ##### Request
   447  
   448  ```json
   449  {
   450    "inputData": "dGVzdGRhdGEK==",
   451    "pubKey": "1122aabb"
   452  }
   453  ```
   454  
   455  ##### Command
   456  
   457  ```sh
   458    curl -s -XPOST -H "Authorization: Bearer abcd.efgh.ijkl" -d 'YOUR_REQUEST' http://127.0.0.1:1789/api/v1/sign
   459  ```
   460  
   461  ##### Response
   462  
   463  ```json
   464  {
   465    "hexSignature": "0xhafdsf86df876af",
   466    "base64Signature": "fad7h34k1jh3g413g=="
   467  }
   468  ```