-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtest_demo_advanced_params.py
68 lines (63 loc) · 2 KB
/
test_demo_advanced_params.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pytest as pytest
from didcomm import (
AnonCryptAlg,
Message,
PackEncryptedConfig,
PackEncryptedParameters,
pack_encrypted,
unpack_forward,
unpack,
UnpackConfig,
)
from tests.test_vectors.common import ALICE_DID, BOB_DID
@pytest.mark.asyncio
async def test_demo_advanced_parameters(
resolvers_config_alice, resolvers_config_bob, resolvers_config_mediator1
):
# ALICE
pack_config = PackEncryptedConfig(
protect_sender_id=True,
forward=True,
enc_alg_anon=AnonCryptAlg.A256GCM_ECDH_ES_A256KW,
)
# TODO replace hard-coded values
pack_parameters = PackEncryptedParameters(
forward_headers={"expires_time": 99999},
forward_service_id="did:example:123456789abcdefghi#didcomm-1",
)
message = Message(
body={"aaa": 1, "bbb": 2},
id="1234567890",
type="my-protocol/1.0",
frm=ALICE_DID,
to=[BOB_DID],
created_time=1516269022,
expires_time=1516385931,
)
pack_result = await pack_encrypted(
resolvers_config=resolvers_config_alice,
message=message,
frm="did:example:alice#key-p256-1",
sign_frm="did:example:alice#key-2",
to="did:example:bob#key-p256-1",
pack_config=pack_config,
pack_params=pack_parameters,
)
packed_msg = pack_result.packed_msg
print(f"Sending {packed_msg} to {pack_result.service_metadata.service_endpoint}")
# BOB MEDIATOR
forward_bob = await unpack_forward(resolvers_config_mediator1, packed_msg, True)
packed_msg = forward_bob.forwarded_msg
print(f"Sending {packed_msg} to Bob")
# BOB
unpack_config = UnpackConfig(
expect_decrypt_by_all_keys=False, unwrap_re_wrapping_forward=False
)
unpack_result = await unpack(
resolvers_config=resolvers_config_bob,
packed_msg=packed_msg,
unpack_config=unpack_config,
)
print(
f"Got ${unpack_result.message} message signed as ${unpack_result.metadata.signed_message}"
)