Module: Airwallex::Webhook
- Defined in:
- lib/airwallex/webhook.rb
Defined Under Namespace
Classes: Event
Constant Summary collapse
- DEFAULT_TOLERANCE =
5 minutes
300- MS_THRESHOLD =
Timestamps below this are seconds, at/above are milliseconds. Valid until year 2286.
10_000_000_000
Class Method Summary collapse
- .construct_event(payload, signature, timestamp, secret:, tolerance: DEFAULT_TOLERANCE) ⇒ Object
- .verify_signature(payload, signature, timestamp, secret, tolerance) ⇒ Object
Class Method Details
.construct_event(payload, signature, timestamp, secret:, tolerance: DEFAULT_TOLERANCE) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/airwallex/webhook.rb', line 13 def construct_event(payload, signature, , secret:, tolerance: DEFAULT_TOLERANCE) verify_signature(payload, signature, , secret, tolerance) data = JSON.parse(payload) Event.new(data) rescue JSON::ParserError => e raise SignatureVerificationError, "Invalid payload: #{e.}" end |
.verify_signature(payload, signature, timestamp, secret, tolerance) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/airwallex/webhook.rb', line 22 def verify_signature(payload, signature, , secret, tolerance) (, tolerance) expected_signature = compute_signature(, payload, secret) unless secure_compare(expected_signature, signature) raise SignatureVerificationError, "Signature verification failed" end true end |