@@ -39,7 +39,13 @@ import {
39
39
import { toClaimNonRevStatus , toGISTProof } from './common' ;
40
40
import { NativeProver } from './prover' ;
41
41
42
- import { DocumentLoader , Options , Path , getDocumentLoader } from '@iden3/js-jsonld-merklization' ;
42
+ import {
43
+ DocumentLoader ,
44
+ Merklizer ,
45
+ Options ,
46
+ Path ,
47
+ getDocumentLoader
48
+ } from '@iden3/js-jsonld-merklization' ;
43
49
import { ZKProof } from '@iden3/js-jwz' ;
44
50
import { Signer } from 'ethers' ;
45
51
import { ZeroKnowledgeProofRequest , ZeroKnowledgeProofResponse } from '../iden3comm' ;
@@ -62,6 +68,7 @@ interface PreparedCredential {
62
68
export interface QueryWithFieldName {
63
69
query : Query ;
64
70
fieldName : string ;
71
+ rawValue ?: unknown ;
65
72
isSelectiveDisclosure ?: boolean ;
66
73
}
67
74
@@ -639,7 +646,7 @@ export class ProofService implements IProofService {
639
646
}
640
647
641
648
let path : Path = new Path ( ) ;
642
- if ( ! ! parsedQuery . fieldName ) {
649
+ if ( parsedQuery . fieldName ) {
643
650
path = await Path . getContextPathKey (
644
651
JSON . stringify ( schema ) ,
645
652
credential . type [ 1 ] ,
@@ -650,6 +657,7 @@ export class ProofService implements IProofService {
650
657
path . prepend ( [ 'https://www.w3.org/2018/credentials#credentialSubject' ] ) ;
651
658
652
659
const mk = await credential . merklize ( opts ) ;
660
+
653
661
const { proof, value : mtValue } = await mk . proof ( path ) ;
654
662
655
663
const pathKey = await path . mtEntry ( ) ;
@@ -665,7 +673,7 @@ export class ProofService implements IProofService {
665
673
} else {
666
674
parsedQuery . query . slotIndex = 5 ; // value data slot b
667
675
}
668
- if ( ! parsedQuery . fieldName ) {
676
+ if ( ! parsedQuery . fieldName ) {
669
677
const resultQuery = parsedQuery . query ;
670
678
resultQuery . operator = QueryOperators . $eq ;
671
679
resultQuery . values = [ mtEntry ] ;
@@ -684,6 +692,14 @@ export class ProofService implements IProofService {
684
692
resultQuery . values = [ mtEntry ] ;
685
693
return { query : resultQuery , vp } ;
686
694
}
695
+ if ( parsedQuery . rawValue === null || parsedQuery . rawValue === undefined ) {
696
+ throw new Error ( 'value is not presented in the query' ) ;
697
+ }
698
+ const ldType = await mk . jsonLDType ( path ) ;
699
+ parsedQuery . query . values = await this . transformQueryValueToBigInts (
700
+ parsedQuery . rawValue ,
701
+ ldType
702
+ ) ;
687
703
688
704
return { query : parsedQuery . query } ;
689
705
}
@@ -711,19 +727,27 @@ export class ProofService implements IProofService {
711
727
parsedQuery . fieldName ,
712
728
byteEncoder . encode ( JSON . stringify ( schema ) )
713
729
) ;
730
+ const { vp, mzValue, dataType } = await verifiablePresentationFromCred (
731
+ credential ,
732
+ query ,
733
+ parsedQuery . fieldName ,
734
+ opts
735
+ ) ;
714
736
715
737
if ( parsedQuery . isSelectiveDisclosure ) {
716
- const { vp, mzValue } = await verifiablePresentationFromCred (
717
- credential ,
718
- query ,
719
- parsedQuery . fieldName ,
720
- opts
721
- ) ;
722
738
const resultQuery = parsedQuery . query ;
723
739
resultQuery . operator = QueryOperators . $eq ;
724
740
resultQuery . values = [ await mzValue . mtEntry ( ) ] ;
725
741
return { query : resultQuery , vp } ;
726
742
}
743
+ if ( parsedQuery . rawValue === null || parsedQuery . rawValue === undefined ) {
744
+ throw new Error ( 'value is not presented in the query' ) ;
745
+ }
746
+
747
+ parsedQuery . query . values = await this . transformQueryValueToBigInts (
748
+ parsedQuery . rawValue ,
749
+ dataType
750
+ ) ;
727
751
728
752
return { query : parsedQuery . query } ;
729
753
}
@@ -756,24 +780,28 @@ export class ProofService implements IProofService {
756
780
}
757
781
758
782
let operator = 0 ;
759
- const values : bigint [ ] = new Array < bigint > ( 64 ) . fill ( BigInt ( 0 ) ) ;
760
783
const [ key , value ] = fieldReqEntries [ 0 ] ;
761
784
if ( ! QueryOperators [ key ] ) {
762
785
throw new Error ( `operator is not supported by lib` ) ;
763
786
}
764
787
operator = QueryOperators [ key ] ;
788
+
789
+ query . operator = operator ;
790
+
791
+ return { query, fieldName, rawValue : value } ;
792
+ }
793
+
794
+ async transformQueryValueToBigInts ( value : unknown , ldType : string ) : Promise < bigint [ ] > {
795
+ const values : bigint [ ] = new Array < bigint > ( 64 ) . fill ( BigInt ( 0 ) ) ;
796
+
765
797
if ( Array . isArray ( value ) ) {
766
798
for ( let index = 0 ; index < value . length ; index ++ ) {
767
- values [ index ] = BigInt ( value [ index ] ) ;
799
+ values [ index ] = await Merklizer . hashValue ( ldType , value ) ;
768
800
}
769
801
} else {
770
- values [ 0 ] = BigInt ( value ) ;
802
+ values [ 0 ] = await Merklizer . hashValue ( ldType , value ) ;
771
803
}
772
-
773
- query . operator = operator ;
774
- query . values = values ;
775
-
776
- return { query, fieldName } ;
804
+ return values ;
777
805
}
778
806
779
807
/** {@inheritdoc IProofService.generateAuthV2Inputs } */
0 commit comments