Skip to content

Commit

Permalink
Merge pull request #3 from hyperledger/feat/present-proof-v2
Browse files Browse the repository at this point in the history
Feat/present proof v2
  • Loading branch information
NB-PrasadKatkar authored Jan 28, 2022
2 parents 7e03954 + 4a201c1 commit 9d8791a
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 37 deletions.
49 changes: 47 additions & 2 deletions packages/core/src/modules/proofs/ProofService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
RequestProofOptions,
} from './models/ServiceOptions'
import type { RetrievedCredentials } from './protocol/v1/models'
import type { ProofRecord } from './repository'
import type { ProofRecord, ProofRepository } from './repository'
import type { PresentationRecordType } from './repository/PresentationExchangeRecord'

import { ConsoleLogger, LogLevel } from '../../logger'
Expand All @@ -22,7 +22,14 @@ const logger = new ConsoleLogger(LogLevel.debug)
* - stores records
* - returns records & messages
*/

export abstract class ProofService {
private proofRepository: ProofRepository

public constructor(proofRepository: ProofRepository) {
this.proofRepository = proofRepository
}

abstract getVersion(): ProofProtocolVersion

/**
Expand Down Expand Up @@ -101,7 +108,45 @@ export abstract class ProofService {
throw Error('Not Implemented')
}

public getById(proofRecordId: string): Promise<ProofRecord> {
/**
* Retrieve all proof records
*
* @returns List containing all proof records
*/
public async getAll(): Promise<ProofRecord[]> {
return this.proofRepository.getAll()
}

/**
* Retrieve a proof record by id
*
* @param proofRecordId The proof record id
* @throws {RecordNotFoundError} If no record is found
* @return The proof record
*
*/
public async getById(proofRecordId: string): Promise<ProofRecord> {
return this.proofRepository.getById(proofRecordId)
}

/**
* Retrieve a proof record by id
*
* @param proofRecordId The proof record id
* @return The proof record or null if not found
*
*/
public async findById(proofRecordId: string): Promise<ProofRecord | null> {
return this.proofRepository.findById(proofRecordId)
}

/**
* Delete a proof record by id
*
* @param proofId the proof record id
*/
public async deleteById(proofId: string) {
const proofRecord = await this.getById(proofId)
return this.proofRepository.delete(proofRecord)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { PresentationAckMessage, PresentationAckMessageOptions } from '../../../messages/PresentationAckMessage'

import { Equals } from 'class-validator'
import { PresentationAckMessageOptions } from '../..'
import { AckMessage } from '../../../common'
import { PresentationAckMessage } from '../../messages/PresentationAckMessage'

import { AckMessage } from 'packages/core/src/modules/common'

/**
* @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0015-acks/README.md#explicit-acks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService'

import { Expose, Type } from 'class-transformer'
import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'

import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'

import { AgentMessage } from '@aries-framework/core'
import { Attachment } from 'packages/core/src/decorators/attachment/Attachment'
import { uuid } from 'packages/core/src/utils/uuid'

export interface V2PresentationMessageOptions {
id?: string
goalCode?: string
comment?: string
willConfirm?: boolean
attachmentInfo: ProofAttachmentFormat[]
}

export class V2PresentationMessage extends AgentMessage {
public constructor(options: V2PresentationMessageOptions) {
super()
if (options) {
this.id = options.id ?? uuid()
this.comment = options.comment
this.goalCode = options.goalCode
this.willConfirm = options.willConfirm ?? false

for (const entry of options.attachmentInfo) {
this.addPresentationsAttachment(entry)
}
}
}

public addPresentationsAttachment(attachment: ProofAttachmentFormat) {
this.formats.push(attachment.format)
this.presentationsAttach.push(attachment.attachment)
}

@Equals(V2PresentationMessage.type)
public readonly type = V2PresentationMessage.type
public static readonly type = 'https://didcomm.org/present-proof/2.0/presentation'

@IsString()
@IsOptional()
public comment?: string

@Expose({ name: 'goal_code' })
@IsString()
@IsOptional()
public goalCode?: string

@Expose({ name: 'will_confirm' })
@IsBoolean()
public willConfirm = false

@Expose({ name: 'formats' })
@Type(() => ProofFormatSpec)
@IsArray()
@ValidateNested({ each: true })
@IsInstance(ProofFormatSpec, { each: true })
public formats!: ProofFormatSpec[]

@Expose({ name: 'presentations~attach' })
@Type(() => Attachment)
@IsArray()
@ValidateNested({ each: true })
@IsInstance(Attachment, { each: true })
public presentationsAttach!: Attachment[]
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import type { V2ProofFormatSpec } from '../formats/V2ProofFormat'
import type { ProofAttachmentFormat } from '../../../formats/models/ProofFormatServiceOptions'

import { Expose, Type } from 'class-transformer'
import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'

import { AgentMessage } from '../../../../../agent/AgentMessage'
import { Attachment } from '../../../../../decorators/attachment/Attachment'
import { uuid } from '../../../../../utils/uuid'
import { PresentationPreview } from '../../v1/models/PresentationPreview'
import { PRES_20_PROPOSAL } from '../formats/MessageTypes'
import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'

import { Attachment } from 'packages/core/src/decorators/attachment/Attachment'

export interface V2ProposePresentationMessageOptions {
id?: string
formats: V2ProofFormatSpec
formats: ProofFormatSpec
filtersAttach: Attachment[]
comment?: string
presentationProposal: PresentationPreview
goalCode?: string
willConfirm?: boolean
attachmentInfo: ProofAttachmentFormat[]
}

export class V2ProposalPresentationMessage extends AgentMessage {
Expand All @@ -23,40 +25,48 @@ export class V2ProposalPresentationMessage extends AgentMessage {
if (options) {
this.id = options.id ?? uuid()
this.comment = options.comment
this.presentationProposal = options.presentationProposal
this.formats = options.formats
this.filtersAttach = options.filtersAttach
this.goalCode = options.goalCode
this.willConfirm = options.willConfirm ?? false

for (const entry of options.attachmentInfo) {
this.addProposalsAttachment(entry)
}
}
}

public addProposalsAttachment(attachment: ProofAttachmentFormat) {
this.formats.push(attachment.format)
this.proposalsAttach.push(attachment.attachment)
}

@Equals(V2ProposalPresentationMessage.type)
public readonly type = V2ProposalPresentationMessage.type
public static readonly type = `https://didcomm.org/${PRES_20_PROPOSAL}`

@Expose({ name: 'filters~attach' })
@Type(() => Attachment)
@IsArray()
@ValidateNested({
each: true,
})
@IsInstance(Attachment, { each: true })
public filtersAttach!: Attachment[]
public static readonly type = `https://didcomm.org/present-proof/2.0/propose-presentation`

/**
* Provides some human readable information about the proposed presentation.
*/
@IsString()
@IsOptional()
public comment?: string

/**
* Represents the presentation example that prover wants to provide.
*/
@Expose({ name: 'presentation_proposal' })
@Type(() => PresentationPreview)
@ValidateNested()
@IsInstance(PresentationPreview)
public presentationProposal!: PresentationPreview
@Expose({ name: 'goal_code' })
@IsString()
@IsOptional()
public goalCode?: string

@Expose({ name: 'will_confirm' })
@IsBoolean()
public willConfirm = false

@Expose({ name: 'formats' })
@Type(() => ProofFormatSpec)
@IsArray()
@ValidateNested({ each: true })
@IsInstance(ProofFormatSpec, { each: true })
public formats!: ProofFormatSpec[]

public formats!: V2ProofFormatSpec
@Expose({ name: 'proposals~attach' })
@Type(() => Attachment)
@IsArray()
@ValidateNested({ each: true })
@IsInstance(Attachment, { each: true })
public proposalsAttach!: Attachment[]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService'

import { Expose, Type } from 'class-transformer'
import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'

import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'

import { AgentMessage } from '@aries-framework/core'
import { Attachment } from 'packages/core/src/decorators/attachment/Attachment'
import { uuid } from 'packages/core/src/utils/uuid'

export interface V2RequestPresentationMessageOptions {
id?: string
comment?: string
goalCode?: string
willConfirm?: boolean
attachmentInfo: ProofAttachmentFormat[]
}

export class V2RequestPresentationMessage extends AgentMessage {
public constructor(options: V2RequestPresentationMessageOptions) {
super()
if (options) {
this.id = options.id ?? uuid()
this.comment = options.comment
this.goalCode = options.goalCode
this.willConfirm = options.willConfirm ?? false

for (const entry of options.attachmentInfo) {
this.addRequestPresentationsAttachment(entry)
}
}
}

public addRequestPresentationsAttachment(attachment: ProofAttachmentFormat) {
this.formats.push(attachment.format)
this.requestPresentationsAttach.push(attachment.attachment)
}

@Equals(V2RequestPresentationMessage.type)
public readonly type = V2RequestPresentationMessage.type
public static readonly type = 'https://didcomm.org/present-proof/2.0/request-presentation'

@IsString()
@IsOptional()
public comment?: string

@Expose({ name: 'goal_code' })
@IsString()
@IsOptional()
public goalCode?: string

@Expose({ name: 'will_confirm' })
@IsBoolean()
public willConfirm = false

@Expose({ name: 'formats' })
@Type(() => ProofFormatSpec)
@IsArray()
@ValidateNested({ each: true })
@IsInstance(ProofFormatSpec, { each: true })
public formats!: ProofFormatSpec[]

@Expose({ name: 'request_presentations~attach' })
@Type(() => Attachment)
@IsArray()
@ValidateNested({ each: true })
@IsInstance(Attachment, { each: true })
public requestPresentationsAttach!: Attachment[]
}

0 comments on commit 9d8791a

Please sign in to comment.