Skip to content

Commit

Permalink
use implode() instead of join() + version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Atif Nazir committed Jul 4, 2020
1 parent 2e8dc8e commit 2f443b2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Block.io PHP
===========

**Current Release**: 1.3.2
**Current Release**: 1.3.3

**07/03/20**: Use implode() instead of join() to remove PHP7.4 warning.
**07/01/20**: Use low R signatures by default.
**06/02/20**: Replace deprecated array_key_exists. Tested for PHP7.2, PHP7.3, PHP7.4. Support for earlier (EOL) versions of PHP is not guaranteed.
**05/10/19**: Minor updates. Tested for PHP7.x.
Expand Down
6 changes: 3 additions & 3 deletions examples/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
*/

<?php
require_once '/path/to/block_io.php';
require_once '../lib/block_io.php';

/* Replace the $apiKey with the API Key from your Block.io Wallet. A different API key exists for Dogecoin, Dogecoin Testnet, Litecoin, Litecoin Testnet, etc. */
$apiKey = 'YOUR DOGECOIN TESTNET API KEY';
$pin = 'SECRET PIN';
$apiKey = getenv("API_KEY");
$pin = getenv("PIN");
$version = 2; // the API version

$block_io = new BlockIo($apiKey, $pin, $version);
Expand Down
6 changes: 3 additions & 3 deletions examples/dtrust.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/

<?php
require_once '/path/to/block_io.php';
require_once '../lib/block_io.php';

/* Replace the $apiKey with the API Key from your Block.io Wallet. A different API key exists for Dogecoin, Dogecoin Testnet, Litecoin, Litecoin Testnet, etc. */
$apiKey = 'DogecoinTestnetAPIKey';
$pin = 'SecretPin';
$apiKey = getenv("API_KEY");
$pin = getenv("PIN");
$version = 2; // the API version

$block_io = new BlockIo($apiKey, $pin, $version);
Expand Down
6 changes: 3 additions & 3 deletions examples/keys.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/

<?php
require_once 'path/to/block_io.php';
require_once '../lib/block_io.php';

/* Replace the $apiKey with the API Key from your Block.io Wallet. */
$apiKey = 'YOUR API KEY';
$pin = 'PIN - NOT NEEDED';
$apiKey = getenv("API_KEY");
$pin = "";
$version = 2; // the API version

$block_io = new BlockIo($apiKey, $pin, $version);
Expand Down
10 changes: 5 additions & 5 deletions examples/sweeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
*/

<?php
require_once '/path/to/block_io.php';
require_once '../lib/block_io.php';

$apiKey = 'YOUR API KEY';
$apiKey = getenv("API_KEY");
$pin = 'NONE'; // Not Needed
$version = 2; // the API version

$block_io = new BlockIo($apiKey, $pin, $version);

$from_address = 'FROM ADDRESS';
$to_address = 'TO ADDRESS';
$private_key = 'PRIVATE KEY OF FROM_ADDRESS IN WALLET IMPORT FORMAT';
$from_address = getenv("FROM_ADDRESS");
$to_address = getenv("TO_ADDRESS");
$private_key = getenv("PRIVATE_KEY"); // Wallet Import Format (WIF)

// let's sweep the coins from the From Address to the To Address

Expand Down
13 changes: 9 additions & 4 deletions lib/block_io.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,9 @@ public function deterministicGenerateK($message, $key, $extra_entropy)
$v = "0101010101010101010101010101010101010101010101010101010101010101";

$e = "";
if ($extra_entropy > 0) {
$e = join(array_reverse(str_split(sprintf("%064s", dechex($extra_entropy)),2)),"");
};

if (!is_null($extra_entropy)) { $e = $extra_entropy; }

// step D
$k = hash_hmac('sha256', hex2bin($v) . hex2bin("00") . hex2bin($key) . hex2bin($hash) . hex2bin($e), hex2bin($k));

Expand Down Expand Up @@ -1230,6 +1229,7 @@ public function getSignatureHashPoints($hash, $nonce = null)
$n = $this->n;
$k = $this->k;
$counter = 0;
$extra_entropy = "";
$nonce_not_provided = is_null($nonce);

if(empty($k))
Expand All @@ -1241,7 +1241,12 @@ public function getSignatureHashPoints($hash, $nonce = null)
if($nonce_not_provided)
{
// use a deterministic nonce
$nonce = $this->deterministicGenerateK($hash, $this->k, $counter);

if ($counter > 0) {
$extra_entropy = implode(array_reverse(str_split(sprintf("%064s", dechex($counter)),2)));
}

$nonce = $this->deterministicGenerateK($hash, $this->k, $extra_entropy);
$counter = $counter + 1;
}

Expand Down

0 comments on commit 2f443b2

Please sign in to comment.