The interaction with the API happens over a websocket. All json should be sent on a single line, it's pretty printed here for readability. For an example client see here.
To connect to the API server:
$ websocat --origin https://powrelay.xyz https://powrelay.xyz/api
Once connected, you can send a request for proof of work:
{
"target_difficulty": <number of leading zeroes in the binary representation>,
"pubkey": <pubkey>,
"kind": <kind>,
"tags": <tags>,
"content": <content>
}
If there's an error, the server will send an error message:
{
"status": "ERROR",
"reason": <error details>
}
Otherwise, the server will send back a payment request:
{
"payment_request": <bech32-serialized lightning invoice>
}
You can verify that the description_hash of this invoice
matches the sha256 hash of the UTF-8 JSON-serialized string
(with no white space or line breaks) of the following structure:
[ "POW", <target difficulty, as number>, <pubkey, as a (lowercase) hex string>, <kind, as a number>, <tags, as an array of arrays of non-null strings>, <content, as a string> ]
When the payment is accepted the server will reply with a payment received message:
{
"status": "Payment received"
}
and start working on the request.
Only when a nonce with sufficient target difficulty is found,
will the server settle the payment and reply with the unsigned event:
{
"pubkey": <pubkey>,
"kind": <kind>,
"tags": <tags>,
"content": <content>
}
If an error happens, the server will cancel the invoice.
If a bug causes the invoice to be settled without the unsigned event being delivered,
the invoice and preimage constitute proof of payment,
so please contact
me
.