Signature signing
This commit is contained in:
2 files changed
+17
-4
No files matched your search
+2
-1
@@ -8,4 +8,5 @@ BERRYDASH_DB_PORT=
|
|||||||
BERRYDASH_DB_USER=
|
BERRYDASH_DB_USER=
|
||||||
BERRYDASH_DB_PASS=
|
BERRYDASH_DB_PASS=
|
||||||
BERRYDASH_DB_NAME=
|
BERRYDASH_DB_NAME=
|
||||||
TURNSTILE_SECRET_KEY=
|
TURNSTILE_SECRET_KEY=
|
||||||
|
PRIVATE_SIGNING_KEY=
|
||||||
+15
-3
@@ -10,14 +10,26 @@ import { Context } from 'elysia'
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import FormData from 'form-data'
|
import FormData from 'form-data'
|
||||||
import nodemailer from 'nodemailer'
|
import nodemailer from 'nodemailer'
|
||||||
import { createHash } from 'crypto'
|
import { createHash, createPrivateKey, sign } from 'crypto'
|
||||||
import { and, eq, sql } from 'drizzle-orm'
|
import { and, eq, sql } from 'drizzle-orm'
|
||||||
import { verifyCodes } from './tables'
|
import { verifyCodes } from './tables'
|
||||||
|
|
||||||
export const jsonResponse = (data: any, status = 200) => {
|
export const jsonResponse = (data: any, status = 200) => {
|
||||||
return new Response(JSON.stringify(data), {
|
const body = JSON.stringify(data)
|
||||||
|
|
||||||
|
const key = Buffer.from(
|
||||||
|
process.env.PRIVATE_SIGNING_KEY ?? '',
|
||||||
|
'base64'
|
||||||
|
).toString('utf-8')
|
||||||
|
const privateKey = createPrivateKey(key)
|
||||||
|
const signature = sign(null, Buffer.from(body), privateKey).toString('base64')
|
||||||
|
|
||||||
|
return new Response(body, {
|
||||||
status,
|
status,
|
||||||
headers: { 'Content-Type': 'application/json' }
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-Signature': signature
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user