Class: Clickwrap::IntegrityAttestation

Inherits:
ApplicationRecord show all
Defined in:
lib/clickwrap/models/integrity_attestation.rb

Overview

One immutable result from an optional external integrity adapter. Merely configuring an adapter is not evidence; this row records what was actually submitted, what the provider returned, and whether its verifier checked the exact event digest.

Constant Summary collapse

KINDS =
%w[event_anchor third_party_timestamp].freeze
STATES =
%w[verified issued_unverified unavailable failed].freeze

Instance Method Summary collapse

Instance Method Details

#canonical_bodyObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/clickwrap/models/integrity_attestation.rb', line 50

def canonical_body
  {
    "event_id" => event_id,
    "kind" => kind,
    "state" => state,
    "provider_name" => provider_name,
    "subject_digest" => subject_digest,
    "chain_scope" => chain_scope,
    "chain_sequence" => chain_sequence,
    "provider_reference" => provider_reference,
    "provider_result" => provider_result.presence,
    "verification" => verification.presence,
    "adapter_capabilities" => adapter_capabilities.presence,
    "attempted_at" => Receipt.format_time(attempted_at),
    "provider_reported_at" => Receipt.format_time(provider_reported_at),
    "created_at" => Receipt.format_time(created_at)
  }.compact
end

#canonical_fragmentObject



44
45
46
47
48
# File 'lib/clickwrap/models/integrity_attestation.rb', line 44

def canonical_fragment
  canonical_body.merge(
    "attestation_digest" => attestation_digest
  )
end

#digest_verified?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/clickwrap/models/integrity_attestation.rb', line 40

def digest_verified?
  Digest.secure_compare?(attestation_digest.to_s, compute_attestation_digest)
end

#verified?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/clickwrap/models/integrity_attestation.rb', line 28

def verified?
  state == "verified" && verification.to_h["checked"] == true &&
    verification.to_h["verified"] == true && digest_verified?
end

#verified_for?(source_event) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/clickwrap/models/integrity_attestation.rb', line 33

def verified_for?(source_event)
  verified? && event_id.to_s == source_event.id.to_s &&
    subject_digest.to_s == source_event.event_digest.to_s &&
    (kind != "event_anchor" ||
      (chain_scope.to_s == source_event.chain_scope.to_s && chain_sequence == source_event.chain_sequence))
end