@cheqd/did-provider-cheqd 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +34 -0
- package/build/did-manager/cheqd-did-provider.d.ts +61 -0
- package/build/did-manager/cheqd-did-provider.d.ts.map +1 -0
- package/build/did-manager/cheqd-did-provider.js +129 -0
- package/build/did-manager/cheqd-did-provider.js.map +1 -0
- package/build/did-manager/cheqd-did-resolver.d.ts +9 -0
- package/build/did-manager/cheqd-did-resolver.d.ts.map +1 -0
- package/build/did-manager/cheqd-did-resolver.js +53 -0
- package/build/did-manager/cheqd-did-resolver.js.map +1 -0
- package/build/did-manager/resolver.d.ts +46 -0
- package/build/did-manager/resolver.d.ts.map +1 -0
- package/build/did-manager/resolver.js +83 -0
- package/build/did-manager/resolver.js.map +1 -0
- package/build/index.d.ts +9 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/package.json +80 -0
- package/plugin.schema.json +48 -0
- package/src/did-manager/cheqd-did-provider.ts +157 -0
- package/src/did-manager/cheqd-did-resolver.ts +50 -0
- package/src/did-manager/resolver.ts +81 -0
- package/src/index.ts +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2021 Cheqd Foundation Limited (doing business as "cheqd")
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Veramo plugin template
|
|
2
|
+
|
|
3
|
+
This template repository provides a bare-bones structure for writing an agent plugin for Veramo and/or for providing
|
|
4
|
+
your own implementations for key management and storage, or for DID storage.
|
|
5
|
+
|
|
6
|
+
## Quick start
|
|
7
|
+
|
|
8
|
+
- Copy this repo
|
|
9
|
+
- Rename package in `package.json`
|
|
10
|
+
- `yarn`
|
|
11
|
+
- `yarn build` or `yarn watch`
|
|
12
|
+
- `yarn generate-plugin-schema`
|
|
13
|
+
- `yarn start` or VSCode Debugger (CMD + Shift + D) > Run `OpenAPI server`
|
|
14
|
+
|
|
15
|
+
## Structure of this template
|
|
16
|
+
|
|
17
|
+
### Using plugin with @veramo/cli
|
|
18
|
+
|
|
19
|
+
See [./agent.yml](./agent.yml) for an example Veramo CLI configuration that uses the plugin and customizations from this
|
|
20
|
+
template alongside other Veramo plugins to create a fully functioning agent.
|
|
21
|
+
|
|
22
|
+
## Testing your plugin
|
|
23
|
+
|
|
24
|
+
There are a number of ways to test your plugin.
|
|
25
|
+
|
|
26
|
+
### Integration tests
|
|
27
|
+
|
|
28
|
+
Will be added in the nearest future.
|
|
29
|
+
|
|
30
|
+
### Call your agent using the Veramo OpenAPI server
|
|
31
|
+
|
|
32
|
+
You can also run `yarn veramo server` in your terminal and then go to <http://localhost:3335/api-docs> to see all the
|
|
33
|
+
available plugin methods. You can call them after you click Authorize and provide the API key defined
|
|
34
|
+
in [agent.yml](./agent.yml#L119). By default, it is `test123`.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { IIdentifier, IKey, IService, IAgentContext, IKeyManager } from '@veramo/core';
|
|
2
|
+
import { AbstractIdentifierProvider } from '@veramo/did-manager';
|
|
3
|
+
declare type IContext = IAgentContext<IKeyManager>;
|
|
4
|
+
export declare enum DefaultRPCUrl {
|
|
5
|
+
Mainnet = "https://rpc.cheqd.net",
|
|
6
|
+
Testnet = "https://rpc.cheqd.network"
|
|
7
|
+
}
|
|
8
|
+
export declare enum NetworkType {
|
|
9
|
+
Mainnet = "mainnet",
|
|
10
|
+
Testnet = "testnet"
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* You can use this template for an `AbstractIdentifierProvider` implementation.
|
|
14
|
+
*
|
|
15
|
+
* Implementations of this interface are used by `@veramo/did-manager` to implement
|
|
16
|
+
* CRUD operations for various DID methods.
|
|
17
|
+
*
|
|
18
|
+
* If you wish to implement support for a particular DID method, this is the type of class
|
|
19
|
+
* you need to implement.
|
|
20
|
+
*
|
|
21
|
+
* If you don't want to customize this, then it is safe to remove from the template.
|
|
22
|
+
*
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
export declare class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
26
|
+
private defaultKms;
|
|
27
|
+
private readonly network;
|
|
28
|
+
private rpcUrl;
|
|
29
|
+
constructor(options: {
|
|
30
|
+
defaultKms: string;
|
|
31
|
+
rpcUrl?: string;
|
|
32
|
+
networkType?: NetworkType;
|
|
33
|
+
});
|
|
34
|
+
createIdentifier({ kms, alias }: {
|
|
35
|
+
kms?: string;
|
|
36
|
+
alias?: string;
|
|
37
|
+
}, context: IContext): Promise<Omit<IIdentifier, 'provider'>>;
|
|
38
|
+
deleteIdentifier(identity: IIdentifier, context: IContext): Promise<boolean>;
|
|
39
|
+
addKey({ identifier, key, options, }: {
|
|
40
|
+
identifier: IIdentifier;
|
|
41
|
+
key: IKey;
|
|
42
|
+
options?: any;
|
|
43
|
+
}, context: IContext): Promise<any>;
|
|
44
|
+
addService({ identifier, service, options, }: {
|
|
45
|
+
identifier: IIdentifier;
|
|
46
|
+
service: IService;
|
|
47
|
+
options?: any;
|
|
48
|
+
}, context: IContext): Promise<any>;
|
|
49
|
+
removeKey(args: {
|
|
50
|
+
identifier: IIdentifier;
|
|
51
|
+
kid: string;
|
|
52
|
+
options?: any;
|
|
53
|
+
}, context: IContext): Promise<any>;
|
|
54
|
+
removeService(args: {
|
|
55
|
+
identifier: IIdentifier;
|
|
56
|
+
id: string;
|
|
57
|
+
options?: any;
|
|
58
|
+
}, context: IContext): Promise<any>;
|
|
59
|
+
}
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=cheqd-did-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cheqd-did-provider.d.ts","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,WAAW,EAEX,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAA;AAIhE,aAAK,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;AAE1C,oBAAY,aAAa;IACvB,OAAO,0BAA0B;IACjC,OAAO,8BAA8B;CACtC;AAED,oBAAY,WAAW;IACtB,OAAO,YAAY;IACnB,OAAO,YAAY;CACnB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,gBAAiB,SAAQ,0BAA0B;IAC/D,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,MAAM,CAAQ;gBAEV,OAAO,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,WAAW,CAAA;KAAE;IAOjF,gBAAgB,CAErB,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,EAChD,OAAO,EAAE,QAAQ,GACf,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IA8BnC,gBAAgB,CACrB,QAAQ,EAAE,WAAW,EACrB,OAAO,EAAE,QAAQ,GACf,OAAO,CAAC,OAAO,CAAC;IAOb,MAAM,CACX,EAEC,UAAU,EAEV,GAAG,EAEH,OAAO,GAEP,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,GAAG,EAAE,IAAI,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAExD,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;IAIT,UAAU,CACf,EAEC,UAAU,EAEV,OAAO,EAEP,OAAO,GAEP,EAAE;QAAE,UAAU,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,QAAQ,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAA;KAAE,EAEhE,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;IAIT,SAAS,CAEd,IAAI,EAAE;QACL,UAAU,EAAE,WAAW,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;QAEZ,OAAO,CAAC,EAAE,GAAG,CAAA;KACb,EAED,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;IAIT,aAAa,CAElB,IAAI,EAAE;QACL,UAAU,EAAE,WAAW,CAAC;QACxB,EAAE,EAAE,MAAM,CAAC;QAEX,OAAO,CAAC,EAAE,GAAG,CAAA;KACb,EAED,OAAO,EAAE,QAAQ,GAEf,OAAO,CAAC,GAAG,CAAC;CAGf"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CheqdDIDProvider = exports.NetworkType = exports.DefaultRPCUrl = void 0;
|
|
16
|
+
const did_manager_1 = require("@veramo/did-manager");
|
|
17
|
+
const multibase_1 = __importDefault(require("multibase"));
|
|
18
|
+
const multicodec_1 = __importDefault(require("multicodec"));
|
|
19
|
+
var DefaultRPCUrl;
|
|
20
|
+
(function (DefaultRPCUrl) {
|
|
21
|
+
DefaultRPCUrl["Mainnet"] = "https://rpc.cheqd.net";
|
|
22
|
+
DefaultRPCUrl["Testnet"] = "https://rpc.cheqd.network";
|
|
23
|
+
})(DefaultRPCUrl = exports.DefaultRPCUrl || (exports.DefaultRPCUrl = {}));
|
|
24
|
+
var NetworkType;
|
|
25
|
+
(function (NetworkType) {
|
|
26
|
+
NetworkType["Mainnet"] = "mainnet";
|
|
27
|
+
NetworkType["Testnet"] = "testnet";
|
|
28
|
+
})(NetworkType = exports.NetworkType || (exports.NetworkType = {}));
|
|
29
|
+
/**
|
|
30
|
+
* You can use this template for an `AbstractIdentifierProvider` implementation.
|
|
31
|
+
*
|
|
32
|
+
* Implementations of this interface are used by `@veramo/did-manager` to implement
|
|
33
|
+
* CRUD operations for various DID methods.
|
|
34
|
+
*
|
|
35
|
+
* If you wish to implement support for a particular DID method, this is the type of class
|
|
36
|
+
* you need to implement.
|
|
37
|
+
*
|
|
38
|
+
* If you don't want to customize this, then it is safe to remove from the template.
|
|
39
|
+
*
|
|
40
|
+
* @alpha
|
|
41
|
+
*/
|
|
42
|
+
class CheqdDIDProvider extends did_manager_1.AbstractIdentifierProvider {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
super();
|
|
45
|
+
this.defaultKms = options.defaultKms;
|
|
46
|
+
this.network = options.networkType ? options.networkType : NetworkType.Testnet;
|
|
47
|
+
this.rpcUrl = options.rpcUrl ? options.rpcUrl : (this.network === NetworkType.Testnet ? DefaultRPCUrl.Testnet : DefaultRPCUrl.Mainnet);
|
|
48
|
+
}
|
|
49
|
+
createIdentifier(
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
+
{ kms, alias }, context) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const key = yield context.agent.keyManagerCreate({
|
|
54
|
+
kms: kms || this.defaultKms,
|
|
55
|
+
type: 'Ed25519',
|
|
56
|
+
});
|
|
57
|
+
const methodSpecificId = Buffer.from(multibase_1.default.encode('base58btc', multicodec_1.default.addPrefix('ed25519-pub', Buffer.from(key.publicKeyHex, 'hex'))))
|
|
58
|
+
.toString()
|
|
59
|
+
.substr(0, 32);
|
|
60
|
+
const identifier = {
|
|
61
|
+
did: `did:cheqd:${this.network}:` + methodSpecificId,
|
|
62
|
+
controllerKeyId: key.kid,
|
|
63
|
+
keys: [key],
|
|
64
|
+
services: [],
|
|
65
|
+
provider: 'cheqd',
|
|
66
|
+
};
|
|
67
|
+
// TODO: Implement custom debugger on creation.
|
|
68
|
+
return identifier;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
deleteIdentifier(identity, context) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
for (const { kid } of identity.keys) {
|
|
74
|
+
yield context.agent.keyManagerDelete({ kid });
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
addKey({
|
|
80
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
81
|
+
identifier,
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
83
|
+
key,
|
|
84
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
85
|
+
options,
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
},
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
89
|
+
context) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
throw Error('CheqdDIDProvider addKey not supported yet.');
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
addService({
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
96
|
+
identifier,
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
98
|
+
service,
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
100
|
+
options,
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
+
},
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
104
|
+
context) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
throw Error('CheqdDIDProvider addService not supported yet.');
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
removeKey(
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
111
|
+
args,
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
113
|
+
context) {
|
|
114
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
throw Error('CheqdDIDProvider removeKey not supported yet.');
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
removeService(
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
120
|
+
args,
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
122
|
+
context) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
throw Error('CheqdDIDProvider removeService not supported yet.');
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.CheqdDIDProvider = CheqdDIDProvider;
|
|
129
|
+
//# sourceMappingURL=cheqd-did-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cheqd-did-provider.js","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAQA,qDAAgE;AAChE,0DAAiC;AACjC,4DAAmC;AAInC,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kDAAiC,CAAA;IACjC,sDAAqC,CAAA;AACvC,CAAC,EAHW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAGxB;AAED,IAAY,WAGX;AAHD,WAAY,WAAW;IACtB,kCAAmB,CAAA;IACnB,kCAAmB,CAAA;AACpB,CAAC,EAHW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAGtB;AAED;;;;;;;;;;;;GAYG;AACH,MAAa,gBAAiB,SAAQ,wCAA0B;IAK/D,YAAY,OAA2E;QACtF,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAA;QACpC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAA;QAC9E,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,OAAO,KAAK,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAE,CAAA;IACzI,CAAC;IAEK,gBAAgB;IACrB,8DAA8D;IAC9D,EAAE,GAAG,EAAE,KAAK,EAAoC,EAChD,OAAiB;;YAEjB,MAAM,GAAG,GAAmB,MAAM,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC;gBAChE,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,UAAU;gBAC3B,IAAI,EAAE,SAAS;aACf,CAAC,CAAA;YAEF,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CACnC,mBAAS,CAAC,MAAM,CACf,WAAW,EACX,oBAAU,CAAC,SAAS,CACnB,aAAa,EACb,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,KAAK,CAAC,CACpC,CACD,CACD;iBACC,QAAQ,EAAE;iBACV,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YAEf,MAAM,UAAU,GAAgB;gBAC/B,GAAG,EAAE,aAAa,IAAI,CAAC,OAAO,GAAG,GAAG,gBAAgB;gBACpD,eAAe,EAAE,GAAG,CAAC,GAAG;gBACxB,IAAI,EAAE,CAAC,GAAG,CAAC;gBACX,QAAQ,EAAE,EAAE;gBACZ,QAAQ,EAAE,OAAO;aACjB,CAAA;YAED,+CAA+C;YAC/C,OAAO,UAAU,CAAA;QAClB,CAAC;KAAA;IAEK,gBAAgB,CACrB,QAAqB,EACrB,OAAiB;;YAEjB,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,QAAQ,CAAC,IAAI,EAAE;gBACpC,MAAM,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;aAC7C;YACD,OAAO,IAAI,CAAA;QACZ,CAAC;KAAA;IAEK,MAAM,CACX;IACC,8DAA8D;IAC9D,UAAU;IACV,8DAA8D;IAC9D,GAAG;IACH,8DAA8D;IAC9D,OAAO;IACP,+DAA+D;MACR;IACxD,8DAA8D;IAC9D,OAAiB;;YAGjB,MAAM,KAAK,CAAC,4CAA4C,CAAC,CAAA;QAC1D,CAAC;KAAA;IAEK,UAAU,CACf;IACC,8DAA8D;IAC9D,UAAU;IACV,8DAA8D;IAC9D,OAAO;IACP,8DAA8D;IAC9D,OAAO;IACP,+DAA+D;MACA;IAChE,8DAA8D;IAC9D,OAAiB;;YAGjB,MAAM,KAAK,CAAC,gDAAgD,CAAC,CAAA;QAC9D,CAAC;KAAA;IAEK,SAAS;IACd,8DAA8D;IAC9D,IAKC;IACD,8DAA8D;IAC9D,OAAiB;;YAGjB,MAAM,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAC7D,CAAC;KAAA;IAEK,aAAa;IAClB,8DAA8D;IAC9D,IAKC;IACD,8DAA8D;IAC9D,OAAiB;;YAGjB,MAAM,KAAK,CAAC,mDAAmD,CAAC,CAAA;QACjE,CAAC;KAAA;CACD;AAvHD,4CAuHC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DIDResolutionOptions, DIDResolutionResult, DIDResolver, ParsedDID, Resolvable } from 'did-resolver';
|
|
2
|
+
export declare function getResolver(resolverUrl?: string): Record<string, DIDResolver>;
|
|
3
|
+
export declare class CheqdDidResolver {
|
|
4
|
+
private resolverUrl;
|
|
5
|
+
constructor(resolverUrl?: string);
|
|
6
|
+
resolve(did: string, parsed: ParsedDID, _unused: Resolvable, options: DIDResolutionOptions): Promise<DIDResolutionResult>;
|
|
7
|
+
build(): Record<string, DIDResolver>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=cheqd-did-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cheqd-did-resolver.d.ts","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACX,SAAS,EACT,UAAU,EACX,MAAM,cAAc,CAAA;AAMrB,wBAAgB,WAAW,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAI7E;AAED,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAC4B;gBAEnC,WAAW,CAAC,EAAE,MAAM;IAI1B,OAAO,CACX,GAAG,EAAE,MAAM,EAEX,MAAM,EAAE,SAAS,EAEjB,OAAO,EAAE,UAAU,EAEnB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC;IAY/B,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC;CAGrC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CheqdDidResolver = exports.getResolver = void 0;
|
|
13
|
+
/* interface Options {
|
|
14
|
+
resolver: Resolvable
|
|
15
|
+
} */
|
|
16
|
+
function getResolver(resolverUrl) {
|
|
17
|
+
if (resolverUrl)
|
|
18
|
+
return new CheqdDidResolver(resolverUrl).build();
|
|
19
|
+
return new CheqdDidResolver().build();
|
|
20
|
+
}
|
|
21
|
+
exports.getResolver = getResolver;
|
|
22
|
+
class CheqdDidResolver {
|
|
23
|
+
constructor(resolverUrl) {
|
|
24
|
+
this.resolverUrl = 'https://resolver.cheqd.net/1.0/identifiers/';
|
|
25
|
+
if (resolverUrl)
|
|
26
|
+
this.resolverUrl = resolverUrl;
|
|
27
|
+
}
|
|
28
|
+
resolve(did,
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
|
+
parsed,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
|
+
_unused,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
options) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
try {
|
|
37
|
+
const result = yield fetch(this.resolverUrl + did, {
|
|
38
|
+
headers: { 'Content-Type': 'application/did+json' },
|
|
39
|
+
});
|
|
40
|
+
const ddo = (yield result.json());
|
|
41
|
+
return ddo;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
return Promise.reject(e);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
build() {
|
|
49
|
+
return { cheqd: this.resolve.bind(this) };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.CheqdDidResolver = CheqdDidResolver;
|
|
53
|
+
//# sourceMappingURL=cheqd-did-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cheqd-did-resolver.js","sourceRoot":"","sources":["../../src/did-manager/cheqd-did-resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA;;IAEI;AAEJ,SAAgB,WAAW,CAAC,WAAoB;IAC9C,IAAI,WAAW;QAAE,OAAO,IAAI,gBAAgB,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,CAAA;IAEjE,OAAO,IAAI,gBAAgB,EAAE,CAAC,KAAK,EAAE,CAAA;AACvC,CAAC;AAJD,kCAIC;AAED,MAAa,gBAAgB;IAI3B,YAAY,WAAoB;QAHxB,gBAAW,GACjB,6CAA6C,CAAA;QAG7C,IAAI,WAAW;YAAE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IACjD,CAAC;IAEK,OAAO,CACX,GAAW;IACX,6DAA6D;IAC7D,MAAiB;IACjB,6DAA6D;IAC7D,OAAmB;IACnB,6DAA6D;IAC7D,OAA6B;;YAE7B,IAAI;gBACF,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,WAAW,GAAG,GAAG,EAAE;oBACjD,OAAO,EAAE,EAAE,cAAc,EAAE,sBAAsB,EAAE;iBACpD,CAAC,CAAA;gBACF,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,EAAE,CAAwB,CAAA;gBACxD,OAAO,GAAG,CAAA;aACX;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;aACzB;QACH,CAAC;KAAA;IAED,KAAK;QACH,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;IAC3C,CAAC;CACF;AA/BD,4CA+BC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { DIDResolver } from 'did-resolver';
|
|
2
|
+
interface Options {
|
|
3
|
+
url: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated please use `getUniresolver(url)` or `getUniresolverFor(methods, url)` instead
|
|
7
|
+
*/
|
|
8
|
+
export declare class CheqdResolver {
|
|
9
|
+
constructor(options: Options);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a DIDResolver instance that can be used with `did-resolver`
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const uniResolver = getUniversalResolver()
|
|
17
|
+
* const resolver = new Resolver({
|
|
18
|
+
* web: uniResolver,
|
|
19
|
+
* key: uniResolver,
|
|
20
|
+
* elem: uniResolver
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param url the URL for the universal resolver instance (See https://uniresolver.io )
|
|
25
|
+
* @returns `DIDResolver`
|
|
26
|
+
*/
|
|
27
|
+
export declare function getUniversalResolver(url?: string): DIDResolver;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a mapping of DID methods to a DIDResolver instance that can be used with `did-resolver`
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const uniResolver = getUniversalResolverFor(['web', 'key', 'elem'])
|
|
34
|
+
* const resolver = new Resolver({
|
|
35
|
+
* ...uniResolver,
|
|
36
|
+
* // other resolvers
|
|
37
|
+
* })
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param methods an array of DID methods that should be resolved by this universal resolver
|
|
41
|
+
* @param url the URL for the universal resolver instance (See https://uniresolver.io )
|
|
42
|
+
* @returns `Record<string, DIDResolver>` a mapping of the given methods to an instance of `DIDResolver`
|
|
43
|
+
*/
|
|
44
|
+
export declare function getUniversalResolverFor(methods: string[], url?: string): Record<string, DIDResolver>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/did-manager/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE1C,UAAU,OAAO;IACf,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,qBAAa,aAAa;gBACZ,OAAO,EAAE,OAAO;CAG7B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,SAAgD,GAClD,WAAW,CAmBb;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EAAE,EACjB,GAAG,SAAgD,GAClD,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAO7B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUniversalResolverFor = exports.getUniversalResolver = exports.CheqdResolver = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated please use `getUniresolver(url)` or `getUniresolverFor(methods, url)` instead
|
|
15
|
+
*/
|
|
16
|
+
class CheqdResolver {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
return getUniversalResolver(options.url);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.CheqdResolver = CheqdResolver;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a DIDResolver instance that can be used with `did-resolver`
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const uniResolver = getUniversalResolver()
|
|
28
|
+
* const resolver = new Resolver({
|
|
29
|
+
* web: uniResolver,
|
|
30
|
+
* key: uniResolver,
|
|
31
|
+
* elem: uniResolver
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @param url the URL for the universal resolver instance (See https://uniresolver.io )
|
|
36
|
+
* @returns `DIDResolver`
|
|
37
|
+
*/
|
|
38
|
+
function getUniversalResolver(url = 'https://resolver.cheqd.net/1.0/identifiers/') {
|
|
39
|
+
if (!url) {
|
|
40
|
+
throw Error('[did-resolver] Universal: url required');
|
|
41
|
+
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const resolve = (didUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
const result = yield fetch(url + didUrl, {
|
|
46
|
+
headers: { 'Content-Type': 'application/did+ld+json' },
|
|
47
|
+
});
|
|
48
|
+
const ddo = yield result.json();
|
|
49
|
+
return ddo;
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
return Promise.reject(e);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return resolve;
|
|
56
|
+
}
|
|
57
|
+
exports.getUniversalResolver = getUniversalResolver;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a mapping of DID methods to a DIDResolver instance that can be used with `did-resolver`
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const uniResolver = getUniversalResolverFor(['web', 'key', 'elem'])
|
|
64
|
+
* const resolver = new Resolver({
|
|
65
|
+
* ...uniResolver,
|
|
66
|
+
* // other resolvers
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param methods an array of DID methods that should be resolved by this universal resolver
|
|
71
|
+
* @param url the URL for the universal resolver instance (See https://uniresolver.io )
|
|
72
|
+
* @returns `Record<string, DIDResolver>` a mapping of the given methods to an instance of `DIDResolver`
|
|
73
|
+
*/
|
|
74
|
+
function getUniversalResolverFor(methods, url = 'https://resolver.cheqd.net/1.0/identifiers/') {
|
|
75
|
+
const uniResolver = getUniversalResolver(url);
|
|
76
|
+
const mapping = {};
|
|
77
|
+
for (const method of methods) {
|
|
78
|
+
mapping[method] = uniResolver;
|
|
79
|
+
}
|
|
80
|
+
return mapping;
|
|
81
|
+
}
|
|
82
|
+
exports.getUniversalResolverFor = getUniversalResolverFor;
|
|
83
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/did-manager/resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA;;GAEG;AACH,MAAa,aAAa;IACxB,YAAY,OAAgB;QAC1B,OAAO,oBAAoB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAC1C,CAAC;CACF;AAJD,sCAIC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,oBAAoB,CAClC,GAAG,GAAG,6CAA6C;IAEnD,IAAI,CAAC,GAAG,EAAE;QACR,MAAM,KAAK,CAAC,wCAAwC,CAAC,CAAA;KACtD;IAED,8DAA8D;IAC9D,MAAM,OAAO,GAAgB,CAAO,MAAc,EAAgB,EAAE;QAClE,IAAI;YACF,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,GAAG,MAAM,EAAE;gBACvC,OAAO,EAAE,EAAE,cAAc,EAAE,yBAAyB,EAAE;aACvD,CAAC,CAAA;YACF,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;YAC/B,OAAO,GAAG,CAAA;SACX;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;SACzB;IACH,CAAC,CAAA,CAAA;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AArBD,oDAqBC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAgB,uBAAuB,CACrC,OAAiB,EACjB,GAAG,GAAG,6CAA6C;IAEnD,MAAM,WAAW,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAA;IAC7C,MAAM,OAAO,GAAgC,EAAE,CAAA;IAC/C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,OAAO,CAAC,MAAM,CAAC,GAAG,WAAW,CAAA;KAC9B;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAVD,0DAUC"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
declare const schema: any;
|
|
5
|
+
export { schema };
|
|
6
|
+
export { CheqdDIDProvider } from './did-manager/cheqd-did-provider';
|
|
7
|
+
export { CheqdDidResolver, getResolver } from './did-manager/cheqd-did-resolver';
|
|
8
|
+
export { CheqdResolver } from './did-manager/resolver';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,QAAA,MAAM,MAAM,KAAmC,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,CAAA;AACjB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CheqdResolver = exports.getResolver = exports.CheqdDidResolver = exports.CheqdDIDProvider = exports.schema = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
// It can be disabled even not import statement is needed
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
9
|
+
const schema = require('../plugin.schema.json');
|
|
10
|
+
exports.schema = schema;
|
|
11
|
+
var cheqd_did_provider_1 = require("./did-manager/cheqd-did-provider");
|
|
12
|
+
Object.defineProperty(exports, "CheqdDIDProvider", { enumerable: true, get: function () { return cheqd_did_provider_1.CheqdDIDProvider; } });
|
|
13
|
+
var cheqd_did_resolver_1 = require("./did-manager/cheqd-did-resolver");
|
|
14
|
+
Object.defineProperty(exports, "CheqdDidResolver", { enumerable: true, get: function () { return cheqd_did_resolver_1.CheqdDidResolver; } });
|
|
15
|
+
Object.defineProperty(exports, "getResolver", { enumerable: true, get: function () { return cheqd_did_resolver_1.getResolver; } });
|
|
16
|
+
var resolver_1 = require("./did-manager/resolver");
|
|
17
|
+
Object.defineProperty(exports, "CheqdResolver", { enumerable: true, get: function () { return resolver_1.CheqdResolver; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,yDAAyD;AACzD,8DAA8D;AAC9D,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAAA;AACtC,wBAAM;AACf,uEAAmE;AAA1D,sHAAA,gBAAgB,OAAA;AACzB,uEAAgF;AAAvE,sHAAA,gBAAgB,OAAA;AAAE,iHAAA,WAAW,OAAA;AACtC,mDAAsD;AAA7C,yGAAA,aAAa,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cheqd/did-provider-cheqd",
|
|
3
|
+
"version": "1.1.1",
|
|
4
|
+
"description": "Veramo SDK plugin for the did:cheqd DID method",
|
|
5
|
+
"licence": "Apache-2.0",
|
|
6
|
+
"source": "src/index.ts",
|
|
7
|
+
"main": "build/index.js",
|
|
8
|
+
"types": "build/index.d.ts",
|
|
9
|
+
"author": "Cheqd Foundation Limited (https://github.com/cheqd)",
|
|
10
|
+
"repository": "https://github.com/cheqd/did-provider-cheqd.git",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/cheqd/did-provider-cheqd/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/cheqd/did-provider-cheqd#readme",
|
|
15
|
+
"veramo": {
|
|
16
|
+
"pluginInterfaces": {
|
|
17
|
+
"IMyAgentPlugin": "./src/types/IMyAgentPlugin.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
22
|
+
"generate-plugin-schema": "yarn veramo dev generate-plugin-schema",
|
|
23
|
+
"start": "veramo server",
|
|
24
|
+
"build:watch": "tsc -b --watch",
|
|
25
|
+
"test:ci": "jest --config=jest.json",
|
|
26
|
+
"test": "jest --passWithNoTests",
|
|
27
|
+
"test:watch": "yarn test --watch --verbose",
|
|
28
|
+
"clean": "rm -rf tmp && rm database.sqlite && rm -rf build && rm tsconfig.tsbuildinfo",
|
|
29
|
+
"lint": "eslint --max-warnings=0 src",
|
|
30
|
+
"semantic": "npx semantic-release"
|
|
31
|
+
},
|
|
32
|
+
"eslintConfig": {
|
|
33
|
+
"root": true,
|
|
34
|
+
"extends": [
|
|
35
|
+
"typescript",
|
|
36
|
+
"prettier"
|
|
37
|
+
]
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
41
|
+
"@semantic-release/commit-analyzer": "^9.0.2",
|
|
42
|
+
"@semantic-release/git": "^10.0.1",
|
|
43
|
+
"@semantic-release/github": "^8.0.5",
|
|
44
|
+
"@semantic-release/npm": "^9.0.1",
|
|
45
|
+
"@semantic-release/release-notes-generator": "^10.0.3",
|
|
46
|
+
"@types/jest": "27.5.1",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.31.0",
|
|
48
|
+
"@typescript-eslint/parser": "^5.31.0",
|
|
49
|
+
"@veramo/cli": "^3.1.5",
|
|
50
|
+
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
51
|
+
"eslint": "^7.32.0",
|
|
52
|
+
"eslint-config-prettier": "^8.5.0",
|
|
53
|
+
"eslint-config-typescript": "^3.0.0",
|
|
54
|
+
"jest": "27.5.1",
|
|
55
|
+
"prettier": "^2.7.1",
|
|
56
|
+
"semantic-release": "^19.0.3",
|
|
57
|
+
"ts-jest": "27.1.5",
|
|
58
|
+
"typescript": "4.7.3"
|
|
59
|
+
},
|
|
60
|
+
"files": [
|
|
61
|
+
"build/**/*",
|
|
62
|
+
"src/**/*",
|
|
63
|
+
"README.md",
|
|
64
|
+
"plugin.schema.json",
|
|
65
|
+
"LICENSE"
|
|
66
|
+
],
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"@veramo/core": "^3.1.3",
|
|
69
|
+
"@veramo/did-manager": "^3.1.3",
|
|
70
|
+
"@veramo/did-provider-key": "^3.1.3",
|
|
71
|
+
"@veramo/key-manager": "^3.1.3",
|
|
72
|
+
"debug": "^4.3.4",
|
|
73
|
+
"multibase": "^4.0.6",
|
|
74
|
+
"multicodec": "^3.2.1"
|
|
75
|
+
},
|
|
76
|
+
"publishConfig": {
|
|
77
|
+
"registry": "https://registry.npmjs.org/",
|
|
78
|
+
"access": "public"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"IMyAgentPlugin": {
|
|
3
|
+
"components": {
|
|
4
|
+
"schemas": {
|
|
5
|
+
"IMyAgentPluginFooArgs": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"did": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Decentralized identifier"
|
|
11
|
+
},
|
|
12
|
+
"bar": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Lorem ipsum"
|
|
15
|
+
},
|
|
16
|
+
"foo": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Dolorem"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["did", "bar", "foo"],
|
|
22
|
+
"description": "Arguments needed for {@link MyAgentPlugin.myPluginFoo } \nTo be able to export a plugin schema, your plugin methods should use an `args` parameter of a named type or interface."
|
|
23
|
+
},
|
|
24
|
+
"IMyAgentPluginFooResult": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"properties": {
|
|
27
|
+
"foobar": {
|
|
28
|
+
"type": "string"
|
|
29
|
+
},
|
|
30
|
+
"baz": {}
|
|
31
|
+
},
|
|
32
|
+
"description": "Result of {@link MyAgentPlugin.myPluginFoo } \nTo be able to export a plugin schema, your plugin return types need to be Promises of a named type or interface."
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"methods": {
|
|
36
|
+
"myPluginFoo": {
|
|
37
|
+
"description": "Your plugin method description",
|
|
38
|
+
"arguments": {
|
|
39
|
+
"$ref": "#/components/schemas/IMyAgentPluginFooArgs"
|
|
40
|
+
},
|
|
41
|
+
"returnType": {
|
|
42
|
+
"$ref": "#/components/schemas/IMyAgentPluginFooResult"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IIdentifier,
|
|
3
|
+
IKey,
|
|
4
|
+
IService,
|
|
5
|
+
IAgentContext,
|
|
6
|
+
IKeyManager,
|
|
7
|
+
ManagedKeyInfo,
|
|
8
|
+
} from '@veramo/core'
|
|
9
|
+
import { AbstractIdentifierProvider } from '@veramo/did-manager'
|
|
10
|
+
import Multibase from 'multibase'
|
|
11
|
+
import Multicodec from 'multicodec'
|
|
12
|
+
|
|
13
|
+
type IContext = IAgentContext<IKeyManager>
|
|
14
|
+
|
|
15
|
+
export enum DefaultRPCUrl {
|
|
16
|
+
Mainnet = 'https://rpc.cheqd.net',
|
|
17
|
+
Testnet = 'https://rpc.cheqd.network'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export enum NetworkType {
|
|
21
|
+
Mainnet = "mainnet",
|
|
22
|
+
Testnet = "testnet"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* You can use this template for an `AbstractIdentifierProvider` implementation.
|
|
27
|
+
*
|
|
28
|
+
* Implementations of this interface are used by `@veramo/did-manager` to implement
|
|
29
|
+
* CRUD operations for various DID methods.
|
|
30
|
+
*
|
|
31
|
+
* If you wish to implement support for a particular DID method, this is the type of class
|
|
32
|
+
* you need to implement.
|
|
33
|
+
*
|
|
34
|
+
* If you don't want to customize this, then it is safe to remove from the template.
|
|
35
|
+
*
|
|
36
|
+
* @alpha
|
|
37
|
+
*/
|
|
38
|
+
export class CheqdDIDProvider extends AbstractIdentifierProvider {
|
|
39
|
+
private defaultKms: string
|
|
40
|
+
private readonly network: NetworkType
|
|
41
|
+
private rpcUrl: string
|
|
42
|
+
|
|
43
|
+
constructor(options: { defaultKms: string, rpcUrl?: string, networkType?: NetworkType }) {
|
|
44
|
+
super()
|
|
45
|
+
this.defaultKms = options.defaultKms
|
|
46
|
+
this.network = options.networkType ? options.networkType : NetworkType.Testnet
|
|
47
|
+
this.rpcUrl = options.rpcUrl ? options.rpcUrl : ( this.network === NetworkType.Testnet ? DefaultRPCUrl.Testnet : DefaultRPCUrl.Mainnet )
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async createIdentifier(
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
|
+
{ kms, alias }: { kms?: string; alias?: string },
|
|
53
|
+
context: IContext,
|
|
54
|
+
): Promise<Omit<IIdentifier, 'provider'>> {
|
|
55
|
+
const key: ManagedKeyInfo = await context.agent.keyManagerCreate({
|
|
56
|
+
kms: kms || this.defaultKms,
|
|
57
|
+
type: 'Ed25519',
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const methodSpecificId = Buffer.from(
|
|
61
|
+
Multibase.encode(
|
|
62
|
+
'base58btc',
|
|
63
|
+
Multicodec.addPrefix(
|
|
64
|
+
'ed25519-pub',
|
|
65
|
+
Buffer.from(key.publicKeyHex, 'hex'),
|
|
66
|
+
),
|
|
67
|
+
),
|
|
68
|
+
)
|
|
69
|
+
.toString()
|
|
70
|
+
.substr(0, 32)
|
|
71
|
+
|
|
72
|
+
const identifier: IIdentifier = {
|
|
73
|
+
did: `did:cheqd:${this.network}:` + methodSpecificId,
|
|
74
|
+
controllerKeyId: key.kid,
|
|
75
|
+
keys: [key],
|
|
76
|
+
services: [],
|
|
77
|
+
provider: 'cheqd',
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// TODO: Implement custom debugger on creation.
|
|
81
|
+
return identifier
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async deleteIdentifier(
|
|
85
|
+
identity: IIdentifier,
|
|
86
|
+
context: IContext,
|
|
87
|
+
): Promise<boolean> {
|
|
88
|
+
for (const { kid } of identity.keys) {
|
|
89
|
+
await context.agent.keyManagerDelete({ kid })
|
|
90
|
+
}
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async addKey(
|
|
95
|
+
{
|
|
96
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
97
|
+
identifier,
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
99
|
+
key,
|
|
100
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
101
|
+
options,
|
|
102
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
103
|
+
}: { identifier: IIdentifier; key: IKey; options?: any },
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
105
|
+
context: IContext,
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
107
|
+
): Promise<any> {
|
|
108
|
+
throw Error('CheqdDIDProvider addKey not supported yet.')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async addService(
|
|
112
|
+
{
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
114
|
+
identifier,
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
116
|
+
service,
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
118
|
+
options,
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
120
|
+
}: { identifier: IIdentifier; service: IService; options?: any },
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
122
|
+
context: IContext,
|
|
123
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
124
|
+
): Promise<any> {
|
|
125
|
+
throw Error('CheqdDIDProvider addService not supported yet.')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async removeKey(
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
130
|
+
args: {
|
|
131
|
+
identifier: IIdentifier;
|
|
132
|
+
kid: string;
|
|
133
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
+
options?: any
|
|
135
|
+
},
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
137
|
+
context: IContext,
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
+
): Promise<any> {
|
|
140
|
+
throw Error('CheqdDIDProvider removeKey not supported yet.')
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async removeService(
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
145
|
+
args: {
|
|
146
|
+
identifier: IIdentifier;
|
|
147
|
+
id: string;
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
|
+
options?: any
|
|
150
|
+
},
|
|
151
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
152
|
+
context: IContext,
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
154
|
+
): Promise<any> {
|
|
155
|
+
throw Error('CheqdDIDProvider removeService not supported yet.')
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DIDResolutionOptions,
|
|
3
|
+
DIDResolutionResult,
|
|
4
|
+
DIDResolver,
|
|
5
|
+
ParsedDID,
|
|
6
|
+
Resolvable,
|
|
7
|
+
} from 'did-resolver'
|
|
8
|
+
|
|
9
|
+
/* interface Options {
|
|
10
|
+
resolver: Resolvable
|
|
11
|
+
} */
|
|
12
|
+
|
|
13
|
+
export function getResolver(resolverUrl?: string): Record<string, DIDResolver> {
|
|
14
|
+
if (resolverUrl) return new CheqdDidResolver(resolverUrl).build()
|
|
15
|
+
|
|
16
|
+
return new CheqdDidResolver().build()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class CheqdDidResolver {
|
|
20
|
+
private resolverUrl: undefined | string =
|
|
21
|
+
'https://resolver.cheqd.net/1.0/identifiers/'
|
|
22
|
+
|
|
23
|
+
constructor(resolverUrl?: string) {
|
|
24
|
+
if (resolverUrl) this.resolverUrl = resolverUrl
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async resolve(
|
|
28
|
+
did: string,
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
|
+
parsed: ParsedDID,
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
32
|
+
_unused: Resolvable,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
options: DIDResolutionOptions,
|
|
35
|
+
): Promise<DIDResolutionResult> {
|
|
36
|
+
try {
|
|
37
|
+
const result = await fetch(this.resolverUrl + did, {
|
|
38
|
+
headers: { 'Content-Type': 'application/did+json' },
|
|
39
|
+
})
|
|
40
|
+
const ddo = (await result.json()) as DIDResolutionResult
|
|
41
|
+
return ddo
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return Promise.reject(e)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
build(): Record<string, DIDResolver> {
|
|
48
|
+
return { cheqd: this.resolve.bind(this) }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { DIDResolver } from 'did-resolver'
|
|
2
|
+
|
|
3
|
+
interface Options {
|
|
4
|
+
url: string
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated please use `getUniresolver(url)` or `getUniresolverFor(methods, url)` instead
|
|
9
|
+
*/
|
|
10
|
+
export class CheqdResolver {
|
|
11
|
+
constructor(options: Options) {
|
|
12
|
+
return getUniversalResolver(options.url)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a DIDResolver instance that can be used with `did-resolver`
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const uniResolver = getUniversalResolver()
|
|
22
|
+
* const resolver = new Resolver({
|
|
23
|
+
* web: uniResolver,
|
|
24
|
+
* key: uniResolver,
|
|
25
|
+
* elem: uniResolver
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param url the URL for the universal resolver instance (See https://uniresolver.io )
|
|
30
|
+
* @returns `DIDResolver`
|
|
31
|
+
*/
|
|
32
|
+
export function getUniversalResolver(
|
|
33
|
+
url = 'https://resolver.cheqd.net/1.0/identifiers/',
|
|
34
|
+
): DIDResolver {
|
|
35
|
+
if (!url) {
|
|
36
|
+
throw Error('[did-resolver] Universal: url required')
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
const resolve: DIDResolver = async (didUrl: string): Promise<any> => {
|
|
41
|
+
try {
|
|
42
|
+
const result = await fetch(url + didUrl, {
|
|
43
|
+
headers: { 'Content-Type': 'application/did+ld+json' },
|
|
44
|
+
})
|
|
45
|
+
const ddo = await result.json()
|
|
46
|
+
return ddo
|
|
47
|
+
} catch (e) {
|
|
48
|
+
return Promise.reject(e)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return resolve
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Creates a mapping of DID methods to a DIDResolver instance that can be used with `did-resolver`
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const uniResolver = getUniversalResolverFor(['web', 'key', 'elem'])
|
|
61
|
+
* const resolver = new Resolver({
|
|
62
|
+
* ...uniResolver,
|
|
63
|
+
* // other resolvers
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param methods an array of DID methods that should be resolved by this universal resolver
|
|
68
|
+
* @param url the URL for the universal resolver instance (See https://uniresolver.io )
|
|
69
|
+
* @returns `Record<string, DIDResolver>` a mapping of the given methods to an instance of `DIDResolver`
|
|
70
|
+
*/
|
|
71
|
+
export function getUniversalResolverFor(
|
|
72
|
+
methods: string[],
|
|
73
|
+
url = 'https://resolver.cheqd.net/1.0/identifiers/',
|
|
74
|
+
): Record<string, DIDResolver> {
|
|
75
|
+
const uniResolver = getUniversalResolver(url)
|
|
76
|
+
const mapping: Record<string, DIDResolver> = {}
|
|
77
|
+
for (const method of methods) {
|
|
78
|
+
mapping[method] = uniResolver
|
|
79
|
+
}
|
|
80
|
+
return mapping
|
|
81
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
*/
|
|
4
|
+
// It can be disabled even not import statement is needed
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
6
|
+
const schema = require('../plugin.schema.json')
|
|
7
|
+
export { schema }
|
|
8
|
+
export { CheqdDIDProvider } from './did-manager/cheqd-did-provider'
|
|
9
|
+
export { CheqdDidResolver, getResolver } from './did-manager/cheqd-did-resolver'
|
|
10
|
+
export { CheqdResolver } from './did-manager/resolver'
|