Skip to content

Commit

Permalink
implement idcxserver, dcxserver, issuerserver; todo - applicantserver
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnonni committed Aug 22, 2024
1 parent e0d8ad7 commit f5f6a3b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"publish:all": "pnpm --filter applicant publish && pnpm --filter common publish && pnpm --filter issuer publish && pnpm --filter server publish",
"test": "pnpm --recursive --stream test",
"test:node": "pnpm --recursive --stream test:node",
"workflow": "pnpm install --frozen-lockfile && pnpm lint && pnpm build && pnpm build:tests:node",
"workflow": "pnpm lint && pnpm install --frozen-lockfile && pnpm lint && pnpm build && pnpm build:tests:node",
"build-test": "pnpm --recursive --stream build && pnpm --recursive --stream build:tests:node && pnpm --recursive --stream test:node",
"version": "tsx scripts/version.ts",
"version:patch": "tsx scripts/version.ts patch",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/applicant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ApplicantServer extends DcxServer {
*/
constructor(params: { type: 'applicant', applicant: DcxApplicant; }) {
super(params);
this.applicant = params.applicant ?? this.dcxActor as DcxApplicant ?? new DcxApplicant({});
this.applicant = params.applicant ?? this.dcx as DcxApplicant ?? new DcxApplicant({});
}


Expand Down
30 changes: 15 additions & 15 deletions packages/server/src/dcx-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IssuerServer } from './issuer/index.js';
export interface IDcxServer {
isTest : boolean;
isPolling : boolean;
dcxActor : DcxIssuer | DcxApplicant;
dcx : DcxIssuer | DcxApplicant;
server : IssuerServer | ApplicantServer;

use(path: string, ...args: any[]): void;
Expand All @@ -21,33 +21,33 @@ export interface IDcxServer {
}

export interface DcxServerParams {
type?: 'issuer' | 'applicant';
issuer?: DcxIssuer;
applicant?: DcxApplicant
type?: 'issuer' | 'applicant';
}

export class DcxServer implements IDcxServer {
isPolling : boolean = false;
isTest : boolean = process.env.NODE_ENV?.includes('test') || argv.slice(2).some((arg) => ['--test', '-t'].includes(arg));

dcxActor : DcxIssuer | DcxApplicant;
dcx : DcxIssuer | DcxApplicant;
server : IssuerServer | ApplicantServer;

constructor(params: DcxServerParams) {
if(params.type === 'applicant' || params.applicant) {
this.dcxActor = params.applicant ?? new DcxApplicant({});
this.dcx = params.applicant ?? new DcxApplicant({});
this.server = new ApplicantServer({
type : 'applicant',
applicant : this.dcxActor as DcxApplicant
applicant : this.dcx as DcxApplicant
});
} else if (params.type === 'issuer' || params.issuer) {
this.dcxActor = params.issuer ?? new DcxIssuer({});
this.dcx = params.issuer ?? new DcxIssuer({});
this.server = new IssuerServer({
type : 'issuer',
issuer : this.dcxActor as DcxIssuer
issuer : this.dcx as DcxIssuer
});
} else {
throw new DcxServerError('Invalid server type: must be either "applicant" or "issuer"');
throw new DcxServerError('Invalid server params: must be pass type "applicant" or "issuer" or must pass an applicant or issuer object');
}
}

Expand All @@ -69,7 +69,7 @@ export class DcxServer implements IDcxServer {
);
}
if (validPaths.includes(path)) {
this.dcxActor.options[path].push(...args);
this.dcx.options[path].push(...args);
} else {
throw new DcxServerError(`Invalid server.use() object: ${args}`);
}
Expand All @@ -85,7 +85,7 @@ export class DcxServer implements IDcxServer {
*
*/
public useManifest(manifest: Manifest): void {
this.dcxActor.options.manifests.push(manifest);
this.dcx.options.manifests.push(manifest);
}

/**
Expand All @@ -98,7 +98,7 @@ export class DcxServer implements IDcxServer {
*
*/
public useHandler(handler: Handler): void {
this.dcxActor.options.handlers.push(handler);
this.dcx.options.handlers.push(handler);
}

/**
Expand All @@ -111,7 +111,7 @@ export class DcxServer implements IDcxServer {
*
*/
public useProvider(provider: Provider): void {
this.dcxActor.options.providers.push(provider);
this.dcx.options.providers.push(provider);
}

/**
Expand All @@ -124,7 +124,7 @@ export class DcxServer implements IDcxServer {
*
*/
public useIssuer(issuer: Issuer): void {
this.dcxActor.options.issuers.push(issuer);
this.dcx.options.issuers.push(issuer);
}

/**
Expand All @@ -136,7 +136,7 @@ export class DcxServer implements IDcxServer {
*
*/
public useDwn(dwn: string): void {
this.dcxActor.options.dwns.push(dwn);
this.dcx.options.dwns.push(dwn);
}

/**
Expand All @@ -148,6 +148,6 @@ export class DcxServer implements IDcxServer {
*
*/
public useGateway(gateway: string): void {
this.dcxActor.options.gateways.push(gateway);
this.dcx.options.gateways.push(gateway);
}
}
2 changes: 1 addition & 1 deletion packages/server/src/issuer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class IssuerServer extends DcxServer {
*/
constructor(params: { type: 'issuer', issuer: DcxIssuer; }) {
super(params);
this.issuer = params.issuer ?? this.dcxActor as DcxIssuer ?? new DcxIssuer({});
this.issuer = params.issuer ?? this.dcx as DcxIssuer ?? new DcxIssuer({});
}

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/server/tests/dcx-server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { DcxAgent, dcxConfig, DcxIdentityVault, FileSystem, Mnemonic } from '@dc
import { DcxIssuer } from '@dcx-protocol/issuer';
import { Web5 } from '@web5/api';
import { expect } from 'chai';
import { DcxIssuerServer } from '../src/index.js';
import { DcxServer } from '../src/index.js';

process.env.NODE_ENV = 'test';

Expand All @@ -18,7 +18,7 @@ const issuer = new DcxIssuer({
}
}
});
const server: DcxIssuerServer = new DcxIssuerServer({ issuer });
const server: DcxServer = new DcxServer({ issuer });

describe('DcxServer class', () => {
afterEach(async () => {
Expand Down Expand Up @@ -54,16 +54,16 @@ describe('DcxServer class', () => {
});

it('should include property serverOptions as an object containing 6 entries', () => {
const serverOptions = server.issuer.options;
const serverOptions = server.dcx.options;
expect(serverOptions).to.not.be.null.and.not.be.undefined;
expect(Object.entries(serverOptions)).to.have.lengthOf.gte(5);
});
});

describe('.initialize()', () => {
it('should initialize the server', async () => {
await server.issuer.initializeWeb5();
expect(server.issuer.isInitialized).equals(true);
await server.dcx.initializeWeb5();
expect(server.dcx.isInitialized).equals(true);
});

it('should initialize the DcxManager', () => {
Expand All @@ -80,8 +80,8 @@ describe('DcxServer class', () => {

describe('.setupDwn()', () => {
it('should setup the remote DWN', async () => {
await server.issuer.setupDwn();
expect(server.issuer.isSetup).equals(true);
await server.dcx.setupDwn();
expect(server.dcx.isSetup).equals(true);
});
});
});

0 comments on commit f5f6a3b

Please sign in to comment.