diff --git a/README.md b/README.md index 8ed89f2..a7b4903 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ an error and the second being the successfully validated SNS message. The message validator checks the `SigningCertURL`, `SignatureVersion`, and `Signature` to make sure they are valid and consistent with the message data. +#### Javascript ```javascript var MessageValidator = require('sns-validator'), validator = new MessageValidator(); @@ -47,6 +48,21 @@ validator.validate(message, function (err, message) { }); ``` +#### Typescript +```typescript +import { MessageValidator } from "sns-validator" +const validator = new MessageValidator(); + +validator.validate(message, function (err, message) { + if (err) { + // Your message could not be validated. + return; + } + + // message has been validated and its signature checked. +}); +``` + ## Installation The SNS Message Validator relies on the Node crypto module and is only designed diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..7a38ddb --- /dev/null +++ b/index.d.ts @@ -0,0 +1,4 @@ +export declare class MessageValidator { + encoding: string; + validate(hash: any, cb: (err: string, message: string) => any); +} \ No newline at end of file diff --git a/index.js b/index.js index 6f2fcd5..46f91ab 100644 --- a/index.js +++ b/index.js @@ -213,4 +213,6 @@ MessageValidator.prototype.validate = function (hash, cb) { validateSignature(hash, cb, this.encoding); }; +MessageValidator.MessageValidator = MessageValidator; + module.exports = MessageValidator;