CofheError objects on failure. This replaces the Result wrapper pattern used by cofhejs.
Catching errors
CofheError structure
EveryCofheError has:
code— aCofheErrorCodeenum value identifying the error typemessage— a human-readable description of what went wrong
isCofheError(err) to check if a caught error is a CofheError.
Common error codes
| Error code | When it occurs |
|---|---|
ZkPackFailed | encryptInputs exceeded the 2048-bit plaintext limit |
PermitNotFound | No permit found for the given chainId + account |
PermitInvalid | The permit signature is invalid or expired |
DecryptFailed | Decryption request was rejected by the Threshold Network |
NotConnected | Attempted an operation before calling client.connect(...) |
Error handling patterns
Encryption errors
Decryption errors
Distinguishing why a permit is invalid
Since@cofhe/sdk@0.5.0, the decrypt flows call PermitUtils.validate(permit) internally before talking to the Threshold Network. That helper enforces schema + signed + not-expired all at once, so when it fails the recovery path depends on which check tripped.
Use the non-throwing ValidationUtils.isValid helper from @cofhe/sdk/permits to pre-flight the active permit and route based on the typed reason — this avoids the thrown error path entirely:
ValidationResult.error is the typed union 'invalid-schema' | 'expired' | 'not-signed' | null — see Permits → Validating permits for the full helper surface.
If you prefer the throwing path:
PermitUtils.validate(permit) raises plain Errors with messages Permit is expired / Permit is not signed (or a Zod schema error). These are not wrapped in CofheError, so use err.message rather than an error code to branch.