-
Notifications
You must be signed in to change notification settings - Fork 182
/
ProofRequest.ts
83 lines (70 loc) · 2.43 KB
/
ProofRequest.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type { IndyProofRequest } from 'indy-sdk'
import { Expose, Type } from 'class-transformer'
import { IsString, ValidateNested, IsOptional, IsIn, IsInstance } from 'class-validator'
import { JsonTransformer } from '../../../utils/JsonTransformer'
import { IsMap } from '../../../utils/transformers'
import { RevocationInterval } from '../../credentials'
import { ProofAttributeInfo } from './ProofAttributeInfo'
import { ProofPredicateInfo } from './ProofPredicateInfo'
export interface ProofRequestOptions {
name: string
version: string
nonce: string
nonRevoked?: RevocationInterval
ver?: '1.0' | '2.0'
requestedAttributes?: Record<string, ProofAttributeInfo>
requestedPredicates?: Record<string, ProofPredicateInfo>
}
/**
* Proof Request for Indy based proof format
*
* @see https://github.com/hyperledger/indy-sdk/blob/57dcdae74164d1c7aa06f2cccecaae121cefac25/libindy/src/api/anoncreds.rs#L1222-L1239
*/
export class ProofRequest {
public constructor(options: ProofRequestOptions) {
if (options) {
this.name = options.name
this.version = options.version
this.nonce = options.nonce
this.requestedAttributes = options.requestedAttributes
? new Map(Object.entries(options.requestedAttributes))
: new Map()
this.requestedPredicates = options.requestedPredicates
? new Map(Object.entries(options.requestedPredicates))
: new Map()
this.nonRevoked = options.nonRevoked
this.ver = options.ver
}
}
@IsString()
public name!: string
@IsString()
public version!: string
@IsString()
public nonce!: string
@Expose({ name: 'requested_attributes' })
@IsMap()
@ValidateNested({ each: true })
@Type(() => ProofAttributeInfo)
@IsInstance(ProofAttributeInfo, { each: true })
public requestedAttributes!: Map<string, ProofAttributeInfo>
@Expose({ name: 'requested_predicates' })
@IsMap()
@ValidateNested({ each: true })
@Type(() => ProofPredicateInfo)
@IsInstance(ProofPredicateInfo, { each: true })
public requestedPredicates!: Map<string, ProofPredicateInfo>
@Expose({ name: 'non_revoked' })
@ValidateNested()
@Type(() => RevocationInterval)
@IsOptional()
@IsInstance(RevocationInterval)
public nonRevoked?: RevocationInterval
@IsIn(['1.0', '2.0'])
@IsOptional()
public ver?: '1.0' | '2.0'
public toJSON() {
// IndyProofRequest is indy-sdk json type
return JsonTransformer.toJSON(this) as unknown as IndyProofRequest
}
}