Class: Virgil::SDK::Client::VirgilClient

Inherits:
Object
  • Object
show all
Defined in:
lib/virgil/sdk/client/virgil_client.rb

Overview

This class represents a Virgil Security services client and contains all methods to interaction with server.

Defined Under Namespace

Classes: InvalidCardException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token = nil, cards_service_url = Card::SERVICE_URL, cards_read_only_service_url = Card::READ_ONLY_SERVICE_URL, identity_service_url = HighLevel::VirgilIdentity::IDENTITY_SERVICE_URL, ra_service_url = Card::RA_SERVICE_URL) ⇒ VirgilClient

Initializes a new instance of the Virgil::SDK::Client::VirgilClient class.



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/virgil/sdk/client/virgil_client.rb', line 69

def initialize(
    access_token=nil,
    cards_service_url=Card::SERVICE_URL,
    cards_read_only_service_url=Card::READ_ONLY_SERVICE_URL,
    identity_service_url=HighLevel::VirgilIdentity::IDENTITY_SERVICE_URL,
    ra_service_url=Card::RA_SERVICE_URL
)
  self.access_token = access_token
  self.cards_service_url = cards_service_url
  self.cards_read_only_service_url = cards_read_only_service_url
  self.identity_service_url = identity_service_url
  self.ra_service_url = ra_service_url
end

Instance Attribute Details

#access_tokenString

Provides an authenticated secure access to the Virgil Security services.

Returns:

  • (String)

    the current value of access_token



48
49
50
# File 'lib/virgil/sdk/client/virgil_client.rb', line 48

def access_token
  @access_token
end

#card_validatorCardValidator

Returns the current value of card_validator

Returns:



48
49
50
# File 'lib/virgil/sdk/client/virgil_client.rb', line 48

def card_validator
  @card_validator
end

#cards_read_only_service_urlString

Virgil Cards RO service url

Returns:

  • (String)

    the current value of cards_read_only_service_url



48
49
50
# File 'lib/virgil/sdk/client/virgil_client.rb', line 48

def cards_read_only_service_url
  @cards_read_only_service_url
end

#cards_service_urlString

Virgil Cards service url

Returns:

  • (String)

    the current value of cards_service_url



48
49
50
# File 'lib/virgil/sdk/client/virgil_client.rb', line 48

def cards_service_url
  @cards_service_url
end

#identity_service_urlString

Virgil Identity service url

Returns:

  • (String)

    the current value of identity_service_url



48
49
50
# File 'lib/virgil/sdk/client/virgil_client.rb', line 48

def identity_service_url
  @identity_service_url
end

#ra_service_urlString

Virgil RA service url

Returns:

  • (String)

    the current value of ra_service_url



48
49
50
# File 'lib/virgil/sdk/client/virgil_client.rb', line 48

def ra_service_url
  @ra_service_url
end

Instance Method Details

#add_relation(request) ⇒ Card

Adds a relation for the Virgil Card to Virgil cards service.

Examples:

Add bob_card as a relation to alice_card

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
alice_card = client.create_card(
    "alice",
    "unknown",
    alice_keys,
    app_id,
    app_key
)
bob_card = client.create_card(
    "bob",
    "unknown",
    bob_keys,
    app_id,
    app_key
)

add_relation_request = Client::Requests::AddRelationRequest.new(
    bob_card
)
request_signer = Client::RequestSigner.new(crypto)
request_signer.authority_sign(add_relation_request, alice_card.id, alice_keys.private_key)
updated_alice_card = client.add_relation(add_relation_request)

Parameters:

  • request (AddRelationRequest)

    request that contains a trusted card. Updated card from server response. It's an instance of Card class.

Returns:

  • (Card)

    Updated card from server response.

Raises:

  • (ArgumentError)

    if request doesn't have trusted card's snapshot or doesn't have exactly 1 signature.

  • (Client::HTTP::BaseConnection::ApiError)

    if some error has occurred on the server.

See Also:



283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/virgil/sdk/client/virgil_client.rb', line 283

