Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcxserver #106

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcx-protocol/root",
"version": "0.6.0",
"version": "0.7.0",
"description": "DCX: Decentralized Credential Exchange. DWN protocol for verifiable credential exchange.",
"type": "module",
"workspaces": [
Expand All @@ -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
3 changes: 2 additions & 1 deletion packages/applicant/src/dcx-applicant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class DcxApplicant implements DcxManager {
/**
* Query records from DWN
*/
public async queryRecords({ from, protocolPath }: RecordsQueryParams): Promise<RecordsQueryResponse> {
public async queryRecords({ from, protocolPath, options }: RecordsQueryParams): Promise<RecordsQueryResponse> {
const { status, records = [], cursor } = await DcxApplicant.web5.dwn.records.query({
from,
message : {
Expand All @@ -220,6 +220,7 @@ export class DcxApplicant implements DcxManager {
schema : manifestSchema.$id,
dataFormat : 'application/json',
},
...options
},
});

Expand Down
52 changes: 41 additions & 11 deletions packages/applicant/tests/dcx-applicant.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import dotenv from 'dotenv';
dotenv.config({ path: '.env.test' });

import { dcxConfig, FileSystem, Mnemonic } from '@dcx-protocol/common';
import { Web5 } from '@web5/api';
import { Protocol, Web5 } from '@web5/api';
import { Web5UserAgent } from '@web5/user-agent';
import { expect } from 'chai';
import { DcxApplicant } from '../src/index.js';

process.env.NODE_ENV = 'test';

const dcxApplicant = new DcxApplicant({
const applicant = new DcxApplicant({
config : {
...dcxConfig,
dwnEndpoints : ['http://localhost:3000'],
Expand All @@ -28,28 +28,28 @@ describe('DcxApplicant class', () => {

describe('has default properties that', () => {
it('should include static property isSetup as a boolean equal to false', () => {
const isSetup = dcxApplicant.isSetup;
const isSetup = applicant.isSetup;
expect(isSetup).to.not.be.null.and.not.be.undefined;
expect(isSetup).equals(false);
});

it('should include property isInitialized as a boolean equal to false', () => {
const isInitialized = dcxApplicant.isInitialized;
const isInitialized = applicant.isInitialized;
expect(isInitialized).to.not.be.null.and.not.be.undefined;
expect(typeof isInitialized).equals('boolean');
expect(isInitialized).equals(false);
});

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

describe('.initializeWeb5()', () => {
it('should initialize the dcxApplicant web5 connection', async () => {
await dcxApplicant.initializeWeb5();
expect(dcxApplicant.isInitialized).equals(true);
it('should initialize the applicant web5 connection', async () => {
await applicant.initializeWeb5();
expect(applicant.isInitialized).equals(true);
});

it('should initialize the DcxApplicant', () => {
Expand All @@ -61,10 +61,40 @@ describe('DcxApplicant class', () => {
});
});

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

describe('applicant.queryProtocols()', () => {
it('should query the remote DWN for protocols', async () => {
const { protocols } = await applicant.queryProtocols();
expect(protocols).to.not.be.null.and.not.be.undefined;
expect(protocols).to.be.instanceof(Array);
});
});

describe('applicant.configureProtocols()', () => {
it('should configure the applicant protocol in the remote DWN', async () => {
const { status, protocol } = await applicant.configureProtocols();
expect(protocol).to.not.be.null.and.not.be.undefined;
expect(protocol).to.be.instanceof(Protocol);
const { code, detail } = status;
expect(status).to.not.be.null.and.not.be.undefined;
expect(typeof code).to.equal('number');
expect(code).to.equals(202);
expect(typeof detail).to.equal('string');
expect(detail).to.equals('Accepted');
});
});

describe('applicant.queryRecords()', () => {
it('should query the remote DWN for records', async () => {
const { records } = await applicant.queryRecords({ protocolPath: 'application/response' });
expect(records).to.not.be.null.and.not.be.undefined;
expect(records).to.be.instanceof(Array);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/types/pex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export type RecordsDeleteParams = {};
export type RecordsDeleteResponse = {};

// Records[] - Query
export type RecordsQueryParams = { from?: string; protocolPath?: DcxProtocolPath }
export type RecordsQueryParams = { from?: string; protocolPath?: DcxProtocolPath; options?: any };
export type RecordsQueryResponse = DwnResponseStatus & { records: DwnRecord[]; cursor?: DwnPaginationCursor };

// Records[] - Filter
Expand Down
5 changes: 5 additions & 0 deletions packages/server/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
9 changes: 7 additions & 2 deletions packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dcx-protocol/server",
"version": "0.3.1",
"version": "0.4.0",
"description": "DCX Server Implementation",
"type": "module",
"main": "./dist/cjs/index.js",
Expand Down Expand Up @@ -79,7 +79,10 @@
"@web5/dids": "^1.1.2",
"@web5/user-agent": "^0.4.1",
"chalk": "^5.3.0",
"ed25519-keygen": "^0.6.2"
"ed25519-keygen": "^0.6.2",
"next": "^14.2.6",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
"devDependencies": {
"@playwright/test": "^1.45.3",
Expand All @@ -88,6 +91,8 @@
"@types/eslint": "^9.6.0",
"@types/mocha": "^10.0.7",
"@types/node": "^20.14.11",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@types/readable-stream": "^4.0.15",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
Expand Down
Loading
Loading