htlc

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClaimPreImage = "htlc.cpi"
	LockHash      = "htlc.lh"
)
View Source
const (
	ScanForPreImageStartingTransaction = "htlc.ScanForPreImage.StartingTransaction"
)
View Source
const (
	ScriptType = "htlc" // htlc script

)

Variables

This section is empty.

Functions

func ClaimKey

func ClaimKey(v []byte) string

ClaimKey returns the claim key for the passed byte array

func CreateNonce

func CreateNonce() ([]byte, error)

CreateNonce generates a nonce using the common/crypto package

func ExchangeRecipientIdentities

func ExchangeRecipientIdentities(context view.Context, walletID string, recipient view.Identity, opts ...token.ServiceOption) (view.Identity, view.Identity, error)

ExchangeRecipientIdentities executes the ttx ExchangeRecipientIdentitiesView

func GetWallet

func GetWallet(sp view2.ServiceProvider, id string, opts ...token.ServiceOption) *token.OwnerWallet

GetWallet returns the wallet whose id is the passed id

func LockKey

func LockKey(v []byte) string

LockKey returns the lock key for the passed byte array

func LockValue

func LockValue(v []byte) []byte

LockValue returns the encoding of the value for a lock key

func NewAcceptView

func NewAcceptView(tx *Transaction) view.View

NewAcceptView returns an instance of the ttx acceptView struct

func NewCollectEndorsementsView

func NewCollectEndorsementsView(tx *Transaction) view.View

NewCollectEndorsementsView returns an instance of the ttx collectEndorsementsView struct

func NewFinalityView

func NewFinalityView(tx *Transaction) view.View

NewFinalityView returns an instance of the ttx FinalityView

func NewFinalityWithTimeoutView

func NewFinalityWithTimeoutView(tx *Transaction, timeout time.Duration) view.View

NewFinalityWithTimeoutView returns an instance of the ttx FinalityView with timeout

func NewOrderingAndFinalityView

func NewOrderingAndFinalityView(tx *Transaction) view.View

NewOrderingAndFinalityView returns a new instance of the ttx orderingAndFinalityView struct

func NewOrderingAndFinalityWithTimeoutView

func NewOrderingAndFinalityWithTimeoutView(tx *Transaction, timeout time.Duration) view.View

NewOrderingAndFinalityWithTimeoutView returns a new instance of the ttx orderingAndFinalityWithTimeoutView struct

func NewReceiveTransactionView

func NewReceiveTransactionView(network string) *receiveTransactionView

NewReceiveTransactionView returns an instance of receiveTransactionView struct

func RespondExchangeRecipientIdentities

func RespondExchangeRecipientIdentities(context view.Context) (view.Identity, view.Identity, error)

RespondExchangeRecipientIdentities executes the ttx RespondExchangeRecipientIdentitiesView

func ScanForPreImage

func ScanForPreImage(ctx view.Context, image []byte, hashFunc crypto.Hash, hashEncoding encoding.Encoding, timeout time.Duration, opts ...token.ServiceOption) ([]byte, error)

ScanForPreImage scans the ledger for a preimage of the passed image, taking into account the timeout

func SelectExpired

func SelectExpired(tok *token.UnspentToken, script *Script) (bool, error)

SelectExpired selects expired htlc-tokens

func SelectNonExpired

func SelectNonExpired(tok *token.UnspentToken, script *Script) (bool, error)

SelectNonExpired selects non-expired htlc-tokens

func WithHash

func WithHash(hash []byte) token.TransferOption

WithHash sets a hash attribute to be used to customize the transfer command

func WithHashEncoding

func WithHashEncoding(encoding encoding.Encoding) token.TransferOption

WithHashEncoding sets a hash encoding attribute to be used to customize the transfer command

func WithHashFunc

func WithHashFunc(hashFunc crypto.Hash) token.TransferOption

WithHashFunc sets a hash function attribute to be used to customize the transfer command

func WithStartingTransaction

func WithStartingTransaction(txID string) token.ServiceOption

WithStartingTransaction sets the network name

Types

type ClaimSignature

type ClaimSignature struct {
	RecipientSignature []byte
	Preimage           []byte
}

ClaimSignature is the claim signature of an htlc script

type ClaimSigner

type ClaimSigner struct {
	Recipient driver.Signer
	Preimage  []byte
}

ClaimSigner is the signer for the claim of an htlc script

func (*ClaimSigner) Sign

func (cs *ClaimSigner) Sign(tokenRequestAndTxID []byte) ([]byte, error)

Sign returns a signature of the recipient over the token request and preimage

type ClaimVerifier

type ClaimVerifier struct {
	Recipient driver.Verifier
	HashInfo  HashInfo
}

ClaimVerifier is the verifier of a ClaimSignature

func (*ClaimVerifier) Verify

func (cv *ClaimVerifier) Verify(tokenRequestAndTxID, claimSignature []byte) error

Verify verifies that the passed signature is valid and that the contained preimage matches the hash info

type DistributeTermsView

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

DistributeTermsView holds the terms and the recipient identity to be used by the view

func NewDistributeTermsView

func NewDistributeTermsView(recipient view.Identity, terms *Terms) *DistributeTermsView

NewDistributeTermsView creates a view which distributes the terms to the recipient

func (*DistributeTermsView) Call

func (v *DistributeTermsView) Call(context view.Context) (interface{}, error)

type ExpiredAndHashSelector added in v0.3.0

type ExpiredAndHashSelector struct {
	Hash []byte
}

ExpiredAndHashSelector selects expired htlc-tokens with a specific hash

func (*ExpiredAndHashSelector) Select added in v0.3.0

func (s *ExpiredAndHashSelector) Select(tok *token.UnspentToken, script *Script) (bool, error)

type FilteredIterator

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

func (*FilteredIterator) Close

func (f *FilteredIterator) Close()

func (*FilteredIterator) Next

func (f *FilteredIterator) Next() (*token2.UnspentToken, error)

func (*FilteredIterator) Sum

func (f *FilteredIterator) Sum(precision uint64) (token2.Quantity, error)

Sum computes the sum of the quantities of the tokens in the iterator. Sum closes the iterator at the end of the execution.

type HashInfo

type HashInfo struct {
	Hash         []byte
	HashFunc     crypto.Hash
	HashEncoding encoding.Encoding
}

HashInfo contains the information regarding the hashing

func (*HashInfo) Compare added in v0.3.0

func (i *HashInfo) Compare(image []byte) error

Compare compares the passed image with the hash contained in this struct

func (*HashInfo) Image

func (i *HashInfo) Image(preImage []byte) ([]byte, error)

Image computes the image of the passed pre-image using the hash and encoding function of this struct

func (*HashInfo) Validate

func (i *HashInfo) Validate() error

Validate checks that the hash and encoding functions are available

type Input

type Input struct {
	*token.Input
	// contains filtered or unexported fields
}

func ToInput

func ToInput(i *token.Input) (*Input, error)

func (*Input) IsHTLC

func (i *Input) IsHTLC() bool

func (*Input) Script

func (i *Input) Script() (*Script, error)

type Output

type Output struct {
	*token.Output
	// contains filtered or unexported fields
}

func ToOutput

func ToOutput(i *token.Output) (*Output, error)

func (*Output) IsHTLC

func (o *Output) IsHTLC() bool

func (*Output) Script

func (o *Output) Script() (*Script, error)

type OutputStream

type OutputStream struct {
	*token.OutputStream
}

OutputStream models a stream over a set of outputs

func NewOutputStream

func NewOutputStream(outputs *token.OutputStream) *OutputStream

NewOutputStream creates a new OutputStream for the passed outputs

func (*OutputStream) ByScript

func (o *OutputStream) ByScript() *OutputStream

ByScript filters the OutputStream to only include outputs that are owned by an htlc script

func (*OutputStream) Filter

func (o *OutputStream) Filter(f func(t *token.Output) bool) *OutputStream

Filter filters the OutputStream to only include outputs that match the passed predicate

func (*OutputStream) ScriptAt

func (o *OutputStream) ScriptAt(i int) *Script

ScriptAt returns an htlc script that is the owner of the output at the passed index of the OutputStream

type OwnerWallet

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

OwnerWallet is a combination of a wallet and a query service

func Wallet

func Wallet(sp view2.ServiceProvider, wallet *token.OwnerWallet) *OwnerWallet

Wallet returns an OwnerWallet which contains a wallet and a query service

