chore: license server updates and tests
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+2
-16
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user