+// ---------------------------------------------------------------------------
+
+function isOdd (num: number) {
+ return (num % 2) !== 0
+}
+
+function toEven (num: number) {
+ if (isOdd(num)) return num + 1
+
+ return num
+}
+
+// ---------------------------------------------------------------------------
+
+function generateRSAKeyPairPromise (size: number) {
+ return new Promise<{ publicKey: string, privateKey: string }>((res, rej) => {
+ const options: RSAKeyPairOptions<'pem', 'pem'> = {
+ modulusLength: size,
+ publicKeyEncoding: {
+ type: 'spki',
+ format: 'pem'
+ },
+ privateKeyEncoding: {
+ type: 'pkcs1',
+ format: 'pem'
+ }
+ }
+
+ generateKeyPair('rsa', options, (err, publicKey, privateKey) => {
+ if (err) return rej(err)
+
+ return res({ publicKey, privateKey })
+ })
+ })
+}
+
+function generateED25519KeyPairPromise () {
+ return new Promise<{ publicKey: string, privateKey: string }>((res, rej) => {
+ const options: ED25519KeyPairOptions<'pem', 'pem'> = {
+ publicKeyEncoding: {
+ type: 'spki',
+ format: 'pem'
+ },
+ privateKeyEncoding: {
+ type: 'pkcs8',
+ format: 'pem'
+ }
+ }
+
+ generateKeyPair('ed25519', options, (err, publicKey, privateKey) => {
+ if (err) return rej(err)
+
+ return res({ publicKey, privateKey })
+ })
+ })
+}
+
+// ---------------------------------------------------------------------------
+