1.1.1 • Published 4 years ago

@devoxa/paddle-webhook-verification v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Installation

yarn add @devoxa/paddle-webhook-verification

Usage

You can use this module as just a verification function for your post body:

import { verify } from '@devoxa/paddle-webhook-verification'

const publicKey = `-----BEGIN PUBLIC KEY-----
...
-----END PUBLIC KEY-----`

const postBody = {
  alert_id: '970782801',
  // ...
  p_signature: 'avXxYVv9gQ...EyU9o430N0=',
}

const isVerified = verify(publicKey, postBody)

You can also use it as a type guard:

if (verify(publicKey, postBody)) {
  switch (postBody.alert_name) {
    case 'subscription_created':
      // postBody is typed as PaddleSubscriptionCreatedEvent
      break
  }
} else {
  throw new Error('Failed verification of post body')
}

:warning: To discriminate the returned union based on alert_name, you have to use a switch statement. if statements will not work until this PR has been merged into TypeScript.

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT

1.1.1

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago