ed25519key
Generate ed25519 key pair
https://github.com/starcoinorg/stc-ed25519
yarn add @starcoin/stc-ed25519
# or
npm install @starcoin/stc-ed25519
// Common.js and ECMAScript Modules (ESM)
import * as ed from '@starcoin/stc-ed25519';
function ByteArrayToHexString(byteArray) {
return Array.from(byteArray, function (byte) {
return ('0' + (byte & 0xff).toString(16)).slice(-2);
}).join('');
}
const GenerateEd25519KeyPair = async () => {
let privateObj = ed.utils.randomPrivateKey();
let pubkeyObj = await ed.getPublicKey(privateObj);
let PrivateKey = ByteArrayToHexString(privateObj);
let PublicKey = ByteArrayToHexString(pubkeyObj);
return {
PrivateKey,
PublicKey,
};
};
const { PrivateKey, PublicKey } = await GenerateEd25519KeyPair();
// ⚠️ Keep your private key in safe place