feat: generate key pair function

This commit is contained in:
Justin Lin committed 2024-10-14 10:53:15 +08:00
1 parent 2a3429106c
commit 2cc348687a
2 files changed
+29

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
import { generateKeyPairSync } from 'crypto'
type KeyPair = {
privateKey: string
publicKey: string
}
export function generateKeyPair(): KeyPair {
const { privateKey, publicKey } = generateKeyPairSync('ed25519', {
publicKeyEncoding: {
type: 'spki',
format: 'pem',
},
privateKeyEncoding: {
type: 'pkcs8',
format: 'pem',
},
})
return { privateKey, publicKey }
}