Skip to content

Commit

Permalink
Merge pull request #85 from 0xPolygonID/feature/use-latest-jsonld-mer…
Browse files Browse the repository at this point in the history
…klizer

Use latest JSON-LD merklizer
  • Loading branch information
vmidyllic authored Jun 29, 2023
2 parents b9f582b + a267fd8 commit 682f3ef
Show file tree
Hide file tree
Showing 21 changed files with 614 additions and 740 deletions.
100 changes: 7 additions & 93 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xpolygonid/js-sdk",
"version": "1.0.0-beta.9",
"version": "1.0.0-beta.10",
"description": "SDK to work with Polygon ID",
"main": "dist/cjs/index.js",
"module": "dist/esm_esbuild/index.js",
Expand Down Expand Up @@ -67,7 +67,7 @@
"dependencies": {
"@iden3/js-crypto": "1.0.0-beta.1",
"@iden3/js-iden3-core": "1.0.0-beta.2",
"@iden3/js-jsonld-merklization": "1.0.0-beta.8",
"@iden3/js-jsonld-merklization": "1.0.0-beta.15",
"@iden3/js-jwz": "1.0.0-beta.2",
"@iden3/js-merkletree": "1.0.0-beta.4",
"@lumeweb/js-sha3-browser": "^0.8.1",
Expand Down
1 change: 0 additions & 1 deletion src/circuits/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export class BaseConfig {
getMTLevelOnChain(): number {
return this.mtLevelOnChain ? this.mtLevelOnChain : defaultMTLevelsOnChain;
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/circuits/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export enum CircuitId {
// AtomicQuerySig is a type for credentialAttrQuerySig.circom
AtomicQuerySigV2 = 'credentialAtomicQuerySigV2',
// AtomicQuerySigOnChain is a type for credentialAtomicQuerySigOnChain.circom
AtomicQuerySigV2OnChain = 'credentialAtomicQuerySigV2OnChain',
AtomicQuerySigV2OnChain = 'credentialAtomicQuerySigV2OnChain'
}

/**
Expand Down
18 changes: 11 additions & 7 deletions src/credentials/status/on-chain-revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ export class OnChainResolver implements CredentialStatusResolver {
*/
constructor(private readonly _configs: EthConnectionConfig[]) {}

async resolve(credentialStatus: CredentialStatus, opts: {
issuer: DID;
}): Promise<RevocationStatus> {
async resolve(
credentialStatus: CredentialStatus,
opts: {
issuer: DID;
}
): Promise<RevocationStatus> {
return this.getRevocationOnChain(credentialStatus, opts.issuer);
}

Expand All @@ -34,10 +37,11 @@ export class OnChainResolver implements CredentialStatusResolver {
* @param {DID} issuerDid - issuer did
* @returns Promise<RevocationStatus>
*/
async getRevocationOnChain(credentialStatus: CredentialStatus, issuer: DID): Promise<RevocationStatus> {
const { contractAddress, chainId, revocationNonce } = this.parseOnChainId(
credentialStatus.id
);
async getRevocationOnChain(
credentialStatus: CredentialStatus,
issuer: DID
): Promise<RevocationStatus> {
const { contractAddress, chainId, revocationNonce } = this.parseOnChainId(credentialStatus.id);
if (revocationNonce !== credentialStatus.revocationNonce) {
throw new Error('revocationNonce does not match');
}
Expand Down
2 changes: 1 addition & 1 deletion src/iden3comm/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export class AuthHandler implements IAuthHandler {
{
authProfileNonce: authProfileNonce,
credentialSubjectProfileNonce: r.credentialSubjectProfileNonce,
skipRevocation: false,
skipRevocation: false
}
);

Expand Down
43 changes: 34 additions & 9 deletions src/identity/identity-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { JSONSchema, Parser, CoreClaimOptions } from '../schema-processor';
import { IDataStorage } from '../storage/interfaces/data-storage';
import { MerkleTreeType } from '../storage/entities/mt';
import { getRandomBytes, keyPath } from '../kms/provider-helpers';
import { UniversalSchemaLoader } from '../loaders';
import {
VerifiableConstants,
BJJSignatureProof2021,
Expand All @@ -37,7 +36,8 @@ import {
import { CredentialRequest, ICredentialWallet } from '../credentials';
import { pushHashesToRHS, TreesModel } from '../credentials/rhs';
import { TreeState } from '../circuits';
import { byteDecoder } from '../utils';
import { byteEncoder } from '../utils';
import { Options, Path, getDocumentLoader } from '@iden3/js-jsonld-merklization';

/**
* DID creation options
Expand Down Expand Up @@ -539,13 +539,22 @@ export class IdentityWallet implements IIdentityWallet {
}

/** {@inheritDoc IIdentityWallet.issueCredential} */
async issueCredential(issuerDID: DID, req: CredentialRequest): Promise<W3CCredential> {
async issueCredential(
issuerDID: DID,
req: CredentialRequest,
opts?: Options
): Promise<W3CCredential> {
req.revocationOpts.id = req.revocationOpts.id.replace(/\/$/, '');

const schema = await new UniversalSchemaLoader('ipfs.io').load(req.credentialSchema);

const jsonSchema: JSONSchema = JSON.parse(byteDecoder.decode(schema));
let schema: object;
const loader = getDocumentLoader(opts);
try {
schema = (await loader(req.credentialSchema)).document;
} catch (e) {
throw new Error(`can't load credential schema ${req.credentialSchema}`);
}

const jsonSchema = schema as JSONSchema;
let credential: W3CCredential = new W3CCredential();

req.revocationOpts.nonce =
Expand All @@ -568,13 +577,29 @@ export class IdentityWallet implements IIdentityWallet {
subjectPosition: req.subjectPosition,
merklizedRootPosition: this.defineMTRootPosition(jsonSchema, req.merklizedRootPosition),
updatable: false,
version: 0
version: 0,
merklizeOpts: opts
};

let jsonLDCtx: object;
try {
jsonLDCtx = (await loader(jsonSchema.$metadata.uris.jsonLdContext)).document;
} catch (e) {
throw new Error(`can't load json-ld schema ${jsonSchema.$metadata.uris.jsonLdContext}`);
}

const schemaBytes = byteEncoder.encode(JSON.stringify(jsonSchema));

const credentialType = await Path.getTypeIDFromContext(
JSON.stringify(jsonLDCtx),
req.type,
opts
);

const coreClaim = await new Parser().parseClaim(
credential,
`${jsonSchema.$metadata.uris['jsonLdContext']}#${req.type}`,
schema,
credentialType,
schemaBytes,
coreClaimOpts
);

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ export * from './loaders';
export * from './iden3comm/handlers';
export * from './utils';
import * as core from '@iden3/js-iden3-core';
import * as jsonLDMerklizer from '@iden3/js-jsonld-merklization';
export { core };
export { jsonLDMerklizer };
1 change: 0 additions & 1 deletion src/loaders/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './key';
export * from './schema';
Loading

0 comments on commit 682f3ef

Please sign in to comment.