Skip to content

Commit

Permalink
V3 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogervila authored Nov 17, 2022
1 parent fe48863 commit 0211a35
Show file tree
Hide file tree
Showing 25 changed files with 319 additions and 342 deletions.
12 changes: 3 additions & 9 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ clone_folder: C:\projects\app

environment:
matrix:
- php_ver: 8.1
- php_ver: 8.0
- php_ver: 7.4
- php_ver: 7.3
- php_ver: 7.2
# - php_ver: 7.1
# - php_ver: 7.0
- php_ver: 8.1.12

cache:
- '%APPDATA%\Composer'
Expand All @@ -35,7 +29,7 @@ install:
- echo extension=php_mbstring.dll >> php.ini
- echo extension=php_sqlite3.dll >> php.ini
- echo extension=php_pdo_sqlite.dll >> php.ini
- IF NOT EXIST C:\tools\composer.phar (cd C:\tools && appveyor DownloadFile https://getcomposer.org/download/2.0.14/composer.phar)
- IF NOT EXIST C:\tools\composer.phar (cd C:\tools && appveyor DownloadFile https://getcomposer.org/download/2.4.4/composer.phar)
- php C:\tools\composer.phar --version
- cd C:\projects\app

Expand All @@ -46,4 +40,4 @@ before_test:

test_script:
- cd C:\projects\app
- vendor\bin\phpunit
- php C:\tools\composer.phar test
8 changes: 8 additions & 0 deletions .gitattributes
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
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
# Maintain dependencies for composer
- package-ecosystem: composer
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
time: "04:00"
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
php: ['8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0']
php: ['8.2', '8.1']

name: PHP ${{ matrix.php }} - ${{ matrix.os }}

Expand All @@ -31,6 +31,6 @@ jobs:
run: composer update --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
run: composer test
env:
XDEBUG_MODE: coverage
4 changes: 2 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
php: ['8.1', '8.0', '7.4', '7.3', '7.2', '7.1', '7.0']
php: ['8.2', '8.1']

name: PHP ${{ matrix.php }} - ${{ matrix.os }}

Expand All @@ -28,6 +28,6 @@ jobs:
run: composer update --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
run: composer test
env:
XDEBUG_MODE: coverage
18 changes: 0 additions & 18 deletions .php_cs

This file was deleted.

13 changes: 0 additions & 13 deletions .scrutinizer.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .styleci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
preset: psr2
preset: psr12

finder:
exclude:
Expand Down
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

22 changes: 12 additions & 10 deletions composer.json
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"
]
}
Expand Down
81 changes: 47 additions & 34 deletions index.php
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>
Expand All @@ -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">
Expand All @@ -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>
40 changes: 17 additions & 23 deletions phpunit.xml
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>
Loading

1 comment on commit 0211a35

@vercel
Copy link

@vercel vercel bot commented on 0211a35 Nov 17, 2022

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

Please sign in to comment.