open-standards/openpay/crates/op-mobile-wallets/src/error.rs
Transaction Science 01d4ad9c7b Ingest batch 2: 9 new crates across openpay / smart-byte / eoc
openpay/ (+3 crates, ~8400 LOC, 162 tests)
  op-iso8583/         ISO 8583 messages for direct acquirer / card-network
                      connectivity. MTIs, primary+secondary bitmaps, full
                      DE catalogue, BCD/ASCII/EBCDIC/LLVAR/LLLVAR codecs,
                      five dialects (Visa Base I, Mastercard MDS, Amex GNS,
                      Discover, JCB), network-management messages
                      (sign-on/echo/cutover), DE 55 EMV TLV.
  op-mobile-wallets/  Apple Pay (ECDH-P256 + AES-256-GCM), Google Pay ECv2
                      (ECDH + HKDF + AES-256-CTR + HMAC), Samsung Pay. PAN
                      never leaves the decryption boundary as a String;
                      lands in VaultRef. No-PAN-leakage assertions per
                      wallet.
  op-routing/         Least-cost routing + MCC-aware routing + intelligent
                      retry / soft-decline recovery. 231-MCC catalogue.
                      Real ISO 8583 DE-39 soft/hard decline taxonomies.

smart-byte/smart-byte-rs/ (+3 crates, ~7100 LOC, 96 tests)
  smart-byte-vc/      W3C Verifiable Credentials 2.0: VCDM, presentations,
                      Data Integrity proofs (eddsa-jcs-2022), VC-JWT,
                      SD-JWT (selective disclosure), Bitstring Status
                      List 2021. Cargo-bridge maps VCs to Smart Byte
                      envelopes with SAID stability.
  smart-byte-did/     W3C DID resolution: did:key (Ed25519/P-256/secp256k1),
                      did:web (HTTPS), did:peer (numalgo 2+4), did:jwk,
                      did:ion (feature-gated stub). DID URL dereferencer.
  smart-byte-pq/      Post-quantum signatures: ML-DSA-44/65/87 (FIPS 204),
                      SLH-DSA across 12 parameter sets (FIPS 205), FN-DSA
                      (draft FIPS 206, feature-gated). Hybrid Ed25519 +
                      ML-DSA pattern for the transition. Secret-key
                      zeroize-on-drop.

eoc/eoc-rs/ (+3 crates, ~6450 LOC, 76 tests)
  eoc-vendor-api/     NeuralBackend implementations: Anthropic, OpenAI,
                      Google, Mistral, Cohere, Groq, Together, Fireworks.
                      SSE streaming. Prompt-caching where supported.
                      Joule estimates per published energy coefficient
                      (12-model curated table).
  eoc-embeddings/     21 embedding models behind one Embedder trait:
                      OpenAI v3 (3), Cohere v3 (3), Voyage (5), Mistral,
                      Jina, plus local ONNX (BGE x3, nomic, mxbai, GTE,
                      E5) behind 'local' feature. Matryoshka-style
                      dimension projection. Per-content-hash cache.
  eoc-route-learned/  RouteLLM-style matrix-factorisation router +
                      multinomial-logreg classifier + LinUCB / Thompson
                      bandits for online learning. LearnedCascade wraps
                      the rule-based cascade with a confidence-threshold
                      skip policy. Synthetic-eval accuracy: MF 0.935,
                      LogReg 0.980.

Quality:
- cargo check across all three workspaces: clean
- cargo clippy --all-targets -- -D warnings on every new crate: clean
- 334 new tests total; all passing
- #![forbid(unsafe_code)] across every new crate
- No unwrap/expect outside #[cfg(test)]

Rust 1.95.0 edition 2024 (inherited via root rust-toolchain.toml).
2026-05-23 18:12:24 -04:00

82 lines
3.5 KiB
Rust

//! Typed errors for mobile-wallet decryption.
//!
//! One sealed enum per crate convention. Every error variant maps
//! deterministically to a single decryption failure mode so callers
//! can drive precise telemetry without string-matching.
use thiserror::Error;
/// Result alias.
pub type Result<T> = core::result::Result<T, Error>;
/// All failure modes for mobile-wallet payment-token decryption.
#[derive(Debug, Error, Clone, PartialEq, Eq)]
pub enum Error {
/// The wrapping signature on the token did not verify against the
/// supplied root signing keys. Apple Pay: the leaf certificate
/// could not be chained to the Apple Root CA. Google Pay: the
/// `intermediateSigningKey.signatures` did not verify against any
/// configured Google root key, or the `signedMessage` signature
/// did not verify against the intermediate key. Samsung Pay: the
/// signing-leaf signature failed.
#[error("bad signature on wallet token")]
BadSignature,
/// The certificate chain failed validation: malformed encoding,
/// wrong issuer, or — most commonly in tests — the configured
/// signing-key material is expired.
#[error("bad certificate / cert chain")]
BadCertificate,
/// The token / cryptogram's authoring timestamp is outside the
/// allowable window relative to `now`. Returned for replay-window
/// failures: Google Pay's `messageExpiration` has passed, Apple
/// Pay's `transaction_identifier` carries a too-old timestamp, or
/// the cryptogram itself is past its issuance-window expiry.
#[error("cryptogram / message expired")]
BadCryptogramExpired,
/// The token's declared protocol version is not supported by this
/// build. Google Pay ECv1 returns this (deprecated and stubbed in
/// this crate); any non-ECv2 Google Pay protocol returns this.
#[error("unsupported wallet protocol version: {0}")]
UnsupportedProtocolVersion(String),
/// The token's bound merchant identifier does not match the
/// `merchant_id` (or `merchant_id_hash` for Apple Pay) configured
/// on the decryptor. This is a hard fail: a token issued for
/// merchant A must not decrypt at merchant B.
#[error("merchant id mismatch")]
MerchantIdMismatch,
/// The encrypted payload is malformed: wrong base64, wrong
/// JSON shape, missing field, or an internal length/structure
/// invariant was violated.
#[error("malformed payment payload: {0}")]
MalformedPayload(&'static str),
/// The AEAD step failed to authenticate. AES-GCM tag mismatch
/// (Apple Pay, Samsung Pay) or HMAC-SHA256 mismatch on the
/// CTR-mode payload (Google Pay ECv2). Either the ciphertext was
/// tampered with, or the wrong recipient private key was used.
#[error("AEAD authentication failed (tag mismatch)")]
AeadAuthFailed,
/// The ECDH key-agreement step failed: a point was not on the
/// curve, or the operator's recipient private key didn't parse.
#[error("ECDH key-agreement failed")]
KeyAgreementFailed,
/// The operator-supplied [`crate::VaultTokenizer`] returned an
/// error. This is a non-recoverable failure of the merchant's
/// vault integration; the caller's vault is unavailable or
/// rejected the credential.
#[error("vault tokenizer failed: {0}")]
VaultTokenizer(String),
/// Internal cryptographic invariant violated — should not occur
/// in practice and indicates a bug in this crate or one of its
/// dependencies.
#[error("internal crypto invariant: {0}")]
Internal(&'static str),
}