@tidecloak/js
Version:
TideCloak client side JS SDK
58 lines • 3.21 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Utils_js_1 = require("../../Tools/Utils.js");
const BaseTideRequest_js_1 = __importDefault(require("../../Models/BaseTideRequest.js"));
const NodeClient_js_1 = __importDefault(require("../../Clients/NodeClient.js"));
const VoucherFlow_js_1 = __importDefault(require("../VoucherFlows/VoucherFlow.js"));
const KeyDecryption_js_1 = require("../../Math/KeyDecryption.js");
const Doken_js_1 = require("../../Models/Doken.js");
const Ed25519Components_js_1 = require("../../Cryptide/Components/Schemes/Ed25519/Ed25519Components.js");
const TideKey_js_1 = __importDefault(require("../../Cryptide/TideKey.js"));
class dVVKDecryptionFlow {
/**
* @param {string} vvkid
* @param {Point} vvkPublic
* @param {OrkInfo[]} orks
* @param {TideKey} sessKey
* @param {Doken} doken
* @param {string} voucherURL
*/
constructor(vvkid, vvkPublic, orks, sessKey, doken, voucherURL) {
this.vvkid = vvkid;
this.vvkPublic = vvkPublic;
this.orks = orks;
this.orks = (0, Utils_js_1.sortORKs)(this.orks); // sort for bitwise!
if (!doken.payload.sessionKey.Equals(sessKey.get_public_component()))
throw Error("Mismatch between session key private and Doken session key public");
this.sessKey = sessKey;
this.doken = doken;
this.getVouchersFunction = null;
this.voucherURL = voucherURL;
}
/**
* @param {(request: string) => Promise<string> } getVouchersFunction
* @returns {dVVKSigningFlow}
*/
setVoucherRetrievalFunction(getVouchersFunction) {
this.getVouchersFunction = getVouchersFunction;
return this;
}
/**
* @param {BaseTideRequest} request
* @param {bool} waitForAll
*/
async start(request, waitForAll = false) {
const pre_clients = this.orks.map(info => new NodeClient_js_1.default(info.orkURL).AddBearerAuthorization(this.sessKey.get_private_component().rawBytes, this.sessKey.get_public_component().Serialize().ToString(), this.doken.serialize()).EnableTideDH(info.orkPublic));
const voucherFlow = new VoucherFlow_js_1.default(this.orks.map(o => o.orkPaymentPublic), this.voucherURL, "vendordecrypt");
const { vouchers } = await voucherFlow.GetVouchers(this.getVouchersFunction);
const clients = await Promise.all(pre_clients); // to speed things up - computer shared key while grabbing vouchers
const pre_PreDecryptResponses = clients.map((client, i) => client.Decrypt(i, this.vvkid, request, vouchers.toORK(i)));
const { fulfilledResponses, bitwise } = await (0, Utils_js_1.WaitForNumberofORKs)(this.orks, pre_PreDecryptResponses, "VVK", waitForAll ? Utils_js_1.Max : Utils_js_1.Threshold, null, clients);
return (0, KeyDecryption_js_1.GetKeys)(fulfilledResponses, this.orks.map(o => BigInt(o.orkID))); // to be used for symmetric encryption now with caller
}
}
exports.default = dVVKDecryptionFlow;
//# sourceMappingURL=dVVKDecryptionFlow.js.map