|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -import { Resolver, parse } from '../resolver' |
| 15 | +import { Resolver, parse, DIDResolutionResult } from '../resolver' |
16 | 16 |
|
17 | 17 | describe('resolver', () => { |
18 | 18 | describe('parse()', () => { |
@@ -161,7 +161,7 @@ describe('resolver', () => { |
161 | 161 | beforeAll(() => { |
162 | 162 | mockmethod = jest.fn().mockReturnValue(mockReturn) |
163 | 163 | resolver = new Resolver({ |
164 | | - example: async (did: string) => ({ |
| 164 | + example: async (did: string): Promise<DIDResolutionResult> => ({ |
165 | 165 | didResolutionMetadata: { contentType: 'application/did+ld+json' }, |
166 | 166 | didDocument: { |
167 | 167 | '@context': 'https://w3id.org/did/v1', |
@@ -213,6 +213,114 @@ describe('resolver', () => { |
213 | 213 | didDocumentMetadata: {}, |
214 | 214 | }) |
215 | 215 | }) |
| 216 | + |
| 217 | + it('resolves did document with service', async () => { |
| 218 | + const altResolver = new Resolver({ |
| 219 | + example: async (did: string): Promise<DIDResolutionResult> => ({ |
| 220 | + didResolutionMetadata: { contentType: 'application/did+ld+json' }, |
| 221 | + didDocument: { |
| 222 | + '@context': 'https://w3id.org/did/v1', |
| 223 | + id: did, |
| 224 | + verificationMethod: [ |
| 225 | + { |
| 226 | + id: 'owner', |
| 227 | + controller: '1234', |
| 228 | + type: 'xyz', |
| 229 | + }, |
| 230 | + ], |
| 231 | + service: [ |
| 232 | + { |
| 233 | + id: `service-${did}`, |
| 234 | + type: 'Service', |
| 235 | + serviceEndpoint: 'https://example.com/', |
| 236 | + } |
| 237 | + ], |
| 238 | + }, |
| 239 | + didDocumentMetadata: {}, |
| 240 | + }), |
| 241 | + mock: mockmethod, |
| 242 | + }) |
| 243 | + |
| 244 | + await expect(altResolver.resolve('did:example:123456789')).resolves.toEqual({ |
| 245 | + didResolutionMetadata: { contentType: 'application/did+ld+json' }, |
| 246 | + didDocument: { |
| 247 | + '@context': 'https://w3id.org/did/v1', |
| 248 | + id: 'did:example:123456789', |
| 249 | + verificationMethod: [ |
| 250 | + { |
| 251 | + id: 'owner', |
| 252 | + controller: '1234', |
| 253 | + type: 'xyz', |
| 254 | + }, |
| 255 | + ], |
| 256 | + service: [ |
| 257 | + { |
| 258 | + id: 'service-did:example:123456789', |
| 259 | + type: 'Service', |
| 260 | + serviceEndpoint: 'https://example.com/', |
| 261 | + } |
| 262 | + ], |
| 263 | + }, |
| 264 | + didDocumentMetadata: {}, |
| 265 | + }) |
| 266 | + }) |
| 267 | + |
| 268 | + it('resolves did document with expanded service', async () => { |
| 269 | + const altResolver = new Resolver({ |
| 270 | + example: async (did: string): Promise<DIDResolutionResult> => ({ |
| 271 | + didResolutionMetadata: { contentType: 'application/did+ld+json' }, |
| 272 | + didDocument: { |
| 273 | + '@context': 'https://w3id.org/did/v1', |
| 274 | + id: did, |
| 275 | + verificationMethod: [ |
| 276 | + { |
| 277 | + id: 'owner', |
| 278 | + controller: '1234', |
| 279 | + type: 'xyz', |
| 280 | + }, |
| 281 | + ], |
| 282 | + service: [ |
| 283 | + { |
| 284 | + id: `service-${did}`, |
| 285 | + type: 'Service', |
| 286 | + serviceEndpoint: { |
| 287 | + uri: 'yep', |
| 288 | + accept: ['xyz'] |
| 289 | + }, |
| 290 | + } |
| 291 | + ], |
| 292 | + }, |
| 293 | + didDocumentMetadata: {}, |
| 294 | + }), |
| 295 | + mock: mockmethod, |
| 296 | + }) |
| 297 | + |
| 298 | + await expect(altResolver.resolve('did:example:123456789')).resolves.toEqual({ |
| 299 | + didResolutionMetadata: { contentType: 'application/did+ld+json' }, |
| 300 | + didDocument: { |
| 301 | + '@context': 'https://w3id.org/did/v1', |
| 302 | + id: 'did:example:123456789', |
| 303 | + verificationMethod: [ |
| 304 | + { |
| 305 | + id: 'owner', |
| 306 | + controller: '1234', |
| 307 | + type: 'xyz', |
| 308 | + }, |
| 309 | + ], |
| 310 | + service: [ |
| 311 | + { |
| 312 | + id: 'service-did:example:123456789', |
| 313 | + type: 'Service', |
| 314 | + serviceEndpoint: { |
| 315 | + uri: 'yep', |
| 316 | + accept: ['xyz'] |
| 317 | + }, |
| 318 | + } |
| 319 | + ], |
| 320 | + }, |
| 321 | + didDocumentMetadata: {}, |
| 322 | + }) |
| 323 | + }) |
216 | 324 |
|
217 | 325 | it('resolves did document with legacy resolver', async () => { |
218 | 326 | const resolverWithLegacy = new Resolver( |
|
0 commit comments