Package com.algorand.algosdk.account
Class Account
- java.lang.Object
-
- com.algorand.algosdk.account.Account
-
public class Account extends 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 BigInteger
MIN_TX_FEE_UALGOS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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(Object obj)
static 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, 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, 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 bytesString
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.
-
-
-
Field Detail
-
MIN_TX_FEE_UALGOS
public static final BigInteger MIN_TX_FEE_UALGOS
-
-
Constructor Detail
-
Account
public Account() throws NoSuchAlgorithmException
Account creates a new, random account.- Throws:
NoSuchAlgorithmException
-
Account
public Account(byte[] seed) throws NoSuchAlgorithmException
Create a new account from an rfc8037 private key.- Parameters:
seed
-- Throws:
NoSuchAlgorithmException
-
Account
public Account(String mnemonic) throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
Account
public Account(KeyPair pkPair)
-
Account
public Account(PrivateKey pk) throws NoSuchAlgorithmException
- Throws:
NoSuchAlgorithmException
-
-
Method Detail
-
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 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 NoSuchAlgorithmException
Sign a transaction with this account- Parameters:
tx
- the transaction to sign- Returns:
- a signed transaction
- Throws:
NoSuchAlgorithmException
- if signing algorithm could not be found
-
signTransactionBytes
public SignedTransaction signTransactionBytes(byte[] bytes) throws NoSuchAlgorithmException, IOException
Sign a canonical msg-pack encoded Transaction- Parameters:
bytes
- a canonical msg-pack encoded transaction- Returns:
- a signed transaction
- Throws:
NoSuchAlgorithmException
- if ed25519 not found on this systemIOException
-
signTransactionWithFeePerByte
public SignedTransaction signTransactionWithFeePerByte(Transaction tx, BigInteger feePerByte) throws NoSuchAlgorithmException
Sign 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:
NoSuchAlgorithmException
- crypto provider not found
-
signBid
public SignedBid signBid(Bid bid) throws NoSuchAlgorithmException
Sign a bid with this account- Parameters:
bid
- the bid to sign- Returns:
- a signed bid
- Throws:
NoSuchAlgorithmException
-
setFeeByFeePerByte
public static void setFeeByFeePerByte(Transaction tx, int suggestedFeePerByte) throws NoSuchAlgorithmException
Sets the transaction fee according to suggestedFeePerByte * estimateTxSize.- Parameters:
tx
- transaction to populate fee fieldsuggestedFeePerByte
- suggestedFee given by network- Throws:
NoSuchAlgorithmException
- could not estimate tx encoded size.
-
setFeeByFeePerByte
public static void setFeeByFeePerByte(Transaction tx, BigInteger suggestedFeePerByte) throws NoSuchAlgorithmException
Sets the transaction fee according to suggestedFeePerByte * estimateTxSize.- Parameters:
tx
- transaction to populate fee fieldsuggestedFeePerByte
- suggestedFee given by network- Throws:
NoSuchAlgorithmException
- could not estimate tx encoded size.
-
estimatedEncodedSize
public static BigInteger estimatedEncodedSize(Transaction tx) throws 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:
NoSuchAlgorithmException
-
signBytes
public Signature signBytes(byte[] bytes) throws 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:
NoSuchAlgorithmException
-
signMultisigTransaction
public SignedTransaction signMultisigTransaction(MultisigAddress from, Transaction tx) throws NoSuchAlgorithmException
signMultisigTransaction 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:
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 NoSuchAlgorithmException
appendMultisigTransaction 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:
NoSuchAlgorithmException
- unknown signature algorithm
-
mergeMultisigTransactionBytes
public static byte[] mergeMultisigTransactionBytes(byte[]... txsBytes) throws NoSuchAlgorithmException, 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:
NoSuchAlgorithmException
- if could not compute signatureIOException
-
appendMultisigTransactionBytes
public byte[] appendMultisigTransactionBytes(MultisigAddress from, byte[] txBytes) throws NoSuchAlgorithmException, 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:
NoSuchAlgorithmException
- on failure to compute signatureIOException
-
signMultisigTransactionBytes
public byte[] signMultisigTransactionBytes(MultisigAddress from, Transaction tx) throws NoSuchAlgorithmException, 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:
NoSuchAlgorithmException
- on failure to compute signatureIOException
-
signLogicsig
public LogicsigSignature signLogicsig(LogicsigSignature lsig) throws IOException
Sign LogicSig with account's secret key- Parameters:
lsig
- LogicsigSignature to sign- Returns:
- LogicsigSignature with updated signature
- Throws:
IOException
-
signLogicsig
public LogicsigSignature signLogicsig(LogicsigSignature lsig, MultisigAddress ma) throws IOException
Sign LogicSig as multisig- Parameters:
lsig
- LogicsigSignature to signma
- MultisigAddress to format multi signature from- Returns:
- LogicsigSignature
- Throws:
IOException
-
appendToLogicsig
public LogicsigSignature appendToLogicsig(LogicsigSignature lsig) throws IllegalArgumentException, IOException
Appends a signature to multisig logic signed transaction- Parameters:
lsig
- LogicsigSignature append to- Returns:
- LogicsigSignature
- Throws:
IllegalArgumentException
NoSuchAlgorithmException
IOException
-
signLogicTransactionWithAddress
public static SignedTransaction signLogicTransactionWithAddress(LogicsigSignature lsig, Address lsigAddr, Transaction tx) throws IllegalArgumentException, IOException
- Throws:
IllegalArgumentException
IOException
-
signLogicsigTransaction
public static SignedTransaction signLogicsigTransaction(LogicsigSignature lsig, Transaction tx) throws IllegalArgumentException, IOException
Creates SignedTransaction from LogicsigSignature and Transaction. LogicsigSignature must be valid and verifiable against transaction sender field.- Parameters:
lsig
- LogicsigSignaturetx
- Transaction- Returns:
- SignedTransaction
- Throws:
IllegalArgumentException
IOException
-
tealSign
public Signature tealSign(byte[] data, Address contractAddress) throws NoSuchAlgorithmException, IOException
Creates Signature compatible with ed25519verify TEAL opcode from data and contract address (program hash).- Parameters:
data
- byte[]contractAddress
- Address- Returns:
- Signature
- Throws:
NoSuchAlgorithmException
IOException
-
tealSignFromProgram
public Signature tealSignFromProgram(byte[] data, byte[] program) throws NoSuchAlgorithmException, IOException
Creates Signature compatible with ed25519verify TEAL opcode from data and program bytes- Parameters:
data
- byte[]program
- byte[]- Returns:
- Signature
- Throws:
NoSuchAlgorithmException
IOException
-
toSeed
public byte[] toSeed() throws GeneralSecurityException
25 word mnemonic is obtained and converted to 32 byte private key.- Returns:
- 32 byte private key
- Throws:
GeneralSecurityException
-
getTransactionSigner
public TxnSigner getTransactionSigner()
-
-