Beispiel #1
0
def close_wallet(wallet_handle):
    try:
        run_coroutine(wallet.close_wallet(wallet_handle))
    except IndyError as err:
        if err.error_code == ErrorCode.WalletInvalidHandle:
            return
        raise Exception(err.message)
Beispiel #2
0
def sign_transaction(wallet_handle: int, did: str, transaction: str) -> str:
    try:
        return run_coroutine(ledger.multi_sign_request(wallet_handle, did, transaction))
    except IndyError as err:
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid Transaction')
        raise Exception(err.message)
Beispiel #3
0
def open_pool(config: dict) -> int:
    try:
        return run_coroutine(create_and_open_pool(config))
    except IndyError as err:
        if err.error_code == ErrorCode.PoolLedgerNotCreatedError:
            raise Exception('Pool not found')
        if err.error_code == ErrorCode.CommonInvalidParam2:
            raise Exception('Invalid Pool name has been provided')
        if err.error_code == ErrorCode.PoolLedgerTimeout:
            raise Exception('Cannot connect to Pool')
        raise Exception(err.message)
Beispiel #4
0
def send_transaction(pool_handle: int, transaction: str):
    try:
        response = json.loads(
            run_coroutine(ledger.submit_request(pool_handle, transaction)))

        if response['op'] != 'REPLY':
            raise Exception(response['reason'])
    except IndyError as err:
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid Transaction')
        if err.error_code == ErrorCode.PoolLedgerTimeout:
            raise Exception('Cannot get response from Ledger')
        raise Exception(err.message)
Beispiel #5
0
def build_mint_transaction(wallet_handle: int, payment_address: str, amount: int):
    outputs = [{
        'recipient':
            payment_address if payment_address.startswith(PAYMENT_PREFIX) else PAYMENT_PREFIX + payment_address,
        'amount': amount
    }]

    try:
        return run_coroutine(payment.build_mint_req(wallet_handle, None, json.dumps(outputs), None))
    except IndyError as err:
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid payment address has been provided')
        raise Exception(err.message)
Beispiel #6
0
def open_wallet(name: str, key: str) -> int:
    wallet_config = {'id': name}
    wallet_credential = {'key': key}
    try:
        return run_coroutine(wallet.open_wallet(json.dumps(wallet_config), json.dumps(wallet_credential)))
    except IndyError as err:
        if err.error_code == ErrorCode.WalletNotFoundError:
            raise Exception('Wallet not found')
        if err.error_code == ErrorCode.CommonInvalidStructure:
            raise Exception('Invalid Wallet name has been provided')
        if err.error_code == ErrorCode.WalletAccessFailed:
            raise Exception('Invalid key has been provided')
        raise Exception(err.message)
    (trustee_did, _) = await did.create_and_store_my_did(wallet_handle, json.dumps({"seed": seed_trustee1}))

    # 6. Prepare and send NYM transaction
    nym_txn_req = await ledger.build_nym_request(trustee_did, new_did, new_verkey, None, None)
    await ledger.sign_and_submit_request(pool_handle, wallet_handle, trustee_did, nym_txn_req)

    # 7. Prepare and send GET_NYM request
    get_nym_txn_req = await ledger.build_get_nym_request(trustee_did, new_did)
    get_nym_txn_resp = await ledger.submit_request(pool_handle, get_nym_txn_req)

    get_nym_txn_resp = json.loads(get_nym_txn_resp)

    assert get_nym_txn_resp['result']['dest'] == new_did

    # 8. Close wallet and pool
    await wallet.close_wallet(wallet_handle)
    await pool.close_pool_ledger(pool_handle)

    # 10. Delete wallets
    await wallet.delete_wallet(wallet_name, credentials)

    # 11. Delete pool ledger config
    await pool.delete_pool_ledger_config(pool_name)

    logger.info("Ledger sample -> completed")


if __name__ == '__main__':
    run_coroutine(demo)
    time.sleep(1)  # FIXME waiting for libindy thread complete