func (*OwnerWallet) DeleteClaimedSentTokens

func (w *OwnerWallet) DeleteClaimedSentTokens(context view.Context, opts ...token.ListTokensOption) error

DeleteClaimedSentTokens removes the claimed htlc-tokens whose sender id is in this wallet

func (*OwnerWallet) DeleteExpiredReceivedTokens

func (w *OwnerWallet) DeleteExpiredReceivedTokens(context view.Context, opts ...token.ListTokensOption) error

DeleteExpiredReceivedTokens removes the expired htlc-tokens that have been reclaimed

func (*OwnerWallet) GetExpiredByHash added in v0.3.0

func (w *OwnerWallet) GetExpiredByHash(hash []byte, opts ...token.ListTokensOption) (*token2.UnspentToken, error)

GetExpiredByHash returns the expired htlc-token whose sender id is in this wallet and whose hash is equal to the one passed as argument. It fails if no tokens are found or if more than one token is found.

func (*OwnerWallet) GetExpiredReceivedTokenByHash added in v0.3.0

func (w *OwnerWallet) GetExpiredReceivedTokenByHash(hash []byte, opts ...token.ListTokensOption) (*token2.UnspentToken, error)

GetExpiredReceivedTokenByHash returns the expired htlc-token that matches the passed options, whose recipient belongs to this wallet, is expired, and hash the same hash. It fails if no tokens are found or if more than one token is found.

func (*OwnerWallet) ListByPreImage

func (w *OwnerWallet) ListByPreImage(preImage []byte, opts ...token.ListTokensOption) (*token2.UnspentTokens, error)

ListByPreImage returns a list of tokens whose recipient is this wallet and with a matching preimage

func (*OwnerWallet) ListByPreImageIterator

func (w *OwnerWallet) ListByPreImageIterator(preImage []byte, opts ...token.ListTokensOption) (*FilteredIterator, error)

ListByPreImageIterator returns an iterator of tokens whose recipient is this wallet and with a matching preimage

func (*OwnerWallet) ListExpired

func (w *OwnerWallet) ListExpired(opts ...token.ListTokensOption) (*token2.UnspentTokens, error)

ListExpired returns a list of expired htlc-tokens whose sender id is in this wallet

func (*OwnerWallet) ListExpiredIterator

func (w *OwnerWallet) ListExpiredIterator(opts ...token.ListTokensOption) (*FilteredIterator, error)

ListExpiredIterator returns a iterator of expired htlc-tokens whose sender id is in this wallet

func (*OwnerWallet) ListExpiredReceivedTokens

func (w *OwnerWallet) ListExpiredReceivedTokens(opts ...token.ListTokensOption) (*token2.UnspentTokens, error)

ListExpiredReceivedTokens returns a list of tokens that matches the passed options, whose recipient belongs to this wallet, and are expired

func (*OwnerWallet) ListExpiredReceivedTokensIterator

func (w *OwnerWallet) ListExpiredReceivedTokensIterator(opts ...token.ListTokensOption) (*FilteredIterator, error)

ListExpiredReceivedTokensIterator returns an iterator of tokens that matches the passed options, whose recipient belongs to this wallet, and are expired

func (*OwnerWallet) ListTokens

func (w *OwnerWallet) ListTokens(opts ...token.ListTokensOption) (*token2.UnspentTokens, error)

ListTokens returns a list of tokens that matches the passed options and whose recipient belongs to this wallet

func (*OwnerWallet) ListTokensAsSender

func (w *OwnerWallet) ListTokensAsSender(opts ...token.ListTokensOption) (*FilteredIterator, error)

ListTokensAsSender returns a list of non-expired htlc-tokens whose sender id is in this wallet

func (*OwnerWallet) ListTokensIterator

func (w *OwnerWallet) ListTokensIterator(opts ...token.ListTokensOption) (*FilteredIterator, error)

ListTokensIterator returns an iterator of tokens that matches the passed options and whose recipient belongs to this wallet

type PreImageSelector

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

PreImageSelector selects htlc-tokens that match a given pre-image

func (*PreImageSelector) Filter

func (f *PreImageSelector) Filter(tok *token.UnspentToken, script *Script) (bool, error)

type QueryEngine

