transactions

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const GenesisExpirationHeight = 250001

GenesisExpirationHeight sets the heigth for expiration of the Genesis block

View Source
const MaxLockTime = 250000

MaxLockTime sets the maximum lock time to 250000 blocks

Variables

This section is empty.

Functions

func CommitAmount

func CommitAmount(amount, mask ristretto.Scalar) ristretto.Point

CommitAmount creates a commitment for the specifie amount

func DecryptAmount

func DecryptAmount(encAmount ristretto.Scalar, R ristretto.Point, index uint32, privViewKey key.PrivateView) ristretto.Scalar

DecryptAmount decAmount = EncAmount - H(H(H(R*PrivViewKey || index)))

func DecryptMask

func DecryptMask(encMask ristretto.Scalar, R ristretto.Point, index uint32, privViewKey key.PrivateView) ristretto.Scalar

DecryptMask decMask = Encmask - H(H(r*PubViewKey || index))

func EncryptAmount

func EncryptAmount(amount, r ristretto.Scalar, index uint32, pubViewKey key.PublicView) ristretto.Scalar

EncryptAmount encAmount = amount + H(H(H(r*PubViewKey || index)))

func EncryptMask

func EncryptMask(mask, r ristretto.Scalar, index uint32, pubViewKey key.PublicView) ristretto.Scalar

EncryptMask encMask = mask + H(H(r*PubViewKey || index))

func ShouldEncryptValues

func ShouldEncryptValues(tx Transaction) bool

ShouldEncryptValues returns whether a transaction should be encrypted

Types

type Bid

type Bid struct {
	*Timelock
	M []byte
}

Bid transaction

func NewBid

func NewBid(ver uint8, netPrefix byte, fee int64, lock uint64, M []byte) (*Bid, error)

NewBid creates a new blind bid transaction

func (*Bid) CalculateHash

func (b *Bid) CalculateHash() ([]byte, error)

CalculateHash calculates the hash

func (*Bid) Equals

func (b *Bid) Equals(t Transaction) bool

Equals tests for equality to this bid

func (*Bid) LockTime

func (b *Bid) LockTime() uint64

LockTime returns the lock time for this bid

func (*Bid) Prove

func (b *Bid) Prove() error

Prove the bid to me!

func (*Bid) StandardTx

func (b *Bid) StandardTx() *Standard

StandardTx returns the standard transaction form of this bid

func (*Bid) Type

func (b *Bid) Type() TxType

Type returns the transaction type

type Coinbase

type Coinbase struct {
	//// Encoded fields
	TxType
	R       ristretto.Point
	Score   []byte
	Proof   []byte
	Rewards Outputs

	TxID []byte
	// contains filtered or unexported fields
}

Coinbase transaction

func NewCoinbase

func NewCoinbase(proof, score []byte, netPrefix byte) *Coinbase

NewCoinbase creates a new coinbase

func (*Coinbase) AddReward

func (c *Coinbase) AddReward(pubKey key.PublicKey, amount ristretto.Scalar) error

AddReward adds the reward to the coinbase outputs

func (*Coinbase) CalculateHash

func (c *Coinbase) CalculateHash() ([]byte, error)

CalculateHash calculates the hash of the coinbase tx

func (*Coinbase) Equals

func (c *Coinbase) Equals(t Transaction) bool

Equals tests if a transaction is equal to this coinbase tx

func (*Coinbase) LockTime

func (c *Coinbase) LockTime() uint64

LockTime is 0 for a coinbase transaction

func (*Coinbase) SetTxPubKey

func (c *Coinbase) SetTxPubKey(r ristretto.Scalar)

SetTxPubKey sets the public key of the transaction

func (*Coinbase) StandardTx

func (c *Coinbase) StandardTx() *Standard

StandardTx returns the Standard form of the transaction

func (*Coinbase) Type

func (c *Coinbase) Type() TxType

Type returns the type of the transaction

type FetchDecoys

type FetchDecoys func(numMixins int) []mlsag.PubKeys

FetchDecoys is a function that creates a decoy (ring signature) by camuflaging the actual public key of the signer among a collection of public keys

type Input

