import { createKeyPairFromBytes, createKeyPairSignerFromBytes } from "@solana/kit";

const keypair = await crypto.subtle.generateKey(
    { name: "Ed25519" },
    true,
    ["sign", "verify"]
)

const privateKeyJwk = await crypto.subtle.exportKey('jwk', keypair.privateKey)

const privateKeyBase64 = privateKeyJwk.d

if(!privateKeyBase64) throw new Error('Failed to get private key bytes')

const privateKeyBytes = new Uint8Array(Buffer.from(privateKeyBase64, 'base64'))

const publicKeyBytes = new Uint8Array(await crypto.subtle.exportKey('raw', keypair.publicKey))

const keypairBytes = new Uint8Array([...privateKeyBytes, ...publicKeyBytes])

const signer = await createKeyPairSignerFromBytes(keypairBytes)

console.log(`You have generated a new Solana Wallet: ${signer.address}`)

// Save Wallet 

console.log(`For saving wallet, Copy paste into JSON file : [${keypairBytes}]`)

Output

Screenshot 2025-10-06 at 5.45.09 AM.png

wallet address :

AfzDi5cqnjWFfgXaUTu6YeGJSXFwQdSChWubrpw4CsGv

keypair_bytes

[140,151,91,100,22,28,179,108,237,85,69,151,148,66,108,241,16,117,6,120,208,104,245,146,65,76,56,156,235,114,208,203,143,181,243,112,101,204,219,212,247,27,206,36,56,170,163,211,113,178,55,54,158,72,210,48,190,15,159,1,113,109,33,139]

Explaination

🔹 1. Import the signer utility

import { createKeyPairSignerFromBytes } from "@solana/kit";