Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

966 B
Raw Blame
import {
    generateKeyPair as generateKeyPairCallback,
    RSAKeyPairOptions,
} from 'node:crypto'
import { promisify } from 'node:util'
import { KeyAlgorithm } from '@activepieces/shared'

const generateKeyPair = promisify(generateKeyPairCallback)

export const signingKeyGenerator = {
    async generate(): Promise<GeneratedKeyPair> {
        const algorithm = 'rsa'

        const options: RSAKeyPairOptions<'pem', 'pem'> = {
            modulusLength: 4096,
            publicKeyEncoding: {
                type: 'pkcs1',
                format: 'pem',
            },
            privateKeyEncoding: {
                type: 'pkcs1',
                format: 'pem',
            },
        }

        const keyPair = await generateKeyPair(algorithm, options)

        return {
            ...keyPair,
            algorithm: KeyAlgorithm.RSA,
        }
    },
}

type GeneratedKeyPair = {
    privateKey: string
    publicKey: string
    algorithm: KeyAlgorithm
}