forked from peacekeeper/uni-resolver-driver-did-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
34 lines (33 loc) · 1.11 KB
/
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
import { Elysia } from 'elysia'
import { resolveDID } from 'didwebvh-ts';
const app = new Elysia()
.get('/', () => {
return new Response('Hello World', {status: 200});
})
.get('/1.0/identifiers/:identifier', async ({ params: { identifier } }: { params: { identifier: string } }) => {
console.log(`Resolving ${identifier}`)
try {
const {doc, meta} = await resolveDID(identifier);
if (doc) {
console.log(`Resolved ${doc.id}`);
return Response.json({
didDocument: doc,
didResolutionMetadata: {
contentType: 'application/did+ld+json',
retrieved: new Date().toISOString()
},
didDocumentMetadata: meta
}, {
headers: {
'Content-Type': 'application/json'
}
});
}
return new Response('Not Found', {status: 404});
} catch (e: any) {
console.log(`Failed to resolve ${identifier}: ${e.message}`)
return new Response(e.message, {status: 400});
}
})
.listen(Bun.env.PORT || 8080)
console.log(`did:webvh resolver is running on port ${app.server?.port}`)