hisend 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hisend/webhook.rb +47 -0
  3. data/lib/hisend.rb +1 -0
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8cf15bd446a532daa5f3d6037ba959697017299c1ab53d9e0d0d5428b2607ae
4
- data.tar.gz: b105cc09f5cd95fbf0f05ba0121c859ff21bae60cfa2a36653f71773711a9666
3
+ metadata.gz: 933abf8d75845cc7d2263d3fb6fcfd837e38a0a8efbe54f72473b2f4679bec47
4
+ data.tar.gz: 24b118ff75d7d37503d2aca0b7a4ac08f721e90d55f82d40ed196e7d1eccd784
5
5
  SHA512:
6
- metadata.gz: 4bde86c3c218112b8a668f2315d5f27f8ff9c9aca7e38675c2760ca632e73021b2c235a0fa3ddc3c0fc3ce806749159767e60e020f1edde36eb4358419e9048e
7
- data.tar.gz: 55b06063de5c084426cc5dd69898a9deb5dd33b80c5248df23a7ac15715efc5b6c698ca259c65924b5a7f6ff0796e47fc5aaf7e73a8613a3370b302b3d526e96
6
+ metadata.gz: 13ba139f58e303a6aeefb130395740b9403ea9781a12ea4b93de486c089c86003b551d7a0d13bd0ace5c434d85fbcfed0e8f982c01e9cbc039b54c51a6225319
7
+ data.tar.gz: 6fc1416bfc169cc2e83aaa2f5a6154904782c425da78f83ad51014a7acc2f872f6fb57387ee552b1a210abbd4b880a6dddc71da07594b8949e9ded70aafb5a5d
@@ -0,0 +1,47 @@
1
+ require 'openssl'
2
+
3
+ module Hisend
4
+ # Hisend Webhook signature verification helper.
5
+ #
6
+ # Example (Rails):
7
+ #
8
+ # class WebhooksController < ApplicationController
9
+ # skip_before_action :verify_authenticity_token
10
+ #
11
+ # def hisend
12
+ # payload = request.raw_post
13
+ # signature = request.headers['X-Hisend-Signature']
14
+ # secret = ENV['HISEND_WEBHOOK_SECRET']
15
+ #
16
+ # unless Hisend::Webhook.verify(payload, signature, secret)
17
+ # render json: { error: 'Invalid signature' }, status: :unauthorized
18
+ # return
19
+ # end
20
+ #
21
+ # event = JSON.parse(payload)
22
+ # head :ok
23
+ # end
24
+ # end
25
+ module Webhook
26
+ # Verify the HMAC-SHA256 signature of an incoming Hisend webhook.
27
+ #
28
+ # @param payload [String] Raw request body exactly as received.
29
+ # @param signature [String] Value of the X-Hisend-Signature header.
30
+ # @param secret [String] Your Webhook Signing Secret (starts with whsec_).
31
+ #
32
+ # @return [Boolean] true if the signature is valid, false otherwise.
33
+ def self.verify(payload, signature, secret)
34
+ return false if [payload, signature, secret].any?(&:nil?)
35
+ return false if payload.empty? || signature.empty? || secret.empty?
36
+
37
+ expected = OpenSSL::HMAC.hexdigest('SHA256', secret, payload)
38
+
39
+ # Rack / ActiveSupport provides secure_compare – fall back to plain == if unavailable.
40
+ if defined?(ActiveSupport::SecurityUtils)
41
+ ActiveSupport::SecurityUtils.secure_compare(expected, signature)
42
+ else
43
+ OpenSSL.fixed_length_secure_compare(expected, signature)
44
+ end
45
+ end
46
+ end
47
+ end
data/lib/hisend.rb CHANGED
@@ -8,6 +8,7 @@ require_relative 'hisend/resources/domains'
8
8
  require_relative 'hisend/resources/emails'
9
9
  require_relative 'hisend/resources/routing'
10
10
  require_relative 'hisend/resources/threads'
11
+ require_relative 'hisend/webhook'
11
12
 
12
13
  module Hisend
13
14
  # Entry point is Hisend::Client
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hisend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hisend
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-24 00:00:00.000000000 Z
11
+ date: 2026-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -37,6 +37,7 @@ files:
37
37
  - lib/hisend/resources/emails.rb
38
38
  - lib/hisend/resources/routing.rb
39
39
  - lib/hisend/resources/threads.rb
40
+ - lib/hisend/webhook.rb
40
41
  homepage: https://hisend.app
41
42
  licenses:
42
43
  - MIT