-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
35 lines (30 loc) · 857 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export interface Env {
PRIVATE_KEY: string;
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
if (request.method === 'OPTIONS') {
return new Response('{}', {
headers: {
'access-control-allow-methods': 'GET, HEAD, POST, OPTIONS',
'access-control-allow-origin': '*',
'access-control-allow-headers': '*'
}
})
}
const url = new URL(request.url)
const message = url.pathname.slice(1)
try {
const ethers = await import('ethers');
const wallet = new ethers.Wallet(env.PRIVATE_KEY);
const signedMessage = await wallet.signMessage(String(message));
return new Response(signedMessage, {
headers: {
'access-control-allow-origin': '*'
}
});
} catch (err: any) {
return new Response(err.message, { headers: { 'access-control-allow-origin': '*' } });
}
},
};