Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
com.wavesplatform:waves-crypto
Advanced tools
Tools to work with cryptographic primitives used in the Waves blockchain
Here's a complete example of how to generate a new Waves account:
import com.wavesplatform.crypto.Crypto;
import com.wavesplatform.crypto.base.Base58;
public class WavesAccount {
public static final byte MAINNET = 'W';
public static final byte TESTNET = 'T';
public static void main() {
String seedPhrase = Crypto.getRandomSeedPhrase();
byte[] accountSeed = Crypto.getAccountSeed(seedPhrase);
byte[] privateKey = Crypto.getPrivateKey(accountSeed);
byte[] publicKey = Crypto.getPublicKey(privateKey);
byte[] publicKeyHash = Crypto.getPublicKeyHash(publicKey);
byte[] mainnetAddress = Crypto.getAddress(MAINNET, publicKeyHash);
byte[] testnetAddress = Crypto.getAddress(TESTNET, publicKeyHash);
System.out.println("# Account details");
System.out.println("Seed phrase:\t" + seedPhrase);
System.out.println("Private key:\t" + Base58.encode(privateKey));
System.out.println("Public key:\t" + Base58.encode(publicKey));
System.out.println("Mainnet address:\t" + Base58.encode(mainnetAddress));
System.out.println("Testnet address:\t" + Base58.encode(testnetAddress));
}
}
Please read about Waves cryptography on the official documentation page.
Seed phrase also means Recovery phrase.
This is usually a sequence of several words, but technically it's just an array of arbitrary bytes.
String seedPhraseOf15WordsByDefault = Crypto.getRandomSeedPhrase();
String seedPhraseOfCustomWordsNumber = Crypto.getRandomSeedPhrase(15);
byte[] seedPhraseOf255BytesByDefault = Crypto.getRandomSeedBytes();
byte[] seedPhraseOfCustomNumberOfBytes = Crypto.getRandomSeedBytes(255);
Account seed is a hash of seed phrase and nonce.
Nonce allows creating multiple addresses from a single seed phrase.
The default nonce is 0.
byte[] accountSeedWithNonce0ByDefault = Crypto.getAccountSeed(seedPhrase);
byte[] accountSeedWithSpecificNonce = Crypto.getAccountSeed(seedPhrase, 1);
From account seed, you can calculate a pair of private and public keys.
byte[] privateKey = Crypto.getPrivateKey(accountSeed);
byte[] publicKey = Crypto.getPublicKey(privateKey);
Account address contains hash of public key, so you need to calculate that hash first.
byte chainId = 'T';
byte[] publicKeyHash = Crypto.getPublicKeyHash(publicKey);
byte[] address = Crypto.getAddress(chainId, publicKeyHash);
If you have generated an account, you can sign messages with private key and validate resulting signature with public key.
byte[] message = new Random().nextBytes(new byte[32]);
byte[] proof = Crypto.sign(privateKey, message);
boolean isValid = Crypto.isProofValid(publicKey, message, proof);
In the Waves blockchain, all binary data is presented in Base Encodings:
byte[] message = new Random().nextBytes(new byte[32]);
String base58Encoded = Base58.encode(message);
String base64Encoded = Base64.encode(message);
String base16Encoded = Base16.encode(message);
byte[] base58Decoded = Base58.decode(base58Encoded);
byte[] base64Decoded = Base64.decode(base64Encoded);
byte[] base16Decoded = Base16.decode(base16Encoded);
All decoded results are equal to the initial message.
There are supported hashing algorithms:
byte[] message = new Random().nextBytes(new byte[32]);
byte[] shaHash = Hash.sha256(message);
byte[] blakeHash = Hash.blake(message);
byte[] keccakHash = Hash.keccak(message);
// the same as blake hashing
byte[] fastHash = Hash.fastHash(message);
// sequential hashing with blake and then keccak
byte[] secureHash = Hash.secureHash(message);
TBD... see TestMerkleTree for usage examples.
TBD... see TestRsa for usage examples.
FAQs
Tools to work with cryptographic primitives used in the Waves blockchain
We found that com.wavesplatform:waves-crypto demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.