@@ -15,6 +15,7 @@ import {
1515 AddVerificationMethodParams ,
1616 DidAccountSizeHelper ,
1717 LegacyClient ,
18+ RawDidSolDataAccount ,
1819} from '@identity.com/sol-did-client' ;
1920
2021import {
@@ -172,22 +173,22 @@ describe('sol-did resolve and migrate operations', () => {
172173 expect ( didDoc ) . to . deep . equal (
173174 Object . assign ( { } , migratedLegacyDidDocComplete , {
174175 capabilityInvocation :
175- migratedLegacyDidDocComplete . capabilityInvocation . filter (
176+ migratedLegacyDidDocComplete . capabilityInvocation ? .filter (
176177 ( x : string ) => ! x . endsWith ( 'ledger' )
177178 ) ,
178179 verificationMethod :
179- migratedLegacyDidDocComplete . verificationMethod . filter (
180+ migratedLegacyDidDocComplete . verificationMethod ? .filter (
180181 ( vm ) => ! vm . id . endsWith ( '#ledger' )
181182 ) ,
182- service : migratedLegacyDidDocComplete . service . filter (
183+ service : migratedLegacyDidDocComplete . service ? .filter (
183184 ( s ) => ! s . id . endsWith ( '#test784378' )
184185 ) ,
185186 } )
186187 ) ;
187188
188189 // check that auth
189190 const didAccount = await legacyDidService . getDidAccount ( ) ;
190- expect ( didAccount . verificationMethods [ 0 ] . flags . raw ) . to . equal (
191+ expect ( didAccount ? .verificationMethods [ 0 ] . flags . raw ) . to . equal (
191192 BitwiseVerificationMethodFlag . OwnershipProof |
192193 BitwiseVerificationMethodFlag . CapabilityInvocation
193194 ) ;
@@ -218,10 +219,12 @@ describe('sol-did resolve and migrate operations', () => {
218219 // check migration
219220 const [ didAccount , didAccountSize ] =
220221 await legacyDidService . getDidAccountWithSize ( ) ;
221- expect ( didAccount . services [ 0 ] . serviceEndpoint ) . to . equal ( randomString ) ;
222+ expect ( didAccount ? .services [ 0 ] . serviceEndpoint ) . to . equal ( randomString ) ;
222223
223224 expect (
224- new DidAccountSizeHelper ( didAccount . raw ) . getDidAccountSize ( )
225+ new DidAccountSizeHelper (
226+ didAccount ?. raw as RawDidSolDataAccount
227+ ) . getDidAccountSize ( )
225228 ) . to . equal ( 490 ) ;
226229 expect ( didAccountSize ) . to . equal ( 500 ) ;
227230
@@ -247,7 +250,7 @@ describe('sol-did resolve and migrate operations', () => {
247250
248251 // check that auth
249252 const didAccount = await legacyDidService . getDidAccount ( ) ;
250- expect ( didAccount . verificationMethods [ 0 ] . flags . raw ) . to . equal (
253+ expect ( didAccount ? .verificationMethods [ 0 ] . flags . raw ) . to . equal (
251254 BitwiseVerificationMethodFlag . OwnershipProof |
252255 BitwiseVerificationMethodFlag . CapabilityInvocation
253256 ) ;
@@ -296,7 +299,7 @@ describe('sol-did resolve and migrate operations', () => {
296299 // legacyAuthority.publicKey
297300 // );
298301 // replacement check
299- expect ( legacyAccount . authority . toPublicKey ( ) . toBase58 ( ) ) . to . equal (
302+ expect ( legacyAccount ? .authority . toPublicKey ( ) . toBase58 ( ) ) . to . equal (
300303 legacyAuthority . publicKey . toBase58 ( )
301304 ) ;
302305
@@ -383,7 +386,7 @@ describe('sol-did resolve and migrate operations', () => {
383386 ) ;
384387 expect (
385388 updated_account ?. verificationMethods [ 0 ] . flags . array
386- ) . to . be . deep . equal ( lastElement . flags ) ;
389+ ) . to . be . deep . equal ( lastElement ? .flags ) ;
387390 expect ( updated_account ?. verificationMethods [ 0 ] . keyData ) . to . be . deep . equal (
388391 authority . publicKey . toBytes ( )
389392 ) ;
@@ -397,6 +400,45 @@ describe('sol-did resolve and migrate operations', () => {
397400 expect ( updated_account ?. controllers ) . to . be . deep . equal ( [ ] ) ;
398401 } ) ;
399402
403+ it ( 'updates the verificationMethods of a DID with the correct flags' , async ( ) => {
404+ await existingAccount ( service ) ;
405+ let vms : AddVerificationMethodParams [ ] = [
406+ getTestVerificationMethod ( 'key1' ) ,
407+ getTestVerificationMethod ( 'key2' , Keypair . generate ( ) . publicKey , [
408+ BitwiseVerificationMethodFlag . Authentication ,
409+ BitwiseVerificationMethodFlag . Assertion ,
410+ BitwiseVerificationMethodFlag . KeyAgreement ,
411+ BitwiseVerificationMethodFlag . CapabilityDelegation ,
412+ ] ) ,
413+ getTestVerificationMethod ( 'key3' ) ,
414+ getTestVerificationMethod ( 'key4' ) ,
415+ ] ;
416+ await service
417+ . update ( {
418+ controllerDIDs : [ ] ,
419+ services : [ ] ,
420+ verificationMethods : vms ,
421+ } )
422+ . withSolWallet ( authority )
423+ . rpc ( ) ;
424+ let updated_account = await service . getDidAccount ( ) ;
425+ const doc = await service . resolve ( ) ;
426+ expect ( doc . authentication ) . to . be . deep . equal ( [
427+ `did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#default` ,
428+ `did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2` ,
429+ ] ) ;
430+ expect ( doc . assertionMethod ) . to . be . deep . equal ( [
431+ `did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2` ,
432+ ] ) ;
433+ expect ( doc . keyAgreement ) . to . be . deep . equal ( [
434+ `did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#default` ,
435+ `did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2` ,
436+ ] ) ;
437+ expect ( doc . capabilityDelegation ) . to . be . deep . equal ( [
438+ `did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2` ,
439+ ] ) ;
440+ } ) ;
441+
400442 it ( 'cannot update the verificationMethods of a Did if there are replications' , async ( ) => {
401443 await existingAccount ( service ) ;
402444 let vms = [
0 commit comments