crypto

package
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2023 License: MIT Imports: 12 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LightBlockHeaderPrefix = []byte("B256")

LightBlockHeaderPrefix is prepended to the canonical msgpack encoded light block header when computing its vector commitment leaf.

View Source
var StateProofMessagePrefix = []byte("spm")

StateProofMessagePrefix is prepended to the canonical msgpack encoded state proof message when computing its hash.

Functions

func AddressFromProgram

func AddressFromProgram(program []byte) types.Address

AddressFromProgram returns escrow account address derived from TEAL bytecode

func AppendMultisigToLogicSig

func AppendMultisigToLogicSig(lsig *types.LogicSig, sk ed25519.PrivateKey) error

AppendMultisigToLogicSig adds a new signature to multisigned LogicSig

func AppendMultisigTransaction

func AppendMultisigTransaction(sk ed25519.PrivateKey, ma MultisigAccount, preStxBytes []byte) (txid string, stxBytes []byte, err error)

AppendMultisigTransaction appends the signature corresponding to the given private key, returning an encoded signed multisig transaction including the signature. While we could compute the multisig preimage from the multisig blob, we ask the caller to pass it back in, to explicitly check that they know who they are signing as.

func ComputeGroupID

func ComputeGroupID(txgroup []types.Transaction) (gid types.Digest, err error)

ComputeGroupID returns group ID for a group of transactions

func GenerateAddressFromSK

func GenerateAddressFromSK(sk []byte) (types.Address, error)

GenerateAddressFromSK take a secret key and returns the corresponding Address

func GetApplicationAddress

func GetApplicationAddress(appID uint64) types.Address

GetApplicationAddress returns the address corresponding to an application's escrow account.

func GetTxID

func GetTxID(tx types.Transaction) string

GetTxID returns the txid of a transaction

func HashLightBlockHeader

func HashLightBlockHeader(lightBlockHeader types.LightBlockHeader) types.Digest

HashLightBlockHeader returns the hash of a light block header.

func HashStateProofMessage

func HashStateProofMessage(stateProofMessage *types.Message) types.MessageHash

HashStateProofMessage returns the hash of a state proof message.

func LogicSigAddress

func LogicSigAddress(lsig types.LogicSig) types.Address

LogicSigAddress returns the contract (escrow) address for a LogicSig.

NOTE: If the LogicSig is delegated to another account this will not return the delegated address of the LogicSig.

func MergeMultisigTransactions

func MergeMultisigTransactions(stxsBytes ...[]byte) (txid string, stxBytes []byte, err error)

MergeMultisigTransactions merges the given (partially) signed multisig transactions, and returns an encoded signed multisig transaction with the component signatures.

func RandomBytes

func RandomBytes(s []byte)

RandomBytes fills the passed slice with randomness, and panics if it is unable to do so

func SignBid

func SignBid(sk ed25519.PrivateKey, bid types.Bid) (signedBid []byte, err error)

SignBid accepts a private key and a bid, and returns the signature of the bid under that key

func SignBytes

func SignBytes(sk ed25519.PrivateKey, bytesToSign []byte) (signature []byte, err error)

SignBytes signs the bytes and returns the signature

func SignLogicSigAccountTransaction

func SignLogicSigAccountTransaction(logicSigAccount LogicSigAccount, tx types.Transaction) (txid string, stxBytes []byte, err error)

SignLogicSigAccountTransaction signs a transaction with a LogicSigAccount. It returns the TxID of the signed transaction and the raw bytes ready to be broadcast to the network. Note: any type of transaction can be signed by a LogicSig, but the network will reject the transaction if the LogicSig's program declines the transaction.

func SignLogicSigTransaction

func SignLogicSigTransaction(lsig types.LogicSig, tx types.Transaction) (txid string, stxBytes []byte, err error)

SignLogicSigTransaction takes LogicSig object and a transaction and returns the bytes of a signed transaction ready to be broadcasted to the network Note, LogicSig actually can be attached to any transaction and it is a program's responsibility to approve/decline the transaction

