Class: Virgil::SDK::Client::Card

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

Overview

Model representing cards information.

Constant Summary collapse

APPLICATION =
"application"
GLOBAL =
"global"
SERVICE_URL =
"https://cards.virgilsecurity.com"
READ_ONLY_SERVICE_URL =
"https://cards-ro.virgilsecurity.com"
RA_SERVICE_URL =
"https://ra.virgilsecurity.com"
VRA_VERSION =

version of service, which creates and deletes local and global cards

"v1"
VC_VERSION =

version of service, which gets, searchs card

"v4"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Card

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/virgil/sdk/client/card.rb', line 60

def initialize(options)
  self.id = options[:id]
  self.snapshot = options[:snapshot]
  self.identity = options[:identity]
  self.identity_type = options[:identity_type]
  self.public_key = options[:public_key]
  self.scope = options[:scope]
  self.data = options[:data] || {}
  self.device = options[:device]
  self.device_name = options[:device_name]
  self.version = options[:version]
  self.signatures = options[:signatures] || {}
  self.relations = options[:relations] || {}
end

Instance Attribute Details

#dataHash

Returns the current value of data

Returns:

  • (Hash)

    the current value of data



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def data
  @data
end

#deviceString

Returns the current value of device

Returns:

  • (String)

    the current value of device



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def device
  @device
end

#device_nameString

Returns the current value of device_name

Returns:

  • (String)

    the current value of device_name



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def device_name
  @device_name
end

#idString

Returns the current value of id

Returns:

  • (String)

    the current value of id



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def id
  @id
end

#identityString

Returns the current value of identity

Returns:

  • (String)

    the current value of identity



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def identity
  @identity
end

#identity_typeString

Returns the current value of identity_type

Returns:

  • (String)

    the current value of identity_type



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def identity_type
  @identity_type
end

#public_keyCrypto::Bytes

Returns the current value of public_key

Returns:

  • (Crypto::Bytes)

    the current value of public_key



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def public_key
  @public_key
end

#relationsHash

Returns the current value of relations

Returns:

  • (Hash)

    the current value of relations



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def relations
  @relations
end

#scopeString

Returns the current value of scope

Returns:

  • (String)

    the current value of scope



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def scope
  @scope
end

#signaturesHash

Returns the current value of signatures

Returns:

  • (Hash)

    the current value of signatures



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def signatures
  @signatures
end

#snapshotHash

Returns the current value of snapshot

Returns:

  • (Hash)

    the current value of snapshot



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def snapshot
  @snapshot
end

#validation_tokenHighLevel::VirgilIdentity::ValidationToken

Returns the current value of validation_token

Returns:



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def validation_token
  @validation_token
end

#versionString

Returns the current value of version

Returns:

  • (String)

    the current value of version



53
54
55
# File 'lib/virgil/sdk/client/card.rb', line 53

def version
  @version
end

Class Method Details

.from_request_model(request_model) ⇒ Card

Returns new card.

Parameters:

  • request_model (Hash)

    request model from instance of CreateCardRequest class.

Returns:

  • (Card)

    new card.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/virgil/sdk/client/card.rb', line 124

def self.from_request_model(request_model)
  snapshot = Base64.decode64(request_model[:content_snapshot])
  snapshot_model = JSON.parse(snapshot)
  meta = request_model[:meta]
  info = snapshot_model.fetch("info", {}) || {}
  return new(
      snapshot: snapshot,
      identity: snapshot_model["identity"],
      identity_type: snapshot_model["identity_type"],
      public_key: Virgil::Crypto::Bytes.from_base64(
          snapshot_model["public_key"]
      ),
      device: info["device"],
      device_name: info["device_name"],
      data: snapshot_model.fetch("data", {}),
      scope: snapshot_model["scope"],
      signatures: meta[:signs],
      relations: meta[:relations]
  )
end

.from_response(response) ⇒ Card

Create new Virgil::SDK::Client::Card from response containing json-encoded snapshot.

Parameters:

  • response (Hash)

    Cards service response containing base64 encoded content_snapshot.

Returns:

  • (Card)

    Card model restored from snapshot.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/virgil/sdk/client/card.rb', line 79

def self.from_response(response)
  snapshot = Base64.decode64(response["content_snapshot"])
  snapshot_model = JSON.parse(snapshot)
  info = snapshot_model.fetch("info", {}) || {}

  return new(
      id: response["id"],
      snapshot: snapshot,
      identity: snapshot_model["identity"],
      identity_type: snapshot_model["identity_type"],
      public_key: Virgil::Crypto::Bytes.from_base64(
          snapshot_model["public_key"]
      ),
      device: info["device"],
      device_name: info["device_name"],
      data: snapshot_model.fetch("data", {}),
      scope: snapshot_model["scope"],
      version: response["meta"]["card_version"],
      signatures: response["meta"]["signs"],
      relations: response["meta"]["relations"]
  )
end

Instance Method Details

#exportString

Returns base64-encoded json representation of card's content_snapshot and meta.

Examples:

export a card to string

exported_card = alice_card.export

Returns:

  • (String)

    base64-encoded json representation of card's content_snapshot and meta.

See Also:



117
118
119
# File 'lib/virgil/sdk/client/card.rb', line 117

def export
  self.to_request.export
end

#to_requestRequests::CreateCardRequest



106
107
108
109
110
# File 'lib/virgil/sdk/client/card.rb', line 106

def to_request
  request = Virgil::SDK::Client::Requests::CreateCardRequest.new({})
  request.restore(Crypto::Bytes.from_string(snapshot), signatures, validation_token, relations)
  request
end