@tidecloak/js
Version:
TideCloak client side JS SDK
113 lines • 6.29 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CMKAuth_Basic = CMKAuth_Basic;
exports.CMKAuth_Remembered = CMKAuth_Remembered;
const OrkInfo_js_1 = __importDefault(require("../Models/Infos/OrkInfo.js"));
const H2P_js_1 = __importDefault(require("../Cryptide/Hashing/H2P.js"));
const index_js_1 = require("../Cryptide/index.js");
const Hash_js_1 = require("../Cryptide/Hashing/Hash.js");
const dCMKPasswordFlow_js_1 = __importDefault(require("../Flow/AuthenticationFlows/dCMKPasswordFlow.js"));
const dCMKPasswordlessFlow_js_1 = __importDefault(require("../Flow/AuthenticationFlows/dCMKPasswordlessFlow.js"));
const dKeyGenerationFlow_js_1 = __importDefault(require("../Flow/dKeyGenerationFlow.js"));
const index_js_2 = require("../Cryptide/index.js");
const Math_js_1 = require("../Cryptide/Math.js");
const EnclaveEntry_js_1 = __importDefault(require("../Models/EnclaveEntry.js"));
const KeyInfo_js_1 = __importDefault(require("../Models/Infos/KeyInfo.js"));
const NetworkClient_js_1 = __importDefault(require("../Clients/NetworkClient.js"));
const Utils_js_1 = require("../Tools/Utils.js");
async function CMKAuth_Basic() {
// basic username, password test flow
var orks;
let i = 0;
while (i < 1) {
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);
const sessID = "123ID";
const VRK = BigInt(123456789);
const gVRK = (0, Math_js_1.GetPublic)(VRK);
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, gVRK.toBase64(), orks, sessKey, gSessKey, purpose, "http://host.docker.internal:3000/voucher/new", emails);
const { gMultiplied, gK } = await genFlow.GenShard(2, [null, gPass], reservationConfirmation); // auths can be null if purpose is "new", for now...
GK = gK;
const gPrismAuth = await (0, Math_js_1.CreateGPrismAuth)(gMultiplied[1]);
await genFlow.SetShard(gPrismAuth.toBase64(), "CMK");
await genFlow.Commit();
};
const authenticate = async () => {
const keyInfo = await new NetworkClient_js_1.default("http://host.docker.internal:1001").GetKeyInfo(uid);
const dAuthFlow = new dCMKPasswordFlow_js_1.default(keyInfo, sessID, true, true, "http://host.docker.internal:3000/voucher/new");
await dAuthFlow.Convert(sessKey, gSessKey, gPass, GK, true);
await dAuthFlow.Authenticate(gSessKey); // gVRK can be anything for testing
};
await create();
await authenticate();
console.log("CMKAuth_Basic TEST SUCCESSFUL: " + i);
i++;
}
}
async function CMKAuth_Remembered() {
// authentication flow, provided valid EnclaveEntry (no password required)
var orks;
let i = 0;
while (i < 1) {
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);
const sessID = "123ID";
const VRK = BigInt(123456789);
const gVRK = (0, Math_js_1.GetPublic)(VRK);
let GK;
let keyM;
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, gVRK.toBase64(), 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...
GK = gK;
const gPrismAuth = await (0, Math_js_1.CreateGPrismAuth)(gMultiplied[1]);
await genFlow.SetShard(gPrismAuth.toBase64(), "CMK");
await genFlow.Commit();
};
const authenticate = async () => {
const keyInfo = await new NetworkClient_js_1.default("http://localhost:1001").GetKeyInfo(uid);
const dAuthFlow = new dCMKPasswordFlow_js_1.default(keyInfo, sessID, true, true, "http://localhost:3000/voucher/new");
await dAuthFlow.Convert(sessKey, gSessKey, gPass, GK, true);
const { bitwise, expired, selfRequesti } = await dAuthFlow.Authenticate(gSessKey); // gVRK can be anything for testing
const userInfo = new KeyInfo_js_1.default(uid, GK, keyInfo.UserM, orks);
const auth = new EnclaveEntry_js_1.default(user, "1", BigInt(expired), userInfo, bitwise, selfRequesti, sessKey);
return auth;
};
const authenticateNoPassword = async (auth) => {
const noPassFlow = new dCMKPasswordlessFlow_js_1.default(sessID, auth, "http://localhost:3000/voucher/new");
await noPassFlow.ConvertRemembered();
await noPassFlow.AuthenticateRemembered(gSessKey);
};
await create();
const auth = await authenticate();
await authenticateNoPassword(auth);
console.log("CMKAuth_Remembered TEST SUCCESSFUL: " + i);
i++;
}
}
//# sourceMappingURL=KeyAuthentication.js.map