Skip to content

Commit 9d7a58a

Browse files
IndyProofFormatService(Request and Presentation)
Signed-off-by: NB Prasad Katkar <[email protected]>
1 parent c2d0c45 commit 9d7a58a

File tree

6 files changed

+174
-26
lines changed

6 files changed

+174
-26
lines changed

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { ProofRecord } from '..'
2-
import type { Attachment } from '../../../decorators/attachment/Attachment'
1+
import type { ProofRecord, ProofRequest, ProposePresentationMessage } from '..'
2+
import type { Attachment, AttachmentData } from '../../../decorators/attachment/Attachment'
3+
import type { CreateProposalOptions } from '../models/ServiceOptions'
34

45
import { Expose, Type } from 'class-transformer'
56
import { IsInstance, IsString, ValidateNested } from 'class-validator'
@@ -9,7 +10,7 @@ interface ProofFormatSpecOptions {
910
format: string
1011
}
1112

12-
class ProofFormatSpec {
13+
export class ProofFormatSpec {
1314
public constructor(options: ProofFormatSpecOptions) {
1415
if (options) {
1516
this.attachmentId = options.attachmentId
@@ -24,33 +25,35 @@ class ProofFormatSpec {
2425
public format!: string
2526
}
2627

27-
interface ProofAttachmentFormat {
28-
format: ProofFormatSpec
28+
export interface ProofAttachmentFormat {
29+
// format: ProofFormatSpec
2930
attachment: Attachment
3031
}
3132

32-
interface CreateProposalOptions {
33-
record: ProofRecord
34-
}
33+
// interface CreateProposalOptions {
34+
// record: ProofRecord
35+
// }
3536

36-
interface ProcessProposalOptions {
37+
export interface ProcessProposalOptions {
3738
record: ProofRecord
3839
proposal: ProofAttachmentFormat
3940
options: never // TBD
4041
}
4142

42-
interface CreateRequestOptions {
43-
record: ProofRecord
43+
export interface CreateRequestOptions {
44+
attachId: string
45+
proofRequest: ProofRequest
4446
}
4547

46-
interface ProcessRequestOptions {
48+
export interface ProcessRequestOptions {
4749
record: ProofRecord
4850
request: ProofAttachmentFormat
4951
options: never // TBD
5052
}
5153

52-
interface CreatePresentationOptions {
53-
record: ProofRecord
54+
export interface CreatePresentationOptions {
55+
attachId: string
56+
attachData: AttachmentData
5457
}
5558

5659
interface ProcessPresentationOptions {
@@ -59,6 +62,7 @@ interface ProcessPresentationOptions {
5962
options: never // TBD
6063
}
6164

65+
6266
/**
6367
* This abstract class is the base class for any proof format
6468
* specific service.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import type { ProofFormatSpec } from './ProofFormatService'
2+
3+
type V2ProofAttachmentFormat = {
4+
[id: string]: {
5+
indy: ProofFormatSpec
6+
ldproof: ProofFormatSpec
7+
}
8+
}
9+
10+
const INDY_ATTACH_ID = 'indy'
11+
const PRES_20_PROPOSAL = 'hlindy/[email protected]'
12+
const PRES_20_REQUEST = 'hlindy/[email protected]'
13+
const PRES_20_PROOF = 'hlindy/[email protected]'
14+
15+
const LD_ATTACH_ID = '...' // MJR-TODO
16+
const LD_PROPOSE_FORMAT = '...' // MJR-TODO
17+
const LD_REQUEST_FORMAT = '...' // TODO
18+
19+
const V2IndyProposeProofFormat: ProofFormatSpec = {
20+
attachmentId: INDY_ATTACH_ID,
21+
format: PRES_20_PROPOSAL,
22+
}
23+
24+
const V2JsonLdProposeProofFormat: ProofFormatSpec = {
25+
attachmentId: LD_ATTACH_ID,
26+
format: LD_PROPOSE_FORMAT,
27+
}
28+
29+
const V2IndyRequestProofFormat: ProofFormatSpec = {
30+
attachmentId: INDY_ATTACH_ID,
31+
format: PRES_20_REQUEST,
32+
}
33+
34+
const V2JsonLdRequestProofFormat: ProofFormatSpec = {
35+
attachmentId: LD_ATTACH_ID,
36+
format: LD_REQUEST_FORMAT,
37+
}
38+
39+
const V2IndyProofFormat: ProofFormatSpec = {
40+
attachmentId: INDY_ATTACH_ID,
41+
format: PRES_20_PROOF,
42+
}
43+
44+
const V2JsonLdProofFormat: ProofFormatSpec = {
45+
attachmentId: LD_ATTACH_ID,
46+
format: LD_REQUEST_FORMAT,
47+
}
48+
49+
export const ATTACHMENT_FORMAT: V2ProofAttachmentFormat = {
50+
PRES_20_PROPOSAL: {
51+
indy: V2IndyProposeProofFormat,
52+
ldproof: V2JsonLdProposeProofFormat,
53+
},
54+
PRES_20_REQUEST: {
55+
indy: V2IndyRequestProofFormat,
56+
ldproof: V2JsonLdRequestProofFormat,
57+
},
58+
PRES_20_PROOF: {
59+
indy: V2IndyProofFormat,
60+
ldproof: V2JsonLdProofFormat,
61+
},
62+
63+
// MJR-TODO
64+
// CRED_20_REQUEST: {
65+
// V20CredFormat.Format.Indy.api: "hlindy/[email protected]",
66+
// V20CredFormat.Format.LD_PROOF.api: "aries/[email protected]",
67+
// },
68+
// CRED_20_ISSUE: {
69+
// V20CredFormat.Format.Indy.api: "hlindy/[email protected]",
70+
// V20CredFormat.Format.LD_PROOF.api: "aries/[email protected]",
71+
// },
72+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { CreateProposalOptions } from '../../models/ServiceOptions'
2+
import type {
3+
CreatePresentationOptions,
4+
CreateRequestOptions,
5+
ProcessProposalOptions,
6+
ProofAttachmentFormat,
7+
} from '../ProofFormatService'
8+
9+
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+
14+
export class IndyProofFormatService extends ProofFormatService {
15+
public createProposal(options: CreateProposalOptions): ProofAttachmentFormat {
16+
throw new Error('Method not implemented.')
17+
}
18+
19+
public processProposal(options: ProcessProposalOptions): void {
20+
throw new Error('Method not implemented.')
21+
}
22+
23+
public createRequest(options: CreateRequestOptions): ProofAttachmentFormat {
24+
const { attachId, proofRequest } = options
25+
const attachment = new Attachment({
26+
id: attachId,
27+
mimeType: 'application/json',
28+
data: new AttachmentData({
29+
base64: JsonEncoder.toBase64(proofRequest),
30+
}),
31+
})
32+
return { attachment }
33+
}
34+
35+
public processRequest(options: ProcessRequestOptions): void {
36+
throw new Error('Method not implemented.')
37+
}
38+
39+
public createPresentation(options: CreatePresentationOptions): ProofAttachmentFormat {
40+
const { attachId, attachData } = options
41+
const attachment = new Attachment({
42+
id: attachId,
43+
mimeType: 'application/json',
44+
data: attachData,
45+
})
46+
return { attachment }
47+
}
48+
49+
public processPresentation(options: ProcessPresentationOptions): void {
50+
throw new Error('Method not implemented.')
51+
}
52+
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
export interface IndyProposeProofFormat {
2-
attributes?: PresentationPreviewAttribute[]
3-
predicates?: PresentationPreviewPredicate[]
4-
nonce: string
5-
name: string
6-
version: string
7-
proofPreview?: PresentationPreview
8-
}
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+
// }
914

1015
export interface ProposeProofFormats {
1116
// If you want to propose an indy proof without attributes or
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {
2+
PresentationPreview,
3+
PresentationPreviewAttribute,
4+
PresentationPreviewPredicate,
5+
} from './PresentationPreview'
6+
7+
export interface IndyProposeProofFormat {
8+
attributes?: PresentationPreviewAttribute[]
9+
predicates?: PresentationPreviewPredicate[]
10+
nonce: string
11+
name: string
12+
version: string
13+
proofPreview?: PresentationPreview
14+
}

packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import type { V2ProofFormatSpec } from '../formats/V2ProofFormat'
33
import { Expose, Type } from 'class-transformer'
44
import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
55

6-
import { AgentMessage } from '../../../../agent/AgentMessage'
7-
import { Attachment } from '../../../../decorators/attachment/Attachment'
6+
import { AgentMessage } from '../../../../../agent/AgentMessage'
7+
import { Attachment } from '../../../../../decorators/attachment/Attachment'
8+
import { uuid } from '../../../../../utils/uuid'
89
import { PresentationPreview } from '../../v1/models/PresentationPreview'
910
import { PRES_20_PROPOSAL } from '../formats/MessageTypes'
1011

1112
export interface V2ProposePresentationMessageOptions {
12-
id: string
13+
id?: string
1314
formats: V2ProofFormatSpec
1415
filtersAttach: Attachment[]
1516
comment?: string
@@ -20,7 +21,7 @@ export class V2ProposalPresentationMessage extends AgentMessage {
2021
public constructor(options: V2ProposePresentationMessageOptions) {
2122
super()
2223
if (options) {
23-
this.id = options.id ?? this.generateId()
24+
this.id = options.id ?? uuid()
2425
this.comment = options.comment
2526
this.presentationProposal = options.presentationProposal
2627
this.formats = options.formats

0 commit comments

Comments
 (0)