1
- import { DidMethod , JSONSchemaType , ledgerLessDIDType , ProofType , schemaRequestType , TemplateIdentifier } from '@credebl/enum/enum' ;
1
+ import {
2
+ DidMethod ,
3
+ JSONSchemaType ,
4
+ ledgerLessDIDType ,
5
+ ProofType ,
6
+ schemaRequestType ,
7
+ TemplateIdentifier
8
+ } from '../../enum/src/enum' ;
2
9
import { ISchemaFields } from './interfaces/schema.interface' ;
3
10
import { BadRequestException , PipeTransform } from '@nestjs/common' ;
4
11
import { plainToClass } from 'class-transformer' ;
@@ -82,19 +89,22 @@ export function isSafeString(value: string): boolean {
82
89
}
83
90
84
91
export const IsNotSQLInjection =
85
- ( validationOptions ?: ValidationOptions ) : PropertyDecorator => ( object : object , propertyName : string ) => {
92
+ ( validationOptions ?: ValidationOptions ) : PropertyDecorator =>
93
+ ( object : object , propertyName : string ) => {
86
94
registerDecorator ( {
87
95
name : 'isNotSQLInjection' ,
88
96
target : object . constructor ,
89
97
propertyName,
90
98
options : validationOptions ,
91
99
validator : {
92
100
validate ( value ) {
93
-
94
101
// Check if the value is a string
95
102
if ( 'string' === typeof value ) {
96
103
// Regex to check for SQL injection keywords at the start
97
- const startInjectionRegex = new RegExp ( `^\\b(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|ALTER|CREATE|EXEC|FROM|WHERE|AND|OR)\\b` , 'i' ) ;
104
+ const startInjectionRegex = new RegExp (
105
+ `^\\b(SELECT|INSERT|UPDATE|DELETE|DROP|UNION|ALTER|CREATE|EXEC|FROM|WHERE|AND|OR)\\b` ,
106
+ 'i'
107
+ ) ;
98
108
99
109
// Check if the SQL injection pattern is present at the start
100
110
if ( startInjectionRegex . test ( value ) ) {
@@ -110,7 +120,7 @@ export const IsNotSQLInjection =
110
120
}
111
121
} ) ;
112
122
} ;
113
-
123
+
114
124
@ValidatorConstraint ( { name : 'customText' , async : false } )
115
125
export class ImageBase64Validator implements ValidatorConstraintInterface {
116
126
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type, @typescript-eslint/no-unused-vars
@@ -167,7 +177,7 @@ export class EmptyStringParamPipe implements PipeTransform {
167
177
private constructor ( paramName : string ) {
168
178
this . paramName = paramName ;
169
179
}
170
-
180
+
171
181
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
172
182
transform ( value : string ) {
173
183
const trimmedValue = value . trim ( ) ;
@@ -194,7 +204,6 @@ export class EmptyStringParamPipe implements PipeTransform {
194
204
// });
195
205
// };
196
206
197
-
198
207
export function validateSchemaPayload ( schemaPayload : ISchemaFields , schemaType : string ) : void {
199
208
const errors : string [ ] = [ ] ;
200
209
@@ -314,21 +323,19 @@ export class AgentSpinupValidator {
314
323
public static validate ( agentSpinupDto ) : void {
315
324
this . validateWalletName ( agentSpinupDto . walletName ) ;
316
325
}
317
-
318
326
}
319
327
320
328
export const validateEmail = ( email : string ) : boolean => {
321
329
const emailRegex = / ^ [ a - z A - Z 0 - 9 . _ - ] + @ [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , 4 } $ / ;
322
330
return emailRegex . test ( email ) ;
323
331
} ;
324
332
325
-
326
333
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type
327
334
export const createOobJsonldIssuancePayload = ( JsonldCredentialDetails : IJsonldCredential , prettyVc : IPrettyVc ) => {
328
- const { credentialData, orgDid, orgId, schemaLedgerId, schemaName, isReuseConnection} = JsonldCredentialDetails ;
329
- const credentialSubject = { } ;
335
+ const { credentialData, orgDid, orgId, schemaLedgerId, schemaName, isReuseConnection } = JsonldCredentialDetails ;
336
+ const credentialSubject = { } ;
330
337
331
- const proofType = ( orgDid ?. includes ( DidMethod . POLYGON ) ) ? ProofType . POLYGON_PROOFTYPE : ProofType . NO_LEDGER_PROOFTYPE ;
338
+ const proofType = orgDid ?. includes ( DidMethod . POLYGON ) ? ProofType . POLYGON_PROOFTYPE : ProofType . NO_LEDGER_PROOFTYPE ;
332
339
333
340
for ( const key in credentialData ) {
334
341
if ( credentialData . hasOwnProperty ( key ) && TemplateIdentifier . EMAIL_COLUMN !== key ) {
@@ -339,41 +346,39 @@ export const createOobJsonldIssuancePayload = (JsonldCredentialDetails: IJsonldC
339
346
return {
340
347
credentialOffer : [
341
348
{
342
- ' emailId' : `${ credentialData . email_identifier } ` ,
343
- ' credential' : {
349
+ emailId : `${ credentialData . email_identifier } ` ,
350
+ credential : {
344
351
'@context' : [ 'https://www.w3.org/2018/credentials/v1' , `${ schemaLedgerId } ` ] ,
345
- 'type' : [
346
- 'VerifiableCredential' ,
347
- `${ schemaName } `
348
- ] ,
349
- 'issuer' : {
350
- 'id' : `${ orgDid } `
352
+ type : [ 'VerifiableCredential' , `${ schemaName } ` ] ,
353
+ issuer : {
354
+ id : `${ orgDid } `
351
355
} ,
352
- ' issuanceDate' : new Date ( ) . toISOString ( ) ,
356
+ issuanceDate : new Date ( ) . toISOString ( ) ,
353
357
credentialSubject,
354
358
prettyVc
355
359
} ,
356
- ' options' : {
360
+ options : {
357
361
proofType,
358
- ' proofPurpose' : 'assertionMethod'
362
+ proofPurpose : 'assertionMethod'
359
363
}
360
364
}
361
365
] ,
362
- ' comment' : 'string' ,
363
- ' protocolVersion' : 'v2' ,
364
- ' credentialType' : 'jsonld' ,
366
+ comment : 'string' ,
367
+ protocolVersion : 'v2' ,
368
+ credentialType : 'jsonld' ,
365
369
orgId,
366
370
isReuseConnection
367
371
} ;
368
372
} ;
369
373
370
-
371
374
@ValidatorConstraint ( { name : 'isHostPortOrDomain' , async : false } )
372
375
export class IsHostPortOrDomainConstraint implements ValidatorConstraintInterface {
373
376
validate ( value : string ) : boolean {
374
377
// Regular expression for validating URL with host:port or domain
375
- const hostPortRegex = / ^ ( h t t p : \/ \/ | h t t p s : \/ \/ ) ? (?: (?: (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) \. ) { 3 } (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) : (?: \d { 1 , 5 } ) ( \/ [ ^ \s ] * ) ? $ / ;
376
- const domainRegex = / ^ ( h t t p : \/ \/ | h t t p s : \/ \/ ) ? (?: l o c a l h o s t | (?: [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? \. ) + [ a - z A - Z ] { 2 , } ) ( : \d { 1 , 5 } ) ? ( \/ [ ^ \s ] * ) ? $ / ;
378
+ const hostPortRegex =
379
+ / ^ ( h t t p : \/ \/ | h t t p s : \/ \/ ) ? (?: (?: (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) \. ) { 3 } (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) : (?: \d { 1 , 5 } ) ( \/ [ ^ \s ] * ) ? $ / ;
380
+ const domainRegex =
381
+ / ^ ( h t t p : \/ \/ | h t t p s : \/ \/ ) ? (?: l o c a l h o s t | (?: [ a - z A - Z 0 - 9 ] (?: [ a - z A - Z 0 - 9 - ] { 0 , 61 } [ a - z A - Z 0 - 9 ] ) ? \. ) + [ a - z A - Z ] { 2 , } ) ( : \d { 1 , 5 } ) ? ( \/ [ ^ \s ] * ) ? $ / ;
377
382
378
383
return hostPortRegex . test ( value ) || domainRegex . test ( value ) ;
379
384
}
@@ -396,10 +401,9 @@ export function IsHostPortOrDomain(validationOptions?: ValidationOptions) {
396
401
}
397
402
398
403
export function checkDidLedgerAndNetwork ( schemaType : string , did : string ) : boolean {
399
-
400
404
const cleanSchemaType = schemaType . trim ( ) . toLowerCase ( ) ;
401
405
const cleanDid = did . trim ( ) . toLowerCase ( ) ;
402
-
406
+
403
407
if ( JSONSchemaType . POLYGON_W3C === cleanSchemaType ) {
404
408
return cleanDid . includes ( JSONSchemaType . POLYGON_W3C ) ;
405
409
}
0 commit comments