示例#1
0
async def run():
    # CREATE POOL
    pool_name = 'pool1'
    # logger.info("Open Pool Ledger: {}".format(pool_name))
    pool_genesis_txn_path = get_pool_genesis_txn_path(pool_name)
    pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})

    # Set protocol version 2 to work with Indy Node 1.4
    await pool.set_protocol_version(PROTOCOL_VERSION)
    try:
        await pool.create_pool_ledger_config(pool_name, pool_config)
    except IndyError as ex:
        if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
            pass
    pool_handle = await pool.open_pool_ledger(pool_name, None)

    for i in range(1, 1000):
        node_A = str(i) + "_wallet"
        node_A_wallet_config = json.dumps({"id": node_A})
        keyA = str(i) + "_wallet_key"
        nodeA_wallet_credentials = json.dumps({"key": keyA})
        try:
            await wallet.create_wallet(node_A_wallet_config,
                                       nodeA_wallet_credentials)
        except:
            pass
        NodeA_wallet = await wallet.open_wallet(node_A_wallet_config,
                                                nodeA_wallet_credentials)
        (NodeA_did,
         NodeA_key) = await did.create_and_store_my_did(NodeA_wallet, "{}")
        print(NodeA_did, NodeA_key)
        with open('wallets/' + node_A + '.nfo', 'w') as file:
            file.write(NodeA_did + ',' + NodeA_key)
示例#2
0
async def run():
    pool_name = 'pool1'
    pool_genesis_txn_path = get_pool_genesis_txn_path(pool_name)
    pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})

    # Set protocol version 2 to work with Indy Node 1.4
    await pool.set_protocol_version(PROTOCOL_VERSION)

    try:
        await pool.create_pool_ledger_config(pool_name, pool_config)
    except IndyError as ex:
        if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
            pass
    # pool_handle = await pool.open_pool_ledger(pool_name, None)

    steward_wallet_config = json.dumps({"id": "sovrin_steward_wallet"})
    steward_wallet_credentials = json.dumps({"key": "steward_wallet_key"})
    try:
        await wallet.create_wallet(steward_wallet_config,
                                   steward_wallet_credentials)
    except IndyError as ex:
        if ex.error_code == ErrorCode.WalletAlreadyExistsError:
            pass
    steward_wallet = await wallet.open_wallet(steward_wallet_config,
                                              steward_wallet_credentials)

    steward_did_info = {'seed': '000000000000000000000000Steward1'}
    (steward_did, steward_key) = await did.create_and_store_my_did(
        steward_wallet, json.dumps(steward_did_info))
    print(steward_did)
示例#3
0
async def connectPool():

    logger.info("Getting started -> started")

    pool_name = 'pool1'
    logger.info("Open Pool Ledger: {}".format(pool_name))
    pool_genesis_txn_path = get_pool_genesis_txn_path(pool_name)
    pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})

    # Set protocol version 2 to work with Indy Node 1.4
    await pool.set_protocol_version(PROTOCOL_VERSION)

    try:
        await pool.create_pool_ledger_config(pool_name, pool_config)
    except IndyError as ex:
        if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
            pass
    pool_handle = await pool.open_pool_ledger(pool_name, None)
示例#4
0
async def run(nA, nB, messages, number, NodeA_did, NodeA_key, NodeB_did, NodeB_key):

    # launch the message
    startProcedure = str(datetime.datetime.now())
    logging.info(str(nA) + "-" + str(nB) + ", " + str(messages) + "msg, start at: " + str(startProcedure))
    # OPEN POOL
    pool_name = 'pool1'
    # logger.info("Open Pool Ledger: {}".format(pool_name))
    pool_genesis_txn_path = get_pool_genesis_txn_path(pool_name)
    pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})
    # Set protocol version 2 to work with Indy Node 1.4
    await pool.set_protocol_version(PROTOCOL_VERSION)
    pool_handle = await pool.open_pool_ledger(pool_name, None)
    # print('procces: ', number)
    node_A = str(nA) + "_wallet"
    node_A_wallet_config = json.dumps({"id": node_A})
    keyA = str(nA) + "_wallet_key"
    nodeA_wallet_credentials = json.dumps({"key": keyA})
    NodeA_wallet = await wallet.open_wallet(node_A_wallet_config, nodeA_wallet_credentials)

    # print(nB)
    node_B = str(nB) + "_wallet"
    mode_B_wallet_config = json.dumps({"id": node_B})
    keyB = str(nB) + "_wallet_key"
    Node_B_wallet_credentials = json.dumps({"key": keyB})
    NodeB_wallet = await wallet.open_wallet(mode_B_wallet_config, Node_B_wallet_credentials)

    (NodeA_did, NodeA_key) = await did.create_and_store_my_did(NodeA_wallet, "{}")
    (NodeB_did, NodeB_key) = await did.create_and_store_my_did(NodeB_wallet, "{}")

    # Count time elapsed since write operation in the ledger
    start = time.time()
    #Write to leadger
    await send_nym(pool_handle, NodeA_wallet, NodeA_did, NodeB_did, NodeB_key, None)

    parametersB = [NodeB_wallet, NodeB_did, NodeA_key, NodeA_wallet, NodeB_key]

    string = str(nA)
    troughput = await runTwoNode(parametersB, string, messages, nA, nB)
    end = time.time()
    endProcedure = str(datetime.datetime.now())
    log = str(nA) + "-" + str(nB) + ", " + str(messages) + " msg in " + str(end - start) + troughput + ", end at: " + str(endProcedure)
    # print(log)
    logging.info(log)
