Skip to content

Commit

Permalink
Merge pull request #200 from identity-com/feature/IDCOM-2208__did-sol…
Browse files Browse the repository at this point in the history
…-resolve-bug

assertion flags issue in resolve
  • Loading branch information
DiosAkhilleus authored Dec 8, 2022
2 parents 8a171a5 + add5dc8 commit 7efb212
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 663 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`class JsonRpcSigner extends Signer` of `ethers`.
- Filter methods on `DidAccount` verificationmethods are not public.
- `DidSolError` is now public.
- Fixed resolve error when setting verificationmethod flags

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion sol-did/client/packages/core/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const mapVerificationMethodsToDidComponents = (
`${identifier.toString()}#${method.fragment}`
);
}
if (method.flags.has(BitwiseVerificationMethodFlag.Authentication)) {
if (method.flags.has(BitwiseVerificationMethodFlag.Assertion)) {
didComponents.assertionMethod.push(
`${identifier.toString()}#${method.fragment}`
);
Expand Down
2 changes: 1 addition & 1 deletion sol-did/scripts/createTestFixtureAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DID_SOL_PROGRAM,
BitwiseVerificationMethodFlag,
} from '@identity.com/sol-did-client';
import { SolDid } from '../dist/target/types/sol_did';
import { SolDid } from '../target/types/sol_did';

import { airdrop, getTestService } from '../tests/utils/utils';
import { getDerivationPath, MNEMONIC } from '../tests/fixtures/config';
Expand Down
60 changes: 51 additions & 9 deletions sol-did/tests/suite-resolve/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AddVerificationMethodParams,
DidAccountSizeHelper,
LegacyClient,
RawDidSolDataAccount,
} from '@identity.com/sol-did-client';

import {
Expand Down Expand Up @@ -172,22 +173,22 @@ describe('sol-did resolve and migrate operations', () => {
expect(didDoc).to.deep.equal(
Object.assign({}, migratedLegacyDidDocComplete, {
capabilityInvocation:
migratedLegacyDidDocComplete.capabilityInvocation.filter(
migratedLegacyDidDocComplete.capabilityInvocation?.filter(
(x: string) => !x.endsWith('ledger')
),
verificationMethod:
migratedLegacyDidDocComplete.verificationMethod.filter(
migratedLegacyDidDocComplete.verificationMethod?.filter(
(vm) => !vm.id.endsWith('#ledger')
),
service: migratedLegacyDidDocComplete.service.filter(
service: migratedLegacyDidDocComplete.service?.filter(
(s) => !s.id.endsWith('#test784378')
),
})
);

// check that auth
const didAccount = await legacyDidService.getDidAccount();
expect(didAccount.verificationMethods[0].flags.raw).to.equal(
expect(didAccount?.verificationMethods[0].flags.raw).to.equal(
BitwiseVerificationMethodFlag.OwnershipProof |
BitwiseVerificationMethodFlag.CapabilityInvocation
);
Expand Down Expand Up @@ -218,10 +219,12 @@ describe('sol-did resolve and migrate operations', () => {
// check migration
const [didAccount, didAccountSize] =
await legacyDidService.getDidAccountWithSize();
expect(didAccount.services[0].serviceEndpoint).to.equal(randomString);
expect(didAccount?.services[0].serviceEndpoint).to.equal(randomString);

expect(
new DidAccountSizeHelper(didAccount.raw).getDidAccountSize()
new DidAccountSizeHelper(
didAccount?.raw as RawDidSolDataAccount
).getDidAccountSize()
).to.equal(490);
expect(didAccountSize).to.equal(500);

Expand All @@ -247,7 +250,7 @@ describe('sol-did resolve and migrate operations', () => {

// check that auth
const didAccount = await legacyDidService.getDidAccount();
expect(didAccount.verificationMethods[0].flags.raw).to.equal(
expect(didAccount?.verificationMethods[0].flags.raw).to.equal(
BitwiseVerificationMethodFlag.OwnershipProof |
BitwiseVerificationMethodFlag.CapabilityInvocation
);
Expand Down Expand Up @@ -296,7 +299,7 @@ describe('sol-did resolve and migrate operations', () => {
// legacyAuthority.publicKey
// );
// replacement check
expect(legacyAccount.authority.toPublicKey().toBase58()).to.equal(
expect(legacyAccount?.authority.toPublicKey().toBase58()).to.equal(
legacyAuthority.publicKey.toBase58()
);

Expand Down Expand Up @@ -383,7 +386,7 @@ describe('sol-did resolve and migrate operations', () => {
);
expect(
updated_account?.verificationMethods[0].flags.array
).to.be.deep.equal(lastElement.flags);
).to.be.deep.equal(lastElement?.flags);
expect(updated_account?.verificationMethods[0].keyData).to.be.deep.equal(
authority.publicKey.toBytes()
);
Expand All @@ -397,6 +400,45 @@ describe('sol-did resolve and migrate operations', () => {
expect(updated_account?.controllers).to.be.deep.equal([]);
});

it('updates the verificationMethods of a DID with the correct flags', async () => {
await existingAccount(service);
let vms: AddVerificationMethodParams[] = [
getTestVerificationMethod('key1'),
getTestVerificationMethod('key2', Keypair.generate().publicKey, [
BitwiseVerificationMethodFlag.Authentication,
BitwiseVerificationMethodFlag.Assertion,
BitwiseVerificationMethodFlag.KeyAgreement,
BitwiseVerificationMethodFlag.CapabilityDelegation,
]),
getTestVerificationMethod('key3'),
getTestVerificationMethod('key4'),
];
await service
.update({
controllerDIDs: [],
services: [],
verificationMethods: vms,
})
.withSolWallet(authority)
.rpc();
let updated_account = await service.getDidAccount();
const doc = await service.resolve();
expect(doc.authentication).to.be.deep.equal([
`did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#default`,
`did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2`,
]);
expect(doc.assertionMethod).to.be.deep.equal([
`did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2`,
]);
expect(doc.keyAgreement).to.be.deep.equal([
`did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#default`,
`did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2`,
]);
expect(doc.capabilityDelegation).to.be.deep.equal([
`did:sol:localnet:A2oYuurjzc8ACwQQN56SBLv1kUmYJJTBjwMNWVNgVaT3#key2`,
]);
});

it('cannot update the verificationMethods of a Did if there are replications', async () => {
await existingAccount(service);
let vms = [
Expand Down
Loading

0 comments on commit 7efb212

Please sign in to comment.