Module: Sidetree

Defined in:
lib/sidetree.rb,
lib/sidetree/op.rb,
lib/sidetree/cas.rb,
lib/sidetree/did.rb,
lib/sidetree/key.rb,
lib/sidetree/util.rb,
lib/sidetree/model.rb,
lib/sidetree/op/base.rb,
lib/sidetree/version.rb,
lib/sidetree/cas/ipfs.rb,
lib/sidetree/util/jwk.rb,
lib/sidetree/util/jws.rb,
lib/sidetree/op/create.rb,
lib/sidetree/op/update.rb,
lib/sidetree/validator.rb,
lib/sidetree/op/recover.rb,
lib/sidetree/model/chunk.rb,
lib/sidetree/model/delta.rb,
lib/sidetree/model/suffix.rb,
lib/sidetree/op/updatable.rb,
lib/sidetree/model/service.rb,
lib/sidetree/op/deactivate.rb,
lib/sidetree/model/document.rb,
lib/sidetree/util/compressor.rb,
lib/sidetree/cas/fetch_result.rb,
lib/sidetree/model/chunk_file.rb,
lib/sidetree/model/cas_file_base.rb,
lib/sidetree/model/core_index_file.rb,
lib/sidetree/model/core_proof_file.rb,
lib/sidetree/model/provisional_index_file.rb,
lib/sidetree/model/provisional_proof_file.rb,
lib/sidetree/util/anchored_data_serializer.rb

Defined Under Namespace

Modules: CAS, Model, OP, Params, Util, Validator Classes: DID, Error, Key

Constant Summary collapse

VERSION =
"0.1.5"

Class Method Summary collapse

Class Method Details

.to_hash(data) ⇒ String

Calculate Base64 encoded hash of hash object.

Parameters:

  • data (Hash)

Returns:

  • (String)

    Base64 encoded hash value



78
79
80
81
82
83
84
85
# File 'lib/sidetree.rb', line 78

def to_hash(data)
  digest = Digest::SHA256.digest(data.is_a?(Hash) ? data.to_json_c14n : data)
  hash = Multihashes.encode(digest, Params::HASH_ALGORITH_STRING)

  # TODO Need to decide on what hash algorithm to use when hashing suffix data
  # - https://github.com/decentralized-identity/sidetree/issues/965
  Base64.urlsafe_encode64(hash, padding: false)
end