@tidecloak/js
Version:
TideCloak client side JS SDK
96 lines • 3.98 kB
JavaScript
;
//
// Tide Protocol - Infrastructure for a TRUE Zero-Trust paradigm
// Copyright (C) 2022 Tide Foundation Ltd
//
// This program is free software and is subject to the terms of
// the Tide Community Open Code License as published by the
// Tide Foundation Limited. You may modify it and redistribute
// it in accordance with and subject to the terms of that License.
// This program is distributed WITHOUT WARRANTY of any kind,
// including without any implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
// See the Tide Community Open Code License for more details.
// You should have received a copy of the Tide Community Open
// Code License along with this program.
// If not, see https://tide.org/licenses_tcoc2-0-0-en
//
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const KeyInfo_js_1 = __importDefault(require("../Models/Infos/KeyInfo.js"));
const OrkInfo_js_1 = __importDefault(require("../Models/Infos/OrkInfo.js"));
const ClientBase_js_1 = __importDefault(require("./ClientBase.js"));
class NetworkClient extends ClientBase_js_1.default {
/**
* @param {string} url
*/
constructor(url = null) {
if (url == null)
super(window.location.origin);
else
super(url); // no gaurantee that the home ork will be part of selected orks, we need a selected ork url here for uncommitted entries
}
/**
* @param {string} uid
* @returns {OrkInfo[]}
*/
async FindReservers(uid) {
const response = await this._get(`/Network/Authentication/Users/GetReservers/${uid}`);
try {
const responseData = await this._handleError(response, "Find Reservers");
const formattedResponse = JSON.parse(responseData);
if (formattedResponse.length == 0)
throw Error("Username forbidden");
const returnedResponse = formattedResponse.map(orkEntry => OrkInfo_js_1.default.from(orkEntry));
return returnedResponse;
}
catch (err) {
throw Error(err);
}
}
async GetSomeORKs() {
const response = await this._get('/Network/Authentication/Node/Some');
const responseData = await this._handleError(response, "Get Some Orks");
const formattedResponse = JSON.parse(responseData);
const returnedResponse = formattedResponse.map(orkEntry => {
return OrkInfo_js_1.default.from(orkEntry);
});
return returnedResponse;
}
async GetMaxORKs() {
const response = await this._get('/Network/Authentication/Node/Max');
const responseData = await this._handleError(response, "Get Max Orks");
const formattedResponse = JSON.parse(responseData);
const returnedResponse = formattedResponse.map(orkEntry => {
return OrkInfo_js_1.default.from(orkEntry);
});
return returnedResponse;
}
async GetPayerUrl(payerPublic) {
const response = await this._get(`/Network/Payment/Node/Urls/${payerPublic}`);
const responseData = await this._handleError(response, "Get Some Orks");
const urlArray = JSON.parse(responseData);
const randomUrl = urlArray[Math.floor(Math.random() * urlArray.length)];
return randomUrl;
}
/**
*
* @param {string} uid
* @returns
*/
async GetKeyInfo(uid) {
const response = await this._get(`/Network/Authentication/Users/UserInfo/${uid}`);
let responseData;
try {
responseData = await this._handleError(response, "Get Key Info");
}
catch {
throw Error("simulator.invalidAccount");
}
return KeyInfo_js_1.default.from(responseData);
}
}
exports.default = NetworkClient;
//# sourceMappingURL=NetworkClient.js.map