hfs
Version:
HTTP File Server
22 lines (21 loc) • 1.2 kB
JavaScript
// This file is part of HFS - Copyright 2021-2023, Massimo Melina <a@rejetto.com> - License https://www.gnu.org/licenses/gpl-3.0.txt
Object.defineProperty(exports, "__esModule", { value: true });
exports.srpClientSequence = srpClientSequence;
exports.srpClientPart = srpClientPart;
const tssrp6a_1 = require("tssrp6a");
async function srpClientSequence(username, password, apiCall, extra) {
const { pubKey, salt } = await apiCall('loginSrp1', { username });
if (!salt)
throw Error('salt');
const client = await srpClientPart(username, password, salt, pubKey);
const res = await apiCall('loginSrp2', { pubKey: String(client.A), proof: String(client.M1), ...extra }); // bigint-s must be cast to string to be json-ed
await client.step3(BigInt(res.proof)).catch(() => Promise.reject('trust'));
return res;
}
async function srpClientPart(username, password, salt, pubKey) {
const srp6aNimbusRoutines = new tssrp6a_1.SRPRoutines(new tssrp6a_1.SRPParameters());
const srpClient = new tssrp6a_1.SRPClientSession(srp6aNimbusRoutines);
const res = await srpClient.step1(username, password);
return await res.step2(BigInt(salt), BigInt(pubKey));
}
;