Repository navigation
fix(sdk): fail mock decrypts with the threshold network's error codes - #437
Merged
alexshchur merged 1 commit intoOct 28, 2026
Merged
alexshchur merged 1 commit into
alexshchur merged 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 271fce7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 packages
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 |
nftpoetrist
force-pushed
the
fix/sdk-mock-decrypt-error-codes
branch
from
October 27, 2026 13:40
7687d40 to
271fce7
Compare
alexshchur
approved these changes
Oct 28, 2026
alexshchur
left a comment
Contributor
There was a problem hiding this comment.
Thanks @nftpoetrist , merged!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
decryptForViewanddecryptForTxon the mocks now throw the sameCofheErrorCodeandapiErrorCodeas the threshold network:ACPDenied/acp_deniedwhen the ACL says no or the ACP was revoked,ACPExpired/acp_expired,ACPInvalid/acp_invalidfor a bad issuer or recipient signature, andNotPubliclyAllowed/not_publicly_allowedforwithoutACP()on a value that is not public.SealOutputFailed/DecryptFailed. The message still carries the mock's reason string.@cofhe/sdk.Root cause
cofheMocksDecryptForViewandcofheMocksDecryptForTxwrap every rejection fromMockThresholdNetworkin one generic code:The production path maps the threshold network's
errorfield to dedicated codes (apiError.ts), and the decryption lifecycle page lists them as the errors a decrypt throws. teecryptor picks those codes from the same ACL checks the mock runs (permit.rs#L682-L690, http.rs#L996-L1062):isAllowedWithPermissionreturns false, or revertsPermissionInvalid_Disabled: 401acp_deniedPermissionInvalid_Expired:acp_expired;PermissionInvalid_IssuerSignature/_RecipientSignature:acp_invalidisPubliclyAllowedfalse: 403not_publicly_allowedSo an app's
ACPDeniedorNotPubliclyAllowedhandling can't be exercised on the mocks.acp-demo-flow.test.tsalready works around the difference with/PermissionInvalid_Disabled|acp_denied/.Fix
mockRejectionToApiErrorCode(reason, withACP)inapiError.tsreturns the backend code for a mock reason, and both mock functions build the error withmapApiErrorCodeToCofheErrorCode(apiErrorCode, <generic code>), as the production path does. Messages are unchanged.Testing
core/test/cofheMocksDecryptErrors.test.ts(13 cases). RED onmaster: 11 failed, 2 passed (the two that keep the generic code).hardhat-3-plugin-test, against the real mock contracts: a contract-scoped ACP that does not cover the value givesACPDenied, anddecryptForTx().withoutACP()on a value that is not public givesNotPubliclyAllowed. RED onmaster: both fail withmocks querySealOutput call failed: NotAllowed/mocks decryptForTx call failed: NotAllowed. With the fix: 45 passing.pnpm --filter @cofhe/sdk test: 632 passed, 35 skipped.@cofhe/react: 78 passed.hardhat-plugin-test: 102 passing.pnpm check:types,pnpm lint,pnpm check:formatting(tracked files),check:circles,check:pinned-deps: pass.Scope
Mock path only. Production decrypts and the public API are unchanged.
Note
Low Risk
Mock-only decrypt error mapping; production API and decrypt paths are unchanged.
Overview
Mock
decryptForViewanddecryptForTxnow surface the sameCofheErrorCodeandapiErrorCodeas the real threshold network instead of always throwing genericSealOutputFailed/DecryptFailed.A new
mockRejectionToApiErrorCodemapsMockThresholdNetworkrejection strings to backend codes; mock decrypt helpers usemapApiErrorCodeToCofheErrorCodelike production. ACP failures becomeACPDenied,ACPExpired, orACPInvalid;decryptForTx().withoutACP()on non-public data becomesNotPubliclyAllowed. Unmapped reasons still use the previous generic codes.Adds unit tests for the mapping and Hardhat inherited tests that assert those errors end-to-end against mock contracts. Patch changeset for
@cofhe/sdk.Reviewed by Cursor Bugbot for commit 271fce7. Bugbot is set up for automated code reviews on this repo. Configure here.