partial update to new ap:// DID scheme

This commit is contained in:
Mike Macgirvin 2024-04-23 07:39:01 +10:00
parent f5fbe5a80a
commit 1f895f6f76
5 changed files with 10 additions and 10 deletions

View file

@ -322,7 +322,7 @@ class Permissions
$n = []; $n = [];
if ($p) { if ($p) {
foreach ($p as $k => $v) { foreach ($p as $k => $v) {
if (intval($v)) { if ((int)$v) {
$n[] = $k; $n[] = $k;
} }
} }

View file

@ -16,10 +16,10 @@ class ActorId
public function __construct($id) public function __construct($id)
{ {
$this->id = $id; $this->id = $id;
if (str_contains($this->id, 'did:ap:key:')) { if (str_contains($this->id, 'did:key:')) {
$this->type = ActorId::ACTORID_TYPE_DID; $this->type = ActorId::ACTORID_TYPE_DID;
if (str_starts_with($this->id, 'http')) { if (str_starts_with($this->id, 'http') || str_starts_with($this->id, 'ap://')) {
$this->id = substr($this->id, strpos($this->id, 'did:ap:key:')); $this->id = substr($this->id, strpos($this->id, 'did:key:'));
$this->id = substr($this->id, 0, strpos($this->id, '?') ? strpos($this->id, '?') : null); $this->id = substr($this->id, 0, strpos($this->id, '?') ? strpos($this->id, '?') : null);
$this->id = substr($this->id, 0, strpos($this->id, '#') ? strpos($this->id, '#') : null); $this->id = substr($this->id, 0, strpos($this->id, '#') ? strpos($this->id, '#') : null);
} }

View file

@ -2072,7 +2072,7 @@ class Channel
else { else {
$ed25519publicKey = (new Multibase())->publicKey($channel['channel_epubkey']); $ed25519publicKey = (new Multibase())->publicKey($channel['channel_epubkey']);
} }
return 'did:ap:key:' . $ed25519publicKey; return 'did:key:' . $ed25519publicKey;
} }
public static function getDidActor($channel) public static function getDidActor($channel)

View file

@ -25,7 +25,7 @@ class Apresolver extends Controller
$url .= argv($index); $url .= argv($index);
} }
// Extract the ed25519 key from the DID URL. // Extract the ed25519 key from the DID URL.
$key = str_replace('did:ap:key:', '', $url); $key = str_replace('did:key:', '', $url);
$key = rtrim($key, '/'); $key = rtrim($key, '/');
$index = strpos($key, '/'); $index = strpos($key, '/');
$key = substr($key, 0, $index ?: null); $key = substr($key, 0, $index ?: null);
@ -38,7 +38,7 @@ class Apresolver extends Controller
if (!($query && isset($query[0]['channel_id']))) { if (!($query && isset($query[0]['channel_id']))) {
http_status_exit(404, 'Not found'); http_status_exit(404, 'Not found');
} }
$mappedPath = $this->mapObject(str_replace('did:ap:key:' . $key, '', rtrim($url, '/')), $query[0]); $mappedPath = $this->mapObject(str_replace('did:key:' . $key, '', rtrim($url, '/')), $query[0]);
$localPath = ltrim($mappedPath, '/'); $localPath = ltrim($mappedPath, '/');
App::$cmd = $localPath; App::$cmd = $localPath;
$controller = "\\Code\Module\\" . ucfirst(substr($localPath, 0, strpos($localPath, '/'))); $controller = "\\Code\Module\\" . ucfirst(substr($localPath, 0, strpos($localPath, '/')));

View file

@ -9,10 +9,10 @@ class ActorIdTest extends UnitTestCase
public function testActorId() public function testActorId()
{ {
$this->assertEquals('did:ap:key:abc12345', (new ActorId('https://resolver.com/resolver/did:ap:key:abc12345?foo'))->getId()); $this->assertEquals('did:key:abc12345', (new ActorId('https://resolver.com/resolver/did:key:abc12345?foo'))->getId());
$this->assertEquals('did:ap:key:abc12345', (new ActorId('https://resolver.com/resolver/did:ap:key:abc12345#foo'))->getId()); $this->assertEquals('did:key:abc12345', (new ActorId('https://resolver.com/resolver/did:key:abc12345#foo'))->getId());
$this->assertEquals('https://example.com/actor', (new ActorId('https://example.com/actor'))->getId()); $this->assertEquals('https://example.com/actor', (new ActorId('https://example.com/actor'))->getId());
$this->assertEquals('did:ap:key:abc12345', (new ActorId('did:ap:key:abc12345'))->getId()); $this->assertEquals('did:key:abc12345', (new ActorId('did:key:abc12345'))->getId());
} }