Class: Cryptopay::Callbacks
- Inherits:
-
Object
- Object
- Cryptopay::Callbacks
- Defined in:
- lib/cryptopay/callbacks.rb
Instance Method Summary collapse
-
#initialize(secret) ⇒ Callbacks
constructor
A new instance of Callbacks.
-
#verify(body, signature) ⇒ Object
Verifies callback body and builds Callback object.
Constructor Details
#initialize(secret) ⇒ Callbacks
Returns a new instance of Callbacks.
5 6 7 |
# File 'lib/cryptopay/callbacks.rb', line 5 def initialize(secret) @secret = secret end |
Instance Method Details
#verify(body, signature) ⇒ Object
Verifies callback body and builds Callback object
13 14 15 16 17 18 19 20 21 |
# File 'lib/cryptopay/callbacks.rb', line 13 def verify(body, signature) expected_signature = OpenSSL::HMAC.hexdigest('SHA256', secret, body) equals = secure_compare(signature, expected_signature) raise(SignatureVerificationError, 'Signature mismatch') unless equals data = JSON.parse(body, symbolize_names: true) Callback.build_from_hash(data) end |