timelock

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

timelock

Pure Go implementation of Tezos Timelocks and Chest primitives.

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidArgument = errors.New("invalid argument")
	ErrVerification    = errors.New("timelock tuple verification failed")
)

Functions

func Decrypt

func Decrypt(key *[32]byte, c *CipherText) ([]byte, bool)

func NewChest

func NewChest(random io.Reader, payload []byte, time int, mod *big.Int) (chest *Chest, key *ChestKey, err error)
Example
time := 10_000
payload := []byte("message")
chest, key, err := NewChest(rand.Reader, payload, time, nil)
fmt.Println(err)

var chestBytes, keyBytes bytes.Buffer
err = encoding.Encode(&chestBytes, chest)
fmt.Println(err)
err = encoding.Encode(&keyBytes, key)
fmt.Println(err)
Output:

<nil>
<nil>
<nil>

func NewChestFromTimelock

func NewChestFromTimelock(random io.Reader, payload []byte, time int, timelock *Timelock, mod *big.Int) (chest *Chest, key *ChestKey, err error)
Example
time := 10_000
precomputed, err := PrecomputeTimelock(rand.Reader, time, nil) // can be cached
fmt.Println(err)

payload := []byte("message")
chest, key, err := NewChestFromTimelock(rand.Reader, payload, time, precomputed, nil)
fmt.Println(err)

var chestBytes, keyBytes bytes.Buffer
err = encoding.Encode(&chestBytes, chest)
fmt.Println(err)
err = encoding.Encode(&keyBytes, key)
fmt.Println(err)
Output:

<nil>
<nil>
<nil>
<nil>

func Verify

func Verify(locked *big.Int, proof *TimelockProof, time int, mod *big.Int) bool

Types

type Chest

type Chest struct {
	LockedValue tz.BigUint `json:"locked_value"`
	CipherText  CipherText `json:"ciphertext"`
}

func (*Chest) NewKey

func (chest *Chest) NewKey(time int, mod *big.Int) (key *ChestKey, err error)

func (*Chest) Open

func (chest *Chest) Open(key *ChestKey, time int, mod *big.Int) ([]byte, bool, error)

type ChestKey

type ChestKey = TimelockProof

type CipherText

type CipherText struct {
	Nonce   [24]byte `json:"nonce"`
	Payload []byte   `tz:"dyn" json:"payload"`
}

func Encrypt

func Encrypt(random io.Reader, key *[32]byte, payload []byte) (*CipherText, error)

type Timelock

type Timelock struct {
	LockedValue   tz.BigUint `json:"locked_value"`
	UnlockedValue tz.BigUint `json:"unlocked_value"`
	VDFProof      tz.BigUint `json:"vdf_proof"`
}

func PrecomputeTimelock

func PrecomputeTimelock(random io.Reader, time int, mod *big.Int) (*Timelock, error)

func (*Timelock) NewProof

func (v *Timelock) NewProof(random io.Reader, time int, mod *big.Int) (locked *big.Int, proof *TimelockProof, err error)

type TimelockProof

type TimelockProof struct {
	VDFTuple Timelock   `json:"vdf_tuple"`
	Nonce    tz.BigUint `json:"nonce"`
}

func Prove

func Prove(time int, locked, unlocked, mod *big.Int) *TimelockProof

func UnlockAndProve

func UnlockAndProve(time int, locked, mod *big.Int) *TimelockProof

func (*TimelockProof) SymmetricKey

func (p *TimelockProof) SymmetricKey(mod *big.Int) [32]byte

Jump to

Keyboard shortcuts

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