upgrade to phpseclib3

This commit is contained in:
Developer Team - emroc GmbH 2022-04-28 15:42:30 +00:00
parent 1b73688a8e
commit 6cfcc24bb5
9 changed files with 22 additions and 40 deletions

View File

@ -13,7 +13,7 @@
"guzzlehttp/guzzle": "^6.3|^7.0",
"PHP": "^7.2|^8.0",
"kornrunner/keccak": "~1.0",
"phpseclib/phpseclib": "~2.0.30",
"phpseclib/phpseclib": "~3.0",
"ext-mbstring": "*"
},
"require-dev": {

View File

@ -11,11 +11,12 @@
namespace Web3;
use phpseclib3\Math\BigInteger;
use RuntimeException;
use InvalidArgumentException;
use stdClass;
use kornrunner\Keccak;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
class Utils
{
@ -293,7 +294,7 @@ class Utils
*
* @param BigNumber|string $number
* @param string $unit
* @return \phpseclib\Math\BigInteger
* @return \phpseclib3\Math\BigInteger
*/
public static function toWei($number, $unit)
{
@ -319,26 +320,7 @@ class Utils
}
$whole = $whole->multiply($bnt);
// There is no pow function in phpseclib 2.0, only can see in dev-master
// Maybe implement own biginteger in the future
// See 2.0 BigInteger: https://github.com/phpseclib/phpseclib/blob/2.0/phpseclib/Math/BigInteger.php
// See dev-master BigInteger: https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Math/BigInteger.php#L700
// $base = (new BigNumber(10))->pow(new BigNumber($fractionLength));
// So we switch phpseclib special global param, change in the future
switch (MATH_BIGINTEGER_MODE) {
case $whole::MODE_GMP:
static $two;
$powerBase = gmp_pow(gmp_init(10), (int) $fractionLength);
break;
case $whole::MODE_BCMATH:
$powerBase = bcpow('10', (string) $fractionLength, 0);
break;
default:
$powerBase = pow(10, (int) $fractionLength);
break;
}
$base = new BigNumber($powerBase);
$base = (new BigNumber(10))->pow(new BigNumber($fractionLength));
$fraction = $fraction->multiply($bnt)->divide($base)[0];
if ($negative1 !== false) {
@ -381,7 +363,7 @@ class Utils
*
* @param BigNumber|string|int $number
* @param string $unit
* @return \phpseclib\Math\BigInteger
* @return \phpseclib3\Math\BigInteger
*/
public static function fromWei($number, $unit)
{
@ -484,7 +466,7 @@ class Utils
* Change number or number string to bignumber.
*
* @param BigNumber|string|int $number
* @return array|\phpseclib\Math\BigInteger
* @return array|\phpseclib3\Math\BigInteger
*/
public static function toBn($number)
{
@ -545,4 +527,4 @@ class Utils
}
return $bn;
}
}
}

View File

@ -3,7 +3,7 @@
namespace Test\Unit;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
use Web3\Formatters\BigNumberFormatter;
class BigNumberFormatterTest extends TestCase
@ -39,4 +39,4 @@ class BigNumberFormatterTest extends TestCase
$this->assertEquals($bigNumber->toString(), '1');
$this->assertTrue($bigNumber instanceof BigNumber);
}
}
}

View File

@ -10,7 +10,7 @@ use Web3\Contract;
use Web3\Utils;
use Web3\Contracts\Ethabi;
use Web3\Formatters\IntegerFormatter;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
class ContractTest extends TestCase
{
@ -1514,4 +1514,4 @@ class ContractTest extends TestCase
}
});
}
}
}

View File

@ -5,7 +5,7 @@ namespace Test\Unit;
use RuntimeException;
use InvalidArgumentException;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
class EthApiTest extends TestCase
{
@ -822,4 +822,4 @@ class EthApiTest extends TestCase
$eth->protocolVersion();
}
}
}

View File

@ -4,7 +4,7 @@ namespace Test\Unit;
use RuntimeException;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
class EthBatchTest extends TestCase
{
@ -48,4 +48,4 @@ class EthBatchTest extends TestCase
$this->assertTrue($data[1] !== null);
});
}
}
}

View File

@ -5,7 +5,7 @@ namespace Test\Unit;
use RuntimeException;
use InvalidArgumentException;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
class NetApiTest extends TestCase
{
@ -111,4 +111,4 @@ class NetApiTest extends TestCase
$net->version();
}
}
}

View File

@ -4,7 +4,7 @@ namespace Test\Unit;
use RuntimeException;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
class NetBatchTest extends TestCase
{
@ -50,4 +50,4 @@ class NetBatchTest extends TestCase
$this->assertTrue($data[2] instanceof BigNumber);
});
}
}
}

View File

@ -5,7 +5,7 @@ namespace Test\Unit;
use InvalidArgumentException;
use stdClass;
use Test\TestCase;
use phpseclib\Math\BigInteger as BigNumber;
use phpseclib3\Math\BigInteger as BigNumber;
use Web3\Utils;
use Web3\Contract;
@ -649,4 +649,4 @@ class UtilsTest extends TestCase
$this->expectException(InvalidArgumentException::class);
$bn = Utils::toBn(new stdClass);
}
}
}