wtmock

package
v0.18.0-beta.rc1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockConn

func NewMockConn(localPk, remotePk *btcec.PublicKey,
	localAddr, remoteAddr net.Addr,
	bufferSize int) (*MockPeer, *MockPeer)

NewMockConn establishes a bidirectional connection between two MockPeers.

func NewQueueDB

func NewQueueDB[T any]() wtdb.Queue[T]

NewQueueDB constructs a new DiskQueueDB.

Types

type DiskQueueDB

type DiskQueueDB[T any] struct {
	// contains filtered or unexported fields
}

DiskQueueDB is an in-memory implementation of the wtclient.Queue interface.

func (*DiskQueueDB[T]) Len

func (d *DiskQueueDB[T]) Len() (uint64, error)

Len returns the number of tasks in the queue.

NOTE: This is part of the wtclient.Queue interface.

func (*DiskQueueDB[T]) PopUpTo

func (d *DiskQueueDB[T]) PopUpTo(n int) ([]T, error)

PopUpTo attempts to pop up to n items from the queue. If the queue is empty, then ErrEmptyQueue is returned.

NOTE: This is part of the Queue interface.

func (*DiskQueueDB[T]) Push

func (d *DiskQueueDB[T]) Push(items ...T) error

Push adds new T items to the tail of the queue.

NOTE: This is part of the wtclient.Queue interface.

func (*DiskQueueDB[T]) PushHead

func (d *DiskQueueDB[T]) PushHead(items ...T) error

PushHead pushes new T items to the head of the queue.

NOTE: This is part of the wtclient.Queue interface.

type MockPeer

type MockPeer struct {
	IncomingMsgs chan []byte
	OutgoingMsgs chan []byte

	RemoteQuit chan struct{}
	Quit       chan struct{}
	// contains filtered or unexported fields
}

MockPeer emulates a single endpoint of brontide transport.

func NewMockPeer

func NewMockPeer(lpk, rpk *btcec.PublicKey, addr net.Addr,
	bufferSize int) *MockPeer

NewMockPeer returns a fresh MockPeer.

func (*MockPeer) Close

func (p *MockPeer) Close() error

Close tears down the connection, and fails any pending reads or writes.

func (*MockPeer) LocalAddr

func (p *MockPeer) LocalAddr() net.Addr

LocalAddr returns the local net address of the peer.

func (*MockPeer) Read

func (p *MockPeer) Read(dst []byte) (int, error)

Read is not implemented.

func (*MockPeer) ReadNextMessage

func (p *MockPeer) ReadNextMessage() ([]byte, error)

ReadNextMessage returns the raw bytes of the next full message read from the remote peer. The read will fail if either party closes the connection or the read deadline expires.

func (*MockPeer) RemoteAddr

func (p *MockPeer) RemoteAddr() net.Addr

RemoteAddr returns the net address of the remote peer.

func (*MockPeer) RemotePub

func (p *MockPeer) RemotePub() *btcec.PublicKey

RemotePub returns the public key of the remote peer.

func (*MockPeer) SetDeadline

func (p *MockPeer) SetDeadline(t time.Time) error

SetDeadline is not implemented.

func (*MockPeer) SetReadDeadline

func (p *MockPeer) SetReadDeadline(t time.Time) error

SetReadDeadline initializes a timer that will cause any pending reads to fail at time t. If t is zero, the deadline is infinite.

func (*MockPeer) SetWriteDeadline

func (p *MockPeer) SetWriteDeadline(t time.Time) error

SetWriteDeadline initializes a timer that will cause any pending writes to fail at time t. If t is zero, the deadline is infinite.

func (*MockPeer) Write

func (p *MockPeer) Write(b []byte) (n int, err error)

Write sends the raw bytes as the next full message read to the remote peer. The write will fail if either party closes the connection or the write deadline expires. The passed bytes slice is copied before sending, thus the bytes may be reused once the method returns.

type MockSigner

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

MockSigner is an input.Signer that allows one to add arbitrary private keys and sign messages by passing the assigned keychain.KeyLocator.

func NewMockSigner

func NewMockSigner() *MockSigner

NewMockSigner returns a fresh MockSigner.

func (*MockSigner) AddPrivKey

func (s *MockSigner) AddPrivKey(privKey *btcec.PrivateKey) keychain.KeyLocator

AddPrivKey records the passed privKey in the MockSigner's registry of keys it can sign with in the future. A unique key locator is returned, allowing the caller to sign with this key when presented via an input.SignDescriptor.

func (*MockSigner) ComputeInputScript

