@@ -257,6 +257,13 @@ export class DIDModule extends AbstractCheqdSDKModule {
257
257
throw new Error ( `DID payload is not spec compliant: ${ error } ` ) ;
258
258
}
259
259
260
+ const { valid : authenticationValid , error : authenticationError } =
261
+ await DIDModule . validateAuthenticationAgainstSignatures ( didPayload , signInputs as SignInfo [ ] , this . querier ) ;
262
+
263
+ if ( ! authenticationValid ) {
264
+ throw new Error ( `DID authentication is not valid: ${ authenticationError } ` ) ;
265
+ }
266
+
260
267
const payload = MsgCreateDidDocPayload . fromPartial ( {
261
268
context : < string [ ] > didPayload ?. [ '@context' ] ,
262
269
id : didPayload . id ,
@@ -328,6 +335,17 @@ export class DIDModule extends AbstractCheqdSDKModule {
328
335
throw new Error ( `DID payload is not spec compliant: ${ error } ` ) ;
329
336
}
330
337
338
+ const { valid : authenticationValid , error : authenticationError } =
339
+ await DIDModule . validateAuthenticationAgainstSignaturesKeyRotation (
340
+ didPayload ,
341
+ signInputs as SignInfo [ ] ,
342
+ this . querier
343
+ ) ;
344
+
345
+ if ( ! authenticationValid ) {
346
+ throw new Error ( `DID authentication is not valid: ${ authenticationError } ` ) ;
347
+ }
348
+
331
349
const payload = MsgUpdateDidDocPayload . fromPartial ( {
332
350
context : < string [ ] > didPayload ?. [ '@context' ] ,
333
351
id : didPayload . id ,
@@ -342,9 +360,27 @@ export class DIDModule extends AbstractCheqdSDKModule {
342
360
alsoKnownAs : < string [ ] > didPayload . alsoKnownAs ,
343
361
versionId : versionId ,
344
362
} ) ;
363
+
364
+ // check whether external controller or not
365
+ const externalController = ( didPayload . controller as string [ ] ) . some ( ( c ) => c !== didPayload . id ) ;
366
+
367
+ // get external controllers' documents, if any
368
+ const externalControllersDocuments = externalController
369
+ ? (
370
+ await Promise . all (
371
+ ( didPayload . controller as string [ ] )
372
+ . filter ( ( c ) => c !== didPayload . id )
373
+ . map ( async ( c ) => {
374
+ const { didDoc } = await this . querier [ defaultDidExtensionKey ] . didDoc ( c ) ;
375
+ return didDoc ;
376
+ } )
377
+ )
378
+ ) . filter ( ( d ) => d !== undefined ) || [ ]
379
+ : [ ] ;
380
+
345
381
let signatures : SignInfo [ ] ;
346
382
if ( ISignInputs . isSignInput ( signInputs ) ) {
347
- signatures = await this . _signer . #dateDidDocTx ( signInputs , payload ) ;
383
+ signatures = await this . _signer . #dateDidDocTx ( signInputs , payload , externalControllersDocuments ) ;
348
384
} else {
349
385
signatures = signInputs ;
350
386
}
@@ -393,14 +429,21 @@ export class DIDModule extends AbstractCheqdSDKModule {
393
429
throw new Error ( `DID payload is not spec compliant: ${ error } ` ) ;
394
430
}
395
431
432
+ const { valid : authenticationValid , error : authenticationError } =
433
+ await DIDModule . validateAuthenticationAgainstSignatures ( didPayload , signInputs as SignInfo [ ] , this . querier ) ;
434
+
435
+ if ( ! authenticationValid ) {
436
+ throw new Error ( `DID authentication is not valid: ${ authenticationError } ` ) ;
437
+ }
438
+
396
439
const payload = MsgDeactivateDidDocPayload . fromPartial ( {
397
440
id : didPayload . id ,
398
441
versionId : versionId ,
399
442
} ) ;
400
443
401
444
let signatures : SignInfo [ ] ;
402
445
if ( ISignInputs . isSignInput ( signInputs ) ) {
403
- signatures = await this . _signer . signdeactivateDidDocTx ( signInputs , payload , protobufVerificationMethod ! ) ;
446
+ signatures = await this . _signer . signDeactivateDidDocTx ( signInputs , payload , protobufVerificationMethod ! ) ;
404
447
} else {
405
448
signatures = signInputs ;
406
449
}
0 commit comments