# Use Crypto Utilities
You can work with the Private Key, Public Key, and Address methods.
# Private Key
NOTE: The SDK makes private keys clamped—bit-adjusted to ensure validity and resistance to small subgroup attacks.
You can create a private key from:
- Seed phrase.
- Randomly generated seed phrase.
- Randomly generated seed phrase with nonce 2.
- Seed bytes.
- Randomly generated seed bytes.
- Bytes.
- Encoded string.
# Create Private Key from Seed Phrase
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Specify your seed phrase.
$seed = 'PASTE YOUR SEED PHRASE';
// Get the private key from the given seed phrase.
$account = PrivateKey::fromSeed($seed);
$privateKey = $account->toString();
// Print the results.
echo "Seed Phrase: $privateKey\n";
echo "Sender's Private Key: $seed\n";
# Generate Random Seed Phrase and Private Key
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Util\Functions;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Generation of a random seed phrase.
$seed = Functions::getRandomSeedPhrase();
// Get the private key from the given seed phrase.
$account = PrivateKey::fromSeed($seed);
$privateKey = $account->toString();
// Print the results.
echo "Seed Phrase: $seed\n";
echo "Sender's Private Key: $privateKey\n";
# Generate Random Seed Phrase with Nonce 2
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Util\Functions;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Generation of a random seed phrase.
$seed = Functions::getRandomSeedPhrase();
// Get the private key from the given seed phrase, using nonce = 2.
$account = PrivateKey::fromSeed($seed, 2);
$privateKey = $account->toString();
// Print the results.
echo "Seed Phrase: $seed\n";
echo "Sender's Private Key (nonce 2): $privateKey\n";
# Create Private Key from Seed Bytes
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Creation of a byte array.
$seedBytes = pack('C*', 1, 2, 3, 4, 5, 6, 7); // Array example.
// Creation of the private key from the seed bytes.
$account = PrivateKey::fromSeed($seedBytes);
$privateKey = $account->toString();
// Print the results.
echo "Sender's Private Key: $privateKey\n";
# Create Private Key from Randomly Generated Seed Bytes
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Util\Functions;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Generation of random seed bytes that are 32 bytes long.
$randomSeedBytes = random_bytes(32);
// Creation of the private key from the randomly generated seed bytes.
$account = PrivateKey::fromSeed($randomSeedBytes);
$privateKey = $account->toString();
// Print the results.
echo "Sender's Private Key: $privateKey\n";
# Create Private Key from Bytes
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Creation of a byte array.
$bytes = pack('c*', 56, -3, 37, 64, 2, 38, 78, 37, -98, -45, -23, 117, 14, 88, 20, 42, -9, 21, 55, 87, 117, -8, -81, 77, 77, -99, -87, -23, 7, 116, -99, -20); // Array example.
// Creation of the private key from the byte array.
$account = PrivateKey::fromSeed($bytes);
$privateKey = $account->toString();
// Print the results.
echo "Sender's Private Key: $privateKey\n";
# Create Private Key from an Encoded String
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Necessary imports.
use Waves\Account\PrivateKey;
use Waves\Util\Functions;
use Waves\Model\ChainId;
use Waves\Model\WavesConfig;
// Hide deprecated warnings temporarily.
error_reporting(E_ALL & ~E_DEPRECATED);
/*
* Specify the network chain ID:
* - Mainnet: `ChainId::MAINNET()`
* - Testnet: `ChainId::TESTNET()`
* - Stagenet: `ChainId::STAGENET()`
*/
WavesConfig::chainId(ChainId::TESTNET());
// Creation of a Base58 string.
$base58String = "A5u9Ugt2nG1rWfLkL7pzZrtkP8LgF2rD3g1XBjsF8ZzV"; // Value example.
// Decode the Base58 string to raw bytes.
$decodedBytes = Functions::base58Decode($base58String);
// Creation of the private key from the decoded bytes.
$account = PrivateKey::fromSeed($decodedBytes);
$privateKey = $account->toString();
// Print the output.
echo "Sender's Private Key: $privateKey\n";
# Public Key
You can create a public key from a private key:
- Generate the private key.
- Place the following code after the private key generation:
// Create the public key from the private key. $publicKey = $account->publicKey()->toString(); // Print the results. echo "Sender's Public Key: $publicKey\n";
# Address
You can create an address from a public key:
Place the following code after the public key generation:
// Create the address from the public key. $address = $account->publicKey()->address()->toString(); // Print the results. echo "Sender's Address: $address\n";