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: miscellaneous issue credential v2 fixes #769

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
fde70a0
Fix message validation error related to CredentialFormatSpec
NB-MikeRichardson May 12, 2022
91f33ac
Move Holder DID into options object
NB-MikeRichardson May 12, 2022
ef856d7
Tweak to processProposal to ensure message validation operates on JSO…
NB-MikeRichardson May 12, 2022
3a98889
Various small tweaks
NB-MikeRichardson May 12, 2022
9dfc359
Various (further) small tweaks
NB-MikeRichardson May 12, 2022
c1ff509
Merge branch 'main' into fix/icv2comments
NB-MikeRichardson May 13, 2022
045209d
Merge branch 'main' of https://github.com/NB-MikeRichardson/aries-fra…
NB-MikeRichardson May 13, 2022
a4dfeb0
Merge branch 'fix/icv2comments' of https://github.com/NB-MikeRichards…
NB-MikeRichardson May 13, 2022
f7094ba
Change to CredentialExchangeRecord to prevent tests failing
NB-MikeRichardson May 13, 2022
fcfbd73
merge with AFJ main
NB-MikeRichardson May 16, 2022
31e7b3c
Merge branch 'hyperledger-main3' into fix/icv2comments
NB-MikeRichardson May 16, 2022
adc0d1c
move CredentialResponseCoordinator into utils
NB-MikeRichardson May 16, 2022
61f2b1a
Change to CredentialExchangeRecord
NB-MikeRichardson May 17, 2022
1263e51
check whether indy key is present in v1 credential service
NB-MikeRichardson May 18, 2022
2ceab37
Remove protocol version from accept proposal options
NB-MikeRichardson May 18, 2022
7436770
Remove protocol version from accept proposal options
NB-MikeRichardson May 18, 2022
e223d2e
More small changes from comments
NB-MikeRichardson May 19, 2022
0e5d444
merge with main
NB-MikeRichardson May 19, 2022
14850c0
Merge branch 'hyperledger-main' into fix/icv2comments
NB-MikeRichardson May 19, 2022
17b26c6
fix broken test
NB-MikeRichardson May 19, 2022
0c987a5
Merge branch 'main' into fix/icv2comments
NB-MikeRichardson May 19, 2022
409428a
Minor fixes
NB-MikeRichardson May 19, 2022
91742ee
Minor fixes
NB-MikeRichardson May 19, 2022
9ea1dc7
Merge branch 'fix/icv2comments' of https://github.com/NB-MikeRichards…
NB-MikeRichardson May 19, 2022
c2bf770
Restore mandatory protocol version in offer cred options (temporarily)
NB-MikeRichardson May 19, 2022
973a8a4
Merge branch 'main' into fix/icv2comments
TimoGlastra May 25, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface ServiceRequestCredentialOptions extends RequestCredentialOption
attachId?: string
offerAttachment?: Attachment
requestAttachment?: Attachment
holderDid?: string
}

