types

package
v0.0.10-alpha Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 11 Imported by: 3

Documentation

Index

Constants

View Source
const (
	CommitmentLen = 32
	ScriptHashLen = 32
	AmountLen     = 8
	AmountPad     = 24
	AssetIDLen    = 32
	StateLen      = 128
	SaltLen       = 32
)
View Source
const NanosPerILX = 1e9
View Source
const NullifierSize = hash.HashSize

Variables

View Source
var ErrIDStrSize = fmt.Errorf("max ID string length is %v bytes", hash.HashSize*2)
View Source
var IlliumCoinID = NewID(bytes.Repeat([]byte{0x00}, 32))

Functions

func RandomSalt

func RandomSalt() ([32]byte, error)

RandomSalt generates a random number that is less than the lurk max field element.

Types

type Amount

type Amount uint64

Amount represents the base illium monetary unit (nanoillium or nanos). The total number of nanoillium issued is not expected to overflow an uint64 for 250 years from genesis.

func (Amount) ToBytes

func (a Amount) ToBytes() []byte

ToBytes returns the byte representation of the amount

func (Amount) ToILX

func (a Amount) ToILX() float64

ToILX returns the amount, formatted as ILX

type HexEncodable

type HexEncodable []byte

func (HexEncodable) MarshalJSON

func (h HexEncodable) MarshalJSON() ([]byte, error)

func (*HexEncodable) UnmarshalJSON

func (h *HexEncodable) UnmarshalJSON(data []byte) error

type ID

type ID [hash.HashSize]byte

func NewID

func NewID(digest []byte) ID

func NewIDFromData

func NewIDFromData(data []byte) ID

func NewIDFromString

func NewIDFromString(id string) (ID, error)

func (ID) Bytes

func (id ID) Bytes() []byte

func (ID) Clone

func (id ID) Clone() ID

func (ID) Compare

func (id ID) Compare(target ID) int

Compare returns 1 if hash > target, -1 if hash < target and 0 if hash == target.

func (*ID) MarshalJSON

func (id *ID) MarshalJSON() ([]byte, error)

func (*ID) SetBytes

func (id *ID) SetBytes(data []byte)

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

type LockingParams

type LockingParams [][]byte

func (*LockingParams) ToExpr

func (lp *LockingParams) ToExpr() (string, error)

type LockingScript

type LockingScript struct {
	ScriptCommitment ID
	LockingParams    [][]byte
}

LockingScript represents a utxo script in which coins are locked.

func (*LockingScript) Deserialize

func (ul *LockingScript) Deserialize(ser []byte) error

Deserialize turns a serialized byte slice back into an LockingScript

func (*LockingScript) Hash

func (u *LockingScript) Hash() (ID, error)

Hash returns the Lurk Commitment hash of the locking script

func (*LockingScript) Serialize

func (u *LockingScript) Serialize() []byte

Serialize returns the locking script serialized as a byte slice

type Nullifier

type Nullifier [hash.HashSize]byte

func CalculateNullifier

func CalculateNullifier(commitmentIndex uint64, salt [32]byte, scriptCommitment []byte, lockingParams ...[]byte) (Nullifier, error)

CalculateNullifier calculates and returns the nullifier for the given inputs.

func NewNullifier

func NewNullifier(b []byte) Nullifier

func NewNullifierFromString

func NewNullifierFromString(n string) (Nullifier, error)

func (Nullifier) Bytes

func (n Nullifier) Bytes() []byte

func (Nullifier) Clone added in v0.0.2

func (n Nullifier) Clone() Nullifier

func (*Nullifier) MarshalJSON

func (n *Nullifier) MarshalJSON() ([]byte, error)

func (*Nullifier) SetBytes

func (n *Nullifier) SetBytes(data []byte)

func (Nullifier) String

func (n Nullifier) String() string

func (*Nullifier) UnmarshalJSON

func (n *Nullifier) UnmarshalJSON(data []byte) error

type Serializable

type Serializable interface {
	Serialize() ([]byte, error)
	Deserialize(data []byte) error
	MarshalJSON() ([]byte, error)
	UnmarshalJSON(data []byte) error
}

type SpendNote

type SpendNote struct {
	ScriptHash ID
	Amount     Amount
	AssetID    ID
	Salt       [SaltLen]byte
	State      State
}

SpendNote holds all the data that makes up an output commitment.

func (*SpendNote) Commitment

func (s *SpendNote) Commitment() (ID, error)

Commitment builds a Lurk list expression out of the note data and returns the Lurk Commitment hash.

func (*SpendNote) Deserialize

func (s *SpendNote) Deserialize(ser []byte) error

Deserialize turns a serialized byte slice back into a SpendNote

func (*SpendNote) Serialize

func (s *SpendNote) Serialize() ([]byte, error)

Serialize returns the note serialized as a byte array. This format is suitable for encrypting and including in a transaction output.

func (*SpendNote) ToPublicCiphertext

func (s *SpendNote) ToPublicCiphertext() ([]byte, error)

ToPublicCiphertext returns the note serialization format used by the PublicAddressScript.

type State

type State [][]byte

State represents the state field out an output note.

There are two different representations of the state:

  • Inside a lurk program it is a list expression of field elements
  • Outside a lurk program we serialize it as a byte slice when encrypting the output note.

func (*State) Deserialize

func (s *State) Deserialize(ser []byte) error

Deserialize will deserialize the slice into the State.

func (*State) Serialize

func (s *State) Serialize(pad bool) ([]byte, error)

Serialize serializes the state into a format that can be encrypted and used as the ciphertext in a Transaction.

Each element is prepended with the element's length. If pad is true and the serialized length is less than 128, zeros will be appended.

A length byte of zero is treated as a delimiter.

func (*State) ToExpr

func (s *State) ToExpr() (string, error)

ToExpr converts the state to a lurk expression for use inside the lurk program.

Boolean: Elements with a len of 1 will be treated as a bool.

Uint64: Elements with len of 2-8 will be treated as a uint64.

Num: Elements with a len of 9-31 will be treated as a big endian lurk num.

Hash: If the element is len 32 it will be treated as a hex string prefixed with 0x. Lurk interprets this the same as Num.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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