Skip to content

Commit

Permalink
Merge pull request #431 from nrempel/fix-nonce
Browse files Browse the repository at this point in the history
Use recommend indy generate_nonce
  • Loading branch information
swcurran authored Mar 23, 2020
2 parents d78dd56 + 5352528 commit c48dd5d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
8 changes: 8 additions & 0 deletions aries_cloudagent/indy/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""Libindy utility functions."""

from indy.anoncreds import generate_nonce


async def generate_pr_nonce():
"""Generate a nonce for a proof request."""
return await generate_nonce()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


from enum import Enum
from uuid import uuid4
from time import time
from typing import Mapping, Sequence

Expand All @@ -14,6 +13,7 @@
from ......messaging.valid import INDY_CRED_DEF_ID, INDY_PREDICATE
from ......revocation.models.indy import NonRevocationInterval
from ......wallet.util import b64_to_str
from ......indy.util import generate_pr_nonce


from ...message_types import PRESENTATION_PREVIEW
Expand Down Expand Up @@ -321,7 +321,7 @@ def non_revoc(cred_def_id: str) -> NonRevocationInterval:
proof_req = {
"name": name or "proof-request",
"version": version or "1.0",
"nonce": nonce or str(uuid4().int),
"nonce": nonce or await generate_pr_nonce(),
"requested_attributes": {},
"requested_predicates": {},
}
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/protocols/present_proof/v1_0/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Admin routes for presentations."""

import json
from uuid import uuid4

from aiohttp import web
from aiohttp_apispec import docs, request_schema, response_schema
Expand All @@ -20,6 +19,7 @@
UUIDFour,
)
from ....storage.error import StorageNotFoundError
from ....indy.util import generate_pr_nonce

from .manager import PresentationManager
from .messages.inner.presentation_preview import (
Expand Down Expand Up @@ -457,7 +457,7 @@ async def presentation_exchange_create_request(request: web.BaseRequest):
comment = body.get("comment")
indy_proof_request = body.get("proof_request")
if not indy_proof_request.get("nonce"):
indy_proof_request["nonce"] = str(uuid4().int)
indy_proof_request["nonce"] = await generate_pr_nonce()

presentation_request_message = PresentationRequest(
comment=comment,
Expand Down Expand Up @@ -518,7 +518,7 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest):
comment = body.get("comment")
indy_proof_request = body.get("proof_request")
if not indy_proof_request.get("nonce"):
indy_proof_request["nonce"] = str(uuid4().int)
indy_proof_request["nonce"] = await generate_pr_nonce()

presentation_request_message = PresentationRequest(
comment=comment,
Expand Down
3 changes: 2 additions & 1 deletion aries_cloudagent/protocols/presentations/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ...holder.base import BaseHolder
from ...ledger.base import BaseLedger
from ...verifier.base import BaseVerifier
from ...indy.util import generate_pr_nonce

from .models.presentation_exchange import PresentationExchange
from .messages.presentation_request import PresentationRequest
Expand Down Expand Up @@ -56,7 +57,7 @@ async def create_request(
presentation_request = {
"name": name,
"version": version,
"nonce": str(uuid4().int),
"nonce": await generate_pr_nonce(),
"requested_attributes": {},
"requested_predicates": {},
}
Expand Down
3 changes: 0 additions & 3 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import sys
import time

from uuid import uuid4

from aiohttp import ClientError

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # noqa
Expand Down Expand Up @@ -292,7 +290,6 @@ async def main(
indy_proof_request = {
"name": "Proof of Education",
"version": "1.0",
"nonce": str(uuid4().int),
"requested_attributes": {
f"0_{req_attr['name']}_uuid": req_attr for req_attr in req_attrs
},
Expand Down

0 comments on commit c48dd5d

Please sign in to comment.