export interface ServiceAcceptCredentialOptions {
Expand Down
10 changes: 4 additions & 6 deletions packages/core/src/modules/credentials/CredentialsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ export class CredentialsModule implements CredentialsModule {
const requestOptions: RequestCredentialOptions = {
comment: options.comment,
autoAcceptCredential: options.autoAcceptCredential,
holderDid: connection.did,
}
const { message, credentialRecord } = await service.createRequest(record, requestOptions, connection.did)
const { message, credentialRecord } = await service.createRequest(record, requestOptions)

await this.didCommMessageRepo.saveAgentMessage({
agentMessage: message,
Expand Down Expand Up @@ -272,12 +273,9 @@ export class CredentialsModule implements CredentialsModule {
const requestOptions: RequestCredentialOptions = {
comment: options.comment,
autoAcceptCredential: options.autoAcceptCredential,
holderDid: ourService.recipientKeys[0],
}
const { message, credentialRecord } = await service.createRequest(
record,
requestOptions,
ourService.recipientKeys[0]
)
const { message, credentialRecord } = await service.createRequest(record, requestOptions)

// Set and save ~service decorator to record (to remember our verkey)
message.service = ourService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ interface ProposeCredentialOptions extends BaseOptions {
}

interface AcceptProposalOptions extends BaseOptions {
connectionId?: string
protocolVersion: CredentialProtocolVersion
credentialRecordId: string
credentialFormats: FormatServiceAcceptProposeCredentialFormats
}
Expand Down Expand Up @@ -57,6 +55,7 @@ interface NegotiateOfferOptions extends ProposeCredentialOptions {
interface RequestCredentialOptions extends BaseOptions {
connectionId?: string
credentialFormats?: FormatServiceRequestCredentialFormats
holderDid?: string
}

interface AcceptRequestOptions extends BaseOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ describe('CredentialService', () => {
// mock offer so that the request works

// when
const options: RequestCredentialOptions = {}
await credentialService.createRequest(credentialRecord, options, 'holderDid')
const options: RequestCredentialOptions = { holderDid: 'holderDid' }
await credentialService.createRequest(credentialRecord, options)

// then
expect(repositoryUpdateSpy).toHaveBeenCalledTimes(1)
Expand All @@ -310,14 +310,11 @@ describe('CredentialService', () => {
const options: RequestCredentialOptions = {
connectionId: credentialRecord.connectionId,
comment: 'credential request comment',
holderDid: 'holderDid',
}

// when
const { message: credentialRequest } = await credentialService.createRequest(
credentialRecord,
options,
'holderDid'
)
const { message: credentialRequest } = await credentialService.createRequest(credentialRecord, options)

// then
expect(credentialRequest.toJSON()).toMatchObject({
Expand Down Expand Up @@ -345,7 +342,7 @@ describe('CredentialService', () => {
await Promise.all(
invalidCredentialStates.map(async (state) => {
await expect(
credentialService.createRequest(mockCredentialRecord({ state }), {}, 'holderDid')
credentialService.createRequest(mockCredentialRecord({ state }), { holderDid: 'holderDid' })
).rejects.toThrowError(`Credential record is in invalid state ${state}. Valid states are: ${validState}.`)
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,12 @@ describe('CredentialService', () => {

const requestOptions: RequestCredentialOptions = {
credentialFormats: v2CredentialRequest,
holderDid: 'holderDid',
}

// when

await credentialService.createRequest(credentialRecord, requestOptions, 'holderDid')
await credentialService.createRequest(credentialRecord, requestOptions)

// then
expect(repositoryUpdateSpy).toHaveBeenCalledTimes(1)
Expand All @@ -314,13 +315,10 @@ describe('CredentialService', () => {
const options: RequestCredentialOptions = {
connectionId: credentialRecord.connectionId,
comment: 'credential request comment',
holderDid: 'holderDid',
}
// when
const { message: credentialRequest } = await credentialService.createRequest(
credentialRecord,
options,
'holderDid'
)
const { message: credentialRequest } = await credentialService.createRequest(credentialRecord, options)

// then
expect(credentialRequest.toJSON()).toMatchObject({
Expand Down Expand Up @@ -348,7 +346,7 @@ describe('CredentialService', () => {
await Promise.all(
invalidCredentialStates.map(async (state) => {
await expect(
credentialService.createRequest(mockCredentialRecord({ state }), {}, 'mockDid')
credentialService.createRequest(mockCredentialRecord({ state }), { holderDid: 'mockDid' })
).rejects.toThrowError(`Credential record is in invalid state ${state}. Valid states are: ${validState}.`)
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ 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,
HandlerAutoAcceptOptions,
FormatServiceOfferAttachmentFormats,
FormatServiceProposeAttachmentFormats,
Expand All @@ -34,19 +32,22 @@ import { Lifecycle, scoped } from 'tsyringe'
import { AgentConfig } from '../../../../agent/AgentConfig'
import { EventEmitter } from '../../../../agent/EventEmitter'
import { AriesFrameworkError } from '../../../../error'
import { JsonTransformer } from '../../../../utils'
import { CredentialResponseCoordinator } from '../../../../utils/CredentialResponseCoordinator'
import { MessageValidator } from '../../../../utils/MessageValidator'
import { uuid } from '../../../../utils/uuid'
import { IndyHolderService, IndyIssuerService } from '../../../indy'
import { IndyLedgerService } from '../../../ledger'
import { AutoAcceptCredential } from '../../CredentialAutoAcceptType'
import { CredentialResponseCoordinator } from '../../CredentialResponseCoordinator'
import { CredentialUtils } from '../../CredentialUtils'
import { CredentialFormatType } from '../../CredentialsModuleOptions'
import { CredentialProblemReportError, CredentialProblemReportReason } from '../../errors'
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'
import { CredentialFormatSpec } from '../models/CredentialFormatServiceOptions'

@scoped(Lifecycle.ContainerScoped)
export class IndyCredentialFormatService extends CredentialFormatService {
Expand Down Expand Up @@ -81,10 +82,11 @@ export class IndyCredentialFormatService extends CredentialFormatService {
*
*/
public createProposal(options: ProposeCredentialOptions): FormatServiceProposeAttachmentFormats {
const formats: CredentialFormatSpec = {
const formats = new CredentialFormatSpec({
attachId: this.generateId(),
format: 'hlindy/cred-filter@v2.0',
}
})

if (!options.credentialFormats.indy?.payload) {
throw new AriesFrameworkError('Missing payload in createProposal')
}
Expand All @@ -99,24 +101,25 @@ export class IndyCredentialFormatService extends CredentialFormatService {
options: ServiceAcceptProposalOptions,
credentialRecord: CredentialExchangeRecord
): Promise<void> {
const credPropose = options.proposalAttachment?.getDataAsJson<CredPropose>()
if (!credPropose) {
const credProposalJson = options.proposalAttachment?.getDataAsJson<CredPropose>()
if (!credProposalJson) {
throw new AriesFrameworkError('Missing indy credential proposal data payload')
}
await MessageValidator.validate(credPropose)
const credProposal = JsonTransformer.fromJSON(credProposalJson, CredPropose)
await MessageValidator.validate(credProposal)

if (credPropose.credentialDefinitionId) {
if (credProposal.credentialDefinitionId) {
options.credentialFormats = {
indy: {
credentialDefinitionId: credPropose?.credentialDefinitionId,
credentialDefinitionId: credProposal?.credentialDefinitionId,
attributes: [],
},
}
}

credentialRecord.metadata.set(CredentialMetadataKeys.IndyCredential, {
schemaId: credPropose.schemaId,
credentialDefinitionId: credPropose.credentialDefinitionId,
schemaId: credProposal.schemaId,
credentialDefinitionId: credProposal.credentialDefinitionId,
})
}

Expand All @@ -129,10 +132,10 @@ export class IndyCredentialFormatService extends CredentialFormatService {
*
*/
public async createOffer(options: ServiceOfferCredentialOptions): Promise<FormatServiceOfferAttachmentFormats> {
const formats: CredentialFormatSpec = {
const formats = new CredentialFormatSpec({
attachId: this.generateId(),
format: 'hlindy/cred-abstract@v2.0',
}
format: 'hlindy/cred-filter@v2.0',
})
const offer = await this.createCredentialOffer(options)

let preview: V2CredentialPreview | undefined
Expand Down Expand Up @@ -181,24 +184,29 @@ export class IndyCredentialFormatService extends CredentialFormatService {
*/
public async createRequest(
options: ServiceRequestCredentialOptions,
credentialRecord: CredentialExchangeRecord,
holderDid: string
credentialRecord: CredentialExchangeRecord
): Promise<FormatServiceCredentialAttachmentFormats> {
if (!options.offerAttachment) {
throw new AriesFrameworkError(
`Missing attachment from offer message, credential record id = ${credentialRecord.id}`
)
}

if (!options.holderDid) {
throw new AriesFrameworkError(
`Missing holder DID from offer message, credential record id = ${credentialRecord.id}`
)
}
const offer = options.offerAttachment.getDataAsJson<CredOffer>()
const credDef = await this.getCredentialDefinition(offer)

const { credReq, credReqMetadata } = await this.createIndyCredentialRequest(offer, credDef, holderDid)
const { credReq, credReqMetadata } = await this.createIndyCredentialRequest(offer, credDef, options.holderDid)
credentialRecord.metadata.set(CredentialMetadataKeys.IndyRequest, credReqMetadata)

const formats: CredentialFormatSpec = {
const formats = new CredentialFormatSpec({
attachId: this.generateId(),
format: 'hlindy/cred-req@v2.0',
}
format: 'hlindy/cred-filter@v2.0',
})

const attachmentId = options.attachId ?? formats.attachId
const requestAttach: Attachment = this.getFormatData(credReq, attachmentId)
Expand Down Expand Up @@ -358,10 +366,10 @@ export class IndyCredentialFormatService extends CredentialFormatService {
credentialValues: CredentialUtils.convertAttributesToValues(credentialAttributes),
})

const formats: CredentialFormatSpec = {
const formats = new CredentialFormatSpec({
attachId: this.generateId(),
format: 'hlindy/cred-abstract@v2.0',
}
format: 'hlindy/cred-filter@v2.0',
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor

Choose a reason for hiding this comment

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

This also doesn't seem resolved

})

const attachmentId = options.attachId ? options.attachId : formats.attachId
const issueAttachment: Attachment = this.getFormatData(credential, attachmentId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export interface IndyIssueCredentialFormat {
}

export class CredentialFormatSpec {
public constructor(options: { attachId: string; format: string }) {
if (options) {
this.attachId = options.attachId
this.format = options.format
}
}
@Expose({ name: 'attach_id' })
@IsString()
public attachId!: string
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/modules/credentials/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ export * from './CredentialState'
export * from './CredentialEvents'
export * from './CredentialAutoAcceptType'
export * from './CredentialProtocolVersion'
export * from './CredentialResponseCoordinator'
Loading