Skip to content

Commit 682f3ef

Browse files
authored
Merge pull request #85 from 0xPolygonID/feature/use-latest-jsonld-merklizer
Use latest JSON-LD merklizer
2 parents b9f582b + a267fd8 commit 682f3ef

21 files changed

+614
-740
lines changed

package-lock.json

+7-93
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.9",
3+
"version": "1.0.0-beta.10",
44
"description": "SDK to work with Polygon ID",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm_esbuild/index.js",
@@ -67,7 +67,7 @@
6767
"dependencies": {
6868
"@iden3/js-crypto": "1.0.0-beta.1",
6969
"@iden3/js-iden3-core": "1.0.0-beta.2",
70-
"@iden3/js-jsonld-merklization": "1.0.0-beta.8",
70+
"@iden3/js-jsonld-merklization": "1.0.0-beta.15",
7171
"@iden3/js-jwz": "1.0.0-beta.2",
7272
"@iden3/js-merkletree": "1.0.0-beta.4",
7373
"@lumeweb/js-sha3-browser": "^0.8.1",

src/circuits/common.ts

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export class BaseConfig {
6868
getMTLevelOnChain(): number {
6969
return this.mtLevelOnChain ? this.mtLevelOnChain : defaultMTLevelsOnChain;
7070
}
71-
7271
}
7372

7473
/**

src/circuits/models.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export enum CircuitId {
7070
// AtomicQuerySig is a type for credentialAttrQuerySig.circom
7171
AtomicQuerySigV2 = 'credentialAtomicQuerySigV2',
7272
// AtomicQuerySigOnChain is a type for credentialAtomicQuerySigOnChain.circom
73-
AtomicQuerySigV2OnChain = 'credentialAtomicQuerySigV2OnChain',
73+
AtomicQuerySigV2OnChain = 'credentialAtomicQuerySigV2OnChain'
7474
}
7575

7676
/**

src/credentials/status/on-chain-revocation.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ export class OnChainResolver implements CredentialStatusResolver {
2121
*/
2222
constructor(private readonly _configs: EthConnectionConfig[]) {}
2323

24-
async resolve(credentialStatus: CredentialStatus, opts: {
25-
issuer: DID;
26-
}): Promise<RevocationStatus> {
24+
async resolve(
25+
credentialStatus: CredentialStatus,
26+
opts: {
27+
issuer: DID;
28+
}
29+
): Promise<RevocationStatus> {
2730
return this.getRevocationOnChain(credentialStatus, opts.issuer);
2831
}
2932

@@ -34,10 +37,11 @@ export class OnChainResolver implements CredentialStatusResolver {
3437
* @param {DID} issuerDid - issuer did
3538
* @returns Promise<RevocationStatus>
3639
*/
37-
async getRevocationOnChain(credentialStatus: CredentialStatus, issuer: DID): Promise<RevocationStatus> {
38-
const { contractAddress, chainId, revocationNonce } = this.parseOnChainId(
39-
credentialStatus.id
40-
);
40+
async getRevocationOnChain(
41+
credentialStatus: CredentialStatus,
42+
issuer: DID
43+
): Promise<RevocationStatus> {
44+
const { contractAddress, chainId, revocationNonce } = this.parseOnChainId(credentialStatus.id);
4145
if (revocationNonce !== credentialStatus.revocationNonce) {
4246
throw new Error('revocationNonce does not match');
4347
}

src/iden3comm/handlers/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export class AuthHandler implements IAuthHandler {
250250
{
251251
authProfileNonce: authProfileNonce,
252252
credentialSubjectProfileNonce: r.credentialSubjectProfileNonce,
253-
skipRevocation: false,
253+
skipRevocation: false
254254
}
255255
);
256256

src/identity/identity-wallet.ts

+34-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { JSONSchema, Parser, CoreClaimOptions } from '../schema-processor';
2121
import { IDataStorage } from '../storage/interfaces/data-storage';
2222
import { MerkleTreeType } from '../storage/entities/mt';
2323
import { getRandomBytes, keyPath } from '../kms/provider-helpers';
24-
import { UniversalSchemaLoader } from '../loaders';
2524
import {
2625
VerifiableConstants,
2726
BJJSignatureProof2021,
@@ -37,7 +36,8 @@ import {
3736
import { CredentialRequest, ICredentialWallet } from '../credentials';
3837
import { pushHashesToRHS, TreesModel } from '../credentials/rhs';
3938
import { TreeState } from '../circuits';
40-
import { byteDecoder } from '../utils';
39+
import { byteEncoder } from '../utils';
40+
import { Options, Path, getDocumentLoader } from '@iden3/js-jsonld-merklization';
4141

4242
/**
4343
* DID creation options
@@ -539,13 +539,22 @@ export class IdentityWallet implements IIdentityWallet {
539539
}
540540

541541
/** {@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> {
543547
req.revocationOpts.id = req.revocationOpts.id.replace(/\/$/, '');
544548

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+
}
548556

557+
const jsonSchema = schema as JSONSchema;
549558
let credential: W3CCredential = new W3CCredential();
550559

551560
req.revocationOpts.nonce =
@@ -568,13 +577,29 @@ export class IdentityWallet implements IIdentityWallet {
568577
subjectPosition: req.subjectPosition,
569578
merklizedRootPosition: this.defineMTRootPosition(jsonSchema, req.merklizedRootPosition),
570579
updatable: false,
571-
version: 0
580+
version: 0,
581+
merklizeOpts: opts
572582
};
573583

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+
574599
const coreClaim = await new Parser().parseClaim(
575600
credential,
576-
`${jsonSchema.$metadata.uris['jsonLdContext']}#${req.type}`,
577-
schema,
601+
credentialType,
602+
schemaBytes,
578603
coreClaimOpts
579604
);
580605

src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ export * from './loaders';
1111
export * from './iden3comm/handlers';
1212
export * from './utils';
1313
import * as core from '@iden3/js-iden3-core';
14+
import * as jsonLDMerklizer from '@iden3/js-jsonld-merklization';
1415
export { core };
16+
export { jsonLDMerklizer };

src/loaders/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
export * from './key';
2-
export * from './schema';

0 commit comments

Comments
 (0)