Skip to content

Commit 4de4303

Browse files
fix: IndyProofFormatService, V1ProofService
Signed-off-by: NB Prasad Katkar <[email protected]>
1 parent 9d7a58a commit 4de4303

File tree

10 files changed

+497
-163
lines changed

10 files changed

+497
-163
lines changed

packages/core/src/modules/proofs/ProofService.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import type { AgentMessage } from '../../agent/AgentMessage'
2-
import type { HandlerInboundMessage } from '../../agent/Handler'
32
import type { InboundMessageContext } from '../../agent/models/InboundMessageContext'
3+
import type { CreateRequestAsResponseOptions } from './interface'
4+
import type { ProofProtocolVersion } from './models/ProofProtocolVersion'
45
import type {
5-
CreateRequestOptions,
6-
RequestProofOptions,
7-
CreateProposalOptions,
6+
CreatePresentationOptions,
87
CreateProposalAsResponseOptions,
9-
CreateRequestAsResponseOptions,
10-
} from './interface'
11-
import type { ProofProtocolVersion } from './models/ProofProtocolVersion'
12-
import type { ProofRequest, RetrievedCredentials } from './protocol/v1/models'
13-
import type { PresentationPreview } from './protocol/v1/models/PresentationPreview'
8+
CreateProposalOptions,
9+
RequestProofOptions,
10+
} from './models/ServiceOptions'
11+
import type { RetrievedCredentials } from './protocol/v1/models'
1412
import type { ProofRecord } from './repository'
1513
import type { PresentationRecordType } from './repository/PresentationExchangeRecord'
1614
import type { ProofFormatService } from './v2/formats/ProofFormatService'
17-
import type { V2ProposePresentationHandler } from './v2/handlers/V2ProposePresentationHandler'
1815

1916
import { ConsoleLogger, LogLevel } from '../../logger'
2017

