runes

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Apostrophe uint32 = 0x80000000 // 0'
)
View Source
const HashLength = 32
View Source
const (
	MaxStandardTxWeight = blockchain.MaxBlockWeight / 10
)

Variables

View Source
var ZeroHash = Hash{}

Functions

func BuildEtchingCompleteRevealTx

func BuildEtchingCompleteRevealTx(etching *runestone.Etching, feeRate int64, privateKey string, commitTxHash string, toAddr string, network *chaincfg.Params) ([]byte, int64, string, error)

func BuildEtchingDummyRevealTx

func BuildEtchingDummyRevealTx(etching *runestone.Etching, feeRate int64, privateKey string, toAddr string, network *chaincfg.Params) (int64, string, error)

func BuildEtchingTxs

func BuildEtchingTxs(etching *runestone.Etching, feeRate int64, privateKey string, network *chaincfg.Params) ([]byte, []byte, int64, string, error)

func BuildInscriptionTxs

func BuildInscriptionTxs(privateKey *btcec.PrivateKey, utxo []*Utxo, mime string, content []byte, feeRate int64, revealValue int64, net *chaincfg.Params, inscriptionAddData []byte, opReturnData []byte) ([]byte, []byte, int64, error)

func BuildRuneEtchingCompleteRevealTx

func BuildRuneEtchingCompleteRevealTx(privateKey *btcec.PrivateKey, runeOpReturnData []byte, runeCommitment []byte,
	feeRate int64, revealValue int64, net *chaincfg.Params, toAddr string, commitTxHash string) ([]byte, int64, string, error)

func BuildRuneEtchingDummyRevealTx

func BuildRuneEtchingDummyRevealTx(privateKey *btcec.PrivateKey, runeOpReturnData []byte, runeCommitment []byte,
	feeRate int64, revealValue int64, net *chaincfg.Params, toAddr string) (int64, string, error)

func BuildRuneEtchingTxs

func BuildRuneEtchingTxs(privateKey *btcec.PrivateKey, utxo []*Utxo, runeOpReturnData []byte, runeCommitment []byte,
	feeRate int64, revealValue int64, net *chaincfg.Params, toAddr string) ([]byte, []byte, int64, string, error)

func BuildTransferBTCTx

func BuildTransferBTCTx(privateKey *btcec.PrivateKey, utxo []*Utxo, toAddr string, toAmount, feeRate int64, net *chaincfg.Params, runeData []byte) ([]byte, error)

func CreateCommitmentScript

func CreateCommitmentScript(pk *btcec.PublicKey, commitment []byte) ([]byte, error)

func CreateInscriptionScript

func CreateInscriptionScript(pk *btcec.PublicKey, contentType string, fileBytes []byte, inscriptionAddData []byte) ([]byte, error)

func FromHex

func FromHex(s string) []byte

FromHex returns the bytes represented by the hexadecimal string s. s may be prefixed with "0x".

func Generate

func Generate(compress bool) (wif, address, segwitBech32, segwitNested, p2tr string, err error)

func GenerateFromBytes

func GenerateFromBytes(prvKey *btcec.PrivateKey, compress bool) (wif, address, segwitBech32, segwitNested, p2tr string, err error)

func GetInscriptionContent

func GetInscriptionContent(tx *wire.MsgTx) (contentType string, content []byte, err error)

func GetOrdinalsContent

func GetOrdinalsContent(tapScript []byte) (mime string, content []byte, err error)

func GetP2TRAddress

func GetP2TRAddress(pubKey *btcec.PublicKey, net *chaincfg.Params) (string, error)

GetP2TRAddress returns a taproot address for a given public key.

func GetPrivateKeyAddr

func GetPrivateKeyAddr(privateKey string, network *chaincfg.Params) (*btcec.PrivateKey, string, error)

func GetTapScriptAddress

func GetTapScriptAddress(pk *btcec.PublicKey, revealedScript []byte, net *chaincfg.Params) (btcutil.Address, error)

func GetTaprootPubkey

func GetTaprootPubkey(pubkey *btcec.PublicKey, revealedScript []byte) (*btcec.PublicKey, error)

func GetUtilP2TRAddress

func GetUtilP2TRAddress(pubKey *btcec.PublicKey, net *chaincfg.Params) (btcutil.Address, error)

func Hex2Bytes

func Hex2Bytes(str string) []byte

Hex2Bytes returns the bytes represented by the hexadecimal string str.

func IsOrdinalsScript

func IsOrdinalsScript(script []byte) bool

func IsTapScript

func IsTapScript(witness wire.TxWitness) bool

func SendRevealTx

func SendRevealTx(connector *MempoolConnector, rtx []byte) error

func SendTx

func SendTx(connector *MempoolConnector, ctx []byte, rtx []byte) error

func VerifyTx

func VerifyTx(rawTx string, prevTxOutScript []byte, prevTxOutValue int64) error

Types

type BtcTxInfo

type BtcTxInfo struct {
	Tx            *wire.MsgTx
	BlockHeight   uint64
	BlockHash     Hash
	BlockTime     uint64
	Confirmations uint64
	TxIndex       uint64
}

type CoinType

type CoinType = uint32

CoinType SLIP-0044 : Registered coin types for BIP-0044 https://github.com/satoshilabs/slips/blob/master/slip-0044.md

const (
	CoinTypeBTC CoinType = 0x80000000
	CoinTypeLTC CoinType = 0x80000002
	CoinTypeETH CoinType = 0x8000003c
	CoinTypeEOS CoinType = 0x800000c2
)

type Hash

