@tidecloak/js
Version:
TideCloak client side JS SDK
73 lines • 3.95 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_js_1 = require("../../Cryptide/index.js");
const BaseTideRequest_js_1 = __importDefault(require("../../Models/BaseTideRequest.js"));
const Utils_js_1 = require("../../Tools/Utils.js");
const NodeClient_js_1 = __importDefault(require("../../Clients/NodeClient.js"));
const OrkInfo_js_1 = __importDefault(require("../../Models/Infos/OrkInfo.js"));
const KeySigning_js_1 = require("../../Math/KeySigning.js");
const Serialization_js_1 = require("../../Cryptide/Serialization.js");
const VoucherFlow_js_1 = __importDefault(require("../VoucherFlows/VoucherFlow.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 dVVKSigningFlow {
/**
* @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) {
if (!doken.payload.sessionKey.Equals(sessKey.get_public_component()))
throw Error("Mismatch between session key private and Doken session key public");
this.doken = doken.serialize();
}
this.sessKey = sessKey;
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).EnableTideDH(info.orkPublic));
const voucherFlow = new VoucherFlow_js_1.default(this.orks.map(o => o.orkPaymentPublic), this.voucherURL, "vendorsign");
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_PreSignResponses = clients.map((client, i) => client.PreSign(i, this.vvkid, request, vouchers.toORK(i)));
const { fulfilledResponses, bitwise } = await (0, Utils_js_1.WaitForNumberofORKs)(this.orks, pre_PreSignResponses, "VVK", waitForAll ? Utils_js_1.Max : Utils_js_1.Threshold, null, clients);
const GRj = (0, KeySigning_js_1.PreSign)(fulfilledResponses);
const pre_SignResponses = clients.map(client => client.Sign(this.vvkid, request, GRj, (0, Serialization_js_1.serializeBitArray)(bitwise)));
const SignResponses = await Promise.all(pre_SignResponses);
const Sj = (0, KeySigning_js_1.Sign)(SignResponses);
if (GRj.length != Sj.length)
throw Error("Weird amount of GRjs and Sjs");
let sigs = [];
for (let i = 0; i < GRj.length; i++) {
sigs.push((0, Serialization_js_1.ConcatUint8Arrays)([GRj[i].toRawBytes(), (0, Serialization_js_1.BigIntToByteArray)(Sj[i])]));
}
return sigs;
}
}
exports.default = dVVKSigningFlow;
//# sourceMappingURL=dVVKSigningFlow.js.map