def add_relation(request)
  unless (request.is_a?(Requests::AddRelationRequest) && !request.snapshot.nil? && request.signatures.count == 1)
    raise ArgumentError.new("Request is not valid. Request must have snapshot and exactly 1 relation signature.")
  end
  http_request = Client::HTTP::Request.new(
      method: Client::HTTP::Request::POST,
      endpoint: "/#{Card::VC_VERSION}/card/#{request.signatures.keys.first}/collections/relations",
      body: request.request_model
  )
  raw_response = self.cards_connection.send_request(http_request)
  card = Card.from_response(raw_response)
  self.validate_cards([card]) if self.card_validator
  card
end

#cards_connectionHTTP::CardsServiceConnection

Cards service connection used for add and delete relations.



568
569
570
571
572
573
# File 'lib/virgil/sdk/client/virgil_client.rb', line 568

def cards_connection
  @_cards_connection ||= HTTP::CardsServiceConnection.new(
      self.access_token,
      self.cards_service_url
  )
end

#confirm_identity(action_id, confirmation_code, time_to_live, count_to_live) ⇒ String

Confirms the identity using confirmation code, that has been generated to confirm an identity.

Parameters:

  • action_id (String)

    The action identifier that was obtained on verification step.

  • confirmation_code (String)

    The confirmation code that was received on email box.

  • time_to_live (Fixnum)

    The time to live.

  • count_to_live (Fixnum)

    The count to live.

Returns:

  • (String)

    an identity validation token value.



443
444
445
446
447
448
449
450
451
452
# File 'lib/virgil/sdk/client/virgil_client.rb', line 443

def confirm_identity(action_id, confirmation_code, time_to_live, count_to_live)
  confirm_request = Requests::ConfirmIdentityRequest.new(confirmation_code, action_id, time_to_live, count_to_live)
  http_request = Client::HTTP::Request.new(
      method: HTTP::Request::POST,
      endpoint: "/#{Card::VRA_VERSION}/confirm",
      body: confirm_request.request_model
  )
  raw_response = self.identity_service_connection.send_request(http_request)
  raw_response['validation_token']
end

#create_card(identity, identity_type, key_pair, app_id, app_key) ⇒ Card

Create published new card from given attributes.

Examples:

Create published card

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
crypto = Cryptography::VirgilCrypto.new
app_key_password = "[YOUR_APP_KEY_PASSWORD_HERE]"
app_id = "[YOUR_APP_ID_HERE]"
app_key_data = Virgil::Crypto::Bytes.from_string(File.read("[YOUR_APP_KEY_PATH_HERE]"))

app_key = crypto.import_private_key(app_key_data, app_key_password)
alice_keys = crypto.generate_keys()

alice_card = client.create_card(
    "alice",
    "unknown",
    alice_keys,
    app_id,
    app_key
)

Parameters:

  • identity (String)

    Created card identity.

  • identity_type (String)

    Created card identity type.

  • key_pair (Cryptography::Keys::KeyPair)

    Key pair of the created card. Public key is stored in the card, private key is used for request signing.

  • app_id (String)

    Application identity for authority sign.

  • app_key (Cryptography::Keys::PrivateKey)

    Application key for authority sign.

Returns:

  • (Card)

    Created card from server response.



109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/virgil/sdk/client/virgil_client.rb', line 109

def create_card(identity, identity_type, key_pair, app_id, app_key)
  request = Client::Requests::CreateCardRequest.new(
      identity: identity,
      identity_type: identity_type,
      scope: Client::Card::APPLICATION,
      raw_public_key: self.crypto.export_public_key(key_pair.public_key)
  )
  self.request_signer.self_sign(request, key_pair.private_key)
  self.request_signer.authority_sign(request, app_id, app_key)

  return self.create_card_from_signed_request(request)
end

#create_card_from_signed_request(create_request) ⇒ Card

Create new published card from signed creation request.

Examples:

create published card through [Requests::CreateCardRequest]

exported_public_key = crypto.export_public_key(alice_keys.public_key)
create_card_request = Client::Requests::CreateCardRequest.new(
    identity: "alice",
    identity_type: "unknown",
    public_key: exported_public_key
)
request_signer = Client::RequestSigner.new(crypto)

request_signer.self_sign(create_card_request, alice_keys.private_key)

app_id = "[YOUR_APP_ID_HERE]"
app_key_data = Virgil::Crypto::Bytes.from_string(File.read("[YOUR_APP_KEY_PATH_HERE]"))
app_key = crypto.import_private_key(app_key_data, app_key_password)

request_signer.authority_sign(create_card_request, app_id, app_key)

