Skip to content

Commit

Permalink
add MerklizeOptions to prover setup
Browse files Browse the repository at this point in the history
  • Loading branch information
vmidyllic committed Jun 29, 2023
1 parent fd5d47f commit efb862e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/identity/identity-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,8 @@ 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;
Expand Down
20 changes: 14 additions & 6 deletions src/proof/proof-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
import { toClaimNonRevStatus, toGISTProof } from './common';
import { NativeProver } from './prover';

import { Options, Path, getDocumentLoader } from '@iden3/js-jsonld-merklization';
import { DocumentLoader, Options, Path, getDocumentLoader } from '@iden3/js-jsonld-merklization';
import { ZKProof } from '@iden3/js-jwz';
import { Signer } from 'ethers';
import { ZeroKnowledgeProofRequest, ZeroKnowledgeProofResponse } from '../iden3comm';
Expand Down Expand Up @@ -154,6 +154,7 @@ export interface IProofService {
*/
export class ProofService implements IProofService {
private readonly _prover: NativeProver;
private readonly _ldLoader: DocumentLoader;
/**
* Creates an instance of ProofService.
* @param {IIdentityWallet} _identityWallet - identity wallet
Expand All @@ -165,9 +166,11 @@ export class ProofService implements IProofService {
private readonly _identityWallet: IIdentityWallet,
private readonly _credentialWallet: ICredentialWallet,
_circuitStorage: ICircuitStorage,
private readonly _stateStorage: IStateStorage
private readonly _stateStorage: IStateStorage,
opts?: Options
) {
this._prover = new NativeProver(_circuitStorage);
this._ldLoader = getDocumentLoader(opts);
}

/** {@inheritdoc IProofService.verifyProof} */
Expand Down Expand Up @@ -349,7 +352,8 @@ export class ProofService implements IProofService {
const { query, vp } = await this.toCircuitsQuery(
proofReq.query,
preparedCredential.credential,
preparedCredential.credentialCoreClaim
preparedCredential.credentialCoreClaim,
{documentLoader:this._ldLoader}
);
circuitInputs.query = query;
circuitInputs.claim = {
Expand Down Expand Up @@ -415,7 +419,9 @@ export class ProofService implements IProofService {
const { query, vp } = await this.toCircuitsQuery(
proofReq.query,
preparedCredential.credential,
preparedCredential.credentialCoreClaim
preparedCredential.credentialCoreClaim,
{documentLoader:this._ldLoader}

);
circuitInputs.query = query;
circuitInputs.claim = {
Expand Down Expand Up @@ -460,7 +466,8 @@ export class ProofService implements IProofService {
const { query, vp } = await this.toCircuitsQuery(
proofReq.query,
preparedCredential.credential,
preparedCredential.credentialCoreClaim
preparedCredential.credentialCoreClaim,
{documentLoader:this._ldLoader}
);
circuitInputs.query = query;
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
Expand Down Expand Up @@ -501,7 +508,8 @@ export class ProofService implements IProofService {
const { query, vp } = await this.toCircuitsQuery(
proofReq.query,
preparedCredential.credential,
preparedCredential.credentialCoreClaim
preparedCredential.credentialCoreClaim,
{documentLoader:this._ldLoader}
);
circuitInputs.query = query;
circuitInputs.currentTimeStamp = getUnixTimestamp(new Date());
Expand Down
10 changes: 6 additions & 4 deletions src/schema-processor/json/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export interface CoreClaimOptions {
subjectPosition: string;
merklizedRootPosition: string;
updatable: boolean;
merklizeOpts: Options;
}

/**
Expand All @@ -94,15 +95,16 @@ export class Parser {
credential: W3CCredential,
credentialType: string,
jsonSchemaBytes: Uint8Array,
opts?: Options & CoreClaimOptions
opts?: CoreClaimOptions
): Promise<CoreClaim> {
if (!opts) {
opts = {
revNonce: 0,
version: 0,
subjectPosition: SubjectPosition.Index,
merklizedRootPosition: MerklizedRootPosition.None,
updatable: false
updatable: false,
merklizeOpts: {}
};
}

Expand Down Expand Up @@ -143,12 +145,12 @@ export class Parser {

switch (opts.merklizedRootPosition) {
case MerklizedRootPosition.Index: {
const mk = await credential.merklize(opts);
const mk = await credential.merklize(opts.merklizeOpts);
claim.setIndexMerklizedRoot((await mk.root()).bigInt());
break;
}
case MerklizedRootPosition.Value: {
const mk = await credential.merklize(opts);
const mk = await credential.merklize(opts.merklizeOpts);
claim.setValueMerklizedRoot((await mk.root()).bigInt());
break;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/handlers/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('auth', () => {
credWallet = new CredentialWallet(dataStorage, resolvers);
idWallet = new IdentityWallet(kms, dataStorage, credWallet);

proofService = new ProofService(idWallet, credWallet, circuitStorage, mockStateStorage);
proofService = new ProofService(idWallet, credWallet, circuitStorage, mockStateStorage,{ipfsGatewayURL:"https://ipfs.io"});
packageMgr = await getPackageMgr(
await circuitStorage.loadCircuitData(CircuitId.AuthV2),
proofService.generateAuthV2Inputs.bind(proofService),
Expand Down
4 changes: 3 additions & 1 deletion tests/proofs/sig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ describe('sig proofs', () => {
credWallet = new CredentialWallet(dataStorage, resolvers);
idWallet = new IdentityWallet(kms, dataStorage, credWallet);

proofService = new ProofService(idWallet, credWallet, circuitStorage, mockStateStorage);
proofService = new ProofService(idWallet, credWallet, circuitStorage, mockStateStorage, {
ipfsGatewayURL: 'ipfs.io'
});
});

it('sigv2-non-merklized', async () => {
Expand Down

0 comments on commit efb862e

Please sign in to comment.