htlc

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Copyright 2017 - 2018 Oneledger

Functions to wrap the atomic swap mechanics for Bitcoin

OneLedger Wallet

OneLedger Wallet

Index

Constants

View Source
const (
	// MaxFundingTxOutputs is the maximum number of allowed outputs on a
	// funding transaction within the protocol. This is due to the fact
	// that we use 2-bytes to encode the index within the funding output
	// during the funding workflow. Funding transaction with more outputs
	// than this are considered invalid within the protocol.
	MaxFundingTxOutputs = math.MaxUint16
)
View Source
const OnionPacketSize = 1366

OnionPacketSize is the size of the serialized Sphinx onion packet included in each UpdateAddHTLC message. The breakdown of the onion packet is as follows: 1-byte version, 33-byte ephemeral public key (for ECDH), 1300-bytes of per-hop data, and a 32-byte HMAC over the entire packet.

Variables

View Source
var ConnectionWideID = ChannelID{}

ConnectionWideID is an all-zero ChannelID, which is used to represent a message intended for all channels to specific peer.

Functions

This section is empty.

Types

type AuditContractCmd

type AuditContractCmd struct {
	SecretHash [secretSize]byte
	// contains filtered or unexported fields
}

func NewAuditContractCmd

func NewAuditContractCmd(contract []byte, contractTx *wire.MsgTx) *AuditContractCmd

Audit an existing contract

func (*AuditContractCmd) RunCommand

func (cmd *AuditContractCmd) RunCommand(b *rpc.Bitcoind) error

func (*AuditContractCmd) RunOfflineCommand

func (cmd *AuditContractCmd) RunOfflineCommand(chainParams *chaincfg.Params) error

type ChannelID

type ChannelID [32]byte

ChannelID is a series of 32-bytes that uniquely identifies all channels within the network. The ChannelID is computed using the outpoint of the funding transaction (the txid, and output index). Given a funding output the ChannelID can be calculated by XOR'ing the big-endian serialization of the txid and the big-endian serialization of the output index, truncated to 2 bytes.

func NewChanIDFromOutPoint

func NewChanIDFromOutPoint(op *wire.OutPoint) ChannelID

NewChanIDFromOutPoint converts a target OutPoint into a ChannelID that is usable within the network. In order to convert the OutPoint into a ChannelID, we XOR the lower 2-bytes of the txid within the OutPoint with the big-endian serialization of the Index of the OutPoint, truncated to 2-bytes.

func (*ChannelID) GenPossibleOutPoints

func (c *ChannelID) GenPossibleOutPoints() [MaxFundingTxOutputs]wire.OutPoint

GenPossibleOutPoints generates all the possible outputs given a channel ID. In order to generate these possible outpoints, we perform a brute-force search through the candidate output index space, performing a reverse mapping from channelID back to OutPoint.

func (ChannelID) IsChanPoint

func (c ChannelID) IsChanPoint(op *wire.OutPoint) bool

IsChanPoint returns true if the OutPoint passed corresponds to the target ChannelID.

func (ChannelID) String

func (c ChannelID) String() string

String returns the string representation of the ChannelID. This is just the hex string encoding of the ChannelID itself.

type ExtractSecretCmd

type ExtractSecretCmd struct {
	Secret []byte
	// contains filtered or unexported fields
}

func NewExtractSecretCmd

func NewExtractSecretCmd(redemptionTx *wire.MsgTx, secretHash [32]byte) *ExtractSecretCmd

Extract the Secret from the transaction as issued by the counterparty

func (*ExtractSecretCmd) RunCommand

func (cmd *ExtractSecretCmd) RunCommand(c *rpc.Bitcoind) error

func (*ExtractSecretCmd) RunOfflineCommand

func (cmd *ExtractSecretCmd) RunOfflineCommand() error

type InitiateCmd

type InitiateCmd struct {
	Contract   []byte
	ContractTx *wire.MsgTx
	RefundTx   *wire.MsgTx
	// contains filtered or unexported fields
}

func NewInitiateCmd

func NewInitiateCmd(cp2Addr *btcutil.AddressPubKeyHash, amount btcutil.Amount, lockTime int64, scrHash [32]byte) *InitiateCmd

Initiate a new swpa between parties

func (*InitiateCmd) RunCommand

func (cmd *InitiateCmd) RunCommand(c *rpc.Bitcoind) (*chainhash.Hash, error)

type OneLedgerChannel

type OneLedgerChannel struct {
}

OneLedgerChannel implements the state machine which corresponds to the current commitment protocol wire spec.

type ParticipateCmd

type ParticipateCmd struct {
	Contract   []byte
	ContractTx *wire.MsgTx
	// contains filtered or unexported fields
}

func NewParticipateCmd

func NewParticipateCmd(cp1Addr *btcutil.AddressPubKeyHash, amount btcutil.Amount,
	secretHash [32]byte, lockTime int64) *ParticipateCmd

Participate in the swap

func (*ParticipateCmd) RunCommand

func (cmd *ParticipateCmd) RunCommand(c *rpc.Bitcoind) (*chainhash.Hash, error)

type PaymentDescriptor

type PaymentDescriptor struct {
	// RHash is the payment hash for this HTLC. The HTLC can be settled iff
	// the preimage to this hash is presented.
	RHash PaymentHash

	// RPreimage is the preimage that settles the HTLC pointed to within the
	// log by the ParentIndex.
	RPreimage PaymentHash

	// Timeout is the absolute timeout in blocks, after which this HTLC
	// expires.
	Timeout uint32

	// Amount is the HTLC amount.
	Amount uint64

	// LogIndex is the log entry number that his HTLC update has within the
	// log. Depending on if IsIncoming is true, this is either an entry the
	// remote party added, or one that we added locally.
	LogIndex uint64

	// HtlcIndex is the index within the main update log for this HTLC.
	// Entries within the log of type Add will have this field populated,
	// as other entries will point to the entry via this counter.
	//
	// NOTE: This field will only be populate if EntryType is Add.
	HtlcIndex uint64

	// ParentIndex is the HTLC index of the entry that this update settles or
	// times out.
	//
	// NOTE: This field will only be populate if EntryType is Fail or
	// Settle.
	ParentIndex uint64

	// OnionBlob is an opaque blob which is used to complete multi-hop
	// routing.
	//
	// NOTE: Populated only on add payment descriptor entry types.
	OnionBlob []byte

	// ShaOnionBlob is a sha of the onion blob.
	//
	// NOTE: Populated only in payment descriptor with MalfromedFail type.
	ShaOnionBlob [sha256.Size]byte

	// FailReason stores the reason why a particular payment was cancelled.
	//
	// NOTE: Populate only in fail payment descriptor entry types.
	FailReason []byte

	// EntryType denotes the exact type of the PaymentDescriptor. In the
	// case of a Timeout, or Settle type, then the Parent field will point
	// into the log to the HTLC being modified.
	EntryType updateType
	// contains filtered or unexported fields
}

PaymentDescriptor represents a commitment state update which either adds, settles, or removes an HTLC. PaymentDescriptors encapsulate all necessary metadata w.r.t to an HTLC, and additional data pairing a settle message to the original added HTLC.

type PaymentHash

type PaymentHash [32]byte

PaymentHash represents the sha256 of a random value. This hash is used to uniquely track incoming/outgoing payments within this channel, as well as payments requested by the wallet/daemon.

type RedeemCmd

type RedeemCmd struct {
	RedeemContractTx *wire.MsgTx
	// contains filtered or unexported fields
}

func NewRedeemCmd

func NewRedeemCmd(contract []byte, contractTx *wire.MsgTx, secret []byte) *RedeemCmd

Redeem the asset within the contact, the swap is approved

