Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow public invites for alice/faber demo #1574

Merged
merged 6 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aries_cloudagent/protocols/out_of_band/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

LOGGER = logging.getLogger(__name__)
REUSE_WEBHOOK_TOPIC = "acapy::webhook::connection_reuse"
REUSE_ACCEPTED_WEBHOOK_TOPIC = "acapy::webhook:connection_reuse_accepted"
REUSE_ACCEPTED_WEBHOOK_TOPIC = "acapy::webhook::connection_reuse_accepted"


class OutOfBandManagerError(BaseError):
Expand Down
56 changes: 47 additions & 9 deletions demo/runners/agent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,23 @@ def connection_ready(self):
return self._connection_ready.done() and self._connection_ready.result()

async def handle_oob_invitation(self, message):
print("handle_oob_invitation()")
pass

async def handle_connection_reuse(self, message):
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
# we are reusing an existing connection, set our status to the existing connection
if not self._connection_ready.done():
self.connection_id = message["connection_id"]
self.log("Connected")
self._connection_ready.set_result(True)

async def handle_connection_reuse_accepted(self, message):
shaangill025 marked this conversation as resolved.
Show resolved Hide resolved
# we are reusing an existing connection, set our status to the existing connection
if not self._connection_ready.done():
self.connection_id = message["connection_id"]
self.log("Connected")
self._connection_ready.set_result(True)

