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
+18
View File
@@ -0,0 +1,18 @@
import { createPrivateKey, sign } from 'node:crypto';
import { canonicalJson } from './canonicalJson.mjs';
export function b64url(buf) {
return Buffer.from(buf)
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/u, '');
}
export 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)}`;
}