Skip to content

tilttek/loot-tables

✅ published

Loot tables rolled with any die — committed before, revealed after, and checked by anyone.

tilttek/loot-tables describes what a product may hold as tables of entries, each rolled with one die: six entries with a d6, eight with a d8, twenty with a d20. Every entry has a name, an image and the slot it fills — a head, a hand, a belt. A box declares the tables a product rolls, in order: six tables of six entries roll 6d6. The draw is verifiable: its secret seed is committed before anyone knows the result, the dice are rolled from it through tilttek/dice, and the published proof lets anyone roll them again. Physical dice, rolled in front of a cashier, are entered as they fell. A text drawn from a list is a table of one die. A result writes itself as a shop code, one character per die, and as a line a receipt shows and a program reads back.

It is for any PHP code that sells or hands out what nobody chose: a loot box of a shop, a mystery item of a game, a random text printed on a product. tilttek/loot-tables-bundle integrates it with Symfony and with the options of a commerce order.

It is a plain PHP library that depends only on tilttek/dice.

Status

PartState
Entries, tables of any die, boxes, catalogues and their readerImplemented and tested
Verifiable draws: pending draw, reveal, proof and verificationImplemented and tested
Results of physical dice, texts drawn from a listImplemented and tested
Shop codes and draw texts, written and read back, fuzzedImplemented and tested

Documentation

DocumentWhat it covers
InstallationRequirements, installing and a first draw.
Tables and boxesLootEntry, LootTable, LootBox, LootCatalog, CatalogReader, and their limits.
DrawingPendingDraw, LootDrawer, RevealedDraw, the proof and its verification, physical dice.
CodesShopCode and DrawText.
ExceptionsLootException and its classes.
Extension pointsWhere the application plugs in.
TestingThe library's tests, its fuzz targets, and how to test code that uses it.
ReferenceEvery type of the library, with its role.

Quick start

composer require tilttek/loot-tables
use Random\Engine\Secure;
use Random\Randomizer;
use Tilttek\LootTables\Code\ShopCode;
use Tilttek\LootTables\Draw\LootDrawer;
use Tilttek\LootTables\Draw\PendingDraw;
use Tilttek\LootTables\Reading\CatalogReader;

$catalog = new CatalogReader()->read($decodedYaml);
$box = $catalog->box('starter');

$pending = PendingDraw::open(new Randomizer(new Secure()));
$commitment = $pending->commitment()->hex;      // shown to the buyer before the payment

// once, after the payment, with the client seed the buyer typed after seeing the commitment
$revealed = new LootDrawer()->reveal($box, $pending, $buyerClientSeed);
ShopCode::write($revealed->result);             // "352614"
$proof = $revealed->proof();                    // published: anyone verifies it
new LootDrawer()->verify($box, $proof);         // true

Requirements

PHP 8.5 or later, the mbstring extension, and tilttek/dice.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Tilttek project. See LICENSE.