X25519 Playground

Generate Two X25519 key pairs

  

PubkeyA:

PrivatekeyA:

PubkeyB:

PrivatekeyB:

  

ShareKey:

JavaScript CodeDemo

yarn add @noble/ed25519
# or
npm install @noble/ed25519
// Common.js and ECMAScript Modules (ESM)
import * as ed from '@noble/ed25519';
const ByteArrayToHexString = (byteArray: Uint8Array) => {
return Array.from(byteArray, function (byte) {
return ('0' + (byte & 0xff).toString(16)).slice(-2);
}).join('');
};
const GenerateX25519KeyPair = async (exportType: string) => {
let privateObj = ed.utils.randomPrivateKey();
let pubkeyObj = ed.curve25519.scalarMultBase(privateObj);
let PrivateKey = '',
PublicKey = '';
if (exportType == 'base64') {
PrivateKey = Uint8ToBase64String(privateObj);
PublicKey = Uint8ToBase64String(pubkeyObj);
} else if ((exportType = 'hex')) {
// PrivateKey = ByteArrayToHexString(privateObj);
PrivateKey = ed.utils.bytesToHex(privateObj);
PublicKey = ed.utils.bytesToHex(pubkeyObj);
}
return {
PrivateKey,
PublicKey,
};
};