Class: Bytom::Keys

Inherits:
Object
  • Object
show all
Defined in:
lib/bytom/api/keys.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Keys

Returns a new instance of Keys.



8
9
10
# File 'lib/bytom/api/keys.rb', line 8

def initialize(client)
  @client = client
end

Instance Method Details

#check_key_password(xpub:, password:) ⇒ Hash

Check key password.

Parameters:

  • xpub (string)
  • password (string)

Returns:

  • (Hash)

    check_result, result of check key password, true is check successfully, otherwise is false.



81
82
83
84
85
86
87
# File 'lib/bytom/api/keys.rb', line 81

def check_key_password(xpub:, password:)
  params = {
      xpub: xpub,
      password: password
  }
  client.make_request('/check-key-password', 'post', params: params)
end

#create_key(alias_name:, password:, language: 'en', mnemonic: nil) ⇒ Hash

It is to create private key essentially, returns the information of key. The private key is encrypted in the file and not visible to the user.

Parameters:

  • alias_name (string)

    the filed alias is a keyword in ruby. so use alias_name to map.

  • password (string)
  • language (string) (defaults to: 'en')
  • mnemonic (string) (defaults to: nil)

    Optional

Returns:

  • (Hash)


22
23
24
25
26
27
28
29
30
# File 'lib/bytom/api/keys.rb', line 22

def create_key(alias_name:, password:, language: 'en', mnemonic: nil)
  params = {
      alias: alias_name,
      password: password,
      language: language,
      mnemonic: nil
  }
  client.make_request('/create-key', 'post', params: params)
end

#delete_key(xpub:, password:) ⇒ nil

Delete existed key, please make sure that there is no balance in the related accounts.

Parameters:

  • xpub (string)
  • password (string)

Returns:

  • (nil)


65
66
67
68
69
70
71
# File 'lib/bytom/api/keys.rb', line 65

def delete_key(xpub:, password:)
  params = {
      xpub: xpub,
      password: password
  }
  client.make_request('/delete-key', 'post', params: params)
end

#list_keysHash

Returns the list of all available keys.

Returns:

  • (Hash)


37
38
39
# File 'lib/bytom/api/keys.rb', line 37

def list_keys
  client.make_request('/list-keys', 'get')
end

#list_pubkeys(account_alias: nil, account_id: nil, public_key: nil) ⇒ Hash

Returns the list of all available pubkeys by account.

Parameters:

  • account_alias (String) (defaults to: nil)

    optional

  • account_id (String) (defaults to: nil)

    optional

  • public_keyoptional (String)

Returns:

  • (Hash)


116
117
118
119
120
121
122
# File 'lib/bytom/api/keys.rb', line 116

def list_pubkeys(account_alias: nil, account_id: nil, public_key: nil)
  params = {}
  params = {account_alias: } if 
  params = {account_id: } if 
  #params = {public_key: public_key} if public_key
  client.make_request('/list-pubkeys', 'post', params: params)
end

#reset_key_password(xpub:, old_password:, new_password:) ⇒ Hash

Reset key password.

Parameters:

  • xpub (string)
  • old_password (string)
  • new_password (string)

Returns:

  • (Hash)

    changed, result of reset key password, true is reset successfully, otherwise is false.



98
99
100
101
102
103
104
105
# File 'lib/bytom/api/keys.rb', line 98

def reset_key_password(xpub:, old_password:, new_password:)
  params = {
      xpub: xpub,
      old_password: old_password,
      new_password: new_password
  }
  client.make_request('/reset-key-password', 'post', params: params)
end

#update_key_alias(xpub:, new_alias:) ⇒ nil

Update alias for the existed key.

Parameters:

  • xpub (string)
  • new_alias (string)

Returns:

  • (nil)


49
50
51
52
53
54
55
# File 'lib/bytom/api/keys.rb', line 49

def update_key_alias(xpub:, new_alias:)
  params = {
      xpub: xpub,
      new_alias: new_alias
  }
  client.make_request('/update-key-alias', 'post', params: params)
end