Skip to content

Commit 5aed955

Browse files
Merge branch 'main' into feat/problem-report
2 parents d8ecb6e + 5864fc1 commit 5aed955

17 files changed

+351
-105
lines changed

package-lock.json

+6-6
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.28.0",
3+
"version": "1.28.1",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/node/cjs/index.js",
66
"module": "dist/node/esm/index.js",
@@ -90,7 +90,7 @@
9090
"peerDependencies": {
9191
"@iden3/js-crypto": "1.2.0",
9292
"@iden3/js-iden3-core": "1.6.0",
93-
"@iden3/js-jsonld-merklization": "1.5.0",
93+
"@iden3/js-jsonld-merklization": "1.5.2",
9494
"@iden3/js-jwz": "1.9.0",
9595
"@iden3/js-merkletree": "1.4.0",
9696
"ffjavascript": "0.3.0",

src/schema-processor/jsonld/cache.ts

+19
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,32 @@ import { VerifiableConstants } from '../../verifiable';
1010
*/
1111

1212
const doc = JSON.parse(VerifiableConstants.JSONLD_SCHEMA.W3C_VC_DOCUMENT_2018);
13+
const docIden3Proofs = JSON.parse(
14+
VerifiableConstants.JSONLD_SCHEMA.IDEN3_PROOFS_DEFINITION_DOCUMENT
15+
);
16+
const docIden3DisplayMethod = JSON.parse(
17+
VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD_DEFINITION_DOCUMENT
18+
);
19+
const docIden3AuthBJJ = JSON.parse(VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD);
1320

1421
export const cacheLoader = (opts?: Options): DocumentLoader => {
1522
const cache = new Map<string, RemoteDocument>();
1623
cache.set(VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018, {
1724
document: doc,
1825
documentUrl: VerifiableConstants.JSONLD_SCHEMA.W3C_CREDENTIAL_2018
1926
});
27+
cache.set(VerifiableConstants.JSONLD_SCHEMA.IDEN3_CREDENTIAL, {
28+
document: docIden3Proofs,
29+
documentUrl: VerifiableConstants.JSONLD_SCHEMA.IDEN3_PROOFS_DEFINITION_DOCUMENT
30+
});
31+
cache.set(VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD, {
32+
document: docIden3DisplayMethod,
33+
documentUrl: VerifiableConstants.JSONLD_SCHEMA.IDEN3_DISPLAY_METHOD_DEFINITION_DOCUMENT
34+
});
35+
cache.set(VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD_URL, {
36+
document: docIden3AuthBJJ,
37+
documentUrl: VerifiableConstants.AUTH.AUTH_BJJ_CREDENTIAL_SCHEMA_JSONLD
38+
});
2039

2140
return async (url: Url): Promise<RemoteDocument> => {
2241
let remoteDoc = cache.get(url);

src/verifiable/constants.ts

+5-2
Large diffs are not rendered by default.

tests/adapter/onchain-issuer.test.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { DID } from '@iden3/js-iden3-core';
44
import { W3CCredential } from '../../src/verifiable';
55
import { expect } from 'chai';
66
import { defaultEthConnectionConfig } from '../../src';
7+
import { schemaLoaderForTests } from '../mocks/schema';
78

89
// prettier-ignore
910
const balanceCredentialHttpSchema =
10-
{"id":"urn:iden3:onchain:80002:0x19875eA86503734f2f9Ed461463e0312A3b42563:6","@context":["https://www.w3.org/2018/credentials/v1","https://schema.iden3.io/core/jsonld/iden3proofs.jsonld","https://gist.githubusercontent.com/ilya-korotya/660496c859f8d31a7d2a92ca5e970967/raw/6b5fc14fe630c17bfa52e05e08fdc8394c5ea0ce/non-merklized-non-zero-balance.jsonld","https://schema.iden3.io/core/jsonld/displayMethod.jsonld"],"type":["VerifiableCredential","Balance"],"expirationDate":"2024-05-24T10:29:56.000Z","issuanceDate":"2024-04-24T10:29:56.000Z","credentialSubject":{"address":"955350806412517903000132372584919937355495621189","balance":"439010757238782730","id":"did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ","type":"Balance"},"credentialStatus":{"id":"did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ/credentialStatus?revocationNonce=6\u0026contractAddress=80002:0x19875eA86503734f2f9Ed461463e0312A3b42563","type":"Iden3OnchainSparseMerkleTreeProof2023","revocationNonce":6},"issuer":"did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ","credentialSchema":{"id":"https://gist.githubusercontent.com/ilya-korotya/e10cd79a8cc26ab6e40400a11838617e/raw/575edc33d485e2a4c806baad97e21117f3c90a9f/non-merklized-non-zero-balance.json","type":"JsonSchema2023"},"proof":[{"type":"Iden3SparseMerkleTreeProof","issuerData":{"id":"did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ","state":{"rootOfRoots":"4078a4330d42e9d112b61500e538dc229cce10e2ffc50861c26c115b263c3214","claimsTreeRoot":"b087bb8fe253f1b04f8357f0844796bbec597e4def7fd76a19814d8159dcbb05","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000","value":"006143913300b027d1d70878468aa0530dfea5a042f8325a826d409df7911512"}},"coreClaim":"f52f1795c533d7b4aa4e7ab02485f86f0a00000000000000000000000000000002130000000000000019875ea86503734f2f9ed461463e0312a3b425635f070045c28dba443bdace6830060f2d2784fa696957a70000000000000000000000000afbca2df5ad17060000000000000000000000000000000000000000000000000600000000000000246c50660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","mtp":{"existence":true,"siblings":["13848368485573735212679136988282305230819438728637424764846468785502433652840","1096649694805431452149042575143897926182559273612207814941177729902834445226","12160962874465332870109484495496045222172553451373175361415786953298859195139","3819622883660148852432672044432820232715025265850740602622985339171079887367","14062102965326789511040283612678585475708167692394425899926219149423935791693","8688920842723779052034352461580251823545042582416894537724528294186594808930","19295275136572781615245322801038686629126714006877213606851647038393713692426"]}}],"displayMethod":{"id":"ipfs://QmS8eY8ZCiAAW8qgx3T6SQ3HDGeddwLZsjPXNAZExQwRY4","type":"Iden3BasicDisplayMethodV1"}};
11+
{ "id": "urn:iden3:onchain:80002:0x19875eA86503734f2f9Ed461463e0312A3b42563:6", "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld", "https://gist.githubusercontent.com/ilya-korotya/660496c859f8d31a7d2a92ca5e970967/raw/6b5fc14fe630c17bfa52e05e08fdc8394c5ea0ce/non-merklized-non-zero-balance.jsonld", "https://schema.iden3.io/core/jsonld/displayMethod.jsonld"], "type": ["VerifiableCredential", "Balance"], "expirationDate": "2024-05-24T10:29:56.000Z", "issuanceDate": "2024-04-24T10:29:56.000Z", "credentialSubject": { "address": "955350806412517903000132372584919937355495621189", "balance": "439010757238782730", "id": "did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ", "type": "Balance" }, "credentialStatus": { "id": "did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ/credentialStatus?revocationNonce=6\u0026contractAddress=80002:0x19875eA86503734f2f9Ed461463e0312A3b42563", "type": "Iden3OnchainSparseMerkleTreeProof2023", "revocationNonce": 6 }, "issuer": "did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ", "credentialSchema": { "id": "https://gist.githubusercontent.com/ilya-korotya/e10cd79a8cc26ab6e40400a11838617e/raw/575edc33d485e2a4c806baad97e21117f3c90a9f/non-merklized-non-zero-balance.json", "type": "JsonSchema2023" }, "proof": [{ "type": "Iden3SparseMerkleTreeProof", "issuerData": { "id": "did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ", "state": { "rootOfRoots": "4078a4330d42e9d112b61500e538dc229cce10e2ffc50861c26c115b263c3214", "claimsTreeRoot": "b087bb8fe253f1b04f8357f0844796bbec597e4def7fd76a19814d8159dcbb05", "revocationTreeRoot": "0000000000000000000000000000000000000000000000000000000000000000", "value": "006143913300b027d1d70878468aa0530dfea5a042f8325a826d409df7911512" } }, "coreClaim": "f52f1795c533d7b4aa4e7ab02485f86f0a00000000000000000000000000000002130000000000000019875ea86503734f2f9ed461463e0312a3b425635f070045c28dba443bdace6830060f2d2784fa696957a70000000000000000000000000afbca2df5ad17060000000000000000000000000000000000000000000000000600000000000000246c50660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "mtp": { "existence": true, "siblings": ["13848368485573735212679136988282305230819438728637424764846468785502433652840", "1096649694805431452149042575143897926182559273612207814941177729902834445226", "12160962874465332870109484495496045222172553451373175361415786953298859195139", "3819622883660148852432672044432820232715025265850740602622985339171079887367", "14062102965326789511040283612678585475708167692394425899926219149423935791693", "8688920842723779052034352461580251823545042582416894537724528294186594808930", "19295275136572781615245322801038686629126714006877213606851647038393713692426"] } }], "displayMethod": { "id": "ipfs://QmS8eY8ZCiAAW8qgx3T6SQ3HDGeddwLZsjPXNAZExQwRY4", "type": "Iden3BasicDisplayMethodV1" } };
1112
// prettier-ignore
1213
const balanceCredentialIpfsSchema =
13-
{"id":"urn:iden3:onchain:80002:0xFDb204CCC55794C861366dBc2Cd6BBBd25752894:0","@context":["https://www.w3.org/2018/credentials/v1","https://schema.iden3.io/core/jsonld/iden3proofs.jsonld","ipfs://Qma5B4jNwiHtRd5RXGoRncV79EZvB7LsfpHgv8Vi4xitV1","https://schema.iden3.io/core/jsonld/displayMethod.jsonld"],"type":["VerifiableCredential","Balance"],"expirationDate":"2024-05-24T16:23:56.000Z","issuanceDate":"2024-04-24T16:23:56.000Z","credentialSubject":{"address":"657065114158124047812701241180089030040156354062","balance":"34206141476401658683","id":"did:polygonid:polygon:amoy:2qZYiH9CFMoo6oTjSEot3qzkHFHhjLRLKp8yfwCYng","type":"Balance"},"credentialStatus":{"id":"did:polygonid:polygon:amoy:2qQ68JkRcf3z3923i5rrszrsJ4kdu4GKWARQ5eftsB/credentialStatus?revocationNonce=0\u0026contractAddress=80002:0xFDb204CCC55794C861366dBc2Cd6BBBd25752894","type":"Iden3OnchainSparseMerkleTreeProof2023","revocationNonce":0},"issuer":"did:polygonid:polygon:amoy:2qQ68JkRcf3z3923i5rrszrsJ4kdu4GKWARQ5eftsB","credentialSchema":{"id":"ipfs://QmcC7i1PCU8ymJscGjs8pqmZEWtBGWPFLmQ8s7P6QzELN6","type":"JsonSchema2023"},"proof":[{"type":"Iden3SparseMerkleTreeProof","issuerData":{"id":"did:polygonid:polygon:amoy:2qQ68JkRcf3z3923i5rrszrsJ4kdu4GKWARQ5eftsB","state":{"rootOfRoots":"ae476a5ee415f804663e9449c285e49e5cf239d1d2b95e77bf84543974acc113","claimsTreeRoot":"87df6035bab67e067892307e74c55c7c1a324e4b69a9390ee734c20ccac1fb18","revocationTreeRoot":"0000000000000000000000000000000000000000000000000000000000000000","value":"32a269e965d1486d20749ef071e1a03713703487edee224a7768ee1394288f11"}},"coreClaim":"f52f1795c533d7b4aa4e7ab02485f86f0a0000000000000000000000000000000213d0591345a3d71ee61cd299b38959df8dea1f4a4f75a2bd4f25b8215f0d000eb6cb518d3dd33341899bcec9dcc68998d117730000000000000000000000003b3baddd70a0b4da01000000000000000000000000000000000000000000000000000000000000001cbf50660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","mtp":{"existence":true,"siblings":["0","11379033735565694648078358700935740809038384149401106458334374311488117433921"]}}],"displayMethod":{"id":"ipfs://QmS8eY8ZCiAAW8qgx3T6SQ3HDGeddwLZsjPXNAZExQwRY4","type":"Iden3BasicDisplayMethodV1"}};
14+
{ "id": "urn:iden3:onchain:80002:0xFDb204CCC55794C861366dBc2Cd6BBBd25752894:0", "@context": ["https://www.w3.org/2018/credentials/v1", "https://schema.iden3.io/core/jsonld/iden3proofs.jsonld", "ipfs://Qma5B4jNwiHtRd5RXGoRncV79EZvB7LsfpHgv8Vi4xitV1", "https://schema.iden3.io/core/jsonld/displayMethod.jsonld"], "type": ["VerifiableCredential", "Balance"], "expirationDate": "2024-05-24T16:23:56.000Z", "issuanceDate": "2024-04-24T16:23:56.000Z", "credentialSubject": { "address": "657065114158124047812701241180089030040156354062", "balance": "34206141476401658683", "id": "did:polygonid:polygon:amoy:2qZYiH9CFMoo6oTjSEot3qzkHFHhjLRLKp8yfwCYng", "type": "Balance" }, "credentialStatus": { "id": "did:polygonid:polygon:amoy:2qQ68JkRcf3z3923i5rrszrsJ4kdu4GKWARQ5eftsB/credentialStatus?revocationNonce=0\u0026contractAddress=80002:0xFDb204CCC55794C861366dBc2Cd6BBBd25752894", "type": "Iden3OnchainSparseMerkleTreeProof2023", "revocationNonce": 0 }, "issuer": "did:polygonid:polygon:amoy:2qQ68JkRcf3z3923i5rrszrsJ4kdu4GKWARQ5eftsB", "credentialSchema": { "id": "ipfs://QmcC7i1PCU8ymJscGjs8pqmZEWtBGWPFLmQ8s7P6QzELN6", "type": "JsonSchema2023" }, "proof": [{ "type": "Iden3SparseMerkleTreeProof", "issuerData": { "id": "did:polygonid:polygon:amoy:2qQ68JkRcf3z3923i5rrszrsJ4kdu4GKWARQ5eftsB", "state": { "rootOfRoots": "ae476a5ee415f804663e9449c285e49e5cf239d1d2b95e77bf84543974acc113", "claimsTreeRoot": "87df6035bab67e067892307e74c55c7c1a324e4b69a9390ee734c20ccac1fb18", "revocationTreeRoot": "0000000000000000000000000000000000000000000000000000000000000000", "value": "32a269e965d1486d20749ef071e1a03713703487edee224a7768ee1394288f11" } }, "coreClaim": "f52f1795c533d7b4aa4e7ab02485f86f0a0000000000000000000000000000000213d0591345a3d71ee61cd299b38959df8dea1f4a4f75a2bd4f25b8215f0d000eb6cb518d3dd33341899bcec9dcc68998d117730000000000000000000000003b3baddd70a0b4da01000000000000000000000000000000000000000000000000000000000000001cbf50660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "mtp": { "existence": true, "siblings": ["0", "11379033735565694648078358700935740809038384149401106458334374311488117433921"] } }], "displayMethod": { "id": "ipfs://QmS8eY8ZCiAAW8qgx3T6SQ3HDGeddwLZsjPXNAZExQwRY4", "type": "Iden3BasicDisplayMethodV1" } };
1415

1516
describe('OnchainIssuer', () => {
1617
const copyDefaultEthConnectionConfig = { ...defaultEthConnectionConfig };
@@ -24,7 +25,9 @@ describe('OnchainIssuer', () => {
2425
const userDid = DID.parse(
2526
'did:polygonid:polygon:amoy:2qQ68JkRcf3xyDFsGSWU5QqxbKpzM75quxS628JgvJ'
2627
);
27-
const adapter = new OnchainIssuer([copyDefaultEthConnectionConfig]);
28+
const adapter = new OnchainIssuer([copyDefaultEthConnectionConfig], {
29+
merklizationOptions: { documentLoader: schemaLoaderForTests() }
30+
});
2831
const cred = await adapter.getCredential(issuerDid, userDid, BigInt(6));
2932
expect(W3CCredential.fromJSON(balanceCredentialHttpSchema)).to.deep.equal(cred);
3033
});
@@ -38,7 +41,7 @@ describe('OnchainIssuer', () => {
3841
);
3942
const adapter = new OnchainIssuer([copyDefaultEthConnectionConfig], {
4043
merklizationOptions: {
41-
ipfsNodeURL: IPFS_URL
44+
documentLoader: schemaLoaderForTests({ ipfsNodeURL: IPFS_URL })
4245
}
4346
});
4447
const cred = await adapter.getCredential(issuerDid, userId, BigInt(0));

tests/adapter/onchain-non-merklized-issuer-adapter.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { expect } from 'chai';
1010
import { W3CCredential } from '../../src/verifiable';
1111
import { IPFS_URL } from '../helpers';
1212
import { defaultEthConnectionConfig } from '../../src';
13+
import { schemaLoaderForTests } from '../mocks/schema';
1314

1415
// prettier-ignore
1516
const w3cHttpSchemaExpect =
@@ -160,7 +161,7 @@ describe('Convertor v0.0.1', () => {
160161
issuerDid,
161162
{
162163
merklizationOptions: {
163-
ipfsNodeURL: IPFS_URL
164+
documentLoader: schemaLoaderForTests({ ipfsNodeURL: IPFS_URL })
164165
}
165166
}
166167
);

tests/credentials/credential-statuses/on-chain-revocation.test.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import path from 'path';
4141
import spies from 'chai-spies';
4242
import { JsonRpcProvider, Wallet } from 'ethers';
4343
import { getRandomBytes } from '@iden3/js-crypto';
44+
import { schemaLoaderForTests } from '../../mocks/schema';
4445
chai.use(spies);
4546
const expect = chai.expect;
4647

@@ -164,6 +165,7 @@ describe('onchain revocation checks', () => {
164165
let storage: OnChainRevocationStorage;
165166
let signer: Wallet;
166167
let onchainResolver: OnChainResolver;
168+
let merklizeOpts;
167169

168170
const createCredRequest = (
169171
credentialSubjectId: string,
@@ -241,7 +243,12 @@ describe('onchain revocation checks', () => {
241243
idWallet = new IdentityWallet(registerKeyProvidersInMemoryKMS(), dataStorage, credWallet, {
242244
credentialStatusPublisherRegistry
243245
});
244-
proofService = new ProofService(idWallet, credWallet, circuitStorage, ethStorage);
246+
247+
merklizeOpts = {
248+
documentLoader: schemaLoaderForTests()
249+
};
250+
251+
proofService = new ProofService(idWallet, credWallet, circuitStorage, ethStorage, merklizeOpts);
245252
});
246253

247254
it('issuer has genesis state', async () => {
@@ -264,7 +271,7 @@ describe('onchain revocation checks', () => {
264271

265272
const claimReq: CredentialRequest = createCredRequest(userDID.string());
266273

267-
const issuerCred = await idWallet.issueCredential(issuerDID, claimReq);
274+
const issuerCred = await idWallet.issueCredential(issuerDID, claimReq, merklizeOpts);
268275

269276
await credWallet.save(issuerCred);
270277

@@ -363,7 +370,11 @@ describe('onchain revocation checks', () => {
363370
}
364371
});
365372

366-
const issuerCred = await idWallet.issueCredential(issuerDID, claimReq);
373+
const issuerCred = await idWallet.issueCredential(
374+
issuerDID,
375+
claimReq,
376+
merklizeOpts
377+
);
367378

368379
expect(issuerCred.credentialSubject.id).to.equal(userDID.string());
369380

tests/credentials/credential-statuses/sparse-merkle-tree-proof.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
registerKeyProvidersInMemoryKMS
1212
} from '../../helpers';
1313
import { DID } from '@iden3/js-iden3-core';
14+
import { schemaLoaderForTests } from '../../mocks/schema';
1415

1516
describe('SparseMerkleTreeProof', () => {
1617
let idWallet: IdentityWallet;
@@ -22,6 +23,9 @@ describe('SparseMerkleTreeProof', () => {
2223
let issuerDID: DID;
2324
const walletUrl = 'https://user-wallet.com';
2425
const issuerWalletUrl = 'https://issuer.com';
26+
const merklizeOpts = {
27+
documentLoader: schemaLoaderForTests()
28+
};
2529

2630
beforeEach(async () => {
2731
const kms = registerKeyProvidersInMemoryKMS();
@@ -67,7 +71,7 @@ describe('SparseMerkleTreeProof', () => {
6771
id: walletUrl
6872
}
6973
};
70-
const issuedCredential = await idWallet.issueCredential(issuerDID, credRequest);
74+
const issuedCredential = await idWallet.issueCredential(issuerDID, credRequest, merklizeOpts);
7175

7276
await credWallet.save(issuedCredential);
7377

0 commit comments

Comments
 (0)