Class Account

java.lang.Object
com.algorand.algosdk.account.Account

public class Account
extends java.lang.Object
Create and manage secrets, and perform account-based work such as signing transactions.
  • Field Details

    • MIN_TX_FEE_UALGOS

      public static final java.math.BigInteger MIN_TX_FEE_UALGOS
  • Constructor Details

    • Account

      public Account() throws java.security.NoSuchAlgorithmException
      Account creates a new, random account.
      Throws:
      java.security.NoSuchAlgorithmException
    • Account

      public Account​(byte[] seed) throws java.security.NoSuchAlgorithmException
      Create a new account from an rfc8037 private key.
      Parameters:
      seed -
      Throws:
      java.security.NoSuchAlgorithmException
    • Account

      public Account​(java.lang.String mnemonic) throws java.security.GeneralSecurityException
      Throws:
      java.security.GeneralSecurityException
    • Account

      public Account​(java.security.KeyPair pkPair)
    • Account

      public Account​(java.security.PrivateKey pk) throws java.security.NoSuchAlgorithmException
      Throws:
      java.security.NoSuchAlgorithmException
  • Method Details

    • getClearTextPublicKey

      public byte[] getClearTextPublicKey()
      Convenience method for getting the underlying public key for raw operations.
      Returns:
      the public key as length 32 byte array.
    • getEd25519PublicKey

      public Ed25519PublicKey getEd25519PublicKey()
    • getAddress

      public Address getAddress()
      Convenience method for getting underlying address.
      Returns:
      account address
    • toMnemonic

      public java.lang.String toMnemonic()
      Converts the 32 byte private key to a 25 word mnemonic, including a checksum. Refer to the mnemonic package for additional documentation.
      Returns:
      string a 25 word mnemonic
    • signTransaction

      public SignedTransaction signTransaction​(Transaction tx) throws java.security.NoSuchAlgorithmException
      Sign a transaction with this account
      Parameters:
      tx - the transaction to sign
      Returns:
      a signed transaction
      Throws:
      java.security.NoSuchAlgorithmException - if signing algorithm could not be found
    • signTransactionBytes

      public SignedTransaction signTransactionBytes​(byte[] bytes) throws java.security.NoSuchAlgorithmException, java.io.IOException
      Sign a canonical msg-pack encoded Transaction
      Parameters:
      bytes - a canonical msg-pack encoded transaction
      Returns:
      a signed transaction
      Throws:
      java.security.NoSuchAlgorithmException - if ed25519 not found on this system
      java.io.IOException
    • signTransactionWithFeePerByte

      public SignedTransaction signTransactionWithFeePerByte​(Transaction tx, java.math.BigInteger feePerByte) throws java.security.NoSuchAlgorithmException
      Sign a transaction with this account, replacing the fee with the given feePerByte.
      Parameters:
      tx - transaction to sign
      feePerByte - fee per byte, often returned as a suggested fee
      Returns:
      a signed transaction
      Throws:
      java.security.NoSuchAlgorithmException - crypto provider not found
    • signBid

      public SignedBid signBid​(Bid bid) throws java.security.NoSuchAlgorithmException
      Sign a bid with this account
      Parameters:
      bid - the bid to sign
      Returns:
      a signed bid
      Throws:
      java.security.NoSuchAlgorithmException
    • transactionWithSuggestedFeePerByte

      @Deprecated public static Transaction transactionWithSuggestedFeePerByte​(Transaction copyTx, java.math.BigInteger suggestedFeePerByte) throws java.security.NoSuchAlgorithmException
      Deprecated.
      Replaced by setFeeByFeePerByte(com.algorand.algosdk.transaction.Transaction, int). This is unsafe to use because the returned transaction is a shallow copy of copyTx.
      Creates a version of the given transaction with fee populated according to suggestedFeePerByte * estimateTxSize.
      Parameters:
      copyTx - transaction to populate fee field
      suggestedFeePerByte - suggestedFee given by network
      Returns:
      transaction with proper fee set
      Throws:
      java.security.NoSuchAlgorithmException - could not estimate tx encoded size.
    • setFeeByFeePerByte

      public static void setFeeByFeePerByte​(Transaction tx, int suggestedFeePerByte) throws java.security.NoSuchAlgorithmException
      Sets the transaction fee according to suggestedFeePerByte * estimateTxSize.
      Parameters:
      tx - transaction to populate fee field
      suggestedFeePerByte - suggestedFee given by network
      Throws:
      java.security.NoSuchAlgorithmException - could not estimate tx encoded size.
    • setFeeByFeePerByte

      public static void setFeeByFeePerByte​(Transaction tx, java.math.BigInteger suggestedFeePerByte) throws java.security.NoSuchAlgorithmException
      Sets the transaction fee according to suggestedFeePerByte * estimateTxSize.
      Parameters:
      tx - transaction to populate fee field
      suggestedFeePerByte - suggestedFee given by network
      Throws:
      java.security.NoSuchAlgorithmException - could not estimate tx encoded size.
    • estimatedEncodedSize

      public static java.math.BigInteger estimatedEncodedSize​(Transaction tx) throws java.security.NoSuchAlgorithmException
      EstimateEncodedSize returns the estimated encoded size of the transaction including the signature. This function is useful for calculating the fee from suggested fee per byte.
      Returns:
      an estimated byte size for the transaction.
      Throws:
      java.security.NoSuchAlgorithmException
    • signBytes

      public Signature signBytes​(byte[] bytes) throws java.security.NoSuchAlgorithmException
      Sign the given bytes, and wrap in signature. The message is prepended with "MX" for domain separation.
      Parameters:
      bytes - the data to sign
      Returns:
      a signature
      Throws:
      java.security.NoSuchAlgorithmException
    • signMultisigTransaction

      public SignedTransaction signMultisigTransaction​(MultisigAddress from, Transaction tx) throws java.security.NoSuchAlgorithmException
      signMultisigTransaction creates a multisig transaction from the input and the multisig account.
      Parameters:
      from - sign as this multisignature account
      tx - the transaction to sign
      Returns:
      SignedTransaction a partially signed multisig transaction
      Throws:
      java.security.NoSuchAlgorithmException - if could not sign tx
    • mergeMultisigTransactions

      public static SignedTransaction mergeMultisigTransactions​(SignedTransaction... txs)
      mergeMultisigTransactions merges the given (partially) signed multisig transactions.
      Parameters:
      txs - partially signed multisig transactions to merge. Underlying transactions may be mutated.
      Returns:
      a merged multisig transaction
    • appendMultisigTransaction

      public SignedTransaction appendMultisigTransaction​(MultisigAddress from, SignedTransaction signedTx) throws java.security.NoSuchAlgorithmException
      appendMultisigTransaction appends our signature to the given multisig transaction.
      Parameters:
      from - the multisig public identity we are signing for
      signedTx - the partially signed msig tx to which to append signature
      Returns:
      a merged multisig transaction
      Throws:
      java.security.NoSuchAlgorithmException - unknown signature algorithm
    • mergeMultisigTransactionBytes

      public static byte[] mergeMultisigTransactionBytes​(byte[]... txsBytes) throws java.security.NoSuchAlgorithmException, java.io.IOException
      mergeMultisigTransactionBytes is a convenience method for working directly with raw transaction files.
      Parameters:
      txsBytes - list of multisig transactions to merge
      Returns:
      an encoded, merged multisignature transaction
      Throws:
      java.security.NoSuchAlgorithmException - if could not compute signature
      java.io.IOException
    • appendMultisigTransactionBytes

      public byte[] appendMultisigTransactionBytes​(MultisigAddress from, byte[] txBytes) throws java.security.NoSuchAlgorithmException, java.io.IOException
      appendMultisigTransactionBytes is a convenience method for directly appending our signature to a raw tx file.
      Parameters:
      from - the public identity we are signing as.
      txBytes - the multisig transaction to append signature to
      Returns:
      merged multisignature transaction inclukding our signature
      Throws:
      java.security.NoSuchAlgorithmException - on failure to compute signature
      java.io.IOException
    • signMultisigTransactionBytes

      public byte[] signMultisigTransactionBytes​(MultisigAddress from, Transaction tx) throws java.security.NoSuchAlgorithmException, java.io.IOException
      signMultisigTransactionBytes is a convenience method for signing a multistransaction into bytes
      Parameters:
      from - the public identity we are signing as.
      tx - the multisig transaction to append signature to
      Returns:
      merged multisignature transaction inclukding our signature
      Throws:
      java.security.NoSuchAlgorithmException - on failure to compute signature
      java.io.IOException
    • signLogicsig

      public LogicsigSignature signLogicsig​(LogicsigSignature lsig) throws java.io.IOException
      Sign LogicSig with account's secret key
      Parameters:
      lsig - LogicsigSignature to sign
      Returns:
      LogicsigSignature with updated signature
      Throws:
      java.io.IOException
    • signLogicsig

      public LogicsigSignature signLogicsig​(LogicsigSignature lsig, MultisigAddress ma) throws java.io.IOException
      Sign LogicSig as multisig
      Parameters:
      lsig - LogicsigSignature to sign
      ma - MultisigAddress to format multi signature from
      Returns:
      LogicsigSignature
      Throws:
      java.io.IOException
    • appendToLogicsig

      public LogicsigSignature appendToLogicsig​(LogicsigSignature lsig) throws java.lang.IllegalArgumentException, java.io.IOException
      Appends a signature to multisig logic signed transaction
      Parameters:
      lsig - LogicsigSignature append to
      Returns:
      LogicsigSignature
      Throws:
      java.lang.IllegalArgumentException
      java.security.NoSuchAlgorithmException
      java.io.IOException
    • signLogicTransactionWithAddress

      public static SignedTransaction signLogicTransactionWithAddress​(LogicsigSignature lsig, Address lsigAddr, Transaction tx) throws java.lang.IllegalArgumentException, java.io.IOException
      Throws:
      java.lang.IllegalArgumentException
      java.io.IOException
    • signLogicsigTransaction

      public static SignedTransaction signLogicsigTransaction​(LogicsigSignature lsig, Transaction tx) throws java.lang.IllegalArgumentException, java.io.IOException
      Creates SignedTransaction from LogicsigSignature and Transaction. LogicsigSignature must be valid and verifiable against transaction sender field.
      Parameters:
      lsig - LogicsigSignature
      tx - Transaction
      Returns:
      SignedTransaction
      Throws:
      java.lang.IllegalArgumentException
      java.io.IOException
    • tealSign

      public Signature tealSign​(byte[] data, Address contractAddress) throws java.security.NoSuchAlgorithmException, java.io.IOException
      Creates Signature compatible with ed25519verify TEAL opcode from data and contract address (program hash).
      Parameters:
      data - byte[]
      contractAddress - Address
      Returns:
      Signature
      Throws:
      java.security.NoSuchAlgorithmException
      java.io.IOException
    • tealSignFromProgram

      public Signature tealSignFromProgram​(byte[] data, byte[] program) throws java.security.NoSuchAlgorithmException, java.io.IOException
      Creates Signature compatible with ed25519verify TEAL opcode from data and program bytes
      Parameters:
      data - byte[]
      program - byte[]
      Returns:
      Signature
      Throws:
      java.security.NoSuchAlgorithmException
      java.io.IOException
    • toSeed

      public byte[] toSeed() throws java.security.GeneralSecurityException
      25 word mnemonic is obtained and converted to 32 byte private key.
      Returns:
      32 byte private key
      Throws:
      java.security.GeneralSecurityException
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • getTransactionSigner

      public TxnSigner getTransactionSigner()