-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path[...slug].ts
More file actions
22 lines (15 loc) · 817 Bytes
/
[...slug].ts
File metadata and controls
22 lines (15 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { createKoaRouter, withKoaRouter } from 'next-ssr-middleware';
export const config = { api: { bodyParser: false } };
const router = createKoaRouter(import.meta.url);
router.post('/verification', async context => {
const { algorithm, publicKey, value, signature } = Reflect.get(context.request, 'body');
const rawAlgorithm = JSON.parse(atob(algorithm)),
rawPublicKey = JSON.parse(atob(publicKey)),
rawSignature = Buffer.from(signature, 'hex'),
encodedValue = new TextEncoder().encode(value);
const key = await crypto.subtle.importKey('jwk', rawPublicKey, rawAlgorithm, true, ['verify']);
const verified = await crypto.subtle.verify(rawAlgorithm, key, rawSignature, encodedValue);
context.status = verified ? 200 : 400;
context.body = {};
});
export default withKoaRouter(router);