Identification

User

Defines a User class.

class layers.identification.user.User(private_key, name, domain, ip, public_info)

Create an User object. This object can be use to create a passive node in the BSMD

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> public = Domain('public', 'default_role')
>>> account_information = json.dumps(x)
>>> me = User('private_key', 'My Name', public, '123.456.789', account_information)
>>> print(me.name)
My name
Parameters
  • private_key (str) – private key of the user. This is not save in the class is just used to generate a public_key. In other functions the private_key must be used to sign transactions. You can generate private keys with IrohaCrypto.private_key()

  • name (str) – name of the user (lower case)

  • domain (Domain) – domain where the user will live

  • ip (str) – ip of one node hosting the blockchain

  • public_info (json) – public information of the user. If domain is public this field can’t be null

create_account(private_key)

Create a personal account in the BSMD. In the public domain all your public information is automatically populated

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> public = Domain('public', 'default_role')
>>> user = User('private_key','David', public, '123.456.789', account_information)
>>> user.create_account('private_key')
Parameters

private_key (str) – The private key of the user

create_domain(domain, private_key)

Creates a domain for personal use. You can create a domain for a particular process, e.g., Federated Learning

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key', 'My Name', 'My domain', '123.456.789', account_information)
>>> user.create_domain(domain, 'private_key')
Parameters
  • domain (Domain) – domain to be created

  • private_key (str) – key to sign the transaction

get_a_detail(detail_key, private_key)

Consult a detail of the user

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> details = user.get_a_detail('private_key', 'age')
>>> print(details)
{
    "user@domainA":{
        "Age":"35"
    }
}
Parameters
  • private_key (str) – key to sign the transaction

  • detail_key (str) – name of the detail to be consulted

Returns

solicited details of the user

Return type

json

get_a_detail_written_by(user, detail_key, private_key)

Consult a detail of the node writen by other node

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> x = { "age": 34, "city": "Mexico" }
>>> account_information_juan = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> juan = User('private_key_juan','Juan',domain, account_information_juan)
>>> details = user.get_a_detail_written_by(juan, 'FederatingParam',  'private_key')
>>> print(details)
{
    "user@domainC":{
        "FederatingParam":"35.242553"
    }
}
Parameters
  • private_key (str) – key to sign the transaction

  • user (User) – user who write information on your identification

  • detail_key (str) – name of the detail to be consulted

Returns

solicited details of the user

Return type

json

get_all_details(private_key)

Consult all details of the user in all the domains

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> details = user.get_all_details('private_key')
>>> print(details)
Parameters

private_key (str) – Key to sign the transaction

Returns

solicited details of the user

Return type

json

{
user@domainA”:{

“Age”:”35”, “Name”:”Quetzalcoatl”

}, “user@domainB”:{

“Location”:”35.3333535,-45.2141556464”, “Status”:”valid”

}, “user@domainC”:{

“FederatingParam”:”35.242553”, “Loop”:”3”

}

}

get_all_details_written_by(user, private_key)

Consult all details writen by some other node

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> x = { "age": 34, "city": "Mexico" }
>>> account_information_juan = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> juan = User('private_key_juan','Juan',domain, account_information_juan)
>>> details = user.get_all_details_written_by(juan, 'private_key')
>>> print(details)
{
    "user@domain":{
        "FederatingParam":"35.242553",
        "Loop":"3"
    },
    "user@domain":{
        "sa_param":"44",
        "Loop":"3"
    }
}
Parameters
  • private_key (str) – key to sign the transaction

  • user (User) – user who write information on your identification

Returns

solicited details of the user

Return type

json

get_balance(private_key)

Get the balance of my account. Use the private key of the user to get his current balance. The function will return a dictionary with the id of the asset, the account id and the balance.

Example

>>> import json
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> user = User('private_key', 'My Name', 'My domain', '123.456.789', account_information)
>>> balance = user.get_balance('private_key')
>>> print(balance)
{asset_id: "fedcoin#federated",
account_id: "generator@federated",
balance: "1000"}
Parameters

private_key (str) – key to sign the transaction

Returns

A a dictionary with the id of the asset, the account id and the balance

Return type

dict

grants_access_set_details_to(user, private_key)

Grant permission to a node to set details on your identification

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> x = { "age": 34, "city": "Mexico" }
>>> account_information_juan = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> juan = User('private_key_juan','Juan',domain, account_information_juan)
>>> user.grants_access_set_details_to(juan, 'private_key')
Parameters
  • user (User) – User you want to grant permissions to set detail on your behalf

  • private_key (str) – Key to sign the transaction

revoke_access_set_details_to(user, private_key)

Revoke permission to a node to set details on your identification

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> x = { "age": 34, "city": "Mexico" }
>>> account_information_juan = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> juan = User('private_key_juan','Juan',domain, account_information_juan)
>>> user.revoke_access_set_details_to(juan, 'private_key')
Parameters
  • user (User) – User you want to revoke permissions to set details on your behalf

  • private_key (str) – Key to sign the transaction

set_detail(detail_key, detail_value, private_key)

Set a detail in my account. The details can be stored in JSON format with limit of 4096 characters per detail

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "gender": 30, "address": "123 Tennis" }
>>> account_information = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David', domain, account_information)
>>> user.set_detail('personal information', account_information, 'private_key')
Parameters
  • detail_key (str) – Name of the detail we want to set

  • detail_value (json) – Value of the detail

  • private_key (str) – Key to sign the transaction

set_detail_to(user, detail_key, detail_value, private_key)

Set a detail to a node. The details can be stored in JSON format with limit of 4096 characters per detail. You must have the permission from the node to set information on his identification

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> x = { "age": 34, "city": "Mexico" }
>>> account_information_juan = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> juan = User('private_key_juan','Juan',domain, account_information_juan)
>>> user.set_detail_to(juan, 'Job', 'Bartender', 'private_key')
Parameters
  • user (User) – user you want to set the details

  • detail_key (str) – Name of the detail we want to set

  • detail_value (str) – Value of the detail

  • private_key (str) – key to sign the transaction

transfer_assets_to(user, asset_name, quantity, description, private_key)

Transfer assets from one account to another. Both users must be in the same domain.

Example

>>> import json
>>> from utils.administrator import Domain
>>> x = { "age": 30, "city": "New York" }
>>> account_information = json.dumps(x)
>>> x = { "age": 34, "city": "Mexico" }
>>> account_information_dante = json.dumps(x)
>>> domain = Domain('name', 'default_role')
>>> user = User('private_key','David',domain, account_information)
>>> dante = User('dante_private_key','Dante',domain, account_information_dante)
>>> user.transfer_assets_to(dante, 'coin', '2', 'Shut up and take my money')
Parameters
  • user (User) – User you want to transfer the assets

  • asset_name (str) – Name of the asset to be transferred

  • quantity (float) – Number of assets we want to transfer

  • description (str) – Small message to the receiver of assets

  • private_key (str) – Key to sign the transaction