Example #1
0
def genesisTxns(stewardWallet: Wallet, trusteeWallet: Wallet):
    return [Member.nym_txn(
        nym = stewardWallet.defaultId,
        verkey=stewardWallet.getVerkey(),
        role=STEWARD,
        txn_id="9c86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b"
    )]
Example #2
0
def updatedPoolTxnData(poolTxnData):
    data = deepcopy(poolTxnData)
    trusteeSeed = 'thisistrusteeseednotsteward12345'
    signer = DidSigner(seed=trusteeSeed.encode())
    t = Member.nym_txn(nym=signer.identifier,
                       name="Trustee1",
                       verkey=signer.verkey,
                       role=TRUSTEE,
                       txn_id="6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4a")
    data["seeds"]["Trustee1"] = trusteeSeed
    data["txns"].insert(0, t)
    return data
Example #3
0
def getPoolTxnData(poolId, newPoolTxnNodeNames):
    data = {}
    data["seeds"] = {}
    data["txns"] = []
    data['nodesWithBls'] = {}
    for index, n in enumerate(newPoolTxnNodeNames, start=1):
        newStewardAlias = poolId + "Steward" + str(index)
        stewardSeed = (newStewardAlias + "0" *
                       (32 - len(newStewardAlias))).encode()
        data["seeds"][newStewardAlias] = stewardSeed
        stewardSigner = SimpleSigner(seed=stewardSeed)
        data["txns"].append(
            Member.nym_txn(nym=stewardSigner.identifier,
                           verkey=stewardSigner.verkey,
                           role=STEWARD,
                           name=poolId + "Steward" + str(index),
                           seq_no=index,
                           txn_id=sha256("{}".format(stewardSigner.verkey).encode()).hexdigest()))

        newNodeAlias = n
        nodeSeed = (newNodeAlias + "0" * (32 - len(newNodeAlias))).encode()
        data["seeds"][newNodeAlias] = nodeSeed
        nodeSigner = SimpleSigner(seed=nodeSeed)

        _, bls_key = create_default_bls_crypto_factory().generate_bls_keys(
            seed=data['seeds'][n])
        data['nodesWithBls'][n] = True

        node_txn = Steward.node_txn(
            steward_nym=stewardSigner.verkey,
            node_name=newNodeAlias,
            nym=nodeSigner.verkey,
            ip="127.0.0.1",
            node_port=genHa()[1],
            client_port=genHa()[1],
            client_ip="127.0.0.1",
            blskey=bls_key,
            services=[VALIDATOR],
            txn_id=sha256("{}".format(nodeSigner.verkey).encode()).hexdigest()
        )

        data["txns"].append(node_txn)

    return data
Example #4
0
def poolTxnData(request):
    nodeCount = getValueFromModule(request, "nodeCount", 4)
    nodes_with_bls = getValueFromModule(request, "nodes_wth_bls", nodeCount)
    data = {'txns': [], 'seeds': {}, 'nodesWithBls': {}}
    for i, node_name in zip(range(1, nodeCount + 1), genNodeNames(nodeCount)):
        data['seeds'][node_name] = node_name + '0' * (32 - len(node_name))
        steward_name = 'Steward' + str(i)
        data['seeds'][steward_name] = steward_name + \
                                      '0' * (32 - len(steward_name))

        n_idr = SimpleSigner(seed=data['seeds'][node_name].encode()).identifier
        s_idr = DidSigner(seed=data['seeds'][steward_name].encode())

        data['txns'].append(
                Member.nym_txn(nym=s_idr.identifier,
                               verkey=s_idr.verkey,
                               role=STEWARD,
                               name=steward_name,
                               seq_no=i)
        )

        node_txn = Steward.node_txn(steward_nym=s_idr.identifier,
                                    node_name=node_name,
                                    nym=n_idr,
                                    ip='127.0.0.1',
                                    node_port=genHa()[1],
                                    client_port=genHa()[1],
                                    client_ip='127.0.0.1',
                                    services=[VALIDATOR],
                                    seq_no=i)

        if i <= nodes_with_bls:
            _, bls_key, bls_key_proof = create_default_bls_crypto_factory().generate_bls_keys(
                seed=data['seeds'][node_name])
            get_payload_data(node_txn)[DATA][BLS_KEY] = bls_key
            get_payload_data(node_txn)[DATA][BLS_KEY_PROOF] = bls_key_proof
            data['nodesWithBls'][node_name] = True

        data['txns'].append(node_txn)

    # Add 4 Trustees
    for i in range(4):
        trustee_name = 'Trs' + str(i)
        data['seeds'][trustee_name] = trustee_name + '0' * (
                32 - len(trustee_name))
        t_sgnr = DidSigner(seed=data['seeds'][trustee_name].encode())
        data['txns'].append(
            Member.nym_txn(nym=t_sgnr.identifier,
                           verkey=t_sgnr.verkey,
                           role=TRUSTEE,
                           name=trustee_name)
        )

    more_data_seeds = \
        {
            "Alice": "99999999999999999999999999999999",
            "Jason": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
            "John": "dddddddddddddddddddddddddddddddd",
            "Les": "ffffffffffffffffffffffffffffffff"
        }
    more_data_users = []
    for more_name, more_seed in more_data_seeds.items():
        signer = DidSigner(seed=more_seed.encode())
        more_data_users.append(
            Member.nym_txn(nym=signer.identifier,
                           verkey=signer.verkey,
                           name=more_name,
                           creator="5rArie7XKukPCaEwq5XGQJnM9Fc5aZE3M9HAPVfMU2xC")
        )

    data['txns'].extend(more_data_users)
    data['seeds'].update(more_data_seeds)
    return data
