Skip to content

Commit

Permalink
Use latest JSON-LD merklizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Jun 27, 2023
1 parent b9f582b commit 36457da
Show file tree
Hide file tree
Showing 18 changed files with 594 additions and 634 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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.13",
"@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
48 changes: 40 additions & 8 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,12 @@ 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 as MerklizerOptions,
Path,
getDocumentLoader
} from '@iden3/js-jsonld-merklization';

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

/** {@inheritDoc IIdentityWallet.issueCredential} */
async issueCredential(issuerDID: DID, req: CredentialRequest): Promise<W3CCredential> {
async issueCredential(
issuerDID: DID,
req: CredentialRequest,
opts?: MerklizerOptions
): 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 =
opts?.documentLoader ??
getDocumentLoader({
ipfsNodeURL: 'ipfs.io'
});
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 @@ -571,10 +588,25 @@ export class IdentityWallet implements IIdentityWallet {
version: 0
};

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';
122 changes: 0 additions & 122 deletions src/loaders/schema.ts

This file was deleted.

Loading

0 comments on commit 36457da

Please sign in to comment.