alice_card = client.create_card_from_signed_request(create_card_request)

Parameters:

Returns:

  • (Card)

    Created card from server response.

Raises:

See Also:



240
241
242
243
244
245
246
247
248
249
250
# File 'lib/virgil/sdk/client/virgil_client.rb', line 240

def create_card_from_signed_request(create_request)
  http_request = Client::HTTP::Request.new(
      method: Client::HTTP::Request::POST,
      endpoint: "/#{Card::VRA_VERSION}/card",
      body: create_request.request_model
  )
  raw_response = self.ra_connection.send_request(http_request)
  card = Card.from_response(raw_response)
  self.validate_cards([card]) if self.card_validator
  card
end

#cryptoCryptography::VirgilCrypto

Crypto library wrapper.



616
617
618
# File 'lib/virgil/sdk/client/virgil_client.rb', line 616

def crypto
  @_crypto ||= Cryptography::VirgilCrypto.new
end

#delete_relation(request) ⇒ Card

Deletes a relation for the Virgil Card to Virgil cards service.

Examples:

delete bob_card from alice_card's relations

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
delete_relation_request = Client::Requests::DeleteRelationRequest.new({card_id: bob_card.id})
request_signer = Client::RequestSigner.new(crypto)
request_signer.authority_sign(delete_relation_request, alice_card.id, alice_keys.private_key)

updated_alice_card = client.delete_relation(delete_relation_request)

Parameters:

  • request (DeleteRelationRequest)

    request that contains a trusted card to be deleted.

Returns:

  • (Card)

    Updated card from server response.

Raises:

  • (ArgumentError)

    if request doesn't have trusted card's snapshot or doesn't have exactly 1 signature.

  • (Client::HTTP::BaseConnection::ApiError)

    if some error has occurred on the server.

See Also:



313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/virgil/sdk/client/virgil_client.rb', line 313

def delete_relation(request)
  unless (request.is_a?(Requests::DeleteRelationRequest) && !request.snapshot.nil? && request.signatures.count == 1)
    raise ArgumentError.new("Request is not valid. Request must have snapshot and exactly 1 relation signature.")
  end
  http_request = Client::HTTP::Request.new(
      method: Client::HTTP::Request::DELETE,
      endpoint: "/#{Card::VC_VERSION}/card/#{request.signatures.keys.first}/collections/relations",
      body: request.request_model
  )
  raw_response = self.cards_connection.send_request(http_request)
  card = Card.from_response(raw_response)
  self.validate_cards([card]) if self.card_validator
  card
end

#get_card(card_id) ⇒ Card

Get card by id.

Examples:

Get card by id.

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
card = client.get_card("[YOUR_CARD_ID_HERE]")

Parameters:

  • card_id (String)

    id of the card to get.

Returns:

  • (Card)

    Found card from server response.

Raises:



463
464
465
466
467
468
469
470
471
472
# File 'lib/virgil/sdk/client/virgil_client.rb', line 463

def get_card(card_id)
  http_request = Client::HTTP::Request.new(
      method: HTTP::Request::GET,
      endpoint: "/#{Card::VC_VERSION}/card/#{card_id}",
  )
  raw_response = self.read_cards_connection.send_request(http_request)
  card = Card.from_response(raw_response)
  self.validate_cards([card]) if self.card_validator
  card
end

#identity_service_connectionHTTP::CardsServiceConnection

Virgil Identity service connection used for validation of user's identities like email, application, etc.



598
599
600
601
602
603
604
# File 'lib/virgil/sdk/client/virgil_client.rb', line 598

def identity_service_connection
  @identity_service_connection = HTTP::CardsServiceConnection.new(
      nil,
      self.identity_service_url
  )

end

#new_card(identity, identity_type, private_key, custom_data = {}) ⇒ Card

Create unpublished local card from given attributes.

Examples:

Create unpublished local card

client = Client::VirgilClient.new()
crypto = Cryptography::VirgilCrypto.new
alice_keys = crypto.generate_keys()
alice_card = client.new_card(
    "alice",
    "unknown",
    alice_keys.private_key,
    {data: {}, device: "iPhone6s", device_name: "Space grey one"}
)
# Then you can export created local card and transmit it to the server