Beispiel #8
0
import time

from src import anoncreds, crypto, ledger, getting_started
from src.utils import run_coroutine


async def main():
    await anoncreds.demo()
    await crypto.demo()
    await ledger.demo()
    await getting_started.run()


if __name__ == '__main__':
    run_coroutine(main)
    time.sleep(1)  # FIXME waiting for libindy thread complete
        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)

    logger.info(
        " \"Sovrin Steward\" -> Creating wallet to store its credentials\n")
    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

    logger.info(" \"Sovrin Steward\" -> Opening Steward wallet \n")
    steward_wallet = await wallet.open_wallet(steward_wallet_config,
                                              steward_wallet_credentials)

    logger.info(" \"Sovrin Steward\" -> Deleting Steward wallet \n")
    await wallet.close_wallet(steward_wallet)
    await wallet.delete_wallet(steward_wallet_config,
                               steward_wallet_credentials)


if __name__ == '__main__':
    run_coroutine(run)
    time.sleep(1)
Beispiel #10
0
def get_stored_dids(wallet_handle) -> list:
    try:
        dids = run_coroutine(did.list_my_dids_with_meta(wallet_handle))
        return json.loads(dids)
    except IndyError as err:
        raise Exception(err.message)
Beispiel #11
0
def close_pool(pool_handle):
    try:
        run_coroutine(close_and_delete_pool(pool_handle))
    except IndyError as err:
        raise Exception(err.message)
Beispiel #12
0
wallet_credentials = json.dumps({"key": "wallet_key"})
pool_config = json.dumps({"genesis_txn": str(pool_genesis_txn_path)})


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 write_nym_and_query_verkey():
    try:
        await pool.set_protocol_version(PROTOCOL_VERSION)
        # Step 2 code goes here.

        # Step 3 code goes here.

        # Step 4 code goes here.

        # Step 5 code goes here.

    except IndyError as e:
        print('Error occurred: %s' % e)


if __name__ == '__main__':
    run_coroutine(write_nym_and_query_verkey)
    time.sleep(1)  # FIXME waiting for libindy thread complete

Beispiel #13
0
    # 7. User send ATTRIB transaction to Ledger
    attr_req = \
        await ledger.build_attrib_request(user['did'], user['did'], None, '{"endpoint":{"ha":"127.0.0.1:5555"}}', None)
    resp = await ledger.sign_and_submit_request(user['pool'], user['wallet'], user['did'], attr_req)

    assert json.loads(resp)['op'] == 'REPLY'

    # 8. Close and delete Trustee wallet
    await wallet.close_wallet(trustee['wallet'])
    await wallet.delete_wallet(trustee['wallet_config'], trustee['wallet_credentials'])

    # 9. Close and delete User wallet
    await wallet.close_wallet(user['wallet'])
    await wallet.delete_wallet(user['wallet_config'], user['wallet_credentials'])

    # 10. Close Trustee and User pools
    await pool.close_pool_ledger(trustee['pool'])
    await pool.close_pool_ledger(user['pool'])

    # 11 Delete pool ledger config
    await pool.delete_pool_ledger_config(trustee['pool_name'])
    await pool.delete_pool_ledger_config(user['pool_name'])

    logger.info("Ledger sample -> completed")


if __name__ == '__main__':
    run_coroutine(demo)
    time.sleep(1)  # FIXME waiting for libindy thread complete
Beispiel #14
0
import time

from src import anoncreds, anoncreds_revocation, crypto, ledger, getting_started, txn_author_agreement
from src.utils import run_coroutine


async def main():
    await getting_started.run()
    await anoncreds.demo()
    await anoncreds_revocation.demo()
    await anoncreds.demo()
    await crypto.demo()
    await ledger.demo()
    await txn_author_agreement.demo()

if __name__ == '__main__':
    run_coroutine(main)
    time.sleep(1)  # FIXME waiting for libindy thread complete