Class: Virgil::SDK::Client::Requests::SignableRequest
- Inherits:
-
Object
- Object
- Virgil::SDK::Client::Requests::SignableRequest
- Defined in:
- lib/virgil/sdk/client/requests/signable_request.rb
Overview
Base class for all cards API requests.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
-
#signatures ⇒ Object
readonly
Returns the value of attribute signatures.
-
#snapshot ⇒ Object
readonly
Request data snapshot.
-
#validation_token ⇒ Object
readonly
Returns the value of attribute validation_token.
Instance Method Summary collapse
-
#export ⇒ String
Exports request snapshot.
-
#initialize ⇒ SignableRequest
constructor
Constructs new SignableRequest object.
-
#request_model ⇒ Object
Request model used for json representation.
-
#restore(snapshot, signatures, validation_token = nil, relations = nil) ⇒ SignableRequest
Restores request from snapshot.
-
#restore_from_snapshot_model(snapshot) ⇒ Object
Restores request from snapshot model.
-
#sign_with(fingerprint_id, signature) ⇒ Object
Adds signature to request.
-
#snapshot_model ⇒ Object
Constructs snapshot model for exporting and signing.
-
#take_snapshot ⇒ Object
Takes request data snapshot.
Constructor Details
#initialize ⇒ SignableRequest
Constructs new Virgil::SDK::Client::Requests::SignableRequest object
48 49 50 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 48 def initialize @signatures = {} end |
Instance Attribute Details
#relations ⇒ Object (readonly)
Returns the value of attribute relations
44 45 46 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 44 def relations @relations end |
#signatures ⇒ Object (readonly)
Returns the value of attribute signatures
44 45 46 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 44 def signatures @signatures end |
#snapshot ⇒ Object (readonly)
Request data snapshot
103 104 105 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 103 def snapshot @snapshot end |
#validation_token ⇒ Object (readonly)
Returns the value of attribute validation_token
44 45 46 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 44 def validation_token @validation_token end |
Instance Method Details
#export ⇒ String
Exports request snapshot.
96 97 98 99 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 96 def export json_string = self.request_model.to_json Base64.strict_encode64(json_string) end |
#request_model ⇒ Object
Request model used for json representation.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 113 def request_model model = { 'content_snapshot': Base64.strict_encode64(snapshot.to_s), 'meta': { 'signs': signatures } } if validation_token model[:meta][:validation] = {'token': validation_token.value} end if relations model[:meta][:relations] = relations end return model end |
#restore(snapshot, signatures, validation_token = nil, relations = nil) ⇒ SignableRequest
Restores request from snapshot.
76 77 78 79 80 81 82 83 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 76 def restore(snapshot, signatures, validation_token = nil, relations = nil) @snapshot = snapshot @signatures = signatures @validation_token = validation_token @relations = relations model = JSON.parse(Crypto::Bytes.new(snapshot).to_s) restore_from_snapshot_model(model) end |
#restore_from_snapshot_model(snapshot) ⇒ Object
Restores request from snapshot model.
Should be implemented in the derived classes.
65 66 67 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 65 def restore_from_snapshot_model(snapshot) raise NotImplementedError.new end |
#sign_with(fingerprint_id, signature) ⇒ Object
Adds signature to request.
108 109 110 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 108 def sign_with(fingerprint_id, signature) @signatures[fingerprint_id] = signature end |
#snapshot_model ⇒ Object
Constructs snapshot model for exporting and signing.
Should be implemented in the derived classes.
56 57 58 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 56 def snapshot_model raise NotImplementedError.new end |
#take_snapshot ⇒ Object
Takes request data snapshot.
Request snapshot bytes.
88 89 90 91 |
# File 'lib/virgil/sdk/client/requests/signable_request.rb', line 88 def take_snapshot json_string = self.snapshot_model.to_json Crypto::Bytes.from_string(json_string) end |