about summary refs log tree commit diff
path: root/app/helpers/jsonld_helper.rb
diff options
context:
space:
mode:
authorPuck Meerburg <puck@puck.moe>2022-01-22 13:48:27 +0000
committerClaire <claire.github-309c@sitedethib.com>2022-02-02 16:13:11 +0100
commit63da32468cf5f5145deb51c93019009a6ef7f8db (patch)
treedc92c782651a9b05996e730b63a2a68a0735762f /app/helpers/jsonld_helper.rb
parent20a4b8081f419195334faee1b066e7e609ad4ffe (diff)
Compact JSON-LD signed incoming activities
Diffstat (limited to 'app/helpers/jsonld_helper.rb')
-rw-r--r--app/helpers/jsonld_helper.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/app/helpers/jsonld_helper.rb b/app/helpers/jsonld_helper.rb
index c24d2ddf1..841f27746 100644
--- a/app/helpers/jsonld_helper.rb
+++ b/app/helpers/jsonld_helper.rb
@@ -1,6 +1,8 @@
 # frozen_string_literal: true
 
 module JsonLdHelper
+  include ContextHelper
+
   def equals_or_includes?(haystack, needle)
     haystack.is_a?(Array) ? haystack.include?(needle) : haystack == needle
   end
@@ -69,6 +71,12 @@ module JsonLdHelper
     graph.dump(:normalize)
   end
 
+  def compact(json)
+    compacted = JSON::LD::API.compact(json.without('signature'), full_context, documentLoader: method(:load_jsonld_context))
+    compacted['signature'] = json['signature']
+    compacted
+  end
+
   def fetch_resource(uri, id, on_behalf_of = nil)
     unless id
       json = fetch_resource_without_id_validation(uri, on_behalf_of)