def sign(self, signer: str, secret: bytes): """Sign this response message.""" self['connection~sig'] = crypto.sign_message_field( self['connection'], signer=signer, secret=secret ) del self['connection']
async def test_connection_started_by_suite(config, temporary_channel): """ Test a connection as started by the suite. """ with temporary_channel() as conn: invite_str = build_invite('test-suite-connection-started-by-suite', conn.my_vk_b58, config['endpoint']) print('Encoding invitation:', parse_invite(invite_str)) print("\n\nInvitation encoded as URL: ", invite_str) print("Awaiting request from tested agent...") def condition(msg): print(msg) return msg.type == REQUEST request = await conn.await_message(condition=condition, timeout=30) REQUEST_SCHEMA(request) print("\nReceived request:\n", request.pretty_print()) (_, conn.their_vk_b58, conn.endpoint) = ( request['connection']['DIDDoc']['publicKey'][0]['controller'], request['connection']['DIDDoc']['publicKey'][0]['publicKeyBase58'], request['connection']['DIDDoc']['service'][0]['serviceEndpoint']) conn.their_vk = crypto.b58_to_bytes(conn.their_vk_b58) conn.my_vk, conn.my_sk = crypto.create_keypair() conn.did = crypto.bytes_to_b58(conn.my_vk[:16]) conn.my_vk_b58 = crypto.bytes_to_b58(conn.my_vk) response = build_response(request.id, conn.did, conn.my_vk_b58, config['endpoint']) print("\nSending Response (pre signature packing):\n", response.pretty_print()) response['connection~sig'] = crypto.sign_message_field( response['connection'], signer=conn.my_vk_b58, secret=conn.my_sk) del response['connection'] print("\nSending Response (post signature packing):\n", response.pretty_print()) await conn.send_async(response)
async def request(self, msg, _agent): """ Process a request. """ print(msg.pretty_print()) connection = self.connections[msg.mtc.ad['recip_vk']] connection.state.transition(Events.RECV_REQ) # Old connection keys, need to sign new keys with these conn_vk, conn_sk = connection.my_vk, connection.my_sk # Relationship keys, replacing connection keys my_vk, my_sk = crypto.create_keypair() # Update connection connection.my_vk, connection.my_sk = my_vk, my_sk connection.did = crypto.bytes_to_b58(my_vk[:16]) connection.vk_b58 = crypto.bytes_to_b58(my_vk) connection.their_did = msg['connection']['DIDDoc']['publicKey'][0][ 'controller'] connection.their_vk = crypto.b58_to_bytes( msg['connection']['DIDDoc']['publicKey'][0]['publicKeyBase58']) connection.endpoint = msg['connection']['DIDDoc']['service'][0][ 'serviceEndpoint'] del self.connections[msg.mtc.ad['recip_vk']] self.connections[connection.vk_b58] = connection # Prepare response connection_block = { 'DID': connection.did, 'DIDDoc': { "@context": "https://w3id.org/did/v1", "id": connection.did, "publicKey": [{ "id": connection.did + "#keys-1", "type": "Ed25519VerificationKey2018", "controller": connection.did, "publicKeyBase58": connection.vk_b58 }], "service": [{ "id": connection.did + ";indy", "type": "IndyAgent", "recipientKeys": [connection.vk_b58], "routingKeys": [], "serviceEndpoint": self.endpoint, }], } } connection.state.transition(Events.SEND_RESP) await connection.send_async({ '@type': self.type('response'), '~thread': { 'thid': msg.id, 'sender_order': 0 }, 'connection~sig': crypto.sign_message_field(connection_block, crypto.bytes_to_b58(conn_vk), conn_sk) })