core

package
v0.0.0-...-fcb70ce Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const FilePermission = 0750
View Source
const MainnetMagic = uint(764824073)
View Source
const (
	MinUTxODefaultValue = uint64(1000000)
)

Variables

View Source
var (
	ErrInvalidSignature          = errors.New("invalid signature")
	ErrInvalidAddressInfo        = errors.New("invalid address info")
	ErrWaitForTransactionTimeout = errors.New("timeout while waiting for transaction")
)

Functions

func AssembleTxWitnesses

func AssembleTxWitnesses(txRaw []byte, witnesses [][]byte) ([]byte, error)

AssembleTxWitnesses assembles final signed transaction

func CreateTxWitness

func CreateTxWitness(txHash string, wallet ISigner) ([]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 GetKeyHash

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

GetKeyHash gets Cardano key hash from verification key

func GetKeyHashCli

func GetKeyHashCli(verificationKeyPath string) (string, error)

func GetOutputsSum

func GetOutputsSum(outputs []TxOutput) (receiversSum uint64)

func GetTxHash

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

GetTxHash gets hash from transaction cbor slice

func GetVerificationKeyFromSigningKey

func GetVerificationKeyFromSigningKey(signingKey []byte) []byte

GetVerificationKeyFromSigningKey retrieves verification/public key from signing/private key

func GetWalletAddress

func GetWalletAddress(wallet IWallet, testNetMagic uint) (addr string, stakeAddr string, err error)

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

func SaveKeyBytesToFile

func SaveKeyBytesToFile(keyBytes []byte, filePath string, isSigningKey bool, isStakeKey bool) error

func SignMessage

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

SignMessage signs message

func SignTx

func SignTx(txRaw []byte, txHash string, wallet ISigner) ([]byte, error)

SignTx creates witness and assembles it to final tx

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

func WaitForTransaction

func WaitForTransaction(ctx context.Context, txRetriever ITxRetriever,
	hash string, numRetries int, waitTime time.Duration) (map[string]interface{}, error)

WaitForTransaction waits for transaction to be included in block

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"`
}

func GetAddressInfo

func GetAddressInfo(address string) (AddressInfo, error)

GetAddressInfo returns address info if string representation for address is valid or error

type IPolicyScript

type IPolicyScript interface {
	GetPolicyScript() []byte
	GetCount() int
}

type ISigner

type ISigner interface {
	GetSigningKey() []byte
	GetVerificationKey() []byte
}

type IStakeSigner

type IStakeSigner interface {
	ISigner
	GetStakeSigningKey() []byte
	GetStakeVerificationKey() []byte
}

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 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 IWallet

type IWallet interface {
	IStakeSigner
	GetKeyHash() string
}

type IWalletManager

type IWalletManager interface {
	// Create creates new wallet
	Create(directory string, forceCreate bool) (IWallet, error)
	// Load loads wallet
	Load(directory string) (IWallet, 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 {
	PolicyScript []byte `json:"ps"`
	Count        int    `json:"cnt"`
}

func NewPolicyScript

func NewPolicyScript(keyHashes []string, atLeastSignersCount int) (*PolicyScript, error)

func NewPolicyScriptFromKeyHash

func NewPolicyScriptFromKeyHash(keyHash string) (*PolicyScript, error)

func (PolicyScript) CreateMultiSigAddress

func (ps PolicyScript) CreateMultiSigAddress(testNetMagic uint) (string, error)

func (PolicyScript) GetCount

func (ps PolicyScript) GetCount() int

func (PolicyScript) GetPolicyID

func (ps PolicyScript) GetPolicyID() (string, error)

func (PolicyScript) GetPolicyScript

func (ps PolicyScript) GetPolicyScript() []byte

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 StakeWalletManager

type StakeWalletManager struct {
}

func NewStakeWalletManager

func NewStakeWalletManager() *StakeWalletManager

func (*StakeWalletManager) Create

func (w *StakeWalletManager) Create(directory string, forceCreate bool) (IWallet, error)

func (*StakeWalletManager) Load

func (w *StakeWalletManager) Load(directory string) (IWallet, error)

type TransactionUnwitnessedRaw

type TransactionUnwitnessedRaw []byte

func NewTransactionUnwitnessedRawFromJSON

func NewTransactionUnwitnessedRawFromJSON(bytes []byte) (TransactionUnwitnessedRaw, error)

func (TransactionUnwitnessedRaw) ToJSON

func (tx TransactionUnwitnessedRaw) ToJSON() ([]byte, error)

type TransactionWitnessedRaw

type TransactionWitnessedRaw []byte

func NewTransactionWitnessedRawFromJSON

func NewTransactionWitnessedRawFromJSON(bytes []byte) (TransactionWitnessedRaw, error)

func (TransactionWitnessedRaw) ToJSON

func (tx TransactionWitnessedRaw) ToJSON() ([]byte, error)

type TxBuilder

type TxBuilder struct {
	// contains filtered or unexported fields
}

func NewTxBuilder

func NewTxBuilder() (*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) Build

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

func (*TxBuilder) CalculateFee

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

func (*TxBuilder) Dispose

func (b *TxBuilder) Dispose()

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

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

type TxInput

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

func (TxInput) String

func (i TxInput) String() string

type TxInputWithPolicyScript

type TxInputWithPolicyScript struct {
	Input        TxInput
	PolicyScript IPolicyScript
}

type TxInputs

type TxInputs struct {
	Inputs []TxInput
	Sum    uint64
}

func GetUTXOs

func GetUTXOs(ctx context.Context, retriever IUTxORetriever, addr string, desired uint64) (TxInputs, error)

func GetUTXOsForAmount

func GetUTXOsForAmount(ctx context.Context, retriever IUTxORetriever, addr string, desired uint64) (TxInputs, error)

type TxOutput

type TxOutput struct {
	Addr   string `json:"addr"`
	Amount uint64 `json:"amount"`
}

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, error)

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) (*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) GetUtxos

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

func (*TxProviderCli) SubmitTx

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

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"`
}

type Wallet

type Wallet struct {
	VerificationKey      []byte `json:"verificationKey"`
	SigningKey           []byte `json:"signingKey"`
	KeyHash              string `json:"keyHash"`
	StakeVerificationKey []byte `json:"stakeVerificationKey"`
	StakeSigningKey      []byte `json:"stakeSigningKey"`
}

func NewStakeWallet

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

func NewWallet

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

func (Wallet) GetKeyHash

func (w Wallet) GetKeyHash() string

func (Wallet) GetSigningKey

func (w Wallet) GetSigningKey() []byte

func (Wallet) GetStakeSigningKey

func (w Wallet) GetStakeSigningKey() []byte

func (Wallet) GetStakeVerificationKey

func (w Wallet) GetStakeVerificationKey() []byte

func (Wallet) GetVerificationKey

func (w Wallet) GetVerificationKey() []byte

type WalletManager

type WalletManager struct {
}

func NewWalletManager

func NewWalletManager() *WalletManager

func (*WalletManager) Create

func (w *WalletManager) Create(directory string, forceCreate bool) (IWallet, error)

func (*WalletManager) Load

func (w *WalletManager) Load(directory string) (IWallet, error)

Jump to

Keyboard shortcuts

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