Skip to content

Commit

Permalink
feat[php]: (#72) confirm passphrases
Browse files Browse the repository at this point in the history
  • Loading branch information
sk33z3r committed Jun 23, 2022
1 parent c67aa3f commit a873a59
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
26 changes: 16 additions & 10 deletions php/mint-config/1.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<div data-tooltip="Minter Address: The L2 wallet address or ENS or Account ID of the minter"><input required type="text" class="form wide" id="minter" name="minter" placeholder="Minter Address [Wallet Address, ENS, or Account ID]" /></div>
<div data-tooltip="Minter Private Key: The Loopring private key of the minter [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="private_key" name="private_key" placeholder="Minter Private Key" /></div>
<div data-tooltip="Config Passphrase: A passphrase to encrypt your private key with [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="secret" name="secret" placeholder="Config Passphrase" /></div>
<div data-tooltip="Confirm Passphrase: Re-type the passphrase you previously entered [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="pass_confirm" name="pass_confirm" placeholder="Confirm Passphrase" onpaste="return false;" /></div>
<div data-tooltip="Default Royalty Percentage: Percentage of the price of a sale that will go to the Royalty Address (LooPyGen generated collections override this percentage)">
<input required type="number" class="form wide" id="royalty_percentage" min="0" max="10" name="royalty_percentage" placeholder="Default Royalty Percentage: 0-10" />
</div>
Expand All @@ -41,22 +42,27 @@
$minter = $_POST['minter'];
$private_key = $_POST['private_key'];
$secret = base64_encode($_POST['secret']);
$pass_confirm = base64_encode($_POST['pass_confirm']);
$royalty_percentage = $_POST['royalty_percentage'];
$nft_type = $_POST['nft_type'];
$fee_token = $_POST['fee_token'];

$config_data = array("minter"=>$minter,
"private_key"=>$private_key,
"royalty_percentage"=>(int)$royalty_percentage,
"nft_type"=>(int)$nft_type,
"fee_token"=>(int)$fee_token);
if ($secret !== $pass_confirm) {
$code = "100";
} else {
$config_data = array("minter"=>$minter,
"private_key"=>$private_key,
"royalty_percentage"=>(int)$royalty_percentage,
"nft_type"=>(int)$nft_type,
"fee_token"=>(int)$fee_token);

$config_json = json_encode($config_data, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
file_put_contents($mint_config, $config_json);
$config_json = json_encode($config_data, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
file_put_contents($mint_config, $config_json);

# encrypt the config file
$command = "encrypt --mint --secret ${secret}";
exec($command, $output, $code);
# encrypt the config file
$command = "encrypt --mint --secret ${secret}";
exec($command, $output, $code);
}

Redirect("/mint-config/finish?result=${code}", false);
}
Expand Down
11 changes: 5 additions & 6 deletions php/mint-config/finish.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<?php

if (!file_exists($mint_config) or !isset($_GET['result'])) {
BrowserRedirect('/mint-config/1');
}

if ($_GET['result'] === "0") { ?>
<h3 class="success">Configuration Successfully Encrypted</h3>
<div id="guide">
Expand All @@ -15,11 +11,14 @@
<div class="nav"><a href="/">BACK TO HOME</a></div>
<div class="nav"><a href="/mint-config/1">REMAKE CONFIG</a></div>
<?php } else {
unlink($mint_config); ?>
if (file_exists($mint_config)) { unlink($mint_config); } ?>
<h3 class="error">Configuration Not Encrypted</h3>
<?php if ($_GET['result'] === "100") { ?>
<h3 class="warning">Your passphrases did not match.</h3>
<?php } ?>
<div id="guide">
<section>
<p>Your configuration was not encrypted and has been removed from the system.</p>
<p>Your configuration was not stored.</p>
<p>Please try again.</p>
</section>
</div>
Expand Down
28 changes: 17 additions & 11 deletions php/transfer-config/1.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<div data-tooltip="Loopring L2 Private Key: The Loopring private key of the from address [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="private_key" name="private_key" placeholder="Loopring L2 Private Key (from step 01)" /></div>
<div data-tooltip="L1 Private Key: The private key of the from address [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="private_key_mm" name="private_key_mm" placeholder="L1 Private Key (from step 02)" /></div>
<div data-tooltip="Config Passphrase: A passphrase to encrypt your private key with [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="secret" name="secret" placeholder="Config Passphrase" /></div>
<div data-tooltip="Confirm Passphrase: Re-type the passphrase you previously entered [DO NOT SHARE THIS INFO WITH ANYONE]"><input required type="password" class="form wide" id="pass_confirm" name="pass_confirm" placeholder="Confirm Passphrase" onpaste="return false;" /></div>
<div class="row">
<div data-tooltip="Fee Token: The token to be used to pay protocol fees">
<label for="fee_token" class="med">
Expand All @@ -41,23 +42,28 @@
$sender = $_POST['sender'];
$private_key = $_POST['private_key'];
$secret = base64_encode($_POST['secret']);
$pass_confirm = $_POST['pass_confirm'];
$private_key_mm = $_POST['private_key_mm'];
$fee_token = $_POST['fee_token'];

if(!str_starts_with($private_key_mm, '0x'))
$private_key_mm = '0x' . $private_key_mm;
if ($secret !== $pass_confirm) {
$code = "100";
} else {
if(!str_starts_with($private_key_mm, '0x'))
$private_key_mm = '0x' . $private_key_mm;

$config_data = array("sender"=>$sender,
"private_key"=>$private_key,
"private_key_mm"=>$private_key_mm,
"fee_token"=>(int)$fee_token);
$config_data = array("sender"=>$sender,
"private_key"=>$private_key,
"private_key_mm"=>$private_key_mm,
"fee_token"=>(int)$fee_token);

$config_json = json_encode($config_data, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
file_put_contents($transfer_config, $config_json);
$config_json = json_encode($config_data, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
file_put_contents($transfer_config, $config_json);

# encrypt the config file
$command = "encrypt --transfer --secret ${secret}";
exec($command, $output, $code);
# encrypt the config file
$command = "encrypt --transfer --secret ${secret}";
exec($command, $output, $code);
}

Redirect("/transfer-config/finish?result=${code}", false);
}
Expand Down
7 changes: 5 additions & 2 deletions php/transfer-config/finish.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
<div class="nav"><a href="/">BACK TO HOME</a></div>
<div class="nav"><a href="/transfer-config/1">REMAKE CONFIG</a></div>
<?php } else {
unlink($mint_config); ?>
if (file_exists($transfer_config)) { unlink($transfer_config); ?>
<h3 class="error">Configuration Not Encrypted</h3>
<?php if ($_GET['result'] === "100") { ?>
<h3 class="warning">Your passphrases did not match.</h3>
<?php } ?>
<div id="guide">
<section>
<p>Your configuration was not encrypted and has been removed from the system.</p>
<p>Your configuration was not stored.</p>
<p>Please try again.</p>
</section>
</div>
Expand Down

0 comments on commit a873a59

Please sign in to comment.