Class: Keybase::User

Inherits:
Object
  • Object
show all
Defined in:
lib/keybase/models/user.rb

Overview

A Keybase user containing all attributes you have permission to see

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ User

Returns a new instance of User.



8
9
10
11
12
13
14
15
16
17
# File 'lib/keybase/models/user.rb', line 8

def initialize(params)
  @id = params['id']
  @invitation_stats = OpenStruct.new(params['invitation_stats'])
  
  set_basics(params['basics'])             if params['basics']
  set_profile(params['profile'])           if params['profile']
  set_emails(params['emails'])             if params['emails']
  set_public_keys(params['public_keys'])   if params['public_keys']
  set_private_keys(params['private_keys']) if params['private_keys']
end

Instance Attribute Details

#basicsObject (readonly)

Returns the value of attribute basics.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def basics
  @basics
end

#emailsObject (readonly)

Returns the value of attribute emails.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def emails
  @emails
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def id
  @id
end

#invitation_statsObject (readonly)

Returns the value of attribute invitation_stats.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def invitation_stats
  @invitation_stats
end

#private_keysObject (readonly)

Returns the value of attribute private_keys.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def private_keys
  @private_keys
end

#profileObject (readonly)

Returns the value of attribute profile.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def profile
  @profile
end

#public_keysObject (readonly)

Returns the value of attribute public_keys.



5
6
7
# File 'lib/keybase/models/user.rb', line 5

def public_keys
  @public_keys
end

Class Method Details

.login(email_or_username, passphrase) ⇒ Keybase::Model::User

Login to Keybase

Parameters:

  • the email or username of the account

  • the passphrase for the account

Returns:

  • the user, if login is successful

Raises:

  • if the user is not found

  • if the submitted parameters are empty or invalid

  • if the submitted passphrase is incorrect



37
38
39
40
41
42
43
# File 'lib/keybase/models/user.rb', line 37

def self.(email_or_username, passphrase)
  salt,  = Request::Root.(email_or_username)
  pwh = Crypto.scrypt(passphrase, salt)
  hmac_pwh = Crypto.hmac_sha512(pwh, )
  response = Request::Root.(email_or_username, hmac_pwh, )
  return new(response['me'])
end

.lookup(username) ⇒ Keybase::Model::User

Lookup a user on Keybase

Parameters:

  • the username of the user you are searching for

Returns:

  • the user, if they exist

Raises:

  • if the user is not found

  • if the username is empty or invalid



25
26
27
# File 'lib/keybase/models/user.rb', line 25

def self.lookup(username)
  new(Request::User.lookup(username))
end

Instance Method Details

#add_private_key(key) ⇒ String

Add a new private key to Keybase

This requires login first.

Parameters:

  • the private key

Returns:

  • The Key ID for the uploaded key

Raises:

  • if the key is empty or invalid

  • if the session is not valid

  • if the CSRF token is not valid



108
109
110
# File 'lib/keybase/models/user.rb', line 108

def add_private_key(key)
  Request::Key.add(private_key: key)
end

#add_public_key(key) ⇒ String

Add a new public key to Keybase

This requires login first.

Parameters:

  • the public key

Returns:

  • The Key ID for the uploaded key

Raises:

  • if the key is empty or invalid

  • if the session is not valid

  • if the CSRF token is not valid



95
96
97
# File 'lib/keybase/models/user.rb', line 95

def add_public_key(key)
  Request::Key.add(public_key: key)
end

#post_auth(sig) ⇒ String

Post a self-signed authentication certificate to Keybase

This requires login first.

The payload of the signature should take the form of other keybase signatures, like self-signing keys, or proving ownership of remote accounts.

An example looks like:

{

"body": {
  "key": {
    "fingerprint": "da99a6ebeca98b14d944cb6e1ca9bfeab344f0fc",
    "host": "keybase.io",
    "key_id": "1ca9bfeab344f0fc",
    "uid": "15a9e2826313eaf005291a1ae00c3f00",
    "username": "taco422107"
  },
  "nonce": null,
  "type": "auth",
  "version": 1
},
"ctime": 1386537779,
"expire_in": 86400,
"tag": "signature"

}

The client can provide an optional nonce to randomize the signatures. The server will check the signature for validatity, and on success, will return an auth_token, which is the SHA-256 hash of the full signature body, from the “—- BEGIN” all the way through to the —- END PGP MESSAGE —-.

Parameters:

  • the whole certificate contents

Returns:

  • the authentication token

Raises:

  • if the certificate is empty or invalid

  • if the session is not valid

  • if the CSRF token is not valid



82
83
84
# File 'lib/keybase/models/user.rb', line 82

def post_auth(sig)
  Request::Sig.post_auth(basics.username, sig)
end

#revoke_key(kid) ⇒ Boolean

Revoke a key from Keybase

This requires login first.

Currently the key is simply deleted - full revokation is due in later revisions of the API.

Parameters:

  • the key id to be revoked

Returns:

  • success

Raises:

  • if the key id is empty or invalid

  • if the session is not valid

  • if the CSRF token is not valid



124
125
126
# File 'lib/keybase/models/user.rb', line 124

def revoke_key(kid)
  Request::Key.revoke(kid)
end