Repository navigation
fix(sdk): fail mock decrypts with the threshold network's error codes - #437
Open
nftpoetrist wants to merge 1 commit into
Open
nftpoetrist wants to merge 1 commit into
nftpoetrist wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 7687d40 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 |
This branch has not been deployed
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 error mapping; production decrypt APIs are unchanged, with broader test coverage for ACL failure cases.
Overview
Mock decrypt paths now align with threshold-network error semantics so local/dev tests can assert the same
CofheErrorCodeandapiErrorCodeas production.mockRejectionToApiErrorCodemapsMockThresholdNetworkrejection strings to backend codes (acp_denied,acp_expired,acp_invalid,not_publicly_allowed).cofheMocksDecryptForViewandcofheMocksDecryptForTxmerge the previous separateerror/allowed == falsebranches and throw viamapApiErrorCodeToCofheErrorCode, still falling back toSealOutputFailed/DecryptFailedfor unmapped reasons. Error messages are unchanged.Coverage adds unit tests for each mapped reason plus Hardhat inherited tests for wrong-scope ACP (
ACPDenied) anddecryptForTx().withoutACP()on non-public ciphertext (NotPubliclyAllowed). Patch changeset for@cofhe/sdk.Reviewed by Cursor Bugbot for commit 7687d40. Bugbot is set up for automated code reviews on this repo. Configure here.