-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
319 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/.gitattributes export-ignore | ||
/.github export-ignore | ||
/.gitignore export-ignore | ||
/.styleci.yml export-ignore | ||
/tests export-ignore | ||
/phpunit.xml export-ignore | ||
|
||
*.* text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
preset: psr2 | ||
preset: psr12 | ||
|
||
finder: | ||
exclude: | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
{ | ||
"name": "rogervila/provably-fair", | ||
"description": "PHP implementation of Bustabit's Provably Fair system", | ||
"license": "MIT", | ||
"type": "library", | ||
"keywords": [ | ||
"provably fair" | ||
], | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Roger Vilà", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": "^7.0|^8.0" | ||
"php": "^8.1" | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^6.0|^7.0|^8.0|^9.0", | ||
"rogervila/php-sonarqube-scanner": "^1.0" | ||
"phpunit/phpunit": "^9.5.26", | ||
"rogervila/php-sonarqube-scanner": "^1.1.0", | ||
"squizlabs/php_codesniffer": "^3.7" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"autoload": { | ||
"psr-4": { | ||
"ProvablyFair\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\ProvablyFair\\": "tests/" | ||
"ProvablyFairTests\\": "tests/" | ||
} | ||
}, | ||
"config": { | ||
"optimize-autoloader": true, | ||
"preferred-install": "dist", | ||
"sort-packages": true, | ||
"optimize-autoloader": true | ||
"sort-packages": true | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"scripts": { | ||
"test": [ | ||
"composer validate", | ||
"vendor/bin/phpcs --standard=PSR12 --bootstrap=vendor/autoload.php src", | ||
"vendor/bin/phpunit" | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,25 @@ | ||
<?php | ||
|
||
require(__DIR__ . '/vendor/autoload.php'); | ||
use ProvablyFair\Algorithm; | ||
use ProvablyFair\ProvablyFair; | ||
use ProvablyFair\Seed; | ||
|
||
define('ALGO', 'sha512'); | ||
define('SERVER', 'example'); | ||
define('CLIENT', 'example'); | ||
define('AMOUNT', 100); | ||
require __DIR__ . '/vendor/autoload.php'; | ||
|
||
$algo = new \ProvablyFair\Algorithm(ALGO); | ||
const ALGORITHM = 'sha512'; | ||
const SERVER = 'example'; | ||
const CLIENT = 'example'; | ||
const AMOUNT = 100; | ||
const PREPEND = false; | ||
|
||
$system = new \ProvablyFair\System($algo); | ||
|
||
$serverSeed = new \ProvablyFair\Seed(isset($_GET['server']) ? $_GET['server'] : SERVER); | ||
$clientSeed = new \ProvablyFair\Seed(isset($_GET['client']) ? $_GET['client'] : CLIENT); | ||
$resultAmount = isset($_GET['amount']) ? $_GET['amount'] : AMOUNT; | ||
$results = (new ProvablyFair( | ||
$clientSeed = new Seed($_GET['client'] ?? CLIENT), | ||
$serverSeed = new Seed($_GET['server'] ?? SERVER), | ||
$algorithm = new Algorithm($_GET['algorithm'] ?? ALGORITHM), | ||
))->generate( | ||
$amount = intval($_GET['amount'] ?? AMOUNT), | ||
$prepend = boolval($_GET['prepend'] ?? PREPEND) | ||
) | ||
|
||
?> | ||
<!DOCTYPE html> | ||
|
@@ -23,36 +29,46 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Provably Fair Demo</title> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous"> | ||
</head> | ||
<body> | ||
<div class="container-fluid"> | ||
<div class="container"> | ||
<h1 class="mt-5">Provably Fair Demo</h1> | ||
<hr> | ||
<form class="mb-5"> | ||
<div class="row"> | ||
<div class="form-group col"> | ||
<label class="d-block" for="algo">Algorithm</label> | ||
<input id="algo" readonly disabled autocomplete="off" type="text" name="algo" value="<?php echo $algo->getValue() ?>"> | ||
<div class="col-12 col-md-3"> | ||
<label class="form-label" for="algorithm">Algorithm</label> | ||
<select class="form-select" name="algorithm" id="algorithm"> | ||
<?php foreach (hash_hmac_algos() as $available_algorithm): ?> | ||
<option <?php echo $available_algorithm === $algorithm->value ? 'selected' : '' ?> value="<?php echo $available_algorithm ?>"><?php echo $available_algorithm ?></option> | ||
<?php endforeach; ?> | ||
</select> | ||
</div> | ||
|
||
<div class="form-group col"> | ||
<label class="d-block" for="server">Server seed</label> | ||
<input id="server" autocomplete="off" type="text" name="server" value="<?php echo $serverSeed->getValue() ?>" required> | ||
<div class="col-12 col-md-3"> | ||
<label class="form-label" for="server">Server seed</label> | ||
<input class="form-control" id="server" autocomplete="off" type="text" name="server" value="<?php echo $serverSeed->value ?>" required> | ||
</div> | ||
|
||
<div class="form-group col"> | ||
<label class="d-block" for="client">Client seed</label> | ||
<input id="client" autocomplete="off" type="text" name="client" value="<?php echo $clientSeed->getValue() ?>" required> | ||
<div class="col-12 col-md-3"> | ||
<label class="form-label" for="client">Client seed</label> | ||
<input class="form-control" id="client" autocomplete="off" type="text" name="client" value="<?php echo $clientSeed->value ?>" required> | ||
</div> | ||
|
||
<div class="form-group col"> | ||
<label class="d-block" for="amount">Amount of results</label> | ||
<input id="amount" autocomplete="off" type="number" min="0" name="amount" value="<?php echo $resultAmount ?>" required> | ||
<div class="col-12 col-md-3"> | ||
<label class="form-label" for="amount">Amount of results</label> | ||
<input class="form-control" id="amount" autocomplete="off" type="number" min="0" name="amount" value="<?php echo $amount ?>" required> | ||
</div> | ||
</div> | ||
|
||
<input type="submit" class="btn btn-primary" value="Submit"> | ||
<div class="mt-3"> | ||
<input type="submit" class="btn btn-primary me-2" value="Submit"> | ||
<div class="form-check form-check-inline"> | ||
<input class="form-check-input" type="checkbox" id="prepend" name="prepend" <?php echo $prepend === true ? 'checked' : '' ?> > | ||
<label class="form-check-label" for="prepend">Prepend original server seed result</label> | ||
</div> | ||
</div> | ||
</form> | ||
|
||
<table class="table table-responsive w-100 d-block d-md-table"> | ||
|
@@ -61,23 +77,20 @@ | |
<th>Hash</th> | ||
<th>Result</th> | ||
</tr> | ||
<?php for ($result = $resultAmount; $result > 0; $result--) : ?> | ||
<?php $serverSeed = $system->generateServerSeed($serverSeed); ?> | ||
<?php foreach ($results as $result): ?> | ||
<tr> | ||
<td> | ||
<small><?php echo $result ?></small> | ||
<small><?php echo $result->index ?></small> | ||
</td> | ||
<td> | ||
<pre class="m-0"><?php echo $serverSeed->getValue() ?></pre> | ||
<pre class="m-0"><?php echo $result->hash ?></pre> | ||
</td> | ||
<td> | ||
<strong><?php echo $system->calculate($serverSeed, $clientSeed) ?></strong> | ||
<strong><?php echo $result->value ?></strong> | ||
</td> | ||
</tr> | ||
<?php endfor; ?> | ||
<?php endforeach; ?> | ||
</table> | ||
</div> | ||
|
||
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4739670084306482" crossorigin="anonymous"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-clover" target="clover.xml"/> | ||
<log type="junit" target="junit-logfile.xml"/> | ||
</logging> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="clover.xml"/> | ||
</report> | ||
</coverage> | ||
<logging> | ||
<junit outputFile="junit-logfile.xml"/> | ||
</logging> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
Oops, something went wrong.
0211a35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
provably-fair – ./
provably-fair.vercel.app
provably-fair-rogervila.vercel.app
provably-fair-git-master-rogervila.vercel.app