Skip to content

feat(settlement): canonical request, policy fixture, receipt, and classifier (B02) - #12

Merged
selezenart merged 1 commit into
milestone/b01-sdk-network-compatibilityfrom
milestone/b02-request-policy-receipt
Sep 7, 2026
Merged

selezenart merged 1 commit into
milestone/b01-sdk-network-compatibilityfrom
milestone/b02-request-policy-receipt

Conversation

@selezenart

Copy link
Copy Markdown
Collaborator

Summary

Implements B02 — Canonical request, policy, and receipt verification for the
Coder B lane. Pure adapter logic: no network, no durable state, no credential.

Stacked on B01 (PR #11), which is not yet merged, so this PR targets the B01
branch. Review B01 first.

Four pieces: a byte-stable canonical settlement request with a stable provider
idempotency identity, an expected Privy policy with a drift digest, an Arc
receipt verifier, and an exhaustive submission-outcome classifier.

Scope and acceptance criteria

  • The change is limited to the stated milestone or issue.

  • Acceptance criteria are listed and satisfied.

  • No unrelated cleanup is included.

  • B02.1 correlated calldata — direct transfer(address,uint256) with exact
    chain, token, method, recipient, amount, and zero native value. Golden vectors
    pin calldata, canonical body, and fingerprint. The Arc Memo forwarded call is
    not built: B01.3 recorded it NOT_SUPPORTED.

  • B02.2 Privy request identity — deterministic body, keccak256 payload
    fingerprint, derived idempotency key, stable reference ID, and refusal of key
    reuse under a different fingerprint. The 24-hour provider window is documented
    as supplemental only.

  • B02.3 policy fixture — default-deny policy over the documented Privy
    condition fields, a soundness check, and a digest for drift detection.

  • B02.4 receipt verifier — confirmation only from a final receipt plus
    exactly one matching Transfer emitted by the configured token.

  • B02.5 outcome classifier — exhaustive mapping to CONFIRMED,
    DEFINITELY_NOT_SUBMITTED, or POSSIBLY_SUBMITTED.

Product and security invariants

  • Tenant isolation remains fail-closed.
  • Sponsor authorization, auditability, and daily caps remain enforced where applicable.
  • Recipients cannot modify sponsor controls or access sponsor-only data.
  • No secret, token, production identifier, or personal data is committed.
  • Any non-applicable invariant is explained below.

Invariant notes:

No durable state, table, or migration is touched, so tenant isolation and
sponsor-control rows are not applicable. The invariants this change carries:

  • At most one committed settlement. One intent yields one byte-stable
    request and one derived idempotency key, so independent workers building the
    same obligation produce the identical key and a duplicate collapses at the
    provider too. OneShot durable state remains the authority; the provider key is
    defence in depth.
  • status: 1 is not confirmation. A successful receipt with no matching
    Transfer is NOT_CONFIRMED, not success and not failure. Two matching
    Transfers are also refused: that would mean more value moved than authorized.
  • Doubt never permits a retry. Only DEFINITELY_NOT_SUBMITTED allows a
    fresh attempt without reconciliation, and it is granted only for narrow
    pre-flight proofs where nothing was broadcast. Every ambiguous signal,
    unrecognized response, and unmatched receipt is POSSIBLY_SUBMITTED.
  • Money is bigint throughout. Amounts are compared and encoded exactly,
    including values beyond IEEE-754 integer safety.

Validation

packages/arc-adapter        : lint, typecheck, build PASS; 136 tests PASS
packages/privy-adapter      : lint, typecheck, build PASS;  66 tests PASS
packages/testkit-settlement : lint, typecheck, build PASS;  10 tests PASS
total                       : 212 tests PASS
git diff --cached --check   : PASS

Independent review evidence

Gate A — exact candidate tree before push

  • Base commit SHA: 8be8d09b8ab5da19031af28fcee9da128a16f82b (develop)

  • Candidate tree SHA: 3351a19e455024cf65de3f9fb400d8eac5df4080

  • Candidate commit SHA: 031b119b8d97570b1247cbe37a5e42032333ef84

  • Reviewer tool: free-pi-cli 0.2.19

  • Reviewer model: glm-5.3-flash

  • Verdict: VERDICT: PASS

  • Blocking findings: None

  • The reviewed tree equals the committed tree.

Reviewed the full branch content, B01 and B02 together, against the frozen
contract pack and the security invariants.

Non-blocking findings, recorded and deferred:

  1. packages/arc-adapter/src/receipt.ts — the verifier does not bind a receipt
    to an expected transaction hash; correctness currently relies on the caller
    having fetched by hash. Worth tightening in B03/B04, where the hash is known.
  2. packages/privy-adapter/src/request.ts — assertIdempotencyKeyBinding is
    only reachable on a caller-supplied mismatch, because the key is derived from
    the fingerprint. The code comment already says so, and the check is kept
    deliberately so the invariant outlives the derivation choice.

Gate B — exact remote PR head

  • Verdict: NOT RUN (no CI gate configured for these packages yet; see below)

Risk and rollback

Residual risks:

  • CI does not lint or test these packages. The ESLint and TypeScript job
    looks for a root package.json plus pnpm-lock.yaml, finds neither, and
    skips. All validation above is local. The job also hard-fails if those two
    files are ever committed apart.
  • npm versus pnpm. These packages use npm with package-local lockfiles;
    repo CI expects a pnpm workspace. When Coder A scaffolds the root workspace,
    the three package-lock.json files should be dropped. A owns root config, so
    this is not resolved here.
  • The Privy policy is modelled, not yet exercised against a live Privy tenant.
    B03 does that.

Rollback: additive packages on a short-lived branch. Revert or close the PR. No
migration, deployment, or durable state.

Human merge

  • A human owner has reviewed the evidence and will perform the merge.

… classifier

Implements B02 for the Coder B lane as pure adapter logic with no network, no
durable state, and no credential.

Canonical request (B02.1, B02.2). One intent produces byte-stable calldata, a
keccak256 payload fingerprint, a provider idempotency key, and a reference ID.
Serialization writes an explicit field order rather than relying on
JSON.stringify over an object literal, whose key order depends on construction
order; two workers building the same obligation must fingerprint identically or
the provider key stops collapsing duplicates. Addresses are lowercased so
checksummed and non-checksummed spellings cannot fingerprint apart. A golden
vector pins the exact bytes, because changing any of them changes every
in-flight idempotency key. The 24-hour provider window is documented as
supplemental: OneShot durable state remains the authority past it.

Only the direct transfer path is built. B01.3 recorded the Arc Memo forwarded
call NOT_SUPPORTED, so no memo calldata builder exists to be reached by
mistake.

Policy fixture (B02.3). Expresses the required Privy policy as rules over the
documented condition fields, terminated by an unconditional default deny.
assessPolicySoundness catches the two ways such a policy silently stops
protecting anything: losing its terminal deny, or dropping a constrained
dimension. A keccak256 digest lets readiness detect drift, since the policy
lives in Privy configuration outside this repository and can be edited without
a commit. The digest ignores recipient ordering so an operator relisting the
same addresses does not read as drift.

Receipt verification (B02.4). Confirmation requires a final receipt and exactly
one Transfer matching sender, recipient, and amount, emitted by the configured
token. status: 1 alone is not confirmation, and tests cover the cases that
would otherwise pass: no logs, a redirected recipient, an amount off by one
atomic unit, a Transfer from an impostor contract, and two matching transfers,
which would mean more value moved than was authorized.

Outcome classifier (B02.5). Doubt is structural. DEFINITELY_NOT_SUBMITTED is
granted only for narrow pre-flight proofs where nothing was broadcast; every
ambiguous signal and every unrecognized response shape falls through to
POSSIBLY_SUBMITTED, including a response kind from a future provider version.
A receipt that fails to prove settlement is POSSIBLY_SUBMITTED, never
DEFINITELY_NOT_SUBMITTED: absence of proof is not proof of absence.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
oneshot 031b119 Sep 07 2026, 01:59 PM

@selezenart
selezenart merged commit 1dda3c1 into milestone/b01-sdk-network-compatibility Sep 7, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant