Documentation
¶
Overview ¶
Package network contains functions that deal with stellar network passphrases and IDs.
Index ¶
- Constants
- Variables
- func HashFeeBumpTransaction(tx xdr.FeeBumpTransaction, passphrase string) ([32]byte, error)
- func HashTransaction(tx xdr.Transaction, passphrase string) ([32]byte, error)
- func HashTransactionInEnvelope(envelope xdr.TransactionEnvelope, passphrase string) ([32]byte, error)
- func HashTransactionV0(tx xdr.TransactionV0, passphrase string) ([32]byte, error)
- func ID(passphrase string) [32]byte
- type TransactionViewHasher
Constants ¶
const ( // PublicNetworkPassphrase is the pass phrase used for every transaction intended for the public stellar network PublicNetworkPassphrase = "Public Global Stellar Network ; September 2015" // TestNetworkPassphrase is the pass phrase used for every transaction intended for the SDF-run test network TestNetworkPassphrase = "Test SDF Network ; September 2015" // FutureNetworkPassphrase is the pass phrase used for every transaction intended for the SDF-run future network FutureNetworkPassphrase = "Test SDF Future Network ; October 2022" )
Variables ¶
var ( // PublicNetworkhistoryArchiveURLs is a list of history archive URLs for stellar 'pubnet' PublicNetworkhistoryArchiveURLs = []string{ "https://history.stellar.org/prd/core-live/core_live_001/", "https://history.stellar.org/prd/core-live/core_live_002/", "https://history.stellar.org/prd/core-live/core_live_003/", } // TestNetworkhistoryArchiveURLs is a list of history archive URLs for stellar 'testnet' TestNetworkhistoryArchiveURLs = []string{ "https://history.stellar.org/prd/core-testnet/core_testnet_001/", "https://history.stellar.org/prd/core-testnet/core_testnet_002/", "https://history.stellar.org/prd/core-testnet/core_testnet_003", } // FutureNetworkhistoryArchiveURLs is a list of history archive URLs for stellar 'futurenet' FutureNetworkhistoryArchiveURLs = []string{ "http://history.stellar.org/dev/core-futurenet/core_futurenet_001/", "http://history.stellar.org/dev/core-futurenet/core_futurenet_002/", "http://history.stellar.org/dev/core-futurenet/core_futurenet_003/", } )
Functions ¶
func HashFeeBumpTransaction ¶
func HashFeeBumpTransaction(tx xdr.FeeBumpTransaction, passphrase string) ([32]byte, error)
HashFeeBumpTransaction derives the network specific hash for the provided fee bump transaction using the network identified by the supplied passphrase. The resulting hash is the value that can be signed by stellar secret key to authorize the transaction identified by the hash to stellar validators.
func HashTransaction ¶
func HashTransaction(tx xdr.Transaction, passphrase string) ([32]byte, error)
HashTransaction derives the network specific hash for the provided transaction using the network identified by the supplied passphrase. The resulting hash is the value that can be signed by stellar secret key to authorize the transaction identified by the hash to stellar validators.
func HashTransactionInEnvelope ¶
func HashTransactionInEnvelope(envelope xdr.TransactionEnvelope, passphrase string) ([32]byte, error)
HashTransactionInEnvelope derives the network specific hash for the transaction contained in the provided envelope using the network identified by the supplied passphrase. The resulting hash is the value that can be signed by stellar secret key to authorize the transaction identified by the hash to stellar validators.
func HashTransactionV0 ¶
func HashTransactionV0(tx xdr.TransactionV0, passphrase string) ([32]byte, error)
HashTransactionV0 derives the network specific hash for the provided legacy transaction using the network identified by the supplied passphrase. The resulting hash is the value that can be signed by stellar secret key to authorize the transaction identified by the hash to stellar validators.
Types ¶
type TransactionViewHasher ¶ added in v0.7.0
type TransactionViewHasher struct {
// contains filtered or unexported fields
}
TransactionViewHasher computes transaction hashes straight from envelope view wire bytes — the zero-copy twin of HashTransactionInEnvelope. The tx-hash preimage is
SHA256(networkID ‖ envelope-type tag (4 bytes) ‖ Transaction XDR)
and every piece is available as a wire-byte slice off the view, so no envelope decode (UnmarshalBinary) is needed. The network ID is derived once and the SHA-256 state is reused, so hashing allocates nothing per envelope.
A TransactionViewHasher is NOT safe for concurrent use (it reuses one hash state); use one per goroutine.
func NewTransactionViewHasher ¶ added in v0.7.0
func NewTransactionViewHasher(passphrase string) (*TransactionViewHasher, error)
NewTransactionViewHasher derives the network ID from passphrase. The empty-passphrase guard is the same validatePassphrase hashTx uses, surfaced once per hasher instead of once per envelope.
func (*TransactionViewHasher) Hash ¶ added in v0.7.0
func (th *TransactionViewHasher) Hash(env xdr.TransactionEnvelopeView) (txHash [32]byte, err error)
Hash returns the transaction hash, reading everything from the envelope view's wire bytes without decoding the envelope. The envelope type is read internally to select the preimage shape but deliberately NOT returned — callers that need the type (or soroban-ness) read those discriminants themselves; neither involves hashing or the passphrase.
A TX_V0 envelope hashes as its V1 conversion (see HashTransactionV0): on the wire that conversion is exactly the 4-byte ed25519 key-type prefix followed by the unchanged TransactionV0 bytes — the V0 optional-TimeBounds and V1 Preconditions encodings are identical (absent ⇒ 0 ⇒ PRECOND_NONE, present ⇒ 1 + TimeBounds ⇒ PRECOND_TIME), as are all fields after them (both Ext arms are void).