Skip to content

feat: useCofheDecryptFn, useCofheDecryptForTx and a configurable decrypt timeout - #452

Draft
alexshchur wants to merge 3 commits into
feat/acp-sharing-writersfrom
feat/decrypt-fn
Draft

alexshchur wants to merge 3 commits into
feat/acp-sharing-writersfrom
feat/decrypt-fn

Conversation

@alexshchur

Copy link
Copy Markdown
Contributor

Stacked on #450 (feat/acp-sharing-writers, the 1.1.0-alpha.0 commit); the diff against it is three commits.

An app that decrypts a list of handles in a job the user starts (a transfer history to sum, a set of bids to reveal) had no way to do it through the SDK's React layer: useCofheDecrypt is one handle per mount, and the React package exposes neither an imperative read through its query cache nor the decrypt key. Such apps call client.decryptForView directly and reinvent the cache, the ACP gate and the concurrency cap. Likewise client.decryptForTx had no hook, and the overall decrypt timeout was fixed at 5 minutes.

@cofhe/sdk

  • .setTimeout(timeoutMs) on decryptForView and decryptForTx: the whole budget of one decrypt (submit attempts, 204/404 submit retries, status polling), threaded through tnSealOutputV2 / tnDecryptV2; the default stays 5 minutes (DEFAULT_DECRYPT_TIMEOUT_MS). Validation (assertDecryptTimeoutMs) sits next to the 404 window's in submitRetry.ts.

@cofhe/react

  • useCofheDecryptFn({ chainId?, acp?, concurrency? }) returns { decrypt, isReady, acp }. decrypt(input, options?) runs queryClient.fetchQuery with the same key, queryFn and meta as useCofheDecrypt, so a value decrypted either way is one cache entry, persisted under the same rule (self ACP only) and listed once in the activity panel. Same gate, as rejections: no valid ACP → ACPRequired / ACPExpired, SNAPSHOT share without the handle → ACPDenied, never a request. A zero handle resolves to the type's zero. Calls run at most concurrency at a time (4). Per-call options: meta, context, onPoll, timeoutMs, staleTime (Infinity), retry.
  • useCofheDecryptForTx(options?): useInternalMutation around client.decryptForTx, shaped like useCofheEncrypt (decryptForTxAsync, decryptForTx, isDecrypting). acp selects the mode: null → withoutACP(), omitted → active ACP, ACP or hash → withACP(x); chainId, account, onPoll, timeoutMs, retry404TimeoutMs map onto the builder.
  • useCofheDecrypt: the query's key / queryFn / meta move into the shared cofheDecryptQuery, the invalid-ACP purge into useDropDecryptsOfInvalidACP, the default retry into defaultDecryptRetry; it takes timeoutMs. Behaviour unchanged, the existing test is untouched.

Docs

New /react/decrypt (reachable by link, like /react/acp): the three hooks, one per shape of work. .setTimeout sections on both builder pages; the lifecycle page names the budget. Changeset: react minor + sdk minor.

Verification

  • @cofhe/sdk: tsc --noEmit clean apart from the pre-existing @cofhe/test-setup errors; decryptBuilders.test.ts 46 pass (6 new: setTimeout stored, rejected for 0 / NaN / negative, forwarded to the threshold network call on both builders).
  • @cofhe/react: tsc --noEmit clean; vitest 90 pass (6 new for useCofheDecryptFn: key + persisted meta + default retry, builder configured from call options with a scoped ACP, zero handle, invalid ACP, out-of-scope handle, concurrency; 5 new for useCofheDecryptForTx: mutation key, the three ACP modes, variable mapping, no client). eslint clean on the touched files. Prettier clean.
  • Not run: the Anvil / live suites.

Follow-up on the platform side: the sites that call client.decryptForView directly move to useCofheDecryptFn; the app-local useDecryptForTx wrappers to useCofheDecryptForTx.

…ole submit + poll budget

The overall budget of one decrypt (submit attempts, 204/404 submit retries
and status polling together) was a fixed 5 minutes in tnSealOutputV2 and
tnDecryptV2. Both builders now take it per request; the default stays.
The validation lives next to the 404 retry window's in submitRetry.ts.
`useCofheDecryptFn` returns a function that decrypts one handle on demand,
for a job over many handles run from a `useMutation`. Each call is the
same query `useCofheDecrypt` runs (key, ACP gate, persistence, activity
row), through `queryClient.fetchQuery`, so a handle decrypted either way
is decrypted once; calls run at most `concurrency` at a time. The query's
key, `queryFn` and `meta` move into `cofheDecryptQuery`, shared by both.

`useCofheDecryptForTx` is a mutation hook around `client.decryptForTx`,
shaped like `useCofheEncrypt`; `acp: null` selects `withoutACP()`.

Both hooks and `useCofheDecrypt` take `timeoutMs` for the builder's new
overall budget.
…ooks and `setTimeout`

A page for the three decrypt hooks, one per shape of work: a value to
render (`useCofheDecrypt`), a job over many handles (`useCofheDecryptFn`),
a plaintext with proof (`useCofheDecryptForTx`). Reachable by link like
/react/acp; the React section stays out of the sidebar.
@changeset-bot

changeset-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 41510d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@cofhe/react Minor
@cofhe/sdk Minor
@cofhe/example-react Minor
@cofhe/abi Minor
@cofhe/hardhat-3-plugin Minor
@cofhe/hardhat-plugin Minor
@cofhe/mock-contracts Minor
@cofhe/site Minor
@cofhe/foundry-plugin Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Vercel previews (commit 41510d2)

Project Deployment Updated
docs Visit Preview Oct 19, 2026 12:08 UTC
react Visit Preview Oct 19, 2026 12:09 UTC

This branch was successfully deployed

3 active deployments
Preview – react — 41510d2e Deployed Oct 19, 2026 by github-actions[bot]
Preview – docs — 41510d2e Deployed Oct 19, 2026 by github-actions[bot]
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