Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
deemru committed Nov 27, 2023
1 parent 6f150f4 commit b39fe8a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Account/Address.php
Expand Up @@ -38,7 +38,10 @@ static function fromPublicKey( PublicKey $publicKey, ChainId $chainId = null ):
$address = new Address;
$wk = new \deemru\WavesKit( ( isset( $chainId ) ? $chainId : WavesConfig::chainId() )->asString() );
$wk->setPublicKey( $publicKey->bytes(), true );
$address->address = Base58String::fromBytes( $wk->getAddress( true ) );
$bytes = $wk->getAddress( true );
if( !is_string( $bytes ) || strlen( $bytes ) !== Address::BYTE_LENGTH )
throw new Exception( __FUNCTION__ . ' bad key', ExceptionCode::BAD_KEY );
$address->address = Base58String::fromBytes( $bytes );
return $address;
}

Expand Down
7 changes: 6 additions & 1 deletion src/Account/PrivateKey.php
Expand Up @@ -2,7 +2,9 @@

namespace Waves\Account;

use Exception;
use Waves\Common\Base58String;
use Waves\Common\ExceptionCode;

class PrivateKey
{
Expand All @@ -16,7 +18,10 @@ private function __construct(){}
static function fromSeed( string $seed, int $nonce = 0 ): PrivateKey
{
$privateKey = new PrivateKey;
$privateKey->key = Base58String::fromBytes( ( new \deemru\WavesKit )->getPrivateKey( true, $seed, pack( 'N', $nonce ) ) );
$bytes = ( new \deemru\WavesKit )->getPrivateKey( true, $seed, pack( 'N', $nonce ) );
if( !is_string( $bytes ) || strlen( $bytes ) !== PrivateKey::LENGTH )
throw new Exception( __FUNCTION__ . ' bad key', ExceptionCode::BAD_KEY );
$privateKey->key = Base58String::fromBytes( $bytes );
return $privateKey;
}

Expand Down
7 changes: 6 additions & 1 deletion src/Account/PublicKey.php
Expand Up @@ -2,7 +2,9 @@

namespace Waves\Account;

use Exception;
use Waves\Common\Base58String;
use Waves\Common\ExceptionCode;
use Waves\Model\ChainId;

class PublicKey
Expand Down Expand Up @@ -34,7 +36,10 @@ static function fromPrivateKey( PrivateKey $key ): PublicKey
$publicKey = new PublicKey;
$wk = new \deemru\WavesKit;
$wk->setPrivateKey( $key->bytes(), true );
$publicKey->key = Base58String::fromBytes( $wk->getPublicKey( true ) );
$bytes = $wk->getPublicKey( true );
if( !is_string( $bytes ) || strlen( $bytes ) !== PublicKey::BYTES_LENGTH )
throw new Exception( __FUNCTION__ . ' bad key', ExceptionCode::BAD_KEY );
$publicKey->key = Base58String::fromBytes( $bytes );
return $publicKey;
}

Expand Down
1 change: 1 addition & 0 deletions src/Common/ExceptionCode.php
Expand Up @@ -23,4 +23,5 @@ class ExceptionCode
const BAD_CHAINID = ExceptionCode::BASE | 16;
const TIMEOUT = ExceptionCode::BASE | 17;
const UNEXPECTED = ExceptionCode::BASE | 18;
const BAD_KEY = ExceptionCode::BASE | 19;
}

0 comments on commit b39fe8a

Please sign in to comment.