def to_create_activity(self, user, **kwargs): """returns the object wrapped in a Create activity""" activity_object = self.to_activity_dataclass(**kwargs) signature = None create_id = self.remote_id + "/activity" if hasattr(activity_object, "content") and activity_object.content: signer = pkcs1_15.new(RSA.import_key(user.key_pair.private_key)) content = activity_object.content signed_message = signer.sign(SHA256.new(content.encode("utf8"))) signature = activitypub.Signature( creator="%s#main-key" % user.remote_id, created=activity_object.published, signatureValue=b64encode(signed_message).decode("utf8"), ) return activitypub.Create( id=create_id, actor=user.remote_id, to=activity_object.to, cc=activity_object.cc, object=activity_object, signature=signature, ).serialize()
def to_create_activity(self, user): ''' returns the object wrapped in a Create activity ''' activity_object = self.to_activity() signer = pkcs1_15.new(RSA.import_key(user.key_pair.private_key)) content = activity_object['content'] signed_message = signer.sign(SHA256.new(content.encode('utf8'))) create_id = self.remote_id + '/activity' signature = activitypub.Signature( creator='%s#main-key' % user.remote_id, created=activity_object['published'], signatureValue=b64encode(signed_message).decode('utf8') ) return activitypub.Create( id=create_id, actor=user.remote_id, to=activity_object['to'], cc=activity_object['cc'], object=activity_object, signature=signature, ).serialize()
def to_create_activity(self, user, pure=False): ''' returns the object wrapped in a Create activity ''' activity_object = self.to_activity(pure=pure) signer = pkcs1_15.new(RSA.import_key(user.private_key)) content = activity_object['content'] signed_message = signer.sign(SHA256.new(content.encode('utf8'))) create_id = self.remote_id + '/activity' signature = activitypub.Signature( creator='%s#main-key' % user.remote_id, created=activity_object['published'], signatureValue=b64encode(signed_message).decode('utf8') ) return activitypub.Create( id=create_id, actor=user.remote_id, to=['%s/followers' % user.remote_id], cc=['https://www.w3.org/ns/activitystreams#Public'], object=activity_object, signature=signature, ).serialize()