chore: license server updates and tests

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-05-11 22:20:21 +08:00
parent 4a0523f309
commit d595f4ca5a
6 changed files with 66 additions and 18 deletions
+2 -16
View File
@@ -1,10 +1,11 @@
import { createPrivateKey, randomUUID, sign } from 'node:crypto';
import { randomUUID } from 'node:crypto';
import fs from 'node:fs';
import http from 'node:http';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { canonicalJson } from '../lib/canonicalJson.mjs';
import { signPayload } from '../lib/signPayload.mjs';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(__dirname, '..');
@@ -20,21 +21,6 @@ function writeData(data) {
fs.writeFileSync(p, `${JSON.stringify(data, null, 2)}\n`, 'utf8');
}
function b64url(buf) {
return Buffer.from(buf)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/u, '');
}
function signPayload(payload, privateKeyPem) {
const key = createPrivateKey(privateKeyPem);
const body = canonicalJson(payload);
const sig = sign(null, Buffer.from(body, 'utf8'), key);
return `${b64url(Buffer.from(body, 'utf8'))}.${b64url(sig)}`;
}
function json(res, code, obj) {
const body = JSON.stringify(obj);
res.writeHead(code, {