Bluesky, Farcaster, Lemmy, Mastodon, Nostr, Threads providers with Core\Plug\Web3 namespace alignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
111 lines
2.5 KiB
PHP
111 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Plug\Web3\Nostr;
|
|
|
|
use Core\Plug\Concern\BuildsResponse;
|
|
use Core\Plug\Concern\UsesHttp;
|
|
use Core\Plug\Contract\Deletable;
|
|
use Core\Plug\Response;
|
|
|
|
/**
|
|
* Nostr event deletion (soft delete via NIP-09).
|
|
*
|
|
* Creates kind 5 deletion events. Note: relays may
|
|
* not honour deletion requests.
|
|
*/
|
|
class Delete implements Deletable
|
|
{
|
|
use BuildsResponse;
|
|
use UsesHttp;
|
|
|
|
private ?string $privateKey = null;
|
|
|
|
private ?string $publicKey = null;
|
|
|
|
private array $relays = [];
|
|
|
|
/**
|
|
* Set the private key for signing.
|
|
*/
|
|
public function withPrivateKey(string $privateKey): self
|
|
{
|
|
$this->privateKey = $privateKey;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set the public key.
|
|
*/
|
|
public function withPublicKey(string $publicKey): self
|
|
{
|
|
$this->publicKey = $publicKey;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set relays to publish to.
|
|
*/
|
|
public function withRelays(array $relays): self
|
|
{
|
|
$this->relays = $relays;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Request deletion of an event (NIP-09).
|
|
*
|
|
* @param string $id Event ID to delete
|
|
*/
|
|
public function delete(string $id): Response
|
|
{
|
|
if (! $this->privateKey || ! $this->publicKey) {
|
|
return $this->error('Private and public keys required');
|
|
}
|
|
|
|
// Build deletion event (kind 5)
|
|
$event = [
|
|
'kind' => 5,
|
|
'pubkey' => $this->publicKey,
|
|
'created_at' => time(),
|
|
'tags' => [
|
|
['e', $id], // Reference to event being deleted
|
|
],
|
|
'content' => 'Deletion request',
|
|
];
|
|
|
|
// Calculate event ID
|
|
$serialized = json_encode([
|
|
0,
|
|
$event['pubkey'],
|
|
$event['created_at'],
|
|
$event['kind'],
|
|
$event['tags'],
|
|
$event['content'],
|
|
]);
|
|
$event['id'] = hash('sha256', $serialized);
|
|
|
|
// Sign the event
|
|
$event['sig'] = $this->signEvent($event['id']);
|
|
|
|
// Note: This is a soft delete - relays may ignore it
|
|
return $this->ok([
|
|
'deletion_event_id' => $event['id'],
|
|
'deleted_event_id' => $id,
|
|
'note' => 'Deletion is a request; relays may not honour it',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Sign event with private key.
|
|
*/
|
|
protected function signEvent(string $eventId): string
|
|
{
|
|
// Placeholder - use proper Schnorr signing in production
|
|
return hash_hmac('sha256', $eventId, $this->privateKey);
|
|
}
|
|
}
|