Python indy.wallet.open_wallet() Examples

The following are 12 code examples of indy.wallet.open_wallet(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module indy.wallet , or try the search function .
Example #1
Source File: generate_txns.py    From indy-plenum with Apache License 2.0 6 votes vote down vote up
def get_wallet_and_pool():
    pool_name = 'pool' + randomString(3)
    wallet_name = 'wallet' + randomString(10)
    their_wallet_name = 'their_wallet' + randomString(10)
    seed_trustee1 = "000000000000000000000000Trustee1"

    await wallet.create_wallet(pool_name, wallet_name, None, None, None)
    my_wallet_handle = await wallet.open_wallet(wallet_name, None, None)

    await wallet.create_wallet(pool_name, their_wallet_name, None, None, None)
    their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None)

    await did.create_and_store_my_did(my_wallet_handle, "{}")

    (their_did, their_verkey) = await did.create_and_store_my_did(their_wallet_handle,
                                                                  json.dumps({"seed": seed_trustee1}))

    await did.store_their_did(my_wallet_handle, json.dumps({'did': their_did, 'verkey': their_verkey}))

    return their_wallet_handle, their_did 
Example #2
Source File: msgme.py    From indy-dev with Apache License 2.0 6 votes vote down vote up
def init():
    me = input('Who are you? ').strip()
    wallet_config = '{"id": "%s-wallet"}' % me
    wallet_credentials = '{"key": "%s-wallet-key"}' % me

    try:
        await wallet.create_wallet(wallet_config, wallet_credentials)
    except:
        pass
    wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials)
    print('wallet = %s' % wallet_handle)

    (my_did, my_vk) = await did.create_and_store_my_did(wallet_handle, "{}")
    print('my_did and verkey = %s %s' % (my_did, my_vk))

    their = input("Other party's DID and verkey? ").strip().split(' ')
    return wallet_handle, my_did, my_vk, their[0], their[1] 
Example #3
Source File: set_did_metadata.py    From von-network with Apache License 2.0 6 votes vote down vote up
def set_did_metadata():
    try:
        print_log('\nOpening wallet ...\n')
        print(wallet_config)
        print(wallet_credentials)
        wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials)

        print_log('\nGenerating seed hash ...')
        seed_hash = sha256(did_seed.encode()).hexdigest()
        did_metadata = {**(metadata or {}), 'public': True, 'seed_hash': seed_hash}
        
        print_log('\nWriting metadata for DID ...')
        print_log('DID: ' + wallet_did)
        print_log('Metadata: ' + json.dumps(did_metadata))
        await did.set_did_metadata(wallet_handle, wallet_did, json.dumps(did_metadata))

    except IndyError as e:
        print('Error occurred: %s' % e) 
Example #4
Source File: conftest.py    From indy-plenum with Apache License 2.0 5 votes vote down vote up
def _gen_wallet_handler(wallet_data):
    wallet_config, wallet_credentials = wallet_data
    await create_wallet(wallet_config, wallet_credentials)
    wallet_handle = await open_wallet(wallet_config, wallet_credentials)
    return wallet_handle 
Example #5
Source File: indy_provider.py    From aries-protocol-test-suite with Apache License 2.0 5 votes vote down vote up
def setup(self, config):
        if not 'ledger_name' in config:
            raise Exception(
                "The Indy provider requires a 'ledger_name' value in config.toml")
        self.pool_name = config['ledger_name']
        if not 'ledger_url' in config:
            raise Exception(
                "The Indy provider requires a 'ledger_url' value in config.toml")
        self.ledger_url = config['ledger_url']
        if not 'ledger_apts_seed' in config:
            raise Exception(
                "The Indy provider requires a 'ledger_apts_seed' value in config.toml")
        seed = config['ledger_apts_seed']
        id = config.get('name', 'test')
        key = config.get('pass', 'testpw')
        self.cfg = json.dumps({'id': id})
        self.creds = json.dumps({'key': key})
        self.seed = json.dumps({'seed': seed})
        try:
            await wallet.delete_wallet(self.cfg, self.creds)
        except Exception as e:
            pass
        await wallet.create_wallet(self.cfg, self.creds)
        self.wallet = await wallet.open_wallet(self.cfg, self.creds)
        self.master_secret_id = await anoncreds.prover_create_master_secret(self.wallet, None)
        (self.did, self.verkey) = await did.create_and_store_my_did(self.wallet, self.seed)
        # Download the genesis file
        resp = await aiohttp.ClientSession().get(self.ledger_url)
        genesis = await resp.read()
        genesisFileName = "genesis.apts"
        with open(genesisFileName, 'wb') as output:
            output.write(genesis)
        await self._open_pool({'genesis_txn': genesisFileName}) 
Example #6
Source File: conftest.py    From indy-agent with Apache License 2.0 5 votes vote down vote up
def wallet_handle(config, logger):
    wallet_config = (
        json.dumps({
            'id': config.wallet_name,
            'storage_config': {
                'path': config.wallet_path
            }
        }),
        json.dumps({'key': 'test-agent'})
    )
    # Initialization steps
    # -- Create wallet
    logger.debug('Creating wallet: {}'.format(config.wallet_name))
    try:
        await wallet.create_wallet(*wallet_config)
    except:
        pass

    # -- Open a wallet
    logger.debug('Opening wallet: {}'.format(config.wallet_name))
    wallet_handle = await wallet.open_wallet(*wallet_config)

    yield wallet_handle

    # Cleanup
    if config.clear_wallets:
        logger.debug("Closing wallet")
        await wallet.close_wallet(wallet_handle)
        logger.debug("deleting wallet")
        await wallet.delete_wallet(*wallet_config)

        logger.debug("removing wallet directory")
        os.rmdir(config.wallet_path) 
Example #7
Source File: utils.py    From indy-node with Apache License 2.0 5 votes vote down vote up
def wallet_helper(wallet_id=None, wallet_key='', wallet_key_derivation_method='ARGON2I_INT'):
    if not wallet_id:
        wallet_id = random_string(5)
    wallet_config = json.dumps({"id": wallet_id})
    wallet_credentials = json.dumps({"key": wallet_key, "key_derivation_method": wallet_key_derivation_method})
    await wallet.create_wallet(wallet_config, wallet_credentials)
    wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials)

    return wallet_handle, wallet_config, wallet_credentials 
Example #8
Source File: perf_client.py    From indy-node with Apache License 2.0 5 votes vote down vote up
def wallet_open_wallet(self, config, credential):
        return await wallet.open_wallet(config, credential) 
Example #9
Source File: getting_started.py    From indy-dev with Apache License 2.0 4 votes vote down vote up
def onboarding(pool_handle, _from, from_wallet, from_did, to, to_wallet: Optional[str], to_wallet_config: str,
                     to_wallet_credentials: str):
    logger.info("\"{}\" -> Create and store in Wallet \"{} {}\" DID".format(_from, _from, to))
    (from_to_did, from_to_key) = await did.create_and_store_my_did(from_wallet, "{}")

    logger.info("\"{}\" -> Send Nym to Ledger for \"{} {}\" DID".format(_from, _from, to))
    await send_nym(pool_handle, from_wallet, from_did, from_to_did, from_to_key, None)

    logger.info("\"{}\" -> Send connection request to {} with \"{} {}\" DID and nonce".format(_from, to, _from, to))
    connection_request = {
        'did': from_to_did,
        'nonce': 123456789
    }

    if not to_wallet:
        logger.info("\"{}\" -> Create wallet".format(to))
        try:
            await wallet.create_wallet(to_wallet_config, to_wallet_credentials)
        except IndyError as ex:
            if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
                pass
        to_wallet = await wallet.open_wallet(to_wallet_config, to_wallet_credentials)

    logger.info("\"{}\" -> Create and store in Wallet \"{} {}\" DID".format(to, to, _from))
    (to_from_did, to_from_key) = await did.create_and_store_my_did(to_wallet, "{}")

    logger.info("\"{}\" -> Get key for did from \"{}\" connection request".format(to, _from))
    from_to_verkey = await did.key_for_did(pool_handle, to_wallet, connection_request['did'])

    logger.info("\"{}\" -> Anoncrypt connection response for \"{}\" with \"{} {}\" DID, verkey and nonce"
                .format(to, _from, to, _from))
    connection_response = json.dumps({
        'did': to_from_did,
        'verkey': to_from_key,
        'nonce': connection_request['nonce']
    })
    anoncrypted_connection_response = await crypto.anon_crypt(from_to_verkey, connection_response.encode('utf-8'))

    logger.info("\"{}\" -> Send anoncrypted connection response to \"{}\"".format(to, _from))

    logger.info("\"{}\" -> Anondecrypt connection response from \"{}\"".format(_from, to))
    decrypted_connection_response = \
        json.loads((await crypto.anon_decrypt(from_wallet, from_to_key,
                                              anoncrypted_connection_response)).decode("utf-8"))

    logger.info("\"{}\" -> Authenticates \"{}\" by comparision of Nonce".format(_from, to))
    assert connection_request['nonce'] == decrypted_connection_response['nonce']

    logger.info("\"{}\" -> Send Nym to Ledger for \"{} {}\" DID".format(_from, to, _from))
    await send_nym(pool_handle, from_wallet, from_did, to_from_did, to_from_key, None)

    return to_wallet, from_to_key, to_from_did, to_from_key, decrypted_connection_response 
Example #10
Source File: did_auth.py    From indy-dev with Apache License 2.0 4 votes vote down vote up
def onboarding(pool_handle, _from, from_wallet, from_did, to, to_wallet: Optional[str], to_wallet_config: str,
                     to_wallet_credentials: str):
    logger.info("\"{}\" -> Create and store in Wallet \"{} {}\" DID".format(_from, _from, to))
    (from_to_did, from_to_key) = await did.create_and_store_my_did(from_wallet, "{}")

    logger.info("\"{}\" -> Send Nym to Ledger for \"{} {}\" DID".format(_from, _from, to))
    await send_nym(pool_handle, from_wallet, from_did, from_to_did, from_to_key, None)

    logger.info("\"{}\" -> Send connection request to {} with \"{} {}\" DID and nonce".format(_from, to, _from, to))
    connection_request = {
        'did': from_to_did,
        'nonce': 123456789
    }

    if not to_wallet:
        logger.info("\"{}\" -> Create wallet".format(to))
        try:
            await wallet.create_wallet(to_wallet_config, to_wallet_credentials)
        except IndyError as ex:
            if ex.error_code == ErrorCode.PoolLedgerConfigAlreadyExistsError:
                pass
        to_wallet = await wallet.open_wallet(to_wallet_config, to_wallet_credentials)

    logger.info("\"{}\" -> Create and store in Wallet \"{} {}\" DID".format(to, to, _from))
    (to_from_did, to_from_key) = await did.create_and_store_my_did(to_wallet, "{}")

    logger.info("\"{}\" -> Get key for did from \"{}\" connection request".format(to, _from))
    from_to_verkey = await did.key_for_did(pool_handle, to_wallet, connection_request['did'])

    logger.info("\"{}\" -> Anoncrypt connection response for \"{}\" with \"{} {}\" DID, verkey and nonce"
                .format(to, _from, to, _from))
    connection_response = json.dumps({
        'did': to_from_did,
        'verkey': to_from_key,
        'nonce': connection_request['nonce']
    })
    anoncrypted_connection_response = await crypto.anon_crypt(from_to_verkey, connection_response.encode('utf-8'))

    logger.info("\"{}\" -> Send anoncrypted connection response to \"{}\"".format(to, _from))

    logger.info("\"{}\" -> Anondecrypt connection response from \"{}\"".format(_from, to))
    decrypted_connection_response = \
        json.loads((await crypto.anon_decrypt(from_wallet, from_to_key,
                                              anoncrypted_connection_response)).decode("utf-8"))

    logger.info("\"{}\" -> Authenticates \"{}\" by comparision of Nonce".format(_from, to))
    assert connection_request['nonce'] == decrypted_connection_response['nonce']

    logger.info("\"{}\" -> Send Nym to Ledger for \"{} {}\" DID".format(_from, to, _from))
    await send_nym(pool_handle, from_wallet, from_did, to_from_did, to_from_key, None)

    return to_wallet, from_to_key, to_from_did, to_from_key, decrypted_connection_response 
Example #11
Source File: agent.py    From indy-agent with Apache License 2.0 4 votes vote down vote up
def connect_wallet(self, agent_name, passphrase, ephemeral=False):
        """ Create if not already exists and open wallet.
        """

        self.owner = agent_name
        wallet_suffix = "wallet"
        if ephemeral:
            wallet_suffix = "ephemeral_wallet"
        wallet_name = '{}-{}'.format(self.owner, wallet_suffix)

        wallet_config = json.dumps({"id": wallet_name})
        wallet_credentials = json.dumps({"key": passphrase})

        # Handle ephemeral wallets
        if ephemeral:
            try:
                await wallet.delete_wallet(wallet_config, wallet_credentials)
                print("Removing ephemeral wallet.")
            except error.IndyError as e:
                if e.error_code is error.ErrorCode.WalletNotFoundError:
                    pass  # This is ok, and expected.
                else:
                    print("Unexpected Indy Error: {}".format(e))
            except Exception as e:
                print(e)
        # pylint: disable=bare-except

        try:
            await wallet.create_wallet(wallet_config, wallet_credentials)
        except error.IndyError as e:
            if e.error_code is error.ErrorCode.WalletAlreadyExistsError:
                pass  # This is ok, and expected.
            else:
                print("Unexpected Indy Error: {}".format(e))
        except Exception as e:
            print(e)

        try:
            if self.wallet_handle:
                await wallet.close_wallet(self.wallet_handle)

            self.wallet_handle = await wallet.open_wallet(
                wallet_config,
                wallet_credentials
            )

            (_, self.endpoint_vk) = await did.create_and_store_my_did(self.wallet_handle, "{}")

            self.initialized = True

        except Exception as e:
            print(e)
            print("Could not open wallet!")

            raise WalletConnectionException 
Example #12
Source File: cred_def.py    From von-network with Apache License 2.0 4 votes vote down vote up
def write_schema_and_cred_def(cred_def_primary_file="/tmp/primarykey.txt"):
    try:
        pool_ = {
            'name': pool_name
        }
        print_log("Open Pool Ledger: {}".format(pool_['name']))

        # 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)

        # 4.
        print_log('\n4. Open wallet and get handle from libindy\n')
        print(wallet_config)
        print(wallet_credentials)
        wallet_handle = await wallet.open_wallet(wallet_config, wallet_credentials)

        print(wallet_handle)

        # 9.
        print_log('\n9. Build the SCHEMA request to add new schema to the ledger as a Steward\n')
        # get the seq # from the Sovrin schema transaction
        schema = {
            'seqNo': seq_no,
            'dest': author_did,
            'data': {
                'id': author_did + ':2:' + schema_name + ':' + schema_version,
                'seqNo': seq_no,
                'name': schema_name,
                'version': schema_version,
                'ver': '1.0',
                'attrNames': schema_attributes
            }
        }
        schema_data = schema['data']
        print(schema)

        # 11.
        print_log('\n11. Creating and storing CRED DEFINITION using anoncreds as Trust Anchor, for the given Schema\n')
        cred_def_config = json.dumps({"support_revocation": False})

        (cred_def_id, cred_def_json) = await anoncreds.issuer_create_and_store_credential_def(
                        wallet_handle, author_did, json.dumps(schema_data),
                        cred_def_tag, cred_def_type, cred_def_config)

        print_log('Credential definition: ')
        cred_def = json.loads(cred_def_json)
        pprint.pprint(cred_def)
        print_log('\nCred def primary: ')
        cred_def_primary = cred_def['value']['primary']
        cred_def_primary_output = json.dumps(cred_def_primary).translate({ord(c): None for c in string.whitespace})
        print(cred_def_primary_output)
        with open(cred_def_primary_file, "w") as text_file:
            text_file.write(cred_def_primary_output)

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