Parameters:

  • identity (String)

    Created card identity.

  • identity_type (String)

    Created card identity type.

  • private_key (Cryptography::Keys::PrivateKey)

    Private key of the created card.

  • custom_data (Hash) (defaults to: {})

    contains application specific parameters(under key :data) and information about the device on which the keypair was created(under key :device and :device_name). example: {my_key1: “my_val1”, my_key2: “my_val2”, device: “iPhone6s”, device_name: “Space grey one”}

Returns:

  • (Card)

    Created local card that is not published to Virgil Security services

See Also:



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/virgil/sdk/client/virgil_client.rb', line 144

def new_card(identity, identity_type, private_key, custom_data={})
  data = custom_data[:data]
  custom_data.delete(:data)
  request = Client::Requests::CreateCardRequest.new(
      identity: identity,
      identity_type: identity_type,
      scope: Client::Card::APPLICATION,
      raw_public_key: self.crypto.extract_public_key(private_key).value,
      info: custom_data,
      data: data
  )
  self.request_signer.self_sign(request, private_key)

  return Client::Card.from_request_model(request.request_model)
end

#new_global_card(identity, identity_type, private_key, custom_data = {}) ⇒ Card

Create unpublished global card from given attributes.

Parameters:

  • identity (String)

    Created card identity.

  • identity_type (String)

    Created card identity type.

  • private_key (Cryptography::Keys::PrivateKey)

    Private key of the created card.

  • custom_data (Hash) (defaults to: {})

    contains application specific parameters(under key :data) and information about the device on which the keypair was created(under key :device and :device_name). example: {my_key1: “my_val1”, my_key2: “my_val2”, device: “iPhone6s”, device_name: “Space grey one”}

Returns:

  • (Card)

    Created global card that is not published to Virgil Security services



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/virgil/sdk/client/virgil_client.rb', line 170

def new_global_card(identity, identity_type, private_key, custom_data={})
  data = custom_data[:data]
  custom_data.delete(:data)
  request = Client::Requests::CreateCardRequest.new(
      identity: identity,
      identity_type: identity_type,
      scope: Client::Card::GLOBAL,
      raw_public_key: self.crypto.extract_public_key(private_key).value,
      info: custom_data,
      data: data
  )
  self.request_signer.self_sign(request, private_key)

  return Client::Card.from_request_model(request.request_model)
end

#publish_as_global_card(card) ⇒ Card

Publishes Global card in Virgil cards service.

Parameters:

  • card (Card)

    Created Global card.

Returns:

  • (Card)

    Global card that is published to Virgil Security services



209
210
211
212
# File 'lib/virgil/sdk/client/virgil_client.rb', line 209

def publish_as_global_card(card)
  request = card.to_request
  create_card_from_signed_request(request)
end

#ra_connectionHTTP::CardsServiceConnection

The Virgil Registration Authority service connection used for creating and revoking cards.



578
579
580
581
582
583
# File 'lib/virgil/sdk/client/virgil_client.rb', line 578

def ra_connection
  @_ra_connection ||= HTTP::CardsServiceConnection.new(
      self.access_token,
      self.ra_service_url
  )
end

#read_cards_connectionHTTP::CardsServiceConnection

Cards service connection used for getting and searching cards.



588
589
590
591
592
593
# File 'lib/virgil/sdk/client/virgil_client.rb', line 588

def read_cards_connection
  @_read_cards_connection = HTTP::CardsServiceConnection.new(
      self.access_token,
      self.cards_read_only_service_url
  )
end

#request_signerRequestSigner

Request signer for signing constructed requests.

Returns:



609
610
611
# File 'lib/virgil/sdk/client/virgil_client.rb', line 609

def request_signer
  @_request_signer ||= RequestSigner.new(self.crypto)
end

#revoke_card(card_id, app_id, app_key, reason = Requests::RevokeCardRequest::Reasons::Unspecified) ⇒ void

This method returns an undefined value.

Revoke card by id.

Examples:

Revoke published card

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
crypto = Cryptography::VirgilCrypto.new
app_key_password = "[YOUR_APP_KEY_PASSWORD_HERE]"
app_id = "[YOUR_APP_ID_HERE]"
app_key_data = Virgil::Crypto::Bytes.from_string(File.read("[YOUR_APP_KEY_PATH_HERE]"))
app_key = crypto.import_private_key(app_key_data, app_key_password)

client.revoke_card("[SOME_LOCAL_CARD_ID]", app_id, app_key)

