Skip to content

Latest commit

 

History

History
151 lines (129 loc) · 3.94 KB

100.md

File metadata and controls

151 lines (129 loc) · 3.94 KB

NIP-100

Chess

draft author:JellyCZYT

This NIP defines new protocol event kinds for enabling playing chess.

Event Kinds (Client to Relay)

Search for opponent (Event kind 5000)

NOTE: You need to call this event every time game ends for starting another. For example:

{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,    
  "kind": 5000,
  "content": "connect",
  "sig": <64-bytes hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
}

Relay will send OK message:

["OK", "b1a649ebe8...", true, ""]

Relay will send EVENT message after game is found:

["EVENT", 5000, <event JSON as defined under>]
{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "content": "gameisfound",
  "sig": <standard signature (NIP-01) encrypted using oponnent´s private key>
}

If you use than 1 relay to search opponents, you need to send cancelsearch.

{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "pubkey": <your public key>,    
  "kind": 5000,
  "content": "cancelsearch",
  "sig": <64-bytes hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
}

After game is found relay sends OK message means that game started:

["OK", "b1a649ebe8...", true, <color of your pieces>]

Making a move (Event kind 5001)

{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "pubkey": <your public key>,    
  "kind": 5001,
  "content": <your move in uci format>,
  "sig": <64-bytes hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
}

NOTE: You don´t need any game IDs, becuase client can only play one game at time.

Relay will respond using OK message:

["OK", "b1a649ebe8...", true, ""]

true means that move is valid otherwise it is invalid (If you have 2 invalid moves game ends).

When opponent makes a move, relay will send you EVENT message:

["EVENT", 5002, <event JSON as defined under>]
{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "content": <his move in uci format>,
  "sig": <standard signature (NIP-01) encrypted using oponnent´s private key>
}

Offering draw (Event kind 5002)

You can only offer a draw after you made a move.

{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "pubkey": <your public key>,    
  "kind": 5002,
  "content": "offer",
  "sig": <64-bytes hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
}

Relay will respond to the offer using OK message:

["OK", "b1a649ebe8...", true, "offer"]

When your opponent offers a draw relay will send you EVENT message:

["EVENT", 5002, <event JSON as defined under>]
{    
  "kind": 5002,
  "content": "offersent",
  "sig": <standard signature (NIP-01) encrypted using oponnent´s private key>
}

Resigning (Event kind 5003)

If you want to resign send this to relay:

{
  "id": <32-bytes lowercase hex-encoded sha256 of the serialized event data>,
  "pubkey": <your public key>,    
  "kind": 5003,
  "content": "resign",
  "sig": <64-bytes hex of the signature of the sha256 hash of the serialized event data, which is the same as the "id" field>
}

Relay will send this to client:

["OK", "b1a649ebe8...", true, "resigned"]

When opponent resigned relay will send you this message:

{
  "kind": 5000,
  "content": "opponentresigned",
  "sig": <standard signature (NIP-01) encrypted using oponnent´s private key>
}

Summary

Content tags: 5000: connect gameisfound cancelsearch opponentresigned gamedraw gamecheckmate 5001: <your move in uci> <his move in uci> 5002: offer offersent 5003: resign