Esempio n. 1
0
    def __init__(self, name, password=None):
        self.name = name
        self._password = password if password else self.name

        self.owner = PasswordKey(self.name, self._password, role='owner')
        self.active = PasswordKey(self.name, self._password, role='active')
        self.posting = PasswordKey(self.name, self._password, role='posting')
        self.signing = None
Esempio n. 2
0
 def test_PasswordKey(self):
     a = ["Aang7foN3oz1Ungai2qua5toh3map8ladei1eem2ohsh2shuo8aeji9Thoseo7ah",
          "iep1Mees9eghiifahwei5iidi0Sazae9aigaeT7itho3quoo2dah5zuvobaelau5",
          "ohBeuyoothae5aer9odaegh5Eeloh1fi7obei9ahSh0haeYuas1sheehaiv5LaiX",
          "geiQuoo9NeeLoaZee0ain3Ku1biedohsesien4uHo1eib1ahzaesh5shae3iena7",
          "jahzeice6Ix8ohBo3eik9pohjahgeegoh9sahthai1aeMahs8ki7Iub1oojeeSuo",
          "eiVahHoh2hi4fazah9Tha8loxeeNgequaquuYee6Shoopo3EiWoosheeX6yohg2o",
          "PheeCh3ar8xoofoiphoo4aisahjiiPah4vah0eeceiJ2iyeem9wahyupeithah9T",
          "IuyiibahNgieshei2eeFu8aic1IeMae9ooXi9jaiwaht4Wiengieghahnguang0U",
          "Ipee1quee7sheughemae4eir8pheix3quac3ei0Aquo9ohieLaeseeh8AhGeM2ew",
          "Tech5iir0aP6waiMeiHoph3iwoch4iijoogh0zoh9aSh6Ueb2Dee5dang1aa8IiP"
          ]
     b = ["DWB5NyCrrXHmdikC6QPRAPoDjSHVQJe3WC5bMZuF6YhqhSsfYfjhN",
          "DWB8gyvJtYyv5ZbT2ZxbAtgufQ5ovV2bq6EQp4YDTzQuSwyg7Ckry",
          "DWB7yE71iVPSpaq8Ae2AmsKfyFxA8pwYv5zgQtCnX7xMwRUQMVoGf",
          "DWB5jRgWA2kswPaXsQNtD2MMjs92XfJ1TYob6tjHtsECg2AusF5Wo",
          "DWB6XHwVxcP6zP5NV1jUbG6Kso9m8ZG9g2CjDiPcZpAxHngx6ATPB",
          "DWB59X1S4ofTAeHd1iNHDGxim5GkLo2AdcznksUsSYGU687ywB5WV",
          "DWB6BPPL4iSRbFVVN8v3BEEEyDsC1STRK7Ba9ewQ4Lqvszn5J8VAe",
          "DWB7cdK927wj95ptUrCk6HKWVeF74LG5cTjDTV22Z3yJ4Xw8xc9qp",
          "DWB7VNFRjrE1hs1CKpEAP9NAabdFpwvzYXRKvkrVBBv2kTQCbNHz7",
          "DWB7ZZFhEBjujcKjkmY31i1spPMx6xDSRhkursZLigi2HKLuALe5t",
          ]
     for i, pwd in enumerate(a):
         p = format(PasswordKey("jared", pwd, "posting").get_public(), "DWB")
         self.assertEqual(p, b[i])
Esempio n. 3
0
    def __init__(self,
                 accountName=None,
                 password=None,
                 key=None,
                 account=None,
                 env='prod',
                 timeout=None):

        self.accountName = accountName
        self.signer = None
        self.timeout = timeout
        self.markets = []
        self.api_root = self.prod_api_endpoint_root
        self.chain_endpoint = self.prod_chain_endpoint
        user_key = key

        if env == 'uat':
            self.api_root = self.uat_api_endpoint_root
            self.chain_endpoint = self.uat_chain_endpoint

        # Prepare HTTPS session
        self.session = requests.Session()

        self.session.headers.update({
            'content-type': 'application/json',
            'accept': 'application/json'
        })
        self._load()

        if not account and accountName:
            self.account = self._find_account(accountName)
        else:
            self.account = account

        if self.account:
            data = {
                "method": "call",
                "params": [0, "get_objects", [[self.account]]],
                "id": 2
            }
            res = self._handle_response(
                requests.post(self.chain_endpoint, json=data))
            # res = await this.executeRestRequest(this.chainEndPoint, "POST", data);
            if len(res):
                if not self.accountName:
                    print(res[0])
                    self.accountName = res[0]["name"]
            if not user_key and password is not None:
                user_key = str(
                    PasswordKey(accountName, password).get_private())

            if user_key:
                self.signer = Signer(self.account, user_key, self.refData)

        if not (self.account and user_key):
            raise CybexSignerException(
                'Cannot initialize signer, no valid account')
