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

Feature blank fields #364

Merged
merged 4 commits into from
Apr 21, 2022
Merged
Changes from 2 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
43 changes: 36 additions & 7 deletions api/src/services/credential-exchange/credential-exchange.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import {
import { ServiceAction, ServiceType } from "../../models/enums";
import { formatCredentialOffer } from "../../utils/credential-exchange";
import { updateInviteRecord } from "../../utils/issuer-invite";
import { AriesSchema } from "../../models/schema";
import { AriesSchema, SchemaDefinition } from "../../models/schema";
import logger from "../../logger";
import { loadJSON } from "../../utils/load-config-file";


interface Data {
token?: string;
Expand All @@ -23,7 +25,7 @@ interface Data {
claims: Claim[];
}

interface ServiceOptions {}
interface ServiceOptions { }

export class CredentialExchange implements ServiceSwaggerAddon {
app: Application;
Expand All @@ -34,6 +36,16 @@ export class CredentialExchange implements ServiceSwaggerAddon {
this.app = app;
}

getSchemaAttrsByID(schema_name: string, schema_version: string): string[] {
const schemas = loadJSON("schemas.json") as SchemaDefinition[]
const filtered = schemas.filter((s) => s.schema_name === schema_name && s.schema_version === schema_version)
let schemaAttributes: string[] = []
if (filtered.length > 0 && filtered[0].attributes) {
schemaAttributes = filtered[0].attributes
}
return schemaAttributes
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would likely be better located in utils/credential-exchange.ts as it is a utility method that might be reused elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change completed

async get(id: Id, params?: Params): Promise<CredExServiceResponse> {
return await this.app.service("aries-agent").create({
service: ServiceType.CredEx,
Expand All @@ -46,11 +58,11 @@ export class CredentialExchange implements ServiceSwaggerAddon {
const comment = this.app.get("issuer").offerComment;
const attributes = data.claims.map(
(claim: any) =>
({
name: claim.name,
value: claim.value,
"mime-type": "text/plain",
} as AriesCredentialAttribute)
({
name: claim.name,
value: claim.value,
"mime-type": "text/plain",
} as AriesCredentialAttribute)
);

let schema_id = data.schema_id;
Expand All @@ -64,6 +76,23 @@ export class CredentialExchange implements ServiceSwaggerAddon {
);
}
schema_id = default_schema.schema_id || default_schema.schema.id;

//allows blank attributes to be supplied in isser-web/admin
const schemaChunks = schema_id.split(':');
const schemaVersion = schemaChunks[schemaChunks.length - 1]
const schemaName = schemaChunks[schemaChunks.length - 2]
const schemaAttributes = this.getSchemaAttrsByID(schemaName, schemaVersion)
const requestAttributes = data.claims.map((claim) => claim.name)

//take the set difference
const diff = schemaAttributes.filter(attr => !requestAttributes.includes(attr))
const diffAttrs = diff.map((attr) =>
({
name: attr,
value: "",
"mime-type": "text/plain",
} as AriesCredentialAttribute))
attributes.push(...diffAttrs)
}
const cred_def_id = this.app.get("credDefs").get(schema_id) as string;

Expand Down