Skip to content

Commit

Permalink
Add test for DID_DOC_HIDDEN flag
Browse files Browse the repository at this point in the history
Add support and relevant tests for the new DID_DOC_HIDDEN flag.

PR: #20

Signed-off-by: Martin Riedel <[email protected]>
Reviewed-by: Robert Leonard <[email protected]>
  • Loading branch information
rado0x54 committed Sep 29, 2023
1 parent bb75e87 commit 0faea7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
6 changes: 1 addition & 5 deletions ts-client/src/service/DidRegistryInternal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Overrides } from 'ethers';

import {
MappedWriteOperation,
Options,
ReadOnlyOperation,
} from '../utils';
import { MappedWriteOperation, Options, ReadOnlyOperation } from '../utils';
import { omit } from 'ramda';
import { DIDRegistry } from '../contracts/typechain-types';
import { DidIdentifier } from './DidIdentifier';
Expand Down
10 changes: 5 additions & 5 deletions ts-client/src/utils/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum BitwiseVerificationMethodFlag {
CapabilityDelegation = 1 << 4,
OwnershipProof = 1 << 5,
Protected = 1 << 6,
DidDocHidden = 1 << 7,
}

export enum VerificationMethodType {
Expand Down Expand Up @@ -56,7 +57,7 @@ export type RawVerificationMethod = {
keyData: string;
};

export type ChainEnviroment = 'mainnet' | 'testnet' | 'localnet'
export type ChainEnviroment = 'mainnet' | 'testnet' | 'localnet';

export type RawService = {
fragment: string;
Expand All @@ -78,10 +79,9 @@ export const mapVerificationMethodsToDidComponents = (
};

for (const method of methods) {
// skip hidden methods (TODO: do we want to suppor this again?)
// if (method.flags.has(BitwiseVerificationMethodFlag.DidDocHidden)) {
// continue;
// }
if (method.flags.has(BitwiseVerificationMethodFlag.DidDocHidden)) {
continue;
}
if (method.flags.has(BitwiseVerificationMethodFlag.Authentication)) {
didComponents.authentication.push(
`${identifier.toString()}#${method.fragment}`
Expand Down
39 changes: 35 additions & 4 deletions ts-client/test/integration/DidRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ describe('Native TS Client Integration Test', () => {
const { address } = await deployDidRegistryContractInstance(deployerWallet);

// Connect didWallet and otherDidWallet to didRegistryContract
didRegistry = new DidRegistry(didWallet, address, {chainEnvironment: 'localnet'});
otherDidRegistry = new DidRegistry(otherDidWallet, address, {chainEnvironment: 'localnet'});
didRegistry = new DidRegistry(didWallet, address, {
chainEnvironment: 'localnet',
});
otherDidRegistry = new DidRegistry(otherDidWallet, address, {
chainEnvironment: 'localnet',
});
otherDidRegistry.setDidIdentifier(didWallet.address); // otherDidWallet is message sender, but DID is still from didWallet
unauthorizedDidRegistry = new DidRegistry(unauthorizedWallet, address, {chainEnvironment: 'localnet'});
unauthorizedDidRegistry = new DidRegistry(unauthorizedWallet, address, {
chainEnvironment: 'localnet',
});
unauthorizedDidRegistry.setDidIdentifier(didWallet.address); // unauthorizedDidWallet is message sender, but DID is still from didWallet
});

it('should generate DIDs with the correct prefix', () => {
expect(didRegistry.getDid().toString()).to.be.a('string').and.satisfy((did: string) => did.startsWith('did:bnb:localnet:'));
expect(didRegistry.getDid().toString())
.to.be.a('string')
.and.satisfy((did: string) => did.startsWith('did:bnb:localnet:'));
});

it('should resolve an initial DID State of the didWallet', async () => {
Expand Down Expand Up @@ -233,6 +241,29 @@ describe('Native TS Client Integration Test', () => {
);
});

it('should hide verification methods in the did document if the related flag is set', async () => {
const currentVerificationMethods = await otherDidRegistry
.resolve()
.then((doc) => doc.verificationMethod);

const tx = await otherDidRegistry
.setVerificationMethodFlags(SECONDARY_KEY_ID, [
BitwiseVerificationMethodFlag.DidDocHidden,
BitwiseVerificationMethodFlag.CapabilityInvocation,
])
.then((tx) => tx.wait());
expect(tx.status).to.equal(1);

const doc = await otherDidRegistry.resolve();
expect(doc.verificationMethod).to.have.lengthOf(
(currentVerificationMethods?.length || Number.NaN) - 1
);
// make sure the hidden verification method is not in the did document
expect(
doc.verificationMethod?.find((vm) => vm.id.endsWith(SECONDARY_KEY_ID))
).to.be.undefined;
});

it('should not able set Ownership proof for a different key', async () => {
return expect(
didRegistry.setVerificationMethodFlags(SECONDARY_KEY_ID, [
Expand Down

0 comments on commit 0faea7f

Please sign in to comment.