UNPKG

@tidecloak/js

Version:

TideCloak client side JS SDK

58 lines 3.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmailRecovery = EmailRecovery; const OrkInfo_js_1 = __importDefault(require("../Models/Infos/OrkInfo.js")); const H2P_js_1 = __importDefault(require("../Cryptide/Hashing/H2P.js")); const Hash_js_1 = require("../Cryptide/Hashing/Hash.js"); const index_js_1 = require("../Cryptide/index.js"); const index_js_2 = require("../Cryptide/index.js"); const dKeyGenerationFlow_js_1 = __importDefault(require("../Flow/dKeyGenerationFlow.js")); const dAccountRecoveryFlow_js_1 = __importDefault(require("../Flow/dAccountRecoveryFlow.js")); const Utils_js_1 = require("../Tools/Utils.js"); const EnclaveEntry_js_1 = __importDefault(require("../Models/EnclaveEntry.js")); const Math_js_1 = require("../Cryptide/Math.js"); const KeyInfo_js_1 = __importDefault(require("../Models/Infos/KeyInfo.js")); const PollingClient_js_1 = __importDefault(require("../Clients/PollingClient.js")); const Ed25519_js_1 = require("../Cryptide/Ed25519.js"); async function EmailRecovery() { var orks; const user = Date.now().toString(); const persona = "1"; const emails = ["testEmail1@doge.com"]; const password = "pass"; const gPass = await (0, H2P_js_1.default)(password); const uid = await index_js_1.Serialization.GetUID(user); const sessKey = index_js_2.Math.GenSessKey(); const gSessKey = index_js_2.Math.GetPublic(sessKey); let GK; const create = async () => { // create account first const purpose = "NEW"; const { reservationConfirmation, activeOrks } = (await dKeyGenerationFlow_js_1.default.ReserveUID(uid, "http://localhost:3000/voucher/new", gSessKey)); orks = activeOrks.slice(0, Utils_js_1.Max); const genFlow = new dKeyGenerationFlow_js_1.default(uid, "", orks, sessKey, gSessKey, purpose, "http://localhost:3000/voucher/new", emails); const { gMultiplied, gK } = await genFlow.GenShard(2, [null, gPass], reservationConfirmation); // auths can be null if purpose is "new", for now... const gPrismAuth = await (0, Math_js_1.CreateGPrismAuth)(gMultiplied[1]); GK = gK; await genFlow.SetShard(gPrismAuth, "CMK"); await genFlow.Commit(); }; const recover = async () => { const newPassword = "pass1"; const newgPass = await (0, H2P_js_1.default)(newPassword); const homeOrkUrl = "http://host.docker.internal:1001"; const pollingClient = new PollingClient_js_1.default(homeOrkUrl); const signal = new AbortController().signal; const recoveryFlow = new dAccountRecoveryFlow_js_1.default(uid, orks, sessKey, gSessKey, "http://localhost:3000/voucher/new"); const { channelId, status: startAccountRecoveryStatus } = await recoveryFlow.StartAccountRecovery(homeOrkUrl, pollingClient, signal); await recoveryFlow.RetrieveEmailAuths(channelId, () => { }, pollingClient, signal); await recoveryFlow.GenerateNewPrism(GK, newgPass, Ed25519_js_1.Point.BASE); }; await create(); await recover(); console.log("EmailRecovery TEST SUCCESSFUL"); } //# sourceMappingURL=AccountRecovery.js.map