func (s *MockSigner) ComputeInputScript(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (*input.Script, error)

ComputeInputScript is not implemented.

func (*MockSigner) MuSig2Cleanup

func (s *MockSigner) MuSig2Cleanup(input.MuSig2SessionID) error

MuSig2Cleanup removes a session from memory to free up resources.

func (*MockSigner) MuSig2CombineSig

MuSig2CombineSig combines the given partial signature(s) with the local one, if it already exists. Once a partial signature of all participants is registered, the final signature will be combined and returned.

func (*MockSigner) MuSig2CreateSession

MuSig2CreateSession creates a new MuSig2 signing session using the local key identified by the key locator. The complete list of all public keys of all signing parties must be provided, including the public key of the local signing key. If nonces of other parties are already known, they can be submitted as well to reduce the number of method calls necessary later on.

func (*MockSigner) MuSig2RegisterNonces

func (s *MockSigner) MuSig2RegisterNonces(input.MuSig2SessionID,
	[][musig2.PubNonceSize]byte) (bool, error)

MuSig2RegisterNonces registers one or more public nonces of other signing participants for a session identified by its ID. This method returns true once we have all nonces for all other signing participants.

func (*MockSigner) MuSig2Sign

MuSig2Sign creates a partial signature using the local signing key that was specified when the session was created. This can only be called when all public nonces of all participants are known and have been registered with the session. If this node isn't responsible for combining all the partial signatures, then the cleanup parameter should be set, indicating that the session can be removed from memory once the signature was produced.

func (*MockSigner) SignOutputRaw

func (s *MockSigner) SignOutputRaw(tx *wire.MsgTx,
	signDesc *input.SignDescriptor) (input.Signature, error)

SignOutputRaw signs an input on the passed transaction using the input index in the sign descriptor. The returned signature is the raw DER-encoded signature without the signhash flag.

type SecretKeyRing

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

SecretKeyRing is a mock, in-memory implementation for deriving private keys.

func NewSecretKeyRing

func NewSecretKeyRing() *SecretKeyRing

NewSecretKeyRing creates a new mock SecretKeyRing.

func (*SecretKeyRing) DeriveKey

func (m *SecretKeyRing) DeriveKey(
	keyLoc keychain.KeyLocator) (keychain.KeyDescriptor, error)

DeriveKey attempts to derive an arbitrary key specified by the passed KeyLocator. This may be used in several recovery scenarios, or when manually rotating something like our current default node key.

NOTE: This is part of the wtclient.ECDHKeyRing interface.

func (*SecretKeyRing) ECDH

func (m *SecretKeyRing) ECDH(keyDesc keychain.KeyDescriptor,
	pub *btcec.PublicKey) ([32]byte, error)

ECDH performs a scalar multiplication (ECDH-like operation) between the target key descriptor and remote public key. The output returned will be the sha256 of the resulting shared point serialized in compressed format. If k is our private key, and P is the public key, we perform the following operation:

sx := k*P
s := sha256(sx.SerializeCompressed())

NOTE: This is part of the wtclient.ECDHKeyRing interface.

type TowerDB

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

TowerDB is a mock, in-memory implementation of a watchtower.DB.

func NewTowerDB

func NewTowerDB() *TowerDB

NewTowerDB initializes a fresh mock TowerDB.

func (*TowerDB) DeleteSession

func (db *TowerDB) DeleteSession(target wtdb.SessionID) error

DeleteSession removes all data associated with a particular session id from the tower's database.

func (*TowerDB) GetLookoutTip

func (db *TowerDB) GetLookoutTip() (*chainntnfs.BlockEpoch, error)

GetLookoutTip retrieves the current lookout tip block epoch from the tower database.

func (*TowerDB) GetSessionInfo

func (db *TowerDB) GetSessionInfo(id *wtdb.SessionID) (*wtdb.SessionInfo, error)

GetSessionInfo retrieves the session for the passed session id. An error is returned if the session could not be found.

func (*TowerDB) InsertSessionInfo

func (db *TowerDB) InsertSessionInfo(info *wtdb.SessionInfo) error

InsertSessionInfo records a negotiated session in the tower database. An error is returned if the session already exists.

func (*TowerDB) InsertStateUpdate

func (db *TowerDB) InsertStateUpdate(update *wtdb.SessionStateUpdate) (uint16, error)

InsertStateUpdate stores an update sent by the client after validating that the update is well-formed in the context of other updates sent for the same session. This include verifying that the sequence number is incremented properly and the last applied values echoed by the client are sane.

func (*TowerDB) QueryMatches

func (db *TowerDB) QueryMatches(
	breachHints []blob.BreachHint) ([]wtdb.Match, error)

QueryMatches searches against all known state updates for any that match the passed breachHints. More than one Match will be returned for a given hint if they exist in the database.

func (*TowerDB) SetLookoutTip

func (db *TowerDB) SetLookoutTip(epoch *chainntnfs.BlockEpoch) error

SetLookoutTip stores the provided epoch as the latest lookout tip epoch in the tower database.

Jump to

Keyboard shortcuts

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