portxo

package
v0.0.0-...-f379a71 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Flags which combined can turn into full utxo modes
	FlagTxoPubKeyHash   TxoMode = 0x01
	FlagTxoScript       TxoMode = 0x02
	FlagTxoWitness      TxoMode = 0x04
	FlagTxoCompressed   TxoMode = 0x08
	FlagTxoUncompressed TxoMode = 0x10

	// fully specified tx output modes
	// raw pubkey outputs (old school)
	TxoP2PKUncomp = FlagTxoUncompressed
	TxoP2PKComp   = FlagTxoCompressed

	// pub key hash outputs, standard p2pkh (common)
	TxoP2PKHUncomp = FlagTxoPubKeyHash | FlagTxoUncompressed
	TxoP2PKHComp   = FlagTxoCompressed | FlagTxoPubKeyHash

	// script hash
	TxoP2SHUncomp = FlagTxoScript | FlagTxoUncompressed
	TxoP2SHComp   = FlagTxoScript | FlagTxoCompressed

	// witness p2wpkh modes
	TxoP2WPKHUncomp = FlagTxoWitness | FlagTxoPubKeyHash | FlagTxoUncompressed
	TxoP2WPKHComp   = FlagTxoWitness | FlagTxoPubKeyHash | FlagTxoCompressed

	// witness script hash
	TxoP2WSHUncomp = FlagTxoWitness | FlagTxoScript | FlagTxoUncompressed
	TxoP2WSHComp   = FlagTxoWitness | FlagTxoScript | FlagTxoCompressed

	// unknown
	TxoUnknownMode = 0x80
)

Constants defining txo modes

Variables

This section is empty.

Functions

func PrivKeyAddBytes

func PrivKeyAddBytes(k *koblitz.PrivateKey, b []byte)

PrivKeyAddBytes adds bytes to a private key. NOTE that this modifies the key in place, overwriting it!!!!1 If k is nil, does nothing and doesn't error (k stays nil)

Types

type KeyGen

type KeyGen struct {
	Depth   uint8     `json:"depth"`   // how many levels of the path to use. 0 means privkey as-is
	Step    [5]uint32 `json:"steps"`   // bip 32 / 44 path numbers
	PrivKey [32]byte  `json:"privkey"` // private key
}

KeyGen describes how to get to the key from the master / seed. it can be used with bip44 or other custom schemes (up to 5 levels deep) Depth must be 0 to 5 inclusive. Child indexes of 0 are OK, so we can't just terminate at the first 0.

func KeyGenFromBytes

func KeyGenFromBytes(b [53]byte) (k KeyGen)

