mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-15 04:41:10 -05:00
🐛 fix: Refactor toB64 function to toB64Url for URL-safe base64 encoding in VlessX25519Pair generation
This commit is contained in:
parent
ebcebd7ddf
commit
8700cf6a91
@ -1,11 +1,13 @@
|
|||||||
import { x25519 } from '@noble/curves/ed25519';
|
import { x25519 } from '@noble/curves/ed25519';
|
||||||
|
|
||||||
const toB64 = (u8: Uint8Array): string => {
|
const toB64Url = (u8: Uint8Array) =>
|
||||||
if (typeof Buffer !== 'undefined') return Buffer.from(u8).toString('base64');
|
(typeof Buffer !== 'undefined'
|
||||||
let s = '';
|
? Buffer.from(u8).toString('base64')
|
||||||
for (const b of u8) s += String.fromCharCode(b);
|
: btoa(String.fromCharCode(...u8))
|
||||||
return btoa(s);
|
)
|
||||||
};
|
.replace(/\+/g, '-')
|
||||||
|
.replace(/\//g, '_')
|
||||||
|
.replace(/=+$/g, '');
|
||||||
|
|
||||||
export type VlessX25519Pair = {
|
export type VlessX25519Pair = {
|
||||||
passwordB64: string;
|
passwordB64: string;
|
||||||
@ -15,7 +17,7 @@ export type VlessX25519Pair = {
|
|||||||
export function generateVlessX25519Pair(): VlessX25519Pair {
|
export function generateVlessX25519Pair(): VlessX25519Pair {
|
||||||
const { secretKey, publicKey } = x25519.keygen();
|
const { secretKey, publicKey } = x25519.keygen();
|
||||||
return {
|
return {
|
||||||
passwordB64: toB64(publicKey),
|
passwordB64: toB64Url(publicKey),
|
||||||
privateKeyB64: toB64(secretKey),
|
privateKeyB64: toB64Url(secretKey),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user