подготовка к билду

This commit is contained in:
Ivan Fontosh
2026-04-19 23:22:05 +08:00
parent 2fa20da94d
commit 726c89e104
13 changed files with 180 additions and 13 deletions
+16 -1
View File
@@ -1,5 +1,13 @@
/** Убирает переносы/неразрывные пробелы из вставки из почты и мессенджеров (иначе `malformed`). */
export function normalizeLicenseTokenInput(token: string): string {
return token.replace(/[\s\u00a0\u200b-\u200d\ufeff\u2028\u2029]+/gu, '').trim();
}
const B64URL = {
encode(bytes: Uint8Array): string {
if (typeof Buffer !== 'undefined') {
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64url');
}
let bin = '';
for (const byte of bytes) {
bin += String.fromCharCode(byte);
@@ -8,6 +16,13 @@ const B64URL = {
return b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/u, '');
},
decode(s: string): Uint8Array {
if (typeof Buffer !== 'undefined') {
try {
return new Uint8Array(Buffer.from(s, 'base64url'));
} catch {
/* fall through */
}
}
const pad = s.length % 4 === 0 ? '' : '='.repeat(4 - (s.length % 4));
const b64 = s.replace(/-/g, '+').replace(/_/g, '/') + pad;
const bin = atob(b64);
@@ -19,7 +34,7 @@ const B64URL = {
/** Тело UTF-8 + подпись Ed25519 (64 байта), разделитель «.». */
export function splitSignedLicenseToken(token: string): { bodyUtf8: string; signature: Uint8Array } | null {
const t = token.trim();
const t = normalizeLicenseTokenInput(token);
const dot = t.indexOf('.');
if (dot <= 0) return null;
const a = t.slice(0, dot);