blob

package
v0.0.0-...-e495a10 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NonceSize is the length of a chacha20poly1305 nonce, 24 bytes.
	NonceSize = chacha20poly1305.NonceSizeX

	// KeySize is the length of a chacha20poly1305 key, 32 bytes.
	KeySize = chacha20poly1305.KeySize

	// CiphertextExpansion is the number of bytes padded to a plaintext
	// encrypted with chacha20poly1305, which comes from a 16-byte MAC.
	CiphertextExpansion = 16

	// V0PlaintextSize is the plaintext size of a version 0 encoded blob.
	//    sweep address length:            1 byte
	//    padded sweep address:           42 bytes
	//    revocation pubkey:              33 bytes
	//    local delay pubkey:             33 bytes
	//    csv delay:                       4 bytes
	//    commit to-local revocation sig: 64 bytes
	//    commit to-remote pubkey:        33 bytes, maybe blank
	//    commit to-remote sig:           64 bytes, maybe blank
	V0PlaintextSize = 274

	// MaxSweepAddrSize defines the maximum sweep address size that can be
	// encoded in a blob.
	MaxSweepAddrSize = 42
)
View Source
const TypeDefault = Type(FlagCommitOutputs)

TypeDefault sweeps only commitment outputs to a sweep address controlled by the user, and does not give the tower a reward.

Variables

View Source
var (

	// ErrUnknownBlobType signals that we don't understand the requested
	// blob encoding scheme.
	ErrUnknownBlobType = errors.New("unknown blob type")

	// ErrCiphertextTooSmall is a decryption error signaling that the
	// ciphertext is smaller than the ciphertext expansion factor.
	ErrCiphertextTooSmall = errors.New(
		"ciphertext is too small for chacha20poly1305",
	)

	// ErrKeySize signals that the provided key is improperly sized.
	ErrKeySize = fmt.Errorf(
		"chacha20poly1305 key size must be %d bytes", KeySize,
	)

	// ErrNoCommitToRemoteOutput is returned when trying to retrieve the
	// commit to-remote output from the blob, though none exists.
	ErrNoCommitToRemoteOutput = errors.New(
		"cannot obtain commit to-remote p2wkh output script from blob",
	)

	// ErrSweepAddressToLong is returned when trying to encode or decode a
	// sweep address with length greater than the maximum length of 42
	// bytes, which supports p2wkh and p2sh addresses.
	ErrSweepAddressToLong = fmt.Errorf(
		"sweep address must be less than or equal to %d bytes long",
		MaxSweepAddrSize,
	)
)

Functions

func IsSupportedType

func IsSupportedType(blobType Type) bool

IsSupportedType returns true if the given type is supported by the package.

func PlaintextSize

func PlaintextSize(blobType Type) int

PlaintextSize returns the size of the encoded-but-unencrypted blob in bytes.

func Size

func Size(blobType Type) int

Size returns the size of the encoded-and-encrypted blob in bytes.

nonce:                24 bytes
enciphered plaintext:  n bytes
MAC:                  16 bytes

Types

type Flag

type Flag uint16

Flag represents a specify option that can be present in a Type.

const (
	// FlagReward signals that the justice transaction should contain an
	// additional output for itself. Signatures sent by the client should
	// include the reward script negotiated during session creation. Without
	// the flag, there is only one output sweeping clients funds back to
	// them solely.
	FlagReward Flag = 1 << iota

	// FlagCommitOutputs signals that the blob contains the information
	// required to sweep commitment outputs.
	FlagCommitOutputs
)

func (Flag) String

func (f Flag) String() string

String returns the name of the flag.

func (Flag) Type

func (f Flag) Type() Type

Type returns a Type consisting solely of this flag enabled.

type JusticeKit

