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

fix: propose payload attachment in in snake_case JSON format #775

Merged
merged 7 commits into from
May 18, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import type {
} from '../../protocol'
import type { V1CredentialPreview } from '../../protocol/v1/V1CredentialPreview'
import type { CredentialExchangeRecord } from '../../repository/CredentialExchangeRecord'
import type { CredPropose } from '../models/CredPropose'
import type {
FormatServiceCredentialAttachmentFormats,
CredentialFormatSpec,
Expand All @@ -34,6 +33,7 @@ import { Lifecycle, scoped } from 'tsyringe'
import { AgentConfig } from '../../../../agent/AgentConfig'
import { EventEmitter } from '../../../../agent/EventEmitter'
import { AriesFrameworkError } from '../../../../error'
import { JsonTransformer } from '../../../../utils/JsonTransformer'
import { MessageValidator } from '../../../../utils/MessageValidator'
import { uuid } from '../../../../utils/uuid'
import { IndyHolderService, IndyIssuerService } from '../../../indy'
Expand All @@ -47,6 +47,7 @@ import { V2CredentialPreview } from '../../protocol/v2/V2CredentialPreview'
import { CredentialMetadataKeys } from '../../repository/CredentialMetadataTypes'
import { CredentialRepository } from '../../repository/CredentialRepository'
import { CredentialFormatService } from '../CredentialFormatService'
import { CredPropose } from '../models/CredPropose'

@scoped(Lifecycle.ContainerScoped)
export class IndyCredentialFormatService extends CredentialFormatService {
Expand Down Expand Up @@ -89,7 +90,12 @@ export class IndyCredentialFormatService extends CredentialFormatService {
throw new AriesFrameworkError('Missing payload in createProposal')
}

const attachment: Attachment = this.getFormatData(options.credentialFormats.indy?.payload, formats.attachId)
// Use class instance instead of interface, otherwise this causes interoperability problems
let proposal = new CredPropose(options.credentialFormats.indy?.payload)
NB-MikeRichardson marked this conversation as resolved.
Show resolved Hide resolved
proposal = JsonTransformer.toJSON(proposal)

const attachment: Attachment = this.getFormatData(proposal, formats.attachId)
NB-MikeRichardson marked this conversation as resolved.
Show resolved Hide resolved

const { previewWithAttachments } = this.getCredentialLinkedAttachments(options)

return { format: formats, attachment, preview: previewWithAttachments }
Expand All @@ -99,7 +105,9 @@ export class IndyCredentialFormatService extends CredentialFormatService {
options: ServiceAcceptProposalOptions,
credentialRecord: CredentialExchangeRecord
): Promise<void> {
const credPropose = options.proposalAttachment?.getDataAsJson<CredPropose>()
let credPropose = options.proposalAttachment?.getDataAsJson<CredPropose>()
credPropose = JsonTransformer.fromJSON(credPropose, CredPropose)

if (!credPropose) {
throw new AriesFrameworkError('Missing indy credential proposal data payload')
}
Expand Down Expand Up @@ -502,11 +510,11 @@ export class IndyCredentialFormatService extends CredentialFormatService {

private areProposalAndOfferDefinitionIdEqual(proposalAttachment?: Attachment, offerAttachment?: Attachment) {
const credOffer = offerAttachment?.getDataAsJson<CredOffer>()
const credPropose = proposalAttachment?.getDataAsJson<CredPropose>()
let credPropose = proposalAttachment?.getDataAsJson<CredPropose>()
credPropose = JsonTransformer.fromJSON(credPropose, CredPropose)

const proposalCredentialDefinitionId = credPropose?.credentialDefinitionId
const offerCredentialDefinitionId = credOffer?.cred_def_id

return proposalCredentialDefinitionId === offerCredentialDefinitionId
}

Expand Down Expand Up @@ -561,7 +569,8 @@ export class IndyCredentialFormatService extends CredentialFormatService {
proposeAttachment?: Attachment
) {
const indyCredentialRequest = requestAttachment?.getDataAsJson<CredReq>()
const indyCredentialProposal = proposeAttachment?.getDataAsJson<CredPropose>()
let indyCredentialProposal = proposeAttachment?.getDataAsJson<CredPropose>()
indyCredentialProposal = JsonTransformer.fromJSON(indyCredentialProposal, CredPropose)

const indyCredentialOffer = offerAttachment?.getDataAsJson<CredOffer>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,6 @@ export class V2CredentialService extends CredentialService {
*/
public getFormatsFromMessage(messageFormats: CredentialFormatSpec[]): CredentialFormatService[] {
const formats: CredentialFormatService[] = []

for (const msg of messageFormats) {
if (msg.format.includes('indy')) {
formats.push(this.getFormatService(CredentialFormatType.Indy))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ describe('credentials', () => {

const testAttributes = {
attributes: credentialPreview.attributes,
credentialDefinitionId: 'GMm4vMw8LLrLJjp81kRRLp:3:CL:12:tag',
payload: {
schemaIssuerDid: 'GMm4vMw8LLrLJjp81kRRLp',
schemaName: 'ahoy',
schemaVersion: '1.0',
schemaId: 'q7ATwTYbQDgiigVijUAej:2:test:1.0',
issuerDid: 'GMm4vMw8LLrLJjp81kRRLp',
credentialDefinitionId: 'GMm4vMw8LLrLJjp81kRRLp:3:CL:12:tag',
},
}
testLogger.test('Alice sends (v1) credential proposal to Faber')
Expand Down Expand Up @@ -227,18 +227,13 @@ describe('credentials', () => {
})
const testAttributes = {
attributes: credentialPreview.attributes,
schemaIssuerDid: 'GMm4vMw8LLrLJjp81kRRLp',
schemaName: 'ahoy',
schemaVersion: '1.0',
schemaId: 'q7ATwTYbQDgiigVijUAej:2:test:1.0',
issuerDid: 'GMm4vMw8LLrLJjp81kRRLp',
credentialDefinitionId: 'GMm4vMw8LLrLJjp81kRRLp:3:CL:12:tag',
payload: {
schemaIssuerDid: 'GMm4vMw8LLrLJjp81kRRLp',
schemaName: 'ahoy',
schemaVersion: '1.0',
schemaId: 'q7ATwTYbQDgiigVijUAej:2:test:1.0',
issuerDid: 'GMm4vMw8LLrLJjp81kRRLp',
credentialDefinitionId: 'GMm4vMw8LLrLJjp81kRRLp:3:CL:12:tag',
},
}
testLogger.test('Alice sends (v2) credential proposal to Faber')
Expand Down