Пример #1
0
    async def start_vcx(self):
        payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
        payment_plugin.nullpay_init()

        print("Provision an agent and wallet, get back configuration details")
        config = await vcx_agent_provision(json.dumps(provisionConfig))
        config = json.loads(config)
        # Set some additional configuration options specific to faber
        config['institution_name'] = 'Faber'
        config['institution_logo_url'] = 'http://robohash.org/234'
        config['genesis_path'] = 'local-genesis.txt'

        print("Initialize libvcx with new configuration")
        await vcx_init_with_config(json.dumps(config))

        pass
Пример #2
0
async def main():

    payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
    payment_plugin.nullpay_init()

    # Set up agent and VCX
    config = await vcx_agent_provision(json.dumps(provisionConfig))
    config = json.loads(config)
    config['institution_name'] = 'prover'
    config['institution_logo_url'] = 'http://robohash.org/2'
    config['genesis_path'] = 'genesis.txn'
    await vcx_init_with_config(json.dumps(config))

    # Input invitation details, connect to issuer and wait for them to issue a credential offer
    details = input('invite details: ')
    jdetails = json.loads(details)
    connection_to_issuer = await Connection.create_with_details('issuer', json.dumps(jdetails))
    await connection_to_issuer.connect('{"use_public_did": true}')
    await connection_to_issuer.update_state()
    sleep(10)
    offers = await Credential.get_offers(connection_to_issuer)

    # Create credential, send credential request and wait for credential offer from issuer
    # The issuer creates an IssuerCredential object and the prover creates a Credential object
    credential = await Credential.create('credential', offers[0])
    await credential.send_request(connection_to_issuer, 0)
    credential_state = await credential.get_state()
    while credential_state != State.Accepted:
        sleep(2)
        await credential.update_state()
        credential_state = await credential.get_state()

    # Wait for a proof request, create proof, fill with credentials from wallet, generate and send
    requests = await DisclosedProof.get_requests(connection_to_issuer)
    proof = await DisclosedProof.create('proof', requests[0])
    credentials = await proof.get_creds()
    for attr in credentials['attrs']:
        credentials['attrs'][attr] = {
            'credential': credentials['attrs'][attr][0]
        }
    await proof.generate_proof(credentials, {})
    await proof.send_proof(connection_to_issuer)
    async def start_vcx(self):
        payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
        payment_plugin.nullpay_init()

        print("Start vcx agency process")
        # http port is the main agency port
        # admin_port and admin_port+1 are used by the agency server
        # we need to rewrite these to the config file
        input_config = "./vcx_agency/agency_config.json.template"
        self.output_config = "./vcx_agency/agency_config.json"
        agency_host = os.getenv("DOCKERHOST") or "host.docker.internal"
        self.rewrite_config(
            input_config, self.output_config, {
                "$DOCKERHOST": agency_host,
                "$AGENCY_PORT": str(self.http_port),
                "$AGENCY_ADDRESS_1": str(self.admin_port),
                "$AGENCY_ADDRESS_2": str(self.admin_port + 1),
            })
        await self.start_vcx_agency()

        print("Provision an agent and wallet, get back configuration details")
        provisionConfig["agency_url"] = "http://localhost:" + str(
            self.admin_port)
        config = await vcx_agent_provision(json.dumps(provisionConfig))
        config = json.loads(config)
        # Set some additional configuration options specific to faber
        config['institution_name'] = 'Faber'
        config['institution_logo_url'] = 'http://robohash.org/234'
        config['genesis_path'] = 'genesis_txn.txt'
        with open(config['genesis_path'], "w") as f_genesis:
            f_genesis.write(self.genesis_data)

        print("Initialize libvcx with new configuration")
        await vcx_init_with_config(json.dumps(config))

        pass
Пример #4
0
async def main():
    doc_version = 1.4
    """
        This section is to initialize the credentials and wallet
    """
    payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
    payment_plugin.nullpay_init()
    print("Iniciando SRE...")
    print("..................")
    # 1 Provision an agent and wallet, get back configuration details
    print("#1 Proporcionar cartera de llaves")
    config = await vcx_agent_provision(json.dumps(provisionConfig))
    config = json.loads(config)
    # print("#2 Extra configuration for SRE")
    # 2 Extra configuration for SRE
    config['institution_name'] = 'SRE'
    config['institution_logo_url'] = 'http://robohash.org/234'
    config['genesis_path'] = 'docker.txn'
    # print(config)
    with open('sre.json', 'w') as outfile:
        json.dump(config, outfile)
    """
        Open serialized config to restore session
    """
    # print("#1 Cargar configuracion inicial")
    # with open('sre.json') as conf:
    #     config = json.load(conf)
    # config = json.loads(config)
    print("#2 Inicializar VCX Libreria con configuracion de cartera")
    session = await vcx_init_with_config(json.dumps(config))
    """
        Here we create a new schema for the structure of credentials
    """
    print("#3 Crear un nuevo Schema en el ledger")
    version = format("%d.%d.%d" % (random.randint(
        1, 101), random.randint(1, 101), random.randint(1, 101)))
    schema = await Schema.create(
        'passport_' + str(doc_version), 'schema_pass_' + str(doc_version),
        version,
        ['name', 'date_of_birth', 'passport_id', 'nationality', 'gender'], 0)
    schema_id = await schema.get_schema_id()
    with open('schema.json', 'w') as out_sch:
        json.dump(await schema.serialize(), out_sch)
    """
        Load already created schema
    """
    # print("#3 Load already created schema on the ledger")
    # with open('schema.json') as conf:
    #     schema_config = json.load(conf)
    # # schema_config = json.loads(config)
    # schema = await Schema.deserialize(schema_config)
    # schema_id = await schema.get_schema_id()
    """
        Here we create a new credential_definition
    """
    print(
        "#4 Crear un nuevo Credential Definition para establecerse como emisor de credenciales"
    )
    cred_def = await CredentialDef.create('credef_pass_' + str(doc_version),
                                          'passport_cred_' + str(doc_version),
                                          schema_id, 0)
    cred_def_handle = cred_def.handle
    cred_def_id = await cred_def.get_cred_def_id()
    with open('cred_def.json', 'w') as out_cred_def:
        json.dump(await cred_def.serialize(), out_cred_def)
    """
        Load already created credentiad_definition
    """
    # print("#4 Cargar definicion de credencial ya hecha en el ledger")
    # with open('cred_def.json') as conf:
    #     cred_def_config = json.load(conf)
    # # cred_def_config = json.loads(config)
    # cred_def = await CredentialDef.deserialize(cred_def_config)
    # cred_def_id = await cred_def.get_cred_def_id()
    """
        New invitation details
    """
    print("#5 SRE crea nueva conexion para Alam y envia invitacion")
    connection_to_alam = await Connection.create('other')
    await connection_to_alam.connect('{"use_public_did": true}')
    await connection_to_alam.update_state()
    details = await connection_to_alam.invite_details(False)
    print("**invite details**")
    print(json.dumps(details))
    print("******************")

    print("#6 Esperar a que Alam acepte la invitacion")
    connection_state = await connection_to_alam.get_state()
    while connection_state != State.Accepted:
        sleep(2)
        await connection_to_alam.update_state()
        connection_state = await connection_to_alam.get_state()

    schema_attrs = {
        'name':
        'Alam',
        'date_of_birth':
        format("%d-%d-%d" % (random.randint(1, 30), random.randint(
            1, 12), random.randint(1960, 2019))),
        'passport_id':
        format("G%d%d%d" % (random.randint(1, 99), random.randint(
            20, 50), random.randint(10, 15))),
        'nationality':
        'mexicana',
        'gender':
        'M',
    }
    """
        Start to create a credential issuer
    """
    print(
        "#12 Crear objeto de emision de credencial utilizando un CredDef y un Schema especificos"
    )
    print("Con la informacion de Alam", schema_attrs)
    credential = await IssuerCredential.create('alam_pass', schema_attrs,
                                               cred_def_handle,
                                               'passport' + str(doc_version),
                                               '0')
    with open('cred_iss.json', 'w') as out_cred_iss:
        json.dump(await credential.serialize(), out_cred_iss)
    """
        Load Credential Issuer
    """
    # print("#4 Load already created Credential Issuer")
    # with open('cred_iss.json') as conf:
    #     cred_iss_config = json.load(conf)
    # cred_iss_config = json.loads(config)
    # credential = await IssuerCredential.deserialize(cred_iss_config)

    print("#13 Emitir oferta de credencial a Alam")
    await credential.send_offer(connection_to_alam)
    await credential.update_state()

    print("#14 Esperar respuesta satisfactoria")
    credential_state = await credential.get_state()
    while credential_state != State.RequestReceived:
        sleep(2)
        await credential.update_state()
        credential_state = await credential.get_state()

    print("#17 Emitir credencial a Alam")
    await credential.send_credential(connection_to_alam)

    print(
        "#18 Esperar a que Alam reciba credencial y responda de confirmacion")
    await credential.update_state()
    credential_state = await credential.get_state()
    while credential_state != State.Accepted:
        sleep(2)
        await credential.update_state()
        credential_state = await credential.get_state()
Пример #5
0
async def main():

    payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
    payment_plugin.nullpay_init()
    print("Iniciando Banco...")
    print("..................")
    print("#1 Proporcionar cartera de llaves")
    config = await vcx_agent_provision(json.dumps(provisionConfig))
    config = json.loads(config)
    # Set some additional configuration options specific to alice
    config['institution_name'] = 'banco'
    config['institution_logo_url'] = 'http://robohash.org/456'
    config['genesis_path'] = 'docker.txn'
    with open('banco.json', 'w') as outfile:
        json.dump(json.dumps(config), outfile)
    print("#8 Inicializar VCX Libreria con configuracion de cartera")
    session = await vcx_init_with_config(json.dumps(config))

    print("#5 Banco crea nueva conexion para Alam y enviar invitacion")
    connection_to_alam = await Connection.create('other')
    await connection_to_alam.connect('{"use_public_did": true}')
    await connection_to_alam.update_state()
    details = await connection_to_alam.invite_details(False)
    print("**invite details**")
    print(json.dumps(details))
    print("******************")

    print("#6 Esperar a que Alam acepte la invitacion")
    connection_state = await connection_to_alam.get_state()
    while connection_state != State.Accepted:
        sleep(2)
        await connection_to_alam.update_state()
        connection_state = await connection_to_alam.get_state()

    with open('sre.json', 'r') as s_c:
        sre_conf = json.load(s_c)
    proof_attrs = [{
        'name':
        'name',
        'restrictions': [{
            'issuer_did': sre_conf['institution_did']
        }]
    }, {
        'name':
        'date_of_birth',
        'restrictions': [{
            'issuer_did': sre_conf['institution_did']
        }]
    }, {
        'name':
        'nationality',
        'restrictions': [{
            'issuer_did': sre_conf['institution_did']
        }]
    }]
    print("\n\n Atributos solicitados:\n")
    for el in proof_attrs:
        print(el["name"])

    print("#19 Crear solicitud de prueba de informacion:")
    print("Solicita - Nombre, fecha de nacimiento y nacionalidad")
    print(
        "En este caso hacemos una solicitud de documentos pero tienen que estar firmados exclusivamente por la SRE"
    )
    proof = await Proof.create('proof_uuid', 'proof_from_alam', proof_attrs,
                               {})

    print("#20 Enviar solicitud de informacion")
    await proof.request_proof(connection_to_alam)

    print("#21 Esperar respuesta de Alam")
    proof_state = await proof.get_state()
    while proof_state != State.Accepted:
        sleep(2)
        await proof.update_state()
        proof_state = await proof.get_state()

    print(
        "#27 Procesar la prueba, comprobar firma digital del emisor, secreto maestro de Alam e informacion valida"
    )
    info = await proof.get_proof(connection_to_alam)

    print("#28 Validando prueba...")
    if proof.proof_state == ProofState.Verified:
        print("Prueba verificada")
    else:
        print("Informacion invalida")
    attrs = info["requested_proof"]["revealed_attrs"]
    print("\n\n Atributos revelados:\n")
    for key, value in attrs.items():
        print(key, value["raw"])
Пример #6
0
async def main():

    payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
    payment_plugin.nullpay_init()
    print("Iniciando Alam...")
    print("..................")
    print("#1 Proporcionar cartera de llaves")
    config = await vcx_agent_provision(json.dumps(provisionConfig))
    config = json.loads(config)
    # Set some additional configuration options specific to alice
    config['institution_name'] = 'alice'
    config['institution_logo_url'] = 'http://robohash.org/456'
    config['genesis_path'] = 'docker.txn'
    with open('alam.json', 'w') as outfile:
        json.dump(json.dumps(config), outfile)
    # print("#1 Cargar configuracion inicial")
    # with open('sre.json') as conf:
    #     config = json.load(conf)
    # print(type(config))
    # config = json.loads(config)
    print("#8 Inicializar VCX Libreria con configuracion de cartera")
    session = await vcx_init_with_config(json.dumps(config))

    print("#9 Ingresar detalles de invitacion SRE")
    details = input('Detalles de invitacion: ')

    print("#10 Convertir string a json y crear conexion")
    jdetails = json.loads(details)
    connection_to_sre = await Connection.create_with_details('sre', json.dumps(jdetails))
    await connection_to_sre.connect('{"use_public_did": true}')
    await connection_to_sre.update_state()

    print("#11 Esperar a que SRE emita oferta de credencial")
    sleep(10)
    offers = await Credential.get_offers(connection_to_sre)

    # Create a credential object from the credential offer
    credential = await Credential.create('credential', offers[0])

    print("#15 Una vez recibida la oferta, responder a la peticion")
    await credential.send_request(connection_to_sre, 0)

    print("#16 Esperar respuesta de SRE y aceptar credencial")
    credential_state = await credential.get_state()
    while credential_state != State.Accepted:
        sleep(2)
        await credential.update_state()
        credential_state = await credential.get_state()
    print("Credencial aceptada!")
    print("#9 Ingresar detalles de invitacion Banco")
    details = input('Detalles de invitacion: ')

    print("#10 Convertir string a json y crear conexion")
    jdetails = json.loads(details)
    connection_to_bank = await Connection.create_with_details('bank', json.dumps(jdetails))
    await connection_to_bank.connect('{"use_public_did": true}')
    await connection_to_bank.update_state()
    sleep(10)
    print("#22 Hacer request de solicitudes de pruebas")
    requests = await DisclosedProof.get_requests(connection_to_bank)

    print("#23 Una vez recibida la solicitud, crear nueva prueba con requisitos")
    proof = await DisclosedProof.create('proof_pass', requests[0])

    print("#24 Consultar cartera por credenciales que satisfagan la informacion requerida")
    credentials = await proof.get_creds()
    print(credentials)
    # Use the first available credentials to satisfy the proof request
    for attr in credentials['attrs']:
        credentials['attrs'][attr] = {
            'credential': credentials['attrs'][attr][0]
        }
    # print(credentials)

    print("#25 Generar la prueba con las credenciales y atributos necesarios")
    await proof.generate_proof(credentials, {})

    print("#26 Enviar prueba de informacion al Banco")
    await proof.send_proof(connection_to_bank)
Пример #7
0
from vcx.api.issuer_credential import IssuerCredential
from vcx.api.proof import Proof
from vcx.api.schema import Schema
from vcx.api.utils import vcx_agent_provision
from vcx.api.vcx_init import vcx_init_with_config
from vcx.state import State, ProofState

app = Quart(__name__, static_url_path='/static')
"""
    Global variables that are going to
    be used throughout all the proces of verification
"""
name = ""
sre_connections = {}
credentials = []
payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
payment_plugin.nullpay_init()


"""
    This is the privisional configuration for the SRE entity
    It is mainly for initialization purposes.
"""
provisionConfig = {
  'agency_url':'http://localhost:8080',
  'agency_did':'VsKV7grR1BUE29mG2Fm2kX',
  'agency_verkey':'Hezce2UWMZ3wUhVkh2LfKSs8nDzWwzs2Win7EzNN3YaR',
  'wallet_name':'sre_wallet',
  'wallet_key':'123',
  'payment_method': 'null',
  'enterprise_seed':'000000000000000000000000Trustee1'
Пример #8
0
async def main():

    payment_plugin = cdll.LoadLibrary('libnullpay' + file_ext())
    payment_plugin.nullpay_init()

    # Set up agent and VCX
    config = await vcx_agent_provision(json.dumps(provisionConfig))
    config = json.loads(config)
    config['institution_name'] = 'Issuer'
    config['institution_logo_url'] = 'http://robohash.org/1'
    config['genesis_path'] = 'genesis.txn'
    await vcx_init_with_config(json.dumps(config))

    # New schema and cred def
    version = format("%d.%d.%d" % (random.randint(
        1, 101), random.randint(1, 101), random.randint(1, 101)))
    schema = await Schema.create('schema_uuid', 'access schema', version,
                                 ['name', 'date', 'access'], 0)
    schema_id = await schema.get_schema_id()
    cred_def = await CredentialDef.create('credef_uuid', 'access', schema_id,
                                          0)
    cred_def_handle = cred_def.handle
    await cred_def.get_cred_def_id()

    # Connect to prover, wait for them to accept (requires prover.py running)
    connection_to_prover = await Connection.create('prover')
    await connection_to_prover.connect('{"use_public_did": true}')
    await connection_to_prover.update_state()
    details = await connection_to_prover.invite_details(False)
    print(json.dumps(details))
    connection_state = await connection_to_prover.get_state()
    while connection_state != State.Accepted:
        sleep(2)
        await connection_to_prover.update_state()
        connection_state = await connection_to_prover.get_state()

    # Create credential and offer it to the prover, wait for them to make a credential request
    # The issuer creates an IssuerCredential object and the prover creates a Credential object
    schema_attrs = {
        'name': 'prover',
        'date': '01-2020',
        'access': 'yes',
    }
    credential = await IssuerCredential.create('prover_access', schema_attrs,
                                               cred_def_handle, 'cred', '0')
    await credential.send_offer(connection_to_prover)
    await credential.update_state()
    credential_state = await credential.get_state()
    while credential_state != State.RequestReceived:
        sleep(2)
        await credential.update_state()
        credential_state = await credential.get_state()

    # Send credential and wait for prover to receive it
    await credential.send_credential(connection_to_prover)
    await credential.update_state()
    credential_state = await credential.get_state()
    while credential_state != State.Accepted:
        sleep(2)
        await credential.update_state()
        credential_state = await credential.get_state()

    # Create proof and request it from the prover, wait for them to sen
    proof_attrs = [{
        'name': 'name',
        'restrictions': [{
            'issuer_did': config['institution_did']
        }]
    }, {
        'name': 'date',
        'restrictions': [{
            'issuer_did': config['institution_did']
        }]
    }, {
        'name': 'access',
        'restrictions': [{
            'issuer_did': config['institution_did']
        }]
    }]
    proof = await Proof.create('proof_uuid', 'proof_from_prover', proof_attrs,
                               {})
    await proof.request_proof(connection_to_prover)
    proof_state = await proof.get_state()
    while proof_state != State.Accepted:
        sleep(2)
        await proof.update_state()
        proof_state = await proof.get_state()

    # Get and verify proof
    await proof.get_proof(connection_to_prover)
    if proof.proof_state == ProofState.Verified:
        print("proof is verified!!")
    else:
        print("could not verify proof.")