philiprehberger-webhook_builder 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +19 -0
- data/lib/philiprehberger/webhook_builder/client.rb +12 -0
- data/lib/philiprehberger/webhook_builder/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c3d746e099083b6d9da206ce5b4630ca0a4c5ee2c4f1f99373af3c992d89c38
|
|
4
|
+
data.tar.gz: 23ed5e8d7b8e40f27a71cf7f4cb42c91d501ef8a5028d39d0a77cd1d08a589be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7e503cd54a9fb91a78879f0ccd541a24b91a447ca30ba89c7d832a4c757d07de2a35e7c0066c8c0e13c01b130f6765afdc96b4b8e234c4ba60d492aba2d3e536
|
|
7
|
+
data.tar.gz: 6f9942dc1678940173ab109c17b236f83bf14087ed1dae8880f17a2703e8e89a87c2455e752ea7c9b6aff14f6992bd408db65bd46b0499729ec8644d27e7d561
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-22
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Client#signature_for(body:)` — compute the HMAC-SHA256 signature this client would send for a given body without performing a delivery.
|
|
14
|
+
|
|
10
15
|
## [0.3.0] - 2026-04-18
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -134,6 +134,24 @@ receiver.verify_signature(body: body, signature: signature) # => true
|
|
|
134
134
|
receiver.verify_signature(body: body, signature: "tampered") # => false
|
|
135
135
|
```
|
|
136
136
|
|
|
137
|
+
You can also compute the signature the client would send for a body without
|
|
138
|
+
performing a delivery — useful for preparing payloads offline or mirroring
|
|
139
|
+
`verify_signature`:
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
require "philiprehberger/webhook_builder"
|
|
143
|
+
|
|
144
|
+
client = Philiprehberger::WebhookBuilder.new(
|
|
145
|
+
url: "https://example.com/webhooks",
|
|
146
|
+
secret: "shared-signing-secret"
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
body = '{"event":"order.created","payload":{"id":1}}'
|
|
150
|
+
signature = client.signature_for(body: body)
|
|
151
|
+
|
|
152
|
+
client.verify_signature(body: body, signature: signature) # => true
|
|
153
|
+
```
|
|
154
|
+
|
|
137
155
|
### Delivery Tracking
|
|
138
156
|
|
|
139
157
|
```ruby
|
|
@@ -164,6 +182,7 @@ delivery.error # => nil or error message
|
|
|
164
182
|
| `#deliver(event:, payload:, headers:)` | Deliver a webhook event and return a Delivery |
|
|
165
183
|
| `#deliver_batch(events)` | Deliver multiple events concurrently and return an array of Delivery results |
|
|
166
184
|
| `#verify_signature(body:, signature:)` | Constant-time HMAC-SHA256 verification of an incoming signature; returns `true`/`false` and never raises |
|
|
185
|
+
| `#signature_for(body:)` | Compute the HMAC-SHA256 signature for a body without sending |
|
|
167
186
|
|
|
168
187
|
### `Delivery`
|
|
169
188
|
|
|
@@ -153,6 +153,18 @@ module Philiprehberger
|
|
|
153
153
|
OpenSSL.fixed_length_secure_compare(expected, signature)
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
+
# Compute the HMAC-SHA256 hex signature this client would send for the given body.
|
|
157
|
+
#
|
|
158
|
+
# Mirrors +verify_signature+: the signature returned by +signature_for(body:)+
|
|
159
|
+
# will verify against the same body. Useful when preparing payloads offline or
|
|
160
|
+
# re-computing signatures without sending a request.
|
|
161
|
+
#
|
|
162
|
+
# @param body [String] the raw request body
|
|
163
|
+
# @return [String] the hex-encoded HMAC signature
|
|
164
|
+
def signature_for(body:)
|
|
165
|
+
sign(body)
|
|
166
|
+
end
|
|
167
|
+
|
|
156
168
|
private
|
|
157
169
|
|
|
158
170
|
# Sign the request body with HMAC-SHA256.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-webhook_builder
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: A webhook delivery client that signs payloads with HMAC-SHA256, retries
|
|
14
14
|
failed deliveries with configurable backoff strategies, supports batch delivery,
|