-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathAnonCredsProofRequest.ts
83 lines (68 loc) · 2.5 KB
/
AnonCredsProofRequest.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 { AnonCredsRequestedAttributeOptions } from './AnonCredsRequestedAttribute'
import type { AnonCredsRequestedPredicateOptions } from './AnonCredsRequestedPredicate'
import { Expose, Type } from 'class-transformer'
import { IsIn, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
import { IsMap } from '../utils'
import { AnonCredsRequestedAttribute } from './AnonCredsRequestedAttribute'
import { AnonCredsRequestedPredicate } from './AnonCredsRequestedPredicate'
import { AnonCredsRevocationInterval } from './AnonCredsRevocationInterval'
export interface AnonCredsProofRequestOptions {
name: string
version: string
nonce: string
nonRevoked?: AnonCredsRevocationInterval
ver?: '1.0' | '2.0'
requestedAttributes?: Record<string, AnonCredsRequestedAttributeOptions>
requestedPredicates?: Record<string, AnonCredsRequestedPredicateOptions>
}
/**
* Proof Request for AnonCreds based proof format
*/
export class AnonCredsProofRequest {
public constructor(options: AnonCredsProofRequestOptions) {
if (options) {
this.name = options.name
this.version = options.version
this.nonce = options.nonce
this.requestedAttributes = new Map(
Object.entries(options.requestedAttributes ?? {}).map(([key, attribute]) => [
key,
new AnonCredsRequestedAttribute(attribute),
])
)
this.requestedPredicates = new Map(
Object.entries(options.requestedPredicates ?? {}).map(([key, predicate]) => [
key,
new AnonCredsRequestedPredicate(predicate),
])
)
this.nonRevoked = options.nonRevoked ? new AnonCredsRevocationInterval(options.nonRevoked) : undefined
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(() => AnonCredsRequestedAttribute)
public requestedAttributes!: Map<string, AnonCredsRequestedAttribute>
@Expose({ name: 'requested_predicates' })
@IsMap()
@ValidateNested({ each: true })
@Type(() => AnonCredsRequestedPredicate)
public requestedPredicates!: Map<string, AnonCredsRequestedPredicate>
@Expose({ name: 'non_revoked' })
@ValidateNested()
@Type(() => AnonCredsRevocationInterval)
@IsOptional()
@IsInstance(AnonCredsRevocationInterval)
public nonRevoked?: AnonCredsRevocationInterval
@IsIn(['1.0', '2.0'])
@IsOptional()
public ver?: '1.0' | '2.0'
}