mirror of
https://github.com/perfect-panel/ppanel-web.git
synced 2026-02-15 21:01:10 -05:00
24 lines
573 B
TypeScript
24 lines
573 B
TypeScript
import { x25519 } from '@noble/curves/ed25519';
|
|
|
|
const toB64Url = (u8: Uint8Array) =>
|
|
(typeof Buffer !== 'undefined'
|
|
? Buffer.from(u8).toString('base64')
|
|
: btoa(String.fromCharCode(...u8))
|
|
)
|
|
.replace(/\+/g, '-')
|
|
.replace(/\//g, '_')
|
|
.replace(/=+$/g, '');
|
|
|
|
export type VlessX25519Pair = {
|
|
passwordB64: string;
|
|
privateKeyB64: string;
|
|
};
|
|
|
|
export function generateVlessX25519Pair(): VlessX25519Pair {
|
|
const { secretKey, publicKey } = x25519.keygen();
|
|
return {
|
|
passwordB64: toB64Url(publicKey),
|
|
privateKeyB64: toB64Url(secretKey),
|
|
};
|
|
}
|