Example #5
0
    def bootstrapTestNodesCore(cls, config, envName, appendToLedgers,
                               domainTxnFieldOrder, trustee_def, steward_defs,
                               node_defs, client_defs, localNodes,
                               nodeParamsFileName):

        if not localNodes:
            localNodes = {}
        try:
            if isinstance(localNodes, int):
                _localNodes = {localNodes}
            else:
                _localNodes = {int(_) for _ in localNodes}
        except BaseException as exc:
            raise RuntimeError(
                'nodeNum must be an int or set of ints') from exc

        baseDir = cls.setup_base_dir(config)

        poolLedger = cls.init_pool_ledger(appendToLedgers, baseDir, config,
                                          envName)

        domainLedger = cls.init_domain_ledger(appendToLedgers, baseDir, config,
                                              envName, domainTxnFieldOrder)

        trustee_txn = Member.nym_txn(trustee_def.nym,
                                     trustee_def.name,
                                     verkey=trustee_def.verkey,
                                     role=TRUSTEE)
        domainLedger.add(trustee_txn)

        for sd in steward_defs:
            nym_txn = Member.nym_txn(sd.nym,
                                     sd.name,
                                     verkey=sd.verkey,
                                     role=STEWARD,
                                     creator=trustee_def.nym)
            domainLedger.add(nym_txn)

        for nd in node_defs:

            if nd.idx in _localNodes:
                _, verkey = initLocalKeys(nd.name,
                                          baseDir,
                                          nd.sigseed,
                                          True,
                                          config=config)
                _, verkey = initLocalKeys(nd.name + CLIENT_STACK_SUFFIX,
                                          baseDir,
                                          nd.sigseed,
                                          True,
                                          config=config)
                verkey = verkey.encode()
                assert verkey == nd.verkey

                if nd.ip != '127.0.0.1':
                    paramsFilePath = os.path.join(baseDir, nodeParamsFileName)
                    print('Nodes will not run locally, so writing '
                          '{}'.format(paramsFilePath))
                    TestNetworkSetup.writeNodeParamsFile(
                        paramsFilePath, nd.name, nd.port, nd.client_port)

                print("This node with name {} will use ports {} and {} for "
                      "nodestack and clientstack respectively".format(
                          nd.name, nd.port, nd.client_port))
            else:
                verkey = nd.verkey
            node_nym = cls.getNymFromVerkey(verkey)

            node_txn = Steward.node_txn(nd.steward_nym, nd.name, node_nym,
                                        nd.ip, nd.port, nd.client_port)
            poolLedger.add(node_txn)

        for cd in client_defs:
            txn = Member.nym_txn(cd.nym,
                                 cd.name,
                                 verkey=cd.verkey,
                                 creator=trustee_def.nym)
            domainLedger.add(txn)

        poolLedger.stop()
        domainLedger.stop()