type QueryEngine interface {
	// UnspentTokensIteratorBy returns an iterator over all unspent tokens by type and id. Type can be empty
	UnspentTokensIteratorBy(id, typ string) (driver.UnspentTokensIterator, error)
}

type Script

type Script struct {
	Sender    view.Identity
	Recipient view.Identity
	Deadline  time.Time
	HashInfo  HashInfo
}

Script contains the details of an htlc

func (*Script) Validate

func (s *Script) Validate(timeReference time.Time) error

Validate performs the following checks: - The sender must be set - The recipient must be set - The deadline must be after the passed time reference - HashInfo must be Available

type ScriptOwnership

type ScriptOwnership struct{}

ScriptOwnership implements the Ownership interface for scripts

func (*ScriptOwnership) AmIAnAuditor

func (s *ScriptOwnership) AmIAnAuditor(tms *token.ManagementService) bool

AmIAnAuditor returns false for script ownership

func (*ScriptOwnership) IsMine

func (s *ScriptOwnership) IsMine(tms *token.ManagementService, tok *token3.Token) ([]string, bool)

IsMine returns true if one is either a sender or a recipient of an htlc script

type SelectFunction

type SelectFunction = func(*token.UnspentToken, *Script) (bool, error)

SelectFunction is the prototype of a function to select pairs (token,script)

type Terms

type Terms struct {
	ReclamationDeadline time.Duration
	TMSID1              token.TMSID
	Type1               string
	Amount1             uint64
	TMSID2              token.TMSID
	Type2               string
	Amount2             uint64
}

Terms contains the details of the htlc to be examined

func ReceiveTerms

func ReceiveTerms(context view.Context) (*Terms, error)

ReceiveTerms runs the termsReceiverView and returns the received terms

func (*Terms) Bytes

func (t *Terms) Bytes() ([]byte, error)

Bytes serializes the terms

func (*Terms) FromBytes

func (t *Terms) FromBytes(raw []byte) error

FromBytes unmarshals terms

func (*Terms) Validate

func (t *Terms) Validate() error

Validate checks the terms

type Transaction

type Transaction struct {
	*ttx.Transaction
}

Transaction holds a ttx transaction

func NewAnonymousTransaction

func NewAnonymousTransaction(sp view.Context, opts ...ttx.TxOption) (*Transaction, error)

NewAnonymousTransaction returns a new anonymous token transaction customized with the passed opts

func NewTransaction

func NewTransaction(sp view.Context, signer view.Identity, opts ...ttx.TxOption) (*Transaction, error)

NewTransaction returns a new token transaction customized with the passed opts that will be signed by the passed signer

func NewTransactionFromBytes

func NewTransactionFromBytes(ctx view.Context, network, channel string, raw []byte) (*Transaction, error)

NewTransactionFromBytes returns a new transaction from the passed bytes

func ReceiveTransaction

func ReceiveTransaction(context view.Context) (*Transaction, error)

ReceiveTransaction executes the receiveTransactionView and returns the received transaction

func (*Transaction) Claim

func (t *Transaction) Claim(wallet *token.OwnerWallet, tok *token2.UnspentToken, preImage []byte) error

Claim appends a claim (transfer) action to the token request of the transaction

func (*Transaction) Lock

func (t *Transaction) Lock(wallet *token.OwnerWallet, sender view.Identity, typ string, value uint64, recipient view.Identity, deadline time.Duration, opts ...token.TransferOption) ([]byte, error)

Lock appends a lock action to the token request of the transaction

func (*Transaction) Outputs

func (t *Transaction) Outputs() (*OutputStream, error)

Outputs returns a new OutputStream of the transaction's outputs

func (*Transaction) Reclaim

func (t *Transaction) Reclaim(wallet *token.OwnerWallet, tok *token2.UnspentToken) error

Reclaim appends a reclaim (transfer) action to the token request of the transaction

type Verifier

type Verifier struct {
	Recipient driver.Verifier
	Sender    driver.Verifier
	Deadline  time.Time
	HashInfo  HashInfo
}

Verifier checks if an htlc script can be claimed or reclaimed

func (*Verifier) Verify

func (v *Verifier) Verify(msg []byte, sigma []byte) error

Verify verifies the claim or reclaim signature

Jump to

Keyboard shortcuts

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