type Input struct {

	// One-time pubkey of the receiver
	// Each input will contain a one-time pubkey
	// Only the private key assosciated with this
	// public key can unlock the funds available at this utxo
	PubKey key.StealthAddress

	// PseudoCommitment refers to a commitment which commits to the same amount
	// as our `Commitment` value, however the mask value is changed. This is to be used in proving
	// that the sumInputs-SumOutputs = 0
	PseudoCommitment ristretto.Point
	// Proof is zk proof that proves that the signer knows the one-time pubkey assosciated with
	// an input in the ring. The secondary key in the key-vector is used as an intermediate process
	// for the balance proof. This will use a pseudo-commitment s.t. C = Comm(amount, r)
	// However, in order for the proof to work we need to know all inputs and outputs in the tx.
	// Proof will output a signature and a keyimage
	Proof     *mlsag.DualKey
	Signature *mlsag.Signature
	KeyImage  ristretto.Point
	// contains filtered or unexported fields
}

Input of a transaction

func NewInput

func NewInput(amount, mask, privkey ristretto.Scalar) *Input

NewInput creates a new transaction input / XXX: maybe we should take an dusk-tx-output and the privkey We can then derive the amount, mask from the encrypted amounts We can derive the mask from encryptedMask, as it is deterministic we can also derive the pubkey

func (*Input) Equals

func (i *Input) Equals(in *Input) bool

Equals returns true if two inputs are the same

func (*Input) Prove

func (i *Input) Prove() error

Prove the transaction input

type Inputs

type Inputs []*Input

Inputs is a slice of pointers to a set of `input`'s

func (Inputs) Equals

func (in Inputs) Equals(other Inputs) bool

Equals returns true, if two slices of inputs are the same

func (Inputs) HasDuplicates

func (in Inputs) HasDuplicates() bool

HasDuplicates checks whether any of the inputs contain duplciates This is done by checking their keyImages

func (Inputs) Len

func (in Inputs) Len() int

Len implements the sort interface

func (Inputs) Less

func (in Inputs) Less(i, j int) bool

Less implements the sort interface

func (Inputs) Swap

func (in Inputs) Swap(i, j int)

Swap implements the sort interface

type Output

type Output struct {
	// Commitment to the amount and the mask value
	// This will be generated by the rangeproof
	Commitment ristretto.Point

	// PubKey refers to the destination key of the receiver
	// One-time pubkey of the receiver
	// Each input will contain a one-time pubkey
	// Only the private key assosciated with this
	// public key can unlock the funds available at this utxo
	PubKey key.StealthAddress

	// Index denotes the position that this output is in the
	// transaction. This is different to the Offset which denotes the
	// position that this output is in, from the start from the blockchain
	Index uint32

	EncryptedAmount ristretto.Scalar
	EncryptedMask   ristretto.Scalar
	// contains filtered or unexported fields
}

Output of a transaction

func NewOutput

func NewOutput(r, amount ristretto.Scalar, index uint32, pubKey key.PublicKey) *Output

NewOutput creates a new transaction Output

func (*Output) Equals

func (o *Output) Equals(out *Output) bool

Equals returns true if two outputs are the same

type Outputs

type Outputs []*Output

Outputs is a slice of pointers to a set of `input`'s

func (Outputs) Equals

func (out Outputs) Equals(other Outputs) bool

Equals returns true, if two slices of Outputs are the same

func (Outputs) HasDuplicates

func (out Outputs) HasDuplicates() bool

HasDuplicates checks whether an output contains a duplicate This is done by checking that there are no matching Destination keys

func (Outputs) Len

func (out Outputs) Len() int

Len implements the sort interface

func (Outputs) Less

func (out Outputs) Less(i, j int) bool

Less implements the sort interface

func (Outputs) Swap

func (out Outputs) Swap(i, j int)

Swap implements the sort interface

type Stake

type Stake struct {
	*Timelock
	PubKeyBLS []byte
}

Stake encapsulates a Stake transaction

func NewStake

func NewStake(ver uint8, netPrefix byte, fee int64, lock uint64, pubKeyBLS []byte) (*Stake, error)

NewStake creates a new Stake transaction

func (*Stake) CalculateHash

func (s *Stake) CalculateHash() ([]byte, error)

CalculateHash calculates the hash of this transaction

func (*Stake) Equals

func (s *Stake) Equals(t Transaction) bool

Equals test the transactions equality

func (*Stake) LockTime

func (s *Stake) LockTime() uint64

LockTime returns the lock time of this transaction

func (*Stake) Prove

func (s *Stake) Prove() error

Prove the transaction

func (*Stake) StandardTx

func (s *Stake) StandardTx() *Standard

StandardTx returns the Standard transaction

func (*Stake) Type

func (s *Stake) Type() TxType

Type returns the transaction type

type Standard