Parameters:

  • card_id (String)

    the id of the revoked card.

  • reason (String) (defaults to: Requests::RevokeCardRequest::Reasons::Unspecified)

    card revocation reason. The possible values can be found in RevokeCardRequest::Reasons class.

  • app_id (String)

    Application identity for authority sign.

  • app_key (Cryptography::Keys::PrivateKey)

    Application key for authority sign.

See Also:



346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/virgil/sdk/client/virgil_client.rb', line 346

def revoke_card(
    card_id,
    app_id,
    app_key,
    reason=Requests::RevokeCardRequest::Reasons::Unspecified
)
  request = Requests::RevokeCardRequest.new(
      card_id: card_id,
      reason: reason
  )
  self.request_signer.authority_sign(request, app_id, app_key)

  self.revoke_card_from_signed_request(request)
end

#revoke_card_from_signed_request(revocation_request) ⇒ void

This method returns an undefined value.

Revoke card using signed revocation request.

Examples:

Revoke card using signed revocation request.

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
crypto = Cryptography::VirgilCrypto.new
request_signer = Client::RequestSigner.new(crypto)
app_id = "[YOUR_APP_ID_HERE]"
app_key_password = "[YOUR_APP_KEY_PASSWORD_HERE]"
app_key_path = "[YOUR_APP_KEY_PATH_HERE]"
app_key_data = Virgil::Crypto::Bytes.from_string(File.read(app_key_path))
app_key = crypto.import_private_key(app_key_data, app_key_password)
card_id = "[YOUR_CARD_ID_HERE]"

revoke_request = Client::Requests::RevokeCardRequest(
    card_id, Client::Requests::RevokeCardRequest::Reasons::Unspecified
)
request_signer.authority_sign(revoke_request, app_id, app_key)

client.revoke_card_from_signed_request(revoke_request)

Parameters:

See Also:



409
410
411
412
413
414
415
416
# File 'lib/virgil/sdk/client/virgil_client.rb', line 409

def revoke_card_from_signed_request(revocation_request)
  http_request = Client::HTTP::Request.new(
      method: HTTP::Request::DELETE,
      endpoint: "/#{Card::VRA_VERSION}/card/#{revocation_request.card_id}",
      body: revocation_request.request_model
  )
  self.ra_connection.send_request(http_request)
end

#revoke_global_card(card_id, key_pair, validation_token, reason = Requests::RevokeCardRequest::Reasons::Unspecified) ⇒ void

This method returns an undefined value.

Revoke Global card by id.

Parameters:

  • card_id (String)

    id of the revoked Global card.

  • reason (String) (defaults to: Requests::RevokeCardRequest::Reasons::Unspecified)

    Global card revocation reason. The possible values can be found in RevokeCardRequest::Reasons class.

  • key_pair (Cryptography::Keys::KeyPair)

    The Key associated with the revoking Global Card.

  • validation_token (HighLevel::VirgilIdentity::ValidationToken)

    an identity token.



369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/virgil/sdk/client/virgil_client.rb', line 369

def revoke_global_card(
    card_id,
    key_pair,
    validation_token,
    reason=Requests::RevokeCardRequest::Reasons::Unspecified
)
  request = Requests::RevokeCardRequest.new(
      card_id: card_id,
      reason: reason
  )
  request.restore(validation_token)
  self.request_signer.authority_sign(request, card_id, key_pair.private_key)
  self.revoke_card_from_signed_request(request)
end

#search_cards_by_app_bundle(bundle) ⇒ Array<Card>

Search cards by specified app bundle.

Examples:

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
app_bundle_cards = client.seach_cards_by_app_bundle("[APP_BUNDLE]")

Parameters:

  • bundle (String)

    application bundle for search.

Returns:

  • (Array<Card>)

    Found cards from server response.

Raises:

See Also:



500
501
502
503
504
# File 'lib/virgil/sdk/client/virgil_client.rb', line 500

def search_cards_by_app_bundle(bundle)
  return self.search_cards_by_criteria(
      SearchCriteria.by_app_bundle(bundle)
  )
end

#search_cards_by_criteria(search_criteria) ⇒ Array<Card>

Search cards by specified search criteria.

Examples:

Search cards by specified search criteria

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
criteria = Client::SearchCriteria.by_identities("alice", "bob")
cards = client.search_cards_by_criteria(criteria)

