outscript

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 16 Imported by: 0

README

outscript

Generate potential outscripts for a given public key.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Formats = map[string]Format{
		"p2pkh":  Format{Bytes{0x76, 0xa9}, IPushBytes{IHash160(IPubKeyComp)}, Bytes{0x88, 0xac}},
		"p2pukh": Format{Bytes{0x76, 0xa9}, IPushBytes{IHash160(IPubKey)}, Bytes{0x88, 0xac}},
		"p2pk":   Format{IPushBytes{IPubKeyComp}, Bytes{0xac}},
		"p2puk":  Format{IPushBytes{IPubKey}, Bytes{0xac}},
		"p2wpkh": Format{Bytes{0}, IPushBytes{IHash160(IPubKeyComp)}},

		"p2sh:p2pkh":  Format{Bytes{0xa9}, IPushBytes{IHash160(Lookup("p2pkh"))}, Bytes{0x87}},
		"p2sh:p2pukh": Format{Bytes{0xa9}, IPushBytes{IHash160(Lookup("p2pukh"))}, Bytes{0x87}},
		"p2sh:p2pk":   Format{Bytes{0xa9}, IPushBytes{IHash160(Lookup("p2pk"))}, Bytes{0x87}},
		"p2sh:p2puk":  Format{Bytes{0xa9}, IPushBytes{IHash160(Lookup("p2puk"))}, Bytes{0x87}},
		"p2sh:p2wpkh": Format{Bytes{0xa9}, IPushBytes{IHash160(Lookup("p2wpkh"))}, Bytes{0x87}},

		"p2wsh:p2pkh":  Format{Bytes{0}, IPushBytes{IHash(Lookup("p2pkh"), sha256.New)}},
		"p2wsh:p2pukh": Format{Bytes{0}, IPushBytes{IHash(Lookup("p2pukh"), sha256.New)}},
		"p2wsh:p2pk":   Format{Bytes{0}, IPushBytes{IHash(Lookup("p2pk"), sha256.New)}},
		"p2wsh:p2puk":  Format{Bytes{0}, IPushBytes{IHash(Lookup("p2puk"), sha256.New)}},
		"p2wsh:p2wpkh": Format{Bytes{0}, IPushBytes{IHash(Lookup("p2wpkh"), sha256.New)}},

		"eth": Format{IHash(IPubKey, newEtherHash)},
	}
)

Functions

This section is empty.

Types

type Bytes added in v0.2.0

type Bytes []byte

func (Bytes) Bytes added in v0.2.0

func (b Bytes) Bytes(*Script) []byte

func (Bytes) String added in v0.2.0

func (b Bytes) String() string

type EvmTx added in v0.2.0

type EvmTx struct {
	Nonce      uint64
	GasTipCap  *big.Int // a.k.a. maxPriorityFeePerGas
	GasFeeCap  *big.Int // a.k.a. maxFeePerGas, correspond to GasFee if tx type is legacy or eip2930
	Gas        uint64   // gas of tx, can be obtained with eth_estimateGas, 21000 if Data is empty
	To         string
	Value      *big.Int
	Data       []byte
	ChainId    uint64    // in legacy tx, chainId is encoded in v before signature
	Type       EvmTxType // type of transaction: legacy, eip2930 or eip1559
	AccessList []any     // TODO
	Signed     bool
	Y, R, S    *big.Int
}

func (*EvmTx) ParseTransaction added in v0.2.0

func (tx *EvmTx) ParseTransaction(buf []byte) error

ParseTransaction will parse an incoming transaction and return an error in case of failure. In case of error, the state of tx is undefined.

func (*EvmTx) RlpFields added in v0.2.0

func (tx *EvmTx) RlpFields() []any

RlpFields returns the Rlp fields for the given transaction, less the signature fields

func (*EvmTx) SenderAddress added in v0.2.0

func (tx *EvmTx) SenderAddress() (string, error)

func (*EvmTx) SenderPubkey added in v0.2.0

func (tx *EvmTx) SenderPubkey() (*secp256k1.PublicKey, error)

func (*EvmTx) SignBytes added in v0.2.0

func (tx *EvmTx) SignBytes() ([]byte, error)

SignBytes returns the bytes used to sign the transaction

func (*EvmTx) Signature added in v0.2.0

func (tx *EvmTx) Signature() (*ecdsa.Signature, error)

type EvmTxType added in v0.2.0

type EvmTxType int
const (
	EvmTxLegacy EvmTxType = iota
	EvmTxEIP2930
	EvmTxEIP1559
	EvmTxEIP4844 //
)

type Format added in v0.2.0

type Format []Insertable

type IHashInfo added in v0.2.0

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

func IHash added in v0.2.0

func IHash(v Insertable, hash ...func() hash.Hash) IHashInfo

func IHash160 added in v0.2.0

func IHash160(v Insertable) IHashInfo

func (IHashInfo) Bytes added in v0.2.0

func (i IHashInfo) Bytes(s *Script) []byte

func (IHashInfo) String added in v0.2.0

func (i IHashInfo) String() string

type IPushBytes added in v0.2.0

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

func (IPushBytes) Bytes added in v0.2.0

func (i IPushBytes) Bytes(s *Script) []byte

func (IPushBytes) String added in v0.2.0

func (i IPushBytes) String() string

type Insertable added in v0.2.0

type Insertable interface {
	Bytes(*Script) []byte
	String() string
}

type Lookup added in v0.2.0

type Lookup string

func (Lookup) Bytes added in v0.2.0

func (l Lookup) Bytes(s *Script) []byte

func (Lookup) String added in v0.2.0

func (l Lookup) String() string

type Out added in v0.1.2

type Out struct {
	Name   string `json:"name"`   // p2sh, etc
	Script string `json:"script"` // out script
	// contains filtered or unexported fields
}

func GetOuts added in v0.1.2

func GetOuts(pubkey *secp256k1.PublicKey) []*Out

GetOuts returns the potential outputs that can be opened in theory with the given pubkey. p2w* values are "pay to segwit" and can only be used on segwit-enabled chains.

func (*Out) Bytes added in v0.1.4

func (o *Out) Bytes() []byte

func (*Out) String added in v0.2.0

func (o *Out) String() string

type PubKeyInsert added in v0.2.0

type PubKeyInsert int
const (
	IPubKeyComp PubKeyInsert = iota
	IPubKey
)

func (PubKeyInsert) Bytes added in v0.2.0

func (pk PubKeyInsert) Bytes(s *Script) []byte

func (PubKeyInsert) String added in v0.2.0

func (pk PubKeyInsert) String() string

type Script added in v0.2.0

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

func New added in v0.2.0

func New(pubkey *secp256k1.PublicKey) *Script

New returns a new Script object for the given public key, which can be used to generate output scripts

func (*Script) Generate added in v0.2.0

func (s *Script) Generate(name string) []byte

Generate will return the byte value for the specified script type for the current public key

func (*Script) Out added in v0.2.0

func (s *Script) Out(name string) *Out

Out returns a Out object matching the requested script

Jump to

Keyboard shortcuts

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