示例#5
0
async def run(nA, nB, messages):
    pool_name = 'pool1'
    pool_genesis_txn_path = get_pool_genesis_txn_path(pool_name)
    pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})

    # Set protocol version 2 to work with Indy Node 1.4
    await pool.set_protocol_version(PROTOCOL_VERSION)
    pool_handle = await pool.open_pool_ledger(pool_name, None)

    NodeA_did = 'Th7MpTaRZVRYnPiabds81Y'
    steward_wallet_config = json.dumps({"id": "sovrin_steward_wallet"})
    steward_wallet_credentials = json.dumps({"key": "steward_wallet_key"})
    nodeA_wallet = await wallet.open_wallet(steward_wallet_config,
                                            steward_wallet_credentials)

    # print(steward_wallet_config, NodeA_did)
    nodeB = str(nB) + "_wallet"
    nodeB_wallet_config = json.dumps({"id": nodeB})
    keyB = str(nB) + "_wallet_key"
    nodeB_wallet_credentials = json.dumps({"key": keyB})

    start = time.time()
    NodeB_wallet, NodeA_NodeB_key, NodeB_NodeA_did, NodeB_NodeA_key, _ \
        = await onboarding(pool_handle, nodeA_wallet, NodeA_did , None,
                           nodeB_wallet_config, nodeB_wallet_credentials)
    # end = time.time()

    parametersB = [
        NodeB_wallet, NodeB_NodeA_did, NodeA_NodeB_key, nodeA_wallet,
        NodeB_NodeA_key
    ]

    string = str(nA)
    troughput = await runTwoNode(parametersB, string, messages, nA, nB)
    end = time.time()
    endProcedure = str(datetime.datetime.now())
    log = str(nA) + "-" + str(nB) + ", " + str(messages) + " msg in " + str(
        end - start) + troughput + ", end at: " + str(endProcedure)
    print(log)
    logging.info(log)
示例#6
0
#These steps only include steps up to the point of generating and storing the trust anchor DID and verkey. The latter is stored in the same wallet as that for the steward

import asyncio
import json
import pprint

from indy import pool, ledger, wallet, did
from indy.error import IndyError, ErrorCode

from utils import get_pool_genesis_txn_path, PROTOCOL_VERSION

pool_name = 'pool'
genesis_file_path = get_pool_genesis_txn_path(pool_name)


def print_log(value_color="", value_noncolor=""):
    """set the colors for text."""
    HEADER = '\033[92m'
    ENDC = '\033[0m'
    print(HEADER + value_color + ENDC + str(value_noncolor))


async def pool_configuration():

    await pool.set_protocol_version(PROTOCOL_VERSION)

    pool_config = json.dumps({'genesis_txn': str(genesis_file_path)})
    print_log(
        '\n1. Create new pool ledger configuration to connect to ledger.\n')

    try:
