generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathdid-api.ts
107 lines (88 loc) · 2.91 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import type { Web5Agent } from '@web5/agent';
// import type {
// DidKeyOptions,
// DidIonCreateOptions,
// DidMethodApi,
// DidMethodCreator,
// DidMethodResolver,
// DidResolverCache,
// DidResolutionResult,
// DidState
// } from '@web5/dids';
// import { DidResolver } from '@web5/dids';
// // Map method names to option types
// type CreateMethodOptions = {
// ion: DidIonCreateOptions;
// key: DidKeyOptions;
// };
// // A conditional type for inferring options based on the method name
// type CreateOptions<M extends keyof CreateMethodOptions> = CreateMethodOptions[M];
// export type DidApiOptions = {
// didMethodApis: DidMethodApi[];
// cache?: DidResolverCache;
// }
/**
* The DID API is used to create and resolve DIDs.
*
* @beta
*/
export class DidApi {
// private didResolver: DidResolver;
// private methodCreatorMap: Map<string, DidMethodCreator> = new Map();
// /**
// * returns the DID resolver created by this api. useful in scenarios where you want to pass around
// * the same resolver so that you can leverage the resolver's cache
// */
// get resolver() {
// return this.didResolver;
// }
private agent: Web5Agent;
private connectedDid: string;
constructor(options: { agent: Web5Agent, connectedDid: string }) {
this.agent = options.agent;
this.connectedDid = options.connectedDid;
}
// constructor(options: DidApiOptions) {
// const { didMethodApis, cache } = options;
// this.didResolver = new DidResolver({ methodResolvers: options.didMethodApis, cache });
// for (let methodApi of didMethodApis) {
// this.methodCreatorMap.set(methodApi.methodName, methodApi);
// }
// }
// /**
// * Creates a DID of the method provided
// * @param method - the method of DID to create
// * @param options - method-specific options
// * @returns the created DID
// */
// create<M extends keyof CreateMethodOptions>(method: M, options?: CreateOptions<M>): Promise<DidState> {
// const didMethodCreator = this.methodCreatorMap.get(method);
// if (!didMethodCreator) {
// throw new Error(`no creator available for ${method}`);
// }
// return didMethodCreator.create(options);
// }
// /**
// * Resolves the provided DID
// * @param did - the did to resolve
// * @see {@link https://www.w3.org/TR/did-core/#did-resolution | DID Resolution}
// * @returns DID Resolution Result
// */
// resolve(did: string): Promise<DidResolutionResult> {
// return this.didResolver.resolve(did);
// }
// /**
// * can be used to add different did method resolvers
// * @param _resolver
// */
// addMethodResolver(_resolver: DidMethodResolver) {
// throw new Error('not yet implemented');
// }
// /**
// * can be used to add differed did method creators
// * @param _creator
// */
// addMethodCreator(_creator: DidMethodCreator) {
// throw new Error('not yet implemented');
// }
}