helpers: add comments on dkim

This commit is contained in:
Saleel
2024-04-03 14:26:31 +05:30
parent 437eb363b2
commit eeac9bb7a1
2 changed files with 10 additions and 3 deletions

View File

@@ -6,7 +6,7 @@ import sanitizers from "./sanitizers";
export interface DKIMVerificationResult {
publicKey: bigint;
signature: bigint;
message: Buffer;
headers: Buffer;
body: Buffer;
bodyHash: string;
signingDomain: string;
@@ -17,6 +17,13 @@ export interface DKIMVerificationResult {
appliedSanitization?: string;
}
/**
*
* @param email Entire email data as a string or buffer
* @param domain Domain to verify DKIM signature for. If not provided, the domain is extracted from the `From` header
* @param enableSanitization If true, email will be applied with various sanitization to try and pass DKIM verification
* @returns
*/
export async function verifyDKIMSignature(
email: Buffer | string,
domain: string = "",
@@ -76,7 +83,7 @@ export async function verifyDKIMSignature(
return {
signature: BigInt("0x" + Buffer.from(signature, "base64").toString("hex")),
message: status.signature_header,
headers: status.signature_header,
body: body,
bodyHash: bodyHash,
signingDomain: dkimResult.signingDomain,

View File

@@ -40,7 +40,7 @@ function removeLabels(email: string): string {
// Sometimes, newline encodings re-encode \r\n as just \n, so re-insert the \r
// TODO: Add test for this
export function insert13Before10(email: string): string {
function insert13Before10(email: string): string {
const byteArray = new TextEncoder().encode(email);
const ret = new Uint8Array(byteArray.length + 1000);