class ProveKeybase::KeybaseAdapter

Public Class Methods

new(proof) click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 4
def initialize(proof)
  @proof = proof
  @domain = ProveKeybase.configuration.domain
  @base_url = ProveKeybase.configuration.keybase_base_url
end

Public Instance Methods

badge_url() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 60
def badge_url
  File.join(@base_url, "#{@proof.kb_username}/proof_badge/#{@proof.token}?username=#{@proof.username}&domain=#{@domain}")
end
keybase_avatar_url() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 48
def keybase_avatar_url
  client.pic_url
end
keybase_live?() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 38
def keybase_live?
  client.proof_live?
end
keybase_valid?() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 34
def keybase_valid?
  client.proof_valid?
end
on_success_path(kb_ua) click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 42
def on_success_path(kb_ua)
  uri = URI.parse(File.join(@base_url, '/_/proof_creation_success'))
  uri.query = URI.encode_www_form(proof_params.merge(kb_ua: kb_ua || 'unknown'))
  uri.to_s
end
profile_url() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 56
def profile_url
  File.join(@base_url, @proof.kb_username)
end
proof_url() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 52
def proof_url
  File.join(@base_url, "#{@proof.kb_username}/sigchain\##{@proof.token}")
end
refresh() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 18
def refresh
  ProveKeybase::UpdateFromKeybaseJob.perform_later(@proof.id)
end
refresh!() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 22
def refresh!
  status = client.remote_status

  # if Keybase thinks the proof is valid but not live, yet the proof exists locally,
  # then this is very likely during the creation flow, and Keybase just hasn't
  # fetched the proof through the API yet. Throw this specific error so we know to
  # retry.
  raise ProveKeybase::ExpectedProofLiveError if status[:proof_valid] && !status[:proof_live]

  @proof.update!(status.slice(:proof_valid, :proof_live))
end
validate!() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 10
def validate!
  if keybase_valid?
    @proof.proof_valid = true
  else
    @proof.errors.add(:base, 'token not valid for user combo in keybase')
  end
end

Private Instance Methods

client() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 75
def client
  @client ||= ProveKeybase::KeybaseClient.new(proof_params, @base_url)
end
proof_params() click to toggle source
# File lib/prove_keybase/keybase_adapter.rb, line 66
def proof_params
  {
    domain: @domain,
    username: @proof.username,
    kb_username: @proof.kb_username,
    sig_hash: @proof.token
  }
end