swap

package
v0.0.0-...-ea68448 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeInvalidSwapRequest = iota
	ErrCodeRejectedSwapRequest
	ErrCodeFailedToComplete
	ErrCodeInvalidTransaction
	ErrCodeBadPricingSwapRequest
	ErrCodeAborted
	ErrCodeFailedToBroadcast
)

Variables

This section is empty.

Functions

func Accept

func Accept(opts AcceptOpts) (string, []byte, error)

Accept takes a AcceptOpts and returns the id of the SwapAccept entity and its serialized version

func Complete

func Complete(opts CompleteOpts) (string, []byte, error)

Complete takes a CompleteOpts and returns the id of the SwapComplete entity and its serialized version

func Fail

func Fail(opts FailOpts) (string, []byte, error)

func FailV1

func FailV1(opts FailOpts) (string, []byte, error)

func Request

func Request(opts RequestOpts) ([]byte, error)

Request takes a RequestOpts struct and returns a serialized protobuf message.

func ValidateCompletePset

func ValidateCompletePset(opts ValidateCompletePsetOpts) error

ValidateCompletePset takes a VerifyCompeltePsetOpts and returns whether the final signed pset matches the original SwapRequest message

func ValidateProposerReceiveV2

func ValidateProposerReceiveV2(opts ValidateProposerReceiveV2Opts) error

ValidateProposerReceiveV2 is the PSETv2 sibling of ValidateCompletePset, scoped to protect the PROPOSER (the seqob taker) before it signs a responder-returned swap. ValidateCompletePset itself cannot be used here: it parses with the PSETv0 pset.NewPsetFromBase64 and matches a tdexv1.SwapRequest's amounts ANYWHERE in the tx (not to the proposer's own script), whereas the seqob path is PSETv2 and the theft this guards against is the responder reducing, removing, or redirecting the proposer's receive output (or swapping out the proposer's funding inputs) right before the proposer signs.

It asserts:

  1. the final tx contains an output to RecvScript paying EXACTLY AmountR of AssetR (unblinding a confidential receive with RecvBlindingKey); and
  2. every input the proposer contributed (by outpoint) is still present in the final tx, so the responder cannot substitute the proposer's inputs.

Types

type AcceptOpts

type AcceptOpts struct {
	Message            []byte
	Transaction        string
	InputBlindingKeys  map[string][]byte
	OutputBlindingKeys map[string][]byte
	UnblindedInputs    []UnblindedInput
}

AcceptOpts is the struct given to Accept method

type CompleteOpts

type CompleteOpts struct {
	Message     []byte
	Transaction string
}

CompleteOpts is the struct given to the Complete method

type FailOpts

type FailOpts struct {
	MessageID string
	ErrCode   int
}

type RequestOpts

type RequestOpts struct {
	Id                 string
	AssetToSend        string
	AmountToSend       uint64
	AssetToReceive     string
	AmountToReceive    uint64
	Transaction        string
	InputBlindingKeys  map[string][]byte
	OutputBlindingKeys map[string][]byte
	UnblindedInputs    []UnblindedInput
	// Fee asset and amount are not (de)serialized, they're used only to check
	// that the amounts of the swap request match those of the PSETv2 tx.
	FeeAsset  string
	FeeAmount uint64
}

RequestOpts is the struct to be given to the Request method

type UnblindedInput

type UnblindedInput struct {
	Index         uint32
	Asset         string
	Amount        uint64
	AssetBlinder  string
	AmountBlinder string
}

type ValidateCompletePsetOpts

type ValidateCompletePsetOpts struct {
	PsetBase64         string
	InputBlindingKeys  map[string][]byte
	OutputBlindingKeys map[string][]byte
	SwapRequest        *tdexv1.SwapRequest
}

ValidateCompletePsetOpts is the struct given to the ValidateCompletePset method

type ValidateProposerReceiveV2Opts

type ValidateProposerReceiveV2Opts struct {
	// ProposerPsetBase64 is the proposer's OWN request PSETv2 (the half it built
	// before the responder co-signed). Its inputs are the proposer's funding
	// inputs; they must survive into the final tx unchanged.
	ProposerPsetBase64 string
	// FinalPsetBase64 is the responder-returned co-signed PSETv2 (the
	// SwapAccept.transaction the proposer is about to sign).
	FinalPsetBase64 string
	// RecvScript is the proposer's own receive scriptPubKey (the script its
	// receive output must pay to).
	RecvScript []byte
	// RecvBlindingKey is the proposer's 32-byte private blinding key, used to
	// unblind a confidential receive output. May be nil for an explicit receive.
	RecvBlindingKey []byte
	// AssetR / AmountR are the asset and exact amount the proposer must receive.
	AssetR  string
	AmountR uint64
}

ValidateProposerReceiveV2Opts configures ValidateProposerReceiveV2.

Jump to

Keyboard shortcuts

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