This function supports signing transactions with a sender that differs from the LogicSig's address, EXCEPT IF the LogicSig is delegated to a non-multisig account. In order to properly handle that case, create a LogicSigAccount and use SignLogicSigAccountTransaction instead.

func SignMultisigTransaction

func SignMultisigTransaction(sk ed25519.PrivateKey, ma MultisigAccount, tx types.Transaction) (txid string, stxBytes []byte, err error)

SignMultisigTransaction signs the given transaction, and multisig preimage, with the private key, returning the bytes of a signed transaction with the multisig field partially populated, ready to be passed to other multisig signers to sign or broadcast.

func SignTransaction

func SignTransaction(sk ed25519.PrivateKey, tx types.Transaction) (txid string, stxBytes []byte, err error)

SignTransaction accepts a private key and a transaction, and returns the bytes of a signed transaction ready to be broadcasted to the network If the SK's corresponding address is different than the txn sender's, the SK's corresponding address will be assigned as AuthAddr

func TealSign

func TealSign(sk ed25519.PrivateKey, data []byte, contractAddress types.Address) (rawSig types.Signature, err error)

TealSign creates a signature compatible with ed25519verify opcode from contract address

func TealSignFromProgram

func TealSignFromProgram(sk ed25519.PrivateKey, data []byte, program []byte) (rawSig types.Signature, err error)

TealSignFromProgram creates a signature compatible with ed25519verify opcode from raw program bytes

func TealVerify

func TealVerify(pk ed25519.PublicKey, data []byte, contractAddress types.Address, rawSig types.Signature) bool

TealVerify verifies signatures generated by TealSign and TealSignFromProgram

func TransactionID

func TransactionID(tx types.Transaction) (txid []byte)

TransactionID is the unique identifier for a Transaction in progress

func TransactionIDString

func TransactionIDString(tx types.Transaction) (txid string)

TransactionIDString is a base32 representation of a TransactionID

func VerifyBytes

func VerifyBytes(pk ed25519.PublicKey, message, signature []byte) bool

VerifyBytes verifies that the signature is valid

func VerifyLogicSig

func VerifyLogicSig(lsig types.LogicSig, singleSigner types.Address) (result bool)

VerifyLogicSig verifies that a LogicSig contains a valid program and, if a delegated signature is present, that the signature is valid.

The singleSigner argument is only used in the case of a delegated LogicSig whose delegating account is backed by a single private key (i.e. not a multsig account). In that case, it should be the address of the delegating account.

func VerifyMultisig

func VerifyMultisig(addr types.Address, message []byte, msig types.MultisigSig) bool

VerifyMultisig verifies an assembled MultisigSig

addr is the address of the Multisig account message is the bytes there were signed msig is the Multisig signature to verify

Types

type Account

type Account struct {
	PublicKey  ed25519.PublicKey
	PrivateKey ed25519.PrivateKey
	Address    types.Address
}

Account holds both the public and private information associated with an Algorand address

func AccountFromPrivateKey

func AccountFromPrivateKey(sk ed25519.PrivateKey) (account Account, err error)

AccountFromPrivateKey derives the remaining Account fields from only a private key. The argument sk must have a length equal to ed25519.PrivateKeySize.

func GenerateAccount

func GenerateAccount() (kp Account)

GenerateAccount generates a random Account

type LogicSigAccount

type LogicSigAccount struct {

	// The underlying LogicSig object
	Lsig types.LogicSig `codec:"lsig"`

	// The key that provided Lsig.Sig, if any
	SigningKey ed25519.PublicKey `codec:"sigkey"`
	// contains filtered or unexported fields
}

LogicSigAccount represents an account that can sign with a LogicSig program.

func LogicSigAccountFromLogicSig

func LogicSigAccountFromLogicSig(lsig types.LogicSig, signerPublicKey *ed25519.PublicKey) (lsa LogicSigAccount, err error)

LogicSigAccountFromLogicSig creates a LogicSigAccount from an existing LogicSig object.