type JusticeKit struct {
	// SweepAddress is the witness program of the output where the client's
	// fund will be deposited. This value is included in the blobs, as
	// opposed to the session info, such that the sweep addresses can't be
	// correlated across sessions and/or towers.
	//
	// NOTE: This is chosen to be the length of a maximally sized witness
	// program.
	SweepAddress []byte

	// RevocationPubKey is the compressed pubkey that guards the revocation
	// clause of the remote party's to-local output.
	RevocationPubKey PubKey

	// LocalDelayPubKey is the compressed pubkey in the to-local script of
	// the remote party, which guards the path where the remote party
	// claims their commitment output.
	LocalDelayPubKey PubKey

	// CSVDelay is the relative timelock in the remote party's to-local
	// output, which the remote party must wait out before sweeping their
	// commitment output.
	CSVDelay uint32

	// CommitToLocalSig is a signature under RevocationPubKey using
	// SIGHASH_ALL.
	CommitToLocalSig lnwire.Sig

	// CommitToRemotePubKey is the public key in the to-remote output of the revoked
	// commitment transaction.
	//
	// NOTE: This value is only used if it contains a valid compressed
	// public key.
	CommitToRemotePubKey PubKey

	// CommitToRemoteSig is a signature under CommitToRemotePubKey using SIGHASH_ALL.
	//
	// NOTE: This value is only used if CommitToRemotePubKey contains a valid
	// compressed public key.
	CommitToRemoteSig lnwire.Sig
}

JusticeKit is lé Blob of Justice. The JusticeKit contains information required to construct a justice transaction, that sweeps a remote party's revoked commitment transaction. It supports encryption and decryption using chacha20poly1305, allowing the client to encrypt the contents of the blob, and for a watchtower to later decrypt if action must be taken. The encoding format is versioned to allow future extensions.

func Decrypt

func Decrypt(key, ciphertext []byte, blobType Type) (*JusticeKit, error)

Decrypt unenciphers a blob of justice by decrypting the ciphertext using chacha20poly1305 with the chosen (nonce, key) pair. The internal plaintext is then deserialized using the given encoding version.

func (*JusticeKit) CommitToLocalRevokeWitnessStack

func (b *JusticeKit) CommitToLocalRevokeWitnessStack() ([][]byte, error)

CommitToLocalRevokeWitnessStack constructs a witness stack spending the revocation clause of the commitment to-local output.

<revocation-sig> 1

func (*JusticeKit) CommitToLocalWitnessScript

func (b *JusticeKit) CommitToLocalWitnessScript() ([]byte, error)

CommitToLocalWitnessScript returns the serialized witness script for the commitment to-local output.

func (*JusticeKit) CommitToRemoteWitnessScript

func (b *JusticeKit) CommitToRemoteWitnessScript() ([]byte, error)

CommitToRemoteWitnessScript returns the witness script for the commitment to-remote p2wkh output, which is the pubkey itself.

func (*JusticeKit) CommitToRemoteWitnessStack

func (b *JusticeKit) CommitToRemoteWitnessStack() ([][]byte, error)

CommitToRemoteWitnessStack returns a witness stack spending the commitment to-remote output, which is a regular p2wkh.

<to-remote-sig>

func (*JusticeKit) Encrypt

func (b *JusticeKit) Encrypt(key []byte, blobType Type) ([]byte, error)

Encrypt encodes the blob of justice using encoding version, and then creates a ciphertext using chacha20poly1305 under the chosen (nonce, key) pair.

NOTE: It is the caller's responsibility to ensure that this method is only called once for a given (nonce, key) pair.

func (*JusticeKit) HasCommitToRemoteOutput

func (b *JusticeKit) HasCommitToRemoteOutput() bool

HasCommitToRemoteOutput returns true if the blob contains a to-remote p2wkh pubkey.

type PubKey

type PubKey [33]byte

PubKey is a 33-byte, serialized compressed public key.

type Type

type Type uint16

Type is a bit vector composed of Flags that govern various aspects of reconstructing the justice transaction from an encrypted blob. The flags can be used to signal behaviors such as which inputs are being swept, which outputs should be added to the justice transaction, or modify serialization of the blob itself.

func SupportedTypes

func SupportedTypes() []Type

SupportedTypes returns a list of all supported blob types.

func TypeFromFlags

func TypeFromFlags(flags ...Flag) Type

TypeFromFlags creates a single Type from an arbitrary list of flags.

func (Type) Has

func (t Type) Has(flag Flag) bool

Has returns true if the Type has the passed flag enabled.

func (Type) String

func (t Type) String() string

String returns a human readable description of a Type.

Jump to

Keyboard shortcuts

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