Esempio n. 4
0
class Account(object):
    def __init__(self, name, password=None):
        self.name = name
        self._password = password if password else self.name

        self.owner = PasswordKey(self.name, self._password, role='owner')
        self.active = PasswordKey(self.name, self._password, role='active')
        self.posting = PasswordKey(self.name, self._password, role='posting')
        self.signing = None

    def __eq__(self, other):
        return self.name == other.name

    def get_active_public(self):
        return str(self.owner.get_public())
        # return str(self.active.get_public())

    def get_active_private(self):
        return str(self.owner.get_private())
        # return str(self.active.get_private())

    def get_owner_public(self):
        return str(self.owner.get_public())

    def get_owner_private(self):
        return str(self.owner.get_private())

    def get_posting_public(self):
        return str(self.owner.get_public())
        # return str(self.posting.get_public())

    def get_posting_private(self):
        return str(self.owner.get_private())
        # return str(self.posting.get_private())

    def get_signing_public(self):
        return str(self.signing.get_public())

    def get_signing_private(self):
        return str(self.signing.get_private())

    def set_signing_key(self):
        self.signing = PasswordKey(self.name, self._password, role='signing')
        return self
Esempio n. 5
0
    def create_account(self,
                       account_name,
                       json_meta={},
                       creator=None,
                       additional_owner_keys=[],
                       additional_active_keys=[],
                       additional_posting_keys=[],
                       additional_owner_accounts=[],
                       additional_active_accounts=[],
                       additional_posting_accounts=[],
                       storekeys=True,
                       ):
        """ Create new account in Steem and store new keys in the wallet
            automatically and return the brain key.

            The brainkey can be used to recover all generated keys (see
            `graphenebase.account` for more details.

            By default, this call will use ``default_author`` to
            register a new name ``account_name`` with all keys being
            derived from a new brain key that will be returned. The
            corresponding keys will automatically be installed in the
            wallet.

            .. note:: Account creations cost a fee that is defined by
                       the network. If you create an account, you will
                       need to pay for that fee!

            .. warning:: Don't call this method unless you know what
                          you are doing! Be sure to understand what this
                          method does and where to find the private keys
                          for your account.

            :param str account_name: (**required**) new account name
            :param str json_meta: Optional meta data for the account
            :param str creator: which account should pay the registration fee
                                (defaults to ``default_author``)
            :param array additional_owner_keys:  Additional owner public keys
            :param array additional_active_keys: Additional active public keys
            :param array additional_posting_keys: Additional posting public keys
            :param array additional_owner_accounts: Additional owner account names
            :param array additional_active_accounts: Additional acctive account names
            :param array additional_posting_accounts: Additional posting account names
            :param bool storekeys: Store new keys in the wallet (default: ``True``)
            :raises AccountExistsException: if the account already exists on the blockchain

        """
        if not creator and config["default_author"]:
            creator = config["default_author"]
        if not creator:
            raise ValueError(
                "Not creator account given. Define it with " +
                "creator=x, or set the default_author in piston")

        account = None
        try:
            account = self.rpc.get_account(account_name)
        except:
            pass
        if account:
            raise AccountExistsException

        " Generate new keys "
        from graphenebase.account import PasswordKey
        password = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(16))
        posting_key = PasswordKey(account_name, password, role="posting")
        active_key  = PasswordKey(account_name, password, role="active")
        owner_key   = PasswordKey(account_name, password, role="owner")
        memo_key    = PasswordKey(account_name, password, role="memo")

        owner   = format(owner_key.get_public_key(), prefix)
        active  = format(active_key.get_public_key(), prefix)
        posting = format(posting_key.get_public_key(), prefix)
        memo    = format(memo_key.get_public_key(), prefix)
        # owner
        if storekeys:
            self.wallet.addPrivateKey(owner_key.get_private_key())
            self.wallet.addPrivateKey(active_key.get_private_key())
            self.wallet.addPrivateKey(posting_key.get_private_key())
            self.wallet.addPrivateKey(memo_key.get_private_key())

        owner_key_authority = [[owner, 1]]
        active_key_authority = [[active, 1]]
        posting_key_authority = [[posting, 1]]
        owner_accounts_authority = []
        active_accounts_authority = []
        posting_accounts_authority = []

        # additional authorities
        for k in additional_owner_keys:
            owner_key_authority.append([k, 1])
        for k in additional_active_keys:
            active_key_authority.append([k, 1])
        for k in additional_posting_keys:
            posting_key_authority.append([k, 1])

        for k in additional_owner_accounts:
            owner_accounts_authority.append([k, 1])
        for k in additional_active_accounts:
            active_accounts_authority.append([k, 1])
        for k in additional_posting_accounts:
            posting_accounts_authority.append([k, 1])

        props = self.rpc.get_chain_properties()
        fee = props["account_creation_fee"]
        s = {'creator': creator,
             'fee': fee,
             'json_metadata': json_meta,
             'memo_key': memo,
             'new_account_name': account_name,
             'owner': {'account_auths': owner_accounts_authority,
                       'key_auths': owner_key_authority,
                       'weight_threshold': 1},
             'active': {'account_auths': active_accounts_authority,
                        'key_auths': active_key_authority,
                        'weight_threshold': 1},
             'posting': {'account_auths': posting_accounts_authority,
                         'key_auths': posting_key_authority,
                         'weight_threshold': 1}}

        op = transactions.Account_create(**s)
        wif = self.wallet.getPostingKeyForAccount(creator)
        self.executeOp(op, wif)

        return password
Esempio n. 6
0
 def set_signing_key(self):
     self.signing = PasswordKey(self.name, self._password, role='signing')
     return self