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

Endorser protocol for Issuer Agency #11

Merged
merged 16 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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: 4 additions & 0 deletions controller/src/models/endorser.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export interface EndorserServiceModel {
tran_id: string;
}

export interface EndorserMetadataServiceRequest {
connection_id: string;
did: string;
Expand Down
5 changes: 3 additions & 2 deletions controller/src/models/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export enum CredServiceAction {

export enum EndorserServiceAction {
Set_Metadata = 'Metadata',
Create_Request = 'Request',
}

export enum LedgerServiceAction {
Expand Down Expand Up @@ -50,11 +51,11 @@ export enum ServiceType {
CredDef = 'Credential Definition',
Cred = 'Credential',
Endorser = 'Endorser',
Schema = 'Schema',
IssuerRegistration = 'IssuerRegistration',
Ledger = 'Ledger',
Multitenancy = 'Multitenancy',
Schema = 'Schema',
Wallet = 'Wallet',
IssuerRegistration = 'IssuerRegistration',
}

export enum WebhookTopic {
Expand Down
73 changes: 42 additions & 31 deletions controller/src/services/aries-agent/aries-agent.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,12 @@ export class AriesAgent {
//eslint-disable-next-line @typescript-eslint/no-unused-vars
async create(data: AriesAgentData, params?: Params): Promise<any> {
switch (data.service) {
case ServiceType.Multitenancy:
if (data.action === MultitenancyServiceAction.Create) {
return this.newSubWallet(data.data as MultitenancyServiceRequest);
}
case ServiceType.Wallet:
if (data.action === WalletServiceAction.Create) {
return this.newDID(data.token);
} else if (data.action === WalletServiceAction.Fetch) {
return this.getPublicDID(data.token);
} else if (data.action === WalletServiceAction.Publish) {
return this.publishDID(data.data.did, data.token);
}
case ServiceType.Connection:
if (data.action === ConnectionServiceAction.CreateVCR) {
return this.newRegistryConnection(data.data.alias, data.token);
} else if (data.action === ConnectionServiceAction.CreateEndorser) {
return this.newEndorserConnection(data.data.alias, data.token);
}
case ServiceType.Ledger:
if (data.action === LedgerServiceAction.TAA_Fetch) {
return this.fetchTAA(data.token);
} else if (data.action === LedgerServiceAction.TAA_Accept) {
return this.acceptTAA(
data.token,
data.data.mechanism,
data.data.text,
data.data.version
);
}
case ServiceType.CredDef:
if (data.action === CredDefServiceAction.Details) {
return this.getCredDefDetailsForSchema(
Expand All @@ -118,6 +95,29 @@ export class AriesAgent {
} else if (data.action === CredDefServiceAction.Create) {
return this.createCredential(data.data, data.token);
}
case ServiceType.IssuerRegistration:
if (data.action === IssuerRegistrationServiceAction.Submit) {
return this.handleIssuerRegistration(data.data, data.token);
}
case ServiceType.Endorser:
if (data.action === EndorserServiceAction.Create_Request) {
return this.createEndorserRequest(data.data);
}
case ServiceType.Ledger:
if (data.action === LedgerServiceAction.TAA_Fetch) {
return this.fetchTAA(data.token);
} else if (data.action === LedgerServiceAction.TAA_Accept) {
return this.acceptTAA(
data.token,
data.data.mechanism,
data.data.text,
data.data.version
);
}
case ServiceType.Multitenancy:
if (data.action === MultitenancyServiceAction.Create) {
return this.newSubWallet(data.data as MultitenancyServiceRequest);
}
case ServiceType.Schema:
if (data.action === SchemaServiceAction.Details) {
return this.getSchemaDetails(data.token, data.data.schema_id);
Expand All @@ -126,9 +126,13 @@ export class AriesAgent {
} else if (data.action === SchemaServiceAction.Create) {
return this.publishSchema(data.data, data.token);
}
case ServiceType.IssuerRegistration:
if (data.action === IssuerRegistrationServiceAction.Submit) {
return this.handleIssuerRegistration(data.data, data.token);
case ServiceType.Wallet:
if (data.action === WalletServiceAction.Create) {
return this.newDID(data.token);
} else if (data.action === WalletServiceAction.Fetch) {
return this.getPublicDID(data.token);
} else if (data.action === WalletServiceAction.Publish) {
return this.publishDID(data.data.did, data.token);
}
case ServiceType.Endorser:
if (data.action === EndorserServiceAction.Set_Metadata) {
Expand Down Expand Up @@ -533,8 +537,7 @@ export class AriesAgent {
credential,
this.acaPyUtils.getRequestConfig(token)
);
const credentialResponse = response.data;
return credentialResponse;
return response.data;
} catch (e) {
const error = e as AxiosError;
throw new AriesAgentError(
Expand All @@ -558,9 +561,9 @@ export class AriesAgent {
credential,
this.acaPyUtils.getRequestConfig(token)
);
const credentialResponse = response.data;
return credentialResponse;
} catch (error) {
return response.data;
} catch (e) {
const error = e as AxiosError;
throw new AriesAgentError(
error.response?.statusText || error.message,
error.response?.status,
Expand Down Expand Up @@ -645,4 +648,12 @@ export class AriesAgent {
);
}
}

private async createEndorserRequest(
data: any
): Promise<any> {
// TODO:
throw new Error('Method not implemented.');
}

}
1 change: 0 additions & 1 deletion controller/src/services/credential/credential.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HookContext, Service } from '@feathersjs/feathers';
import { authenticateIssuer } from '../../utils/hooks/authentication';
import { postProcessCredentials, preProcessCredentials } from '../../utils/hooks/credential';
import { checkValidIssuerProfile } from '../../utils/hooks/issuer-profile';
Expand Down
4 changes: 2 additions & 2 deletions controller/src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import webHooks from './webhooks/webhooks.service';

export function services(app: Application): void {
app.configure(admin);
app.configure(credential);
app.configure(issuerProfile);
app.configure(issuerAuthentication);
app.configure(schema);
app.configure(taaRead);
app.configure(taaAccept);
app.configure(schema);
app.configure(credential);
}

export function internalServices(app: Application): void {
Expand Down
34 changes: 17 additions & 17 deletions controller/src/utils/hooks/credential.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { HookContext, Paginated, Service } from '@feathersjs/feathers';

export async function preProcessCredentials(context: HookContext): Promise<HookContext<any, Service<any>>> {
context.params.credentials = { pending: [], results: [] };
return context;
context.params.credentials = { pending: [], results: [] };
return context;
}

export async function postProcessCredentials(context: HookContext): Promise<HookContext<any, Service<any>>> {
const params = context.params;
params.credentials.results
.sort((a: any, b: any) => a.order - b.order)
.forEach((result: any, idx: number, self: any[]) => {
self[idx] = {
cred_ex_id: result?.credExId,
success: result.success,
error: result?.error?.message
};
});
if (params.credentials.results.length === 1) {
params.credentials.results = params.credentials.results[0];
}
context.result = params.credentials.results;
return context;
const params = context.params;
params.credentials.results
.sort((a: any, b: any) => a.order - b.order)
.forEach((result: any, idx: number, self: any[]) => {
self[idx] = {
cred_ex_id: result?.credExId,
success: result.success,
error: result?.error?.message
};
});
if (params.credentials.results.length === 1) {
params.credentials.results = params.credentials.results[0];
}
context.result = params.credentials.results;
return context;
}