Bind a Mina signature to the zkApp operation it authorizes

An o1js signature authenticates an ordered array of fields. A verifier must reproduce that array and constrain the returned Boolean in its circuit.

Sign the context and payload

Suppose the same key can approve a vote in two independent elections. Signing only the choice field permits the same signature to verify wherever that choice has the same encoding. Agree on a stable domain constant, election ID, choice encoding and nonce. Produce a test vector and verify that swapping two fields fails.

const message = [domain, electionId, choice, nonce];
signature.verify(voterKey, message).assertTrue();

Enforce the result and consume the nonce

Calling verify returns a provable Bool. Assert that it is true and obtain the authorized public key from trusted policy. If the action must run only once, check and update nonce state atomically. A correctly scoped signature can still be replayed within its original scope until its nonce is consumed.

Sources