Skip to content

Commit

Permalink
update submitResponse latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 29, 2025
1 parent 2aca7f9 commit 16a2460
Show file tree
Hide file tree
Showing 8 changed files with 677 additions and 450 deletions.
34 changes: 16 additions & 18 deletions src/iden3comm/handlers/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
BasicMessage,
JsonDocumentObject,
JWSPackerParams,
ZeroKnowledgeProofAuth,
ZeroKnowledgeProofAuthResponse,
ZeroKnowledgeProofQuery,
ZeroKnowledgeProofRequest,
ZeroKnowledgeProofResponse
Expand Down Expand Up @@ -138,7 +140,6 @@ export const processZeroKnowledgeProofRequests = async (
return zkpResponses;
};


/**
* Processes zero knowledge proof requests.
*
Expand All @@ -155,13 +156,14 @@ export const processProofAuth = async (
opts: {
supportedCircuits: CircuitId[];
acceptProfile?: AcceptProfile;
challenge?: bigint;
}
): Promise<AuthProofResponse[]> => {
): Promise<AuthProofResponse> => {
if (!opts.acceptProfile) {
opts.acceptProfile = defaultAcceptProfile;
}

const authResponses = [];
let authResponse: any;
// First version we only generate proof for ZKPMessage
if (opts.acceptProfile.env === MediaType.ZKPMessage) {
if (!opts.acceptProfile.circuits) {
Expand All @@ -173,31 +175,27 @@ export const processProofAuth = async (
throw new Error(`Circuit ${circuitId} is not supported`);
}

const authProof: ZeroKnowledgeProofRequest = {
id: 0,
circuitId: circuitId as unknown as CircuitId,
optional: false,
query: {
allowedIssuers: ['*'],
context: '',
credentialSubject: {},
type: 'Auth'
}
const authProof: ZeroKnowledgeProofAuth = {
circuitId: circuitId as unknown as CircuitId
};

const zkpRes: ZeroKnowledgeProofResponse = await proofService.generateProof(authProof, to);
const authRes: AuthProofResponse = {
authType: "zk-" + circuitId as string,
const zkpRes: ZeroKnowledgeProofAuthResponse = await proofService.generateAuthProof(
authProof,
to,
{ challenge: opts.challenge, skipRevocation: true }
);

authResponse = {
authType: ('zk-' + circuitId) as string,
circuitId: authProof.circuitId,
proof: zkpRes.proof,
pub_signals: zkpRes.pub_signals
};
authResponses.push(authRes);
break;
}
}

return authResponses;
return authResponse;
};

/**
Expand Down
11 changes: 5 additions & 6 deletions src/iden3comm/handlers/contract-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,8 @@ export class ContractRequestHandler
}
case FunctionSignaturesMultiQuery.SubmitResponse: {
// We need to
// 1. Generate auth proof from message.body.accept -> authResponses
// 2. Generate proofs for each query in scope without group -> singleResponses
// 3. Generate proofs for each query in scope with group -> groupedResponses
// 1. Generate auth proof from message.body.accept -> authResponse
// 2. Generate proofs for each query in scope -> zkpResponses

// Build auth response from accept
if (!message.to) {
Expand All @@ -188,16 +187,16 @@ export class ContractRequestHandler
);

const identifier = DID.parse(message.to);
const authResponses = await processProofAuth(
const authResponse = await processProofAuth(
identifier,
this._proofService,
{ supportedCircuits: this._supportedCircuits, acceptProfile }
{ supportedCircuits: this._supportedCircuits, acceptProfile, challenge: BigInt(10) }
);

return this._verifierMultiQuery.submitResponse(
ethSigner,
message.body.transaction_data,
authResponses,
authResponse,
zkpResponses
);
}
Expand Down
11 changes: 10 additions & 1 deletion src/iden3comm/types/protocol/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ export type ZeroKnowledgeProofResponse = {
id: number;
circuitId: string;
vp?: VerifiablePresentation;
groupId?: number;
} & ZKProof;

/** ZeroKnowledgeProofAuth represents structure of zkp auth object */
export type ZeroKnowledgeProofAuth = {
circuitId: CircuitId;
};

/** ZeroKnowledgeProofAuthResponse represents structure of zkp auth response */
export type ZeroKnowledgeProofAuthResponse = {
circuitId: string;
} & ZKProof;

/** VerifiablePresentation represents structure of Verifiable Presentation */
Expand Down
51 changes: 49 additions & 2 deletions src/proof/proof-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ import {
ZeroKnowledgeProofResponse,
PROTOCOL_CONSTANTS,
VerifiablePresentation,
JsonDocumentObject
JsonDocumentObject,
ZeroKnowledgeProofAuth,
ZeroKnowledgeProofAuthResponse
} from '../iden3comm';
import { cacheLoader } from '../schema-processor';
import { ICircuitStorage, IStateStorage } from '../storage';
Expand Down Expand Up @@ -121,6 +123,21 @@ export interface IProofService {
opts?: ProofGenerationOptions
): Promise<ZeroKnowledgeProofResponse>;

/**
* Generate auth proof from given identity
*
* @param {ZeroKnowledgeProofAuth} proofAuth - protocol zkp auth
* @param {DID} identifier - did that will generate proof
* @param {ProofGenerationOptions} opts - options that will be used for proof generation
*
* @returns `Promise<ZeroKnowledgeProofResponse>`
*/
generateAuthProof(
proofAuth: ZeroKnowledgeProofAuth,
identifier: DID,
opts?: ProofGenerationOptions
): Promise<ZeroKnowledgeProofAuthResponse>;

/**
* generates auth inputs
*
Expand Down Expand Up @@ -356,7 +373,37 @@ export class ProofService implements IProofService {
id: proofReq.id,
circuitId: proofReq.circuitId,
vp,
groupId,
proof,
pub_signals
};
}

/** {@inheritdoc IProofService.generateAuthProof} */
async generateAuthProof(
proofAuth: ZeroKnowledgeProofAuth,
identifier: DID,
opts?: ProofGenerationOptions
): Promise<ZeroKnowledgeProofAuthResponse> {
if (!opts) {
opts = {
skipRevocation: false,
challenge: 0n
};
}

const { genesisDID } =
await this._identityWallet.getGenesisDIDMetadata(identifier);

const challenge = opts.challenge
? BytesHelper.intToBytes(opts.challenge)
: new Uint8Array(32);

const inputs = await this.generateAuthV2Inputs(challenge, genesisDID, proofAuth.circuitId);

const { proof, pub_signals } = await this._prover.generate(inputs, proofAuth.circuitId);

return {
circuitId: proofAuth.circuitId,
proof,
pub_signals
};
Expand Down
Loading

0 comments on commit 16a2460

Please sign in to comment.