waves_logo Docs
  • Overview
    Overview
  • How-to Guides
    • Reading Blockchain Data
      Reading Blockchain Data
    • Creating & Broadcasting Transactions
      Creating & Broadcasting Transactions
    • Tokenization
      Tokenization
    • Airdrop
      Airdrop
    • Payments
      Payments
    • Exchange Tokens
      Exchange Tokens
    • Simple Voting
      Simple Voting
    • List as argument
      List as argument
    How-to Guides
  • Waves Smart Contracts
    Waves Smart Contracts
  • dApp
    • Creating & Launching dApp
      Creating & Launching dApp
    dApp
  • Smart Account
    • Creating smart account
      Creating smart account
    • Creating and deploying a script manually
      Creating and deploying a script manually
    • Video tutorials
      • Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
        Introduction to the Waves blockchain, Waves Smart Accounts and Waves Smart Assets
      • Waves Smart Account with multisignature
        Waves Smart Account with multisignature
      • Waves Smart Account with escrow service
        Waves Smart Account with escrow service
      • Creating multisignature account via Waves IDE tools
        Creating multisignature account via Waves IDE tools
      • Creating multisignature account via Waves Client
        Creating multisignature account via Waves Client
      • Waves console explained
        Waves console explained
      Video tutorials
    Smart Account
  • Smart Asset
    Smart Asset
  • Developer Tools
    • Waves IDE
      Waves IDE
    • Visual Studio Code Extension
      Visual Studio Code Extension
    • Surfboard
      Surfboard
    • Ride REPL
      Ride REPL
    Developer Tools
  • Signer ◆
    Signer ◆
  • Waves API
    • Data Service API
      Data Service API
    • Node REST API
      Node REST API
    • Node gRPC Server
      Node gRPC Server
    • Blockchain Updates
      Blockchain Updates
    Waves API
  • Client Libraries
    • Waves C#
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      Waves C#
    • Gowaves
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      Gowaves
    • WavesJ
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      WavesJ
    • Ts-lib-crypto & waves-transactions
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      Ts-lib-crypto & waves-transactions
    • Waves-PHP
      • Install SDK
        Install SDK
      Waves-PHP
    • PyWaves-CE
      • Install SDK
        Install SDK
      • Run Code Sample
        • Send Transactions
          Send Transactions
        • Use Crypto Utilities
          Use Crypto Utilities
        • Interact With Node
          Interact With Node
        • Set Up Smart Contracts
          Set Up Smart Contracts
        Run Code Sample
      PyWaves-CE
    • Waves-rust
      • Install SDK
        Install SDK
      Waves-rust
    Client Libraries
      • English
      • Русский
      On this page
        • Private Key
        • Public Key
        • Address
      waves_logo Docs

          # Use Crypto Utilities

          You can work with the Private Key, Public Key, and Address methods.

          # Private Key

          You can create a private key from:

          • Seed phrase.
          • Randomly generated seed phrase.
          • Seed bytes.
          • Randomly generated seed bytes.
          • Bytes.
          • Encoded string.

          # Create Private Key from Seed Phrase

          // Necessary import.
          import { keyPair } from '@waves/ts-lib-crypto';
          
          // Specify your account's seed phrase.
          const seedPhrase: string = 'PASTE A SEED PHRASE';
          
          // Create the key pair, including the private and public keys.
          const accountKeyPair = keyPair(seedPhrase);
          
          // Print the private key.
          console.log("Sender's Private Key:", accountKeyPair.privateKey);
          

          # Generate Random Seed Phrase and Private Key

          // Necessary import.
          import { keyPair, randomSeed } from '@waves/ts-lib-crypto';
          
          // Generate a random seed phrase.
          const seedPhrase: string = randomSeed();
          
          // Create the key pair, including the private and public keys.
          const accountKeyPair = keyPair(seedPhrase);
          
          // Print the private key.
          console.log("Seed Phrase:", seedPhrase);
          console.log("Sender's Private Key:", accountKeyPair.privateKey);
          

          # Create Private Key from Seed Bytes

          // Necessary import.
          import { keyPair } from '@waves/ts-lib-crypto';
          
          // Create a byte array.
          const seedBytes: Uint8Array = Uint8Array.from(
            [1, 2, 3, 4, 5, 6, 7] // Array example.
          );
          
          // Convert the byte array to a string seed.
          const seedString: string = new TextDecoder().decode(seedBytes);
          
          // Create the key pair, including the private and public keys.
          const accountKeyPair = keyPair(seedString);
          
          // Print the private key.
          console.log("Sender's Private Key:", accountKeyPair.privateKey);
          

          # Create Private Key from Randomly Generated Seed Bytes

          // Necessary import.
          import { randomBytes, blake2b, keyPair } from '@waves/ts-lib-crypto';
          
          // Generate random seed bytes. 32 bytes by default.
          const randomSeedBytes: Uint8Array = randomBytes(32);
          
          // Derive the private key from the random seed bytes.
          const hashedSeed: Uint8Array = blake2b(randomSeedBytes);
          
          // Create the key pair from the hashed seed.
          const accountKeyPair = keyPair(hashedSeed);
          
          // Print the private key.
          console.log("Sender's Private Key:", accountKeyPair.privateKey);
          

          # Create Private Key from Bytes

          // Necessary import.
          import { keyPair } from '@waves/ts-lib-crypto';
          
          // Define the private key bytes.
          const privateKeyBytes: Uint8Array = Uint8Array.from([
            56, 253, 37, 64, 2, 38, 78, 37, 158, 211, 233, 117, 14, 88, 20, 42,
            247, 21, 55, 87, 117, 248, 175, 77, 77, 157, 169, 233, 7, 116, 157, 236
          ]); // Array example.
          
          // Create the key pair, including the private and public keys.
          const accountKeyPair = keyPair(privateKeyBytes);
          
          // Print the private key.
          console.log("Sender's Private Key:", accountKeyPair.privateKey);
          

          # Create Private Key from an Encoded String

          // Necessary import.
          import { base58Decode, keyPair } from '@waves/ts-lib-crypto';
          
          // Define the Base58-encoded private key string.
          const base58String: string = 'A5u9Ugt2nG1rWfLkL7pzZrtkP8LgF2rD3g1XBjsF8ZfV'; // Value example.
          
          // Decode the Base58 string to raw bytes.
          const privateKeyBytes: Uint8Array = base58Decode(base58String);
          
          // Create the key pair, including the private and public keys.
          const accountKeyPair = keyPair(privateKeyBytes);
          
          // Print the private key.
          console.log("Sender's Private Key:", accountKeyPair.privateKey);
          

          # Public Key

          You can create a public key from the seed's key pair:

          1. Generate the private key.
          2. Place the following code after the private key generation:
            // Generate the public key from the existing key pair.
            const publicKey: string = accountKeyPair.publicKey;
            
            // Print the public key.
            console.log("Sender's Public Key:", publicKey);
            

          # Address

          You can create an address from a public key:

          1. Generate the public key.

          2. Place the following code after the public key generation:

            NOTE: Ensure importing the following dependencies: import { address } from '@waves/ts-lib-crypto';

            // Necessary import.
            import { address } from '@waves/ts-lib-crypto';
            
            /*
             * Specify the network chain ID:
             * - 'W' for Mainnet.
             * - 'T' for Testnet.
             */
            const chainId: string = 'T'
            
            // Generate the address from the given public key and chain ID.
            const senderAddress = address(publicKey, chainId);
            
            // Print the address.
            console.log("Sender's Address:", senderAddress);
            
          Send Transactions
          Interact With Node
          Send Transactions
          Interact With Node