53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
import { argv } from 'node:process';
|
|
|
|
import express from 'express';
|
|
import _sodium from "libsodium-wrappers";
|
|
|
|
// import fetch from 'node-fetch';
|
|
// async function loadDirectory(directoryUrl) {
|
|
// const response = await fetch(directoryUrl);
|
|
// const list = await response.json();
|
|
// // munge to obj with id for key
|
|
|
|
// var returnObj = {};
|
|
// list.forEach((agent, idx) => {
|
|
// const id = agent.id;
|
|
// returnObj[id] = agent;
|
|
// });
|
|
// return returnObj;
|
|
// }
|
|
|
|
|
|
// 0 is node, 1 is script, 2 is hex-encoded verify key; would have an arg parser here but chaos reigns
|
|
if (argv.length != 3) {
|
|
console.log("specify hex-encoded verify key as argument.")
|
|
} else {
|
|
console.log("waiting for nacl...");
|
|
await _sodium.ready;
|
|
const sodium = _sodium;
|
|
|
|
console.log(argv[2]);
|
|
const verifyKey = Buffer.from(argv[2], 'hex');
|
|
|
|
console.log("starting express server...")
|
|
const app = express();
|
|
|
|
app.use(express.raw());
|
|
|
|
app.post('/v1/agent/:id', (req, res) => {
|
|
const agent_id = req.params.id;
|
|
|
|
const opened = Buffer.from(sodium.crypto_sign_open(req.body, verifyKey));
|
|
const loaded = JSON.parse(opened.toString("utf-8"));
|
|
console.log(loaded);
|
|
|
|
return res.status(200).send({
|
|
token: "fake-token-do-not-use"
|
|
});
|
|
});
|
|
|
|
app.listen(9000, () => {
|
|
console.log("listening on http://127.0.0.1:9000/");
|
|
});
|
|
}
|