Skip to content

Add Typescript typings #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export declare class MessageValidator {
encoding: string;
validate(hash: any, cb: (err: string, message: string) => any);
}
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,6 @@ MessageValidator.prototype.validate = function (hash, cb) {
validateSignature(hash, cb, this.encoding);
};

MessageValidator.MessageValidator = MessageValidator;

module.exports = MessageValidator;