コード例 #1
0
ファイル: faber.py プロジェクト: xxjoshuaxx/hyperledgertest
def create_faber(name=None,
                 wallet=None,
                 base_dir_path=None,
                 port=5555,
                 client=None):

    if client is None:
        client = create_client(base_dir_path=base_dir_path,
                               client_class=TestClient)

    endpoint_args = {'onlyListener': True}
    if wallet:
        endpoint_args['seed'] = wallet._signerById(wallet.defaultId).seed
    else:
        wallet = Wallet(name)
        wallet.addIdentifier(signer=FABER_SIGNER)
        endpoint_args['seed'] = FABER_SEED

    agent = WalletedAgent(name=name or "Faber College",
                          basedirpath=base_dir_path,
                          client=client,
                          wallet=wallet,
                          port=port,
                          endpointArgs=endpoint_args)

    agent._invites = {
        "b1134a647eb818069c089e7694f63e6d": (1, "Alice"),
        "2a2eb72eca8b404e8d412c5bf79f2640": (2, "Carol"),
        "7513d1397e87cada4214e2a650f603eb": (3, "Frank"),
        "710b78be79f29fc81335abaa4ee1c5e8": (4, "Bob")
    }

    transcript_def = AttribDef('Transcript', [
        AttribType('student_name', encode=True),
        AttribType('ssn', encode=True),
        AttribType('degree', encode=True),
        AttribType('year', encode=True),
        AttribType('status', encode=True)
    ])

    agent.add_attribute_definition(transcript_def)

    backend = MockBackendSystem(transcript_def)

    backend.add_record(1,
                       student_name="Alice Garcia",
                       ssn="123-45-6789",
                       degree="Bachelor of Science, Comp Sci",
                       year="2015",
                       status="graduated")

    backend.add_record(2,
                       student_name="Carol Atkinson",
                       ssn="783-41-2695",
                       degree="Bachelor of Science, Physics",
                       year="2012",
                       status="graduated")

    backend.add_record(3,
                       student_name="Frank Jeffrey",
                       ssn="996-54-1211",
                       degree="Bachelor of Arts, History",
                       year="2013",
                       status="dropped")

    backend.add_record(4,
                       student_name="Bob Richards",
                       ssn="151-44-5876",
                       degree="MBA, Finance",
                       year="2015",
                       status="graduated")

    agent.set_issuer_backend(backend)

    return agent
コード例 #2
0
def test_end_to_end(tconf):
    base_dir = tconf.CLI_BASE_DIR

    print('*' * 20)
    print(base_dir)
    print('*' * 20)

    with create_local_pool(base_dir) as network:

        print(network.genesis_transactions)

        network.runFor(5)

        client = network.create_client(5555)

        bank_wallet = Wallet()
        bank_agent = RefAgent(name="bank",
                              basedirpath=base_dir,
                              client=client,
                              wallet=bank_wallet,
                              port=8787,
                              endpointArgs={'seed': BANK_SEED,
                                            'onlyListener': True})

        network.add(bank_agent)

        bank_id, bank_verkey = bank_agent.new_identifier(seed=BANK_SEED)

        print(bank_id)
        print(bank_verkey)

        s1_agent = network.steward_agent()

        s1_agent.publish_trust_anchor(Identity(identifier=bank_id,
                                               verkey=bank_verkey,
                                               role=TRUST_ANCHOR))
        network.runFor(5)

        # this allows calling asynchronous functions from a synchronous context
        run_async = network.run

        bank_attribute_definition = anoncreds.protocol.types.AttribDef(
            'basic', [
                anoncreds.protocol.types.AttribType(
                    'title', encode=True), anoncreds.protocol.types.AttribType(
                    'first_name', encode=True), anoncreds.protocol.types.AttribType(
                    'last_name', encode=True), anoncreds.protocol.types.AttribType(
                        'address_1', encode=True), anoncreds.protocol.types.AttribType(
                            'address_2', encode=True), anoncreds.protocol.types.AttribType(
                                'address_3', encode=True), anoncreds.protocol.types.AttribType(
                                    'postcode_zip', encode=True), anoncreds.protocol.types.AttribType(
                                        'date_of_birth', encode=True), anoncreds.protocol.types.AttribType(
                                            'account_type', encode=True), anoncreds.protocol.types.AttribType(
                                                'year_opened', encode=True), anoncreds.protocol.types.AttribType(
                                                    'account_status', encode=True)])

        bank_agent.add_attribute_definition(bank_attribute_definition)

        backend = MockBackendSystem(bank_attribute_definition)

        alices_id_in_banks_system = 1999891343
        bobs_id_in_banks_system = 2911891343

        backend.add_record(alices_id_in_banks_system,
                           title='Mrs.',
                           first_name='Alicia',
                           last_name='Garcia',
                           address_1='H-301',
                           address_2='Street 1',
                           address_3='UK',
                           postcode_zip='G61 3NR',
                           date_of_birth='December 28, 1990',
                           account_type='savings',
                           year_opened='2000',
                           account_status='active')
        backend.add_record(bobs_id_in_banks_system,
                           title='Mrs.',
                           first_name='Jay',
                           last_name='Raj',
                           address_1='222',
                           address_2='Baker Street',
                           address_3='UK',
                           postcode_zip='G61 3NR',
                           date_of_birth='January 15, 1980',
                           account_type='savings',
                           year_opened='1999',
                           account_status='active')

        bank_agent.set_issuer_backend(backend)

        schema_id = run_async(
            bank_agent.publish_schema('basic',
                                      schema_name='Bank Membership',
                                      schema_version='1.0'))

        # NOTE: do NOT use known primes in a non-test environment

        issuer_pub_key, revocation_pub_key = run_async(
            bank_agent.publish_issuer_keys(schema_id,
                                           p_prime=primes["prime1"][0],
                                           q_prime=primes["prime1"][1]))
        print(issuer_pub_key)
        print(revocation_pub_key)

        # TODO: Not implemented yet
        # accPK = run_async(bank_agent.publish_revocation_registry(
        #     schema_id=schema_id))

        # print(accPK)

        run_async(bank_agent._set_available_claim_by_internal_id(
            alices_id_in_banks_system, schema_id))
        run_async(bank_agent._set_available_claim_by_internal_id(
            bobs_id_in_banks_system, schema_id))

        alice_wallet = Wallet()
        alice_agent = RefAgent(name="Alice",
                               basedirpath=base_dir,
                               client=client,
                               wallet=alice_wallet,
                               port=8786)

        network.add(alice_agent)

        network.runFor(1)

        request = bank_agent.create_connection_request(
            alices_id_in_banks_system, "Alice")

        # Transfer of this request happens out-of-band (website, QR code, etc)

        alices_link_to_bank = alice_agent.load_request_str(request)

        # notice the link is not accepted
        print(alices_link_to_bank)

        alice_agent.accept_request(alices_link_to_bank)

        network.runFor(10)

        # notice that the link is accepted
        print(alices_link_to_bank)

        banks_link_to_alice = bank_agent.get_link_by_name(
            alices_id_in_banks_system)

        # note the available claims are now there
        print(banks_link_to_alice)

        claim_to_request = alices_link_to_bank.find_available_claim(
            name='Bank Membership')

        print(claim_to_request)

        run_async(alice_agent.send_claim(alices_link_to_bank,
                                         claim_to_request))
        network.runFor(5)

        claim = run_async(alice_agent.get_claim(schema_id))
        print(claim)
コード例 #3
0
def create_acme(name=None, wallet=None, base_dir_path=None,
                port=6666, client=None):
    if client is None:
        client = create_client(base_dir_path=None, client_class=TestClient)

    endpoint_args = {'onlyListener': True}
    if wallet:
        endpoint_args['seed'] = wallet._signerById(wallet.defaultId).seed
    else:
        wallet = Wallet(name)
        wallet.addIdentifier(signer=ACME_SIGNER)
        endpoint_args['seed'] = ACME_SEED

    agent = AcmeAgent(name=name or "Acme Corp",
                      basedirpath=base_dir_path,
                      client=client,
                      wallet=wallet,
                      port=port,
                      endpointArgs=endpoint_args)

    # maps request nonces to internal ids
    agent._invites = {
        "57fbf9dc8c8e6acde33de98c6d747b28c": (1, "Alice"),
        "3a2eb72eca8b404e8d412c5bf79f2640": (2, "Carol"),
        "8513d1397e87cada4214e2a650f603eb": (3, "Frank"),
        "810b78be79f29fc81335abaa4ee1c5e8": (4, "Bob")
    }

    job_cert_def = AttribDef('Job-Certificate',
                             [AttribType('first_name', encode=True),
                              AttribType('last_name', encode=True),
                              AttribType('employee_status', encode=True),
                              AttribType('experience', encode=True),
                              AttribType('salary_bracket', encode=True)])

    job_appl_def = AttribDef('Job-Application',
                             [AttribType('first_name', encode=True),
                              AttribType('last_name', encode=True),
                              AttribType('phone_number', encode=True),
                              AttribType('degree', encode=True),
                              AttribType('status', encode=True),
                              AttribType('ssn', encode=True)])

    agent.add_attribute_definition(job_cert_def)
    agent.add_attribute_definition(job_appl_def)

    backend = MockBackendSystem(job_cert_def)
    backend.add_record(1,
                       first_name="Alice",
                       last_name="Garcia",
                       employee_status="Permanent",
                       experience="3 years",
                       salary_bracket="between $50,000 to $100,000")

    backend.add_record(2,
                       first_name="Carol",
                       last_name="Atkinson",
                       employee_status="Permanent",
                       experience="2 years",
                       salary_bracket="between $60,000 to $90,000")

    backend.add_record(3,
                       first_name="Frank",
                       last_name="Jeffrey",
                       employee_status="Temporary",
                       experience="4 years",
                       salary_bracket="between $40,000 to $80,000")

    backend.add_record(4,
                       first_name="Bob",
                       last_name="Richards",
                       employee_status="On Contract",
                       experience="3 years",
                       salary_bracket="between $50,000 to $70,000")

    agent.set_issuer_backend(backend)

    agent._proofRequestsSchema = {
        "Job-Application-v0.2": {
            "name": "Job-Application",
            "version": "0.2",
            "attributes": {
                "first_name": "string",
                "last_name": "string",
                "phone_number": "string",
                "degree": "string",
                "status": "string",
                "ssn": "string"
            },
            "verifiableAttributes": ["degree", "status", "ssn"]
        },
        "Job-Application-v0.3": {
            "name": "Job-Application-2",
            "version": "0.3",
            "attributes": {
                "first_name": "string",
                "last_name": "string",
                "phone_number": "string",
                "degree": "string",
                "status": "string",
                "ssn": "string"
            },
            "verifiableAttributes": ["degree", "status"]
        }
    }

    return agent
コード例 #4
0
ファイル: faber.py プロジェクト: chriswinc/indy-node
def create_faber(name=None, wallet=None, base_dir_path=None,
                 port=5555, client=None):

    if client is None:
        client = create_client(base_dir_path=base_dir_path, client_class=TestClient)

    endpoint_args = {'onlyListener': True}
    if wallet:
        endpoint_args['seed'] = wallet._signerById(wallet.defaultId).seed
    else:
        wallet = Wallet(name)
        wallet.addIdentifier(signer=FABER_SIGNER)
        endpoint_args['seed'] = FABER_SEED

    agent = WalletedAgent(name=name or "Faber College",
                          basedirpath=base_dir_path,
                          client=client,
                          wallet=wallet,
                          port=port,
                          endpointArgs=endpoint_args)

    agent._invites = {
        "b1134a647eb818069c089e7694f63e6d": (1, "Alice"),
        "2a2eb72eca8b404e8d412c5bf79f2640": (2, "Carol"),
        "7513d1397e87cada4214e2a650f603eb": (3, "Frank"),
        "710b78be79f29fc81335abaa4ee1c5e8": (4, "Bob")
    }

    transcript_def = AttribDef('Transcript',
                               [AttribType('student_name', encode=True),
                                AttribType('ssn', encode=True),
                                AttribType('degree', encode=True),
                                AttribType('year', encode=True),
                                AttribType('status', encode=True)])

    agent.add_attribute_definition(transcript_def)

    backend = MockBackendSystem(transcript_def)

    backend.add_record(1,
                       student_name="Alice Garcia",
                       ssn="123-45-6789",
                       degree="Bachelor of Science, Marketing",
                       year="2015",
                       status="graduated")

    backend.add_record(2,
                       student_name="Carol Atkinson",
                       ssn="783-41-2695",
                       degree="Bachelor of Science, Physics",
                       year="2012",
                       status="graduated")

    backend.add_record(3,
                       student_name="Frank Jeffrey",
                       ssn="996-54-1211",
                       degree="Bachelor of Arts, History",
                       year="2013",
                       status="dropped")

    backend.add_record(4,
                       student_name="Bob Richards",
                       ssn="151-44-5876",
                       degree="MBA, Finance",
                       year="2015",
                       status="graduated")

    agent.set_issuer_backend(backend)

    return agent
コード例 #5
0
ファイル: acme.py プロジェクト: chriswinc/indy-node
def create_acme(name=None, wallet=None, base_dir_path=None,
                port=6666, client=None):
    if client is None:
        client = create_client(base_dir_path=base_dir_path, client_class=TestClient)

    endpoint_args = {'onlyListener': True}
    if wallet:
        endpoint_args['seed'] = wallet._signerById(wallet.defaultId).seed
    else:
        wallet = Wallet(name)
        wallet.addIdentifier(signer=ACME_SIGNER)
        endpoint_args['seed'] = ACME_SEED

    agent = AcmeAgent(name=name or "Acme Corp",
                      basedirpath=base_dir_path,
                      client=client,
                      wallet=wallet,
                      port=port,
                      endpointArgs=endpoint_args)

    # maps request nonces to internal ids
    agent._invites = {
        "57fbf9dc8c8e6acde33de98c6d747b28c": (1, "Alice"),
        "3a2eb72eca8b404e8d412c5bf79f2640": (2, "Carol"),
        "8513d1397e87cada4214e2a650f603eb": (3, "Frank"),
        "810b78be79f29fc81335abaa4ee1c5e8": (4, "Bob")
    }

    job_cert_def = AttribDef('Job-Certificate',
                             [AttribType('first_name', encode=True),
                              AttribType('last_name', encode=True),
                              AttribType('employee_status', encode=True),
                              AttribType('experience', encode=True),
                              AttribType('salary_bracket', encode=True)])

    job_appl_def = AttribDef('Job-Application',
                             [AttribType('first_name', encode=True),
                              AttribType('last_name', encode=True),
                              AttribType('phone_number', encode=True),
                              AttribType('degree', encode=True),
                              AttribType('status', encode=True),
                              AttribType('ssn', encode=True)])

    agent.add_attribute_definition(job_cert_def)
    agent.add_attribute_definition(job_appl_def)

    backend = MockBackendSystem(job_cert_def)
    backend.add_record(1,
                       first_name="Alice",
                       last_name="Garcia",
                       employee_status="Permanent",
                       experience="3 years",
                       salary_bracket="between $50,000 to $100,000")

    backend.add_record(2,
                       first_name="Carol",
                       last_name="Atkinson",
                       employee_status="Permanent",
                       experience="2 years",
                       salary_bracket="between $60,000 to $90,000")

    backend.add_record(3,
                       first_name="Frank",
                       last_name="Jeffrey",
                       employee_status="Temporary",
                       experience="4 years",
                       salary_bracket="between $40,000 to $80,000")

    backend.add_record(4,
                       first_name="Bob",
                       last_name="Richards",
                       employee_status="On Contract",
                       experience="3 years",
                       salary_bracket="between $50,000 to $70,000")

    agent.set_issuer_backend(backend)

    agent._proofRequestsSchema = {
        "Job-Application-v0.2": {
            "name": "Job-Application",
            "version": "0.2",
            "attributes": {
                "first_name": "string",
                "last_name": "string",
                "phone_number": "string",
                "degree": "string",
                "status": "string",
                "ssn": "string"
            },
            "verifiableAttributes": ["degree", "status", "ssn"]
        },
        "Job-Application-v0.3": {
            "name": "Job-Application-2",
            "version": "0.3",
            "attributes": {
                "first_name": "string",
                "last_name": "string",
                "phone_number": "string",
                "degree": "string",
                "status": "string",
                "ssn": "string"
            },
            "verifiableAttributes": ["degree", "status"]
        }
    }

    return agent