class Virgil::SDK::HighLevel::VirgilCard

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.

Attributes

card[R]
context[R]

Public Class Methods

new(context:, card:) click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 44
def initialize(context:, card:)
  @context = context
  @card = card
end

Public Instance Methods

check_identity(identity_options = nil) click to toggle source

Initiates an identity verification process for current Card indentity type. It is only working for

Global identity types like Email.

Args:

identity_options: The data to be encrypted.

Returns:

An instance of VirgilIdentity::VerificationAttempt that contains
information about operation etc
# File lib/virgil/sdk/high_level/virgil_card.rb, line 175
def check_identity(identity_options = nil)
  action_id = context.client.verify_identity(identity, identity_type)
  VirgilIdentity::VerificationAttempt.new(context: context, action_id: action_id,
                                          identity: identity, identity_type: identity_type,
                                          additional_options: identity_options)
end
data() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 74
def data
  card.data
end
device() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 88
def device
  card.device
end
device_name() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 93
def device_name
  card.device_name
end
encrypt(buffer) click to toggle source

Encrypts the specified data for current Virgil card recipient

Args:

buffer: The data to be encrypted. It can be VirgilBuffer, utf8-String or Array of bytes

Returns:

Encrypted data for current Virgil card recipient

Raises:

ArgumentError: Buffer has unsupported type if buffer doesn't have type VirgilBuffer, String or Array of bytes
# File lib/virgil/sdk/high_level/virgil_card.rb, line 148
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() click to toggle source

Exports card's snapshot.

Returns:

base64-encoded json representation of card's content_snapshot and meta.
# File lib/virgil/sdk/high_level/virgil_card.rb, line 102
def export
  card.export
end
id() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 59
def id
  card.id
end
identity() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 64
def identity
  card.identity
end
identity_type() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 69
def identity_type
  card.identity_type
end
public_key() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 83
def public_key
  context.crypto.import_public_key(card.public_key)
end
publish() click to toggle source

Publish synchronously the card into application Virgil Services scope Raises: Virgil::SDK::Client::HTTP::BaseConnection::ApiError if access_token is invalid or

Virgil Card with the same fingerprint already exists in Virgil Security services

AppCredentialsException: For this operation we need app_id and app_key

if application credentials is missing
# File lib/virgil/sdk/high_level/virgil_card.rb, line 113
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) click to toggle source

Publish synchronously the global card into application Virgil Services scope Raises: Virgil Card with the same fingerprint already exists in Virgil Security services

# File lib/virgil/sdk/high_level/virgil_card.rb, line 128
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() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 79
def scope
  card.scope
end
verify(buffer, signature) click to toggle source
Verifies the specified buffer and signature with current VirgilCard recipient

Args:

buffer: The data to be verified. It can be VirgilBuffer, utf8-encoded String or Array of bytes
signature: The signature used to verify the data integrity. It can be VirgilBuffer, base64-encoded String or Array of bytes

Returns:

true if signature is valid, false otherwise.

Raises:

ArgumentError: Buffer has unsupported type if buffer doesn't have type VirgilBuffer, Array of bytes or utf8-encoded String
ArgumentError: Signature has unsupported type if signature doesn't have type VirgilBuffer, base64-encoded String or Array of bytes
# File lib/virgil/sdk/high_level/virgil_card.rb, line 195
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

Private Instance Methods

validate_app_credentials() click to toggle source
# File lib/virgil/sdk/high_level/virgil_card.rb, line 223
def validate_app_credentials

  if !(context.credentials && context.credentials.app_id && context.credentials.app_key(context.crypto))
    raise AppCredentialsException
  end

end