@tidecloak/js
Version:
TideCloak client side JS SDK
95 lines • 5.35 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 NodeClient_js_1 = __importDefault(require("../Clients/NodeClient.js"));
//TODO: //import { MarkParticipatingORKs } from "../Tools/Utils.js";
const OrkInfo_js_1 = __importDefault(require("../Models/Infos/OrkInfo.js"));
const Utils_js_1 = require("../Tools/Utils.js");
const index_js_1 = require("../index.js");
const Ed25519_js_1 = require("../Cryptide/Ed25519.js");
const index_js_2 = require("../Cryptide/index.js");
const Serialization_js_1 = require("../Cryptide/Serialization.js");
const Math_js_1 = require("../Cryptide/Math.js");
const dCMKPasswordFlow_js_1 = __importDefault(require("./AuthenticationFlows/dCMKPasswordFlow.js"));
const VoucherFlow_js_1 = __importDefault(require("./VoucherFlows/VoucherFlow.js"));
const KeyInfo_js_1 = __importDefault(require("../Models/Infos/KeyInfo.js"));
const TideKey_js_1 = __importDefault(require("../Cryptide/TideKey.js"));
class dAccountRecoveryFlow {
/**
* @param {string} uid
* @param {OrkInfo[]} orks
* @param {TideKey} sessKey
* @param {string} voucherURL
*/
constructor(uid, orks, sessKey, voucherURL) {
// NOTE: User will only EVER click threshold orks, so for keyGen all of those 14 orks MUST be up. An ork cannot go
// down between email sending and key recreation. Otherwise process must start again.
this.uid = uid;
this.orks = orks;
this.sessKey = sessKey;
this.voucherURL = voucherURL;
this.rState = undefined;
}
async StartAccountRecovery(homeOrkUrl, pollingClient, signal) {
const channelId = await pollingClient.EstablishHttpTunnel(this.uid, this.orks.map(o => o.orkID));
const clients = this.orks.map(ork => new NodeClient_js_1.default(ork.orkURL)); // create node clients
const voucherFlow = new VoucherFlow_js_1.default(this.orks.map(o => o.orkPaymentPublic), this.voucherURL, "updateaccount");
const { vouchers } = await voucherFlow.GetVouchers();
// Here we also find out which ORKs are up
const pre_ConvertResponses = clients.map((client, i) => client.RecoverAccount(i, this.uid, this.sessKey.get_public_component().public, channelId, homeOrkUrl, vouchers.toORK(i)));
await (0, Utils_js_1.WaitForNumberofORKs)(this.orks.slice(), pre_ConvertResponses, "CMK", null, null, null, 30000); // we DON'T want to modify the orks array for this specific flow - we need it in full for the key gen flow below
if (signal.aborted) {
return { status: "cancelled" };
}
return { channelId };
}
/**
* @returns
*/
async RetrieveEmailAuths(channelId, progressTrackerCallback, pollingClient, signal) {
// Start the long polling requests
const { encRequests, bitwise, status } = await pollingClient.pollServer(channelId, progressTrackerCallback, signal);
if (status === "recovered") {
const pre_decData = encRequests.map(async (request) => (0, Serialization_js_1.bytesToBase64)(await index_js_2.ElGamal.decryptData(request, this.sessKey.get_private_component().rawBytes)));
const selfRequesti = await Promise.all(pre_decData);
const expiry = (0, Utils_js_1.CurrentTime)() + 3580;
this.rState = {
bitwise,
selfRequesti,
expiry,
};
}
// return the status, "recovered" or "cancelled"
return { status };
}
/**
* @param {Point} currentUserPublic
* @param {Point} newGPass
* @param {Point} gVRK
*/
async GenerateNewPrism(currentUserPublic, newGPass, gVRK) {
if (this.rState == undefined)
throw Error("RState must be defined first");
if (this.rState.expiry < (0, Utils_js_1.CurrentTime)())
throw Error("Took too long to open emails.");
const newPrismFlow = new index_js_1.dKeyGenerationFlow(this.uid, gVRK.toBase64(), this.orks, this.sessKey.get_private_component().rawBytes, this.sessKey.get_public_component().public, "RECOVER", this.voucherURL, null, this.rState.bitwise, this.rState.selfRequesti, currentUserPublic, this.rState.expiry);
const { gMultiplied } = await newPrismFlow.GenShard(1, [newGPass]);
const newGPrismAuth = await (0, Math_js_1.CreateGPrismAuth)(gMultiplied[0]);
const keyM = await newPrismFlow.SetShard(newGPrismAuth.toBase64(), "Prism");
const keyInfo = new KeyInfo_js_1.default(this.uid, currentUserPublic, keyM, this.orks);
// test new account
const testAuthFlow = new dCMKPasswordFlow_js_1.default(keyInfo, "TEST SESSION", true, false, this.voucherURL);
await testAuthFlow.Convert(this.sessKey, newGPass, currentUserPublic, false);
await testAuthFlow.Authenticate(gVRK);
await newPrismFlow.Commit();
}
async CleanUpRecoverySession(channelId) {
const homeOrkUrl = window.location.origin;
const homeOrkClient = new NodeClient_js_1.default(homeOrkUrl);
await homeOrkClient.FinalizeAccountRecovery(this.uid, channelId);
}
}
exports.default = dAccountRecoveryFlow;
//# sourceMappingURL=dAccountRecoveryFlow.js.map