Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions src/iden3comm/packers/zkp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ export class ZKPPacker implements IPacker {
async pack(payload: Uint8Array, params: ZKPPackerParams): Promise<Uint8Array> {
let provingMethodAlg = params.provingMethodAlg;

let provingMethod = await getProvingMethod(provingMethodAlg);
let provingParams = this.provingParamsMap.get(provingMethodAlg.toString());

if (!provingParams) {
throw new Error(ErrNoProvingMethodAlg);
}
Expand All @@ -156,6 +154,15 @@ export class ZKPPacker implements IPacker {
targetCircuitId = testResult.targetCircuitId;
}

if (targetCircuitId !== params.provingMethodAlg.circuitId) {
provingMethodAlg = new ProvingMethodAlg(params.provingMethodAlg.alg, targetCircuitId);
provingParams = this.provingParamsMap.get(provingMethodAlg.toString());
if (!provingParams) {
throw new Error(ErrNoProvingMethodAlg);
}
}
const provingMethod = await getProvingMethod(provingMethodAlg);

const token = new Token(
provingMethod,
byteDecoder.decode(payload),
Expand All @@ -177,17 +184,6 @@ export class ZKPPacker implements IPacker {
return result;
}
);

if (targetCircuitId !== params.provingMethodAlg.circuitId) {
provingMethodAlg = new ProvingMethodAlg(params.provingMethodAlg.alg, targetCircuitId);
provingMethod = await getProvingMethod(provingMethodAlg);
provingParams = this.provingParamsMap.get(provingMethodAlg.toString());
if (!provingParams) {
throw new Error(ErrNoProvingMethodAlg);
}
}

token.setHeader(Header.CircuitId, targetCircuitId);
token.setHeader(Header.Type, MediaType.ZKPMessage);
const tokenStr = await token.prove(provingParams.provingKey, provingParams.wasm);
return byteEncoder.encode(tokenStr);
Expand Down
16 changes: 15 additions & 1 deletion src/proof/proof-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ export class ProofService implements IProofService {
inputs: Uint8Array;
targetCircuitId: CircuitId;
}> {
if (![CircuitId.AuthV2, CircuitId.AuthV3].includes(circuitId)) {
const authV3_8_32 = 'authV3-8-32' as CircuitId;
if (![CircuitId.AuthV2, CircuitId.AuthV3, authV3_8_32].includes(circuitId)) {
throw new Error('CircuitId is not supported');
}

Expand All @@ -705,6 +706,19 @@ export class ProofService implements IProofService {
const selectTargetCircuit = ():
| { mtLevel: number; mtLevelOnChain: number; targetCircuitId: CircuitId | string }
| undefined => {
if (circuitId === authV3_8_32) {
const subversion = circuitValidator[CircuitId.AuthV3].subVersions?.find(
(i) => i.targetCircuitId === authV3_8_32
);
if (!subversion || !subversion.mtLevel || !subversion.mtLevelOnChain) {
return undefined;
}
return {
mtLevel: subversion.mtLevel,
mtLevelOnChain: subversion.mtLevelOnChain,
targetCircuitId: authV3_8_32
};
}
const subversions = circuitValidator[circuitId].subVersions;
if (!subversions) {
return undefined;
Expand Down
Loading