Module: CoinbaseCommerce::Webhook::WebhookSignature

Defined in:
lib/coinbase_commerce/webhooks.rb

Class Method Summary collapse

Class Method Details

.verify_header(payload, sig_header, secret) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/coinbase_commerce/webhooks.rb', line 18

def self.verify_header(payload, sig_header, secret)
  unless [payload, sig_header, secret].all?
    raise CoinbaseCommerce::Errors::WebhookInvalidPayload.new(
        "Missing payload or signature",
        sig_header, http_body: payload)
  end
  expected_sig = compute_signature(payload, secret)
  unless secure_compare(expected_sig, sig_header)
    raise CoinbaseCommerce::Errors::SignatureVerificationError.new(
        "No signatures found matching the expected signature for payload",
        sig_header, http_body: payload
    )
  end
  true
end