use custom base64encode function to handle UTF8 bytes properly

This commit is contained in:
highperfocused
2025-03-22 13:40:31 +01:00
parent 11aa3f2a14
commit 26cd5f4772

View File

@@ -255,8 +255,21 @@ const UploadComponent: React.FC = () => {
// Sign auth event
const authEventSigned = (await signEvent(loginType, authEvent)) as NostrEvent
// Convert authEventSigned to base64 encoded string without using Buffer
let authString = btoa(JSON.stringify(authEventSigned))
// Custom base64 encoding that handles Unicode characters properly
const base64Encode = (str: string): string => {
// Convert the string to UTF-8 bytes
const bytes = new TextEncoder().encode(str);
// Convert bytes to base64
return btoa(
Array.from(bytes)
.map(byte => String.fromCharCode(byte))
.join('')
);
};
// Convert authEventSigned to base64 encoded string handling Unicode characters
let authString = base64Encode(JSON.stringify(authEventSigned));
const blossomServer = "https://" + serverChoice