Example #6
0
    def bootstrapTestNodesCore(
            cls,
            config,
            network,
            appendToLedgers,
            domainTxnFieldOrder,
            trustee_def,
            steward_defs,
            node_defs,
            client_defs,
            localNodes,
            nodeParamsFileName,
            config_helper_class=PConfigHelper,
            node_config_helper_class=PNodeConfigHelper,
            chroot: str=None):

        if not localNodes:
            localNodes = {}
        try:
            if isinstance(localNodes, int):
                _localNodes = {localNodes}
            else:
                _localNodes = {int(_) for _ in localNodes}
        except BaseException as exc:
            raise RuntimeError('nodeNum must be an int or set of ints') from exc

        config.NETWORK_NAME = network

        config_helper = config_helper_class(config, chroot=chroot)
        os.makedirs(config_helper.genesis_dir, exist_ok=True)
        genesis_dir = config_helper.genesis_dir
        keys_dir = config_helper.keys_dir

        poolLedger = cls.init_pool_ledger(appendToLedgers, genesis_dir, config)
        domainLedger = cls.init_domain_ledger(appendToLedgers, genesis_dir,
                                              config, domainTxnFieldOrder)

        # TODO: make it parameter for generate genesis txns script
        genesis_protocol_version = None

        # 1. INIT DOMAIN LEDGER GENESIS FILE
        seq_no = 1
        trustee_txn = Member.nym_txn(trustee_def.nym, verkey=trustee_def.verkey, role=TRUSTEE,
                                     seq_no=seq_no,
                                     protocol_version=genesis_protocol_version)
        seq_no += 1
        domainLedger.add(trustee_txn)

        for sd in steward_defs:
            nym_txn = Member.nym_txn(sd.nym, verkey=sd.verkey, role=STEWARD, creator=trustee_def.nym,
                                     seq_no=seq_no,
                                     protocol_version=genesis_protocol_version)
            seq_no += 1
            domainLedger.add(nym_txn)

        for cd in client_defs:
            txn = Member.nym_txn(cd.nym, verkey=cd.verkey, creator=trustee_def.nym,
                                 seq_no=seq_no,
                                 protocol_version=genesis_protocol_version)
            seq_no += 1
            domainLedger.add(txn)

        # 2. INIT KEYS AND POOL LEDGER GENESIS FILE
        seq_no = 1
        for nd in node_defs:
            if nd.idx in _localNodes:
                _, verkey, blskey, key_proof = initNodeKeysForBothStacks(nd.name, keys_dir, nd.sigseed, override=True)
                verkey = verkey.encode()
                assert verkey == nd.verkey

                if nd.ip != '127.0.0.1':
                    paramsFilePath = os.path.join(config.GENERAL_CONFIG_DIR, nodeParamsFileName)
                    print('Nodes will not run locally, so writing {}'.format(paramsFilePath))
                    TestNetworkSetup.writeNodeParamsFile(paramsFilePath, nd.name,
                                                         "0.0.0.0", nd.port,
                                                         "0.0.0.0", nd.client_port)

                print("This node with name {} will use ports {} and {} for nodestack and clientstack respectively"
                      .format(nd.name, nd.port, nd.client_port))
            else:
                verkey = nd.verkey
                blskey, key_proof = init_bls_keys(keys_dir, nd.name, nd.sigseed)
            node_nym = cls.getNymFromVerkey(verkey)

            node_txn = Steward.node_txn(nd.steward_nym, nd.name, node_nym,
                                        nd.ip, nd.port, nd.client_port, blskey=blskey,
                                        bls_key_proof=key_proof,
                                        seq_no=seq_no,
                                        protocol_version=genesis_protocol_version)
            seq_no += 1
            poolLedger.add(node_txn)

        poolLedger.stop()
        domainLedger.stop()
Example #7
0
def poolTxnData(request):
    nodeCount = getValueFromModule(request, "nodeCount", 4)
    nodes_with_bls = getValueFromModule(request, "nodes_wth_bls", nodeCount)
    data = {'txns': [], 'seeds': {}, 'nodesWithBls': {}}
    for i, node_name in zip(range(1, nodeCount + 1), genNodeNames(nodeCount)):
        data['seeds'][node_name] = node_name + '0' * (32 - len(node_name))
        steward_name = 'Steward' + str(i)
        data['seeds'][steward_name] = steward_name + \
                                      '0' * (32 - len(steward_name))

        n_idr = SimpleSigner(seed=data['seeds'][node_name].encode()).identifier
        s_idr = DidSigner(seed=data['seeds'][steward_name].encode())

        data['txns'].append(
            Member.nym_txn(nym=s_idr.identifier,
                           verkey=s_idr.verkey,
                           role=STEWARD,
                           name=steward_name,
                           seq_no=i))

        node_txn = Steward.node_txn(steward_nym=s_idr.identifier,
                                    node_name=node_name,
                                    nym=n_idr,
                                    ip='127.0.0.1',
                                    node_port=genHa()[1],
                                    client_port=genHa()[1],
                                    client_ip='127.0.0.1',
                                    services=[VALIDATOR],
                                    seq_no=i)

        if i <= nodes_with_bls:
            _, bls_key = create_default_bls_crypto_factory().generate_bls_keys(
                seed=data['seeds'][node_name])
            get_payload_data(node_txn)[DATA][BLS_KEY] = bls_key
            data['nodesWithBls'][node_name] = True

        data['txns'].append(node_txn)

    # Add 4 Trustees
    for i in range(4):
        trustee_name = 'Trs' + str(i)
        data['seeds'][trustee_name] = trustee_name + '0' * (32 -
                                                            len(trustee_name))
        t_sgnr = DidSigner(seed=data['seeds'][trustee_name].encode())
        data['txns'].append(
            Member.nym_txn(nym=t_sgnr.identifier,
                           verkey=t_sgnr.verkey,
                           role=TRUSTEE,
                           name=trustee_name))

    more_data_seeds = \
        {
            "Alice": "99999999999999999999999999999999",
            "Jason": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
            "John": "dddddddddddddddddddddddddddddddd",
            "Les": "ffffffffffffffffffffffffffffffff"
        }
    more_data_users = []
    for more_name, more_seed in more_data_seeds.items():
        signer = DidSigner(seed=more_seed.encode())
        more_data_users.append(
            Member.nym_txn(
                nym=signer.identifier,
                verkey=signer.verkey,
                name=more_name,
                creator="5rArie7XKukPCaEwq5XGQJnM9Fc5aZE3M9HAPVfMU2xC"))

    data['txns'].extend(more_data_users)
    data['seeds'].update(more_data_seeds)
    return data