コード例 #1
0
ファイル: test_types.py プロジェクト: aigoncharov/anoncreds
async def test_equal_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)})

    proof_serialized = {
        'a_prime': '32',
        'e': '1',
        'm': {
            'name': '12'
        },
        'm1': '12',
        'm2': '32',
        'v': '11',
        'revealed_attrs': {
            'name': '35'
        }
    }

    assert eqProof.to_str_dict() == proof_serialized
    assert eqProof == PrimaryEqualProof.from_str_dict(proof_serialized, n)
    assert eqProof == PrimaryEqualProof.from_str_dict(eqProof.to_str_dict(), n)
コード例 #2
0
ファイル: test_types.py プロジェクト: aigoncharov/anoncreds
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)
コード例 #3
0
    async def _finalizeEqProof(
            self, schemaKey, cH,
            initProof: PrimaryEqualInitProof) -> PrimaryEqualProof:
        e = initProof.eTilde + (cH * initProof.ePrime)
        v = initProof.vTilde + (cH * initProof.vPrime)

        m = {}
        for k in initProof.unrevealedAttrs:
            m[str(k)] = initProof.mTilde[str(k)] + (
                cH * initProof.c1.encodedAttrs[str(k)])
        ms = await self._wallet.getMasterSecret(ID(schemaKey))
        m1 = initProof.m1Tilde + (cH * ms)
        m2 = initProof.m2Tilde + (cH * initProof.c1.m2)

        return PrimaryEqualProof(e, v, m, m1, m2, initProof.Aprime,
                                 initProof.revealedAttrs)