From bd579c8bd753b8e4e65360a6afc5a85625d3409d Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Sun, 29 Oct 2023 06:59:56 +1100 Subject: [PATCH] architecture changes --- Code/Lib/Activity.php | 9 ++++++--- include/network.php | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 496522e6a..4b262edd5 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -4796,19 +4796,22 @@ class Activity return $ret; } - public static function ap_context(): array + 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/data-integrity/v1', - self::ap_schema() + self::ap_schema($contextType) ]]; } - public static function ap_schema() + public static function ap_schema($contextType = null) { + // $contextType is reserved for future use so that the caller can specify + // a limited subset of the entire schema definition for particular activities. + return [ 'nomad' => z_root() . '/apschema#', 'toot' => 'http://joinmastodon.org/ns#', diff --git a/include/network.php b/include/network.php index 91afa0788..a0b4a3282 100644 --- a/include/network.php +++ b/include/network.php @@ -34,26 +34,29 @@ function json_return_and_die($x, $content_type = 'application/json', $debug = fa killme(); } -function as_return_and_die($obj, $channel) +function as_return_and_die($obj, $channel, $contextType = null) { - if(is_array($obj)) { - $x = array_merge(Activity::ap_context(), $obj); + if (! is_array($obj)) { + killme(); } + $data = array_merge(Activity::ap_context($contextType), $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); - logger('data: ' . jindent($ret), LOGGER_DATA); + $data['signature'] = LDSignatures::sign($data, $channel); + $json = json_encode($data, JSON_UNESCAPED_SLASHES); + logger('data: ' . jindent($json), 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['Digest'] = HTTPSig::generate_digest_header($json); $headers['(request-target)'] = strtolower($_SERVER['REQUEST_METHOD']) . ' ' . $_SERVER['REQUEST_URI']; $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], Channel::keyId($channel)); HTTPSig::set_headers($h); - echo $ret; + echo $json; killme(); }