Skip to content

Commit 48ad0e3

Browse files
authored
Merge pull request #5 from wavesplatform/dev
fix warnings
2 parents 6f150f4 + b39fe8a commit 48ad0e3

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/Account/Address.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ static function fromPublicKey( PublicKey $publicKey, ChainId $chainId = null ):
3838
$address = new Address;
3939
$wk = new \deemru\WavesKit( ( isset( $chainId ) ? $chainId : WavesConfig::chainId() )->asString() );
4040
$wk->setPublicKey( $publicKey->bytes(), true );
41-
$address->address = Base58String::fromBytes( $wk->getAddress( true ) );
41+
$bytes = $wk->getAddress( true );
42+
if( !is_string( $bytes ) || strlen( $bytes ) !== Address::BYTE_LENGTH )
43+
throw new Exception( __FUNCTION__ . ' bad key', ExceptionCode::BAD_KEY );
44+
$address->address = Base58String::fromBytes( $bytes );
4245
return $address;
4346
}
4447

src/Account/PrivateKey.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Waves\Account;
44

5+
use Exception;
56
use Waves\Common\Base58String;
7+
use Waves\Common\ExceptionCode;
68

79
class PrivateKey
810
{
@@ -16,7 +18,10 @@ private function __construct(){}
1618
static function fromSeed( string $seed, int $nonce = 0 ): PrivateKey
1719
{
1820
$privateKey = new PrivateKey;
19-
$privateKey->key = Base58String::fromBytes( ( new \deemru\WavesKit )->getPrivateKey( true, $seed, pack( 'N', $nonce ) ) );
21+
$bytes = ( new \deemru\WavesKit )->getPrivateKey( true, $seed, pack( 'N', $nonce ) );
22+
if( !is_string( $bytes ) || strlen( $bytes ) !== PrivateKey::LENGTH )
23+
throw new Exception( __FUNCTION__ . ' bad key', ExceptionCode::BAD_KEY );
24+
$privateKey->key = Base58String::fromBytes( $bytes );
2025
return $privateKey;
2126
}
2227

src/Account/PublicKey.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Waves\Account;
44

5+
use Exception;
56
use Waves\Common\Base58String;
7+
use Waves\Common\ExceptionCode;
68
use Waves\Model\ChainId;
79

810
class PublicKey
@@ -34,7 +36,10 @@ static function fromPrivateKey( PrivateKey $key ): PublicKey
3436
$publicKey = new PublicKey;
3537
$wk = new \deemru\WavesKit;
3638
$wk->setPrivateKey( $key->bytes(), true );
37-
$publicKey->key = Base58String::fromBytes( $wk->getPublicKey( true ) );
39+
$bytes = $wk->getPublicKey( true );
40+
if( !is_string( $bytes ) || strlen( $bytes ) !== PublicKey::BYTES_LENGTH )
41+
throw new Exception( __FUNCTION__ . ' bad key', ExceptionCode::BAD_KEY );
42+
$publicKey->key = Base58String::fromBytes( $bytes );
3843
return $publicKey;
3944
}
4045

src/Common/ExceptionCode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ class ExceptionCode
2323
const BAD_CHAINID = ExceptionCode::BASE | 16;
2424
const TIMEOUT = ExceptionCode::BASE | 17;
2525
const UNEXPECTED = ExceptionCode::BASE | 18;
26+
const BAD_KEY = ExceptionCode::BASE | 19;
2627
}

0 commit comments

Comments
 (0)