Nostr-PHP

https://nostr-php.dev

By sebastix, 1 April, 2025

You can follow the work in progress here in this pull request https://github.com/nostrver-se/nostr-php/pull/68 on Github.

Before my 3-month break (Dec/Jan/Feb) working on Nostr-PHP I started with the NIP-19 integration in October '24. Encoding and decoding the simple prefixes (npub, nsec and note) was already done in the first commits.

Learn more about NIP-19 here: https://nips.nostr.com/19 

TLV's

Things were getting more complicated with the other prefixes / identifiers defined in NIP-19:

  • nevent
  • naddr
  • nprofile

This is because these identifiers contain (optional) metadata called Type-Lenght-Value aka TLV's.

When sharing a profile or an event, an app may decide to include relay information and other metadata such that other apps can locate and display these entities more easily.

For these events, the contents are a binary-encoded list of _TLV_ (type-length-value), with _T_ and _L_ being 1 byte each (_uint8_, i.e. a number in the range of 0-255), and _V_ being a sequence of bytes of the size indicated by _L_.

These possible standardized TLV types are:

  • 0: special
    • depends on the bech32 prefix:
      • for nprofile it will be the 32 bytes of the profile public key
      • for nevent it will be the 32 bytes of the event id
      • for naddr, it is the identifier (the "d" tag) of the event being referenced. For normal replaceable events use an empty string.
  • 1: relay
    • for nprofile, nevent and  naddr, optionally, a relay in which the entity (profile or event) is more likely to be found, encoded as ascii
    • this may be included multiple times
  • 2: author
    • for naddr, the 32 bytes of the pubkey of the event
    • for nevent, optionally, the 32 bytes of the pubkey of the event
  • 3: kind
    • for naddr, the 32-bit unsigned integer of the kind, big-endian
    • for nevent, optionally, the 32-bit unsigned integer of the kind, big-endian

These identifiers are formatted as bech32 strings, but are much longer than the package bitwasp/bech32 (used in the library) for can handle for encoding and decoding. The bech32 strings handled by bitwasp/bech32 are limited to a maximum length of 90 characters.

Thanks to the effort of others (nostr:npub1636uujeewag8zv8593lcvdrwlymgqre6uax4anuq3y5qehqey05sl8qpl4 and nostr:npub1efz8l77esdtpw6l359sjvakm7azvyv6mkuxphjdk3vfzkgxkatrqlpf9s4) during my break, some contributions are made (modifiying the bech32 package supporting much longer strings, up to a max of 5000 characters). At this moment, I'm integrating this (mostly copy-pasting the stuff and refactoring the code):

So what's next?

  • NIP-19 code housekeeping + refactoring
  • Prepare a new release with NIP-19 integration
  • Create documentation page how to use NIP-19 on https://nostr-php.dev
By sebastix, 2 December, 2024

1) How did you spend your time?

I continued to write and publish more detailed weekly updates here: https://nostrver.se/blog. These updates are also cross-posted via Nostr as long-form content.

Integrated RelayResponse classes

Pull requests:

Documentation: https://nostr-php.dev/guides/relay-responses

Researched and build a proof of concept of a handling async requests and concurrency

I have published the research outcomes here: https://nostr-php.dev/references/async-concurrent-requests.   I also created a page here https://nostr-php.dev/guides/asynchronous-and-concurrent-requests with more details and a code snippet. The famous Http/Guzzle client is used for handling the requests in combination with a relative new piece of middleware which enables WebSockets. See https://github.com/valtzu/guzzle-websocket-middleware/issues/1 where I reached out for solving an issue with the middleware.

NIP-42 client to relay authentication

Finished, see https://github.com/nostrver-se/nostr-php/pull/67 

NIP-19 bech32-encoded entities

Work in progress, see https://github.com/nostrver-se/nostr-php/pull/68 

2.0.0 pre-release

See https://github.com/nostrver-se/nostr-php/releases/tag/2.0.0-alpha1 

Other stuff

2) What do you plan to work on next quarter?

  • Finish the NIP-19 implementation which will support every bech32 entity
    • note
    • npub
    • nsec
    • nevent
    • naddr
    • nprofile
  • Research how the revolt/event-loop package can be used to serve as a sort of a message bus for handling async and concurrent requests in the library
  • Build a final 2.0.x release
    • By default and full async concurrent requests support
  • Implement NIP-03
  • Implement NIP-45
  • Implement a firehose demo for requesting Nostr events
  • Host the nostr-php.dev website as a static website with Blossom on Nostr. See https://github.com/lez/nsite and https://github.com/hzrd149/nsite-ts

3) How did you make use of the money?

4) Is there anything we could help with?

I would love to see a (closed/private) digital place with other Nostr OpenSats grantees where we can share our experiences and challenges. We could give feedback to each other as a form of encouragement. For example I'm curious how other grantees are explaining the work they to other which are not familiar with FOSS, Nostr and/or Bitcoin.

By sebastix, 27 September, 2024

Here is code snippet: https://gist.github.com/Sebastix/5991b84334c6c7e12bc28b2e703311b6 

Labels
Nostr-PHP logo created by @npub1gwa27rpgum8mr9d30msg8cv7kwj2lhav2nvmdwh3wqnsa5vnudxqlta2sz (https://bitpopart.com/)

https://nostr-php.dev/assets/nostr-php_hero-splash.png