open-standards/openpay/crates/op-mobile-wallets/src/cryptogram.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

84 lines
3.4 KiB
Rust

//! Common cryptogram + ECI primitives shared by all three wallets.
//!
//! Each wallet emits a per-transaction cryptogram bound to the DPAN and
//! the transaction amount. The wire format differs by network (Visa
//! TAVV, Mastercard AAV/UCAF, Amex AEVV), but the **role** is the same:
//! the cryptogram authenticates the *use* of the network token at
//! authorization time.
//!
//! We reuse [`op_rails_card::network_token::Cryptogram`] as the
//! normalized over-the-wire shape so a decryption pipeline can feed
//! straight into the network-token rail without re-shaping. The
//! types below are the *wallet-side* metadata that doesn't survive
//! into the normalized cryptogram — the ECI string and the 3DS2
//! indicator — but which the rail driver needs to read off the
//! decrypted token before forwarding.
use serde::{Deserialize, Serialize};
pub use op_rails_card::network_token::Cryptogram;
/// Electronic Commerce Indicator (ECI).
///
/// Wallets emit network-specific ECI values that downstream
/// authorization logic forwards verbatim to the acquirer:
///
/// - Visa wallet-authenticated: `"05"`
/// - Visa attempted-authentication: `"06"`
/// - Mastercard wallet-authenticated: `"02"`
/// - Mastercard attempted-authentication: `"01"`
/// - Amex wallet-authenticated: `"05"`
///
/// The decryptor preserves the string the wallet emitted — we do not
/// re-derive ECI from cryptogram material. Translation between
/// network-specific and rail-specific ECI ranges happens at the
/// rail driver, not here.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct EciIndicator(String);
impl EciIndicator {
/// Wrap a wallet-emitted ECI string.
#[must_use]
pub fn new(eci: impl Into<String>) -> Self {
Self(eci.into())
}
/// Borrow the ECI string.
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
/// True if this ECI corresponds to the network's "fully
/// authenticated" code (Visa `"05"` / Mastercard `"02"` /
/// Amex `"05"`). Used by rail drivers to assert the
/// network-token liability-shift posture before forwarding.
#[must_use]
pub fn is_fully_authenticated(&self) -> bool {
matches!(self.0.as_str(), "05" | "02")
}
}
/// 3-D Secure 2 indicator extracted from the wallet payload.
///
/// Apple Pay sets this implicitly via the `paymentDataType` field
/// (`"3DSecure"` vs `"EMV"`); Google Pay surfaces it as a
/// `messageId`-adjacent field; Samsung Pay matches Apple Pay's shape.
/// We normalize across them into a small enum so rail code branches
/// on the type system instead of free-form strings.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ThreeDsIndicator {
/// The wallet has performed 3-D Secure 2 authentication for this
/// transaction; the cryptogram includes the device-attested AAV
/// (Mastercard) / CAVV (Visa) material.
Authenticated,
/// The wallet has *attempted* 3-D Secure but the issuer's ACS
/// returned `attempts` rather than full authentication. Liability
/// shift is still in effect on most networks; surfaced separately
/// because some rail-side risk policies treat it differently.
Attempted,
/// Wallet-authenticated via EMV cryptogram path (Apple Pay
/// `"EMV"`), not via 3-D Secure. Predominant for in-store
/// (Tap-to-Pay) and most in-app transactions.
EmvCryptogram,
}