Module: CoinbaseCommerceClient::Webhook::WebhookSignature

Defined in:
lib/coinbase_commerce_client/webhooks.rb

Class Method Summary collapse

Class Method Details

.verify_header(payload, sig_header, secret) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/coinbase_commerce_client/webhooks.rb', line 14

def self.verify_header(payload, sig_header, secret)
  unless [payload, sig_header, secret].all?
    raise CoinbaseCommerceClient::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 CoinbaseCommerceClient::Errors::SignatureVerificationError.new(
      "No signatures found matching the expected signature for payload",
      sig_header, http_body: payload
    )
  end
  true
end