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

Returns a new instance of Card.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/virgil/sdk/client/card.rb', line 46

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

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def data
  @data
end

#deviceObject

Returns the value of attribute device

Returns:

  • (Object)

    the current value of device



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def device
  @device
end

#device_nameObject

Returns the value of attribute device_name

Returns:

  • (Object)

    the current value of device_name



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def device_name
  @device_name
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def id
  @id
end

#identityObject

Returns the value of attribute identity

Returns:

  • (Object)

    the current value of identity



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def identity
  @identity
end

#identity_typeObject

Returns the value of attribute identity_type

Returns:

  • (Object)

    the current value of identity_type



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def identity_type
  @identity_type
end

#public_keyObject

Returns the value of attribute public_key

Returns:

  • (Object)

    the current value of public_key



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def public_key
  @public_key
end

#relationsObject

Returns the value of attribute relations

Returns:

  • (Object)

    the current value of relations



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def relations
  @relations
end

#scopeObject

Returns the value of attribute scope

Returns:

  • (Object)

    the current value of scope



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def scope
  @scope
end

#signaturesObject

Returns the value of attribute signatures

Returns:

  • (Object)

    the current value of signatures



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def signatures
  @signatures
end

#snapshotObject

Returns the value of attribute snapshot

Returns:

  • (Object)

    the current value of snapshot



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def snapshot
  @snapshot
end

#validation_tokenObject

Returns the value of attribute validation_token

Returns:

  • (Object)

    the current value of validation_token



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def validation_token
  @validation_token
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



40
41
42
# File 'lib/virgil/sdk/client/card.rb', line 40

def version
  @version
end

Class Method Details

.from_request_model(request_model) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/virgil/sdk/client/card.rb', line 103

def self.from_request_model(request_model)
  snapshot = Base64.decode64(request_model[:content_snapshot])
  # if request_model[:content_snapshot].is_a?(Array)
  #   snapshot = Virgil::Crypto::Bytes.new(request_model[:content_snapshot]).to_s
  # end

  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) ⇒ Object

Create new Card from response containing json-encoded snapshot. Args:

response: Cards service response containing base64 encoded content_snapshot.

Returns:

Card model restored from snapshot.


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/virgil/sdk/client/card.rb', line 66

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

#exportObject



98
99
100
# File 'lib/virgil/sdk/client/card.rb', line 98

def export
  self.to_request.export
end

#to_requestObject



92
93
94
95
96
# File 'lib/virgil/sdk/client/card.rb', line 92

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