Initial commit

This commit is contained in:
2026-04-05 15:28:04 +02:00
commit 0435b3d07d
43 changed files with 4394 additions and 0 deletions

32
shared/auth.js Normal file
View File

@@ -0,0 +1,32 @@
const path = require('path');
const { authNodesDir } = require('./paths');
const { readJsonIfExists, writeJson } = require('./fs');
function nodeTokenPath(nodeId) {
return path.join(authNodesDir, `${nodeId}.json`);
}
async function getNodeToken(nodeId) {
return readJsonIfExists(nodeTokenPath(nodeId));
}
async function verifyNodeToken(nodeId, token) {
const record = await getNodeToken(nodeId);
return Boolean(record && record.node_id === nodeId && record.token === token);
}
async function saveNodeToken(nodeId, token) {
await writeJson(nodeTokenPath(nodeId), {
node_id: nodeId,
token,
schema_version: 'v1',
updated_at: new Date().toISOString(),
});
}
module.exports = {
getNodeToken,
verifyNodeToken,
saveNodeToken,
};