Skip to content

Commit 0cc8826

Browse files
authored
Fix query filter to work with 0. Adjusted type CredentialIssuanceRequestMessage (#55)
* Fix query filter to work with 0. Adjusted type CredentialIssuanceRequestMessage * Patch version * Remove console.log. Increase test timeout in ci
1 parent a841f61 commit 0cc8826

File tree

6 files changed

+80
-17
lines changed

6 files changed

+80
-17
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@0xpolygonid/js-sdk",
3-
"version": "1.0.0-beta.3",
3+
"version": "1.0.0-beta.4",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
@@ -22,7 +22,7 @@
2222
"doc:build": "npm run doc:extract && npm run doc:documenter",
2323
"doc:watch:website": "ts-node ./scripts/doc-watch.ts",
2424
"tsc:declaration:watch": "tsc --watch --module commonjs --emitDeclarationOnly",
25-
"test": "mocha --require ts-node/register tests/**/*.ts -t 30000",
25+
"test": "mocha --require ts-node/register tests/**/*.ts -t 60000",
2626
"test:watch": "mocha -p --require ts-node/register tests/**/*.ts -t 60000 --watch",
2727
"lint": "eslint --fix --ext .js,.ts src/**",
2828
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",

src/iden3comm/types/protocol/credentials.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import { JSONObject } from '../index';
33
import { W3CCredential } from '../../../verifiable';
44
import { MediaType } from '../../constants';
55

6+
/** CredentialIssuanceRequestMessageBody represents data for credential issuance request */
7+
export type CredentialIssuanceRequestMessageBody = {
8+
schema: Schema;
9+
data: JSONObject;
10+
expiration: number;
11+
};
12+
613
/** CredentialIssuanceRequestMessage represent Iden3message for credential request */
714
export type CredentialIssuanceRequestMessage = {
815
id: string;
916
typ?: MediaType;
1017
type: ProtocolMessage;
1118
thid?: string;
12-
body?: CredentialIssuanceRequestMessage;
19+
body?: CredentialIssuanceRequestMessageBody;
1320
from?: string;
1421
to?: string;
1522
};
1623

17-
/** CredentialIssuanceRequestMessageBody represents data for credential issuance request */
18-
export type CredentialIssuanceRequestMessageBody = {
19-
schema: Schema;
20-
data: JSONObject;
21-
expiration: number;
22-
};
23-
2424
/** CredentialsOfferMessage represent Iden3message for credential offer */
2525
export type CredentialsOfferMessage = {
2626
id: string;

src/storage/filters/jsonQuery.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class FilterQuery implements IFilterQuery {
109109
throw new Error(SearchError.NotDefinedComparator);
110110
}
111111
const credentialPathValue = resolvePath(credential, this.path);
112-
if (!credentialPathValue) {
112+
if (credentialPathValue === null || credentialPathValue === undefined) {
113113
return false;
114114
}
115115
if (this.isReverseParams) {

tests/credentials/credential-wallet.test.ts

+49-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CredentialStorage } from './../../src/storage/shared/credential-storage
33
import { IDataStorage } from './../../src/storage/interfaces/data-storage';
44
import { CredentialWallet } from '../../src/credentials';
55
import { SearchError } from '../../src/storage/filters/jsonQuery';
6-
import { cred1, cred2, cred3 } from './mock';
6+
import { cred1, cred2, cred3, cred4 } from './mock';
77
import { ProofQuery, W3CCredential } from '../../src/verifiable';
88
import { BrowserDataSource } from '../../src/storage/local-storage/data-source';
99
import chaiAsPromised from 'chai-as-promised';
@@ -45,8 +45,9 @@ const credentialFlow = async (storage: IDataStorage) => {
4545
expect(credentials.length).to.equal(2);
4646

4747
await credentialWallet.save(cred3);
48+
await credentialWallet.save(cred4);
4849
const credentialAll = await credentialWallet.list();
49-
expect(credentialAll.length).to.equal(3);
50+
expect(credentialAll.length).to.equal(4);
5051

5152
// present id
5253
const credById = await credentialWallet.findById(cred2.id);
@@ -143,6 +144,50 @@ const credentialFlow = async (storage: IDataStorage) => {
143144
}
144145
},
145146
expected: [cred3]
147+
},
148+
{
149+
query: {
150+
allowedIssuers: ['*'],
151+
credentialSubject: {
152+
countOfFines: {
153+
$nin: [1, 2]
154+
}
155+
}
156+
},
157+
expected: [cred4]
158+
},
159+
{
160+
query: {
161+
allowedIssuers: ['*'],
162+
credentialSubject: {
163+
countOfFines: {
164+
$in: [0]
165+
}
166+
}
167+
},
168+
expected: [cred4]
169+
},
170+
{
171+
query: {
172+
allowedIssuers: ['*'],
173+
credentialSubject: {
174+
countOfFines: {
175+
$eq: 0
176+
}
177+
}
178+
},
179+
expected: [cred4]
180+
},
181+
{
182+
query: {
183+
allowedIssuers: ['*'],
184+
credentialSubject: {
185+
countOfFines: {
186+
$eq: 1
187+
}
188+
}
189+
},
190+
expected: []
146191
}
147192
];
148193

@@ -182,7 +227,7 @@ const credentialFlow = async (storage: IDataStorage) => {
182227

183228
await credentialWallet.remove('test1');
184229
const finalList = await credentialWallet.list();
185-
expect(finalList.length).to.equal(2);
230+
expect(finalList.length).to.equal(3);
186231
};
187232

188233
describe('credential-wallet', () => {
@@ -192,7 +237,7 @@ describe('credential-wallet', () => {
192237
} as unknown as IDataStorage;
193238
await credentialFlow(storage);
194239
});
195-
it('run in local storage with 3 credential', async () => {
240+
it('run in local storage with 4 credential', async () => {
196241
const storage = {
197242
credential: new CredentialStorage(
198243
new BrowserDataSource<W3CCredential>(CredentialStorage.storageKey)

tests/credentials/mock.ts

+18
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,21 @@ export const cred3 = createTestCredential({
5959
expirationDate: '2023-11-11',
6060
issuanceDate: '2022-11-11'
6161
});
62+
63+
export const cred4 = createTestCredential({
64+
id: 'test4',
65+
'@context': ['context4'],
66+
credentialSchema: {
67+
id: 'credentialSchemaId',
68+
type: 'credentialSchemaType'
69+
},
70+
proof: ['some proof4'],
71+
type: ['type4'],
72+
credentialStatus: {},
73+
issuer: 'issuer4',
74+
credentialSubject: {
75+
countOfFines: 0
76+
},
77+
expirationDate: '2023-11-11',
78+
issuanceDate: '2022-11-11'
79+
});

0 commit comments

Comments
 (0)