@tidecloak/js
Version:
TideCloak client side JS SDK
51 lines • 2.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Ed25519_js_1 = require("../../Cryptide/Ed25519.js");
const NodeClient_js_1 = __importDefault(require("../../Clients/NodeClient.js"));
const VoucherClient_js_1 = __importDefault(require("../../Clients/VoucherClient.js"));
const VoucherResponse_js_1 = __importDefault(require("../../Models/Responses/Vendor/VoucherResponse.js"));
const Utils_js_1 = require("../../Tools/Utils.js");
const TideKey_js_1 = __importDefault(require("../../Cryptide/TideKey.js"));
const Ed25519Scheme_js_1 = __importDefault(require("../../Cryptide/Components/Schemes/Ed25519/Ed25519Scheme.js"));
class VoucherFlow {
/**
* @param {Point[]} orkPaymentPublics
* @param {string} voucherURL
* @param {string} action
*/
constructor(orkPaymentPublics, voucherURL, action) {
this.orkPaymentPublics = orkPaymentPublics;
this.voucherURL = voucherURL;
this.action = action;
}
/**
* I'm making this so I can use keycloak's client that has all of the keycloak's authorization built in.
* @param {(request: string) => Promise<string>} clientFunction
* @returns
*/
async GetVouchers(clientFunction = null) {
let vouchers = undefined;
const k = TideKey_js_1.default.NewKey(Ed25519Scheme_js_1.default);
const blurKeyPub = await k.prepVouchersReq(this.orkPaymentPublics);
if (clientFunction == null) {
// get vouchers
const vendorClient = new VoucherClient_js_1.default(this.voucherURL);
vouchers = await vendorClient.GetVouchers(blurKeyPub, this.action, k.get_public_component().public);
}
else {
const request = JSON.stringify({
BlurPORKi: blurKeyPub.map(blur => blur.toBase64()),
ActionRequest: this.action,
BlurerK: k.get_public_component().public.toBase64()
});
const response = await clientFunction(request);
vouchers = VoucherResponse_js_1.default.from(response, k.get_public_component().public.toBase64());
}
return { vouchers, k };
}
}
exports.default = VoucherFlow;
//# sourceMappingURL=VoucherFlow.js.map