oss.sarwagya.wtf

Errors

Every failure is a typed GhostError with a stable code.

Everything Ghost throws is a GhostError with a stable code, the operation that failed, a human message, and the native cause when there is one. The server verifier is the exception by design: it returns failure codes instead of throwing, because bad proofs are expected traffic.

import { createGhost, isGhostError } from "@0xsarwagya/ghost";
 
try {
  const ghost = await createGhost();
} catch (error) {
  if (isGhostError(error) && error.code === "UNSUPPORTED") {
    // render the unsupported state
  }
}

Codes

CodeFires when
UNSUPPORTEDThe runtime has no usable Web Crypto. Check capabilities() first.
STORAGE_UNAVAILABLEIndexedDB is missing or failing (some private-browsing modes, storage pressure).
KEY_GENERATION_FAILEDThe runtime refused to generate an Ed25519 keypair.
KEY_NOT_FOUNDSigning was attempted on an identity that has been reset().
IDENTITY_CORRUPTEDThe stored record is unreadable. reset() discards it and starts over.
RECOVERY_FAILEDA recovery secret or recovery record is malformed or does not match.
SIGNING_FAILEDThe runtime failed during the signature operation itself.
INVALID_CHALLENGEA challenge or proof is malformed, bound to a different identity, or fails an expectation you configured.
CHALLENGE_EXPIREDexpiresAt has passed — locally at sign(), or at the verifier.
CHALLENGE_REUSEDThe nonce was already consumed. Replay, double-submit, or a shared store misconfiguration.
AUDIENCE_MISMATCHThe proof was issued for a different audience than this verifier serves.
INVALID_SIGNATUREThe signature does not verify, or the ghost ID does not match the public key.
UNSUPPORTED_VERSIONA protocol version or algorithm this build does not speak.

Errors never contain key material. The cause chain preserves the native DOMException when you need to debug an engine quirk.