ts/features/itwallet/machine/credential/guards.ts
import { pipe } from "fp-ts/lib/function";
import * as O from "fp-ts/lib/Option";
import { ItwSessionExpiredError } from "../../api/client";
import { isWalletInstanceAttestationValid } from "../../common/utils/itwAttestationUtils";
import { Context } from "./context";
import { CredentialIssuanceEvents } from "./events";
export const createCredentialIssuanceGuardsImplementation = () => ({
isSessionExpired: ({ event }: { event: CredentialIssuanceEvents }) =>
"error" in event && event.error instanceof ItwSessionExpiredError,
hasValidWalletInstanceAttestation: ({ context }: { context: Context }) =>
pipe(
O.fromNullable(context.walletInstanceAttestation),
O.map(isWalletInstanceAttestationValid),
O.getOrElse(() => false)
)
});