Package com.algorand.algosdk.account
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Account.FixedSecureRandom
-
Field Summary
Fields Modifier and Type Field Description static java.math.BigInteger
MIN_TX_FEE_UALGOS
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description SignedTransaction
appendMultisigTransaction(MultisigAddress from, SignedTransaction signedTx)
appendMultisigTransaction appends our signature to the given multisig transaction.byte[]
appendMultisigTransactionBytes(MultisigAddress from, byte[] txBytes)
appendMultisigTransactionBytes is a convenience method for directly appending our signature to a raw tx file.LogicsigSignature
appendToLogicsig(LogicsigSignature lsig)
Appends a signature to multisig logic signed transactionboolean
equals(java.lang.Object obj)
static java.math.BigInteger
estimatedEncodedSize(Transaction tx)
EstimateEncodedSize returns the estimated encoded size of the transaction including the signature.Address
getAddress()
Convenience method for getting underlying address.byte[]
getClearTextPublicKey()
Convenience method for getting the underlying public key for raw operations.Ed25519PublicKey
getEd25519PublicKey()
TxnSigner
getTransactionSigner()
static byte[]
mergeMultisigTransactionBytes(byte[]... txsBytes)
mergeMultisigTransactionBytes is a convenience method for working directly with raw transaction files.static SignedTransaction
mergeMultisigTransactions(SignedTransaction... txs)
mergeMultisigTransactions merges the given (partially) signed multisig transactions.static void
setFeeByFeePerByte(Transaction tx, int suggestedFeePerByte)
Sets the transaction fee according to suggestedFeePerByte * estimateTxSize.static void
setFeeByFeePerByte(Transaction tx, java.math.BigInteger suggestedFeePerByte)
Sets the transaction fee according to suggestedFeePerByte * estimateTxSize.SignedBid
signBid(Bid bid)
Sign a bid with this accountSignature
signBytes(byte[] bytes)
Sign the given bytes, and wrap in signature.LogicsigSignature
signLogicsig(LogicsigSignature lsig)
Sign LogicSig with account's secret keyLogicsigSignature
signLogicsig(LogicsigSignature lsig, MultisigAddress ma)
Sign LogicSig as multisigstatic SignedTransaction
signLogicsigTransaction(LogicsigSignature lsig, Transaction tx)
Creates SignedTransaction from LogicsigSignature and Transaction.static SignedTransaction
signLogicTransactionWithAddress(LogicsigSignature lsig, Address lsigAddr, Transaction tx)
SignedTransaction
signMultisigTransaction(MultisigAddress from, Transaction tx)
signMultisigTransaction creates a multisig transaction from the input and the multisig account.byte[]
signMultisigTransactionBytes(MultisigAddress from, Transaction tx)
signMultisigTransactionBytes is a convenience method for signing a multistransaction into bytesSignedTransaction
signTransaction(Transaction tx)
Sign a transaction with this accountSignedTransaction
signTransactionBytes(byte[] bytes)
Sign a canonical msg-pack encoded TransactionSignedTransaction
signTransactionWithFeePerByte(Transaction tx, java.math.BigInteger feePerByte)
Sign a transaction with this account, replacing the fee with the given feePerByte.Signature
tealSign(byte[] data, Address contractAddress)
Creates Signature compatible with ed25519verify TEAL opcode from data and contract address (program hash).Signature
tealSignFromProgram(byte[] data, byte[] program)
Creates Signature compatible with ed25519verify TEAL opcode from data and program bytesjava.lang.String
toMnemonic()
Converts the 32 byte private key to a 25 word mnemonic, including a checksum.byte[]
toSeed()
25 word mnemonic is obtained and converted to 32 byte private key.static Transaction
transactionWithSuggestedFeePerByte(Transaction copyTx, java.math.BigInteger suggestedFeePerByte)
Deprecated.Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
MIN_TX_FEE_UALGOS
public static final java.math.BigInteger MIN_TX_FEE_UALGOS
-
-
Constructor Details
-
Account
public Account() throws java.security.NoSuchAlgorithmExceptionAccount creates a new, random account.- Throws:
java.security.NoSuchAlgorithmException
-
Account
public Account(byte[] seed) throws java.security.NoSuchAlgorithmExceptionCreate 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
-
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.NoSuchAlgorithmExceptionSign 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.IOExceptionSign 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 systemjava.io.IOException
-
signTransactionWithFeePerByte
public SignedTransaction signTransactionWithFeePerByte(Transaction tx, java.math.BigInteger feePerByte) throws java.security.NoSuchAlgorithmExceptionSign a transaction with this account, replacing the fee with the given feePerByte.- Parameters:
tx
- transaction to signfeePerByte
- fee per byte, often returned as a suggested fee- Returns:
- a signed transaction
- Throws:
java.security.NoSuchAlgorithmException
- crypto provider not found
-
signBid
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.NoSuchAlgorithmExceptionDeprecated.Replaced bysetFeeByFeePerByte(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 fieldsuggestedFeePerByte
- 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.NoSuchAlgorithmExceptionSets the transaction fee according to suggestedFeePerByte * estimateTxSize.- Parameters:
tx
- transaction to populate fee fieldsuggestedFeePerByte
- 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.NoSuchAlgorithmExceptionSets the transaction fee according to suggestedFeePerByte * estimateTxSize.- Parameters:
tx
- transaction to populate fee fieldsuggestedFeePerByte
- 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.NoSuchAlgorithmExceptionEstimateEncodedSize 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
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.NoSuchAlgorithmExceptionsignMultisigTransaction creates a multisig transaction from the input and the multisig account.- Parameters:
from
- sign as this multisignature accounttx
- the transaction to sign- Returns:
- SignedTransaction a partially signed multisig transaction
- Throws:
java.security.NoSuchAlgorithmException
- if could not sign tx
-
mergeMultisigTransactions
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.NoSuchAlgorithmExceptionappendMultisigTransaction appends our signature to the given multisig transaction.- Parameters:
from
- the multisig public identity we are signing forsignedTx
- 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.IOExceptionmergeMultisigTransactionBytes 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 signaturejava.io.IOException
-
appendMultisigTransactionBytes
public byte[] appendMultisigTransactionBytes(MultisigAddress from, byte[] txBytes) throws java.security.NoSuchAlgorithmException, java.io.IOExceptionappendMultisigTransactionBytes 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 signaturejava.io.IOException
-
signMultisigTransactionBytes
public byte[] signMultisigTransactionBytes(MultisigAddress from, Transaction tx) throws java.security.NoSuchAlgorithmException, java.io.IOExceptionsignMultisigTransactionBytes 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 signaturejava.io.IOException
-
signLogicsig
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.IOExceptionSign LogicSig as multisig- Parameters:
lsig
- LogicsigSignature to signma
- MultisigAddress to format multi signature from- Returns:
- LogicsigSignature
- Throws:
java.io.IOException
-
appendToLogicsig
public LogicsigSignature appendToLogicsig(LogicsigSignature lsig) throws java.lang.IllegalArgumentException, java.io.IOExceptionAppends 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.IOExceptionCreates SignedTransaction from LogicsigSignature and Transaction. LogicsigSignature must be valid and verifiable against transaction sender field.- Parameters:
lsig
- LogicsigSignaturetx
- Transaction- Returns:
- SignedTransaction
- Throws:
java.lang.IllegalArgumentException
java.io.IOException
-
tealSign
public Signature tealSign(byte[] data, Address contractAddress) throws java.security.NoSuchAlgorithmException, java.io.IOExceptionCreates 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.IOExceptionCreates 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.GeneralSecurityException25 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 classjava.lang.Object
-
getTransactionSigner
-
setFeeByFeePerByte(com.algorand.algosdk.transaction.Transaction, int)
.