Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hzrd149/chessnut
Chess over nostr with cachu tokens
https://github.com/hzrd149/chessnut
cashu nostr
Last synced: about 1 month ago
JSON representation
Chess over nostr with cachu tokens
- Host: GitHub
- URL: https://github.com/hzrd149/chessnut
- Owner: hzrd149
- Created: 2023-04-20T13:27:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-02-18T20:26:53.000Z (11 months ago)
- Last Synced: 2024-07-30T19:34:42.017Z (5 months ago)
- Topics: cashu, nostr
- Language: TypeScript
- Homepage: https://hzrd149.github.io/chessnut/
- Size: 574 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ChessNut
Chess over [nostr](https://github.com/nostr-protocol/nostr) where players can place bets using [cashu](https://github.com/cashubtc) tokens (Nuts)
Live demo [Here](https://hzrd149.github.io/chessnut/)
# This is project isn't working yet, don't pay any lightning invoices (you will lose your hard earned sats)
## Nostr Events
```mermaid
erDiagram
METADATA {
string name
string picture
}
PLAYER {
string pubkey
}
PLAYER ||--|| METADATA : pubkeyMODERATOR {
string pubkey
string[] relay-list "10002 relay list"
string[] games "keep track of active games"
}
MODERATOR ||--o{ GAME : games
MODERATOR ||--|| METADATA : pubkeyGAME {
string id "event id"
int kind "2500"
string content "public message"
string author "player starting game"
string type "[type, enum] the type of game, chess/tictacktoe/checkers..."
string playerA "[p, self, r, 'playerA']"
string playerB "[p, playerB, r, 'playerB']"
string moderator "[p, moderator, r, 'moderator']"
string relay "[r, relay] the relay that should be used"
string state "[state, fen] starting state"
int expire "[expire, unix date] the expiration date (optional)"
int timeout "[timeout, seconds] how long to wait for next state (optional)"
}
GAME ||--|| PLAYER : author
GAME ||--|| PLAYER : playerA
GAME ||--|| PLAYER : playerB
GAME ||--|| MODERATOR : moderatorSTATE {
string id "event id"
int kind "2501"
string author "player making the state change"
string type "[type, type enum] (move, forfeit, draw)"
string move "[move, move] chess move (optional)"
string state "[state, fen] new state"
string game "[e, game, r, 'game']"
string previous "[e, state id, r, 'previous'] (optional)"
string moderator "[p, moderator, r, 'moderator']"
}
STATE ||--|| PLAYER : author
STATE ||--|| GAME : game
STATE ||--o| STATE : previous
STATE ||--|| MODERATOR : moderatorPLACE-BET {
string id "event id"
int kind "25002 (Ephemeral Event)"
string author "player creating the bet"
string game "[e, game, r, 'game']"
string moderator "[p, moderator, r, 'moderator']"
string cashuToken "[cashu, tokens] encrypted for moderator"
}
PLACE-BET ||--|| PLAYER : author
PLACE-BET ||--|| GAME : game
PLACE-BET ||--|| MODERATOR : moderatorBET {
string id "event id"
int kind "2502"
string author "moderator"
string player "[p, player] player who create the bet"
int amount "[value, int] value in sats"
string game "[e, game, r, 'game']"
string mint "[mint, mint url] the url of the mint"
}
BET ||--|| MODERATOR : author
BET ||--|| PLAYER : player
BET ||--|| GAME : gameFINISH {
string id "event id"
int kind "2503"
string author "moderator"
string content ""
string reason "[reason, enum reason] (win, draw)"
string game "[e, game, r, 'game']"
string previous "[e, state id, r, 'previous'] (optional)"
string players "[p, player, r, 'player'] multiple p tags for all players"
string winner "[winner, player] (optional) the winning player"
string cashu "[cashu, token, player] (encrypted for player) (can have multiple)"
}
FINISH ||--|| MODERATOR : author
FINISH ||--|| PLAYER : winner
FINISH ||--|| PLAYER : looser
FINISH ||--|| STATE : lastState
FINISH ||--|| GAME : game
```## Game Flow
```mermaid
flowchart TD
subgraph Player A
afindPlayer[Find player B]-->aCreateGame[Create game]
aCreateGame-->aSendNuts[Send nuts]
aCreateGame-.Start without nuts.->aWaitForTurn
aSendNuts--> aWaitForNuts([Wait for reward])
aSendNuts-.Start without nuts.->aWaitForTurn
aWaitForNuts-->aWaitForTurn([Wait for turn])
aWaitForTurn-->aGameMove[Game Move]
aWaitForTurn-->aForfeit[Forfeit]
aWaitForTurn-->aProposeDraw[Propose draw]
aSendNuts-->aWatchTokens([Watch for tokens])
aWatchTokens-->aClaimTokens[Claim tokens]
endsubgraph Moderator Bot
modFindGame([Find game])-->modWatchForNuts([Watch for nuts])
modWatchForNuts-->modConsumeNut[Melt nuts]
modConsumeNut-->modCreateReward[Create reward]
modFindGame-->modWatchMove([Watch moves])
modFindGame-->modWatchForfeit([Watch Forfeit])
modFindGame-->modWatchForDraw([Watch for draws])
modFindGame-->modWatchForBranches([Watch for branches])
modWatchMove--checkmate-->modSendTokens[Send Tokens to winner]
modWatchForfeit-->modSendTokens
modWatchForDraw-->modReturnTokens[Return tokens]
modWatchForBranches--Penalize player-->modSendTokens
endsubgraph Blayer B
bLookForGames([Find game])-->bWaitForNuts([Wait reward])
bWaitForNuts-.start without nuts.->bFirstMove
bWaitForNuts-->bSendNuts[Send nuts]
bSendNuts-->bFirstMove[First move]
bFirstMove-->bWaitForTurn([Wait for turn])
bFirstMove-->bWatchTokens([Watch for tokens])
bWaitForTurn --> bGameMove[Game Move]
bWaitForTurn-->bForfeit[Forfeit]
bWaitForTurn-->bProposeDraw[Propose draw]
bWatchTokens-->bClaimTokens[Claim tokens]
endaSendNuts-.->modWatchForNuts
bSendNuts-.->modWatchForNuts
bFirstMove-.->aWaitForTurn
modCreateReward-.->bWaitForNuts
modCreateReward-.->aWaitForNuts
aCreateGame-.->bLookForGames
aCreateGame-.->modFindGame
aGameMove-.->bWaitForTurn
bGameMove-.->aWaitForTurn
aGameMove-.->modWatchMove
bGameMove-.->modWatchMove
aForfeit-.->modWatchForfeit
bForfeit-.->modWatchForfeit
modSendTokens-.->aWatchTokens
modSendTokens-.->bWatchTokens
aProposeDraw-.->modWatchForDraw
bProposeDraw-.->modWatchForDraw
modReturnTokens-.->aWatchTokens
modReturnTokens-.->bWatchTokens
bFirstMove-.->modWatchForBranches
bGameMove-.->modWatchForBranches
aGameMove-.->modWatchForBranches
```