func (*RedeemCmd) RunCommand

func (cmd *RedeemCmd) RunCommand(c *rpc.Bitcoind) (*chainhash.Hash, error)

type RefundCmd

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

func NewRefundCmd

func NewRefundCmd(contract []byte, contractTx *wire.MsgTx) *RefundCmd

Collect the refund of the contract, it has failed somehow

func (*RefundCmd) RunCommand

func (cmd *RefundCmd) RunCommand(c *rpc.Bitcoind) (*chainhash.Hash, error)

type ShortChannelID

type ShortChannelID struct {
	// BlockHeight is the height of the block where funding transaction
	// located.
	//
	// NOTE: This field is limited to 3 bytes.
	BlockHeight uint32

	// TxIndex is a position of funding transaction within a block.
	//
	// NOTE: This field is limited to 3 bytes.
	TxIndex uint32

	// TxPosition indicating transaction output which pays to the channel.
	TxPosition uint16
}

ShortChannelID represents the set of data which is needed to retrieve all necessary data to validate the channel existence.

func NewShortChanIDFromInt

func NewShortChanIDFromInt(chanID uint64) ShortChannelID

NewShortChanIDFromInt returns a new ShortChannelID which is the decoded version of the compact channel ID encoded within the uint64. The format of the compact channel ID is as follows: 3 bytes for the block height, 3 bytes for the transaction index, and 2 bytes for the output index.

func (ShortChannelID) String

func (c ShortChannelID) String() string

String generates a human-readable representation of the channel ID.

func (ShortChannelID) ToUint64

func (c ShortChannelID) ToUint64() uint64

ToUint64 converts the ShortChannelID into a compact format encoded within a uint64 (8 bytes).

type UpdateAddHTLC

type UpdateAddHTLC struct {
	// ChanID is the particular active channel that this UpdateAddHTLC is
	// bound to.
	ChanID ChannelID

	// ID is the identification server for this HTLC. This value is
	// explicitly included as it allows nodes to survive single-sided
	// restarts. The ID value for this sides starts at zero, and increases
	// with each offered HTLC.
	ID uint64

	// Amount is the amount of this HTLC is worth.
	Amount uint64

	// PaymentHash is the payment hash to be included in the HTLC this
	// request creates. The pre-image to this HTLC must be revealed by the
	// upstream peer in order to fully settle the HTLC.
	PaymentHash [32]byte

	// Expiry is the number of blocks after which this HTLC should expire.
	// It is the receiver's duty to ensure that the outgoing HTLC has a
	// sufficient expiry value to allow her to redeem the incoming HTLC.
	Expiry uint32

	// OnionBlob is the raw serialized mix header used to route an HTLC in
	// a privacy-preserving manner. The mix header is defined currently to
	// be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC,
	// body).  First the receiving node should use the groupElement, and
	// its current onion key to derive a shared Secret with the source.
	// Once the shared Secret has been derived, the headerMAC should be
	// checked FIRST. Note that the MAC only covers the routingInfo field.
	// If the MAC matches, and the shared Secret is fresh, then the node
	// should strip off a layer of encryption, exposing the next hop to be
	// used in the subsequent UpdateAddHTLC message.
	OnionBlob [OnionPacketSize]byte
}

UpdateAddHTLC is the message sent by Alice to Bob when she wishes to add an HTLC to his remote commitment transaction. In addition to information detailing the value, the ID, expiry, and the onion blob is also included which allows Bob to derive the next hop in the route. The HTLC added by this message is to be added to the remote node's "pending" HTLC's. A subsequent CommitSig message will move the pending HTLC to the newly created commitment transaction, marking them as "staged".

func NewUpdateAddHTLC

func NewUpdateAddHTLC() *UpdateAddHTLC

NewUpdateAddHTLC returns a new empty UpdateAddHTLC message.

Jump to

Keyboard shortcuts

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