/** One recipient and the variables their message is rendered with. */ export interface CampaignReceiver { /** The recipient's number, digits only, no `+` and no separators. */ waba: string; /** * Per-recipient template variables, as the manager expects them: a flat list of * `{id, value}` rather than an object, because the ids come from CSV headers * and are not safe as object keys. */ custom_fields: { id: string; value: string; }[]; } /** An encrypted receiver file, ready to upload. */ export interface ReceiverFile { /** Base64 AES ciphertext. This is the entire file body. */ body: string; /** The secret the file was encrypted under. Stored on the campaign as `hash`. */ secret: string; filename: string; contentType: 'text/plain'; /** Byte length of `body`, which the upload ticket is signed against. */ size: number; /** How many recipients the file contains. */ receivers: number; } /** * A fresh secret for one receiver file. * * Sixteen random bytes as hex -- thirty-two characters, which is the shape * already in the field and what the `hash` field on a stored campaign holds. * * The legacy frontend generated this as 16 random bytes, hex-encoded, then * applied `.toString('base64url').replace(/_/gi,'U').replace(/-/gi,'D')`. That * chain is a **no-op**: `String.prototype.toString` ignores its argument and * returns the string unchanged, and the hex alphabet contains no `_` or `-` for * the replacements to find. So the value that reaches the manager has always been * plain hex, and this produces the identical thing without the dead code. * * One secret per file, never reused. That is what keeps the fixed IV above from * being the flaw it would otherwise be. */ export declare const generateReceiverSecret: () => string; /** * Encrypts the receiver list exactly as the campaign manager expects to read it. * * ``` * key = md5(secret) -- 32 lower-case hex characters * key bytes = the ASCII bytes of that hex -- 32 bytes, so AES-256 * iv = ASCII bytes of '678025308de70905' * ciphertext = AES-256-CBC, PKCS#7 padded * file body = base64(ciphertext) * ``` * * Two parts of that are counter-intuitive and both are deliberate, because they * mirror what `CryptoJS.AES.encrypt(text, keyWordArray, {iv})` does: * * - **The key is the hex *text*, not the digest bytes.** `md5()` returns a * 32-character string and it is parsed as UTF-8, which lands on 32 bytes and * therefore AES-256. Using the 16 raw digest bytes instead would be AES-128 and * would not decrypt. * - **There is no `Salted__` header.** CryptoJS only writes one when it derives a * key from a passphrase. Given a key directly, as here, its default formatter * emits bare base64 of the ciphertext. * * Web Crypto applies PKCS#7 padding to AES-CBC itself, which is the same padding * CryptoJS defaults to -- so the outputs are byte-identical. */ export declare const encryptReceivers: (plaintext: string, secret: string) => Promise; /** * The two plaintext encodings a receiver file can hold. * * They are not interchangeable and the reading side picks by campaign type, so * the wrong one produces a file that decrypts cleanly and then parses to * nothing: * * - **`json`** -- `[{waba, custom_fields: [{id, value}]}, …]`. What a bulk * campaign's single file holds. * - **`table`** -- a `||`-delimited table with a header row. What each bucket of * a group campaign holds: * * ``` * waba||first_name||amount * 919000000001||Priya||1299 * 919000000002||Ravi||499 * ``` * * The table form is narrower than the JSON one: every row has to carry the same * columns in the same order, and a value cannot contain a newline -- so newlines * are stripped from values rather than escaped, which is what the panel did. * Columns are taken from the first receiver, because a header can only be * written once. */ export type ReceiverEncoding = 'json' | 'table'; /** The `||` table a group campaign's bucket file holds. */ export declare const encodeReceiverTable: (receivers: readonly CampaignReceiver[]) => string; /** * Turns a receiver list into the encrypted file that gets uploaded. * * The filename is cosmetic: the media service stores the object under a uuid and * keeps only the extension and the display name. The `im_` prefix and `.txt` * extension match what is already in the bucket, so an operator browsing storage * sees one consistent kind of object. */ export declare const buildReceiverFile: (receivers: CampaignReceiver[], encoding?: ReceiverEncoding) => Promise;