Skip to content

Commit

Permalink
remove unnecessary duplicated revocation status type
Browse files Browse the repository at this point in the history
  • Loading branch information
lukachi committed Mar 15, 2024
1 parent ad51e02 commit dffa733
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 77 deletions.
43 changes: 13 additions & 30 deletions packages/zkp-iden3/src/helpers/proof-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const buildTreeState = (
rootOfRoots: string,
): TreeState => ({
state: Hash.fromHex(state),
claimsRoot: Hash.fromHex(claimsTreeRoot),
revocationRoot: Hash.fromHex(revocationTreeRoot),
claimsTreeRoot: Hash.fromHex(claimsTreeRoot),
revocationTreeRoot: Hash.fromHex(revocationTreeRoot),
rootOfRoots: Hash.fromHex(rootOfRoots),
});

Expand All @@ -71,9 +71,16 @@ const getRevocationStatus = async (

const mtp = proofFromJson(data.mtp);

const issuer = buildTreeState(
data.issuer.state,
data.issuer.claimsTreeRoot,
data.issuer.revocationTreeRoot,
data.issuer.rootOfRoots,
);

return {
mtp,
issuer: data.issuer,
issuer,
};
};

Expand Down Expand Up @@ -212,15 +219,6 @@ export const getPreparedCredential = async (credential: W3CCredential) => {
return {
credential,
revStatus,
claimNonRevStatus: {
proof: revStatus.mtp,
treeState: buildTreeState(
revStatus.issuer.state,
revStatus.issuer.claimsTreeRoot,
revStatus.issuer.revocationTreeRoot,
revStatus.issuer.rootOfRoots,
),
},
mtpProofCoreClaim,
sigProofCoreClaim,
};
Expand Down Expand Up @@ -255,12 +253,7 @@ export const formatRawClaimToCircuitClaim = async (
// incProof === smtProf
incProof: {
proof: revStatus.mtp,
treeState: buildTreeState(
revStatus.issuer.state,
revStatus.issuer.claimsTreeRoot,
revStatus.issuer.revocationTreeRoot,
revStatus.issuer.rootOfRoots,
),
treeState: revStatus.issuer,
},
};
}
Expand Down Expand Up @@ -299,21 +292,11 @@ export const formatRawClaimToCircuitClaim = async (
issuerAuthClaim: new Claim().fromHex(sigProof.issuerData.authCoreClaim),
issuerAuthNonRevProof: {
proof: revStatus.mtp,
treeState: buildTreeState(
revStatus.issuer.state,
revStatus.issuer.claimsTreeRoot,
revStatus.issuer.revocationTreeRoot,
revStatus.issuer.rootOfRoots,
),
treeState: revStatus.issuer,
},
issuerAuthIncProof: {
proof: issuerAuthClaimIncMtp.mtp,
treeState: buildTreeState(
issuerAuthClaimIncMtp.issuer.state,
issuerAuthClaimIncMtp.issuer.claimsTreeRoot,
issuerAuthClaimIncMtp.issuer.revocationTreeRoot,
issuerAuthClaimIncMtp.issuer.rootOfRoots,
),
treeState: issuerAuthClaimIncMtp.issuer,
},
},
};
Expand Down
66 changes: 34 additions & 32 deletions packages/zkp-iden3/src/instances/zkp-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import type { Identity } from '@/instances/identity';
import type {
CircuitClaim,
ClaimNonRevStatus,
RevocationStatus,
GISTProof,
NodeAuxValue,
W3CCredential,
Expand Down Expand Up @@ -64,7 +64,7 @@ export class ZkpGen {

nodAuxJSONLD: NodeAuxValue = {} as NodeAuxValue;

claimNonRevStatus: ClaimNonRevStatus = {} as ClaimNonRevStatus;
claimNonRevStatus: RevocationStatus = {} as RevocationStatus;

value: string[] = [];

Expand Down Expand Up @@ -109,7 +109,9 @@ export class ZkpGen {
this.verifiableCredential,
);

this.claimNonRevStatus = preparedCredential.claimNonRevStatus;
// If we here, that means proof ain't in revocation tree, it could be called non revocation proof (nonRevProof, ...etc)
// We need it to populate inputs later, so let's save it
this.claimNonRevStatus = preparedCredential.revStatus;

const coreClaim = {
[CircuitId.AtomicQuerySigV2OnChain]: preparedCredential.sigProofCoreClaim,
Expand Down Expand Up @@ -144,7 +146,7 @@ export class ZkpGen {
this.nodeAuxIssuerAuthNonRev = getNodeAuxValue(
this.circuitClaim.signatureProof.issuerAuthNonRevProof.proof,
);
this.nodeAuxNonRev = getNodeAuxValue(this.claimNonRevStatus.proof);
this.nodeAuxNonRev = getNodeAuxValue(this.claimNonRevStatus.mtp);
this.nodAuxJSONLD = getNodeAuxValue(this.query.valueProof!.mtp);
this.value = prepareCircuitArrayValues(
this.query.values,
Expand Down Expand Up @@ -284,9 +286,9 @@ export class ZkpGen {
defaultMTLevels,
),
issuerAuthClaimsTreeRoot:
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.claimsRoot.string(),
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.claimsTreeRoot.string(),
issuerAuthRevTreeRoot:
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.revocationRoot.string(),
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.revocationTreeRoot.string(),
issuerAuthRootsTreeRoot:
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.rootOfRoots.string(),

Expand All @@ -302,19 +304,19 @@ export class ZkpGen {
issuerClaim: this.circuitClaim.claim.marshalJson(),
isRevocationChecked: '1',
issuerClaimNonRevMtp: prepareSiblingsStr(
this.claimNonRevStatus.proof,
this.claimNonRevStatus.mtp,
defaultMTLevels,
),
issuerClaimNonRevMtpNoAux: this.nodeAuxNonRev.noAux,
issuerClaimNonRevMtpAuxHi: this.nodeAuxNonRev.key.string(),
issuerClaimNonRevMtpAuxHv: this.nodeAuxNonRev.value.string(),
issuerClaimNonRevClaimsTreeRoot:
this.claimNonRevStatus.treeState.claimsRoot.string(),
this.claimNonRevStatus.issuer.claimsTreeRoot.string(),
issuerClaimNonRevRevTreeRoot:
this.claimNonRevStatus.treeState.revocationRoot.string(),
this.claimNonRevStatus.issuer.revocationTreeRoot.string(),
issuerClaimNonRevRootsTreeRoot:
this.claimNonRevStatus.treeState.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.treeState.state.string(),
this.claimNonRevStatus.issuer.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.issuer.state.string(),

issuerClaimSignatureR8x:
this.circuitClaim.signatureProof.signature.R8[0].toString(),
Expand Down Expand Up @@ -367,9 +369,9 @@ export class ZkpGen {
defaultMTLevels,
),
issuerAuthClaimsTreeRoot:
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.claimsRoot.string(),
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.claimsTreeRoot.string(),
issuerAuthRevTreeRoot:
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.revocationRoot.string(),
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.revocationTreeRoot.string(),
issuerAuthRootsTreeRoot:
this.circuitClaim.signatureProof.issuerAuthIncProof.treeState?.rootOfRoots.string(),

Expand All @@ -385,19 +387,19 @@ export class ZkpGen {
issuerClaim: this.circuitClaim.claim.marshalJson(),
isRevocationChecked: '1',
issuerClaimNonRevMtp: prepareSiblingsStr(
this.claimNonRevStatus.proof,
this.claimNonRevStatus.mtp,
defaultMTLevels,
),
issuerClaimNonRevMtpNoAux: this.nodeAuxNonRev.noAux,
issuerClaimNonRevMtpAuxHi: this.nodeAuxNonRev.key.string(),
issuerClaimNonRevMtpAuxHv: this.nodeAuxNonRev.value.string(),
issuerClaimNonRevClaimsTreeRoot:
this.claimNonRevStatus.treeState.claimsRoot.string(),
this.claimNonRevStatus.issuer.claimsTreeRoot.string(),
issuerClaimNonRevRevTreeRoot:
this.claimNonRevStatus.treeState.revocationRoot.string(),
this.claimNonRevStatus.issuer.revocationTreeRoot.string(),
issuerClaimNonRevRootsTreeRoot:
this.claimNonRevStatus.treeState.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.treeState.state.string(),
this.claimNonRevStatus.issuer.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.issuer.state.string(),

issuerClaimSignatureR8x:
this.circuitClaim.signatureProof.signature.R8[0].toString(),
Expand Down Expand Up @@ -446,28 +448,28 @@ export class ZkpGen {
issuerClaim: this.circuitClaim.claim.marshalJson(),
isRevocationChecked: '1',
issuerClaimNonRevMtp: prepareSiblingsStr(
this.claimNonRevStatus.proof,
this.claimNonRevStatus.mtp,
defaultMTLevels,
),
issuerClaimNonRevMtpNoAux: this.nodeAuxNonRev.noAux,
issuerClaimNonRevMtpAuxHi: this.nodeAuxNonRev.key.string(),
issuerClaimNonRevMtpAuxHv: this.nodeAuxNonRev.value.string(),
issuerClaimNonRevClaimsTreeRoot:
this.claimNonRevStatus.treeState.claimsRoot.string(),
this.claimNonRevStatus.issuer.claimsTreeRoot.string(),
issuerClaimNonRevRevTreeRoot:
this.claimNonRevStatus.treeState.revocationRoot.string(),
this.claimNonRevStatus.issuer.revocationTreeRoot.string(),
issuerClaimNonRevRootsTreeRoot:
this.claimNonRevStatus.treeState.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.treeState.state.string(),
this.claimNonRevStatus.issuer.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.issuer.state.string(),

issuerClaimMtp: prepareSiblingsStr(
this.circuitClaim.incProof.proof,
defaultMTLevels,
),
issuerClaimClaimsTreeRoot:
this.circuitClaim.incProof.treeState?.claimsRoot.string(),
this.circuitClaim.incProof.treeState?.claimsTreeRoot.string(),
issuerClaimRevTreeRoot:
this.circuitClaim.incProof.treeState?.revocationRoot.string(),
this.circuitClaim.incProof.treeState?.revocationTreeRoot.string(),
issuerClaimRootsTreeRoot:
this.circuitClaim.incProof.treeState?.rootOfRoots.string(),
issuerClaimIdenState:
Expand Down Expand Up @@ -544,28 +546,28 @@ export class ZkpGen {
issuerClaim: this.circuitClaim.claim.marshalJson(),
isRevocationChecked: '1',
issuerClaimNonRevMtp: prepareSiblingsStr(
this.claimNonRevStatus.proof,
this.claimNonRevStatus.mtp,
defaultMTLevels,
),
issuerClaimNonRevMtpNoAux: this.nodeAuxNonRev.noAux,
issuerClaimNonRevMtpAuxHi: this.nodeAuxNonRev.key.string(),
issuerClaimNonRevMtpAuxHv: this.nodeAuxNonRev.value.string(),
issuerClaimNonRevClaimsTreeRoot:
this.claimNonRevStatus.treeState.claimsRoot.string(),
this.claimNonRevStatus.issuer.claimsTreeRoot.string(),
issuerClaimNonRevRevTreeRoot:
this.claimNonRevStatus.treeState.revocationRoot.string(),
this.claimNonRevStatus.issuer.revocationTreeRoot.string(),
issuerClaimNonRevRootsTreeRoot:
this.claimNonRevStatus.treeState.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.treeState.state.string(),
this.claimNonRevStatus.issuer.rootOfRoots.string(),
issuerClaimNonRevState: this.claimNonRevStatus.issuer.state.string(),

issuerClaimMtp: prepareSiblingsStr(
this.circuitClaim.incProof.proof,
defaultMTLevels,
),
issuerClaimClaimsTreeRoot:
this.circuitClaim.incProof.treeState?.claimsRoot.string(),
this.circuitClaim.incProof.treeState?.claimsTreeRoot.string(),
issuerClaimRevTreeRoot:
this.circuitClaim.incProof.treeState?.revocationRoot.string(),
this.circuitClaim.incProof.treeState?.revocationTreeRoot.string(),
issuerClaimRootsTreeRoot:
this.circuitClaim.incProof.treeState?.rootOfRoots.string(),
issuerClaimIdenState:
Expand Down
20 changes: 5 additions & 15 deletions packages/zkp-iden3/src/types/proof-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,6 @@ export type W3CCredential = {
proof?: [BJJSignatureProofRaw, Iden3SparseMerkleTreeProofRaw];
};

export type RevocationStatus = {
mtp: Proof;
issuer: {
state: string;
rootOfRoots: string;
claimsTreeRoot: string;
revocationTreeRoot: string;
};
};

export type State = {
txId?: string;
blockTimestamp?: number;
Expand All @@ -98,13 +88,13 @@ export type State = {
export type TreeState = {
state: Hash;
rootOfRoots: Hash;
claimsRoot: Hash;
revocationRoot: Hash;
claimsTreeRoot: Hash;
revocationTreeRoot: Hash;
};

export type ClaimNonRevStatus = {
treeState: TreeState;
proof: Proof;
export type RevocationStatus = {
mtp: Proof;
issuer: TreeState;
};

export type QueryWithFieldName = {
Expand Down

0 comments on commit dffa733

Please sign in to comment.