Exemplo n.º 1
0
    async def invitation(self, msg, _agent):
        """ Process an invitation. """
        print(msg.pretty_print())
        their_conn_key = msg['recipientKeys'][0]
        my_vk, my_sk = crypto.create_keypair()
        new_connection = StaticConnection(my_vk,
                                          my_sk,
                                          msg['recipientKeys'][0],
                                          msg['serviceEndpoint'],
                                          dispatcher=self.dispatcher)
        new_connection.did = crypto.bytes_to_b58(my_vk[:16])
        new_connection.vk_b58 = crypto.bytes_to_b58(my_vk)
        new_connection.state = ConnectionState()
        new_connection.state.role = Roles.INVITEE
        new_connection.state.transition(Events.RECV_INVITE)

        self.connections[their_conn_key] = new_connection
        await new_connection.send_async({
            '@type': self.type('request'),
            'label': 'apts-demo-agent-as-invitee',
            'connection': {
                'DID': new_connection.did,
                'DIDDoc': {
                    "@context":
                    "https://w3id.org/did/v1",
                    "id":
                    new_connection.did,
                    "publicKey": [{
                        "id": new_connection.did + "#keys-1",
                        "type": "Ed25519VerificationKey2018",
                        "controller": new_connection.did,
                        "publicKeyBase58": new_connection.vk_b58
                    }],
                    "service": [{
                        "id": new_connection.did + ";indy",
                        "type": "IndyAgent",
                        "recipientKeys": [new_connection.vk_b58],
                        "routingKeys": [],
                        "serviceEndpoint": self.endpoint,
                    }],
                }
            }
        })

        new_connection.state.transition(Events.SEND_REQ)
Exemplo n.º 2
0
 def create_invitation(self):
     """ Create and return an invite. """
     conn_vk, conn_sk = crypto.create_keypair()
     connection = StaticConnection(conn_vk,
                                   conn_sk,
                                   b'',
                                   '',
                                   dispatcher=self.dispatcher)
     conn_vk_b58 = crypto.bytes_to_b58(conn_vk)
     self.connections[conn_vk_b58] = connection
     connection.state = ConnectionState()
     connection.state.role = Roles.INVITER
     connection.state.transition(Events.SEND_INVITE)
     invitation = Message({
         '@type': self.type('invitation'),
         'label': 'static-iiw',
         'recipientKeys': [conn_vk_b58],
         'serviceEndpoint': self.endpoint,
         'routingKeys': []
     })
     invitation_url = '{}?c_i={}'.format(
         self.endpoint,
         crypto.bytes_to_b64(invitation.serialize().encode()))
     return connection, invitation_url