Beispiel #1
0
async def test_primary_proof_from_to_dict():
    n = cmod.integer(12345)

    eqProof = PrimaryEqualProof(e=cmod.integer(1),
                                v=cmod.integer(11),
                                m={'name': cmod.integer(12)},
                                m1=cmod.integer(12),
                                m2=cmod.integer(32),
                                Aprime=cmod.integer(32) % n,
                                revealedAttrs={'name': cmod.integer(35)})

    predicate = PredicateGE(attrName='age', value=18)
    geProof = PrimaryPredicateGEProof(alpha=cmod.integer(1),
                                      mj=cmod.integer(12),
                                      r={'1': cmod.integer(13)},
                                      u={'1': cmod.integer(42)},
                                      T={'1': cmod.integer(21) % n},
                                      predicate=predicate)
    primaryProof = PrimaryProof(eqProof=eqProof, geProofs=[geProof])

    proof_serialized = {
        'eq_proof': {
            'a_prime': '32',
            'e': '1',
            'm': {
                'name': '12'
            },
            'm1': '12',
            'm2': '32',
            'v': '11',
            'revealed_attrs': {
                'name': '35'
            }
        },
        'ge_proofs': [{
            'alpha': '1',
            'mj': '12',
            't': {
                '1': '21'
            },
            'r': {
                '1': '13'
            },
            'u': {
                '1': '42'
            },
            'predicate': {
                'p_type': 'GE',
                'attr_name': 'age',
                'value': 18,
                'schema_seq_no': None,
                'issuer_did': None
            }
        }]
    }

    assert primaryProof.to_str_dict() == proof_serialized
    assert primaryProof == PrimaryProof.from_str_dict(proof_serialized, n)
    assert primaryProof == PrimaryProof.from_str_dict(
        primaryProof.to_str_dict(), n)
Beispiel #2
0
async def test_ge_proof_from_to_dict():
    n = cmod.integer(12345)

    predicate = PredicateGE(attrName='age', value=18)
    geProof = PrimaryPredicateGEProof(alpha=cmod.integer(1), mj=cmod.integer(12), r={'1': cmod.integer(13)},
                                      u={'1': cmod.integer(42)}, T={'1': cmod.integer(21) % n}, predicate=predicate)

    proof_serialized = {
        'alpha': '1',
        'mj': '12',
        't': {'1': '21'},
        'r': {'1': '13'},
        'u': {'1': '42'},
        'predicate': {
            'p_type': 'GE',
            'attr_name': 'age',
            'value': 18,
            'schema_seq_no': None,
            'issuer_did': None
        }
    }

    assert geProof.to_str_dict() == proof_serialized
    assert geProof == PrimaryPredicateGEProof.from_str_dict(
        proof_serialized, n)
    assert geProof == PrimaryPredicateGEProof.from_str_dict(
        geProof.to_str_dict(), n)
    async def _finalizeGeProof(self, schemaId, cH,
                               initProof: PrimaryPrecicateGEInitProof,
                               eqProof: PrimaryEqualProof) \
            -> PrimaryPredicateGEProof:
        u = {}
        r = {}
        urproduct = 0
        for i in range(0, ITERATIONS):
            u[str(i)] = initProof.uTilde[str(i)] + cH * initProof.u[str(i)]
            r[str(i)] = initProof.rTilde[str(i)] + cH * initProof.r[str(i)]
            urproduct += initProof.u[str(i)] * initProof.r[str(i)]
            r[DELTA] = initProof.rTilde[DELTA] + cH * initProof.r[DELTA]

        alpha = initProof.alphaTilde + cH * (initProof.r[DELTA] - urproduct)

        k = initProof.predicate.attrName
        return PrimaryPredicateGEProof(u, r, alpha, eqProof.m[str(k)],
                                       initProof.T, initProof.predicate)