diff --git a/server/src/utils/crypto.ts b/server/src/utils/crypto.ts new file mode 100644 index 0000000..ed452e8 --- /dev/null +++ b/server/src/utils/crypto.ts @@ -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 } +} diff --git a/server/tests/utils/crypto.test.ts b/server/tests/utils/crypto.test.ts new file mode 100644 index 0000000..4c4b17f --- /dev/null +++ b/server/tests/utils/crypto.test.ts @@ -0,0 +1,9 @@ +import { generateKeyPair } from '../../src/utils/crypto' + +describe('generateKeyPair', () => { + it('should generate a key pair', () => { + const keyPair = generateKeyPair() + expect(keyPair).toHaveProperty('privateKey') + expect(keyPair).toHaveProperty('publicKey') + }) +})