| 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 ReEncryptDataRequest extends Omit< |
| 7 | paymentcryptographydata.ReEncryptDataInput, |
| 8 | "IncomingKeyIdentifier" | "OutgoingKeyIdentifier" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `payment-cryptography:ReEncryptData` — decrypts |
| 13 | * ciphertext under the incoming {@link Key} and re-encrypts it under the |
| 14 | * outgoing {@link Key} entirely inside the service; the plaintext never |
| 15 | * leaves AWS Payment Cryptography. At least one side must be a DUKPT Base |
| 16 | * Derivation Key or a dynamic (TR-31 wrapped) key — the service rejects |
| 17 | * plain symmetric-to-symmetric re-encryption with |
| 18 | * `ValidationException: KeyUsages not allowed for this operation`. Provide |
| 19 | * `ReEncryptDataHttp` on the Function to satisfy this service. |
| 20 | * ### Re-Encrypting Data |
| 21 | * **Example:** Translate DUKPT terminal ciphertext to a working key |
| 22 | * ```typescript |
| 23 | * // init — incoming BDK, outgoing symmetric data key |
| 24 | * const reEncrypt = yield* PaymentCryptography.ReEncryptData(bdk, workingKey); |
| 25 | * |
| 26 | * // runtime |
| 27 | * const translated = yield* reEncrypt({ |
| 28 | * CipherText: dukptCipherTextHex, |
| 29 | * IncomingEncryptionAttributes: { |
| 30 | * Dukpt: { KeySerialNumber: ksn, Mode: "CBC" }, |
| 31 | * }, |
| 32 | * OutgoingEncryptionAttributes: { |
| 33 | * Symmetric: { Mode: "CBC", InitializationVector: iv }, |
| 34 | * }, |
| 35 | * }); |
| 36 | * ``` |
| 37 | * |
| 38 | * @binding |
| 39 | */ |
| 40 | export interface ReEncryptData extends Binding.Service< |
| 41 | ReEncryptData, |
| 42 | "AWS.PaymentCryptography.ReEncryptData", |
| 43 | <In extends Key, Out extends Key>( |
| 44 | incomingKey: In, |
| 45 | outgoingKey: Out, |
| 46 | ) => Effect.Effect< |
| 47 | ( |
| 48 | request: ReEncryptDataRequest, |
| 49 | ) => Effect.Effect< |
| 50 | paymentcryptographydata.ReEncryptDataOutput, |
| 51 | paymentcryptographydata.ReEncryptDataError |
| 52 | > |
| 53 | > |
| 54 | > {} |
| 55 | |
| 56 | export const ReEncryptData = Binding.Service<ReEncryptData>( |
| 57 | "AWS.PaymentCryptography.ReEncryptData", |
| 58 | ); |