nostrver-se / nostr-php

PHP helper library for Nostr https://nostr-php.dev
https://nostr-php.dev
MIT License
53 stars 15 forks source link

Bad event id when content includes emojis or unicode characters #23

Closed pjv closed 1 year ago

pjv commented 1 year ago

If an event’s content includes emojis, something doesn’t work right when generating the event’s id.

Here’s some test code that when run against a working relay will reject the event with a “bad id” error message.

<?php

require './vendor/autoload.php';

use swentel\nostr\Event\Event;
use swentel\nostr\Message\EventMessage;
use swentel\nostr\Relay\Relay;
use swentel\nostr\Sign\Sign;

function send($message) {
  $note = new Event();
  $note->setContent($message)->setKind(1);
  $signer = new Sign();
  $signer->signEvent($note, 'some_private_key');
  $eventMessage = new EventMessage($note);

  $websocket = 'wss://some.nostr.relay';
  $relay = new Relay($websocket, $eventMessage);
  $result = $relay->send();
  if ($result->isSuccess()) {
    print "Sent to Nostr!\n";
  } else {
    print 'Something went wrong: ' . $result->message() . "\n";
  }
}

$message = 'This note is a test of emojis 🍕.';

send($message);

The same issue occurs if the content includes a unicode character such as: ñ.

pjv commented 1 year ago

I think I have this solved. PR incoming.

Sebastix commented 1 year ago

It's working: https://nostr.com/nevent1qqs2yz0he7hjmfehr46u5lkh94w3atcuplgujg94eng768q0j62z36sprpmhxue69uhkummnw3ezuum9vfshxarf0qhxgetkqyvhwumn8ghj7mn0wd68ytnnv43xzum5d9uzuer9wchszynhwden5te0wp6hyurvv4cxzeewv4esz9rhwden5te0wfjkccte9ejxzmt4wvhxjmcpzemhxue69uhhyetvv9ujumn0wd68ytnzv9hxgqgnwaehxw309aex2mrp09skymr99ehhyecpzpmhxue69uhkummnw3ezuamfdejsdnmj8m