vegaprotocol/api

JS/TS: Implement walletclient

Opened this issue · 0 comments

At the moment, we have;

  • in the Console: src/contexts/wallet/ ts and tsx files
  • in this repo:
    • python walletclient: https://github.com/vegaprotocol/api/blob/develop/grpc/clients/python/vegaapiclient/walletclient.py
    • (in tests) javascript clunky wallet_server_login function
      function wallet_server_login(walletServerURL, walletName, walletPassphrase) {
      var request = new xhr.XMLHttpRequest();
      var token;
      request.onload = function () {
      if (request.status !== 200) {
      throw "Failed to log in to wallet server: HTTP " + request.status + " " + request.responseText;
      }
      var j = JSON.parse(request.responseText);
      if (j === undefined) {
      throw "Failed to get parse response JSON: " + request.responseText;
      }
      token = j.token;
      if (token === undefined) {
      throw "Failed to get token from response body: " + request.responseText;
      }
      }
      request.open("POST", walletServerURL + "/api/v1/auth/token", true);
      request.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
      request.send(JSON.stringify({wallet: walletName, passphrase: walletPassphrase}, null, 2));
      return token;
      }

Task

Implement walletclient in Javascript/Typescript so it can be used by tests in this repo, as well as by other users of the api package (perhaps possibly the Console).