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
    })
示例#2
0
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
示例#3
0
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
示例#4
0
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})