Skip to content

Commit

Permalink
applicant pex changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnonni committed Sep 5, 2024
1 parent 417e542 commit 2d6fea7
Show file tree
Hide file tree
Showing 21 changed files with 405 additions and 473 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
CreateCredentialApplicationParams,
CredentialApplication,
DcxAgentRecovery,
DcxApplicantError,
DcxDwnError,
DcxError,
DcxManager,
DcxManagerStatus,
DcxValidated,
DwnError,
DwnUtils,
Format,
GetManifestsResponse,
Logger,
manifestSchema,
Expand All @@ -24,7 +24,6 @@ import {
RecordsReadParams,
RecordsReadResponse,
TrustedIssuer,
ValidateApplicationParams,
ValidateVerifiablePresentationResponse
} from '@dcx-protocol/common';
import { Web5PlatformAgent } from '@web5/agent';
Expand All @@ -34,10 +33,27 @@ import {
Record,
Web5
} from '@web5/api';
import { PresentationExchange, VerifiablePresentation } from '@web5/credentials';
import { ApplicantConfig, applicantConfig } from './dcx-applicant-config.js';
import { dcxApplicant } from './index.js';

import { PresentationDefinitionV2, PresentationExchange, VerifiablePresentation } from '@web5/credentials';
import { ApplicantConfig, applicantConfig } from './config.js';
import { applicant } from './index.js';
export type ApplicantProcessRecordParams = { pex: PresentationExchangeParams, recipient: string }
export type DcxValidated = {
tag: string;
status: string;
message: string
};
export type ValidateApplicationParams = {
presentation: any;
presentationDefinition: PresentationDefinitionV2;
};
export type CreateApplicationParams = {
id?: string;
spec_version?: string;
applicant?: string;
manifest_id: string;
format?: Format;
presentation_submission: PresentationSubmission;
};
/**
* DcxApplicant is the core class for the applicant side of the DCX protocol.
* It handles the credential issuance, verification, selection, as well as
Expand Down Expand Up @@ -77,7 +93,7 @@ export class DcxApplicant implements DcxManager {
const { status: query, protocols = [] } = await this.web5.dwn.protocols.query({
message : {
filter : {
protocol : dcxApplicant.protocol,
protocol : applicant.protocol,
},
},
});
Expand All @@ -98,7 +114,7 @@ export class DcxApplicant implements DcxManager {
*/
public async configureProtocols(): Promise<ProtocolsConfigureResponse> {
const { status: configure, protocol } = await this.web5.dwn.protocols.configure({
message : { definition: dcxApplicant },
message : { definition: applicant },
});

if (DwnUtils.isFailure(configure.code) || !protocol) {
Expand Down Expand Up @@ -193,7 +209,7 @@ export class DcxApplicant implements DcxManager {
filter : {
protocolPath,
schema,
protocol : dcxApplicant.protocol,
protocol : applicant.protocol,
dataFormat : 'application/json',
},
...options
Expand All @@ -217,7 +233,7 @@ export class DcxApplicant implements DcxManager {
from,
message : {
filter : {
protocol : dcxApplicant.protocol,
protocol : applicant.protocol,
protocolPath : 'manifest',
schema : manifestSchema.$id,
dataFormat : 'application/json',
Expand Down Expand Up @@ -251,25 +267,27 @@ export class DcxApplicant implements DcxManager {
return { vp };
}

public async createCredentialApplication(
{ presentationSubmission, manifestId }: CreateCredentialApplicationParams
): Promise<CredentialApplication> {
const app = {
id : crypto.randomUUID(),
spec_version : 'https://identity.foundation/credential-manifest/#versioning',
applicant : this.did,
manifest_id : manifestId,
format : { jwt_vc: { alg: ['EdDSA'] }},
presentation_submission : presentationSubmission,
};
return new CredentialApplication(
app.id,
app.spec_version,
app.applicant,
app.manifest_id,
app.format,
app.presentation_submission
);
public createApplication(
{ id, spec_version, applicant, manifest_id, format, presentation_submission }: CreateApplicationParams
): CredentialApplication {
if(!manifest_id) {
throw new DcxApplicantError('Manifest ID is required to create a credential application');
}
if(!presentation_submission) {
throw new DcxApplicantError('Presentation Submission is required to create a credential application');
}
id ??= crypto.randomUUID();
spec_version ??= 'https://identity.foundation/credential-manifest/#versioning';
applicant ??= this.did;
format ??= { jwt_vc: { alg: ['EdDSA'] }};
return new CredentialApplication({
id,
spec_version,
applicant,
manifest_id,
format,
presentation_submission,
});
}

public validatePresentationSubmission(presentationSubmission: PresentationSubmission): DcxValidated {
Expand Down Expand Up @@ -309,7 +327,7 @@ export class DcxApplicant implements DcxManager {
schema,
protocolPath,
dataFormat : 'application/json',
protocol : dcxApplicant.protocol,
protocol : applicant.protocol,
},
});

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/applicant/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './dcx-applicant-config.js';
export * from './dcx-applicant-protocol.js';
export * from './dcx-applicant.js';
export * from './applicant.js';
export * from './config.js';
export * from './protocol.js';
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { responseSchema, invoiceSchema, manifestSchema, applicationSchema } from '@dcx-protocol/common';

export const dcxApplicant = {
export const applicant = {
// applicant protocol is a subset of exchange protocol
// used on client side to interact with applicant & issuer dwn
protocol : 'https://decentralized.cx/protocol/credential-exchange',
protocol : 'https://decentralized.cx/protocol',
published : true,
types : {
application : {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/dcx-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
} from './index.js';

export type DcxManagerStatus = {
setup : boolean;
initialized : boolean;
setup : boolean;
initialized : boolean;
}

export type InitializeParams = {
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ export { schema as invoiceSchema } from './schemas/invoice.js';
export { schema as manifestSchema } from './schemas/manifest.js';

export type * from './types/did.js';
export type * from './types/dwn.js';
export type * from './types/handlers.js';
export type * from './types/dcx.js';
export type * from './types/server.js';
export type * from './types/web5.js';

export * from './utils/cipher.js';
export * from './utils/dcx.js';
export * from './utils/dwn.js';
export * from './utils/error.js';
export * from './utils/file-system.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/manifests/handshake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const DcxHandshakeManifest = {
}
],
format : {
jwt_vc : {
jwt : {
alg : [
'EdDSA'
]
Expand Down
12 changes: 4 additions & 8 deletions packages/common/src/schemas/application.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
export type ApplicationSchema = typeof schema;

export const schema = {
$id : 'https://decentralized.cx/protocol/credential-exchange/schemas/application',
$id : 'https://decentralized.cx/protocol/schemas/application',
$schema : 'http://json-schema.org/draft-07/schema#',
title : 'Credential Application',
type : 'object',
properties : {
'@context' : {
type : 'array',
items : { type: 'string'},
items : { type: 'string' },
description : 'The @context of the application',
},
type : {
type : 'array',
items : { type: 'string'},
items : { type: 'string' },
description : 'The type property of the application',
},
credential_application : {
Expand All @@ -33,11 +33,7 @@ export const schema = {
type : 'string',
description : 'The id of a valid Credential Manifest'
},
format : {
jwt_vc : {
alg : ['EdDSA']
}
},
format : { jwt_vc: { alg: ['EdDSA'] } },
presentation_submission : {
type : 'object',
properties : {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/schemas/invoice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type InvoiceSchema = typeof schema;

export const schema = {
$id : 'https://decentralized.cx/protocol/credential-exchange/schemas/invoice',
$id : 'https://decentralized.cx/protocol/schemas/invoice',
$schema : 'http://json-schema.org/draft-07/schema#',
type : 'object',
title : 'Invoice Record Schema',
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/schemas/manifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type ManifestSchema = typeof schema;

export const schema = {
$id : 'https://decentralized.cx/protocol/credential-exchange/schemas/manifest',
$id : 'https://decentralized.cx/protocol/schemas/manifest',
$schema : 'http://json-schema.org/draft-07/schema',
title : 'Credential Manifest Record Schema',
type : 'object',
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/schemas/response.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export type ResponseSchema = typeof schema;

export const schema = {
$id : 'https://decentralized.cx/protocol/credential-exchange/schemas/response',
$id : 'https://decentralized.cx/protocol/schemas/response',
$schema : 'http://json-schema.org/draft-07/schema#',
title : 'Credential Response',
type : 'object',
Expand Down
Loading

0 comments on commit 2d6fea7

Please sign in to comment.