diff --git a/packages/anoncreds/src/formats/AnonCredsProofFormat.ts b/packages/anoncreds/src/formats/AnonCredsProofFormat.ts index 2bfeb689dc..0c326943f8 100644 --- a/packages/anoncreds/src/formats/AnonCredsProofFormat.ts +++ b/packages/anoncreds/src/formats/AnonCredsProofFormat.ts @@ -42,9 +42,9 @@ export interface AnonCredsProposeProofFormat { export interface AnonCredsRequestProofFormat { name: string version: string - nonRevoked?: AnonCredsNonRevokedInterval - requestedAttributes?: Record - requestedPredicates?: Record + non_revoked?: AnonCredsNonRevokedInterval + requested_attributes?: Record + requested_predicates?: Record } /** diff --git a/packages/anoncreds/src/formats/LegacyIndyProofFormatService.ts b/packages/anoncreds/src/formats/LegacyIndyProofFormatService.ts index 7cf5b18786..b75df46b52 100644 --- a/packages/anoncreds/src/formats/LegacyIndyProofFormatService.ts +++ b/packages/anoncreds/src/formats/LegacyIndyProofFormatService.ts @@ -149,9 +149,9 @@ export class LegacyIndyProofFormatService implements ProofFormatService + requestedAttributes?: Record requestedPredicates?: Record } diff --git a/packages/anoncreds/src/models/AnonCredsRequestedAttribute.ts b/packages/anoncreds/src/models/AnonCredsRequestedAttribute.ts index 806f5f422b..7e2df55c8f 100644 --- a/packages/anoncreds/src/models/AnonCredsRequestedAttribute.ts +++ b/packages/anoncreds/src/models/AnonCredsRequestedAttribute.ts @@ -1,11 +1,20 @@ +import type { AnonCredsRestrictionOptions } from './AnonCredsRestriction' + import { Expose, Type } from 'class-transformer' import { ArrayNotEmpty, IsArray, IsInstance, IsOptional, IsString, ValidateIf, ValidateNested } from 'class-validator' import { AnonCredsRestriction, AnonCredsRestrictionTransformer } from './AnonCredsRestriction' import { AnonCredsRevocationInterval } from './AnonCredsRevocationInterval' +export interface AnonCredsRequestedAttributeOptions { + name?: string + names?: string[] + nonRevoked?: AnonCredsRevocationInterval + restrictions?: AnonCredsRestrictionOptions[] +} + export class AnonCredsRequestedAttribute { - public constructor(options: AnonCredsRequestedAttribute) { + public constructor(options: AnonCredsRequestedAttributeOptions) { if (options) { this.name = options.name this.names = options.names diff --git a/packages/anoncreds/src/models/AnonCredsRequestedPredicate.ts b/packages/anoncreds/src/models/AnonCredsRequestedPredicate.ts index 5f9f99ebc0..9df0bcd698 100644 --- a/packages/anoncreds/src/models/AnonCredsRequestedPredicate.ts +++ b/packages/anoncreds/src/models/AnonCredsRequestedPredicate.ts @@ -1,3 +1,5 @@ +import type { AnonCredsRestrictionOptions } from './AnonCredsRestriction' + import { Expose, Type } from 'class-transformer' import { IsArray, IsIn, IsInstance, IsInt, IsOptional, IsString, ValidateNested } from 'class-validator' @@ -12,7 +14,7 @@ export interface AnonCredsRequestedPredicateOptions { predicateType: AnonCredsPredicateType predicateValue: number nonRevoked?: AnonCredsRevocationInterval - restrictions?: AnonCredsRestriction[] + restrictions?: AnonCredsRestrictionOptions[] } export class AnonCredsRequestedPredicate { diff --git a/packages/anoncreds/src/models/AnonCredsRestriction.ts b/packages/anoncreds/src/models/AnonCredsRestriction.ts index def1fc70a2..c3f8ce843c 100644 --- a/packages/anoncreds/src/models/AnonCredsRestriction.ts +++ b/packages/anoncreds/src/models/AnonCredsRestriction.ts @@ -1,8 +1,21 @@ import { Exclude, Expose, Transform, TransformationType } from 'class-transformer' import { IsOptional, IsString } from 'class-validator' +export interface AnonCredsRestrictionOptions { + schemaId?: string + schemaIssuerDid?: string + schemaIssuerId?: string + schemaName?: string + schemaVersion?: string + issuerDid?: string + issuerId?: string + credentialDefinitionId?: string + attributeMarkers?: Record + attributeValues?: Record +} + export class AnonCredsRestriction { - public constructor(options: AnonCredsRestriction) { + public constructor(options: AnonCredsRestrictionOptions) { if (options) { this.schemaId = options.schemaId this.schemaIssuerDid = options.schemaIssuerDid @@ -12,8 +25,8 @@ export class AnonCredsRestriction { this.issuerDid = options.issuerDid this.issuerId = options.issuerId this.credentialDefinitionId = options.credentialDefinitionId - this.attributeMarkers = options.attributeMarkers - this.attributeValues = options.attributeValues + this.attributeMarkers = options.attributeMarkers ?? {} + this.attributeValues = options.attributeValues ?? {} } } diff --git a/packages/anoncreds/src/models/__tests__/AnonCredsRestriction.test.ts b/packages/anoncreds/src/models/__tests__/AnonCredsRestriction.test.ts index a3d02ab549..33884d09a8 100644 --- a/packages/anoncreds/src/models/__tests__/AnonCredsRestriction.test.ts +++ b/packages/anoncreds/src/models/__tests__/AnonCredsRestriction.test.ts @@ -77,4 +77,69 @@ describe('AnonCredsRestriction', () => { ], }) }) + + test('transforms properties from and to json with correct casing', () => { + const restrictions = new Wrapper({ + restrictions: [ + new AnonCredsRestriction({ + credentialDefinitionId: 'credentialDefinitionId', + issuerDid: 'issuerDid', + issuerId: 'issuerId', + schemaName: 'schemaName', + schemaVersion: 'schemaVersion', + schemaId: 'schemaId', + schemaIssuerDid: 'schemaIssuerDid', + schemaIssuerId: 'schemaIssuerId', + }), + ], + }) + + expect(JsonTransformer.toJSON(restrictions)).toMatchObject({ + restrictions: [ + { + cred_def_id: 'credentialDefinitionId', + issuer_did: 'issuerDid', + issuer_id: 'issuerId', + schema_name: 'schemaName', + schema_version: 'schemaVersion', + schema_id: 'schemaId', + schema_issuer_did: 'schemaIssuerDid', + schema_issuer_id: 'schemaIssuerId', + }, + ], + }) + + expect( + JsonTransformer.fromJSON( + { + restrictions: [ + { + cred_def_id: 'credentialDefinitionId', + issuer_did: 'issuerDid', + issuer_id: 'issuerId', + schema_name: 'schemaName', + schema_version: 'schemaVersion', + schema_id: 'schemaId', + schema_issuer_did: 'schemaIssuerDid', + schema_issuer_id: 'schemaIssuerId', + }, + ], + }, + Wrapper + ) + ).toMatchObject({ + restrictions: [ + { + credentialDefinitionId: 'credentialDefinitionId', + issuerDid: 'issuerDid', + issuerId: 'issuerId', + schemaName: 'schemaName', + schemaVersion: 'schemaVersion', + schemaId: 'schemaId', + schemaIssuerDid: 'schemaIssuerDid', + schemaIssuerId: 'schemaIssuerId', + }, + ], + }) + }) })