generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 57
/
did-api.ts
36 lines (30 loc) · 1007 Bytes
/
did-api.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
import type { Web5Agent } from '@web5/agent';
import type { DidResolutionOptions, DidResolutionResult } from '@web5/dids';
import { DidMessage } from '@web5/agent';
/**
* The DID API is used to resolve DIDs.
*
* @beta
*/
export class DidApi {
private agent: Web5Agent;
private connectedDid: string;
constructor(options: { agent: Web5Agent, connectedDid: string }) {
this.agent = options.agent;
this.connectedDid = options.connectedDid;
}
/**
* Resolves a DID to a DID Resolution Result.
*
* @param didUrl - The DID or DID URL to resolve.
* @returns A promise that resolves to the DID Resolution Result.
*/
async resolve(didUrl: string, resolutionOptions?: DidResolutionOptions): Promise<DidResolutionResult> {
const agentResponse = await this.agent.processDidRequest({
messageOptions : { didUrl, resolutionOptions },
messageType : DidMessage.Resolve
});
const { result } = agentResponse;
return result as DidResolutionResult;
}
}