Class: Sidetree::OP::Deactivate

Inherits:
Base
  • Object
show all
Defined in:
lib/sidetree/op/deactivate.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(did_suffix, signed_data, revealed_value) ⇒ Deactivate

Initialize

Parameters:

  • did_suffix (String)
  • signed_data (JSON::JWS)
  • revealed_value (String)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/sidetree/op/deactivate.rb', line 14

def initialize(did_suffix, signed_data, revealed_value)
  Sidetree::Validator.validate_encoded_multi_hash!(
    did_suffix,
    "#{type} didSuffix"
  )
  Sidetree::Validator.validate_encoded_multi_hash!(
    revealed_value,
    "#{type} revealValue"
  )
  @did_suffix = did_suffix
  @signed_data = signed_data
  @revealed_value = revealed_value
end

Instance Attribute Details

#did_suffixObject (readonly)

Returns the value of attribute did_suffix.



6
7
8
# File 'lib/sidetree/op/deactivate.rb', line 6

def did_suffix
  @did_suffix
end

#revealed_valueObject (readonly)

Returns the value of attribute revealed_value.



8
9
10
# File 'lib/sidetree/op/deactivate.rb', line 8

def revealed_value
  @revealed_value
end

#signed_dataObject (readonly)

Returns the value of attribute signed_data.



7
8
9
# File 'lib/sidetree/op/deactivate.rb', line 7

def signed_data
  @signed_data
end

Class Method Details

.from_json(deactivate_data) ⇒ Sidetree::OP::Deactivate

Parse Deactivate operation data from json string

Parameters:

  • deactivate_data (String)

    deactivate operation data(json string).

Returns:

Raises:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sidetree/op/deactivate.rb', line 32

def self.from_json(deactivate_data)
  begin
    json = JSON.parse(deactivate_data, symbolize_names: true)
    jws, revealed_value, did_suffix = nil, nil, nil
    json.each do |k, v|
      case k
      when :type
        unless v == Sidetree::OP::Type::DEACTIVATE
          raise Sidetree::Error, "Deactivate operation type incorrect"
        end
      when :didSuffix
        did_suffix = v
      when :revealValue
        revealed_value = v
      when :signedData
        jws = Sidetree::Util::JWS.parse(v)
        unless jws.keys.length == 2
          raise Sidetree::Error,
                "Deactivate operation signed data missing or unknown property"
        end
        Sidetree::Util::JWK.validate!(
          Sidetree::Util::JWK.parse(jws["recoveryKey"])
        )
      else
        raise Sidetree::Error,
              "Unexpected property #{k.to_s} in deactivate operation"
      end
    end
    if jws
      Validator.validate_canonicalize_object_hash!(
        jws["recoveryKey"],
        revealed_value,
        "Deactivate key"
      )
    end
    unless did_suffix
      raise Sidetree::Error, "The deactivate didSuffix must be a string"
    end
    Deactivate.new(did_suffix, jws, revealed_value)
  rescue JSON::ParserError
    raise Sidetree::Error, "deactivate_data not json"
  rescue JSON::JWS::InvalidFormat
    raise Sidetree::Error, "Invalid signedData"
  end
end

Instance Method Details

#typeObject



77
78
79
# File 'lib/sidetree/op/deactivate.rb', line 77

def type
  Sidetree::OP::Type::DEACTIVATE
end