Class: Sidetree::Model::ProvisionalProofFile

Inherits:
CASFileBase
  • Object
show all
Defined in:
lib/sidetree/model/provisional_proof_file.rb

Overview

Constant Summary

Constants included from Util::Compressor

Util::Compressor::ESTIMATE_DECOMPRESSION_MULTIPLIER

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CASFileBase

decompress, #to_compress

Methods included from Util::Compressor

compress, decompress

Constructor Details

#initialize(update_proofs) ⇒ ProvisionalProofFile

Initialize

Parameters:

  • update_proofs (Array[JSON::JWS])

    Array of update proof.



9
10
11
# File 'lib/sidetree/model/provisional_proof_file.rb', line 9

def initialize(update_proofs)
  @update_proofs = update_proofs
end

Instance Attribute Details

#update_proofsObject (readonly)

Returns the value of attribute update_proofs.



5
6
7
# File 'lib/sidetree/model/provisional_proof_file.rb', line 5

def update_proofs
  @update_proofs
end

Class Method Details

.parse(proof_file, compressed: true) ⇒ Sidetree::Model::ProvisionalProofFile

Parse provisional proof file from compressed data.

Parameters:

  • proof_file (String)

    compressed provisional proof file.

  • compressed (Boolean) (defaults to: true)

    Whether the proof_file is compressed or not, default: true.

Returns:

Raises:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
# File 'lib/sidetree/model/provisional_proof_file.rb', line 18

def self.parse(proof_file, compressed: true)
  decompressed =
    (
      if compressed
        decompress(proof_file, Sidetree::Params::MAX_PROOF_FILE_SIZE)
      else
        proof_file
      end
    )
  begin
    json = JSON.parse(decompressed, symbolize_names: true)
    json.keys.each do |k|
      unless k == :operations
        raise Sidetree::Error,
              "Unexpected property #{k.to_s} in provisional proof file"
      end
    end
    unless json[:operations]
      raise Sidetree::Error,
            "Provisional proof file does not have any operation proofs"
    end
    json[:operations].keys.each do |k|
      unless k == :update
        raise Sidetree::Error,
              "Unexpected property #{k.to_s} in provisional proof file"
      end
    end
    unless json[:operations][:update].is_a?(Array)
      raise Sidetree::Error,
            "Provisional proof file update property not array"
    end
    update_proofs =
      json[:operations][:update].each.map do |update|
        update.keys.each do |k|
          unless k == :signedData
            raise Sidetree::Error,
                  "Unexpected property #{k.to_s} in provisional proof file"
          end
        end
        Sidetree::Util::JWS.parse(update[:signedData])
      end
    if update_proofs.empty?
      raise Sidetree::Error, "Provisional proof file has no proof"
    end
    ProvisionalProofFile.new(update_proofs)
  rescue JSON::ParserError
    raise Sidetree::Error, "Provisional proof file is not json"
  end
end

Instance Method Details

#to_jsonString

Build json string to be stored in CAS.

Returns:

  • (String)

    json string.



70
71
72
73
74
75
76
77
# File 'lib/sidetree/model/provisional_proof_file.rb', line 70

def to_json
  params = {
    operations: {
      update: update_proofs.map { |u| { signedData: u.to_s } }
    }
  }
  params.to_json
end