2020-02-18 04:12:19 +00:00
|
|
|
''' format Create activities and sign them '''
|
|
|
|
from base64 import b64encode
|
|
|
|
from Crypto.PublicKey import RSA
|
|
|
|
from Crypto.Signature import pkcs1_15
|
|
|
|
from Crypto.Hash import SHA256
|
|
|
|
|
|
|
|
def get_create(user, status_json):
|
|
|
|
''' create activitypub json for a Create activity '''
|
|
|
|
signer = pkcs1_15.new(RSA.import_key(user.private_key))
|
|
|
|
content = status_json['content']
|
|
|
|
signed_message = signer.sign(SHA256.new(content.encode('utf8')))
|
|
|
|
return {
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
|
|
|
|
'id': '%s/activity' % status_json['id'],
|
|
|
|
'type': 'Create',
|
2020-05-13 01:56:28 +00:00
|
|
|
'actor': user.remote_id,
|
2020-02-18 04:12:19 +00:00
|
|
|
'published': status_json['published'],
|
|
|
|
|
2020-05-13 01:56:28 +00:00
|
|
|
'to': ['%s/followers' % user.remote_id],
|
2020-02-18 04:12:19 +00:00
|
|
|
'cc': ['https://www.w3.org/ns/activitystreams#Public'],
|
|
|
|
|
|
|
|
'object': status_json,
|
|
|
|
'signature': {
|
|
|
|
'type': 'RsaSignature2017',
|
2020-05-13 01:56:28 +00:00
|
|
|
'creator': '%s#main-key' % user.remote_id,
|
2020-02-18 04:12:19 +00:00
|
|
|
'created': status_json['published'],
|
|
|
|
'signatureValue': b64encode(signed_message).decode('utf8'),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-03-29 02:12:17 +00:00
|
|
|
def get_update(user, activity_json):
|
|
|
|
''' a user profile or book or whatever got updated '''
|
|
|
|
# TODO: should this have a signature??
|
|
|
|
return {
|
|
|
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
|
|
'id': 'https://friend.camp/users/tripofmice#updates/1585446332',
|
|
|
|
'type': 'Update',
|
2020-05-13 01:56:28 +00:00
|
|
|
'actor': user.remote_id,
|
2020-03-29 02:12:17 +00:00
|
|
|
'to': [
|
|
|
|
'https://www.w3.org/ns/activitystreams#Public'
|
|
|
|
],
|
2020-02-18 04:12:19 +00:00
|
|
|
|
2020-03-29 02:12:17 +00:00
|
|
|
'object': activity_json,
|
|
|
|
}
|