KeyGenFromBytes turns a 53 byte array into a key derivation path. Always works (note a depth > 5 path is invalid, but this just deserializes & doesn't check)

func (KeyGen) Bytes

func (k KeyGen) Bytes() []byte

Bytes returns the 53 byte serialized key derivation path. always works

func (*KeyGen) DerivePrivateKey

func (kg *KeyGen) DerivePrivateKey(
	m *hdkeychain.ExtendedKey) (*koblitz.PrivateKey, error)

DerivePrivateKey returns the private key for a utxo based on a master key

func (KeyGen) String

func (k KeyGen) String() string

String turns a keygen into a string

type KeyGenSortableSlice

type KeyGenSortableSlice []*KeyGen

KeyGenSortableSlice is a sortable slice of keygens. Shorter and lower numbers first.

func (KeyGenSortableSlice) Len

func (s KeyGenSortableSlice) Len() int

func (KeyGenSortableSlice) Less

func (s KeyGenSortableSlice) Less(i, j int) bool

func (KeyGenSortableSlice) Swap

func (s KeyGenSortableSlice) Swap(i, j int)

type PorTxo

type PorTxo struct {
	// got rid of NetID.  If you want to specify different networks / coins,
	// use KeyGen.Step[1], that's what it's for.
	// Heck, set KeyGen.Depth to 0 and still use Step[1] as the network / coin...
	//	NetID  byte          // indicates what network / coin utxo is in
	Op     wire.OutPoint `json:"outpoint"` // unique outpoint
	Value  int64         `json:"val"`      // higher is better
	Height int32         `json:"height"`   // block height of utxo (not needed? nice to know?)
	Seq    uint32        `json:"seq"`      // used for relative timelock
	Mode   TxoMode       `json:"mode"`     // what kind of output

	KeyGen `json:"keygen"`

	PkScript []byte `json:"privkeyscript"` // if empty, try to generate based on mode and priv key

	PreSigStack [][]byte `json:"stack"` // items to push before the sig
}
PorTxo specify a utxo, and all the information needed to spend it.

The first 3 fields (Op, Amt, Mode) are required in all cases. If KeyGen.Depth != 0, that means no key path is supplied, and PrivKey is probably empty / ignored. Having both a KeyGen and a PrivKey is redunant. Having neither KeyGen nor PrivKey means there's no private key, and no indication of how to get it; in that case get the private key from somewhere else.

If BOTH KeyGen AND PrivKey are filled in, add em up! Add the two private keys, modulo the curve order.

PkScript can also be left empty depending on the mode. Basically only script-hash modes need it, as the previous pkscript can be generated

PreSigStack are data pushes that happen before the signature is pushed.

I was thinking of putting PostSigStack as well but I think it makes more sense to always have the data before the sig, since there's pretty much only CHECKSIGVERIFY now and you might as well put the sig check last.

Also makes sense that with a MAST or pay-to-script-merkle-root type of structure, you'd want a bunch stuff before the sig.

func ExtractFromTx

func ExtractFromTx(tx *wire.MsgTx, idx uint32) (*PorTxo, error)

ExtractFromTx returns a portxo from a tx and index. It fills in what it can, but the keygen, sequence, and height can't be determined from just this and need to be put in separately.

func PorTxoFromBytes

func PorTxoFromBytes(b []byte) (*PorTxo, error)

func (*PorTxo) AddWIF

func (u *PorTxo) AddWIF(w btcutil.WIF) error

func (*PorTxo) Bytes

func (u *PorTxo) Bytes() ([]byte, error)

func (*PorTxo) Equal

func (u *PorTxo) Equal(z *PorTxo) bool

Compare deep-compares two portable utxos, returning true if they're the same

func (*PorTxo) EstSize

func (u *PorTxo) EstSize() int64

EstSize returns an estimated vsize in bytes for using this portxo as an input. Might not be perfectly accurate. Also maybe should switch from vsize to weight..? everything is vsize right now though.

func (*PorTxo) Mature

func (u *PorTxo) Mature(curHeight int32) bool

Spendable takes in the current block height, and returns whether this utxo is spendable now or not. It checks height (unconfirmed

func (*PorTxo) String

func (u *PorTxo) String() string

type TxoMode

type TxoMode uint8

func TxoModeFromPkScript

func TxoModeFromPkScript(script []byte) TxoMode

func (TxoMode) String

func (m TxoMode) String() string

String returns the InvType in human-readable form.

type TxoSliceByAmt

type TxoSliceByAmt []*PorTxo

txoSliceByAmt is a sortable txo slice. Sorts by value, and puts unconfirmed last. Also has sum functions for calculating balances

func (TxoSliceByAmt) Len

func (s TxoSliceByAmt) Len() int

func (TxoSliceByAmt) Less

func (s TxoSliceByAmt) Less(i, j int) bool

height 0 means you are lesser

func (TxoSliceByAmt) Sum

func (s TxoSliceByAmt) Sum() int64

func (TxoSliceByAmt) SumWitness

func (s TxoSliceByAmt) SumWitness(currentHeight int32) int64

func (TxoSliceByAmt) Swap

func (s TxoSliceByAmt) Swap(i, j int)

type TxoSliceByBip69

type TxoSliceByBip69 []*PorTxo

txoSliceByBip69 is a sortable txo slice - same algo as txsort / BIP69

func (TxoSliceByBip69) Len

func (s TxoSliceByBip69) Len() int

Sort utxos just like txins -- Len, Less, Swap

func (TxoSliceByBip69) Less

func (s TxoSliceByBip69) Less(i, j int) bool

outpoint sort; First input hash (reversed / rpc-style), then index.

func (TxoSliceByBip69) Swap

func (s TxoSliceByBip69) Swap(i, j int)

Jump to

Keyboard shortcuts

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