architecture changes

This commit is contained in:
Mike Macgirvin 2023-10-29 06:59:56 +11:00
parent e21866b3d8
commit bd579c8bd7
2 changed files with 17 additions and 11 deletions

View file

@ -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#',

View file

@ -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();
}