type Hash [HashLength]byte

func BytesToHash

func BytesToHash(b []byte) Hash

BytesToHash sets b to hash. If b is larger than len(h), b will be cropped from the left.

func HexToHash

func HexToHash(s string) Hash

func (Hash) BtcString

func (hash Hash) BtcString() string

BtcString returns the Hash as the hexadecimal string of the byte-reversed hash.

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

func (Hash) String

func (h Hash) String() string

type Key

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

func (*Key) Encode

func (k *Key) Encode(compress bool) (wif, address, segwitBech32, segwitNested, p2tr string, err error)

func (*Key) GetPath

func (k *Key) GetPath() string

type KeyManager

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

func NewKeyManager

func NewKeyManager(bitSize int, passphrase, mnemonic string) (*KeyManager, error)

NewKeyManager return new key manager bitSize has to be a multiple 32 and be within the inclusive range of {128, 256} 128: 12 phrases 256: 24 phrases

func (*KeyManager) GetAccountKey

func (km *KeyManager) GetAccountKey(purpose, coinType, account uint32) (*bip32.Key, error)

func (*KeyManager) GetChangeKey

func (km *KeyManager) GetChangeKey(purpose, coinType, account, change uint32) (*bip32.Key, error)

GetChangeKey ... https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change change constant 0 is used for external chain change constant 1 is used for internal chain (also known as change addresses)

func (*KeyManager) GetCoinTypeKey

func (km *KeyManager) GetCoinTypeKey(purpose, coinType uint32) (*bip32.Key, error)

func (*KeyManager) GetKey

func (km *KeyManager) GetKey(purpose, coinType, account, change, index uint32) (*Key, error)

func (*KeyManager) GetMasterKey

func (km *KeyManager) GetMasterKey() (*bip32.Key, error)

func (*KeyManager) GetMnemonic

func (km *KeyManager) GetMnemonic() string

func (*KeyManager) GetPassphrase

func (km *KeyManager) GetPassphrase() string

func (*KeyManager) GetPurposeKey

func (km *KeyManager) GetPurposeKey(purpose uint32) (*bip32.Key, error)

func (*KeyManager) GetSeed

func (km *KeyManager) GetSeed() []byte

type MempoolConnector

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

func NewMempoolConnector

func NewMempoolConnector() *MempoolConnector

func (MempoolConnector) GetBalance

func (m MempoolConnector) GetBalance(address string) (uint64, error)

func (MempoolConnector) GetBlockByHash

func (m MempoolConnector) GetBlockByHash(blockHash Hash) (*wire.MsgBlock, error)

func (MempoolConnector) GetBlockByHeight

func (m MempoolConnector) GetBlockByHeight(height uint64) (*wire.MsgBlock, error)

func (MempoolConnector) GetBlockHashByHeight

func (m MempoolConnector) GetBlockHashByHeight(height uint64) ([]byte, error)

func (MempoolConnector) GetBlockHeight

func (m MempoolConnector) GetBlockHeight() (uint64, error)

func (MempoolConnector) GetBlockTxIDS

func (m MempoolConnector) GetBlockTxIDS(bh Hash) ([]Hash, error)

func (MempoolConnector) GetHeaderByHash

func (m MempoolConnector) GetHeaderByHash(h Hash) (*wire.BlockHeader, error)

func (MempoolConnector) GetRawTxByHash

func (m MempoolConnector) GetRawTxByHash(hash string) (*wire.MsgTx, error)

func (MempoolConnector) GetTxByHash

func (m MempoolConnector) GetTxByHash(hash string) (*BtcTxInfo, error)

func (MempoolConnector) GetUtxos

func (m MempoolConnector) GetUtxos(address string) ([]*Utxo, error)

func (MempoolConnector) SendRawTransaction

func (m MempoolConnector) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool) (*chainhash.Hash, error)

type Purpose

type Purpose = uint32

Purpose BIP43 - Purpose Field for Deterministic Wallets https://github.com/bitcoin/bips/blob/master/bip-0043.mediawiki

Purpose is a constant set to 44' (or 0x8000002C) following the BIP43 recommendation. It indicates that the subtree of this node is used according to this specification.

What does 44' mean in BIP44? https://bitcoin.stackexchange.com/questions/74368/what-does-44-mean-in-bip44

44' means that hardened keys should be used. The distinguisher for whether a key a given index is hardened is that the index is greater than 2^31, which is 2147483648. In hex, that is 0x80000000. That is what the apostrophe (') means. The 44 comes from adding it to 2^31 to get the final hardened key index. In hex, 44 is 2C, so 0x80000000 + 0x2C = 0x8000002C.

const (
	PurposeBIP44 Purpose = 0x8000002C // 44' BIP44
	PurposeBIP49 Purpose = 0x80000031 // 49' BIP49
	PurposeBIP84 Purpose = 0x80000054 // 84' BIP84
)

type Utxo

type Utxo struct {
	TxHash   Hash
	Index    uint32
	Value    int64
	PkScript []byte
}

func (*Utxo) OutPoint

func (u *Utxo) OutPoint() wire.OutPoint

func (*Utxo) String

func (u *Utxo) String() string

func (*Utxo) TxOut

func (u *Utxo) TxOut() *wire.TxOut

type UtxoList

type UtxoList []*Utxo

func (UtxoList) Add

func (l UtxoList) Add(utxo *Utxo) UtxoList

func (UtxoList) FetchPrevOutput

func (l UtxoList) FetchPrevOutput(o wire.OutPoint) *wire.TxOut

Jump to

Keyboard shortcuts

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