Parameters:

Returns:

  • (Array<Card>)

    Found cards from server response.

Raises:

See Also:



518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/virgil/sdk/client/virgil_client.rb', line 518

def search_cards_by_criteria(search_criteria)
  body = {identities: search_criteria.identities}
  if search_criteria.identity_type
    body[:identity_type] = search_criteria.identity_type
  end
  if search_criteria.scope == Card::GLOBAL
    body[:scope] = Card::GLOBAL
  end
  http_request = Client::HTTP::Request.new(
      method: HTTP::Request::POST,
      endpoint: "/#{Card::VC_VERSION}/card/actions/search",
      body: body,
  )
  response = nil
  begin
    response = self.read_cards_connection.send_request(http_request)
  rescue
  end
  cards = []
  if response
    cards = response.map { |card| Card.from_response(card) }
    self.validate_cards(cards) if self.card_validator
  end

  return cards
end

#search_cards_by_identities(*identities) ⇒ Array<Card>

Search cards by specified identities.

Examples:

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
cards = client.search_cards_by_identities("alice", "bob")

Parameters:

  • identities (Array<String>)

    identity values for search.

Returns:

  • (Array<Card>)

    Found cards from server response.

See Also:



483
484
485
486
487
# File 'lib/virgil/sdk/client/virgil_client.rb', line 483

def search_cards_by_identities(*identities)
  return self.search_cards_by_criteria(
      SearchCriteria.by_identities(identities)
  )
end

#sign_and_publish_card(card, app_id, app_key) ⇒ Card

Signs and publishes card in Virgil cards service.

Examples:

Sign and publish local card

client = Client::VirgilClient.new("[YOUR_ACCESS_TOKEN_HERE]")
client.sign_and_publish_card(alice_card, app_id, app_key)

Parameters:

  • card (Card)

    created card.

  • app_id (String)

    Application identity for authority sign.

  • app_key (Cryptography::Keys::PrivateKey)

    Application key for authority sign.

Returns:

  • (Card)

    Card that is published to Virgil Security services



195
196
197
198
199
200
201
202
203
# File 'lib/virgil/sdk/client/virgil_client.rb', line 195

def sign_and_publish_card(card, app_id, app_key)
  request = card.to_request
  request_signer.authority_sign(
      request,
      app_id,
      app_key
  )
  create_card_from_signed_request(request)
end

#validate_cards(cards) ⇒ Object

Validate cards signatures.

Examples:

Validate cards

crypto = Cryptography::VirgilCrypto.new
validator = Client::CardValidator.new(crypto)
validator.add_default_verifiers
validator.add_verifier("[HERE_VERIFIER_CARD_ID]", "[HERE_VERIFIER_PUBLIC_KEY]")
client.card_validator = validator
cards = client.search_cards_by_identities("alice", "bob")

Parameters:

  • cards (Array<Card>)

    list of cards to validate.

Raises:

See Also:



558
559
560
561
562
563
# File 'lib/virgil/sdk/client/virgil_client.rb', line 558

def validate_cards(cards)
  invalid_cards = cards.select { |card| !card_validator.is_valid?(card) }
  if invalid_cards.any?
    raise InvalidCardException.new(invalid_cards)
  end
end

#verify_identity(identity, identity_type, extra_fields = {}) ⇒ String

Note:

use method confirm_identity to confirm and get the identity token.

Sends the request for identity verification, that's will be processed depending of specified type.

Parameters:

  • identity (String)

    An unique string that represents identity.

  • identity_type (String)

    The type of identity.

  • extra_fields (HASH) (defaults to: {})

    A parameter for additional information.

Returns:

  • (String)

    The action identifier that is required for confirmation the identity.



425
426
427
428
429
430
431
432
433
434
# File 'lib/virgil/sdk/client/virgil_client.rb', line 425

def verify_identity(identity, identity_type, extra_fields = {})
  verify_identity_request = Requests::VerifyIdentityRequest.new(identity, identity_type, extra_fields)
  http_request = Client::HTTP::Request.new(
      method: HTTP::Request::POST,
      endpoint: "/#{Card::VRA_VERSION}/verify",
      body: verify_identity_request.request_model
  )
  raw_response = self.identity_service_connection.send_request(http_request)
  raw_response['action_id']
end