| 1 | import * as paymentcryptographydata from "@distilled.cloud/aws/payment-cryptography-data"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { makePaymentCryptographyKeyHttpBinding } from "./BindingHttp.ts"; |
| 4 | import { VerifyMac } from "./VerifyMac.ts"; |
| 5 | |
| 6 | /** |
| 7 | * HTTP implementation of {@link VerifyMac} — grants the host Function |
| 8 | * `payment-cryptography:VerifyMac` on the key and calls the |
| 9 | * Payment Cryptography Data API at runtime. A MAC mismatch fails with the |
| 10 | * typed `VerificationFailedException`. |
| 11 | * @example Provide on a Lambda Function |
| 12 | * ```typescript |
| 13 | * Effect.gen(function* () { |
| 14 | * const macKey = yield* PaymentCryptography.Key("MacKey", { ... }); |
| 15 | * const verifyMac = yield* PaymentCryptography.VerifyMac(macKey); |
| 16 | * |
| 17 | * return { |
| 18 | * fetch: Effect.gen(function* () { |
| 19 | * const result = yield* verifyMac({ |
| 20 | * MessageData: messageDataHex, |
| 21 | * Mac: mac, |
| 22 | * VerificationAttributes: { Algorithm: "HMAC" }, |
| 23 | * }).pipe( |
| 24 | * Effect.map(() => "verified"), |
| 25 | * Effect.catchTag("VerificationFailedException", () => |
| 26 | * Effect.succeed("verification-failed"), |
| 27 | * ), |
| 28 | * ); |
| 29 | * // ... |
| 30 | * }), |
| 31 | * }; |
| 32 | * }).pipe(Effect.provide(PaymentCryptography.VerifyMacHttp)) |
| 33 | * ``` |
| 34 | */ |
| 35 | export const VerifyMacHttp = Layer.effect( |
| 36 | VerifyMac, |
| 37 | makePaymentCryptographyKeyHttpBinding({ |
| 38 | tag: "AWS.PaymentCryptography.VerifyMac", |
| 39 | operation: paymentcryptographydata.verifyMac, |
| 40 | actions: ["payment-cryptography:VerifyMac"], |
| 41 | }), |
| 42 | ); |