first commit

This commit is contained in:
2026-07-16 20:48:43 -03:00
commit 5696cee264
1111 changed files with 322270 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
export const getApiHost = () => {
return process.env.API_HOST || "http://localhost:3000";
};
+22
View File
@@ -0,0 +1,22 @@
import { INonce } from "src/models/Nonce.Model";
import crypto from "crypto";
import fs from "fs";
import path from "path";
import { IPayload } from "src/models/Payload.Model";
export const getPayload = (nonce: INonce): IPayload => {
const privateKeyPath = path.resolve(process.cwd(), process.env.API_PRIVATE_KEY || "");
const privateKey = fs.readFileSync(privateKeyPath);
const signature = crypto.sign(
null, // Ed25519 no usa hash explícito
Buffer.from(nonce.nonce), // mensaje a firmar
privateKey,
);
const payload: IPayload = {
nonce,
signature: signature.toString("base64"),
};
return payload;
};
+26
View File
@@ -0,0 +1,26 @@
import axios from "axios";
import { INonce } from "src/models/Nonce.Model";
import { getApiHost } from "./GetApiHost";
export const getSysAdminNonce = async (): Promise<INonce> => {
try {
const response = await axios.get<INonce>(`${getApiHost()}/sysadmin-challenges/create`, {
headers: {
"Content-Type": "application/json",
},
});
if (response.status !== 201) {
throw new Error("Ha ocurrido un error al generar el nonce, por favor intente nuevamente.");
}
if (!response.data) {
throw new Error("Ha ocurrido un error al generar el nonce, por favor intente nuevamente.");
}
return response.data as INonce;
} catch (e) {
console.error(e);
throw new Error("Ha ocurrido un error al generar el nonce, por favor intente nuevamente.");
}
};