Trying to make practical use of lame specs continued.

This commit is contained in:
Mike Macgirvin 2024-08-26 09:38:42 +10:00
parent e391a29cda
commit cf551b674a
5 changed files with 37 additions and 22 deletions

View file

@ -2440,6 +2440,7 @@ class Activity
return;
}
$actorIdUrl = $url;
$actorId = new ActorId($url);
$url = $actorId->getId();
$isDid = in_array($actorId->getType(), [ActorId::ACTORID_TYPE_DIDKEY, ActorId::ACTORID_TYPE_DIDWEB]);
@ -2621,7 +2622,7 @@ class Activity
// create a new record
xchan_store_lowlevel( [
'xchan_hash' => $url,
'xchan_guid' => $url,
'xchan_guid' => $actorIdUrl,
'xchan_pubkey' => $pubkey,
'xchan_epubkey' => $epubkey,
'xchan_addr' => $webfingerAddress,

View file

@ -264,13 +264,15 @@ class ActivityPub
$orig_follow_type = get_abconfig($x['sender']['channel_id'], $x['recipient']['xchan_hash'], 'activitypub', 'their_follow_type');
$locations = Activity::get_actor_hublocs($x['recipient']['xchan_hash'], 'activitypub, not_deleted');
$isNomadic = PConfig::Get($x['sender']['channel_id'], 'system', 'nomadicAP');
$rootPath = (($isNomadic) ? Channel::getDidResolver($x['sender']) : z_root());
if ($locations) {
foreach ($locations as $location) {
$msg = array_merge(
Activity::ap_context(),
[
'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR),
'id' => $rootPath . '/follow/' . $x['recipient']['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR),
'type' => (($orig_follow_type) ?: 'Follow'),
'actor' => $p,
'object' => $location['hubloc_id_url'],
@ -339,20 +341,21 @@ class ActivityPub
if (!$p) {
return;
}
$isNomadic = PConfig::Get($x['sender']['channel_id'], 'system', 'nomadicAP');
$rootPath = (($isNomadic) ? Channel::getDidResolver($x['sender']) : z_root());
$msg = array_merge(
Activity::ap_context(),
[
'id' => z_root() . '/follow/' . $x['recipient']['abook_id'] . '/' . md5($accept),
'id' => $rootPath . '/follow/' . $x['recipient']['abook_id'] . '/' . md5($accept),
'type' => 'Accept',
'actor' => $p,
'object' => [
'type' => (($follow_type) ?: 'Follow'),
'id' => $accept,
'actor' => $x['recipient']['xchan_hash'],
'actor' => $x['recipient']['xchan_guid'],
'object' => Channel::getDidResolver($x['sender'], true)
],
'to' => [$x['recipient']['xchan_hash']],
'to' => [$x['recipient']['xchan_guid']],
'cc' => []
]
);
@ -384,15 +387,17 @@ class ActivityPub
return;
}
$isNomadic = PConfig::Get($x['sender']['channel_id'], 'system', 'nomadicAP');
$msg = array_merge(
Activity::ap_context(),
[
'id' => z_root() . '/channel/' . $x['sender']['channel_address'] . '#update',
'id' => Channel::getDidResolver($x['sender'], true) . '#update',
'type' => 'Update',
'updated' => Time::convert(format: ISO8601),
'actor' => $p,
'object' => z_root() . '/channel/' . $x['sender']['channel_address'],
'to' => [z_root() . '/followers/' . $x['sender']['channel_address']],
'object' => Channel::getDidResolver($x['sender'], true),
'to' => [($isNomadic) ? Channel::getDidResolver($x['sender']) . 'actor/followers' : z_root() . '/followers/' . $x['sender']['channel_address']],
'cc' => [ACTIVITY_PUBLIC_INBOX]
]
);
@ -439,6 +444,9 @@ class ActivityPub
return;
}
$isNomadic = PConfig::Get($channel['channel_id'], 'system', 'nomadicAP');
$rootPath = (($isNomadic) ? Channel::getDidResolver($channel) : z_root());
// send an unfollow activity to the followee's inbox
$orig_activity = get_abconfig($recip[0]['abook_channel'], $recip[0]['xchan_hash'], 'activitypub', 'follow_id');
@ -446,19 +454,20 @@ class ActivityPub
if ($orig_activity && $recip[0]['abook_pending']) {
// was never approved
$msg = array_merge(
Activity::ap_context(),
[
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . '/' . md5($orig_activity) . '?operation=reject',
'id' => $rootPath . '/follow/' . $recip[0]['abook_id'] . '/' . md5($orig_activity) . '?operation=reject',
'type' => 'Reject',
'actor' => $p,
'object' => [
'type' => 'Follow',
'id' => $orig_activity,
'actor' => $recip[0]['xchan_hash'],
'actor' => $recip[0]['xchan_guid'],
'object' => $p
],
'to' => [$recip[0]['xchan_hash']],
'to' => [$recip[0]['xchan_guid']],
'cc' => []
]
);
@ -469,16 +478,16 @@ class ActivityPub
$msg = array_merge(
Activity::ap_context(),
[
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR) . '?operation=unfollow',
'id' => $rootPath . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR) . '?operation=unfollow',
'type' => 'Undo',
'actor' => $p,
'object' => [
'id' => z_root() . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR),
'id' => $rootPath . '/follow/' . $recip[0]['abook_id'] . (($orig_activity) ? '/' . md5($orig_activity) : EMPTY_STR),
'type' => 'Follow',
'actor' => $p,
'object' => $recip[0]['xchan_hash']
'object' => $recip[0]['xchan_guid']
],
'to' => [$recip[0]['xchan_hash']],
'to' => [$recip[0]['xchan_guid']],
'cc' => []
]
);

View file

@ -2080,10 +2080,13 @@ class Channel
return self::getDid($channel);
}
public static function getVerifier($channel)
public static function getVerifier($channel, $id = '')
{
$pubkey = (new Multibase())->publicKey($channel['channel_epubkey']);
$nomadic = PConfig::Get($channel['channel_id'], 'system', 'nomadicAP');
if (!str_contains($id, '/.well-known/apgateway/')) {
$nomadic = false;
}
return (($nomadic) ? Channel::getDid($channel) : Channel::url($channel) . '#' . $pubkey);
}

View file

@ -26,7 +26,7 @@ class JcsEddsa2022
'type' => 'DataIntegrityProof',
'cryptosuite' => 'eddsa-jcs-2022',
'created' => Time::convert(format: ISO8601),
'verificationMethod' => Channel::getVerifier($channel),
'verificationMethod' => Channel::getVerifier($channel, $data['id'] ?? ''),
'proofPurpose' => 'assertionMethod',
];

View file

@ -3,6 +3,7 @@
namespace Code\Module;
use App;
use Code\Lib\PConfig;
use Code\Web\Controller;
use Code\Lib\Libsync;
use Code\Lib\ActivityStreams;
@ -48,12 +49,13 @@ class Follow extends Controller
$orig_follow = get_abconfig($chan['channel_id'], $r[0]['xchan_hash'], 'activitypub', 'their_follow_id');
$orig_follow_type = get_abconfig($chan['channel_id'], $r[0]['xchan_hash'], 'activitypub', 'their_follow_type');
$isNomadic = PConfig::Get($chan['channel_id'], 'system', 'nomadicAP');
$rootPath = (($isNomadic) ? Channel::getDidResolver($chan) : z_root());
as_return_and_die([
'id' => z_root() . '/follow/' . $r[0]['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR),
'id' => $rootPath . '/follow/' . $r[0]['abook_id'] . (($orig_follow) ? '/' . md5($orig_follow) : EMPTY_STR),
'type' => (($orig_follow_type) ?: 'Follow'),
'actor' => $actor,
'object' => $r[0]['xchan_url']
'object' => $r[0]['xchan_guid']
], $chan);
}
@ -146,7 +148,7 @@ class Follow extends Controller
info(t('Connection added.') . EOL);
Channel::abook_sync($channel, $result['abook']);
$can_view_stream = their_perms_contains($channel['channel_id'], $clone['abook_xchan'], 'view_stream');
$can_view_stream = their_perms_contains($channel['channel_id'], $result['abook']['abook_xchan'], 'view_stream');
// If we can view their stream, pull in some posts