{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
-- | Core data types for SD-JWT (Selective Disclosure for JSON Web Tokens).
--
-- This module defines all the data types used throughout the SD-JWT library,
-- including hash algorithms, disclosures, SD-JWT structures, and error types.
-- These types correspond to the structures defined in RFC 9901.
module SDJWT.Internal.Types
  ( HashAlgorithm(..)
  , Salt(..)
  , Digest(..)
  , ObjectDisclosure(..)
  , ArrayDisclosure(..)
  , Disclosure(..)
  , EncodedDisclosure(..)
  , SDJWTPayload(..)
  , KeyBindingInfo(..)
  , SDJWT(..)
  , SDJWTPresentation(..)
  , ProcessedSDJWTPayload(..)
  , SDJWTError(..)
  ) where

import Data.Aeson (Value, Object)
import qualified Data.Aeson.KeyMap as KeyMap
import Data.ByteString (ByteString)
import Data.Map.Strict (Map)
import Data.Text (Text)
import GHC.Generics (Generic)

-- | Hash algorithm identifier for computing disclosure digests.
--
-- All three algorithms (SHA-256, SHA-384, SHA-512) must be supported.
-- SHA-256 is the default when _sd_alg is not specified in the SD-JWT.
data HashAlgorithm
  = SHA256  -- ^ SHA-256 (default, required)
  | SHA384  -- ^ SHA-384
  | SHA512  -- ^ SHA-512
  deriving stock (HashAlgorithm -> HashAlgorithm -> Bool
(HashAlgorithm -> HashAlgorithm -> Bool)
-> (HashAlgorithm -> HashAlgorithm -> Bool) -> Eq HashAlgorithm
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HashAlgorithm -> HashAlgorithm -> Bool
== :: HashAlgorithm -> HashAlgorithm -> Bool
$c/= :: HashAlgorithm -> HashAlgorithm -> Bool
/= :: HashAlgorithm -> HashAlgorithm -> Bool
Eq, Int -> HashAlgorithm -> ShowS
[HashAlgorithm] -> ShowS
HashAlgorithm -> String
(Int -> HashAlgorithm -> ShowS)
-> (HashAlgorithm -> String)
-> ([HashAlgorithm] -> ShowS)
-> Show HashAlgorithm
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HashAlgorithm -> ShowS
showsPrec :: Int -> HashAlgorithm -> ShowS
$cshow :: HashAlgorithm -> String
show :: HashAlgorithm -> String
$cshowList :: [HashAlgorithm] -> ShowS
showList :: [HashAlgorithm] -> ShowS
Show, ReadPrec [HashAlgorithm]
ReadPrec HashAlgorithm
Int -> ReadS HashAlgorithm
ReadS [HashAlgorithm]
(Int -> ReadS HashAlgorithm)
-> ReadS [HashAlgorithm]
-> ReadPrec HashAlgorithm
-> ReadPrec [HashAlgorithm]
-> Read HashAlgorithm
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS HashAlgorithm
readsPrec :: Int -> ReadS HashAlgorithm
$creadList :: ReadS [HashAlgorithm]
readList :: ReadS [HashAlgorithm]
$creadPrec :: ReadPrec HashAlgorithm
readPrec :: ReadPrec HashAlgorithm
$creadListPrec :: ReadPrec [HashAlgorithm]
readListPrec :: ReadPrec [HashAlgorithm]
Read, (forall x. HashAlgorithm -> Rep HashAlgorithm x)
-> (forall x. Rep HashAlgorithm x -> HashAlgorithm)
-> Generic HashAlgorithm
forall x. Rep HashAlgorithm x -> HashAlgorithm
forall x. HashAlgorithm -> Rep HashAlgorithm x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HashAlgorithm -> Rep HashAlgorithm x
from :: forall x. HashAlgorithm -> Rep HashAlgorithm x
$cto :: forall x. Rep HashAlgorithm x -> HashAlgorithm
to :: forall x. Rep HashAlgorithm x -> HashAlgorithm
Generic)

-- | Salt value (cryptographically secure random).
--
-- Salts are used when creating disclosures to prevent brute-force attacks.
-- RFC 9901 recommends 128 bits (16 bytes) of entropy.
newtype Salt = Salt { Salt -> ByteString
unSalt :: ByteString }
  deriving stock (Salt -> Salt -> Bool
(Salt -> Salt -> Bool) -> (Salt -> Salt -> Bool) -> Eq Salt
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Salt -> Salt -> Bool
== :: Salt -> Salt -> Bool
$c/= :: Salt -> Salt -> Bool
/= :: Salt -> Salt -> Bool
Eq, Int -> Salt -> ShowS
[Salt] -> ShowS
Salt -> String
(Int -> Salt -> ShowS)
-> (Salt -> String) -> ([Salt] -> ShowS) -> Show Salt
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Salt -> ShowS
showsPrec :: Int -> Salt -> ShowS
$cshow :: Salt -> String
show :: Salt -> String
$cshowList :: [Salt] -> ShowS
showList :: [Salt] -> ShowS
Show, (forall x. Salt -> Rep Salt x)
-> (forall x. Rep Salt x -> Salt) -> Generic Salt
forall x. Rep Salt x -> Salt
forall x. Salt -> Rep Salt x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Salt -> Rep Salt x
from :: forall x. Salt -> Rep Salt x
$cto :: forall x. Rep Salt x -> Salt
to :: forall x. Rep Salt x -> Salt
Generic)

-- | Digest (base64url-encoded hash).
--
-- A digest is the base64url-encoded hash of a disclosure. Digests replace
-- claim values in the SD-JWT payload to enable selective disclosure.
newtype Digest = Digest { Digest -> Text
unDigest :: Text }
  deriving stock (Digest -> Digest -> Bool
(Digest -> Digest -> Bool)
-> (Digest -> Digest -> Bool) -> Eq Digest
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Digest -> Digest -> Bool
== :: Digest -> Digest -> Bool
$c/= :: Digest -> Digest -> Bool
/= :: Digest -> Digest -> Bool
Eq, Int -> Digest -> ShowS
[Digest] -> ShowS
Digest -> String
(Int -> Digest -> ShowS)
-> (Digest -> String) -> ([Digest] -> ShowS) -> Show Digest
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Digest -> ShowS
showsPrec :: Int -> Digest -> ShowS
$cshow :: Digest -> String
show :: Digest -> String
$cshowList :: [Digest] -> ShowS
showList :: [Digest] -> ShowS
Show, (forall x. Digest -> Rep Digest x)
-> (forall x. Rep Digest x -> Digest) -> Generic Digest
forall x. Rep Digest x -> Digest
forall x. Digest -> Rep Digest x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Digest -> Rep Digest x
from :: forall x. Digest -> Rep Digest x
$cto :: forall x. Rep Digest x -> Digest
to :: forall x. Rep Digest x -> Digest
Generic)

-- | Disclosure for object properties: [salt, claim_name, claim_value]
data ObjectDisclosure = ObjectDisclosure
  { ObjectDisclosure -> Salt
disclosureSalt :: Salt
  , ObjectDisclosure -> Text
disclosureName :: Text
  , ObjectDisclosure -> Value
disclosureValue :: Value
  }
  deriving stock (ObjectDisclosure -> ObjectDisclosure -> Bool
(ObjectDisclosure -> ObjectDisclosure -> Bool)
-> (ObjectDisclosure -> ObjectDisclosure -> Bool)
-> Eq ObjectDisclosure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ObjectDisclosure -> ObjectDisclosure -> Bool
== :: ObjectDisclosure -> ObjectDisclosure -> Bool
$c/= :: ObjectDisclosure -> ObjectDisclosure -> Bool
/= :: ObjectDisclosure -> ObjectDisclosure -> Bool
Eq, Int -> ObjectDisclosure -> ShowS
[ObjectDisclosure] -> ShowS
ObjectDisclosure -> String
(Int -> ObjectDisclosure -> ShowS)
-> (ObjectDisclosure -> String)
-> ([ObjectDisclosure] -> ShowS)
-> Show ObjectDisclosure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ObjectDisclosure -> ShowS
showsPrec :: Int -> ObjectDisclosure -> ShowS
$cshow :: ObjectDisclosure -> String
show :: ObjectDisclosure -> String
$cshowList :: [ObjectDisclosure] -> ShowS
showList :: [ObjectDisclosure] -> ShowS
Show, (forall x. ObjectDisclosure -> Rep ObjectDisclosure x)
-> (forall x. Rep ObjectDisclosure x -> ObjectDisclosure)
-> Generic ObjectDisclosure
forall x. Rep ObjectDisclosure x -> ObjectDisclosure
forall x. ObjectDisclosure -> Rep ObjectDisclosure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ObjectDisclosure -> Rep ObjectDisclosure x
from :: forall x. ObjectDisclosure -> Rep ObjectDisclosure x
$cto :: forall x. Rep ObjectDisclosure x -> ObjectDisclosure
to :: forall x. Rep ObjectDisclosure x -> ObjectDisclosure
Generic)

-- | Disclosure for array elements: [salt, claim_value]
data ArrayDisclosure = ArrayDisclosure
  { ArrayDisclosure -> Salt
arraySalt :: Salt
  , ArrayDisclosure -> Value
arrayValue :: Value
  }
  deriving stock (ArrayDisclosure -> ArrayDisclosure -> Bool
(ArrayDisclosure -> ArrayDisclosure -> Bool)
-> (ArrayDisclosure -> ArrayDisclosure -> Bool)
-> Eq ArrayDisclosure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ArrayDisclosure -> ArrayDisclosure -> Bool
== :: ArrayDisclosure -> ArrayDisclosure -> Bool
$c/= :: ArrayDisclosure -> ArrayDisclosure -> Bool
/= :: ArrayDisclosure -> ArrayDisclosure -> Bool
Eq, Int -> ArrayDisclosure -> ShowS
[ArrayDisclosure] -> ShowS
ArrayDisclosure -> String
(Int -> ArrayDisclosure -> ShowS)
-> (ArrayDisclosure -> String)
-> ([ArrayDisclosure] -> ShowS)
-> Show ArrayDisclosure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ArrayDisclosure -> ShowS
showsPrec :: Int -> ArrayDisclosure -> ShowS
$cshow :: ArrayDisclosure -> String
show :: ArrayDisclosure -> String
$cshowList :: [ArrayDisclosure] -> ShowS
showList :: [ArrayDisclosure] -> ShowS
Show, (forall x. ArrayDisclosure -> Rep ArrayDisclosure x)
-> (forall x. Rep ArrayDisclosure x -> ArrayDisclosure)
-> Generic ArrayDisclosure
forall x. Rep ArrayDisclosure x -> ArrayDisclosure
forall x. ArrayDisclosure -> Rep ArrayDisclosure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ArrayDisclosure -> Rep ArrayDisclosure x
from :: forall x. ArrayDisclosure -> Rep ArrayDisclosure x
$cto :: forall x. Rep ArrayDisclosure x -> ArrayDisclosure
to :: forall x. Rep ArrayDisclosure x -> ArrayDisclosure
Generic)

-- | Unified disclosure type
data Disclosure
  = DisclosureObject ObjectDisclosure
  | DisclosureArray ArrayDisclosure
  deriving stock (Disclosure -> Disclosure -> Bool
(Disclosure -> Disclosure -> Bool)
-> (Disclosure -> Disclosure -> Bool) -> Eq Disclosure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Disclosure -> Disclosure -> Bool
== :: Disclosure -> Disclosure -> Bool
$c/= :: Disclosure -> Disclosure -> Bool
/= :: Disclosure -> Disclosure -> Bool
Eq, Int -> Disclosure -> ShowS
[Disclosure] -> ShowS
Disclosure -> String
(Int -> Disclosure -> ShowS)
-> (Disclosure -> String)
-> ([Disclosure] -> ShowS)
-> Show Disclosure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Disclosure -> ShowS
showsPrec :: Int -> Disclosure -> ShowS
$cshow :: Disclosure -> String
show :: Disclosure -> String
$cshowList :: [Disclosure] -> ShowS
showList :: [Disclosure] -> ShowS
Show, (forall x. Disclosure -> Rep Disclosure x)
-> (forall x. Rep Disclosure x -> Disclosure) -> Generic Disclosure
forall x. Rep Disclosure x -> Disclosure
forall x. Disclosure -> Rep Disclosure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Disclosure -> Rep Disclosure x
from :: forall x. Disclosure -> Rep Disclosure x
$cto :: forall x. Rep Disclosure x -> Disclosure
to :: forall x. Rep Disclosure x -> Disclosure
Generic)

-- | Encoded disclosure (base64url string)
newtype EncodedDisclosure = EncodedDisclosure { EncodedDisclosure -> Text
unEncodedDisclosure :: Text }
  deriving stock (EncodedDisclosure -> EncodedDisclosure -> Bool
(EncodedDisclosure -> EncodedDisclosure -> Bool)
-> (EncodedDisclosure -> EncodedDisclosure -> Bool)
-> Eq EncodedDisclosure
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: EncodedDisclosure -> EncodedDisclosure -> Bool
== :: EncodedDisclosure -> EncodedDisclosure -> Bool
$c/= :: EncodedDisclosure -> EncodedDisclosure -> Bool
/= :: EncodedDisclosure -> EncodedDisclosure -> Bool
Eq, Int -> EncodedDisclosure -> ShowS
[EncodedDisclosure] -> ShowS
EncodedDisclosure -> String
(Int -> EncodedDisclosure -> ShowS)
-> (EncodedDisclosure -> String)
-> ([EncodedDisclosure] -> ShowS)
-> Show EncodedDisclosure
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> EncodedDisclosure -> ShowS
showsPrec :: Int -> EncodedDisclosure -> ShowS
$cshow :: EncodedDisclosure -> String
show :: EncodedDisclosure -> String
$cshowList :: [EncodedDisclosure] -> ShowS
showList :: [EncodedDisclosure] -> ShowS
Show, (forall x. EncodedDisclosure -> Rep EncodedDisclosure x)
-> (forall x. Rep EncodedDisclosure x -> EncodedDisclosure)
-> Generic EncodedDisclosure
forall x. Rep EncodedDisclosure x -> EncodedDisclosure
forall x. EncodedDisclosure -> Rep EncodedDisclosure x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. EncodedDisclosure -> Rep EncodedDisclosure x
from :: forall x. EncodedDisclosure -> Rep EncodedDisclosure x
$cto :: forall x. Rep EncodedDisclosure x -> EncodedDisclosure
to :: forall x. Rep EncodedDisclosure x -> EncodedDisclosure
Generic)

-- | Key Binding information from cnf claim
--
-- The public key is stored as a JWK JSON string (Text), which is compatible
-- with 'SDJWT.Internal.JWT.JWKLike'. This allows users to work with JWKs
-- without requiring a direct dependency on the jose library.
newtype KeyBindingInfo = KeyBindingInfo
  { KeyBindingInfo -> Text
kbPublicKey :: Text  -- ^ Holder's public key from cnf claim (JWK JSON string)
  }
  deriving stock (KeyBindingInfo -> KeyBindingInfo -> Bool
(KeyBindingInfo -> KeyBindingInfo -> Bool)
-> (KeyBindingInfo -> KeyBindingInfo -> Bool) -> Eq KeyBindingInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: KeyBindingInfo -> KeyBindingInfo -> Bool
== :: KeyBindingInfo -> KeyBindingInfo -> Bool
$c/= :: KeyBindingInfo -> KeyBindingInfo -> Bool
/= :: KeyBindingInfo -> KeyBindingInfo -> Bool
Eq, Int -> KeyBindingInfo -> ShowS
[KeyBindingInfo] -> ShowS
KeyBindingInfo -> String
(Int -> KeyBindingInfo -> ShowS)
-> (KeyBindingInfo -> String)
-> ([KeyBindingInfo] -> ShowS)
-> Show KeyBindingInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> KeyBindingInfo -> ShowS
showsPrec :: Int -> KeyBindingInfo -> ShowS
$cshow :: KeyBindingInfo -> String
show :: KeyBindingInfo -> String
$cshowList :: [KeyBindingInfo] -> ShowS
showList :: [KeyBindingInfo] -> ShowS
Show, (forall x. KeyBindingInfo -> Rep KeyBindingInfo x)
-> (forall x. Rep KeyBindingInfo x -> KeyBindingInfo)
-> Generic KeyBindingInfo
forall x. Rep KeyBindingInfo x -> KeyBindingInfo
forall x. KeyBindingInfo -> Rep KeyBindingInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. KeyBindingInfo -> Rep KeyBindingInfo x
from :: forall x. KeyBindingInfo -> Rep KeyBindingInfo x
$cto :: forall x. Rep KeyBindingInfo x -> KeyBindingInfo
to :: forall x. Rep KeyBindingInfo x -> KeyBindingInfo
Generic)

-- | SD-JWT payload structure
-- Note: This is a simplified representation. The actual payload
-- is a JSON object with _sd arrays and ... objects for arrays.
data SDJWTPayload = SDJWTPayload
  { SDJWTPayload -> Maybe HashAlgorithm
sdAlg :: Maybe HashAlgorithm  -- ^ _sd_alg claim
  , SDJWTPayload -> Value
payloadValue :: Value  -- ^ The actual JSON payload
  }
  deriving stock (SDJWTPayload -> SDJWTPayload -> Bool
(SDJWTPayload -> SDJWTPayload -> Bool)
-> (SDJWTPayload -> SDJWTPayload -> Bool) -> Eq SDJWTPayload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDJWTPayload -> SDJWTPayload -> Bool
== :: SDJWTPayload -> SDJWTPayload -> Bool
$c/= :: SDJWTPayload -> SDJWTPayload -> Bool
/= :: SDJWTPayload -> SDJWTPayload -> Bool
Eq, Int -> SDJWTPayload -> ShowS
[SDJWTPayload] -> ShowS
SDJWTPayload -> String
(Int -> SDJWTPayload -> ShowS)
-> (SDJWTPayload -> String)
-> ([SDJWTPayload] -> ShowS)
-> Show SDJWTPayload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SDJWTPayload -> ShowS
showsPrec :: Int -> SDJWTPayload -> ShowS
$cshow :: SDJWTPayload -> String
show :: SDJWTPayload -> String
$cshowList :: [SDJWTPayload] -> ShowS
showList :: [SDJWTPayload] -> ShowS
Show, (forall x. SDJWTPayload -> Rep SDJWTPayload x)
-> (forall x. Rep SDJWTPayload x -> SDJWTPayload)
-> Generic SDJWTPayload
forall x. Rep SDJWTPayload x -> SDJWTPayload
forall x. SDJWTPayload -> Rep SDJWTPayload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDJWTPayload -> Rep SDJWTPayload x
from :: forall x. SDJWTPayload -> Rep SDJWTPayload x
$cto :: forall x. Rep SDJWTPayload x -> SDJWTPayload
to :: forall x. Rep SDJWTPayload x -> SDJWTPayload
Generic)

-- | Complete SD-JWT structure (as issued)
data SDJWT = SDJWT
  { SDJWT -> Text
issuerSignedJWT :: Text  -- ^ The signed JWT (compact serialization)
  , SDJWT -> [EncodedDisclosure]
disclosures :: [EncodedDisclosure]  -- ^ All disclosures
  }
  deriving stock (SDJWT -> SDJWT -> Bool
(SDJWT -> SDJWT -> Bool) -> (SDJWT -> SDJWT -> Bool) -> Eq SDJWT
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDJWT -> SDJWT -> Bool
== :: SDJWT -> SDJWT -> Bool
$c/= :: SDJWT -> SDJWT -> Bool
/= :: SDJWT -> SDJWT -> Bool
Eq, Int -> SDJWT -> ShowS
[SDJWT] -> ShowS
SDJWT -> String
(Int -> SDJWT -> ShowS)
-> (SDJWT -> String) -> ([SDJWT] -> ShowS) -> Show SDJWT
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SDJWT -> ShowS
showsPrec :: Int -> SDJWT -> ShowS
$cshow :: SDJWT -> String
show :: SDJWT -> String
$cshowList :: [SDJWT] -> ShowS
showList :: [SDJWT] -> ShowS
Show, (forall x. SDJWT -> Rep SDJWT x)
-> (forall x. Rep SDJWT x -> SDJWT) -> Generic SDJWT
forall x. Rep SDJWT x -> SDJWT
forall x. SDJWT -> Rep SDJWT x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDJWT -> Rep SDJWT x
from :: forall x. SDJWT -> Rep SDJWT x
$cto :: forall x. Rep SDJWT x -> SDJWT
to :: forall x. Rep SDJWT x -> SDJWT
Generic)

-- | SD-JWT presentation (with selected disclosures)
data SDJWTPresentation = SDJWTPresentation
  { SDJWTPresentation -> Text
presentationJWT :: Text
  , SDJWTPresentation -> [EncodedDisclosure]
selectedDisclosures :: [EncodedDisclosure]
  , SDJWTPresentation -> Maybe Text
keyBindingJWT :: Maybe Text  -- ^ KB-JWT if present
  }
  deriving stock (SDJWTPresentation -> SDJWTPresentation -> Bool
(SDJWTPresentation -> SDJWTPresentation -> Bool)
-> (SDJWTPresentation -> SDJWTPresentation -> Bool)
-> Eq SDJWTPresentation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDJWTPresentation -> SDJWTPresentation -> Bool
== :: SDJWTPresentation -> SDJWTPresentation -> Bool
$c/= :: SDJWTPresentation -> SDJWTPresentation -> Bool
/= :: SDJWTPresentation -> SDJWTPresentation -> Bool
Eq, Int -> SDJWTPresentation -> ShowS
[SDJWTPresentation] -> ShowS
SDJWTPresentation -> String
(Int -> SDJWTPresentation -> ShowS)
-> (SDJWTPresentation -> String)
-> ([SDJWTPresentation] -> ShowS)
-> Show SDJWTPresentation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SDJWTPresentation -> ShowS
showsPrec :: Int -> SDJWTPresentation -> ShowS
$cshow :: SDJWTPresentation -> String
show :: SDJWTPresentation -> String
$cshowList :: [SDJWTPresentation] -> ShowS
showList :: [SDJWTPresentation] -> ShowS
Show, (forall x. SDJWTPresentation -> Rep SDJWTPresentation x)
-> (forall x. Rep SDJWTPresentation x -> SDJWTPresentation)
-> Generic SDJWTPresentation
forall x. Rep SDJWTPresentation x -> SDJWTPresentation
forall x. SDJWTPresentation -> Rep SDJWTPresentation x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. SDJWTPresentation -> Rep SDJWTPresentation x
from :: forall x. SDJWTPresentation -> Rep SDJWTPresentation x
$cto :: forall x. Rep SDJWTPresentation x -> SDJWTPresentation
to :: forall x. Rep SDJWTPresentation x -> SDJWTPresentation
Generic)

-- | Processed SD-JWT payload (after verification)
data ProcessedSDJWTPayload = ProcessedSDJWTPayload
  { ProcessedSDJWTPayload -> Object
processedClaims :: Object  -- ^ Processed claims as a JSON object
  , ProcessedSDJWTPayload -> Maybe KeyBindingInfo
keyBindingInfo :: Maybe KeyBindingInfo  -- ^ Key binding information if KB-JWT was present and verified
  }
  deriving stock (ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool
(ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool)
-> (ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool)
-> Eq ProcessedSDJWTPayload
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool
== :: ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool
$c/= :: ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool
/= :: ProcessedSDJWTPayload -> ProcessedSDJWTPayload -> Bool
Eq, Int -> ProcessedSDJWTPayload -> ShowS
[ProcessedSDJWTPayload] -> ShowS
ProcessedSDJWTPayload -> String
(Int -> ProcessedSDJWTPayload -> ShowS)
-> (ProcessedSDJWTPayload -> String)
-> ([ProcessedSDJWTPayload] -> ShowS)
-> Show ProcessedSDJWTPayload
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> ProcessedSDJWTPayload -> ShowS
showsPrec :: Int -> ProcessedSDJWTPayload -> ShowS
$cshow :: ProcessedSDJWTPayload -> String
show :: ProcessedSDJWTPayload -> String
$cshowList :: [ProcessedSDJWTPayload] -> ShowS
showList :: [ProcessedSDJWTPayload] -> ShowS
Show, (forall x. ProcessedSDJWTPayload -> Rep ProcessedSDJWTPayload x)
-> (forall x. Rep ProcessedSDJWTPayload x -> ProcessedSDJWTPayload)
-> Generic ProcessedSDJWTPayload
forall x. Rep ProcessedSDJWTPayload x -> ProcessedSDJWTPayload
forall x. ProcessedSDJWTPayload -> Rep ProcessedSDJWTPayload x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. ProcessedSDJWTPayload -> Rep ProcessedSDJWTPayload x
from :: forall x. ProcessedSDJWTPayload -> Rep ProcessedSDJWTPayload x
$cto :: forall x. Rep ProcessedSDJWTPayload x -> ProcessedSDJWTPayload
to :: forall x. Rep ProcessedSDJWTPayload x -> ProcessedSDJWTPayload
Generic)

-- | SD-JWT errors
data SDJWTError
  = InvalidDisclosureFormat Text
  | InvalidDigest Text
  | MissingDisclosure Text
  | DuplicateDisclosure Text
  | InvalidSignature Text
  | InvalidKeyBinding Text
  | InvalidHashAlgorithm Text
  | InvalidClaimName Text
  | SaltGenerationError Text
  | JSONParseError Text
  | SerializationError Text
  | VerificationError Text
  deriving stock (SDJWTError -> SDJWTError -> Bool
(SDJWTError -> SDJWTError -> Bool)
-> (SDJWTError -> SDJWTError -> Bool) -> Eq SDJWTError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SDJWTError -> SDJWTError -> Bool
== :: SDJWTError -> SDJWTError -> Bool
$c/= :: SDJWTError -> SDJWTError -> Bool
/= :: SDJWTError -> SDJWTError -> Bool
Eq, Int -> SDJWTError -> ShowS
[SDJWTError] -> ShowS
SDJWTError -> String
(Int -> SDJWTError -> ShowS)
-> (SDJWTError -> String)
-> ([SDJWTError] -> ShowS)
-> Show SDJWTError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SDJWTError -> ShowS
showsPrec :: Int -> SDJWTError -> ShowS
$cshow :: SDJWTError -> String
show :: SDJWTError -> String
$cshowList :: [SDJWTError] -> ShowS
showList :: [SDJWTError] -> ShowS
Show)