Download the PHP package swentel/nostr-php without Composer
On this page you can find all versions of the php package swentel/nostr-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nostr-php
nostr-php
This is a PHP Helper library for Nostr. More info about Nostr: https://github.com/nostr-protocol/nostr.
Installation
To use the package in your PHP project with Composer:
Install dependencies if you would like to test / code some things out for yourself with the code example snippets below.
Create an event
This will create an event object with a short text message (kind 1).
Signing an event
Generates the id and signature for an event. The 'pubkey', 'id' and 'sig' properties are added to the event object.
Generating a message
Generate an event message : ["EVENT", <event JSON as created above with id and sig>]
Publish an event to a relay
Publish an event with a note that has been prepared for sending to a relay.
If you would like to publish the event to multiple relays, you can use the RelaySet
class.
Read events from a relay
Fetch events from a relay.
$response
is a multidimensional array with elements containing each a response message (JSON string) decoded to an array from the relay and sorted by the relay.
Output example:
Read events from a set of relays
Read events from a set of relays with the RelaySet
class.
It's basically the same snippet as above with the difference you create a RelaySet
class and pass it through the Request
object.
Generating a private key and a public key
Converting keys
Convert bech32 encoded keys (npub, nsec) to hex.
Convert hex keys to bech32 (npub, nsec).
Run tests
All tests can be found in tests
.
Documentation with phpDocumentor
Generate documentation with phpDocumentor.
All documentation is saved in the phpdoc.nostr-php.dev
directory where the index.html
can be opened in any browser.
This directory also serves as the root directory for https://phpdoc.nostr-php.dev.
The documentation of phpDocumentor can be found at https://docs.phpdoc.org/.
nostr-php script (cli client)
The library ships with a simple CLI client (bin/nostr-php
) to post a short text note to a Nostr relay.
Note: the key arguments expects a file with your private key! Do not paste your private key on command line.
Roadmap
- [x] Keypair generation and validation
- [x] Convert from hex to bech32-encoded keys
- [x] Event signing with Schnorr signatures (
secp256k1
) - [x] Event validation (issue #17)
- [x] Support NIP-01 basic protocol flow description
- [x] Publish events
- [x] Request events (issue #55 credits to kriptonix)
- [x] Implement all types of relay responses
- [x]
EVENT
- sends events requested by the client - [x]
OK
- indicate an acceptance or denial of an EVENT message - [x]
EOSE
- end of stored events - [x]
CLOSED
- subscription is ended on the server side - [x]
NOTICE
- used to send human-readable messages (like errors) to clients
- [x] Improve handling relay responses
- [ ] Support NIP-19 bech32-encoded identifiers
- [x] Support NIP-42 authentication of clients to relays
- [ ] Support NIP-45 event counts
- [ ] Support NIP-50 search capability
- [ ] Support multi-threading (async concurrency) for handling requests simultaneously
- [ ] Support realtime (runtime) subscriptions with the
bin/nostr-php
CLI client to listen to new events from relays
Community
If you need any help, please join this Telegram group: https://t.me/nostr_php
Funding
In May 2024 OpenSats granted Sebastian Hagens for further development of this library for one year. If you would like to support this project with a donation, you could send some lightning sats to [email protected]
or on-chain to bc1p3p6jq2sxsf650lgllv57st9h97xj37fflg5t8d265saz6yqzcdyqd7pzun
.
Maintainers
- @sebastix
npub1qe3e5wrvnsgpggtkytxteaqfprz0rgxr8c3l34kk3a9t7e2l3acslezefe
- @swentel (original author, inactive)
npub1z8n2zt0vzkefhrhpf60face4wwq2nx87sz7wlgcvuk4adddkkycqknzjk5
Contributors
See https://github.com/nostrver-se/nostr-php/graphs/contributors
All versions of nostr-php with dependencies
ext-gmp Version *
ext-xml Version *
bitwasp/bech32 Version ^0.0.1
phrity/websocket Version ^3.0
simplito/elliptic-php Version ^1.0
uma/phpecc Version ^0.1.3