示例#7
0
Finally, Prover stores Credential in its wallet.
"""

import asyncio
import json
import pprint

from indy import pool, ledger, wallet, did, anoncreds
from indy.error import ErrorCode, IndyError

from utils import open_wallet, get_pool_genesis_txn_path, PROTOCOL_VERSION

pool_name = 'pool'
issuer_wallet_config = json.dumps({"id": "issuer_wallet"})
issuer_wallet_credentials = json.dumps({"key": "issuer_wallet_key"})
genesis_file_path = get_pool_genesis_txn_path(pool_name)

def print_log(value_color="", value_noncolor=""):
    """set the colors for text."""
    HEADER = '\033[92m'
    ENDC = '\033[0m'
    print(HEADER + value_color + ENDC + str(value_noncolor))

async def issue_credential():
    try:
        await pool.set_protocol_version(PROTOCOL_VERSION)

        # 1.
        print_log('\n1. opening a new local pool ledger configuration that will be used '
                  'later when connecting to ledger.\n')
        pool_config = json.dumps({'genesis_txn': str(genesis_file_path)})
示例#8
0
async def init_indy():
    """
    her ledgerde bir kere kullanilmali, start_indy ile karistirma
    wallet create eder, serverin didini trust anchor olarak ekler
    yaptigi islerin bir json dosyasina kayit eder, 
    """

    indy_config = {}
    pool_name = 'sandbox'
    indy_config["pool_name"] = pool_name
    genesis_file_path = get_pool_genesis_txn_path(pool_name)
    wallet_config = json.dumps({"id": "server_wallet"})
    wallet_credentials = json.dumps({"key": "very_secret_key"})
    indy_config["wallet_config"] = wallet_config
    indy_config["wallet_credentials"] = wallet_credentials

    try:
        await pool.set_protocol_version(PROTOCOL_VERSION)

        logging.info("Creates a new local pool ledger configuration")
        pool_config = json.dumps({'genesis_txn': str(genesis_file_path)})

        try:
            await pool.create_pool_ledger_config(config_name=pool_name, config=pool_config)
        except IndyError as ex:
            if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
                logging.warning("Pool ledger config already exists")
                pass

        logging.info("Openging pool ledger")
        pool_handle = await pool.open_pool_ledger(config_name=pool_name, config=None)

        logging.info("Creating new secure wallet for server")
        try:
            await wallet.create_wallet(wallet_config, wallet_credentials)
        except IndyError as ex:
            if ex.error_code == ErrorCode.WalletAlreadyExistsError:
                logging.warning(
                    "wallet already exists  {}".format(wallet_config))
                pass

        logging.info("Open wallet and get handle from libindy")
        wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials)

        steward_seed = '000000000000000000000000Steward1'
        did_json = json.dumps({'seed': steward_seed})
        steward_did, steward_verkey = await did.create_and_store_my_did(wallet_handle, did_json)
        indy_config["steward_did"] = steward_did
        indy_config["steward_verkey"] = steward_verkey
        logging.info('Steward DID: {}, Steward Verkey: {}'.format(
            steward_did, steward_verkey))

        logging.info("Generating and storing trust anchor DID and verkey")
        trust_anchor_seed = '000000000000000ServerTrusteeSeed'
        trust_anchor_did_json = json.dumps({'seed': trust_anchor_seed})
        trust_anchor_did, trust_anchor_verkey = None, None
        try:
            trust_anchor_did, trust_anchor_verkey = await did.create_and_store_my_did(wallet_handle, trust_anchor_did_json)
        except IndyError as e:
            logging.warning('Error occurred: {}'.format(e.message))

        logging.info("Trust anchor seed: {}, Trust anchor DID: {}, Trusf anchor Verkey: {}".format(
            trust_anchor_seed, trust_anchor_did, trust_anchor_verkey))
        indy_config["trust_anchor_seed"] = trust_anchor_seed
        indy_config["trust_anchor_verkey"] = trust_anchor_verkey
        indy_config["trust_anchor_did"] = trust_anchor_did

        # set did metadata
        try:
            await did.set_did_metadata(wallet_handle, trust_anchor_did, "trust anchor did")
            await did.set_did_metadata(wallet_handle, steward_did, "steward did")
        except IndyError as e:
            logging.warning('Error occurred: {}'.format(e.message))

        logging.info("Building NYM request to add Trust Anchor to the ledger")
        nym_transaction_request = await ledger.build_nym_request(submitter_did=steward_did,
                                                                 target_did=trust_anchor_did,
                                                                 ver_key=trust_anchor_verkey,
                                                                 alias=None,
                                                                 role='TRUST_ANCHOR')

        logging.info("NYM transaction request: {}".format(
            json.loads(nym_transaction_request)))
        logging.info("Sending NYM request to the ledger")
        nym_transaction_response = await ledger.sign_and_submit_request(pool_handle=pool_handle,
                                                                        wallet_handle=wallet_handle,
                                                                        submitter_did=steward_did,
                                                                        request_json=nym_transaction_request)
        logging.info("NYM transaction response: {}".format(
            nym_transaction_response))

        with open('indy_config.json', 'w', encoding='utf-8') as f:
            json.dump(indy_config, f, ensure_ascii=False, indent=4)

        # add trust anchor did to wallet

        logging.info("Closing wallet and pool")
        await wallet.close_wallet(wallet_handle)
        await pool.close_pool_ledger(pool_handle)

    except IndyError as e:
        logging.warning('Error occurred: %s' % e.message)