Skip to content

Commit 448e821

Browse files
authored
Feature/idcom 2208 did sol resolve bug
#213
1 parent 8a171a5 commit 448e821

File tree

5 files changed

+324
-663
lines changed

5 files changed

+324
-663
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
`class JsonRpcSigner extends Signer` of `ethers`.
1616
- Filter methods on `DidAccount` verificationmethods are not public.
1717
- `DidSolError` is now public.
18+
- Fixed resolve error when setting verificationmethod flags
1819

1920
### Deprecated
2021

sol-did/client/packages/core/src/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export const mapVerificationMethodsToDidComponents = (
160160
`${identifier.toString()}#${method.fragment}`
161161
);
162162
}
163-
if (method.flags.has(BitwiseVerificationMethodFlag.Authentication)) {
163+
if (method.flags.has(BitwiseVerificationMethodFlag.Assertion)) {
164164
didComponents.assertionMethod.push(
165165
`${identifier.toString()}#${method.fragment}`
166166
);

sol-did/scripts/createTestFixtureAccount.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
DID_SOL_PROGRAM,
1111
BitwiseVerificationMethodFlag,
1212
} from '@identity.com/sol-did-client';
13-
import { SolDid } from '../dist/target/types/sol_did';
13+
import { SolDid } from '../target/types/sol_did';
1414

1515
import { airdrop, getTestService } from '../tests/utils/utils';
1616
import { getDerivationPath, MNEMONIC } from '../tests/fixtures/config';

sol-did/tests/suite-resolve/resolve.ts

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
AddVerificationMethodParams,
1616
DidAccountSizeHelper,
1717
LegacyClient,
18+
RawDidSolDataAccount,
1819
} from '@identity.com/sol-did-client';
1920

2021
import {
@@ -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

Comments
 (0)