From 4582ca1749703c4cf7e0f6b277d454b25d42a2b8 Mon Sep 17 00:00:00 2001 From: Mike Richardson Date: Tue, 31 May 2022 12:22:35 +0300 Subject: [PATCH 1/4] remove protocol version from service offer interface Signed-off-by: Mike Richardson --- .../src/modules/credentials/CredentialServiceOptions.ts | 8 ++++++-- .../core/src/modules/credentials/CredentialsModule.ts | 4 ++-- .../__tests__/V1CredentialServiceProposeOffer.test.ts | 2 -- .../__tests__/V2CredentialServiceOffer.test.ts | 3 +-- .../formats/indy/IndyCredentialFormatService.ts | 2 +- .../credentials/protocol/v1/V1CredentialService.ts | 2 -- .../protocol/v1/handlers/V1OfferCredentialHandler.ts | 4 ++-- .../credentials/protocol/v2/CredentialMessageBuilder.ts | 6 ++++-- .../credentials/protocol/v2/V2CredentialService.ts | 6 ++---- .../protocol/v2/handlers/V2OfferCredentialHandler.ts | 4 ++-- packages/core/src/utils/__tests__/did.test.ts | 8 ++++---- packages/core/src/utils/did.ts | 2 +- 12 files changed, 25 insertions(+), 26 deletions(-) diff --git a/packages/core/src/modules/credentials/CredentialServiceOptions.ts b/packages/core/src/modules/credentials/CredentialServiceOptions.ts index 0013a43f77..500667cfb8 100644 --- a/packages/core/src/modules/credentials/CredentialServiceOptions.ts +++ b/packages/core/src/modules/credentials/CredentialServiceOptions.ts @@ -9,9 +9,9 @@ import type { AcceptRequestOptions, NegotiateOfferOptions, NegotiateProposalOptions, - OfferCredentialOptions, RequestCredentialOptions, } from './CredentialsModuleOptions' +import type { FormatServiceAcceptProposeCredentialFormats } from './formats/models/CredentialFormatServiceOptions' import type { CredentialPreviewAttribute } from './models/CredentialPreviewAttribute' import type { V1CredentialPreview } from './protocol/v1/V1CredentialPreview' import type { ProposeCredentialMessageOptions } from './protocol/v1/messages' @@ -46,9 +46,13 @@ export interface ServiceAcceptOfferOptions extends AcceptOfferOptions { } } -export interface ServiceOfferCredentialOptions extends OfferCredentialOptions { +export interface ServiceOfferCredentialOptions { + autoAcceptCredential?: AutoAcceptCredential + comment?: string + credentialRecordId?: string connection?: ConnectionRecord attachId?: string + credentialFormats: FormatServiceAcceptProposeCredentialFormats } export interface ServiceAcceptProposalOptions extends AcceptProposalOptions { diff --git a/packages/core/src/modules/credentials/CredentialsModule.ts b/packages/core/src/modules/credentials/CredentialsModule.ts index b582f74e83..8b991e9860 100644 --- a/packages/core/src/modules/credentials/CredentialsModule.ts +++ b/packages/core/src/modules/credentials/CredentialsModule.ts @@ -23,7 +23,7 @@ import { ServiceDecorator } from '../../decorators/service/ServiceDecorator' import { AriesFrameworkError } from '../../error' import { DidCommMessageRole } from '../../storage' import { DidCommMessageRepository } from '../../storage/didcomm/DidCommMessageRepository' -import { getIndyDidFromVerficationMethod } from '../../utils/did' +import { getIndyDidFromVerificationMethod } from '../../utils/did' import { ConnectionService } from '../connections/services' import { DidResolverService, findVerificationMethodByKeyType } from '../dids' import { MediationRecipientService } from '../routing' @@ -252,7 +252,7 @@ export class CredentialsModule implements CredentialsModule { 'Invalid DidDocument: Missing verification method with type Ed25519VerificationKey2018 to use as indy holder did' ) } - const indyDid = getIndyDidFromVerficationMethod(verificationMethod) + const indyDid = getIndyDidFromVerificationMethod(verificationMethod) const requestOptions: RequestCredentialOptions = { comment: options.comment, diff --git a/packages/core/src/modules/credentials/__tests__/V1CredentialServiceProposeOffer.test.ts b/packages/core/src/modules/credentials/__tests__/V1CredentialServiceProposeOffer.test.ts index 318ee36376..a17812db7c 100644 --- a/packages/core/src/modules/credentials/__tests__/V1CredentialServiceProposeOffer.test.ts +++ b/packages/core/src/modules/credentials/__tests__/V1CredentialServiceProposeOffer.test.ts @@ -232,14 +232,12 @@ describe('CredentialService', () => { offerOptions = { comment: 'some comment', connection, - connectionId: connection.id, credentialFormats: { indy: { attributes: credentialPreview.attributes, credentialDefinitionId: 'Th7MpTaRZVRYnPiabds81Y:3:CL:17:TAG', }, }, - protocolVersion: CredentialProtocolVersion.V1, } }) diff --git a/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts b/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts index 701bab12f1..66ed0ec87c 100644 --- a/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts +++ b/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts @@ -136,14 +136,13 @@ describe('CredentialService', () => { beforeEach(async () => { offerOptions = { comment: 'some comment', - connectionId: connection.id, + connection, credentialFormats: { indy: { attributes: credentialPreview.attributes, credentialDefinitionId: 'Th7MpTaRZVRYnPiabds81Y:3:CL:17:TAG', }, }, - protocolVersion: CredentialProtocolVersion.V1, } }) diff --git a/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts b/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts index 3c2ca1abf4..4f174269b5 100644 --- a/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts +++ b/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts @@ -315,7 +315,7 @@ export class IndyCredentialFormatService extends CredentialFormatService { * @returns The created credential offer */ private async createCredentialOffer( - proposal: ServiceOfferOptions | NegotiateProposalOptions | OfferCredentialOptions + proposal: NegotiateProposalOptions | ServiceOfferCredentialOptions ): Promise { if (!proposal.credentialFormats?.indy?.credentialDefinitionId) { throw new AriesFrameworkError('Missing Credential Definition id') diff --git a/packages/core/src/modules/credentials/protocol/v1/V1CredentialService.ts b/packages/core/src/modules/credentials/protocol/v1/V1CredentialService.ts index 384997e41d..57a2acc02f 100644 --- a/packages/core/src/modules/credentials/protocol/v1/V1CredentialService.ts +++ b/packages/core/src/modules/credentials/protocol/v1/V1CredentialService.ts @@ -403,7 +403,6 @@ export class V1CredentialService extends CredentialService { attributes: preview.attributes, }, }, - protocolVersion: CredentialProtocolVersion.V1, } const { attachment: offersAttach } = await this.formatService.createOffer(options) @@ -679,7 +678,6 @@ export class V1CredentialService extends CredentialService { attributes: credentialPreview.attributes, }, }, - protocolVersion: CredentialProtocolVersion.V1, } const { attachment: offersAttach } = await this.formatService.createOffer(options) diff --git a/packages/core/src/modules/credentials/protocol/v1/handlers/V1OfferCredentialHandler.ts b/packages/core/src/modules/credentials/protocol/v1/handlers/V1OfferCredentialHandler.ts index 1790e078fb..33d13929f4 100644 --- a/packages/core/src/modules/credentials/protocol/v1/handlers/V1OfferCredentialHandler.ts +++ b/packages/core/src/modules/credentials/protocol/v1/handlers/V1OfferCredentialHandler.ts @@ -10,7 +10,7 @@ import { createOutboundMessage, createOutboundServiceMessage } from '../../../.. import { ServiceDecorator } from '../../../../../decorators/service/ServiceDecorator' import { AriesFrameworkError } from '../../../../../error/AriesFrameworkError' import { DidCommMessageRole } from '../../../../../storage' -import { getIndyDidFromVerficationMethod } from '../../../../../utils/did' +import { getIndyDidFromVerificationMethod } from '../../../../../utils/did' import { findVerificationMethodByKeyType } from '../../../../dids' import { V1OfferCredentialMessage, V1ProposeCredentialMessage } from '../messages' @@ -82,7 +82,7 @@ export class V1OfferCredentialHandler implements Handler { 'Invalid DidDocument: Missing verification method with type Ed25519VerificationKey2018 to use as indy holder did' ) } - const indyDid = getIndyDidFromVerficationMethod(verificationMethod) + const indyDid = getIndyDidFromVerificationMethod(verificationMethod) const { message, credentialRecord } = await this.credentialService.createRequest(record, { holderDid: indyDid, diff --git a/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts b/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts index 35210c394d..4bcea8e0f8 100644 --- a/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts +++ b/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts @@ -214,7 +214,7 @@ export class CredentialMessageBuilder { ): Promise<{ credentialRecord: CredentialExchangeRecord; message: V2OfferCredentialMessage }> { if (formatServices.length === 0) throw new AriesFrameworkError('no format services provided to createOffer') - const { autoAcceptCredential, comment, connectionId } = options + const { autoAcceptCredential, comment, connection } = options const formats: CredentialFormatSpec[] = [] const offerAttachments: Attachment[] = [] @@ -243,8 +243,10 @@ export class CredentialMessageBuilder { // Construct v2 offer message const message = new V2OfferCredentialMessage(messageProps) + const id = connection ? connection.id : undefined + const recordProps: CredentialExchangeRecordProps = { - connectionId, + connectionId: id, threadId: message.threadId, autoAcceptCredential, state: CredentialState.OfferSent, diff --git a/packages/core/src/modules/credentials/protocol/v2/V2CredentialService.ts b/packages/core/src/modules/credentials/protocol/v2/V2CredentialService.ts index 39f37f3e67..12829a63f6 100644 --- a/packages/core/src/modules/credentials/protocol/v2/V2CredentialService.ts +++ b/packages/core/src/modules/credentials/protocol/v2/V2CredentialService.ts @@ -223,7 +223,6 @@ export class V2CredentialService extends CredentialService { const options: ServiceOfferCredentialOptions = { credentialFormats: proposal.credentialFormats, comment: proposal.comment, - protocolVersion: credentialRecord.protocolVersion, } const message = await this.createOfferAsResponse(credentialRecord, options) @@ -341,7 +340,7 @@ export class V2CredentialService extends CredentialService { public async createOffer( options: ServiceOfferCredentialOptions ): Promise> { - const connection = options.connectionId ? await this.connectionService.getById(options.connectionId) : undefined + const connection = options.connection connection?.assertReady() const formats = this.getFormats(options.credentialFormats) @@ -355,7 +354,7 @@ export class V2CredentialService extends CredentialService { formats, options ) - credentialRecord.connectionId = options.connectionId + credentialRecord.connectionId = connection?.id await this.credentialRepository.save(credentialRecord) await this.emitEvent(credentialRecord) @@ -391,7 +390,6 @@ export class V2CredentialService extends CredentialService { options = { credentialFormats: acceptProposalOptions.credentialFormats, - protocolVersion: CredentialProtocolVersion.V2, comment: acceptProposalOptions.comment, } } else { diff --git a/packages/core/src/modules/credentials/protocol/v2/handlers/V2OfferCredentialHandler.ts b/packages/core/src/modules/credentials/protocol/v2/handlers/V2OfferCredentialHandler.ts index ef09979853..e4c5b05c79 100644 --- a/packages/core/src/modules/credentials/protocol/v2/handlers/V2OfferCredentialHandler.ts +++ b/packages/core/src/modules/credentials/protocol/v2/handlers/V2OfferCredentialHandler.ts @@ -11,7 +11,7 @@ import { createOutboundMessage, createOutboundServiceMessage } from '../../../.. import { ServiceDecorator } from '../../../../../decorators/service/ServiceDecorator' import { AriesFrameworkError } from '../../../../../error/AriesFrameworkError' import { DidCommMessageRole } from '../../../../../storage' -import { getIndyDidFromVerficationMethod } from '../../../../../utils/did' +import { getIndyDidFromVerificationMethod } from '../../../../../utils/did' import { findVerificationMethodByKeyType } from '../../../../dids' import { V2OfferCredentialMessage } from '../messages/V2OfferCredentialMessage' import { V2ProposeCredentialMessage } from '../messages/V2ProposeCredentialMessage' @@ -88,7 +88,7 @@ export class V2OfferCredentialHandler implements Handler { 'Invalid DidDocument: Missing verification method with type Ed25519VerificationKey2018 to use as indy holder did' ) } - const indyDid = getIndyDidFromVerficationMethod(verificationMethod) + const indyDid = getIndyDidFromVerificationMethod(verificationMethod) const { message, credentialRecord } = await this.credentialService.createRequest(record, { holderDid: indyDid, }) diff --git a/packages/core/src/utils/__tests__/did.test.ts b/packages/core/src/utils/__tests__/did.test.ts index e455d2cd44..3d7aa07792 100644 --- a/packages/core/src/utils/__tests__/did.test.ts +++ b/packages/core/src/utils/__tests__/did.test.ts @@ -1,5 +1,5 @@ import { - getIndyDidFromVerficationMethod, + getIndyDidFromVerificationMethod, isAbbreviatedVerkey, isDid, isDidIdentifier, @@ -176,12 +176,12 @@ describe('Utils | Did', () => { }) }) - describe('getIndyDidFromVerficationMethod()', () => { - expect(getIndyDidFromVerficationMethod(verificationMethod)).toBe(indyDid) + describe('getIndyDidFromVerificationMethod()', () => { + expect(getIndyDidFromVerificationMethod(verificationMethod)).toBe(indyDid) test.each(invalidVerificationMethod)('throw error when invalid public key in verification method', (method) => { expect(() => { - getIndyDidFromVerficationMethod(method) + getIndyDidFromVerificationMethod(method) }).toThrow() }) }) diff --git a/packages/core/src/utils/did.ts b/packages/core/src/utils/did.ts index 55cc9b8ca9..74f346560d 100644 --- a/packages/core/src/utils/did.ts +++ b/packages/core/src/utils/did.ts @@ -153,7 +153,7 @@ export function isDidIdentifier(identifier: string): boolean { * @param verificationMethod * @returns indy did */ -export function getIndyDidFromVerficationMethod(verificationMethod: VerificationMethod): string { +export function getIndyDidFromVerificationMethod(verificationMethod: VerificationMethod): string { if (!verificationMethod?.publicKeyBase58) { throw new Error(`Unable to get publicKeyBase58 from verification method`) } From f9ae3476249cbb8de93bed5474a17b18434b4931 Mon Sep 17 00:00:00 2001 From: Mike Richardson Date: Tue, 31 May 2022 12:23:29 +0300 Subject: [PATCH 2/4] remove protocol version from service offer interface Signed-off-by: Mike Richardson --- .../credentials/__tests__/V2CredentialServiceOffer.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts b/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts index 66ed0ec87c..2287c44ad1 100644 --- a/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts +++ b/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts @@ -148,6 +148,8 @@ describe('CredentialService', () => { test(`creates credential record in ${CredentialState.OfferSent} state with offer, thread ID`, async () => { const repositorySaveSpy = jest.spyOn(credentialRepository, 'save') + + // when await credentialService.createOffer(offerOptions) // then From 87921f4025a54c0108180671cc41593dc9aa3431 Mon Sep 17 00:00:00 2001 From: Mike Richardson Date: Tue, 31 May 2022 12:26:30 +0300 Subject: [PATCH 3/4] remove protocol version from service offer interface Signed-off-by: Mike Richardson --- .../credentials/__tests__/V2CredentialServiceOffer.test.ts | 1 - .../credentials/formats/indy/IndyCredentialFormatService.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts b/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts index 2287c44ad1..dcf0d34369 100644 --- a/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts +++ b/packages/core/src/modules/credentials/__tests__/V2CredentialServiceOffer.test.ts @@ -20,7 +20,6 @@ import { IndyIssuerService } from '../../indy/services/IndyIssuerService' import { IndyLedgerService } from '../../ledger/services' import { MediationRecipientService } from '../../routing/services/MediationRecipientService' import { CredentialEventTypes } from '../CredentialEvents' -import { CredentialProtocolVersion } from '../CredentialProtocolVersion' import { CredentialState } from '../CredentialState' import { IndyCredentialFormatService } from '../formats/indy/IndyCredentialFormatService' import { V1CredentialPreview } from '../protocol/v1/V1CredentialPreview' diff --git a/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts b/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts index 4f174269b5..9578c0091e 100644 --- a/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts +++ b/packages/core/src/modules/credentials/formats/indy/IndyCredentialFormatService.ts @@ -2,13 +2,11 @@ import type { Attachment } from '../../../../decorators/attachment/Attachment' import type { Logger } from '../../../../logger' import type { NegotiateProposalOptions, - OfferCredentialOptions, ProposeCredentialOptions, RequestCredentialOptions, } from '../../CredentialsModuleOptions' import type { ServiceAcceptCredentialOptions, - ServiceAcceptOfferOptions as ServiceOfferOptions, ServiceAcceptProposalOptions, ServiceAcceptRequestOptions, ServiceOfferCredentialOptions, From 9a42548ac587a3bd673fc89528022a0c6e918950 Mon Sep 17 00:00:00 2001 From: Mike Richardson Date: Tue, 31 May 2022 15:32:05 +0300 Subject: [PATCH 4/4] PR review tweaks Signed-off-by: Mike Richardson --- .../credentials/protocol/v2/CredentialMessageBuilder.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts b/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts index 4bcea8e0f8..003316973a 100644 --- a/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts +++ b/packages/core/src/modules/credentials/protocol/v2/CredentialMessageBuilder.ts @@ -243,10 +243,8 @@ export class CredentialMessageBuilder { // Construct v2 offer message const message = new V2OfferCredentialMessage(messageProps) - const id = connection ? connection.id : undefined - const recordProps: CredentialExchangeRecordProps = { - connectionId: id, + connectionId: connection?.id, threadId: message.threadId, autoAcceptCredential, state: CredentialState.OfferSent,