UNPKG

@unilogin/sdk

Version:

SDK is a JS library, that communicates with relayer. SDK allows managing contract, by creating basic contract-calling messages.

83 lines 3.81 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); var commons_1 = require("@unilogin/commons"); var RelayerApi = /** @class */ (function () { function RelayerApi(relayerUrl, apiKey) { this.apiKey = apiKey; this.http = commons_1.http(commons_1.fetch)(relayerUrl); } RelayerApi.prototype.getHeaders = function () { return this.apiKey ? __assign(__assign({}, commons_1.COMMON_HEADERS), { api_key: this.apiKey }) : commons_1.COMMON_HEADERS; }; RelayerApi.prototype.getConfig = function () { return this.http('GET', '/config'); }; RelayerApi.prototype.execute = function (message) { return this.http('POST', '/wallet/execution', message, this.getHeaders()) .catch(function (e) { // TODO: Maybe wrap this as a custom Error? throw new Error(e !== undefined && e.error); }); }; RelayerApi.prototype.getStatus = function (messageHash) { return this.http('GET', "/wallet/execution/" + messageHash); }; RelayerApi.prototype.connect = function (walletContractAddress, key, applicationInfo) { return this.http('POST', '/authorisation', { walletContractAddress: walletContractAddress, key: key, applicationInfo: applicationInfo, }); }; RelayerApi.prototype.denyConnection = function (authorisationRequest) { var contractAddress = authorisationRequest.contractAddress; return this.http('POST', "/authorisation/" + contractAddress, { authorisationRequest: authorisationRequest, }).catch(function (e) { throw new Error(e.error); }); }; RelayerApi.prototype.getPendingAuthorisations = function (authorisationRequest) { var contractAddress = authorisationRequest.contractAddress, signature = authorisationRequest.signature; return this.http('GET', "/authorisation/" + contractAddress + "?signature=" + signature); }; RelayerApi.prototype.cancelConnection = function (authorisationRequest) { var contractAddress = authorisationRequest.contractAddress; return this.http('DELETE', "/authorisation/" + contractAddress, { authorisationRequest: authorisationRequest }); }; RelayerApi.prototype.getConnectedDevices = function (deviceRequest) { var contractAddress = deviceRequest.contractAddress, signature = deviceRequest.signature; return this.http('GET', "/devices/" + contractAddress + "?signature=" + signature); }; RelayerApi.prototype.deploy = function (publicKey, ensName, gasPrice, gasToken, signature, applicationInfo, contractAddress) { return this.http('POST', '/wallet/deploy', { publicKey: publicKey, ensName: ensName, gasPrice: gasPrice, gasToken: gasToken, signature: signature, applicationInfo: applicationInfo, contractAddress: contractAddress, }, this.getHeaders()); }; RelayerApi.prototype.getDeploymentStatus = function (deploymentHash) { return this.http('GET', "/wallet/deploy/" + deploymentHash); }; RelayerApi.prototype.addFutureWallet = function (storedFutureWallet) { return this.http('POST', '/wallet/future', storedFutureWallet); }; return RelayerApi; }()); exports.RelayerApi = RelayerApi; //# sourceMappingURL=RelayerApi.js.map