shachain

package
v0.9.1-beta Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Producer

type Producer interface {
	// AtIndex produces a secret by evaluating using the initial seed and a
	// particular index.
	AtIndex(uint64) (*chainhash.Hash, error)

	// Encode writes a binary serialization of the Producer implementation
	// to the passed io.Writer.
	Encode(io.Writer) error
}

Producer is an interface which serves as an abstraction over the data structure responsible for efficiently generating the secrets for a particular index based on a root seed. The generation of secrets should be made in such way that secret store might efficiently store and retrieve the secrets. This is typically implemented as a tree-based PRF.

type RevocationProducer

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

RevocationProducer is an implementation of Producer interface using the shachain PRF construct. Starting with a single 32-byte element generated from a CSPRNG, shachain is able to efficiently generate a nearly unbounded number of secrets while maintaining a constant amount of storage. The original description of shachain can be found here: https://github.com/rustyrussell/ccan/blob/master/ccan/crypto/shachain/design.txt with supplementary material here: https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#per-commitment-secret-requirements

func NewRevocationProducer

func NewRevocationProducer(root chainhash.Hash) *RevocationProducer

NewRevocationProducer creates new instance of shachain producer.

func NewRevocationProducerFromBytes

func NewRevocationProducerFromBytes(data []byte) (*RevocationProducer, error)

NewRevocationProducerFromBytes deserializes an instance of a RevocationProducer encoded in the passed byte slice, returning a fully initialized instance of a RevocationProducer.

func (*RevocationProducer) AtIndex

func (p *RevocationProducer) AtIndex(v uint64) (*chainhash.Hash, error)

AtIndex produces a secret by evaluating using the initial seed and a particular index.

NOTE: Part of the Producer interface.

func (*RevocationProducer) Encode

func (p *RevocationProducer) Encode(w io.Writer) error

Encode writes a binary serialization of the Producer implementation to the passed io.Writer.

NOTE: Part of the Producer interface.

type RevocationStore

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

RevocationStore is a concrete implementation of the Store interface. The revocation store is able to efficiently store N derived shachain elements in a space efficient manner with a space complexity of O(log N). The original description of the storage methodology can be found here: https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md#efficient-per-commitment-secret-storage

func NewRevocationStore

func NewRevocationStore() *RevocationStore

NewRevocationStore creates the new shachain store.

func NewRevocationStoreFromBytes

func NewRevocationStoreFromBytes(r io.Reader) (*RevocationStore, error)

NewRevocationStoreFromBytes recreates the initial store state from the given binary shachain store representation.

func (*RevocationStore) AddNextEntry

func (store *RevocationStore) AddNextEntry(hash *chainhash.Hash) error

AddNextEntry attempts to store the given hash within its internal storage in an efficient manner.

NOTE: The hashes derived from the shachain MUST be inserted in the order they're produced by a shachain.Producer.

NOTE: This function is part of the Store interface.

func (*RevocationStore) Encode

func (store *RevocationStore) Encode(w io.Writer) error

Encode writes a binary serialization of the shachain elements currently saved by implementation of shachain.Store to the passed io.Writer.

NOTE: This function is part of the Store interface.

func (*RevocationStore) LookUp

func (store *RevocationStore) LookUp(v uint64) (*chainhash.Hash, error)

LookUp function is used to restore/lookup/fetch the previous secret by its index. If secret which corresponds to given index was not previously placed in store we will not able to derive it and function will fail.

NOTE: This function is part of the Store interface.

type Store

type Store interface {
	// LookUp function is used to restore/lookup/fetch the previous secret
	// by its index.
	LookUp(uint64) (*chainhash.Hash, error)

	// AddNextEntry attempts to store the given hash within its internal
	// storage in an efficient manner.
	//
	// NOTE: The hashes derived from the shachain MUST be inserted in the
	// order they're produced by a shachain.Producer.
	AddNextEntry(*chainhash.Hash) error

	// Encode writes a binary serialization of the shachain elements
	// currently saved by implementation of shachain.Store to the passed
	// io.Writer.
	Encode(io.Writer) error
}

Store is an interface which serves as an abstraction over data structure responsible for efficiently storing and restoring of hash secrets by given indexes.

Description: The Lightning Network wants a chain of (say 1 million) unguessable 256 bit values; we generate them and send them one at a time to a remote node. We don't want the remote node to have to store all the values, so it's better if they can derive them once they see them.

Jump to

Keyboard shortcuts

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