type Standard struct {
	//// Encoded fields
	// TxType represents the transaction type
	TxType TxType

	// R is the transaction Public Key
	R ristretto.Point

	// Version is the transaction version. It does not use semver.
	// A new transaction version denotes a modification of the previous structure
	Version uint8 // 1 byte

	// Inputs represent a list of inputs to the transaction.
	Inputs
	// Outputs represent a list of outputs to the transaction
	Outputs

	Fee ristretto.Scalar

	// RangeProof is the bulletproof rangeproof that proves that the hidden amount
	// is between 0 and 2^64
	RangeProof rangeproof.Proof

	// TxID is the hash of the transaction fields.
	TxID []byte

	TotalSent ristretto.Scalar
	// contains filtered or unexported fields
}

Standard is a generic transaction. It can also be seen as a stealth transaction. It is used to make basic payments on the dusk network.

func NewStandard

func NewStandard(ver uint8, netPrefix byte, fee int64) (*Standard, error)

NewStandard creates a new Standard transaction

func (*Standard) AddDecoys

func (s *Standard) AddDecoys(numMixins int, f FetchDecoys) error

AddDecoys to a standard transaction

func (*Standard) AddInput

func (s *Standard) AddInput(i *Input) error

AddInput to the standard transaction

func (*Standard) AddOutput

func (s *Standard) AddOutput(pubAddr key.PublicAddress, amount ristretto.Scalar) error

AddOutput to a Standard transaction

func (*Standard) CalculateHash

func (s *Standard) CalculateHash() ([]byte, error)

CalculateHash calculates the SHA3 hash of this Standard transaction

func (*Standard) Equals

func (s *Standard) Equals(t Transaction) bool

Equals returns true if two standard tx's are the same

func (*Standard) LockTime

func (s *Standard) LockTime() uint64

LockTime returns 0 since Standard is not a time locked transaction. See Timelock

func (*Standard) Prove

func (s *Standard) Prove() error

Prove creates the rangeproof for output values and creates the mlsag balance and ownership proof Prove assumes that all inputs, outputs and decoys have been added to the transaction

func (*Standard) ProveRangeProof

func (s *Standard) ProveRangeProof() error

ProveRangeProof proves that the transaction amount is positive

func (*Standard) StandardTx

func (s *Standard) StandardTx() *Standard

StandardTx returns this

func (*Standard) Type

func (s *Standard) Type() TxType

Type returns the transaction type

type Timelock

type Timelock struct {
	*Standard
	Lock uint64
}

Timelock represents a standard transaction that has an additional time restriction What does the time-lock represent? For a `Standard TimeLock`; that the TX can only become valid after the time stated. This is not the case for others, please check each transaction for the significance of the timelock

func NewTimelock

func NewTimelock(ver uint8, netPrefix byte, fee int64, lock uint64) (*Timelock, error)

NewTimelock creates a Timelock

func (*Timelock) CalculateHash

func (tl *Timelock) CalculateHash() ([]byte, error)

CalculateHash calculate the SHA3 hash of the timelock

func (*Timelock) Equals

func (tl *Timelock) Equals(t Transaction) bool

Equals checks the equality of the transaction

func (*Timelock) LockTime

func (tl *Timelock) LockTime() uint64

LockTime returns the remaining lock time

func (*Timelock) Prove

func (tl *Timelock) Prove() error

Prove by checking that the hash is correct

func (*Timelock) StandardTx

func (tl *Timelock) StandardTx() *Standard

StandardTx returns the standard transaction encapsulated within the TimeLock

func (*Timelock) Type

func (tl *Timelock) Type() TxType

Type returns the transaction type

type Transaction

type Transaction interface {
	TypeInfo
	merkletree.Payload
	Equals(Transaction) bool
	StandardTx() *Standard
	LockTime() uint64
}

Transaction represents all transaction structures All transactions will embed the standard transaction. Returning Standard() allows the caller to fetch the inputs/outputs/fees without type casting the Transaction interface to a specific type

type TxType

type TxType uint8

TxType defines a transaction type identifier.

const (
	// CoinbaseType is the identifier for a block coinbase
	CoinbaseType TxType = 0x00

	// BidType is the identifier for a blind bid
	BidType TxType = 0x01

	// StakeType is the identifier for a stake
	StakeType TxType = 0x02

	// StandardType is the identifier for a standard transaction
	StandardType TxType = 0x03

	// TimelockType is the identifier for a standard time-locked transaction
	TimelockType TxType = 0x04

	// ContractType is the identifier for a smart contract transaction
	ContractType TxType = 0x05
)

type TypeInfo

type TypeInfo interface {
	Type() TxType
}

TypeInfo returns the underlying type of the transaction This allows the caller to type cast to a TypeInfo and switch on the Types in order to Decode into a TX

Jump to

Keyboard shortcuts

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