Skip to content

Commit

Permalink
add client nonce to presentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Oct 28, 2024
1 parent 62d4858 commit e42522a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type PresentationRequest<

deriveContext(
inputContext: InputContext,
clientNonce: Field,
walletContext: WalletContext
): Field;
};
Expand Down Expand Up @@ -171,6 +172,7 @@ type Presentation<Output, Inputs extends Record<string, Input>> = {
version: 'v0';
claims: Claims<Inputs>;
outputClaim: Output;
clientNonce: Field;
proof: Proof<PublicInputs<Inputs>, Output>;
};

Expand Down Expand Up @@ -211,7 +213,14 @@ async function createPresentation<R extends PresentationRequest>(
credentials: (StoredCredential & { key?: string })[];
}
): Promise<Presentation<Output<R>, Inputs<R>>> {
let context = request.deriveContext(request.inputContext, walletContext);
// generate random client nonce
let clientNonce = Field.random();

let context = request.deriveContext(
request.inputContext,
clientNonce,
walletContext
);
let { program } = await Presentation.compile(request);

let credentialsNeeded = Object.entries(request.spec.inputs).filter(
Expand Down Expand Up @@ -241,6 +250,7 @@ async function createPresentation<R extends PresentationRequest>(
version: 'v0',
claims: request.claims as any,
outputClaim: proof.publicOutput,
clientNonce,
proof,
};
}
Expand Down Expand Up @@ -326,10 +336,7 @@ function ZkAppRequest<Output, Inputs extends Record<string, Input>>(request: {
type: 'zk-app',
...request,

deriveContext(inputContext, walletContext) {
// generate random nonce in the wallet
const clientNonce = Field.random();

deriveContext(inputContext, clientNonce, walletContext) {
const context = computeContext({
...inputContext,
...walletContext,
Expand Down Expand Up @@ -366,10 +373,7 @@ function HttpsRequest<Output, Inputs extends Record<string, Input>>(request: {
type: 'https',
...request,

deriveContext(inputContext, walletContext) {
// generate random nonce in the wallet
const clientNonce = Field.random();

deriveContext(inputContext, clientNonce, walletContext) {
const context = computeContext({
...inputContext,
...walletContext,
Expand Down

0 comments on commit e42522a

Please sign in to comment.