Skip to content
nokto/docsGitHub (opens in a new tab)

Write a verifier

@nokto-protocol/plugin-kit builds the request/response shape around verifyDisclosure so a verifier does not have to hand-roll challenge tracking and error messages.

import { defineVerifier } from '@nokto-protocol/plugin-kit';

const lender = defineVerifier({
  name: 'my-lender',
  verifierId: MY_ID,
  predicate: {
    threshold: 100_000n,
    minTier: 1,
    periodStart: 0n,
    periodEnd: 9_999_999_999n,
    currency: 'USD',
  },
  onAccepted: (claim) => approve(claim.principalId),
});

// Publish exactly what a holder is being asked to permit.
const ask = lender.grantRequest();

// Then, per request:
const pending = lender.request(freshChallenge);
const decision = await lender.evaluate(pending, proof, checkPlonkProof);

You issue the challenge. Nothing is written on chain when a disclosure is made, so the challenge is what makes a proof answer this request rather than an earlier one — see Disclosure and consent.

What each part does

  • predicate — exactly the arguments a grant would be bound to: threshold, minTier, periodStart, periodEnd, and currency. This is not a separate description of your policy; it is the policy, because it is also what grantRequest() returns.
  • grantRequest() — the exact predicate arguments a holder must grant before you can receive an answer. Show this to the holder before they consent, so selective disclosure is a decision they make rather than a label on a button.
  • request(challenge) — begins one request. The challenge must be freshly generated by the caller for each request; reusing one defeats the freshness the challenge exists to provide.
  • evaluate(pending, proof, checkProof) — checks the proof's claim against the pending request's expectation (never against anything read back out of the proof itself) and, if it holds, calls your onAccepted with the disclosed claim.

evaluate returns a Decision: either { approved: true, result } with whatever onAccepted returned, or { approved: false, reason, failure } with a human-readable reason and the underlying VerifyFailure code — useful for distinguishing "wrong verifier," "challenge mismatch," "tier too weak," and so on, rather than a single opaque rejection.

Building this yourself, rather than importing it, requires building from source — the packages are not published.