Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Refactor/redundant config options (#120)
Browse files Browse the repository at this point in the history
* combine options into config and use unshift to push .use() options to front of list

* fix lint

* Refactor redundant config and options #118

* Updated @dcx-protocol/root to version 2.0.0
Updated @dcx-protocol/applicant to version 2.0.0
Updated @dcx-protocol/common to version 3.0.0
Updated @dcx-protocol/issuer to version 2.0.0
Updated @dcx-protocol/server to version 2.0.0
Package versions updated: {
  root: '2.0.0',
  applicant: '2.0.0',
  common: '3.0.0',
  issuer: '2.0.0',
  server: '2.0.0'
}

* add changeset for major version bump

* fix build and tests

* remove close()

* bump common minor
  • Loading branch information
bnonni committed Aug 27, 2024
1 parent e038aea commit 67f34aa
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 310 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-candles-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dcx-protocol/common': minor
---

slightly changes the dcx-config related to #118
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcx-protocol/root",
"version": "2.0.0",
"version": "3.1.0",
"description": "DCX: Decentralized Credential Exchange. DWN protocol for verifiable credential exchange.",
"type": "module",
"workspaces": [
Expand Down
4 changes: 2 additions & 2 deletions packages/applicant/tests/dcx-applicant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ describe('applicant = new DcxApplicant({ config: applicantConfig })', () => {
describe('applicant.config', () => {
// Check applicant.config property "web5Password"
it('should contain property "web5Password" as a string', () => {
expect(applicant.config.web5Password).to.be.a('boolean').and.to.be.false;
expect(applicant.config.web5Password).to.be.a('string');
});

// Check applicant.config property "web5RecoveryPhrase"
it('should contain property "web5RecoveryPhrase" as a string', () => {
expect(applicant.config.web5RecoveryPhrase).to.be.a('boolean').and.to.be.false;
expect(applicant.config.web5RecoveryPhrase).to.be.a('string');
});

// Check applicant.config property "handlers"
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcx-protocol/common",
"version": "3.0.0",
"version": "3.1.0",
"description": "Common library shared by the other @dcx-protocol packages",
"type": "module",
"main": "./dist/cjs/index.js",
Expand Down
15 changes: 3 additions & 12 deletions packages/common/src/dcx-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
TrustedIssuer
} from './index.js';

export interface IDcxConfig {
export type DcxConfig = {
handlers: Handler[];
providers: Provider[];
manifests: CredentialManifest[];
Expand All @@ -17,15 +17,6 @@ export interface IDcxConfig {
dwns: string[];
}

export class DcxConfig implements IDcxConfig {
handlers: Handler[] = [];
providers: Provider[] = [];
manifests: CredentialManifest[] = [];
issuers: TrustedIssuer[] = [];
gateways: string[] = [];
dwns: string[] = [];
}

export const MX = { name: 'mx', id: 'did:dht:kfcakjzahwimgo9zzjw6yknt9srdtkmfqbeybekcg3xzz1ztg95y' };
export const FF = { name: 'formfree', id: 'did:dht:hcf5e55bbm44s4oixp5z89wtxenxyk35su7f5pd4r5np93ikyowy' };

Expand All @@ -34,6 +25,6 @@ export const dcxConfig: DcxConfig = {
providers : [],
manifests : [DcxHandshakeManifest, PhoneNumberManifest, EmailAddressManifest],
issuers : [MX, FF],
gateways : ['https://dwn.tbddev.org/beta'],
dwns : ['https://diddht.tbddev.org/'],
gateways : ['https://diddht.tbddev.org/'],
dwns : ['https://dwn.tbddev.org/beta'],
};
31 changes: 29 additions & 2 deletions packages/common/src/dcx-identity-vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,35 @@ export class DcxIdentityVault implements IdentityVault<{ InitializeResult: strin
}
}

async backup(): Promise<IdentityVaultBackup> {
throw new Error('Method not implemented.');
public async backup(): Promise<IdentityVaultBackup> {
// Verify the identity vault has already been initialized and unlocked.
if (this.isLocked() || await this.isInitialized() === false) {
throw new Error(
'HdIdentityVault: Unable to proceed with the backup operation because the identity vault ' +
'has not been initialized and unlocked. Please ensure the vault is properly initialized ' +
'with a secure password before attempting to backup its contents.'
);
}

// Encode the encrypted CEK and DID as a single Base64Url string.
const backupData: IdentityVaultBackupData = {
did : await this.getStoredDidDcx(),
contentEncryptionKey : await this.getStoredContentEncryptionKeyDcx(),
status : await this.getStatus()
};
const backupDataString = Convert.object(backupData).toBase64Url();

// Create a backup object containing the encrypted vault contents.
const backup: IdentityVaultBackup = {
data : backupDataString,
dateCreated : new Date().toISOString(),
size : backupDataString.length
};

// Update the last backup timestamp in the data store.
await this.setStatusDcx({ lastBackup: backup.dateCreated });

return backup;
}

public async initialize({
Expand Down
57 changes: 30 additions & 27 deletions packages/common/tests/dcx-agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import { expect } from 'chai';
import { DcxAgent, DcxIdentityVault, FileSystem, Mnemonic } from '../src/index.js';
import { LevelStore } from '@web5/common';

describe('DcxAgent', () => {
const dataPath = '__TEST_DATA__/DCX/COMMON/AGENT';
describe('agent = await DcxAgent.create({ dataPath, agentVault: new DcxIdentityVault({ location }) })', () => {
const dataPath = '__AGENT_DATA__/DCX/COMMON/AGENT';
const password = Mnemonic.createPassword();
const recoveryPhrase = Mnemonic.createRecoveryPhrase();
const location = `${dataPath}/VAULT_STORE`;

let agent: DcxAgent;

before(async () => {
agent = await DcxAgent.create({ dataPath });
});

after(async () => {
await FileSystem.rm('__TEST_DATA__', { recursive: true, force: true });
await agent.vault.store.close();
await FileSystem.rm('__AGENT_DATA__', { recursive: true, force: true });
});

describe('agent = await DcxAgent.create({ dataPath, agentVault: new DcxIdentityVault({ location }) })', () => {
describe('agent', () => {
it('should be an instanceof DcxAgent', async () => {
agent = await DcxAgent.create({ dataPath, agentVault: new DcxIdentityVault({ location }) });
expect(agent).to.be.instanceof(DcxAgent);
});

Expand All @@ -38,35 +41,35 @@ describe('DcxAgent', () => {
expect(agent.vault.store).to.be.instanceof(LevelStore);
});
});
});

describe('await agent.firstLaunch()', () => {
it('should be true', async () => {
expect(await agent.firstLaunch()).to.be.true;
describe('await agent.firstLaunch()', () => {
it('should be true', async () => {
expect(await agent.firstLaunch()).to.be.true;
});
});
});

describe('await agent.initialize({ password, recoveryPhrase, dwnEndpoints })', () => {
it('should initialize and return a matching recoveryPhrase', async () => {
expect(await agent.initialize({ password, recoveryPhrase, dwnEndpoints: ['http://localhost:3000'] })).to.equal(recoveryPhrase);
});
describe('await agent.initialize({ password, recoveryPhrase, dwnEndpoints })', () => {
it('should initialize and return a matching recoveryPhrase', async () => {
expect(await agent.initialize({ password, recoveryPhrase, dwnEndpoints: ['http://localhost:3000'] })).to.equal(recoveryPhrase);
});

it('should have a vault that is initialized', async () => {
expect(await agent.vault.isInitialized()).to.be.true;
it('should have a vault that is initialized', async () => {
expect(await agent.firstLaunch()).to.be.false;
});
});
});

describe('await agent.start({ password })', () => {
it('should start the agent', async () => {
await agent.start({ password });
});
describe('await agent.start({ password })', () => {
it('should start the agent', async () => {
await agent.start({ password });
});

it('should have an unlocked vault', () => {
expect(agent.vault.isLocked()).to.be.false;
});
it('should have an unlocked vault', () => {
expect(agent.vault.isLocked()).to.be.false;
});

it('should have agentDid as instanceof BearerDid', () => {
expect(agent.agentDid).to.be.instanceof(BearerDid);
it('should have agentDid as instanceof BearerDid', () => {
expect(agent.agentDid).to.be.instanceof(BearerDid);
});
});
});
});
5 changes: 1 addition & 4 deletions packages/common/tests/dcx-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import dotenv from 'dotenv';
dotenv.config({ path: '.env.test' });

import { expect } from 'chai';
import { DcxConfig, dcxConfig } from '../src/index.js';
import { dcxConfig } from '../src/index.js';

describe('DcxConfig', () => {
it('should be an instance of DcxConfig', () => {
expect(dcxConfig).that.is.an.instanceof(DcxConfig);
});

it('should have entries of length >= 6', () => {
expect(Object.entries(dcxConfig)).to.have.lengthOf.gte(6);
Expand Down
Loading

0 comments on commit 67f34aa

Please sign in to comment.