nostrbuild / nostr.build

FOSS version of nostr.build
https://nostr.build
MIT License
62 stars 15 forks source link

Stronger Types + Enums #5

Closed utxo-one closed 1 year ago

utxo-one commented 1 year ago

You can also consider making even stronger types for the $event array, instead constructing it as a class like

class SignedNostrEvent {

  public function __construct(
    public string $pubkey,
    public string $id,
    public string $sig,
    public int $kind,
    public string $content,
    public array $tags,
    public int $created_at
  ) {}
}

public function getEventHash(SignedNostrEvent $event): string
{
  $serializedEvent = $this->serializeEvent(json_encode($event));
  $eventHash = hash("sha256", $serializedEvent);

  return $eventHash;
}
fishcakeday commented 1 year ago

@utxo-one good suggestion, implemented. Thank you!