Class: Virgil::SDK::HighLevel::VirgilCard
- Inherits:
-
Object
- Object
- Virgil::SDK::HighLevel::VirgilCard
- Defined in:
- lib/virgil/sdk/high_level/virgil_card.rb
Overview
A Virgil Card is the main entity of the Virgil Security services, it includes an information about the user and his public key. The Virgil Card identifies the user by one of his available types, such as an email, a phone number, etc.
Defined Under Namespace
Classes: AppCredentialsException
Instance Method Summary collapse
-
#check_identity(identity_options = nil) ⇒ VirgilIdentity::VerificationAttempt
Initiates an identity verification process for current Card identity type.
- #data ⇒ Object
- #device ⇒ Object
- #device_name ⇒ Object
-
#encrypt(buffer) ⇒ VirgilBuffer
Encrypts the specified data for current Virgil card recipient.
-
#export ⇒ String
Exports card's snapshot.
-
#id ⇒ String
unique identifier for the Virgil Card.
-
#identity ⇒ String
the value of current Virgil Card identity.
-
#identity_type ⇒ String
the identityType of current Virgil Card identity.
-
#initialize(context:, card:) ⇒ VirgilCard
constructor
Initializes a new instance of the VirgilCard class.
- #public_key ⇒ Object
-
#publish ⇒ Object
Publish synchronously the card into application Virgil Services scope.
-
#publish_as_global(validation_token) ⇒ Object
Publish synchronously the global card into application Virgil Services scope.
- #scope ⇒ Object
-
#verify(buffer, signature) ⇒ Boolean
Verifies the specified buffer and signature with current VirgilCard recipient.
Constructor Details
#initialize(context:, card:) ⇒ VirgilCard
Initializes a new instance of the Virgil::SDK::HighLevel::VirgilCard class.
54 55 56 57 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 54 def initialize(context:, card:) @context = context @card = card end |
Instance Method Details
#check_identity(identity_options = nil) ⇒ VirgilIdentity::VerificationAttempt
Initiates an identity verification process for current Card identity type. It is only working for Global identity types like Email.
202 203 204 205 206 207 208 209 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 202 def check_identity( = nil) extra_fields = ? .extra_fields : {} action_id = context.client.verify_identity(identity, identity_type, extra_fields) VirgilIdentity::VerificationAttempt.new(context: context, action_id: action_id, identity: identity, identity_type: identity_type, additional_options: ) end |
#data ⇒ Object
90 91 92 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 90 def data card.data end |
#device ⇒ Object
105 106 107 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 105 def device card.device end |
#device_name ⇒ Object
110 111 112 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 110 def device_name card.device_name end |
#encrypt(buffer) ⇒ VirgilBuffer
Encrypts the specified data for current Virgil card recipient
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 179 def encrypt(buffer) buffer_to_encrypt = case buffer.class.name.split("::").last when 'VirgilBuffer' buffer when 'String' VirgilBuffer.from_string(buffer) when 'Array' VirgilBuffer.from_bytes(buffer) else raise ArgumentError.new("Buffer has unsupported type") end VirgilBuffer.new(context.crypto.encrypt(buffer_to_encrypt.bytes, public_key)) end |
#export ⇒ String
Exports card's snapshot.
123 124 125 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 123 def export card.export end |
#id ⇒ String
unique identifier for the Virgil Card.
71 72 73 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 71 def id card.id end |
#identity ⇒ String
the value of current Virgil Card identity.
78 79 80 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 78 def identity card.identity end |
#identity_type ⇒ String
the identityType of current Virgil Card identity.
85 86 87 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 85 def identity_type card.identity_type end |
#public_key ⇒ Object
100 101 102 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 100 def public_key context.crypto.import_public_key(card.public_key) end |
#publish ⇒ Object
Publish synchronously the card into application Virgil Services scope
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 136 def publish raise NotImplementedError.new("Current card isn't local!") unless @card.scope == Client::Card::APPLICATION validate_app_credentials @card = context.client.sign_and_publish_card( card, context.credentials.app_id, context.credentials.app_key(context.crypto)) end |
#publish_as_global(validation_token) ⇒ Object
Publish synchronously the global card into application Virgil Services scope
154 155 156 157 158 159 160 161 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 154 def publish_as_global(validation_token) raise NotImplementedError.new("Current card isn't global!") unless @card.scope == Client::Card::GLOBAL @card.validation_token = validation_token @card = context.client.publish_as_global_card(card) @card.validation_token = validation_token end |
#scope ⇒ Object
95 96 97 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 95 def scope card.scope end |
#verify(buffer, signature) ⇒ Boolean
Verifies the specified buffer and signature with current VirgilCard recipient
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/virgil/sdk/high_level/virgil_card.rb', line 230 def verify(buffer, signature) buffer_to_verify = case buffer.class.name.split("::").last when 'VirgilBuffer' buffer when 'String' VirgilBuffer.from_string(buffer) when 'Array' VirgilBuffer.from_bytes(buffer) else raise ArgumentError.new("Buffer has unsupported type") end signature_to_verify = case signature.class.name.split("::").last when 'VirgilBuffer' signature when 'String' VirgilBuffer.from_base64(signature) when 'Array' VirgilBuffer.from_bytes(signature) else raise ArgumentError.new("Signature has unsupported type") end context.crypto.verify(buffer_to_verify.bytes, signature_to_verify.bytes, public_key) end |