| 1 | import type * as paymentcryptographydata from "@distilled.cloud/aws/payment-cryptography-data"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Key } from "./Key.ts"; |
| 5 | |
| 6 | export interface VerifyPinDataRequest extends Omit< |
| 7 | paymentcryptographydata.VerifyPinDataInput, |
| 8 | "VerificationKeyIdentifier" | "EncryptionKeyIdentifier" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `payment-cryptography:VerifyPinData` — verifies an |
| 13 | * encrypted PIN block against PIN verification data (e.g. a Visa PVV) using |
| 14 | * a PIN verification {@link Key} (PVK) and the PIN encryption {@link Key} |
| 15 | * (PEK) the block is encrypted under. A mismatch fails with the typed |
| 16 | * `VerificationFailedException`. Provide `VerifyPinDataHttp` on the Function |
| 17 | * to satisfy this service. |
| 18 | * ### PIN Data |
| 19 | * **Example:** Verify a cardholder PIN with a Visa PVV |
| 20 | * ```typescript |
| 21 | * // init |
| 22 | * const verifyPin = yield* PaymentCryptography.VerifyPinData(pvk, pek); |
| 23 | * |
| 24 | * // runtime |
| 25 | * const outcome = yield* verifyPin({ |
| 26 | * VerificationAttributes: { |
| 27 | * VisaPin: { PinVerificationKeyIndex: 1, VerificationValue: pvv }, |
| 28 | * }, |
| 29 | * EncryptedPinBlock: encryptedPinBlock, |
| 30 | * PrimaryAccountNumber: "9123456789012345", |
| 31 | * PinBlockFormat: "ISO_FORMAT_0", |
| 32 | * }).pipe( |
| 33 | * Effect.map(() => "valid"), |
| 34 | * Effect.catchTag("VerificationFailedException", () => |
| 35 | * Effect.succeed("invalid"), |
| 36 | * ), |
| 37 | * ); |
| 38 | * ``` |
| 39 | * |
| 40 | * @binding |
| 41 | */ |
| 42 | export interface VerifyPinData extends Binding.Service< |
| 43 | VerifyPinData, |
| 44 | "AWS.PaymentCryptography.VerifyPinData", |
| 45 | <V extends Key, E extends Key>( |
| 46 | verificationKey: V, |
| 47 | encryptionKey: E, |
| 48 | ) => Effect.Effect< |
| 49 | ( |
| 50 | request: VerifyPinDataRequest, |
| 51 | ) => Effect.Effect< |
| 52 | paymentcryptographydata.VerifyPinDataOutput, |
| 53 | paymentcryptographydata.VerifyPinDataError |
| 54 | > |
| 55 | > |
| 56 | > {} |
| 57 | |
| 58 | export const VerifyPinData = Binding.Service<VerifyPinData>( |
| 59 | "AWS.PaymentCryptography.VerifyPinData", |
| 60 | ); |