def make_domain_genesis(domain_pathname, trustee_defs, steward_defs): domain_ledger = open_ledger(domain_pathname) seq_no = 1 for trustee_def in trustee_defs: txn = Member.nym_txn(trustee_def['nym'], name=trustee_def['name'], verkey=trustee_def['verkey'], role=TRUSTEE, seq_no=seq_no, protocol_version=None) domain_ledger.add(txn) seq_no += 1 for steward_def in steward_defs: txn = Member.nym_txn(steward_def['nym'], verkey=steward_def['verkey'], role=STEWARD, creator=trustee_def['nym'], seq_no=seq_no, protocol_version=None) domain_ledger.add(txn) seq_no += 1 domain_ledger.stop()
def genesisTxns(stewardWallet: Wallet, trusteeWallet: Wallet): return [Member.nym_txn( nym = stewardWallet.defaultId, verkey=stewardWallet.getVerkey(), role=STEWARD, txn_id="9c86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" )]
def _add_did(role, did_name, with_verkey=True): nonlocal data data['seeds'][did_name] = did_name + '0' * (32 - len(did_name)) t_sgnr = DidSigner(seed=data['seeds'][did_name].encode()) verkey = t_sgnr.full_verkey if with_verkey else None data['txns'].append( Member.nym_txn(nym=t_sgnr.identifier, verkey=verkey, role=role.value, name=did_name, creator=trustee.did) ) if verkey: (sdk_did, sdk_verkey) = looper.loop.run_until_complete( create_and_store_my_did( trustee.wallet_handle, json.dumps({'seed': data['seeds'][did_name]})) ) return DID( did=t_sgnr.identifier, role=role, verkey=verkey, creator=trustee, wallet_handle=trustee.wallet_handle )
def bootstrap_domain_ledger_core(cls, config, network, appendToLedgers, domainTxnFieldOrder, trustee_defs, steward_defs, config_helper_class=PConfigHelper, chroot: str = None): 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 domainLedger = cls.init_domain_ledger(appendToLedgers, genesis_dir, config, domainTxnFieldOrder) genesis_protocol_version = None seq_no = 1 for td in trustee_defs: trustee_txn = Member.nym_txn( td.nym, verkey=td.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_defs[0].nym, seq_no=seq_no, protocol_version=genesis_protocol_version) seq_no += 1 domainLedger.add(nym_txn) domainLedger.stop()
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
def domain(domainLedger , nyms): seq_no = 1 trustee_txn = Member.nym_txn(nyms[0].nym,verkey = nyms[0].verkey, role='0',seq_no=seq_no, protocol_version=genesis_protocol_version) seq_no += 1 domainLedger.add(trustee_txn) roles = {'TRUSTEE':'0','STEWARD':'2','TRUST_ANCHOR':'101'} for d in nyms[1:]: if operator.eq('CLIENT', d.role): nym_txn = Member.nym_txn(d.nym, verkey=d.verkey , creator = d.fromnym ,seq_no=seq_no, protocol_version=genesis_protocol_version) else: nym_txn = Member.nym_txn(d.nym, verkey=d.verkey ,role = roles[d.role], creator = d.fromnym ,seq_no=seq_no, protocol_version=genesis_protocol_version) seq_no +=1 domainLedger.add(nym_txn) print(nym_txn) domainLedger.stop()
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, key_proof = 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, bls_key_proof=key_proof, services=[VALIDATOR], txn_id=sha256("{}".format(nodeSigner.verkey).encode()).hexdigest()) data["txns"].append(node_txn) return data
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
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 if _localNodes: 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 else: genesis_dir = cls.setup_clibase_dir(config, network) keys_dir = os.path.join(genesis_dir, "keys") poolLedger = cls.init_pool_ledger(appendToLedgers, genesis_dir, config) domainLedger = cls.init_domain_ledger(appendToLedgers, genesis_dir, config, domainTxnFieldOrder) # 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) 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) 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) 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 = 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 = 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, seq_no=seq_no) seq_no += 1 poolLedger.add(node_txn) poolLedger.stop() domainLedger.stop()
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
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, role=TRUSTEE) domainLedger.add(trustee_txn) for sd in steward_defs: nym_txn = Member.nym_txn(sd.nym, sd.name, 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, creator=trustee_def.nym) domainLedger.add(txn) poolLedger.stop() domainLedger.stop()
node_def.name = node_name node_def.ip = nodeIps[node_num] node_def.port = args.node_port node_def.client_port = args.client_port node_def.sigseed = node_seed node_def.verkey = node_signer.verhex node_def.steward_nym = steward_signer.identifier steward_defs.append(steward_def) node_defs.append(node_def) client_defs.append(client_def) # 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 node_num in range(nodeCountToInit): nym_txn = Member.nym_txn(steward_defs[node_num].nym, verkey=steward_defs[node_num].verkey, role=STEWARD, creator=trustee_def.nym, seq_no=seq_no, protocol_version=genesis_protocol_version) seq_no += 1 domainLedger.add(nym_txn) # Trustee client txn = Member.nym_txn(client_defs[node_num].nym, verkey=client_defs[node_num].verkey, creator=client_defs[node_num].nym, seq_no=seq_no, protocol_version=genesis_protocol_version)
def bootstrap_real_nodes_core(cls, config, network, appendToLedgers, domainTxnFieldOrder, trustee_def, steward_defs, node_defs, node_params_file_name, config_helper_class=PConfigHelper, node_config_helper_class=PNodeConfigHelper, chroot: str = None): # if not local_nodes: # local_nodes = {} # try: # if isinstance(local_nodes, int): # _local_nodes = {local_nodes} # else: # _local_nodes = {int(_) for _ in local_nodes} # 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) # 2. INIT KEYS AND POOL LEDGER GENESIS FILE seq_no = 1 for nd in node_defs: print( "------------------------------------------------------------------------------------------------------" ) print("Node name:", nd.name) # if nd.idx in _local_nodes: _, 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, node_params_file_name) # print('Nodes will not run locally, so writing {}'.format(paramsFilePath)) # RealNetworkSetup.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.get_nym_from_verkey(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) print( "------------------------------------------------------------------------------------------------------\n" ) poolLedger.stop() domainLedger.stop()
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