From 38f6d9a785929006e3de45936d6e351a00991f44 Mon Sep 17 00:00:00 2001 From: im47cn <67424112+im47cn@users.noreply.github.com> Date: Sun, 16 Aug 2026 13:15:50 +0000 Subject: [PATCH] fix(server): use privacyKit.encodeBase64 in randomKey utilities Per repository convention (privacyKit over Buffer for base64), replace Buffer.toString('base64') with privacyKit.encodeBase64 in randomKey and randomKeyNaked. Output format verified unchanged at runtime. --- packages/happy-server/sources/utils/randomKey.ts | 3 ++- packages/happy-server/sources/utils/randomKeyNaked.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/happy-server/sources/utils/randomKey.ts b/packages/happy-server/sources/utils/randomKey.ts index 8b8a81606f..ea9ec110e0 100644 --- a/packages/happy-server/sources/utils/randomKey.ts +++ b/packages/happy-server/sources/utils/randomKey.ts @@ -1,9 +1,10 @@ import * as crypto from 'crypto'; +import * as privacyKit from 'privacy-kit'; export function randomKey(prefix: string, length: number = 24): string { while (true) { const randomBytesBuffer = crypto.randomBytes(length * 2); - const normalized = randomBytesBuffer.toString('base64').replace(/[^a-zA-Z0-9]/g, ''); + const normalized = privacyKit.encodeBase64(randomBytesBuffer).replace(/[^a-zA-Z0-9]/g, ''); if (normalized.length < length) { continue; } diff --git a/packages/happy-server/sources/utils/randomKeyNaked.ts b/packages/happy-server/sources/utils/randomKeyNaked.ts index ba5b5b28e1..8c25fede54 100644 --- a/packages/happy-server/sources/utils/randomKeyNaked.ts +++ b/packages/happy-server/sources/utils/randomKeyNaked.ts @@ -1,9 +1,10 @@ import * as crypto from 'crypto'; +import * as privacyKit from 'privacy-kit'; export function randomKeyNaked(length: number = 24): string { while (true) { const randomBytesBuffer = crypto.randomBytes(length * 2); - const normalized = randomBytesBuffer.toString('base64').replace(/[^a-zA-Z0-9]/g, ''); + const normalized = privacyKit.encodeBase64(randomBytesBuffer).replace(/[^a-zA-Z0-9]/g, ''); if (normalized.length < length) { continue; }