# Use Crypto Utilities
You can work with the Private Key, Public Key, or Address methods.
# Private Key
You can create a private key from:
# Create Private Key from Seed Phrase
package main
// Required imports.
import (
"bytes"
"encoding/binary"
"fmt"
"github.com/wavesplatform/gowaves/pkg/crypto"
)
func main() {
// Paste your seed phrase.
seedPhrase := "PASTE YOUR SEED PHRASE"
accountNumber := uint32(0)
// Concatenate your account number and seed phrase.
accountNumConcatSeedPhrase := bytes.Join([][]byte{
binary.BigEndian.AppendUint32(nil, accountNumber),
[]byte(seedPhrase),
}, nil)
// Securely hash the seed.
accountSeed, err := crypto.SecureHash(accountNumConcatSeedPhrase)
if err != nil {
panic(err)
}
// Generate the private key the hashed seed.
senderPrivateKey, _, err := crypto.GenerateKeyPair(accountSeed.Bytes())
if err != nil {
panic(err)
}
// Print only the private key
fmt.Println("Sender's Private Key:", senderPrivateKey.String())
}
# Create Private Key from Randomly Generated Seed Bytes
package main
// Required imports.
import (
"fmt"
"github.com/tyler-smith/go-bip39"
"github.com/wavesplatform/gowaves/pkg/crypto"
)
func main() {
// Create random entropy bytes.
entropy, err := bip39.NewEntropy(160)
if err != nil {
panic(err)
}
// Generate the seed phrase from the bytes.
seedPhrase, err := bip39.NewMnemonic(entropy)
if err != nil {
panic(err)
}
// Create the private key from the seed.
senderPrivateKey := crypto.GenerateSecretKey([]byte(seedPhrase))
// Print the private key.
fmt.Println("Sender's Private Key:", senderPrivateKey.String())
}
# Create Private Key from Bytes
package main
// Required imports.
import (
"fmt"
"github.com/tyler-smith/go-bip39"
"github.com/wavesplatform/gowaves/pkg/crypto"
)
func main() {
// Create an array of bytes.
seedBytes := []byte{
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0,
0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00,
}
// Generate the seed phrase from the bytes.
seedPhrase, err := bip39.NewMnemonic(seedBytes)
if err != nil {
panic(err)
}
// Create the private key from the seed.
senderPrivateKey := crypto.GenerateSecretKey([]byte(seedPhrase))
// Print the private key.
fmt.Println("Sender's Private Key:", senderPrivateKey.String())
}
# 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. senderPublicKey := crypto.GeneratePublicKey(senderPrivateKey) // Print the pubic key. fmt.Println("Sender's Public Key:", senderPublicKey.String())
# Address
You can create an address from a public key:
Place the following code after the public key generation:
NOTE: Ensure importing the
"github.com/wavesplatform/gowaves/pkg/proto"
dependency in theimport {}
block./* Define the network of your wallet: - Use `proto.MainNetScheme` for Mainnet. - Use `proto.TestNetScheme` for Testnet. - Use `proto.StageNetScheme` for StageNet. */ const = { network = proto.MainNetScheme } // Derive the account address from the public key. senderAddress, err := proto.NewAddressFromPublicKey(network, senderPublicKey) if err != nil { log.Fatalf(err) } // Print the sender address. fmt.Println("Sender's address:", senderAddress.String())