@@ -72,7 +69,7 @@ export abstract class ProofService {
7269
*/
7370
abstract processProposal(messageContext: InboundMessageContext<AgentMessage>): Promise<ProofRecord>
7471

75-
abstract createRequest(options: CreateRequestOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
72+
abstract createRequest(options: RequestProofOptions): Promise<{ proofRecord: ProofRecord; message: AgentMessage }>
7673

7774
abstract createRequestAsResponse(
7875
options: CreateRequestAsResponseOptions
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { RevocationInterval } from '../../credentials/models/RevocationInterval'
2+
import type { ProofRequest, RequestedAttribute, RequestedPredicate } from '../protocol/v1/models'
3+
import type {
4+
PresentationPreview,
5+
PresentationPreviewAttribute,
6+
PresentationPreviewPredicate,
7+
} from '../protocol/v1/models/PresentationPreview'
8+
import type { ProofAttributeInfo } from '../protocol/v1/models/ProofAttributeInfo'
9+
import type { ProofPredicateInfo } from '../protocol/v1/models/ProofPredicateInfo'
10+
11+
export interface IndyProposeProofFormat {
12+
attributes?: PresentationPreviewAttribute[]
13+
predicates?: PresentationPreviewPredicate[]
14+
nonce: string
15+
name: string
16+
version: string
17+
proofPreview?: PresentationPreview
18+
}
19+
20+
export interface IndyRequestProofFormat {
21+
name: string
22+
version: string
23+
nonce: string
24+
nonRevoked?: RevocationInterval
25+
ver?: '1.0' | '2.0'
26+
requestedAttributes?: Record<string, ProofAttributeInfo> | Map<string, ProofAttributeInfo>
27+
requestedPredicates?: Record<string, ProofPredicateInfo> | Map<string, ProofPredicateInfo>
28+
proofRequest?: ProofRequest
29+
}
30+
31+
export interface IndyPresentationProofFormat {
32+
requestedAttributes?: Record<string, RequestedAttribute>
33+
requestedPredicates?: Record<string, RequestedPredicate>
34+
selfAttestedAttributes?: Record<string, string>
35+
}

packages/core/src/modules/proofs/formats/ProofFormatService.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ProofFormatSpec {
2626
}
2727

2828
export interface ProofAttachmentFormat {
29-
// format: ProofFormatSpec
29+
format: ProofFormatSpec
3030
attachment: Attachment
3131
}
3232

@@ -41,7 +41,8 @@ export interface ProcessProposalOptions {
4141
}
4242

4343
export interface CreateRequestOptions {
44-
attachId: string
44+
attachId?: string
45+
messageType: string
4546
proofRequest: ProofRequest
4647
}
4748

@@ -52,7 +53,8 @@ export interface ProcessRequestOptions {
5253
}
5354

5455
export interface CreatePresentationOptions {
55-
attachId: string
56+
attachId?: string
57+
messageType: string
5658
attachData: AttachmentData
5759
}
5860

packages/core/src/modules/proofs/formats/ProofFormats.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const INDY_ATTACH_ID = 'indy'
1111
const PRES_20_PROPOSAL = 'hlindy/[email protected]'
1212
const PRES_20_REQUEST = 'hlindy/[email protected]'
1313
const PRES_20_PROOF = 'hlindy/[email protected]'
14+
const V1_PROOF = 'v1_proof'
1415

1516
const LD_ATTACH_ID = '...' // MJR-TODO
1617
const LD_PROPOSE_FORMAT = '...' // MJR-TODO
@@ -46,6 +47,11 @@ const V2JsonLdProofFormat: ProofFormatSpec = {
4647
format: LD_REQUEST_FORMAT,
4748
}
4849

50+
const V1IndyProofFormat: ProofFormatSpec = {
51+
attachmentId: INDY_ATTACH_ID,
52+
format: V1_PROOF,
53+
}
54+
4955
export const ATTACHMENT_FORMAT: V2ProofAttachmentFormat = {
5056
PRES_20_PROPOSAL: {
5157
indy: V2IndyProposeProofFormat,
@@ -59,6 +65,10 @@ export const ATTACHMENT_FORMAT: V2ProofAttachmentFormat = {
5965
indy: V2IndyProofFormat,
6066
ldproof: V2JsonLdProofFormat,
6167
},
68+
V1_PROOF: {
69+
indy: V1IndyProofFormat,
70+
ldproof: V1IndyProofFormat,
71+
},
6272

6373
// MJR-TODO
6474
// CRED_20_REQUEST: {

packages/core/src/modules/proofs/formats/indy/IndyProofFormatService.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@ import type {
44
CreateRequestOptions,
55
ProcessProposalOptions,
66
ProofAttachmentFormat,
7+
ProofFormatSpec,
78
} from '../ProofFormatService'
89

10+
import { Attachment, AttachmentData } from '../../../../decorators/attachment/Attachment'
11+
import { JsonEncoder } from '../../../../utils/JsonEncoder'
912
import { ProofFormatService } from '../ProofFormatService'
10-
11-
import { Attachment, AttachmentData } from 'packages/core/src/decorators/attachment/Attachment'
12-
import { JsonEncoder } from 'packages/core/src/utils'
13+
import { ATTACHMENT_FORMAT } from '../ProofFormats'
1314

1415
export class IndyProofFormatService extends ProofFormatService {
1516
public createProposal(options: CreateProposalOptions): ProofAttachmentFormat {
17+
// Handle format in service
1618
throw new Error('Method not implemented.')
1719
}
1820

@@ -21,32 +23,46 @@ export class IndyProofFormatService extends ProofFormatService {
2123
}
2224

2325
public createRequest(options: CreateRequestOptions): ProofAttachmentFormat {
26+
const format: ProofFormatSpec = this.getFormatIdentifier(options.messageType)
27+
2428
const { attachId, proofRequest } = options
2529
const attachment = new Attachment({
26-
id: attachId,
30+
id: attachId ? attachId : undefined,
2731
mimeType: 'application/json',
2832
data: new AttachmentData({
2933
base64: JsonEncoder.toBase64(proofRequest),
3034
}),
3135
})
32-
return { attachment }
36+
return { format, attachment }
3337
}
3438

3539
public processRequest(options: ProcessRequestOptions): void {
3640
throw new Error('Method not implemented.')
3741
}
3842

3943
public createPresentation(options: CreatePresentationOptions): ProofAttachmentFormat {
44+
const format: ProofFormatSpec = this.getFormatIdentifier(options.messageType)
45+
4046
const { attachId, attachData } = options
4147
const attachment = new Attachment({
42-
id: attachId,
48+
id: attachId ? attachId : undefined,
4349
mimeType: 'application/json',
4450
data: attachData,
4551
})
46-
return { attachment }
52+
return { format, attachment }
4753
}
4854

4955
public processPresentation(options: ProcessPresentationOptions): void {
5056
throw new Error('Method not implemented.')
5157
}
58+
59+
/**
60+
* Get attachment format identifier for format and message combination
61+
*
62+
* @param messageType Message type for which to return the format identifier
63+
* @return V2CredentialFormatSpec - Issue credential attachment format identifier
64+
*/
65+
public getFormatIdentifier(messageType: string): ProofFormatSpec {
66+
return ATTACHMENT_FORMAT[messageType].indy
67+
}
5268
}

packages/core/src/modules/proofs/models/ServiceOptions.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { AutoAcceptProof, ProofRecord } from '..'
22
import type { ConnectionRecord } from '../../connections'
33
import type { ProofProtocolVersion } from './ProofProtocolVersion'
4-
import type { ProposeProofFormats } from './SharedOptions'
4+
import type { CreatePresentationFormats, ProposeProofFormats, RequestProofFormats } from './SharedOptions'
55

66
// ----- Create Proposal ----- //
77
export interface CreateProposalOptions {
@@ -21,10 +21,10 @@ export interface CreateProposalAsResponseOptions {
2121

2222
// ----- Request Proof ----- //
2323
export interface RequestProofOptions {
24-
connectionId: string
24+
connectionRecord: ConnectionRecord
2525
protocolVersion: ProofProtocolVersion
26-
proofFormats: V2ProposeProofFormat
27-
proofRequestOptions: CreateProofRequestOptions
26+
proofFormats: RequestProofFormats
27+
// proofRequestOptions: CreateProofRequestOptions
2828
comment?: string
2929
autoAcceptProof?: AutoAcceptProof
3030
}
@@ -37,8 +37,9 @@ export interface CreateRequestAsResponseOptions {
3737
}
3838

3939
// ----- Create Presentation ----- //
40-
export interface CreatePresentationOptions {
40+
export interface PresentationOptions {
4141
proofRecord: ProofRecord
4242
proofFormats: CreatePresentationFormats
43+
comment?: string
4344
// TODO: add other options such as comment, etc...
4445
}
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
1-
import type { IndyProposeProofFormat } from '../protocol/v1/models/ProofFormatsInterfaces'
2-
3-
/**
4-
* Moved to protocol/v1/models
5-
*/
6-
// export interface IndyProposeProofFormat {
7-
// attributes?: PresentationPreviewAttribute[]
8-
// predicates?: PresentationPreviewPredicate[]
9-
// nonce: string
10-
// name: string
11-
// version: string
12-
// proofPreview?: PresentationPreview
13-
// }
1+
import type { RequestedCredentials } from '..'
2+
import type {
3+
IndyPresentationProofFormat,
4+
IndyProposeProofFormat,
5+
IndyRequestProofFormat,
6+
} from '../formats/IndyProofFormatsServiceOptions'
147

158
export interface ProposeProofFormats {
169
// If you want to propose an indy proof without attributes or
1710
// any of the other properties you should pass an empty object
1811
indy?: IndyProposeProofFormat
1912
presentationExchange?: never // TBD
2013
}
14+
15+
export interface RequestProofFormats {
16+
// If you want to propose an indy proof without attributes or
17+
// any of the other properties you should pass an empty object
18+
indy?: IndyRequestProofFormat
19+
presentationExchange?: never // TBD
20+
}
21+
22+
export interface CreatePresentationFormats {
23+
// If you want to propose an indy proof without attributes or
24+
// any of the other properties you should pass an empty object
25+
indy?: RequestedCredentials
26+
presentationExchange?: never // TBD
27+
}

packages/core/src/modules/proofs/protocol/v1/V1LegacyProofService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { AgentMessage } from '../../../../agent/AgentMessage'
22
import type { InboundMessageContext } from '../../../../agent/models/InboundMessageContext'
33
import type { Logger } from '../../../../logger'
44
import type { ConnectionRecord } from '../../../connections'
5-
import type { PresentationPreview, PresentationPreviewAttribute } from './models/PresentationPreview'
6-
import type { AutoAcceptProof } from '../../models/ProofAutoAcceptType'
75
import type { ProofStateChangedEvent } from '../../ProofEvents'
6+
import type { AutoAcceptProof } from '../../models/ProofAutoAcceptType'
87
import type { PresentationProblemReportMessage } from './messages/PresentationProblemReportMessage'
8+
import type { PresentationPreview, PresentationPreviewAttribute } from './models/PresentationPreview'
99
import type { CredDef, IndyProof, Schema } from 'indy-sdk'
1010

1111
import { validateOrReject } from 'class-validator'
@@ -26,8 +26,8 @@ import { CredentialUtils, Credential, CredentialRepository } from '../../../cred
2626
import { IndyHolderService, IndyVerifierService } from '../../../indy'
2727
import { IndyLedgerService } from '../../../ledger/services/IndyLedgerService'
2828
import { ProofEventTypes } from '../../ProofEvents'
29-
import { ProofState } from '../../models/ProofState'
3029
import { PresentationProblemReportError, PresentationProblemReportReason } from '../../errors'
30+
import { ProofState } from '../../models/ProofState'
3131
import { ProofRepository } from '../../repository'
3232
import { ProofRecord } from '../../repository/ProofRecord'
3333

0 commit comments

Comments
 (0)