@@ -21,7 +21,6 @@ import { JSONSchema, Parser, CoreClaimOptions } from '../schema-processor';
21
21
import { IDataStorage } from '../storage/interfaces/data-storage' ;
22
22
import { MerkleTreeType } from '../storage/entities/mt' ;
23
23
import { getRandomBytes , keyPath } from '../kms/provider-helpers' ;
24
- import { UniversalSchemaLoader } from '../loaders' ;
25
24
import {
26
25
VerifiableConstants ,
27
26
BJJSignatureProof2021 ,
@@ -37,7 +36,8 @@ import {
37
36
import { CredentialRequest , ICredentialWallet } from '../credentials' ;
38
37
import { pushHashesToRHS , TreesModel } from '../credentials/rhs' ;
39
38
import { TreeState } from '../circuits' ;
40
- import { byteDecoder } from '../utils' ;
39
+ import { byteEncoder } from '../utils' ;
40
+ import { Options , Path , getDocumentLoader } from '@iden3/js-jsonld-merklization' ;
41
41
42
42
/**
43
43
* DID creation options
@@ -539,13 +539,22 @@ export class IdentityWallet implements IIdentityWallet {
539
539
}
540
540
541
541
/** {@inheritDoc IIdentityWallet.issueCredential } */
542
- async issueCredential ( issuerDID : DID , req : CredentialRequest ) : Promise < W3CCredential > {
542
+ async issueCredential (
543
+ issuerDID : DID ,
544
+ req : CredentialRequest ,
545
+ opts ?: Options
546
+ ) : Promise < W3CCredential > {
543
547
req . revocationOpts . id = req . revocationOpts . id . replace ( / \/ $ / , '' ) ;
544
548
545
- const schema = await new UniversalSchemaLoader ( 'ipfs.io' ) . load ( req . credentialSchema ) ;
546
-
547
- const jsonSchema : JSONSchema = JSON . parse ( byteDecoder . decode ( schema ) ) ;
549
+ let schema : object ;
550
+ const loader = getDocumentLoader ( opts ) ;
551
+ try {
552
+ schema = ( await loader ( req . credentialSchema ) ) . document ;
553
+ } catch ( e ) {
554
+ throw new Error ( `can't load credential schema ${ req . credentialSchema } ` ) ;
555
+ }
548
556
557
+ const jsonSchema = schema as JSONSchema ;
549
558
let credential : W3CCredential = new W3CCredential ( ) ;
550
559
551
560
req . revocationOpts . nonce =
@@ -568,13 +577,29 @@ export class IdentityWallet implements IIdentityWallet {
568
577
subjectPosition : req . subjectPosition ,
569
578
merklizedRootPosition : this . defineMTRootPosition ( jsonSchema , req . merklizedRootPosition ) ,
570
579
updatable : false ,
571
- version : 0
580
+ version : 0 ,
581
+ merklizeOpts : opts
572
582
} ;
573
583
584
+ let jsonLDCtx : object ;
585
+ try {
586
+ jsonLDCtx = ( await loader ( jsonSchema . $metadata . uris . jsonLdContext ) ) . document ;
587
+ } catch ( e ) {
588
+ throw new Error ( `can't load json-ld schema ${ jsonSchema . $metadata . uris . jsonLdContext } ` ) ;
589
+ }
590
+
591
+ const schemaBytes = byteEncoder . encode ( JSON . stringify ( jsonSchema ) ) ;
592
+
593
+ const credentialType = await Path . getTypeIDFromContext (
594
+ JSON . stringify ( jsonLDCtx ) ,
595
+ req . type ,
596
+ opts
597
+ ) ;
598
+
574
599
const coreClaim = await new Parser ( ) . parseClaim (
575
600
credential ,
576
- ` ${ jsonSchema . $metadata . uris [ 'jsonLdContext' ] } # ${ req . type } ` ,
577
- schema ,
601
+ credentialType ,
602
+ schemaBytes ,
578
603
coreClaimOpts
579
604
) ;
580
605
0 commit comments