core

package
v0.0.0-...-a6def7b Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdaTokenPolicyID = "ada"
	AdaTokenName     = "lovelace"
)
View Source
const (
	TestNetProtocolMagic = uint(1097911063)
	MainNetProtocolMagic = uint(764824073)

	MainNetNetwork CardanoNetworkType = 1
	TestNetNetwork CardanoNetworkType = 0
)
View Source
const (
	PolicyScriptAtLeastType = "atLeast"
	PolicyScriptSigType     = "sig"
)
View Source
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"
)
View Source
const FilePermission = 0750

Variables

View Source
var (
	ErrUnsupportedAddress = errors.New("invalid/unsupported address type")
	ErrInvalidAddressData = errors.New("invalid address data")
)
View Source
var ErrInvalidSignature = errors.New("invalid signature")

Functions

func CreateTxWitness

func CreateTxWitness(txHash string, signer ITxSigner) ([]byte, error)

CreateTxWitness signs transaction hash and creates witness cbor

func GenerateKeyPair

func GenerateKeyPair() ([]byte, []byte, error)

GenerateKeyPair generates ed25519 (signing key, verifying) key pair

func GetKeyBytes

func GetKeyBytes(key string) (result []byte, err error)

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

func GetKeyHash(bytes []byte) (string, error)

GetKeyHash gets Cardano key hash string from arbitrary key

func GetKeyHashBytes

func GetKeyHashBytes(bytes []byte) ([]byte, error)

GetKeyHashBytes gets Cardano key hash from arbitrary bytes

func GetOutputsSum

func GetOutputsSum(outputs []TxOutput) map[string]uint64

GetOutputsSum returns sum or tokens in outputs (including lovelace)

func GetUtxosSum

func GetUtxosSum(utxos []Utxo) map[string]uint64

GetUtxosSum returns sum for tokens in utxos (including lovelace)

func GetVerificationKeyFromSigningKey

func GetVerificationKeyFromSigningKey(signingKey []byte) []byte

GetVerificationKeyFromSigningKey retrieves verification/public key from signing/private key

func IsAddressWithValidPrefix

func IsAddressWithValidPrefix(addr string) bool

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 PadKeyToSize

func PadKeyToSize(key []byte) []byte

PadKeyToSize pads key to 32 bytes

func ResolveCardanoCliBinary

func ResolveCardanoCliBinary(_ CardanoNetworkType) string

func SignMessage

func SignMessage(signingKey, verificationKey, message []byte) (result []byte, err error)

SignMessage signs message

func VerifyMessage

func VerifyMessage(message, verificationKey, signature []byte) (err error)

VerifyMessage verifies message with verificationKey and signature

func VerifyWitness

func VerifyWitness(txHash string, witness []byte) error

VerifyWitness verifies if txHash is signed by witness

Types

type AddressInfo

type AddressInfo struct {
	Address  string `json:"address"`
	Base16   string `json:"base16"`
	Encoding string `json:"encoding"`
	Era      string `json:"era"`
	Type     string `json:"type"`
}

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 NewCliUtils(cardanoCliBinary string) CliUtils

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) GetKeyHash

func (cu CliUtils) GetKeyHash(key []byte) (string, error)

func (CliUtils) GetPolicyID

func (cu CliUtils) GetPolicyID(policyScript any) (string, error)

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

func (CliUtils) GetTxHash

func (cu CliUtils) GetTxHash(txRaw []byte) (string, error)

GetTxHash gets hash from transaction cbor slice

func (CliUtils) GetWalletAddress

func (cu CliUtils) GetWalletAddress(
	verificationKey, stakeVerificationKey []byte, testNetMagic uint,
) (addr string, stakeAddr string, err error)

GetWalletAddress returns address and stake address for wallet (if wallet is stake wallet)

type IPolicyScript

type IPolicyScript interface {
	GetPolicyScriptJSON() ([]byte, error)
	GetCount() int
}

type ITxDataRetriever

type ITxDataRetriever interface {
	GetTip(ctx context.Context) (QueryTipData, error)
	GetProtocolParameters(ctx context.Context) ([]byte, error)
}

type ITxProvider

type ITxProvider interface {
	ITxSubmitter
	ITxDataRetriever
	IUTxORetriever
	Dispose()
}

type ITxRetriever

type ITxRetriever interface {
	GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)
}

type ITxSigner

type ITxSigner interface {
	SignTransaction([]byte) ([]byte, error)
	GetTransactionVerificationKey() []byte
}

type ITxSubmitter

type ITxSubmitter interface {
	// SubmitTx submits transaction - txSigned should be cbor serialized signed transaction
	SubmitTx(ctx context.Context, txSigned []byte) error
}

type IUTxORetriever

type IUTxORetriever interface {
	GetUtxos(ctx context.Context, addr string) ([]Utxo, error)
}

type Key

type Key struct {
	Type        string `json:"type"`
	Description string `json:"description"`
	Hex         string `json:"cborHex"`
}

func NewKey

func NewKey(filePath string) (Key, error)

func NewKeyFromBytes

func NewKeyFromBytes(keyType string, desc string, bytes []byte) (Key, error)

func (Key) GetKeyBytes

func (k Key) GetKeyBytes() ([]byte, error)

func (Key) WriteToFile

func (k Key) WriteToFile(filePath string) error

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

type ProtocolParametersVersion struct {
	Major uint64 `json:"major"`
	Minor uint64 `json:"minor"`
}

func NewProtocolParametersVersion

func NewProtocolParametersVersion(major, minor uint64) ProtocolParametersVersion

type QueryTipData

type QueryTipData struct {
	Block           uint64 `json:"block"`
	Epoch           uint64 `json:"epoch"`
	Era             string `json:"era"`
	Hash            string `json:"hash"`
	Slot            uint64 `json:"slot"`
	SlotInEpoch     uint64 `json:"slotInEpoch"`
	SlotsToEpochEnd uint64 `json:"slotsToEpochEnd"`
	SyncProgress    string `json:"syncProgress"`
}

type StakePointer

type StakePointer struct {
	Slot      uint64
	TxIndex   uint64
	CertIndex uint64
}

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 NewTxBuilder(cardanoCliBinary string) (*TxBuilder, error)

func (*TxBuilder) AddInputs

func (b *TxBuilder) AddInputs(inputs ...TxInput) *TxBuilder

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 (b *TxBuilder) AddOutputs(outputs ...TxOutput) *TxBuilder

func (*TxBuilder) AddTokenMints

func (b *TxBuilder) AddTokenMints(
	policyScripts []IPolicyScript, tokens []TokenAmount,
) *TxBuilder

func (*TxBuilder) AssembleTxWitnesses

func (b *TxBuilder) AssembleTxWitnesses(txRaw []byte, witnesses [][]byte) ([]byte, error)

AssembleTxWitnesses assembles final signed transaction

func (*TxBuilder) Build

func (b *TxBuilder) Build() ([]byte, string, error)

func (*TxBuilder) CalculateFee

func (b *TxBuilder) CalculateFee(witnessCount int) (uint64, error)

func (*TxBuilder) CheckOutputs

func (b *TxBuilder) CheckOutputs() error

func (*TxBuilder) Dispose

func (b *TxBuilder) Dispose()

func (*TxBuilder) RemoveOutput

func (b *TxBuilder) RemoveOutput(index int) *TxBuilder

func (*TxBuilder) SetFee

func (b *TxBuilder) SetFee(fee uint64) *TxBuilder

func (*TxBuilder) SetMetaData

func (b *TxBuilder) SetMetaData(metadata []byte) *TxBuilder

func (*TxBuilder) SetProtocolParameters

func (b *TxBuilder) SetProtocolParameters(protocolParameters []byte) *TxBuilder

func (*TxBuilder) SetProtocolParametersAndTTL

func (b *TxBuilder) SetProtocolParametersAndTTL(
	ctx context.Context, retriever ITxDataRetriever, timeToLiveInc uint64,
) error

func (*TxBuilder) SetTestNetMagic

func (b *TxBuilder) SetTestNetMagic(testNetMagic uint) *TxBuilder

func (*TxBuilder) SetTimeToLive

func (b *TxBuilder) SetTimeToLive(timeToLive uint64) *TxBuilder

func (*TxBuilder) SignTx

func (b *TxBuilder) SignTx(txRaw []byte, signers []ITxSigner) ([]byte, error)

SignTx signs tx and assembles all signatures in final tx

func (*TxBuilder) UpdateOutputAmount

func (b *TxBuilder) UpdateOutputAmount(index int, amount uint64, tokenAmounts ...uint64) *TxBuilder

type TxInput

type TxInput struct {
	Hash  string `json:"hsh"`
	Index uint32 `json:"ind"`
}

func NewTxInput

func NewTxInput(hash string, index uint32) TxInput

func (TxInput) String

func (i TxInput) String() string

type TxInputs

type TxInputs struct {
	Inputs []TxInput
	Sum    map[string]uint64
}

func GetUTXOsForAmount

func GetUTXOsForAmount(
	ctx context.Context,
	retriever IUTxORetriever,
	addr string,
	tokenNames []string,
	exactSum map[string]uint64,
	atLeastSum map[string]uint64,
) (TxInputs, error)

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

func (TxOutput) String

func (o TxOutput) String() string

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 (*TxProviderBlockFrost) GetTxByHash

func (b *TxProviderBlockFrost) GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)

func (*TxProviderBlockFrost) GetUtxos

func (b *TxProviderBlockFrost) GetUtxos(ctx context.Context, addr string) ([]Utxo, error)

func (*TxProviderBlockFrost) SubmitTx

func (b *TxProviderBlockFrost) SubmitTx(ctx context.Context, txSigned []byte) error

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 (*TxProviderCli) GetTxByHash

func (b *TxProviderCli) GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)

func (*TxProviderCli) GetUtxos

func (b *TxProviderCli) GetUtxos(_ context.Context, addr string) ([]Utxo, error)

func (*TxProviderCli) SubmitTx

func (b *TxProviderCli) SubmitTx(_ context.Context, txSigned []byte) error

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

GetSlot implements ITxProvider.

func (*TxProviderOgmios) GetTxByHash

func (o *TxProviderOgmios) GetTxByHash(ctx context.Context, hash string) (map[string]interface{}, error)

func (*TxProviderOgmios) GetUtxos

func (o *TxProviderOgmios) GetUtxos(ctx context.Context, addr string) ([]Utxo, error)

GetUtxos implements ITxProvider.

func (*TxProviderOgmios) SubmitTx

func (o *TxProviderOgmios) SubmitTx(ctx context.Context, txSigned []byte) error

Expects TxCborString

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

func GenerateWallet(isStake bool) (*Wallet, error)

GenerateWallet generates wallet

func NewStakeWallet

func NewStakeWallet(verificationKey []byte, signingKey []byte,
	stakeVerificationKey []byte, stakeSigningKey []byte) *Wallet

func NewWallet

func NewWallet(verificationKey []byte, signingKey []byte) *Wallet

func (Wallet) GetTransactionVerificationKey

func (w Wallet) GetTransactionVerificationKey() []byte

func (Wallet) SignTransaction

func (w Wallet) SignTransaction(txRaw []byte) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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