Skip to content

Commit

Permalink
chore: commented performance testing code for X25519 key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
kastov committed Mar 7, 2025
1 parent 3432673 commit b370bd8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/modules/subscription/utils/format-hosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,30 @@ export class FormatHosts {
const realitySettings = inbound.streamSettings?.realitySettings;
sniFromConfig = realitySettings?.serverNames?.[0];
fingerprintFromConfig = realitySettings?.fingerprint;

// try {
// const configPrivateKey = realitySettings!.privateKey;

// for (let i = 0; i < 100; i++) {
// console.time('genPublicKeyNodeCrypto');
// const { publicKey } = this.createX25519KeyPairFromBase64(
// configPrivateKey!,
// );
// const base64PublicKey = publicKey
// .export({
// format: 'der',
// type: 'spki',
// })
// .toString('base64url');

// console.timeEnd('genPublicKeyNodeCrypto');
// }
// } catch (error) {
// console.log(error);
// }

publicKeyFromConfig = realitySettings?.publicKey;

spiderXFromConfig = realitySettings?.spiderX;
const shortIds = inbound.streamSettings?.realitySettings?.shortIds || [];
shortIdFromConfig =
Expand Down Expand Up @@ -268,4 +291,29 @@ export class FormatHosts {
return [];
}
}

// private createX25519KeyPairFromBase64(base64PrivateKey: string) {
// try {
// const rawPrivateKey = Buffer.from(base64PrivateKey, 'base64');

// const jwkPrivateKey = {
// kty: 'OKP',
// crv: 'X25519',
// d: Buffer.from(rawPrivateKey).toString('base64url'),
// x: '', // This will be computed by createPrivateKey
// };

// const privateKey = createPrivateKey({
// key: jwkPrivateKey,
// format: 'jwk',
// });

// const publicKey = createPublicKey(privateKey);

// return { privateKey, publicKey };
// } catch (error) {
// console.error('Error converting Base64 to X25519 key pair:', error);
// throw error;
// }
// }
}

0 comments on commit b370bd8

Please sign in to comment.