diff --git a/types/dkim-signer/dkim-signer-tests.ts b/types/dkim-signer/dkim-signer-tests.ts new file mode 100644 index 0000000000..4d3bf1c6aa --- /dev/null +++ b/types/dkim-signer/dkim-signer-tests.ts @@ -0,0 +1,16 @@ +import { DKIMSign, DKIMSignOptions } from "dkim-signer"; +import * as fs from "fs"; + +// generate a RFC822 message +const rfc822message = "Subject: test\r\n\r\nHello world"; + +// setup DKIM options +const dkimOptions: DKIMSignOptions = { + domainName: "müriaad-polüteism.info", + keySelector: "dkim", + privateKey: fs.readFileSync("./test_private.pem") +}; + +// generate signature header field +// $ExpectType string +DKIMSign(rfc822message, dkimOptions); diff --git a/types/dkim-signer/index.d.ts b/types/dkim-signer/index.d.ts new file mode 100644 index 0000000000..6828981649 --- /dev/null +++ b/types/dkim-signer/index.d.ts @@ -0,0 +1,40 @@ +// Type definitions for dkim-signer 0.2 +// Project: https://github.com/andris9/dkim-signer +// Definitions by: Piotr Roszatycki +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as crypto from "crypto"; + +export interface DKIMSignOptions { + /** Header fields to sign (ie: 'from:to:cc:subject') */ + headerFieldNames?: string; + /** DKIM private key */ + privateKey: crypto.SignPrivateKeyInput | crypto.KeyLike; + /** Domain name to use for signing (ie: 'domain.com') */ + domainName: string; + /** Selector for the DKMI public key (ie. 'dkim' if you have set up a TXT record for 'dkim._domainkey.domain.com') */ + keySelector: string; +} + +/** Sign an email with provided DKIM key, uses RSA-SHA256. */ +export function DKIMSign(email: Buffer | string, options: DKIMSignOptions): string; + +/** Generates a DKIM-Signature header field without the signature part ('b=' is empty) */ +export function generateDKIMHeader(domainName: string, keySelector: string, headerFieldNames: string, headers: string, body: string): string; + +/** Generates a SHA-256 hash */ +export function sha256(str: string, encoding?: crypto.HexBase64Latin1Encoding): string; + +/** DKIM canonicalization functions */ +export namespace DKIMCanonicalizer { + /** Simple body canonicalization by rfc4871 #3.4.3 */ + function simpleBody(body: string): string; + /** Relaxed body canonicalization by rfc4871 #3.4.4 */ + function relaxedBody(body: string): string; + /** Relaxed headers canonicalization by rfc4871 #3.4.2 with filtering */ + function relaxedHeaders(headers: string, fieldNames?: string): { headers: string, fieldNames: string }; + /** Relaxed header canonicalization for single header line */ + function relaxedHeaderLine(line: string): { key: string, value: string }; +} diff --git a/types/dkim-signer/tsconfig.json b/types/dkim-signer/tsconfig.json new file mode 100644 index 0000000000..dbabb3d05e --- /dev/null +++ b/types/dkim-signer/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "dkim-signer-tests.ts" + ] +} diff --git a/types/dkim-signer/tslint.json b/types/dkim-signer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/dkim-signer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }