Skip to content

Commit

Permalink
updated create proof according to new claim structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Artemkaaas committed Jun 20, 2017
1 parent 4093245 commit 98c65c6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 32 deletions.
4 changes: 2 additions & 2 deletions anoncreds/protocol/primary/primary_claim_issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ async def issuePrimaryClaim(self, schemaId: ID, attributes: Attribs,
A = await self._sign(schemaId, encodedAttrs, vprimeprime, u, e)

m2 = await self._wallet.getContextAttr(schemaId)
attrs = attributes._vals
attrs = dict()

for key in attributes.keys():
attrs[key] = (str(attrs[key]), str(encodedAttrs[key]))
attrs[key] = (str(attributes._vals[key]), str(encodedAttrs[key]))

return (PrimaryClaim(m2, A, e, vprimeprime), attrs)

Expand Down
24 changes: 14 additions & 10 deletions anoncreds/protocol/primary/primary_proof_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence
from typing import Sequence, Dict

from anoncreds.protocol.globals import LARGE_VPRIME, LARGE_MVECT, LARGE_E_START, \
LARGE_ETILDE, \
Expand Down Expand Up @@ -43,16 +43,16 @@ def __init__(self, wallet: ProverWallet):
async def initProof(self, schemaKey, c1: PrimaryClaim,
revealedAttrs: Sequence[str],
predicates: Sequence[Predicate],
m1Tilde, m2Tilde) -> PrimaryInitProof:
m1Tilde, m2Tilde, attrs: Dict[str, Sequence[str]]) -> PrimaryInitProof:
if not c1:
return None

eqProof = await self._initEqProof(schemaKey, c1, revealedAttrs,
m1Tilde, m2Tilde)
m1Tilde, m2Tilde, attrs)
geProofs = []
for predicate in predicates:
geProof = await self._initGeProof(schemaKey, eqProof, c1,
predicate)
predicate, attrs)
geProofs.append(geProof)
return PrimaryInitProof(eqProof, geProofs)

Expand All @@ -72,11 +72,11 @@ async def finalizeProof(self, schemaKey, cH,
return PrimaryProof(eqProof, geProofs)

async def _initEqProof(self, schemaKey, c1: PrimaryClaim,
revealedAttrs: Sequence[str], m1Tilde, m2Tilde) \
revealedAttrs: Sequence[str], m1Tilde, m2Tilde, attrs: Dict[str, Sequence[str]]) \
-> PrimaryEqualInitProof:
m2Tilde = m2Tilde if m2Tilde else cmod.integer(
cmod.randomBits(LARGE_MVECT))
unrevealedAttrs = getUnrevealedAttrs(c1.encodedAttrs, revealedAttrs)
unrevealedAttrs = getUnrevealedAttrs(attrs, revealedAttrs)
mtilde = self._getMTilde(unrevealedAttrs)

Ra = cmod.integer(cmod.randomBits(LARGE_VPRIME))
Expand All @@ -92,7 +92,7 @@ async def _initEqProof(self, schemaKey, c1: PrimaryClaim,

Rur = 1 % pk.N
for k, value in unrevealedAttrs.items():
if k in c1.encodedAttrs:
if k in attrs:
Rur = Rur * (pk.R[k] ** mtilde[k])
Rur *= pk.Rms ** m1Tilde
Rur *= pk.Rctxt ** m2Tilde
Expand All @@ -106,12 +106,12 @@ async def _initEqProof(self, schemaKey, c1: PrimaryClaim,
unrevealedAttrs.keys(), revealedAttrs)

async def _initGeProof(self, schemaKey, eqProof: PrimaryEqualInitProof,
c1: PrimaryClaim, predicate: Predicate) \
c1: PrimaryClaim, predicate: Predicate, attrs: Dict[str, Sequence[str]]) \
-> PrimaryPrecicateGEInitProof:
# gen U for Delta
pk = await self._wallet.getPublicKey(ID(schemaKey))
k, value = predicate.attrName, predicate.value
delta = c1.encodedAttrs[k] - value
delta = int(attrs[k][1]) - value
if delta < 0:
raise ValueError("Predicate is not satisfied")

Expand Down Expand Up @@ -148,9 +148,13 @@ async def _finalizeEqProof(self, schemaKey, cH,
v = initProof.vTilde + (cH * initProof.vPrime)

m = {}

schema = await self._wallet.getSchema(ID(schemaKey))
attrs = await self._wallet.getClaim(ID(schemaKey=schemaKey, schemaId=schema.seqId))

for k in initProof.unrevealedAttrs:
m[str(k)] = initProof.mTilde[str(k)] + (
cH * initProof.c1.encodedAttrs[str(k)])
cH * int(attrs[str(k)][1]))
ms = await self._wallet.getMasterSecret(ID(schemaKey))
m1 = initProof.m1Tilde + (cH * ms)
m2 = initProof.m2Tilde + (cH * initProof.c1.m2)
Expand Down
14 changes: 10 additions & 4 deletions anoncreds/protocol/prover.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,18 @@ async def _findClaims(self, proofInput: ProofInput) -> (
revealedAttrsForClaim = []
predicatesForClaim = []

schema = await self.wallet.getSchema(ID(schemaKey))
attrs = await self.wallet.getClaim(ID(schemaKey=schemaKey, schemaId=schema.seqId))

for revealedAttr in revealedAttrs:
if revealedAttr in claim.primaryClaim.encodedAttrs:
if revealedAttr in attrs:
revealedAttrsForClaim.append(revealedAttr)
foundRevealedAttrs.add(revealedAttr)
revealedAttrsWithValues[revealedAttr] = \
claim.primaryClaim.attrs[revealedAttr]
attrs[revealedAttr][0]

for predicate in predicates:
if predicate.attrName in claim.primaryClaim.encodedAttrs:
if predicate.attrName in attrs:
predicatesForClaim.append(predicate)
foundPredicates.add(predicate)

Expand Down Expand Up @@ -207,6 +210,9 @@ async def _prepareProof(self, claims: Dict[SchemaKey, ProofClaims],
for schemaKey, val in claims.items():
c1, c2, revealedAttrs, predicates = val.claims.primaryClaim, val.claims.nonRevocClaim, val.revealedAttrs, val.predicates

schema = await self.wallet.getSchema(ID(schemaKey))
attrs = await self.wallet.getClaim(ID(schemaKey=schemaKey, schemaId=schema.seqId))

nonRevocInitProof = None
if c2:
nonRevocInitProof = await self._nonRevocProofBuilder.initProof(
Expand All @@ -220,7 +226,7 @@ async def _prepareProof(self, claims: Dict[SchemaKey, ProofClaims],
nonRevocInitProof.TauListParams.m2)) if nonRevocInitProof else None
primaryInitProof = await self._primaryProofBuilder.initProof(
schemaKey, c1, revealedAttrs, predicates,
m1Tilde, m2Tilde)
m1Tilde, m2Tilde, attrs)
CList += primaryInitProof.asCList()
TauList += primaryInitProof.asTauList()

Expand Down
4 changes: 2 additions & 2 deletions anoncreds/protocol/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def splitRevealedAttrs(encodedAttrs, revealedAttrs):

for k, value in encodedAttrs.items():
if k in revealedAttrs:
Ar[k] = value
Ar[k] = int(value[1])
else:
Aur[k] = value
Aur[k] = int(value[1])
return Ar, Aur


Expand Down
3 changes: 3 additions & 0 deletions anoncreds/protocol/wallet/prover_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ async def submitContextAttr(self, schemaId: ID, m2):
async def getMasterSecret(self, schemaId: ID):
return await self._getValueForId(self._m1s, schemaId)

async def getClaim(self, schemaId: ID):
return await self._getValueForId(self._claims, schemaId)

async def getClaims(self, schemaId: ID) -> Claims:
c1 = await self._getValueForId(self._c1s, schemaId)
c2 = None if not self._c2s else await self._getValueForId(self._c2s,
Expand Down
28 changes: 14 additions & 14 deletions anoncreds/test/test_anoncred_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ async def testSingleIssuerSingleProver(primes1):
proofInput = ProofInput(
['name'],
[PredicateGE('age', 18)])
#
# verifier = Verifier(WalletInMemory('verifier1', publicRepo))
# nonce = verifier.generateNonce()
# proof, revealedAttrs = await prover.presentProof(proofInput, nonce)
# assert revealedAttrs['name'] == 'Alex'
# assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)

verifier = Verifier(WalletInMemory('verifier1', publicRepo))
nonce = verifier.generateNonce()
proof, revealedAttrs = await prover.presentProof(proofInput, nonce)
assert revealedAttrs['name'] == 'Alex'
assert await verifier.verify(proofInput, proof, revealedAttrs, nonce)


@pytest.mark.skipif('sys.platform == "win32"', reason='SOV-86')
Expand Down Expand Up @@ -90,10 +90,10 @@ async def testMultiplIssuersSingleProver(primes1, primes2):
prover = Prover(ProverWalletInMemory(userId, publicRepo))
claimsReq1 = await prover.createClaimRequest(schemaId1)
claimsReq2 = await prover.createClaimRequest(schemaId2)
claims1 = await issuer1.issueClaim(schemaId1, claimsReq1)
claims2 = await issuer2.issueClaim(schemaId2, claimsReq2)
await prover.processClaim(schemaId1, claims1)
await prover.processClaim(schemaId2, claims2)
(signature1, claims1) = await issuer1.issueClaim(schemaId1, claimsReq1)
(signature2, claims2) = await issuer2.issueClaim(schemaId2, claimsReq2)
await prover.processClaim(schemaId1, claims1, signature1)
await prover.processClaim(schemaId2, claims2, signature2)

# 6. proof Claims
proofInput = ProofInput(['name', 'status'],
Expand Down Expand Up @@ -141,8 +141,8 @@ async def testSingleIssuerMultipleCredDefsSingleProver(primes1, primes2):
# 5. request Claims
prover = Prover(ProverWalletInMemory(userId, publicRepo))
claimsReqs = await prover.createClaimRequests([schemaId1, schemaId2])
claims = await issuer.issueClaims(claimsReqs)
await prover.processClaims(claims)
(signature, claims) = await issuer.issueClaims(claimsReqs)
await prover.processClaims(claims, signature)

# 6. proof Claims
proofInput = ProofInput(
Expand Down Expand Up @@ -182,8 +182,8 @@ async def testSingleIssuerSingleProverPrimaryOnly(primes1):
# 5. request Claims
prover = Prover(ProverWalletInMemory(userId, publicRepo))
claimsReq = await prover.createClaimRequest(schemaId, None, False)
claims = await issuer.issueClaim(schemaId, claimsReq)
await prover.processClaim(schemaId, claims)
(signature, claims) = await issuer.issueClaim(schemaId, claimsReq)
await prover.processClaim(schemaId, claims, signature)

# 6. proof Claims
proofInput = ProofInput(
Expand Down

0 comments on commit 98c65c6

Please sign in to comment.