async def handle_connections(self, message):
# a bit of a hack, but for the mediator connection self._connection_ready
# will be None
Expand Down Expand Up @@ -506,6 +521,7 @@ async def generate_invitation(
use_did_exchange: bool,
auto_accept: bool = True,
display_qr: bool = False,
reuse_connections: bool = False,
wait: bool = False,
):
self._connection_ready = asyncio.Future()
Expand All @@ -514,7 +530,11 @@ async def generate_invitation(
log_status(
"#7 Create a connection to alice and print out the invite details"
)
invi_rec = await self.get_invite(use_did_exchange, auto_accept)
invi_rec = await self.get_invite(
use_did_exchange,
auto_accept=auto_accept,
reuse_connections=reuse_connections,
)

if display_qr:
qr = QRCode(border=1)
Expand Down Expand Up @@ -589,6 +609,7 @@ def __init__(
aip: int = 20,
arg_file: str = None,
endorser_role: str = None,
reuse_connections: bool = False,
):
# configuration parameters
self.genesis_txns = genesis_txns
Expand All @@ -603,7 +624,6 @@ def __init__(
self.multitenant = multitenant
self.mediation = mediation
self.use_did_exchange = use_did_exchange
print("Setting use_did_exchange:", self.use_did_exchange)
self.wallet_type = wallet_type
self.public_did = public_did
self.seed = seed
Expand All @@ -616,6 +636,7 @@ def __init__(
self.public_did = True
self.cred_type = CRED_FORMAT_INDY

self.reuse_connections = reuse_connections
self.exchange_tracing = False

# local agent(s)
Expand Down Expand Up @@ -805,13 +826,10 @@ async def receive_credential(
for cred_attr in cred_attrs:
if cred_attr["name"] in wallet_attrs:
if wallet_attrs[cred_attr["name"]] != cred_attr["value"]:
print("Value doesn't match for:", cred_attr["name"])
matched = False
else:
print("Attribute not found for:", cred_attr["name"])
matched = False

print("Matching credential received")
return matched

async def request_proof(self, proof_request):
Expand Down Expand Up @@ -863,12 +881,10 @@ async def verify_proof(self, proof_request):

if self.cred_type == CRED_FORMAT_INDY:
# return verified status
print("Received proof:", self.agent.last_proof_received["verified"])
return self.agent.last_proof_received["verified"]

elif self.cred_type == CRED_FORMAT_JSON_LD:
# return verified status
print("Received proof:", self.agent.last_proof_received["verified"])
return self.agent.last_proof_received["verified"]

else:
Expand Down Expand Up @@ -897,10 +913,18 @@ async def terminate(self):
return terminated

async def generate_invitation(
self, auto_accept: bool = True, display_qr: bool = False, wait: bool = False
self,
auto_accept: bool = True,
display_qr: bool = False,
reuse_connections: bool = False,
wait: bool = False,
):
return await self.agent.generate_invitation(
self.use_did_exchange, auto_accept, display_qr, wait
self.use_did_exchange,
auto_accept=auto_accept,
display_qr=display_qr,
reuse_connections=reuse_connections,
wait=wait,
)

async def input_invitation(self, invite_details: dict, wait: bool = False):
Expand Down Expand Up @@ -1087,6 +1111,15 @@ def arg_parser(ident: str = None, port: int = 8020):
"directly."
),
)
if (not ident) or (ident != "alice"):
parser.add_argument(
"--reuse-connections",
action="store_true",
help=(
"Reuse connections by using Faber public key in the invite. "
"Only applicable for AIP 2.0 (OOB) connections."
),
)
parser.add_argument(
"--arg-file",
type=str,
Expand Down Expand Up @@ -1169,6 +1202,10 @@ async def create_agent_with_args(args, ident: str = None):
f"Initializing demo agent {agent_ident} with AIP {aip} and credential type {cred_type}"
)

reuse_connections = "reuse_connections" in args and args.reuse_connections
if reuse_connections and aip != 20:
raise Exception("Can only specify `--reuse-connections` with AIP 2.0")

agent = AgentContainer(
genesis_txns=genesis,
genesis_txn_list=multi_ledger_config_path,
Expand All @@ -1188,6 +1225,7 @@ async def create_agent_with_args(args, ident: str = None):
arg_file=arg_file,
aip=aip,
endorser_role=args.endorser_role,
reuse_connections=reuse_connections,
)

return agent
Expand Down
10 changes: 8 additions & 2 deletions demo/runners/faber.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ async def main(args):
raise Exception("Invalid credential type:" + faber_agent.cred_type)

# generate an invitation for Alice
await faber_agent.generate_invitation(display_qr=True, wait=True)
await faber_agent.generate_invitation(
display_qr=True, reuse_connections=faber_agent.reuse_connections, wait=True
)

exchange_tracing = False
options = (
Expand Down Expand Up @@ -683,7 +685,11 @@ async def main(args):
"Creating a new invitation, please receive "
"and accept this invitation using Alice agent"
)
await faber_agent.generate_invitation(display_qr=True, wait=True)
await faber_agent.generate_invitation(
display_qr=True,
reuse_connections=faber_agent.reuse_connections,
wait=True,
)

elif option == "5" and faber_agent.revocation:
rev_reg_id = (await prompt("Enter revocation registry ID: ")).strip()
Expand Down
28 changes: 23 additions & 5 deletions demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ def get_agent_args(self):
("--wallet-key", self.wallet_key),
"--preserve-exchange-records",
"--auto-provision",
"--public-invites",
]
if self.aip == 20:
result.append("--emit-new-didcomm-prefix")
Expand Down Expand Up @@ -1144,21 +1145,36 @@ def _postgres_tables(self):
def reset_postgres_stats(self):
self.wallet_stats.clear()

async def get_invite(self, use_did_exchange: bool, auto_accept: bool = True):
async def get_invite(
self,
use_did_exchange: bool,
auto_accept: bool = True,
reuse_connections: bool = False,
):
self.connection_id = None
if use_did_exchange:
# TODO can mediation be used with DID exchange connections?
invi_params = {
"auto_accept": json.dumps(auto_accept),
}
payload = {
"handshake_protocols": ["rfc23"],
"use_public_did": reuse_connections,
}
invi_rec = await self.admin_POST(
"/out-of-band/create-invitation",
{"handshake_protocols": ["rfc23"]},
params={"auto_accept": json.dumps(auto_accept)},
payload,
params=invi_params,
)
else:
if self.mediation:
invi_params = {
"auto_accept": json.dumps(auto_accept),
}
invi_rec = await self.admin_POST(
"/connections/create-invitation",
{"mediation_id": self.mediator_request_id},
params={"auto_accept": json.dumps(auto_accept)},
params=invi_params,
)
else:
invi_rec = await self.admin_POST("/connections/create-invitation")
Expand All @@ -1169,8 +1185,10 @@ async def receive_invite(self, invite, auto_accept: bool = True):
if self.endorser_role and self.endorser_role == "author":
params = {"alias": "endorser"}
else:
params = None
params = {}
if "/out-of-band/" in invite.get("@type", ""):
# always reuse connections if possible
params["use_existing_connection"] = "true"
connection = await self.admin_POST(
"/out-of-band/receive-invitation",
invite,
Expand Down