forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from hyperledger/feat/present-proof-v2
Feat/present proof v2
- Loading branch information
Showing
5 changed files
with
233 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...l/v2/messages/PresentationAckMessageV2.ts → ...l/v2/messages/V2PresentationAckMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] | ||
} |