-
Notifications
You must be signed in to change notification settings - Fork 15
/
getResolver.ts
37 lines (33 loc) · 1.28 KB
/
getResolver.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
36
37
import { ResolutionOptions, ResolutionResponse } from './types';
import { getDidDocument } from './getDidDocument';
import { factory, DidDocument } from '@did-core/data-model';
import { representation } from '@did-core/did-ld-json';
import { getContext } from './getContext';
import { documentLoader } from './documentLoader';
import { LdKeyPairStatic } from '@transmute/ld-key-pair';
export const getResolver = (KeyPairClass: LdKeyPairStatic) => {
return async (
did: string,
options: ResolutionOptions = {
accept: 'application/did+ld+json',
enableEncryptionKeyDerivation: false,
}
): Promise<ResolutionResponse> => {
const didDocumentEntries = await getDidDocument(did, KeyPairClass, options);
const context = getContext(didDocumentEntries);
// console.log(JSON.stringify(context, null));
const didDocument: DidDocument = factory.build({
entries: {
'@context': context,
...didDocumentEntries,
},
});
const serialized: Buffer = await didDocument
.addRepresentation({ 'application/did+json': representation })
.addRepresentation({ 'application/did+ld+json': representation })
.produce(options.accept, documentLoader);
return {
didDocument: JSON.parse(serialized.toString('utf-8')),
};
};
};