@@ -464,4 +464,151 @@ describe('credential-wallet', () => {
464
464
mockedProof . issuerData . state . claimsTreeRoot . bigInt ( ) . toString ( )
465
465
) ;
466
466
} ) ;
467
+
468
+ it ( 'Credential search by query' , async ( ) => {
469
+ const credentialStorage = new CredentialStorage ( new InMemoryDataSource < W3CCredential > ( ) ) ;
470
+
471
+ const credToTest = W3CCredential . fromJSON (
472
+ JSON . parse ( `{
473
+ "id": "urn:uuid:9c421fdc-16cc-11f0-9a77-0a58a9feac02",
474
+ "@context": [
475
+ "https://www.w3.org/2018/credentials/v1",
476
+ "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld",
477
+ "ipfs://Qmb48rJ5SiQMLXjVkaLQB6fWbT7C8LK75MHsCoHv8GAc15"
478
+ ],
479
+ "type": [
480
+ "VerifiableCredential",
481
+ "operators"
482
+ ],
483
+ "credentialSubject": {
484
+ "boolean1": true,
485
+ "date-time1": "2025-04-09T15:48:08.800+02:00",
486
+ "id": "did:iden3:privado:main:2SeEkMwamyzKWr3aGUT9AvDjiQK4rMEAZbUZgEzP72",
487
+ "integer1": 5342,
488
+ "non-negative-integer1": "32423",
489
+ "number1": 1234,
490
+ "positive-integer1": "12345555",
491
+ "string1": "testData",
492
+ "type": "operators"
493
+ },
494
+ "issuer": "did:iden3:polygon:amoy:xJNwv94NrHy1xXU3poKTRL24WJEXmkEggwbBWy6gu",
495
+ "credentialSchema": {
496
+ "id": "https://ipfs.io/ipfs/QmWDmZQrtvidcNK7d6rJwq7ZSi8SUygJaKepN7NhKtGryc",
497
+ "type": "JsonSchema2023"
498
+ },
499
+ "credentialStatus": {
500
+ "id": "https://issuer-node-core-api-testing.privado.id/v2/agent",
501
+ "revocationNonce": 978385127,
502
+ "type": "Iden3commRevocationStatusV1.0"
503
+ },
504
+ "issuanceDate": "2025-04-11T12:00:49.921271223Z",
505
+ "proof": [
506
+ {
507
+ "issuerData": {
508
+ "id": "did:iden3:polygon:amoy:xJNwv94NrHy1xXU3poKTRL24WJEXmkEggwbBWy6gu",
509
+ "state": {
510
+ "claimsTreeRoot": "1483789a545832ba69d54ed1691ce758f9b8297542b2749f6fa4786e74fbe80e",
511
+ "value": "310ccc3f33fbbfd50da56755e442896065b388e9c4adadd644588eaa6e171b1a",
512
+ "rootOfRoots": "0000000000000000000000000000000000000000000000000000000000000000",
513
+ "revocationTreeRoot": "0000000000000000000000000000000000000000000000000000000000000000"
514
+ },
515
+ "mtp": {
516
+ "existence": true,
517
+ "siblings": []
518
+ },
519
+ "authCoreClaim": "cca3371a6cb1b715004407e325bd993c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000079adcc5f988e5e6fb7d04adcb5e07afdd53babf34acdb75aa51ac8e1ddc0ee20211c823ff2b1ee62e988fba84247930add22fbbc2fcc4f1b4fd3a50e07f9e6170000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
520
+ "credentialStatus": {
521
+ "id": "https://issuer-node-core-api-testing.privado.id/v2/agent",
522
+ "revocationNonce": 0,
523
+ "type": "Iden3commRevocationStatusV1.0"
524
+ }
525
+ },
526
+ "type": "BJJSignature2021",
527
+ "coreClaim": "637056ad190ec7df5fef1345fda35e1f2200000000000000000000000000000001a16e78ba913717bc15cbe326e236c7eef4f9201582b50e145cb669139c0d0068fbed6c1ddf63a9a4eaa0d4a577b770a5acaf37a542cf86cb6e9e93e9b608020000000000000000000000000000000000000000000000000000000000000000e7f8503a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
528
+ "signature": "b17ca01ab223b6281e0b22b4f8945729ffb39eaf4b2a0db59548db7ab0df092e423dfc2472cce2e269a80a4d37bb520eda59ab3a0adfae043caa38a464869505"
529
+ }
530
+ ]
531
+ }` )
532
+ ) ;
533
+ await credentialStorage . saveCredential ( credToTest ) ;
534
+
535
+ // positive-integer
536
+
537
+ let cred = await credentialStorage . findCredentialsByQuery ( {
538
+ allowedIssuers : [ '*' ] ,
539
+ context : 'ipfs://Qmb48rJ5SiQMLXjVkaLQB6fWbT7C8LK75MHsCoHv8GAc15' ,
540
+ credentialSubject : {
541
+ 'positive-integer1' : {
542
+ $gt : '2'
543
+ }
544
+ } ,
545
+ groupId : 1745320529 ,
546
+ type : 'operators'
547
+ } ) ;
548
+ expect ( 1 ) . to . be . equal ( cred . length ) ;
549
+ expect ( cred [ 0 ] . credentialSubject [ 'positive-integer1' ] ) . to . be . equal ( '12345555' ) ;
550
+
551
+ //number
552
+
553
+ cred = await credentialStorage . findCredentialsByQuery ( {
554
+ allowedIssuers : [ '*' ] ,
555
+ context : 'ipfs://Qmb48rJ5SiQMLXjVkaLQB6fWbT7C8LK75MHsCoHv8GAc15' ,
556
+ credentialSubject : {
557
+ number1 : {
558
+ $gt : 1
559
+ }
560
+ } ,
561
+ groupId : 1745320529 ,
562
+ type : 'operators'
563
+ } ) ;
564
+ expect ( 1 ) . to . be . equal ( cred . length ) ;
565
+ expect ( cred [ 0 ] . credentialSubject [ 'number1' ] ) . to . be . equal ( 1234 ) ;
566
+
567
+ //boolean
568
+
569
+ cred = await credentialStorage . findCredentialsByQuery ( {
570
+ allowedIssuers : [ '*' ] ,
571
+ context : 'ipfs://Qmb48rJ5SiQMLXjVkaLQB6fWbT7C8LK75MHsCoHv8GAc15' ,
572
+ credentialSubject : {
573
+ boolean1 : {
574
+ $eq : true
575
+ }
576
+ } ,
577
+ groupId : 1745320529 ,
578
+ type : 'operators'
579
+ } ) ;
580
+ expect ( 1 ) . to . be . equal ( cred . length ) ;
581
+ expect ( cred [ 0 ] . credentialSubject [ 'boolean1' ] ) . to . be . equal ( true ) ;
582
+
583
+ //datetime lt
584
+
585
+ cred = await credentialStorage . findCredentialsByQuery ( {
586
+ allowedIssuers : [ '*' ] ,
587
+ context : 'ipfs://Qmb48rJ5SiQMLXjVkaLQB6fWbT7C8LK75MHsCoHv8GAc15' ,
588
+ credentialSubject : {
589
+ 'date-time1' : {
590
+ $lt : '2027-04-09T15:48:08.800+02:00'
591
+ }
592
+ } ,
593
+ groupId : 1745320529 ,
594
+ type : 'operators'
595
+ } ) ;
596
+ expect ( 1 ) . to . be . equal ( cred . length ) ;
597
+ expect ( cred [ 0 ] . credentialSubject [ 'date-time1' ] ) . to . be . equal ( '2025-04-09T15:48:08.800+02:00' ) ;
598
+
599
+ // datetime gt
600
+ cred = await credentialStorage . findCredentialsByQuery ( {
601
+ allowedIssuers : [ '*' ] ,
602
+ context : 'ipfs://Qmb48rJ5SiQMLXjVkaLQB6fWbT7C8LK75MHsCoHv8GAc15' ,
603
+ credentialSubject : {
604
+ 'date-time1' : {
605
+ $gt : '2022-04-09T15:48:08.800+02:00'
606
+ }
607
+ } ,
608
+ groupId : 1745320529 ,
609
+ type : 'operators'
610
+ } ) ;
611
+ expect ( 1 ) . to . be . equal ( cred . length ) ;
612
+ expect ( cred [ 0 ] . credentialSubject [ 'date-time1' ] ) . to . be . equal ( '2025-04-09T15:48:08.800+02:00' ) ;
613
+ } ) ;
467
614
} ) ;
0 commit comments