aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Zotlabs/Daemon/Notifier.php10
-rw-r--r--Zotlabs/Lib/Activity.php76
-rw-r--r--Zotlabs/Lib/ActivityStreams.php1
-rw-r--r--Zotlabs/Module/Activity.php38
-rw-r--r--Zotlabs/Module/Apschema.php65
-rw-r--r--Zotlabs/Module/Event.php26
-rw-r--r--Zotlabs/Module/Follow.php23
-rw-r--r--include/network.php17
8 files changed, 95 insertions, 161 deletions
diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php
index 4b74a7ba9..d1c0e4ec8 100644
--- a/Zotlabs/Daemon/Notifier.php
+++ b/Zotlabs/Daemon/Notifier.php
@@ -5,7 +5,6 @@ namespace Zotlabs\Daemon;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Queue;
-use Zotlabs\Lib\LDSignatures;
require_once('include/html2plain.php');
require_once('include/conversation.php');
@@ -342,14 +341,7 @@ class Notifier {
self::$encoded_item = json_decode($m, true);
}
else {
-
- self::$encoded_item = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], Activity::encode_activity($target_item)
- );
- self::$encoded_item['signature'] = LDSignatures::sign(self::$encoded_item, self::$channel);
+ self::$encoded_item = Activity::build_packet(Activity::encode_activity($target_item), self::$channel, false);
}
logger('target_item: ' . print_r($target_item, true), LOGGER_DEBUG);
diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php
index 0dfa15aea..766b4ed91 100644
--- a/Zotlabs/Lib/Activity.php
+++ b/Zotlabs/Lib/Activity.php
@@ -4211,4 +4211,80 @@ class Activity {
}
+ public static function ap_context($contextType = null): array {
+ return ['@context' => [
+ ACTIVITYSTREAMS_JSONLD_REV,
+ 'https://w3id.org/security/v1',
+ // 'https://www.w3.org/ns/did/v1',
+ // 'https://w3id.org/security/multikey/v1',
+ // 'https://w3id.org/security/data-integrity/v1',
+ 'https://purl.archive.org/socialweb/webfinger',
+ self::ap_schema($contextType)
+ ]];
+ }
+
+ public static function ap_schema($contextType = null): array {
+ // $contextType is reserved for future use so that the caller can specify
+ // a limited subset of the entire schema definition for particular activities.
+
+ return [
+ 'zot' => z_root() . '/apschema#',
+ 'schema' => 'http://schema.org#',
+ 'ostatus' => 'http://ostatus.org#',
+ 'diaspora' => 'https://diasporafoundation.org/ns/',
+
+ 'commentPolicy' => 'zot:commentPolicy',
+ 'locationAddress' => 'zot:locationAddress',
+ 'locationPrimary' => 'zot:locationPrimary',
+ 'locationDeleted' => 'zot:locationDeleted',
+ 'nomadicLocation' => 'zot:nomadicLocation',
+ 'nomadicHubs' => 'zot:nomadicHubs',
+ 'emojiReaction' => 'zot:emojiReaction',
+ 'expires' => 'zot:expires',
+ 'directMessage' => 'zot:directMessage',
+ 'Bookmark' => 'zot:Bookmark',
+ 'Category' => 'zot:Category',
+
+ 'PropertyValue' => 'schema:PropertyValue',
+ 'value' => 'schema:value',
+
+ 'conversation' => 'ostatus:conversation',
+
+ 'guid' => 'diaspora:guid',
+
+ 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
+ 'Hashtag' => 'as:Hashtag'
+
+ ];
+
+ }
+
+ /**
+ * @brief Builds the activity packet and signs it if $channel is provided.
+ *
+ * @param array $obj
+ * @param array $channel (optional) default []
+ * @param bool $json_encode (optional) default true
+ * @return string|array
+ */
+
+ public static function build_packet(array $obj, array $channel = [], bool $json_encode = true): string|array {
+ $arr = array_merge(Activity::ap_context(), $obj);
+
+ if ($channel) {
+ // $proof = (new JcsEddsa2022)->sign($arr, $channel);
+ // $arr['proof'] = $proof;
+
+ $signature = LDSignatures::sign($arr, $channel);
+ $arr['signature'] = $signature;
+ }
+
+ if ($json_encode) {
+ return json_encode($arr, JSON_UNESCAPED_SLASHES);
+ }
+
+ return $arr;
+ }
+
+
}
diff --git a/Zotlabs/Lib/ActivityStreams.php b/Zotlabs/Lib/ActivityStreams.php
index 4c3e3d8f8..c32f82e33 100644
--- a/Zotlabs/Lib/ActivityStreams.php
+++ b/Zotlabs/Lib/ActivityStreams.php
@@ -28,6 +28,7 @@ class ActivityStreams {
public $sigok = false;
public $recips = null;
public $raw_recips = null;
+ public $saved_recips = null;
/**
* @brief Constructor for ActivityStreams.
diff --git a/Zotlabs/Module/Activity.php b/Zotlabs/Module/Activity.php
index 4ddfe602d..b2f0ce498 100644
--- a/Zotlabs/Module/Activity.php
+++ b/Zotlabs/Module/Activity.php
@@ -7,7 +7,6 @@ use Zotlabs\Web\Controller;
use Zotlabs\Daemon\Master;
use Zotlabs\Lib\Activity as ZlibActivity;
use Zotlabs\Lib\ActivityStreams;
-use Zotlabs\Lib\LDSignatures;
use Zotlabs\Web\HTTPSig;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\ThreadListener;
@@ -155,22 +154,7 @@ class Activity extends Controller {
if(! $i)
http_status_exit(404, 'Not found');
- $x = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], $i);
-
- $headers = [];
- $headers['Content-Type'] = 'application/x-zot+json' ;
- $x['signature'] = LDSignatures::sign($x,$chan);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- $headers['Digest'] = HTTPSig::generate_digest_header($ret);
- $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
- $h = HTTPSig::create_sig($headers,$chan['channel_prvkey'],channel_url($chan));
- HTTPSig::set_headers($h);
- echo $ret;
- killme();
+ as_return_and_die($i, $chan);
}
@@ -260,25 +244,7 @@ class Activity extends Controller {
$channel = channelx_by_n($items[0]['uid']);
- $x = array_merge( ['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], ZlibActivity::encode_activity($items[0],true));
-
- $headers = [];
- $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
- $x['signature'] = LDSignatures::sign($x,$channel);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- $headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
- $headers['Digest'] = HTTPSig::generate_digest_header($ret);
- $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
-
- $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
- HTTPSig::set_headers($h);
- echo $ret;
- killme();
-
+ as_return_and_die(ZlibActivity::encode_activity($items[0]), $channel);
}
goaway(z_root() . '/item/' . argv(1));
diff --git a/Zotlabs/Module/Apschema.php b/Zotlabs/Module/Apschema.php
index 8d57fb777..2ec11086a 100644
--- a/Zotlabs/Module/Apschema.php
+++ b/Zotlabs/Module/Apschema.php
@@ -2,70 +2,13 @@
namespace Zotlabs\Module;
+use Zotlabs\Web\Controller;
+use Zotlabs\Lib\Activity;
-class Apschema extends \Zotlabs\Web\Controller {
-
+class Apschema extends Controller {
function init() {
-
- $base = z_root();
-
- $arr = [
- '@context' => [
- 'zot' => z_root() . '/apschema#',
- 'id' => '@id',
- 'type' => '@type',
- 'commentPolicy' => 'zot:commentPolicy',
- 'meData' => 'zot:meData',
- 'meDataType' => 'zot:meDataType',
- 'meEncoding' => 'zot:meEncoding',
- 'meAlgorithm' => 'zot:meAlgorithm',
- 'meCreator' => 'zot:meCreator',
- 'meSignatureValue' => 'zot:meSignatureValue',
- 'locationAddress' => 'zot:locationAddress',
- 'locationPrimary' => 'zot:locationPrimary',
- 'locationDeleted' => 'zot:locationDeleted',
- 'nomadicLocation' => 'zot:nomadicLocation',
- 'nomadicHubs' => 'zot:nomadicHubs',
- 'emojiReaction' => 'zot:emojiReaction',
- 'expires' => 'zot:expires',
- 'directMessage' => 'zot:directMessage',
- 'schema' => 'http://schema.org#',
- 'PropertyValue' => 'schema:PropertyValue',
- 'value' => 'schema:value',
-
- 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
-
-
- 'magicEnv' => [
- '@id' => 'zot:magicEnv',
- '@type' => '@id'
- ],
-
- 'nomadicLocations' => [
- '@id' => 'zot:nomadicLocations',
- '@type' => '@id'
- ],
-
- 'ostatus' => 'http://ostatus.org#',
- 'conversation' => 'ostatus:conversation',
-
- 'diaspora' => 'https://diasporafoundation.org/ns/',
- 'guid' => 'diaspora:guid',
-
- 'Hashtag' => 'as:Hashtag',
- 'Bookmark' => 'zot:Bookmark',
- 'Category' => 'zot:Category'
-
- ]
- ];
-
header('Content-Type: application/ld+json');
- echo json_encode($arr,JSON_UNESCAPED_SLASHES);
+ echo json_encode(Activity::ap_context(), JSON_UNESCAPED_SLASHES);
killme();
-
}
-
-
-
-
}
diff --git a/Zotlabs/Module/Event.php b/Zotlabs/Module/Event.php
index 22a1341cc..767a8f494 100644
--- a/Zotlabs/Module/Event.php
+++ b/Zotlabs/Module/Event.php
@@ -4,7 +4,6 @@ namespace Zotlabs\Module;
use Zotlabs\Web\Controller;
use Zotlabs\Lib\ActivityStreams;
use Zotlabs\Lib\Activity;
-use Zotlabs\Lib\LDSignatures;
use Zotlabs\Web\HTTPSig;
class Event extends Controller {
@@ -17,7 +16,7 @@ class Event extends Controller {
if(! $item_id)
return;
- $item_normal = " and item.item_hidden = 0 and item.item_type = 0 and item.item_unpublished = 0
+ $item_normal = " and item.item_hidden = 0 and item.item_type = 0 and item.item_unpublished = 0
and item.item_delayed = 0 and item.item_blocked = 0 ";
$sql_extra = item_permissions_sql(0);
@@ -49,28 +48,9 @@ class Event extends Controller {
$obj = $items[0]['obj'];
}
- $x = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], $obj );
-
- $headers = [];
- $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
- $x['signature'] = LDSignatures::sign($x,$channel);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- $headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
- $headers['Digest'] = HTTPSig::generate_digest_header($ret);
- $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
-
- $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
- HTTPSig::set_headers($h);
-
- echo $ret;
- killme();
-
+ as_return_and_die($obj, $channel);
}
}
-} \ No newline at end of file
+}
diff --git a/Zotlabs/Module/Follow.php b/Zotlabs/Module/Follow.php
index f8bfc11f3..55ff507c8 100644
--- a/Zotlabs/Module/Follow.php
+++ b/Zotlabs/Module/Follow.php
@@ -7,7 +7,6 @@ use Zotlabs\Lib\Libsync;
use Zotlabs\Lib\ActivityStreams;
use Zotlabs\Lib\Activity;
use Zotlabs\Web\HTTPSig;
-use Zotlabs\Lib\LDSignatures;
use Zotlabs\Lib\Connect;
use Zotlabs\Daemon\Master;
@@ -39,30 +38,14 @@ class Follow extends Controller {
http_status_exit(404, 'Not found');
}
- $x = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]],
- [
+ $obj = [
'id' => z_root() . '/follow/' . $r[0]['abook_id'],
'type' => 'Follow',
'actor' => $actor,
'object' => $r[0]['xchan_url']
- ]);
-
- $headers = [];
- $headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
- $x['signature'] = LDSignatures::sign($x,$chan);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- $headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
- $headers['Digest'] = HTTPSig::generate_digest_header($ret);
- $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
- $h = HTTPSig::create_sig($headers,$chan['channel_prvkey'],channel_url($chan));
- HTTPSig::set_headers($h);
- echo $ret;
- killme();
+ ];
+ as_return_and_die($obj, $chan);
}
if (! local_channel()) {
diff --git a/include/network.php b/include/network.php
index 13339eccd..854434d5a 100644
--- a/include/network.php
+++ b/include/network.php
@@ -1,6 +1,6 @@
<?php
-use Zotlabs\Lib\LDSignatures;
+use Zotlabs\Lib\Activity;
use Zotlabs\Lib\Zotfinger;
use Zotlabs\Lib\Libzot;
use Zotlabs\Lib\Queue;
@@ -423,24 +423,17 @@ function json_return_and_die($x, $content_type = 'application/json') {
killme();
}
-function as_return_and_die($obj,$channel) {
+function as_return_and_die($obj, $channel) {
- $x = array_merge(['@context' => [
- ACTIVITYSTREAMS_JSONLD_REV,
- 'https://w3id.org/security/v1',
- z_root() . ZOT_APSCHEMA_REV
- ]], $obj );
+ $ret = Activity::build_packet($obj, $channel);
+ logger('data: ' . jindent($ret), LOGGER_DATA);
- $headers = [];
$headers['Content-Type'] = 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' ;
- $x['signature'] = LDSignatures::sign($x,$channel);
- $ret = json_encode($x, JSON_UNESCAPED_SLASHES);
- logger('data: ' . jindent($ret), LOGGER_DATA);
$headers['Date'] = datetime_convert('UTC','UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T');
$headers['Digest'] = HTTPSig::generate_digest_header($ret);
$headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI'];
- $h = HTTPSig::create_sig($headers,$channel['channel_prvkey'],channel_url($channel));
+ $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], channel_url($channel));
HTTPSig::set_headers($h);
echo $ret;