Skip to content

Commit

Permalink
actor types
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Sep 12, 2023
1 parent 5bd1df7 commit d8bf672
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
AllCops:
NewCops: enable

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Expand All @@ -9,9 +12,6 @@ Style/StringLiteralsInInterpolation:
Layout/LineLength:
Max: 190

Metrics/BlockLength:
Max: 60

Metrics/ParameterLists:
Max: 8

Expand Down
22 changes: 21 additions & 1 deletion lib/activitypub/actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module ActivityPub
class Actor
attr_accessor :id, :type, :name, :preferred_username, :inbox, :outbox, :followers, :following

def initialize(id:, type: "Person", name:, preferred_username:, inbox:, outbox:, followers: nil, following: nil)
def initialize(id:, name:, preferred_username:, inbox:, outbox:, type: "Person", followers: nil, following: nil)
@id = id
@type = type
@name = name
Expand Down Expand Up @@ -58,5 +58,25 @@ def self.from_h(hash)
following: hash["following"]
)
end

class Person < Actor
# Attributes and methods specific to a Person actor type.
end

class Service < Actor
# Attributes and methods specific to a Service actor type.
end

class Group < Actor
# Attributes and methods specific to a Group actor type.
end

class Organization < Actor
# Attributes and methods specific to an Organization actor type.
end

class Application < Actor
# Attributes and methods specific to an Application actor type.
end
end
end
4 changes: 1 addition & 3 deletions lib/activitypub/outbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ def send_activity(target_inbox_url, activity_data)
signature = ActivityPub::Signature.sign(activity_data, private_key)

# Send the signed activity to the target actor's inbox
response = post_activity(target_inbox_url, activity_data, signature)
post_activity(target_inbox_url, activity_data, signature)

# Save the activity in the outbox (not implemented here for simplicity, but would be in a real-world scenario)
# save_activity(activity_data)

response
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/activitypub/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def self.generate_keypair
# Signs data with the given private key
def self.sign(data, private_key_pem)
private_key = OpenSSL::PKey::RSA.new(private_key_pem)
signature = private_key.sign(OpenSSL::Digest::SHA256.new, data)
signature = private_key.sign(OpenSSL::Digest.new("SHA256"), data)
Base64.encode64(signature).gsub("\n", "")
end

# Verifies the signature with the provided public key
def self.verify?(data, signature, public_key_pem)
public_key = OpenSSL::PKey::RSA.new(public_key_pem)
signature_decoded = Base64.decode64(signature)
public_key.verify(OpenSSL::Digest::SHA256.new, signature_decoded, data)
public_key.verify(OpenSSL::Digest.new("SHA256"), signature_decoded, data)
end
end
end

0 comments on commit d8bf672

Please sign in to comment.