Documentation ¶
Index ¶
- Constants
- Variables
- func CreateTxWitness(txHash string, signer ITxSigner) ([]byte, error)
- func GenerateKeyPair() ([]byte, []byte, error)
- func GetKeyBytes(key string) (result []byte, err error)
- func GetKeyHash(bytes []byte) (string, error)
- func GetKeyHashBytes(bytes []byte) ([]byte, error)
- func GetOutputsSum(outputs []TxOutput) map[string]uint64
- func GetUtxosSum(utxos []Utxo) map[string]uint64
- func GetVerificationKeyFromSigningKey(signingKey []byte) []byte
- func IsAddressWithValidPrefix(addr string) bool
- func IsTxInUtxos(ctx context.Context, utxoRetriever IUTxORetriever, addr string, txHash string) (bool, error)
- func PadKeyToSize(key []byte) []byte
- func ResolveCardanoCliBinary(_ CardanoNetworkType) string
- func SignMessage(signingKey, verificationKey, message []byte) (result []byte, err error)
- func VerifyMessage(message, verificationKey, signature []byte) (err error)
- func VerifyWitness(txHash string, witness []byte) error
- type AddressInfo
- type CardanoAddress
- func NewBaseAddress(network CardanoNetworkType, ...) (*CardanoAddress, error)
- func NewCardanoAddress(raw []byte) (*CardanoAddress, error)
- func NewCardanoAddressFromString(raw string) (*CardanoAddress, error)
- func NewEnterpriseAddress(network CardanoNetworkType, verificationKey []byte) (*CardanoAddress, error)
- func NewPolicyScriptAddress(networkID CardanoNetworkType, policyID string, policyIDStake ...string) (*CardanoAddress, error)
- func NewRewardAddress(network CardanoNetworkType, verificationKey []byte) (*CardanoAddress, error)
- type CardanoAddressInfo
- type CardanoAddressPayload
- type CardanoAddressType
- type CardanoNetworkType
- type CliUtils
- func (cu CliUtils) GetAddressInfo(address string) (AddressInfo, error)
- func (cu CliUtils) GetKeyHash(key []byte) (string, error)
- func (cu CliUtils) GetPolicyID(policyScript any) (string, error)
- func (cu CliUtils) GetPolicyScriptAddress(testNetMagic uint, policyScript *PolicyScript, ...) (string, error)
- func (cu CliUtils) GetTxHash(txRaw []byte) (string, error)
- func (cu CliUtils) GetWalletAddress(verificationKey, stakeVerificationKey []byte, testNetMagic uint) (addr string, stakeAddr string, err error)
- type IPolicyScript
- type ITxDataRetriever
- type ITxProvider
- type ITxRetriever
- type ITxSigner
- type ITxSubmitter
- type IUTxORetriever
- type Key
- type PolicyScript
- type ProtocolParameters
- type ProtocolParametersMemorySteps
- type ProtocolParametersPriceMemorySteps
- type ProtocolParametersVersion
- type QueryTipData
- type StakePointer
- type TokenAmount
- type TxBuilder
- func (b *TxBuilder) AddInputs(inputs ...TxInput) *TxBuilder
- func (b *TxBuilder) AddInputsWithScript(script IPolicyScript, inputs ...TxInput) *TxBuilder
- func (b *TxBuilder) AddInputsWithScripts(inputs []TxInput, scripts []IPolicyScript) *TxBuilder
- func (b *TxBuilder) AddOutputs(outputs ...TxOutput) *TxBuilder
- func (b *TxBuilder) AddTokenMints(policyScripts []IPolicyScript, tokens []TokenAmount) *TxBuilder
- func (b *TxBuilder) AssembleTxWitnesses(txRaw []byte, witnesses [][]byte) ([]byte, error)
- func (b *TxBuilder) Build() ([]byte, string, error)
- func (b *TxBuilder) CalculateFee(witnessCount int) (uint64, error)
- func (b *TxBuilder) CheckOutputs() error
- func (b *TxBuilder) Dispose()
- func (b *TxBuilder) RemoveOutput(index int) *TxBuilder
- func (b *TxBuilder) SetFee(fee uint64) *TxBuilder
- func (b *TxBuilder) SetMetaData(metadata []byte) *TxBuilder
- func (b *TxBuilder) SetProtocolParameters(protocolParameters []byte) *TxBuilder
- func (b *TxBuilder) SetProtocolParametersAndTTL(ctx context.Context, retriever ITxDataRetriever, timeToLiveInc uint64) error
- func (b *TxBuilder) SetTestNetMagic(testNetMagic uint) *TxBuilder
- func (b *TxBuilder) SetTimeToLive(timeToLive uint64) *TxBuilder
- func (b *TxBuilder) SignTx(txRaw []byte, signers []ITxSigner) ([]byte, error)
- func (b *TxBuilder) UpdateOutputAmount(index int, amount uint64, tokenAmounts ...uint64) *TxBuilder
- type TxInput
- type TxInputs
- type TxOutput
- type TxProviderBlockFrost
- func (b *TxProviderBlockFrost) Dispose()
- func (b *TxProviderBlockFrost) GetProtocolParameters(ctx context.Context) ([]byte, error)
- func (b *TxProviderBlockFrost) GetTip(ctx context.Context) (QueryTipData, error)
- func (b *TxProviderBlockFrost) GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)
- func (b *TxProviderBlockFrost) GetUtxos(ctx context.Context, addr string) ([]Utxo, error)
- func (b *TxProviderBlockFrost) SubmitTx(ctx context.Context, txSigned []byte) error
- type TxProviderCli
- func (b *TxProviderCli) Dispose()
- func (b *TxProviderCli) GetProtocolParameters(_ context.Context) ([]byte, error)
- func (b *TxProviderCli) GetTip(_ context.Context) (QueryTipData, error)
- func (b *TxProviderCli) GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)
- func (b *TxProviderCli) GetUtxos(_ context.Context, addr string) ([]Utxo, error)
- func (b *TxProviderCli) SubmitTx(_ context.Context, txSigned []byte) error
- type TxProviderOgmios
- func (o *TxProviderOgmios) Dispose()
- func (o *TxProviderOgmios) GetProtocolParameters(ctx context.Context) ([]byte, error)
- func (o *TxProviderOgmios) GetTip(ctx context.Context) (QueryTipData, error)
- func (o *TxProviderOgmios) GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)
- func (o *TxProviderOgmios) GetUtxos(ctx context.Context, addr string) ([]Utxo, error)
- func (o *TxProviderOgmios) SubmitTx(ctx context.Context, txSigned []byte) error
- type TxWitnessRaw
- type Utxo
- type Wallet
Constants ¶
const ( AdaTokenPolicyID = "ada" AdaTokenName = "lovelace" )
const ( TestNetProtocolMagic = uint(1097911063) MainNetProtocolMagic = uint(764824073) MainNetNetwork CardanoNetworkType = 1 TestNetNetwork CardanoNetworkType = 0 )
const ( PolicyScriptAtLeastType = "atLeast" PolicyScriptSigType = "sig" )
const ( KeyHashSize = 28 KeySize = 32 StakeSigningKeyShelley = "StakeSigningKeyShelley_ed25519" StakeSigningKeyShelleyDesc = "Stake Signing Key" StakeVerificationKeyShelley = "StakeVerificationKeyShelley_ed25519" StakeVerificationKeyShelleyDesc = "Stake Verification Key" PaymentSigningKeyShelley = "PaymentSigningKeyShelley_ed25519" PaymentSigningKeyShelleyDesc = "Payment Signing Key" PaymentVerificationKeyShelley = "PaymentVerificationKeyShelley_ed25519" PaymentVerificationKeyShelleyDesc = "Payment Verification Key" )
const FilePermission = 0750
Variables ¶
var ( ErrUnsupportedAddress = errors.New("invalid/unsupported address type") ErrInvalidAddressData = errors.New("invalid address data") )
var ErrInvalidSignature = errors.New("invalid signature")
Functions ¶
func CreateTxWitness ¶
CreateTxWitness signs transaction hash and creates witness cbor
func GenerateKeyPair ¶
GenerateKeyPair generates ed25519 (signing key, verifying) key pair
func GetKeyBytes ¶
GetKeyBytes extracts the original key bytes from a given string. Supported formats: - Hex + CBOR encoded string: Attempts to decode the key assuming it is hex-encoded, - Bech32 encoded keys: Handles formats like addr_vk, addr_sk, stake_vk, stake_sk
func GetKeyHash ¶
GetKeyHash gets Cardano key hash string from arbitrary key
func GetKeyHashBytes ¶
GetKeyHashBytes gets Cardano key hash from arbitrary bytes
func GetOutputsSum ¶
GetOutputsSum returns sum or tokens in outputs (including lovelace)
func GetUtxosSum ¶
GetUtxosSum returns sum for tokens in utxos (including lovelace)
func GetVerificationKeyFromSigningKey ¶
GetVerificationKeyFromSigningKey retrieves verification/public key from signing/private key
func IsTxInUtxos ¶
func IsTxInUtxos(ctx context.Context, utxoRetriever IUTxORetriever, addr string, txHash string) (bool, error)
IsTxInUtxos checks whether a specified transaction hash (txHash) exists within the UTXOs associated with the given address (addr).
func ResolveCardanoCliBinary ¶
func ResolveCardanoCliBinary(_ CardanoNetworkType) string
func SignMessage ¶
SignMessage signs message
func VerifyMessage ¶
VerifyMessage verifies message with verificationKey and signature
func VerifyWitness ¶
VerifyWitness verifies if txHash is signed by witness
Types ¶
type AddressInfo ¶
type CardanoAddress ¶
type CardanoAddress struct {
// contains filtered or unexported fields
}
func NewBaseAddress ¶
func NewBaseAddress( network CardanoNetworkType, paymentVerificationKey, stakeVerificationKey []byte, ) (*CardanoAddress, error)
func NewCardanoAddress ¶
func NewCardanoAddress(raw []byte) (*CardanoAddress, error)
func NewCardanoAddressFromString ¶
func NewCardanoAddressFromString(raw string) (*CardanoAddress, error)
func NewEnterpriseAddress ¶
func NewEnterpriseAddress( network CardanoNetworkType, verificationKey []byte, ) (*CardanoAddress, error)
func NewPolicyScriptAddress ¶
func NewPolicyScriptAddress( networkID CardanoNetworkType, policyID string, policyIDStake ...string, ) (*CardanoAddress, error)
GetAddress returns address for this policy script
func NewRewardAddress ¶
func NewRewardAddress( network CardanoNetworkType, verificationKey []byte, ) (*CardanoAddress, error)
func (*CardanoAddress) GetBytes ¶
func (a *CardanoAddress) GetBytes() []byte
func (*CardanoAddress) GetInfo ¶
func (a *CardanoAddress) GetInfo() CardanoAddressInfo
func (*CardanoAddress) String ¶
func (a *CardanoAddress) String() string
type CardanoAddressInfo ¶
type CardanoAddressInfo struct { AddressType CardanoAddressType Network CardanoNetworkType Payment *CardanoAddressPayload Stake *CardanoAddressPayload StakePointer *StakePointer Extra []byte }
func (CardanoAddressInfo) ToCardanoAddress ¶
func (cai CardanoAddressInfo) ToCardanoAddress() (*CardanoAddress, error)
type CardanoAddressPayload ¶
type CardanoAddressPayload struct { Payload [KeyHashSize]byte IsScript bool }
func (CardanoAddressPayload) String ¶
func (sc CardanoAddressPayload) String() string
type CardanoAddressType ¶
type CardanoAddressType byte
const ( UnsupportedAddress CardanoAddressType = 0 BaseAddress CardanoAddressType = 1 // 0b0000, 0b0001, 0b0010, 0b0011 PointerAddress CardanoAddressType = 2 // 0b0100, 0b0101 EnterpriseAddress CardanoAddressType = 3 // 0b0110, 0b0111 RewardAddress CardanoAddressType = 4 // 0b1110, 0b1111 )
func GetAddressTypeFromHeader ¶
func GetAddressTypeFromHeader(header byte) CardanoAddressType
type CardanoNetworkType ¶
type CardanoNetworkType byte
func (CardanoNetworkType) GetPrefix ¶
func (n CardanoNetworkType) GetPrefix() string
func (CardanoNetworkType) GetStakePrefix ¶
func (n CardanoNetworkType) GetStakePrefix() string
func (CardanoNetworkType) IsMainNet ¶
func (n CardanoNetworkType) IsMainNet() bool
type CliUtils ¶
type CliUtils struct {
// contains filtered or unexported fields
}
func NewCliUtils ¶
func (CliUtils) GetAddressInfo ¶
func (cu CliUtils) GetAddressInfo(address string) (AddressInfo, error)
GetAddressInfo returns address info if string representation for address is valid or error
func (CliUtils) GetPolicyID ¶
GetPolicyID returns policy id
func (CliUtils) GetPolicyScriptAddress ¶
func (cu CliUtils) GetPolicyScriptAddress( testNetMagic uint, policyScript *PolicyScript, policyScriptStake ...*PolicyScript, ) (string, error)
GetPolicyScriptAddress get address for policy script
type IPolicyScript ¶
type ITxDataRetriever ¶
type ITxProvider ¶
type ITxProvider interface { ITxSubmitter ITxDataRetriever IUTxORetriever Dispose() }
type ITxRetriever ¶
type ITxSubmitter ¶
type IUTxORetriever ¶
type Key ¶
type Key struct { Type string `json:"type"` Description string `json:"description"` Hex string `json:"cborHex"` }
func (Key) GetKeyBytes ¶
func (Key) WriteToFile ¶
type PolicyScript ¶
type PolicyScript struct { Type string `json:"type"` Required int `json:"required,omitempty"` Scripts []PolicyScript `json:"scripts,omitempty"` KeyHash string `json:"keyHash,omitempty"` Slot uint64 `json:"slot,omitempty"` }
func NewPolicyScript ¶
func NewPolicyScript(keyHashes []string, atLeastSignersCount int) *PolicyScript
func (PolicyScript) GetCount ¶
func (ps PolicyScript) GetCount() (cnt int)
func (PolicyScript) GetPolicyScriptJSON ¶
func (ps PolicyScript) GetPolicyScriptJSON() ([]byte, error)
type ProtocolParameters ¶
type ProtocolParameters struct { CostModels map[string][]int64 `json:"costModels"` ProtocolVersion ProtocolParametersVersion `json:"protocolVersion"` MaxBlockHeaderSize uint64 `json:"maxBlockHeaderSize"` MaxBlockBodySize uint64 `json:"maxBlockBodySize"` MaxTxSize uint64 `json:"maxTxSize"` TxFeeFixed uint64 `json:"txFeeFixed"` TxFeePerByte uint64 `json:"txFeePerByte"` StakeAddressDeposit uint64 `json:"stakeAddressDeposit"` StakePoolDeposit uint64 `json:"stakePoolDeposit"` MinPoolCost uint64 `json:"minPoolCost"` PoolRetireMaxEpoch uint64 `json:"poolRetireMaxEpoch"` StakePoolTargetNum uint64 `json:"stakePoolTargetNum"` PoolPledgeInfluence float64 `json:"poolPledgeInfluence"` MonetaryExpansion float64 `json:"monetaryExpansion"` TreasuryCut float64 `json:"treasuryCut"` CollateralPercentage uint64 `json:"collateralPercentage"` ExecutionUnitPrices ProtocolParametersPriceMemorySteps `json:"executionUnitPrices"` UtxoCostPerByte uint64 `json:"utxoCostPerByte"` MaxTxExecutionUnits ProtocolParametersMemorySteps `json:"maxTxExecutionUnits"` MaxBlockExecutionUnits ProtocolParametersMemorySteps `json:"maxBlockExecutionUnits"` MaxCollateralInputs uint64 `json:"maxCollateralInputs"` MaxValueSize uint64 `json:"maxValueSize"` ExtraPraosEntropy *uint64 `json:"extraPraosEntropy"` Decentralization *uint64 `json:"decentralization"` MinUTxOValue *uint64 `json:"minUTxOValue"` }
type ProtocolParametersMemorySteps ¶
type ProtocolParametersMemorySteps struct { Memory uint64 `json:"memory"` Steps uint64 `json:"steps"` }
func NewProtocolParametersMemorySteps ¶
func NewProtocolParametersMemorySteps(memory, steps uint64) ProtocolParametersMemorySteps
type ProtocolParametersPriceMemorySteps ¶
type ProtocolParametersPriceMemorySteps struct { PriceMemory float64 `json:"priceMemory"` PriceSteps float64 `json:"priceSteps"` }
func NewProtocolParametersPriceMemorySteps ¶
func NewProtocolParametersPriceMemorySteps(memory, steps float64) ProtocolParametersPriceMemorySteps
type ProtocolParametersVersion ¶
func NewProtocolParametersVersion ¶
func NewProtocolParametersVersion(major, minor uint64) ProtocolParametersVersion
type QueryTipData ¶
type StakePointer ¶
type TokenAmount ¶
type TokenAmount struct { PolicyID string `json:"pid"` Name string `json:"nam"` // name must not be hex encoded Amount uint64 `json:"val"` }
func GetTokensFromSumMap ¶
func GetTokensFromSumMap(sum map[string]uint64, skipTokenNames ...string) (result []TokenAmount, err error)
GetTokensFromSumMap processes a map of token names to their quantities and returns a slice of TokenAmount objects
func NewTokenAmount ¶
func NewTokenAmount(policyID string, name string, amount uint64) TokenAmount
func NewTokenAmountWithFullName ¶
func NewTokenAmountWithFullName(name string, amount uint64, isNameEncoded bool) (TokenAmount, error)
func (TokenAmount) String ¶
func (tt TokenAmount) String() string
func (TokenAmount) TokenName ¶
func (tt TokenAmount) TokenName() string
type TxBuilder ¶
type TxBuilder struct {
// contains filtered or unexported fields
}
func NewTxBuilder ¶
func (*TxBuilder) AddInputsWithScript ¶
func (b *TxBuilder) AddInputsWithScript(script IPolicyScript, inputs ...TxInput) *TxBuilder
func (*TxBuilder) AddInputsWithScripts ¶
func (b *TxBuilder) AddInputsWithScripts(inputs []TxInput, scripts []IPolicyScript) *TxBuilder
func (*TxBuilder) AddOutputs ¶
func (*TxBuilder) AddTokenMints ¶
func (b *TxBuilder) AddTokenMints( policyScripts []IPolicyScript, tokens []TokenAmount, ) *TxBuilder
func (*TxBuilder) AssembleTxWitnesses ¶
AssembleTxWitnesses assembles final signed transaction
func (*TxBuilder) CheckOutputs ¶
func (*TxBuilder) RemoveOutput ¶
func (*TxBuilder) SetMetaData ¶
func (*TxBuilder) SetProtocolParameters ¶
func (*TxBuilder) SetProtocolParametersAndTTL ¶
func (*TxBuilder) SetTestNetMagic ¶
func (*TxBuilder) SetTimeToLive ¶
type TxInput ¶
func NewTxInput ¶
type TxOutput ¶
type TxOutput struct { Addr string `json:"addr"` Amount uint64 `json:"amount"` Tokens []TokenAmount `json:"token,omitempty"` }
func NewTxOutput ¶
func NewTxOutput(addr string, amount uint64, tokens ...TokenAmount) TxOutput
type TxProviderBlockFrost ¶
type TxProviderBlockFrost struct {
// contains filtered or unexported fields
}
func NewTxProviderBlockFrost ¶
func NewTxProviderBlockFrost(url string, projectID string) *TxProviderBlockFrost
func (*TxProviderBlockFrost) Dispose ¶
func (b *TxProviderBlockFrost) Dispose()
func (*TxProviderBlockFrost) GetProtocolParameters ¶
func (b *TxProviderBlockFrost) GetProtocolParameters(ctx context.Context) ([]byte, error)
func (*TxProviderBlockFrost) GetTip ¶
func (b *TxProviderBlockFrost) GetTip(ctx context.Context) (QueryTipData, error)
func (*TxProviderBlockFrost) GetTxByHash ¶
type TxProviderCli ¶
type TxProviderCli struct {
// contains filtered or unexported fields
}
func NewTxProviderCli ¶
func NewTxProviderCli(testNetMagic uint, socketPath string, cardanoCliBinary string) (*TxProviderCli, error)
func (*TxProviderCli) Dispose ¶
func (b *TxProviderCli) Dispose()
func (*TxProviderCli) GetProtocolParameters ¶
func (b *TxProviderCli) GetProtocolParameters(_ context.Context) ([]byte, error)
func (*TxProviderCli) GetTip ¶
func (b *TxProviderCli) GetTip(_ context.Context) (QueryTipData, error)
func (*TxProviderCli) GetTxByHash ¶
type TxProviderOgmios ¶
type TxProviderOgmios struct {
// contains filtered or unexported fields
}
func NewTxProviderOgmios ¶
func NewTxProviderOgmios(url string) *TxProviderOgmios
func (*TxProviderOgmios) Dispose ¶
func (o *TxProviderOgmios) Dispose()
Dispose implements ITxProvider.
func (*TxProviderOgmios) GetProtocolParameters ¶
func (o *TxProviderOgmios) GetProtocolParameters(ctx context.Context) ([]byte, error)
GetProtocolParameters implements ITxProvider.
func (*TxProviderOgmios) GetTip ¶
func (o *TxProviderOgmios) GetTip(ctx context.Context) (QueryTipData, error)
GetSlot implements ITxProvider.
func (*TxProviderOgmios) GetTxByHash ¶
type TxWitnessRaw ¶
type TxWitnessRaw []byte // cbor slice of bytes
func (TxWitnessRaw) GetSignatureAndVKey ¶
func (w TxWitnessRaw) GetSignatureAndVKey() ([]byte, []byte, error)
func (TxWitnessRaw) ToJSON ¶
func (w TxWitnessRaw) ToJSON() ([]byte, error)
type Utxo ¶
type Utxo struct { Hash string `json:"hsh"` Index uint32 `json:"ind"` Amount uint64 `json:"amount"` Tokens []TokenAmount `json:"tokens,omitempty"` }
type Wallet ¶
type Wallet struct { VerificationKey []byte `json:"vkey"` SigningKey []byte `json:"skey"` StakeVerificationKey []byte `json:"vstake"` StakeSigningKey []byte `json:"sstake"` }
func GenerateWallet ¶
GenerateWallet generates wallet
func NewStakeWallet ¶
func (Wallet) GetTransactionVerificationKey ¶
Source Files ¶
- address.go
- address_types.go
- cli_utils.go
- command_helper.go
- data.go
- network_type.go
- policy_script.go
- protocol_parameters.go
- transaction.go
- transaction_extended.go
- txprovider_blockfrost.go
- txprovider_cli.go
- txprovider_ogmios.go
- txprovider_ogmios_types.go
- txwitness.go
- utils.go
- wallet.go
- wallet_utils.go