async def test_wallet(pool_name, pool_genesis_txn_path, pool_genesis_txn_file): p = NodePool(pool_name, pool_genesis_txn_path) await p.open() assert p.handle is not None seed = '00000000000000000000000000000000' base_name = 'my-wallet' w = Wallet(p.name, seed, base_name, 0) await w.open() num = w.num assert num != None assert w.did assert w.verkey (did, verkey) = (w.did, w.verkey) await w.close() num += 1 x = Wallet(p.name, seed, base_name, num) await x.open() assert did == x.did assert verkey == x.verkey await x.close() await p.close()
async def test_wallet(pool_name, pool_genesis_txn_path, pool_genesis_txn_file): p = NodePool(pool_name, pool_genesis_txn_path, {'auto-remove': True}) await p.open() assert p.handle is not None seed = '00000000000000000000000000000000' name = 'my-wallet' # 1. Exercise configuration: auto-remove must be boolean if present, but extra properties are OK try: Wallet(p.name, seed, name, {'auto-remove': 'non-boolean'}) assert False except JSONValidation: pass Wallet(p.name, seed, name, {'auto-remove': True, 'extra-property': 'ok'}) # 2. Default configuration (auto-remove=False) w = Wallet(p.name, seed, name) await w.open() assert w.did assert w.verkey (did, verkey) = (w.did, w.verkey) await w.close() # 3. Make sure wallet opens from extant file x = Wallet(p.name, seed, name, {'auto-remove': True}) await x.open() assert did == x.did assert verkey == x.verkey await x.close() await p.close()
def __init__(self): config = hyperledger_indy.config() self.pool = NodePool('the-org-book-holder', config['genesis_txn_path']) self.instance = VonHolderProver( self.pool, Wallet(self.pool.name, WALLET_SEED, 'TheOrgBook Holder Wallet'))
def __init__(self): genesis_config = genesis.config() self.pool = NodePool( 'permitify-issuer', genesis_config['genesis_txn_path']) wallet_name = config['name'] + '_Issuer_Wallet' # TODO force to virtual for now issuer_type = 'virtual' issuer_config = {'freshness_time': 0} issuer_creds = {'key': ''} logger.debug('Using virtual Cfg: {} Creds: {}'.format( issuer_config, issuer_creds)) logger.debug("Issuer __init__>>> create wallet {} {} {}".format( issuer_type, issuer_config, issuer_creds)) issuer_wallet = Wallet( self.pool, WALLET_SEED, wallet_name, issuer_type, issuer_config, issuer_creds) logger.debug("Issuer __init__>>> done {} {} {}".format( issuer_type, issuer_config, issuer_creds)) self.instance = VonIssuer( # self.pool, issuer_wallet )
def __init__(self): genesis_config = genesis.config() self.pool = NodePool( 'permitify-verifier', genesis_config['genesis_txn_path']) wallet_name = config['name'] + '_Verifier_Wallet' # TODO force to virtual for now verifier_type = 'virtual' verifier_config = {'freshness_time': 0} verifier_creds = {'key': ''} logger.debug('Using virtual Cfg: {} Creds: {}'.format( verifier_config, verifier_creds)) logger.debug("Verifier __init__>>> {} {} {}".format( verifier_type, verifier_config, verifier_creds)) verifier_wallet = Wallet( self.pool, WALLET_SEED, wallet_name, verifier_type, verifier_config, verifier_creds) logger.debug("Verifier __init__>>> {} {} {}".format( verifier_type, verifier_config, verifier_creds)) self.instance = VonVerifier( # self.pool, verifier_wallet )
def __init__(self): WALLET_SEED = os.environ.get('INDY_WALLET_SEED') if not WALLET_SEED or len(WALLET_SEED) is not 32: raise Exception( 'INDY_WALLET_SEED must be set and be 32 characters long.') self.__logger = logging.getLogger(__name__) config = hyperledger_indy.config() self.pool = NodePool('the-org-book-verifier', config['genesis_txn_path']) wallet_name = 'TheOrgBook_Verifier_Wallet' verifier_type = 'virtual' verifier_config = {'freshness_time': 0} verifier_creds = {'key': ''} self.__logger.debug("Verifier __init__>>> {} {} {}".format( verifier_type, verifier_config, verifier_creds)) verifier_wallet = Wallet(self.pool, WALLET_SEED, wallet_name, verifier_type, verifier_config, verifier_creds) self.__logger.debug("Verifier __init__>>> {} {} {}".format( verifier_type, verifier_config, verifier_creds)) self.instance = VonVerifier( # self.pool, verifier_wallet)
async def register(request): try: seed = request.json['seed'] except KeyError as e: return sanic_text('Missing query parameter: seed', status=400) if not 0 <= len(seed) <= 32: return sanic_text('Seed must be between 0 and 32 characters long.', status=400) # Pad with zeroes seed += '0' * (32 - len(seed)) new_agent = _BaseAgent( pool, Wallet(pool.name, seed, seed + '-wallet'), ) await new_agent.open() # Register agent on the network print('\n\nRegister agents\n\n') for ag in (trust_anchor, new_agent): print('\n\nGet Nym: ' + str(ag) + '\n\n') if not json.loads(await trust_anchor.get_nym(ag.did)): print('\n\nSend Nym: ' + str(ag) + '\n\n') await trust_anchor.send_nym(ag.did, ag.verkey) await new_agent.close() return sanic_json({ 'seed': seed, 'did': new_agent.did, 'verkey': new_agent.verkey })
async def test_wallet_did_loading(pool_name, pool_genesis_txn_path, pool_genesis_txn_file): p = NodePool(pool_name, pool_genesis_txn_path, {'auto_remove': True}) seed1 = '00000000000000000000000000000000' seed2 = '11111111111111111111111111111111' name = 'my-wallet' w = Wallet(p.name, name) await w.open() await w.create_did(seed=seed1) assert w.did assert w.verkey (did1, verkey1) = (w.did, w.verkey) await w.create_did(seed=seed2) assert w.did != did1 assert w.verkey != verkey1 await w.load_did(did1) assert w.did == did1 assert w.verkey == verkey1 await w.close()
async def test_wallet_did_creation(pool_name, pool_genesis_txn_path, pool_genesis_txn_file): p = NodePool(pool_name, pool_genesis_txn_path, {'auto_remove': True}) seed1 = '00000000000000000000000000000000' seed2 = '11111111111111111111111111111111' name = 'my-wallet' w = Wallet(p.name, name) await w.open() await w.create_did(seed=seed1) assert w.did assert w.verkey (did1, verkey1) = (w.did, w.verkey) await w.create_did(seed=seed2) (did2, verkey2) = (w.did, w.verkey) stored_dids = await w.stored_dids() assert len(stored_dids) == 2 assert stored_dids[0]['did'] == did1 assert stored_dids[0]['verkey'] == verkey1 assert stored_dids[1]['did'] == did2 assert stored_dids[1]['verkey'] == verkey2 await w.close()
def __init__(self): genesis_config = genesis.config() self.pool = NodePool('permitify-holder', genesis_config['genesis_txn_path']) self.instance = VonHolderProver( self.pool, Wallet(self.pool.name, WALLET_SEED, config['name'] + ' Holder Wallet'))
async def test_wallet(pool_name, pool_genesis_txn_path, pool_genesis_txn_file): p = NodePool(pool_name, pool_genesis_txn_path, {'auto_remove': True}) seed = '00000000000000000000000000000000' name = 'my-wallet' w = Wallet(p.name, name) await w.open() await w.create_did(seed=seed) assert w.did assert w.verkey (did, verkey) = (w.did, w.verkey) await w.close() x = Wallet(p.name, name) await x.open() await x.create_did(seed=seed) assert did == x.did assert verkey == x.verkey await x.close()
async def boot(): global pool global trust_anchor pool = NodePool( 'nodepool', '/home/indy/.indy-cli/networks/sandbox/pool_transactions_genesis') wallet = Wallet(pool, '000000000000000000000000Trustee1', 'trustee_wallet') await pool.open() await wallet.create() trust_anchor = AgentRegistrar(wallet) await trust_anchor.open()
async def convert_seed_to_did(seed): genesis_config = genesis.config() pool = NodePool('util-agent', genesis_config['genesis_txn_path']) agent = _BaseAgent( pool, Wallet(pool.name, seed, seed + '-wallet'), ) await agent.open() agent_did = agent.did await agent.close() return agent_did
def __init__(self, legal_entity_id: str = None): WALLET_SEED = os.environ.get('INDY_WALLET_SEED') if not WALLET_SEED or len(WALLET_SEED) is not 32: raise Exception( 'INDY_WALLET_SEED must be set and be 32 characters long.') self.__logger = logging.getLogger(__name__) config = hyperledger_indy.config() thread_id = threading.get_ident() self.pool = NodePool('the-org-book-holder-' + str(thread_id), config['genesis_txn_path']) wallet_name = 'TheOrgBook_Holder_Wallet' + '$$' + str(thread_id) holder_type = os.environ.get('INDY_WALLET_TYPE') if holder_type == 'remote': # wallet_name = wallet_name + "$$" + str(thread_id) holder_url = os.environ.get('INDY_WALLET_URL') holder_config = { 'endpoint': holder_url, 'ping': 'schema/', 'auth': 'api-token-auth/', 'keyval': 'keyval/', 'freshness_time': 0 } holder_creds = { 'auth_token': apps.get_remote_wallet_token(), 'virtual_wallet': legal_entity_id } self.__logger.debug('Using remote Cfg: {} Creds: {}'.format( holder_config, holder_creds)) else: # TODO force to virtual for now holder_type = 'virtual' holder_config = {'freshness_time': 0} holder_creds = {'key': '', 'virtual_wallet': legal_entity_id} self.__logger.debug('Using virtual Cfg: {} Creds: {}'.format( holder_config, holder_creds)) self.__logger.debug("Holder __init__>>> {} {} {}".format( holder_type, holder_config, holder_creds)) holder_wallet = Wallet(self.pool, WALLET_SEED, wallet_name, holder_type, holder_config, holder_creds) self.__logger.debug("Holder __init__>>> {} {} {}".format( holder_type, holder_config, holder_creds)) self.instance = VonHolderProver( # self.pool, holder_wallet)
def __init__(self, legal_entity_id: str = None): logger.debug("Issuer __init__>>>") genesis_config = genesis.config() thread_id = threading.get_ident() self.pool = NodePool( # 'dflow-issuer-' + str(thread_id), 'dflow-issuer', genesis_config['genesis_txn_path']) wallet_name = config['name'] + '_Issuer_Wallet' issuer_type = os.environ.get('INDY_WALLET_TYPE') if issuer_type == 'remote': wallet_name = wallet_name + "$$" + str(thread_id) holder_url = os.environ.get('INDY_WALLET_URL') issuer_config = { 'endpoint': holder_url, 'ping': 'schema/', 'auth': 'api-token-auth/', 'keyval': 'keyval/', 'freshness_time': 0 } issuer_creds = { 'auth_token': apps.get_remote_wallet_token(), 'virtual_wallet': legal_entity_id } logger.debug('Using remote Cfg: {} Creds: {}'.format( issuer_config, issuer_creds)) else: # TODO force to virtual for now issuer_type = 'virtual' issuer_config = {'freshness_time': 0} issuer_creds = {'key': '', 'virtual_wallet': legal_entity_id} logger.debug('Using virtual Cfg: {} Creds: {}'.format( issuer_config, issuer_creds)) logger.debug("Issuer __init__>>> create wallet {} {} {}".format( issuer_type, issuer_config, issuer_creds)) issuer_wallet = Wallet(self.pool, WALLET_SEED, wallet_name, issuer_type, issuer_config, issuer_creds) logger.debug("Issuer __init__>>> done {} {} {}".format( issuer_type, issuer_config, issuer_creds)) self.instance = VonIssuer( # self.pool, issuer_wallet) logger.debug("Issuer __init__>>> created VonIssuer")
async def convert_seed_to_did(seed): genesis_config = genesis.config() pool = NodePool('util-agent', genesis_config['genesis_txn_path']) agent_wallet = Wallet(pool, seed, seed + '-' + random_string() + '-wallet') agent = _BaseAgent( # pool, agent_wallet, ) await pool.open() await agent_wallet.create() await agent.open() agent_did = agent.did await agent.close() return agent_did
def __init__(self, legal_entity_id: str = None): logger.debug("Verifier __init__>>>") genesis_config = genesis.config() self.pool = NodePool('dflow-verifier', genesis_config['genesis_txn_path']) wallet_name = config['name'] + '_Verifier_Wallet' verifier_type = os.environ.get('INDY_WALLET_TYPE') if verifier_type == 'remote': holder_url = os.environ.get('INDY_WALLET_URL') verifier_config = { 'endpoint': holder_url, 'ping': 'schema/', 'auth': 'api-token-auth/', 'keyval': 'keyval/', 'freshness_time': 0 } verifier_creds = { 'auth_token': apps.get_remote_wallet_token(), 'virtual_wallet': legal_entity_id } logger.debug('Using remote Cfg: {} Creds: {}'.format( verifier_config, verifier_creds)) else: # TODO force to virtual for now verifier_type = 'virtual' verifier_config = {'freshness_time': 0} verifier_creds = {'key': '', 'virtual_wallet': legal_entity_id} logger.debug('Using virtual Cfg: {} Creds: {}'.format( verifier_config, verifier_creds)) logger.debug("Verifier __init__>>> {} {} {}".format( verifier_type, verifier_config, verifier_creds)) verifier_wallet = Wallet(self.pool, WALLET_SEED, wallet_name, verifier_type, verifier_config, verifier_creds) logger.debug("Verifier __init__>>> {} {} {}".format( verifier_type, verifier_config, verifier_creds)) self.instance = VonVerifier( # self.pool, verifier_wallet)
def __init__(self, wallet_config: WalletConfig, instance_cls, issuer_type: str, ext_cfg=None): if not wallet_config.genesis_path: raise ValueError("Missing genesis_path for wallet configuration") self._pool = NodePool( wallet_config.name + "-" + issuer_type, wallet_config.genesis_path ) self._instance_cls = instance_cls self._instance = None self._wallet = Wallet( self._pool, wallet_config.seed, wallet_config.name + "-" + issuer_type + "-Wallet", wallet_config.type, wallet_config.params, wallet_config.creds, ) self._ext_cfg = ext_cfg self._opened = None self._keep_open = False
async def register(request): global pool body = await request.json() if not body: return web.Response(text='Expected json request body', status=400) seed = body.get('seed') did = body.get('did') verkey = body.get('verkey') alias = body.get('alias') if seed: if not 0 <= len(seed) <= 32: return web.Response( text='Seed must be between 0 and 32 characters long.', status=400) # Pad with zeroes seed += '0' * (32 - len(seed)) else: if not did or not verkey: return web.Response( text= 'Either seed the seed parameter or the did and verkey parameters must be provided.', status=400) if seed: wallet = Wallet(pool, seed, seed + '-wallet') async with _BaseAgent(await wallet.create()) as new_agent: did = new_agent.did verkey = new_agent.verkey print('\n\nRegister agent\n\n') await register_did(did, verkey, alias) return json_response({'seed': seed, 'did': did, 'verkey': verkey})
async def test_wallet(pool_name, pool_genesis_txn_path, pool_genesis_txn_file, path_home): pool = NodePool(pool_name, pool_genesis_txn_path, {'auto-remove': True}) await pool.open() assert pool.handle is not None seed = '00000000000000000000000000000000' name = 'my-wallet' path = Path(path_home, 'wallet', name) path_seed2did = path.with_name('{}.seed2did'.format(path.name)) # 1. Configuration with auto-remove set w = Wallet(pool, seed, name, None, {'auto-remove': True}) await w.create() assert path.exists(), 'Wallet path {} not present'.format(path) await w.open() assert w.did assert w.verkey await w.close() assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 1 == New wallet with auto-remove OK') # 2. Default configuration (auto-remove=False) w = Wallet(pool, seed, name) await w.create() assert path.exists(), 'Wallet path {} not present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) await w.open() assert w.did assert w.verkey (w_did, w_verkey) = (w.did, w.verkey) await w.close() assert path.exists(), 'Wallet path {} not present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 2 == New wallet with default config (no auto-remove) OK') # 3. Make sure wallet opens from extant file x = Wallet(pool, seed, name, None, {'auto-remove': True}) await x.create() async with x: assert x.did == w_did assert x.verkey == w_verkey assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 3 == Re-use extant wallet OK') # 4. Double-open try: async with await Wallet(pool, seed, name, None, { 'auto-remove': True }).create() as w: async with w: assert False except IndyError as e: assert e.error_code == ErrorCode.WalletAlreadyOpenedError assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) await pool.close() # 5. Pool closed try: x = await Wallet(pool, seed, name, None, { 'auto-remove': True }).create() await x.open() assert False except ClosedPool: pass assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 4 == Error cases error as expected')
def go(): logger = logging.getLogger(__name__) cfg = do(mem_cache.get('config')) role = (cfg['Agent']['role'] or '').lower().replace( ' ', '') # will be a dir as a pool name: spaces are evil profile = environ.get('AGENT_PROFILE').lower().replace( ' ', '') # several profiles may share a role logger.debug('Starting agent; profile={}, role={}'.format( profile, role)) pool = NodePool('pool.{}'.format(profile), cfg['Pool']['genesis.txn.path']) do(pool.open()) assert pool.handle do(mem_cache.set('pool', pool)) ag = None if role == 'trust-anchor': bootstrap_json = cfg['Agent'] ag = TrustAnchorAgent( do(Wallet(pool, cfg['Agent']['seed'], profile).create()), BootSequence.agent_config_for(cfg)) do(ag.open()) assert ag.did tag_did = ag.did # register trust anchor if need be if not json.loads(do(ag.get_nym(ag.did))): do(ag.send_nym(ag.did, ag.verkey, ag.wallet.profile)) if not json.loads(do(ag.get_endpoint(ag.did))): do(ag.send_endpoint()) # originate schemata if need be do(BootSequence.originate(ag, cfg)) elif role in ('sri', 'org-book', 'bc-registrar'): # create agent by role if role == 'sri': ag = SRIAgent( do(Wallet(pool, cfg['Agent']['seed'], profile).create()), BootSequence.agent_config_for(cfg)) elif role == 'org-book': ag = OrgBookAgent( do(Wallet(pool, cfg['Agent']['seed'], profile).create()), BootSequence.agent_config_for(cfg)) elif role == 'bc-registrar': ag = BCRegistrarAgent( do(Wallet(pool, cfg['Agent']['seed'], profile).create()), BootSequence.agent_config_for(cfg)) do(ag.open()) logger.debug('profile {}; ag class {}'.format( profile, ag.__class__.__name__)) trust_anchor_base_url = 'http://{}:{}/api/v0'.format( cfg['Trust Anchor']['host'], cfg['Trust Anchor']['port']) # get nym: if not registered; get trust-anchor host & port, post an agent-nym-send form if not json.loads(do(ag.get_nym(ag.did))): try: r = requests.get('{}/did'.format(trust_anchor_base_url)) if not r.ok: logger.error( 'Agent {} nym is not on the ledger, but trust anchor is not responding' .format(profile)) r.raise_for_status() tag_did = r.json() logger.debug('{}; tag_did {}'.format(profile, tag_did)) assert tag_did with open( pjoin(BootSequence.dir_proto, 'agent-nym-send.json'), 'r') as proto: j = proto.read() logger.debug('{}; sending {}'.format( profile, j % (ag.did, ag.verkey))) r = requests.post( '{}/agent-nym-send'.format(trust_anchor_base_url), json=json.loads(j % (ag.did, ag.verkey))) r.raise_for_status() except Exception: raise ServerError( 'Agent {} requires Trust Anchor agent, but it is not responding' .format(profile)) # get endpoint: if not present, send it if not json.loads(do(ag.get_endpoint(ag.did))): do(ag.send_endpoint()) if role in ('bc-registrar', 'sri'): # originate schemata if need be do(BootSequence.originate(ag, cfg)) if role in ('org-book'): # set master secret from os import getpid # append pid to avoid re-using a master secret on restart of HolderProver agent; indy-sdk library # is shared, so it remembers and forbids it unless we shut down all processes do( ag.create_master_secret(cfg['Agent']['master.secret'] + '.' + str(getpid()))) else: raise ServerError( 'Agent profile {} configured for unsupported role {}'.format( profile, role)) assert ag is not None do(mem_cache.set('agent', ag))
async def test_wallet(path_home): seed = '00000000000000000000000000000000' name = 'my-wallet' path = Path(path_home, 'wallet', name) path_seed2did = path.with_name('{}.seed2did'.format(path.name)) # 1. Configuration with auto-remove set w = Wallet(seed, name, None, {'auto-remove': True}) await w.create() assert path.exists(), 'Wallet path {} not present'.format(path) await w.open() assert w.did assert w.verkey await w.close() assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 1 == New wallet with auto-remove OK') # 2. Default configuration (auto-remove=False) w = Wallet(seed, name) await w.create() assert path.exists(), 'Wallet path {} not present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) await w.open() assert w.did assert w.verkey (w_did, w_verkey) = (w.did, w.verkey) await w.close() assert path.exists(), 'Wallet path {} not present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 2 == New wallet with default config (no auto-remove) OK') # 3. Make sure wallet opens from extant file x = Wallet(seed, name, None, {'auto-remove': True}) await x.create() async with x: assert x.did == w_did assert x.verkey == w_verkey assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) print('\n\n== 3 == Re-use extant wallet OK') # 4. Double-open try: async with await Wallet(seed, name, None, { 'auto-remove': True }).create() as w: async with w: assert False except IndyError as e: assert e.error_code == ErrorCode.WalletAlreadyOpenedError assert not path.exists(), 'Wallet path {} still present'.format(path) assert not path_seed2did.exists(), 'Wallet path {} still present'.format( path_seed2did) # 5. Bad config try: Wallet(seed, name, None, {'auto-remove': 'a suffusion of yellow'}) except JSONValidation: pass print('\n\n== 4 == Error cases error as expected')