1
- import { ArrayNotEmpty , IsArray , IsBoolean , IsEmail , IsEnum , IsNotEmpty , IsNumberString , IsObject , IsOptional , IsString , ValidateIf , ValidateNested , IsUUID , ArrayUnique , ArrayMaxSize } from 'class-validator' ;
1
+ import { ArrayNotEmpty , IsArray , IsBoolean , IsEmail , IsEnum , IsNotEmpty , IsNumberString , IsObject , IsOptional , IsString , ValidateIf , ValidateNested , IsUUID , ArrayUnique , ArrayMaxSize , ArrayMinSize } from 'class-validator' ;
2
2
import { trim } from '@credebl/common/cast.helper' ;
3
3
import { ApiProperty , ApiPropertyOptional } from '@nestjs/swagger' ;
4
4
import { Transform , Type } from 'class-transformer' ;
@@ -14,7 +14,7 @@ export class ProofRequestAttribute {
14
14
attributeName ?: string ;
15
15
16
16
@ValidateIf ( ( obj ) => obj . attributeName === undefined )
17
- @IsArray ( { message : 'attributeNames must be an array. ' } )
17
+ @IsArray ( { message : 'attributeNames must be an array' } )
18
18
@ArrayNotEmpty ( { message : 'array can not be empty' } )
19
19
@IsString ( { each : true } )
20
20
@IsNotEmpty ( { each : true , message : 'each element cannot be empty' } )
@@ -23,23 +23,25 @@ export class ProofRequestAttribute {
23
23
@ApiPropertyOptional ( )
24
24
@IsString ( )
25
25
@IsOptional ( )
26
+ @IsNotEmpty ( { message : 'schemaId is required' } )
26
27
schemaId ?: string ;
27
28
28
29
@ApiPropertyOptional ( )
29
- @IsString ( )
30
- @IsOptional ( )
31
- @IsNotEmpty ( { message : 'condition is required. ' } )
30
+ @ValidateIf ( ( obj ) => obj . value !== undefined || obj . condition !== undefined )
31
+ @IsNotEmpty ( { message : 'condition is required' } )
32
+ @IsString ( { message : 'condition must be a string ' } )
32
33
condition ?: string ;
33
-
34
+
34
35
@ApiPropertyOptional ( )
35
- @IsOptional ( )
36
- @IsNotEmpty ( { message : 'value is required. ' } )
37
- @IsNumberString ( { } , { message : 'Value must be a number' } )
36
+ @ValidateIf ( ( obj ) => obj . condition !== undefined || obj . value !== undefined )
37
+ @IsNotEmpty ( { message : 'value is required' } )
38
+ @IsNumberString ( { } , { message : 'value must be a number' } )
38
39
value ?: string ;
39
40
40
41
@ApiPropertyOptional ( )
41
42
@IsString ( )
42
43
@IsOptional ( )
44
+ @IsNotEmpty ( { message : 'credDefId is required' } )
43
45
credDefId ?: string ;
44
46
}
45
47
@@ -54,7 +56,7 @@ class ProofPayload {
54
56
@IsString ( { message : 'parentThreadId must be in string' } )
55
57
@IsNotEmpty ( { message : 'please provide valid parentThreadId' } )
56
58
@IsOptional ( )
57
- parentThreadId : string ;
59
+ parentThreadId ? : string ;
58
60
59
61
@ApiPropertyOptional ( )
60
62
@IsBoolean ( { message : 'willConfirm must be in boolean' } )
@@ -72,14 +74,14 @@ class ProofPayload {
72
74
export class Fields {
73
75
@ApiProperty ( )
74
76
@IsArray ( )
75
- @IsNotEmpty ( { message : 'path is required. ' } )
77
+ @IsNotEmpty ( { message : 'path is required' } )
76
78
path : string [ ] ;
77
79
}
78
80
79
81
export class Constraints {
80
82
@ApiProperty ( { type : ( ) => [ Fields ] } )
81
83
@IsOptional ( )
82
- @IsNotEmpty ( { message : 'Fields are required. ' } )
84
+ @IsNotEmpty ( { message : 'Fields are required' } )
83
85
@ValidateNested ( )
84
86
@Type ( ( ) => Fields )
85
87
fields : Fields [ ] ;
@@ -88,40 +90,40 @@ export class Constraints {
88
90
89
91
export class Schema {
90
92
@ApiProperty ( )
91
- @IsNotEmpty ( { message : 'uri is required. ' } )
93
+ @IsNotEmpty ( { message : 'uri is required' } )
92
94
@IsString ( )
93
95
uri :string ;
94
96
95
97
}
96
98
export class InputDescriptors {
97
99
@ApiProperty ( )
98
- @IsNotEmpty ( { message : 'id is required. ' } )
100
+ @IsNotEmpty ( { message : 'id is required' } )
99
101
@IsString ( )
100
102
id :string ;
101
103
102
104
@ApiProperty ( )
103
105
@IsString ( )
104
106
@IsOptional ( )
105
- @IsNotEmpty ( { message : 'name is required. ' } )
107
+ @IsNotEmpty ( { message : 'name is required' } )
106
108
name :string ;
107
109
108
110
@ApiProperty ( )
109
111
@IsString ( )
110
112
@IsOptional ( )
111
- @IsNotEmpty ( { message : 'purpose is required. ' } )
113
+ @IsNotEmpty ( { message : 'purpose is required' } )
112
114
purpose :string ;
113
115
114
116
115
117
@ApiProperty ( { type : ( ) => [ Schema ] } )
116
- @IsNotEmpty ( { message : 'schema is required. ' } )
118
+ @IsNotEmpty ( { message : 'schema is required' } )
117
119
@ValidateNested ( )
118
120
@Type ( ( ) => Schema )
119
121
schema :Schema [ ] ;
120
122
121
123
122
124
@ApiProperty ( { type : ( ) => Constraints } )
123
125
@IsOptional ( )
124
- @IsNotEmpty ( { message : 'Constraints are required. ' } )
126
+ @IsNotEmpty ( { message : 'Constraints are required' } )
125
127
@ValidateNested ( )
126
128
@Type ( ( ) => Constraints )
127
129
constraints :Constraints ;
@@ -131,19 +133,19 @@ export class InputDescriptors {
131
133
export class ProofRequestPresentationDefinition {
132
134
133
135
@IsString ( )
134
- @IsNotEmpty ( { message : 'id is required. ' } )
136
+ @IsNotEmpty ( { message : 'id is required' } )
135
137
id : string ;
136
138
137
139
@IsString ( )
138
140
@IsOptional ( )
139
141
name : string ;
140
142
141
- @ApiProperty ( { type : ( ) => [ InputDescriptors ] } )
142
- @IsNotEmpty ( { message : 'inputDescriptors is required.' } )
143
+ @ApiProperty ( { type : ( ) => [ InputDescriptors ] } )
143
144
@IsArray ( { message : 'inputDescriptors must be an array' } )
144
- @IsObject ( { each : true } )
145
+ @IsNotEmpty ( { message : 'inputDescriptors is required' } )
146
+ @ArrayMinSize ( 1 )
147
+ @ValidateNested ( { each :true } )
145
148
@Type ( ( ) => InputDescriptors )
146
- @ValidateNested ( )
147
149
// eslint-disable-next-line camelcase
148
150
input_descriptors :InputDescriptors [ ] ;
149
151
}
@@ -162,7 +164,7 @@ export class ProofRequestAttributeDto {
162
164
type : ( ) => [ ProofRequestAttribute ]
163
165
} )
164
166
@IsArray ( { message : 'attributes must be in array' } )
165
- @ValidateNested ( )
167
+ @ValidateNested ( { each : true } )
166
168
@IsObject ( { each : true } )
167
169
@IsNotEmpty ( { message : 'please provide valid attributes' } )
168
170
@Type ( ( ) => ProofRequestAttribute )
@@ -191,13 +193,7 @@ export class IndyDto {
191
193
indy : ProofRequestAttributeDto ;
192
194
}
193
195
194
- export class RequestProofDto extends ProofPayload {
195
- @ApiProperty ( )
196
- @IsString ( )
197
- @Transform ( ( { value } ) => trim ( value ) )
198
- @IsUUID ( )
199
- @IsNotEmpty ( { message : 'connectionId is required.' } )
200
- connectionId : string ;
196
+ export class RequestProofDtoBase extends ProofPayload {
201
197
202
198
@ApiProperty ( {
203
199
'example' :
@@ -213,7 +209,7 @@ export class RequestProofDto extends ProofPayload {
213
209
}
214
210
]
215
211
}
216
- } ,
212
+ } ,
217
213
type : ( ) => [ IndyDto ]
218
214
} )
219
215
@IsOptional ( )
@@ -222,12 +218,13 @@ export class RequestProofDto extends ProofPayload {
222
218
@IsNotEmpty ( { message : 'ProofFormatDto must not be empty' } )
223
219
@Type ( ( ) => IndyDto )
224
220
proofFormats ?: IndyDto ;
225
-
221
+
226
222
@ApiProperty ( {
227
223
'example' :
228
224
{
229
- id : '32f54163-7166-48f1-93d8-ff217bdb0653' ,
230
- inputDescriptors : [
225
+ id : '32f54163-7166-48f1-93d8-ff217bdb0653' ,
226
+ // eslint-disable-next-line camelcase
227
+ input_descriptors : [
231
228
{
232
229
'id' : 'healthcare_input_1' ,
233
230
'name' : 'Medical History' ,
@@ -240,7 +237,7 @@ export class RequestProofDto extends ProofPayload {
240
237
'constraints' : {
241
238
'fields' : [
242
239
{
243
- 'path' : [ '$.PatientID' ]
240
+ 'path' : [ '$.credentialSubject. PatientID' ]
244
241
}
245
242
]
246
243
}
@@ -260,20 +257,44 @@ export class RequestProofDto extends ProofPayload {
260
257
@IsOptional ( )
261
258
@IsString ( { message : 'comment must be in string' } )
262
259
comment : string ;
263
-
260
+
264
261
type :ProofRequestType ;
265
-
262
+
266
263
orgId : string ;
267
-
268
- @ApiPropertyOptional ( )
264
+
265
+ @ApiPropertyOptional ( { enum : AutoAccept } )
269
266
@IsString ( { message : 'auto accept proof must be in string' } )
270
267
@IsNotEmpty ( { message : 'please provide valid auto accept proof' } )
271
268
@IsOptional ( )
272
269
@IsEnum ( AutoAccept , {
273
- message : `Invalid auto accept proof. It should be one of: ${ Object . values ( AutoAccept ) . join ( ', ' ) } `
270
+ message : `Invalid auto accept proof. It should be one of: ${ Object . values ( AutoAccept ) . join ( ', ' ) } `
274
271
} )
275
272
autoAcceptProof : AutoAccept ;
273
+ version : string ;
276
274
}
275
+ export class RequestProofDtoV1 extends RequestProofDtoBase {
276
+ @ApiProperty ( {
277
+ example : '32f54163-7166-48f1-93d8-ff217bdb0653'
278
+ } )
279
+ @IsNotEmpty ( { message : 'connectionId is required' } )
280
+ @IsString ( { message : 'connectionId must be a string' } )
281
+ @IsUUID ( )
282
+ connectionId :string ;
283
+ }
284
+
285
+
286
+ export class RequestProofDtoV2 extends RequestProofDtoBase {
287
+ @ApiProperty ( {
288
+ example : [ '32f54163-7166-48f1-93d8-ff217bdb0653' ]
289
+ } )
290
+ @IsNotEmpty ( { each : true , message : 'connectionId array elements must not be empty' } )
291
+ @IsArray ( { message : 'connectionId must be an array' } )
292
+ @ArrayMinSize ( 1 , { message : 'connectionId must contain at least 1 element' } )
293
+ @ArrayMaxSize ( Number ( process . env . PROOF_REQ_CONN_LIMIT ) , { message : `Limit reached (${ process . env . PROOF_REQ_CONN_LIMIT } connections max).` } )
294
+ @IsUUID ( 'all' , { each : true , message : 'Each connectionId must be a valid UUID' } )
295
+ connectionId : string [ ] ;
296
+ }
297
+
277
298
278
299
export class OutOfBandRequestProof extends ProofPayload {
279
300
@ApiProperty ( {
@@ -421,7 +442,7 @@ export class SendProofRequestPayload {
421
442
@ApiProperty ( { example : true } )
422
443
@IsBoolean ( )
423
444
@IsOptional ( )
424
- @IsNotEmpty ( { message :'Please provide the flag for shorten url. ' } )
445
+ @IsNotEmpty ( { message :'Please provide the flag for shorten url' } )
425
446
isShortenUrl ?: boolean ;
426
447
427
448
@ApiPropertyOptional ( )
0 commit comments