@@ -135,6 +135,11 @@ export class IssuanceService {
135
135
}
136
136
137
137
const getSchemaDetails = await this . issuanceRepository . getSchemaDetails ( schemaUrl ) ;
138
+
139
+ if ( ! getSchemaDetails ) {
140
+ throw new NotFoundException ( ResponseMessages . schema . error . notFound ) ;
141
+ }
142
+
138
143
const schemaAttributes = JSON . parse ( getSchemaDetails ?. attributes ) ;
139
144
140
145
return schemaAttributes ;
@@ -206,6 +211,21 @@ export class IssuanceService {
206
211
comment
207
212
} ;
208
213
} else if ( payload . credentialType === IssueCredentialType . JSONLD ) {
214
+ const schemaIds = credentialData ?. map ( ( item ) => {
215
+ const context : string [ ] = item ?. credential ?. [ '@context' ] ;
216
+ return Array . isArray ( context ) && 1 < context . length ? context [ 1 ] : undefined ;
217
+ } ) ;
218
+
219
+ const schemaDetails = await this . _getSchemaDetails ( schemaIds ) ;
220
+
221
+ const ledgerIds = schemaDetails ?. map ( ( item ) => item ?. ledgerId ) ;
222
+
223
+ for ( const ledgerId of ledgerIds ) {
224
+ if ( agentDetails ?. ledgerId !== ledgerId ) {
225
+ throw new BadRequestException ( ResponseMessages . issuance . error . ledgerMismatched ) ;
226
+ }
227
+ }
228
+
209
229
issueData = {
210
230
protocolVersion : payload . protocolVersion || 'v2' ,
211
231
connectionId,
@@ -379,6 +399,20 @@ export class IssuanceService {
379
399
}
380
400
381
401
if ( credentialType === IssueCredentialType . JSONLD ) {
402
+ const context = credential ?. [ '@context' ] [ 1 ] ;
403
+
404
+ const schemaDetails = await this . issuanceRepository . getSchemaDetails ( String ( context ) ) ;
405
+
406
+ if ( ! schemaDetails ) {
407
+ throw new NotFoundException ( ResponseMessages . schema . error . notFound ) ;
408
+ }
409
+
410
+ const ledgerId = schemaDetails ?. ledgerId ;
411
+
412
+ if ( agentDetails ?. ledgerId !== ledgerId ) {
413
+ throw new BadRequestException ( ResponseMessages . issuance . error . ledgerMismatched ) ;
414
+ }
415
+
382
416
issueData = {
383
417
protocolVersion : protocolVersion || 'v2' ,
384
418
credentialFormats : {
@@ -733,8 +767,25 @@ export class IssuanceService {
733
767
isValidateSchema
734
768
} = outOfBandCredential ;
735
769
770
+ const agentDetails = await this . issuanceRepository . getAgentEndPoint ( orgId ) ;
771
+
736
772
if ( IssueCredentialType . JSONLD === credentialType ) {
737
773
await validateAndUpdateIssuanceDates ( credentialOffer ) ;
774
+
775
+ const schemaIds = credentialOffer ?. map ( ( item ) => {
776
+ const context : string [ ] = item ?. credential ?. [ '@context' ] ;
777
+ return Array . isArray ( context ) && 1 < context . length ? context [ 1 ] : undefined ;
778
+ } ) ;
779
+
780
+ const schemaDetails = await this . _getSchemaDetails ( schemaIds ) ;
781
+
782
+ const ledgerIds = schemaDetails ?. map ( ( item ) => item ?. ledgerId ) ;
783
+
784
+ for ( const ledgerId of ledgerIds ) {
785
+ if ( agentDetails ?. ledgerId !== ledgerId ) {
786
+ throw new BadRequestException ( ResponseMessages . issuance . error . ledgerMismatched ) ;
787
+ }
788
+ }
738
789
}
739
790
740
791
if ( IssueCredentialType . INDY === credentialType ) {
@@ -780,7 +831,6 @@ export class IssuanceService {
780
831
}
781
832
}
782
833
}
783
- const agentDetails = await this . issuanceRepository . getAgentEndPoint ( orgId ) ;
784
834
785
835
const { organisation } = agentDetails ;
786
836
if ( ! agentDetails ) {
@@ -1177,6 +1227,10 @@ export class IssuanceService {
1177
1227
1178
1228
const schemaDetails = await this . issuanceRepository . getSchemaDetails ( schemaResponse . schemaLedgerId ) ;
1179
1229
1230
+ if ( ! schemaDetails ) {
1231
+ throw new NotFoundException ( ResponseMessages . schema . error . notFound ) ;
1232
+ }
1233
+
1180
1234
if ( orgDetails ?. ledgerId !== schemaDetails ?. ledgerId ) {
1181
1235
throw new BadRequestException ( ResponseMessages . issuance . error . ledgerMismatched ) ;
1182
1236
}
@@ -1261,6 +1315,10 @@ export class IssuanceService {
1261
1315
credentialDetails = await this . issuanceRepository . getCredentialDefinitionDetails ( templateId ) ;
1262
1316
const schemaDetails = await this . issuanceRepository . getSchemaDetails ( credentialDetails . schemaLedgerId ) ;
1263
1317
1318
+ if ( ! schemaDetails ) {
1319
+ throw new NotFoundException ( ResponseMessages . schema . error . notFound ) ;
1320
+ }
1321
+
1264
1322
if ( orgDetails ?. ledgerId !== schemaDetails ?. ledgerId ) {
1265
1323
throw new BadRequestException ( ResponseMessages . issuance . error . ledgerMismatched ) ;
1266
1324
}
0 commit comments