The parameter signerPublicKey must be present if the LogicSig is delegated and the delegating account is backed by a single private key (i.e. not a multisig account). In this case, signerPublicKey must be the public key of the delegating account. In all other cases, an error will be returned if signerPublicKey is present.

func MakeLogicSigAccountDelegated

func MakeLogicSigAccountDelegated(program []byte, args [][]byte, signer ed25519.PrivateKey) (lsa LogicSigAccount, err error)

MakeLogicSigAccountDelegated creates a new delegated LogicSigAccount. This type of LogicSig has the authority to sign transactions on behalf of another account, called the delegating account. If the delegating account is a multisig account, use MakeLogicSigAccountDelegated instead.

The parameter signer is the private key of the delegating account.

func MakeLogicSigAccountDelegatedMsig

func MakeLogicSigAccountDelegatedMsig(program []byte, args [][]byte, msigAccount MultisigAccount, signer ed25519.PrivateKey) (lsa LogicSigAccount, err error)

MakeLogicSigAccountDelegatedMsig creates a new delegated LogicSigAccount. This type of LogicSig has the authority to sign transactions on behalf of another account, called the delegating account. Use this function if the delegating account is a multisig account, otherwise use MakeLogicSigAccountDelegated.

The parameter msigAccount is the delegating multisig account.

The parameter signer is the private key of one of the members of the delegating multisig account. Use the method AppendMultisigSignature on the returned LogicSigAccount to add additional signatures from other members.

func MakeLogicSigAccountEscrowChecked

func MakeLogicSigAccountEscrowChecked(program []byte, args [][]byte) (LogicSigAccount, error)

MakeLogicSigAccountEscrowChecked creates a new escrow LogicSigAccount. The address of this account will be a hash of its program.

func (LogicSigAccount) Address

func (lsa LogicSigAccount) Address() (addr types.Address, err error)

Address returns the address of this LogicSigAccount.

If the LogicSig is delegated to another account, this will return the address of that account.

If the LogicSig is not delegated to another account, this will return an escrow address that is the hash of the LogicSig's program code.

func (*LogicSigAccount) AppendMultisigSignature

func (lsa *LogicSigAccount) AppendMultisigSignature(signer ed25519.PrivateKey) error

AppendMultisigSignature adds an additional signature from a member of the delegating multisig account.

The LogicSigAccount must represent a delegated LogicSig backed by a multisig account.

func (LogicSigAccount) IsDelegated

func (lsa LogicSigAccount) IsDelegated() bool

IsDelegated returns true if and only if the LogicSig has been delegated to another account with a signature.

Note this function only checks for the presence of a delegation signature. To verify the delegation signature, use VerifyLogicSig.

type MultisigAccount

type MultisigAccount struct {
	// Version is the version of this multisig
	Version uint8
	// Threshold is how many signatures are needed to fully sign as this address
	Threshold uint8
	// Pks is an ordered list of public keys that could potentially sign a message
	Pks []ed25519.PublicKey
}

MultisigAccount is a convenience type for holding multisig preimage data

func MultisigAccountFromSig

func MultisigAccountFromSig(sig types.MultisigSig) (ma MultisigAccount, err error)

MultisigAccountFromSig is a convenience method that creates an account from a sig in a signed tx. Useful for getting addresses from signed msig txs, etc.

func MultisigAccountWithParams

func MultisigAccountWithParams(version uint8, threshold uint8, addrs []types.Address) (ma MultisigAccount, err error)

MultisigAccountWithParams creates a MultisigAccount with the given parameters

func (MultisigAccount) Address

func (ma MultisigAccount) Address() (addr types.Address, err error)

Address takes this multisig preimage data, and generates the corresponding identifying address, committing to the exact group, version, and public keys that it requires to sign. Hash("MultisigAddr" || version uint8 || threshold uint8 || PK1 || PK2 || ...)

func (MultisigAccount) Blank

func (ma MultisigAccount) Blank() bool

Blank return true if MultisigAccount is empty struct containing []ed25519.PublicKey cannot be compared

func (MultisigAccount) Validate

func (ma MultisigAccount) Validate() (err error)

Validate ensures that this multisig setup is a valid multisig account

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL