arklib

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: MIT Imports: 16 Imported by: 18

Documentation

Index

Constants

View Source
const (
	SEQUENCE_LOCKTIME_MASK         = 0x0000ffff
	SEQUENCE_LOCKTIME_TYPE_FLAG    = 1 << 22
	SEQUENCE_LOCKTIME_GRANULARITY  = 9
	SECONDS_MOD                    = 1 << SEQUENCE_LOCKTIME_GRANULARITY
	SECONDS_MAX                    = SEQUENCE_LOCKTIME_MASK << SEQUENCE_LOCKTIME_GRANULARITY
	SEQUENCE_LOCKTIME_DISABLE_FLAG = 1 << 31

	SECONDS_PER_BLOCK = 10 * 60 // 10 minutes

)

Variables

View Source
var Bitcoin = Network{
	Name: "bitcoin",
	Addr: "ark",
}
View Source
var BitcoinMutinyNet = Network{
	Name: "mutinynet",
	Addr: BitcoinTestNet.Addr,
}
View Source
var BitcoinRegTest = Network{
	Name: "regtest",
	Addr: BitcoinTestNet.Addr,
}
View Source
var BitcoinSigNet = Network{
	Name: "signet",
	Addr: BitcoinTestNet.Addr,
}
View Source
var BitcoinTestNet = Network{
	Name: "testnet",
	Addr: "tark",
}
View Source
var BitcoinTestNet4 = Network{
	Name: "testnet4",
	Addr: BitcoinTestNet.Addr,
}
View Source
var MutinyNetSigNetParams = func() chaincfg.Params {
	params := chaincfg.CustomSignetParams(mutinyNetChallenge, nil)
	params.TargetTimePerBlock = mutinyNetBlockTime
	return params
}()

Functions

func AppDataDir

func AppDataDir(appName string, roaming bool) string

AppDataDir returns an operating system specific directory to be used for storing application data for an application.

The appName parameter is the name of the application the data directory is being requested for. This function will prepend a period to the appName for POSIX style operating systems since that is standard practice. An empty appName or one with a single dot is treated as requesting the current directory so only "." will be returned. Further, the first character of appName will be made lowercase for POSIX style operating systems and uppercase for Mac and Windows since that is standard practice.

The roaming parameter only applies to Windows where it specifies the roaming application data profile (%APPDATA%) should be used instead of the local one (%LOCALAPPDATA%) that is used by default.

Example results:

dir := AppDataDir("myapp", false)
 POSIX (Linux/BSD): ~/.myapp
 Mac OS: $HOME/Library/Application Support/Myapp
 Windows: %LOCALAPPDATA%\Myapp
 Plan 9: $home/myapp

func BIP68Sequence

func BIP68Sequence(locktime RelativeLocktime) (uint32, error)

Types

type AbsoluteLocktime

type AbsoluteLocktime uint32

AbsoluteLocktime represents an nLocktime value it is used as argument to a CheckLocktimeVerify opcode

func (AbsoluteLocktime) IsSeconds

func (l AbsoluteLocktime) IsSeconds() bool

type Address

type Address struct {
	Version    uint8
	HRP        string
	Signer     *btcec.PublicKey
	VtxoTapKey *btcec.PublicKey
}

Address represents an Ark address with Version, prefix, signer public key, and VTXO taproot key.

func DecodeAddressV0

func DecodeAddressV0(addr string) (*Address, error)

DecodeAddressV0 parses a bech32m encoded address string and returns an Address struct.

func (*Address) EncodeV0

func (a *Address) EncodeV0() (string, error)

EncodeV0 converts the address to its bech32m string representation.

func (*Address) GetPkScript added in v0.7.1

func (a *Address) GetPkScript() ([]byte, error)

type Network

type Network struct {
	Name string
	Addr string
}

type RelativeLocktime

type RelativeLocktime struct {
	Type  RelativeLocktimeType
	Value uint32
}

RelativeLocktime represents a BIP68 relative timelock value

func BIP68DecodeSequence

func BIP68DecodeSequence(sequenceNum uint32) (*RelativeLocktime, bool)

func BIP68DecodeSequenceFromBytes

func BIP68DecodeSequenceFromBytes(sequence []byte) (*RelativeLocktime, error)

func (RelativeLocktime) Compare

func (l RelativeLocktime) Compare(other RelativeLocktime) int

func (RelativeLocktime) LessThan

func (l RelativeLocktime) LessThan(other RelativeLocktime) bool

LessThan returns true if this locktime is less than the other locktime

func (RelativeLocktime) Seconds

func (l RelativeLocktime) Seconds() int64

type RelativeLocktimeType

type RelativeLocktimeType uint

RelativeLocktimeType represents a BIP68 relative locktime it is passed as argument to CheckSequenceVerify opcode

const (
	LocktimeTypeSecond RelativeLocktimeType = iota
	LocktimeTypeBlock
)

type TaprootMerkleProof

type TaprootMerkleProof struct {
	ControlBlock []byte
	Script       []byte
}

func BiggestLeafMerkleProof

func BiggestLeafMerkleProof(t TaprootTree) (*TaprootMerkleProof, error)

BiggestLeafMerkleProof returns the leaf with the biggest witness size (for fee estimation) we need this to estimate the fee without knowing the exact leaf that will be spent

type TaprootTree

type TaprootTree interface {
	GetLeaves() []chainhash.Hash
	GetTaprootMerkleProof(leafhash chainhash.Hash) (*TaprootMerkleProof, error)
	GetRoot() chainhash.Hash
}

TaprootTree is an interface wrapping the methods needed to spend a vtxo taproot contract

type VtxoScript

type VtxoScript[T TaprootTree, C interface{}] interface {
	Validate(signer *btcec.PublicKey, minLocktime RelativeLocktime, blockTypeAllowed bool) error
	TapTree() (taprootKey *btcec.PublicKey, taprootScriptTree T, err error)
	Encode() ([]string, error)
	Decode(scripts []string) error
	SmallestExitDelay() (*RelativeLocktime, error)
	ForfeitClosures() []C
	ExitClosures() []C
}

VtxoScript abstracts the taproot complexity behind vtxo contracts.

A vtxo script is defined as a taproot contract with at least 1 collaborative closure (A + S) and 1 exit closure (A after t). It may also contain others closures implementing specific use cases.

TODO: gather common and tree package to prevent circular dependency and move C generic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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