transfer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v0.4.0

type Action struct {
	// Inputs specify the identifiers in of the tokens to be spent
	Inputs []*token2.ID
	// InputCommitments are the PedersenCommitments in the inputs
	InputTokens []*token.Token
	// OutputTokens are the new tokens resulting from the transfer
	OutputTokens []*token.Token
	// ZK Proof that shows that the transfer is correct
	Proof []byte
	// Metadata contains the transfer action's metadata
	Metadata map[string][]byte
}

Action specifies a transfer of one or more tokens

func NewTransfer

func NewTransfer(inputs []*token2.ID, inputToken []*token.Token, outputs []*math.G1, owners [][]byte, proof []byte) (*Action, error)

NewTransfer returns the Action that matches the passed arguments

func (*Action) Deserialize added in v0.4.0

func (t *Action) Deserialize(raw []byte) error

Deserialize unmarshals the Action

func (*Action) GetInputs added in v0.4.0

func (t *Action) GetInputs() []*token2.ID

GetInputs returns the inputs in the Action

func (*Action) GetMetadata added in v0.4.0

func (t *Action) GetMetadata() map[string][]byte

GetMetadata returns metadata of the Action

func (*Action) GetOutputCommitments added in v0.4.0

func (t *Action) GetOutputCommitments() []*math.G1

GetOutputCommitments returns the Pedersen commitments in the Action

func (*Action) GetOutputs added in v0.4.0

func (t *Action) GetOutputs() []driver.Output

GetOutputs returns the outputs in the Action

func (*Action) GetProof added in v0.4.0

func (t *Action) GetProof() []byte

GetProof returns the proof in the Action

func (*Action) GetSerialNumbers added in v0.4.0

func (t *Action) GetSerialNumbers() []string

func (*Action) GetSerializedInputs added in v0.4.0

func (t *Action) GetSerializedInputs() ([][]byte, error)

func (*Action) GetSerializedOutputs added in v0.4.0

func (t *Action) GetSerializedOutputs() ([][]byte, error)

GetSerializedOutputs returns the outputs in the Action serialized

func (*Action) IsGraphHiding added in v0.4.0

func (t *Action) IsGraphHiding() bool

IsGraphHiding returns false zkatdlog is not graph hiding

func (*Action) IsRedeemAt added in v0.4.0

func (t *Action) IsRedeemAt(index int) bool

IsRedeemAt checks if output in the Action at the passed index is redeemed

func (*Action) NumOutputs added in v0.4.0

func (t *Action) NumOutputs() int

NumOutputs returns the number of outputs in the Action

func (*Action) Serialize added in v0.4.0

func (t *Action) Serialize() ([]byte, error)

Serialize marshals the Action

func (*Action) SerializeOutputAt added in v0.4.0

func (t *Action) SerializeOutputAt(index int) ([]byte, error)

SerializeOutputAt marshals the output in the Action at the passed index

type Proof

type Proof struct {
	// proof that inputs and outputs in a Transfer Action are well-formed
	// inputs and outputs have the same total value
	// inputs and outputs have the same type
	TypeAndSum *TypeAndSumProof
	// Proof that the outputs have value in the authorized range
	RangeCorrectness *rp.RangeCorrectness
}

Proof is a zero-knowledge proof that shows that a Action is valid

func (*Proof) Deserialize

func (p *Proof) Deserialize(bytes []byte) error

Deserialize unmarshals Proof

func (*Proof) Serialize

func (p *Proof) Serialize() ([]byte, error)

Serialize marshals Proof

type Prover

type Prover struct {
	TypeAndSum       *TypeAndSumProver
	RangeCorrectness *rp.RangeCorrectnessProver
}

Prover produces a proof that a Action is valid

func NewProver

func NewProver(inputWitness, outputWitness []*token.TokenDataWitness, inputs, outputs []*math.G1, pp *crypto.PublicParams) (*Prover, error)

NewProver returns a Action Prover that corresponds to the passed arguments

func (*Prover) Prove

func (p *Prover) Prove() ([]byte, error)

Prove produces a serialized Proof

type Sender

type Sender struct {
	// Signers is an array of Signer that matches the owners of the inputs
	// to be spent in the transfer action
	Signers []driver.Signer
	// Inputs to be spent in the transfer
	Inputs []*token.Token
	// InputIDs is the identifiers of the Inputs to be spent
	InputIDs []*token2.ID
	// contains the opening of the inputs to be spent
	InputInformation []*token.Metadata
	// PublicParams refers to the public cryptographic parameters to be used
	// to produce the TokenRequest
	PublicParams *crypto.PublicParams
}

Sender produces a signed TokenRequest

func NewSender

func NewSender(signers []driver.Signer, tokens []*token.Token, ids []*token2.ID, inf []*token.Metadata, pp *crypto.PublicParams) (*Sender, error)

NewSender returns a Sender

func (*Sender) GenerateZKTransfer

func (s *Sender) GenerateZKTransfer(ctx context.Context, values []uint64, owners [][]byte) (*Action, []*token.Metadata, error)

GenerateZKTransfer produces a Action and an array of ValidationRecords that corresponds to the openings of the newly created outputs

func (*Sender) SignTokenActions

func (s *Sender) SignTokenActions(raw []byte, txID string) ([][]byte, error)

SignTokenActions produces a signature for each input spent by the Sender

type SigningIdentity

type SigningIdentity interface {
	driver.SigningIdentity
}

SigningIdentity signs TokenRequest

type TypeAndSumProof added in v0.4.0

type TypeAndSumProof struct {
	// a pedersen commitment to the type of the inputs and the outputs
	CommitmentToType *math.G1
	// proof of knowledge of the randomness used in Pedersen commitments in the inputs
	InputBlindingFactors []*math.Zr
	// proof of knowledge of the values encoded in the Pedersen commitments in the inputs
	InputValues []*math.Zr
	// proof of knowledge of the token type encoded in both inputs and outputs
	Type *math.Zr
	// proof of knowledge of blinding factor used to compute the commitment to type
	TypeBlindingFactor *math.Zr
	// proof of knowledge of equality of sum
	EqualityOfSum *math.Zr
	// challenge used in proof
	Challenge *math.Zr
}

TypeAndSumProof is zero-knowledge proof that shows that the inputs of a transaction have the same total value and the same type as its outputs

func (*TypeAndSumProof) Deserialize added in v0.4.0

func (p *TypeAndSumProof) Deserialize(bytes []byte) error

Deserialize un-marshals TypeAndSumProof

func (*TypeAndSumProof) Serialize added in v0.4.0

func (p *TypeAndSumProof) Serialize() ([]byte, error)

Serialize marshals TypeAndSumProof

type TypeAndSumProofCommitments added in v0.4.0

type TypeAndSumProofCommitments struct {
	Inputs           []*math.G1
	Sum              *math.G1
	CommitmentToType *math.G1
}

TypeAndSumProofCommitments are commitments to the randomness used in TypeAndSumProof

type TypeAndSumProofRandomness added in v0.4.0

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

TypeAndSumProofRandomness is the randomness used in the generation of TypeAndSumProof

type TypeAndSumProver added in v0.4.0

type TypeAndSumProver struct {
	// PedParams corresponds to the generators used to compute Pedersen commitments
	// (g_1, g_2, h)
	PedParams []*math.G1
	// Inputs are Pedersen commitments to (Type, Value) of the inputs to be spent
	Inputs []*math.G1
	// Outputs are Pedersen commitments to (Type, Value) of the outputs to be created
	// after the transfer
	Outputs []*math.G1
	// CommitmentToType is a Pedersen commitment to Type
	CommitmentToType *math.G1

	// Curve is the elliptic curve in which Pedersen commitments are computed
	Curve *math.Curve
	// contains filtered or unexported fields
}

TypeAndSumProver produces a TypeAndSumProof proof

func NewTypeAndSumProver added in v0.4.0

func NewTypeAndSumProver(witness *TypeAndSumWitness, pp []*math.G1, inputs []*math.G1, outputs []*math.G1, comType *math.G1, c *math.Curve) *TypeAndSumProver

NewTypeAndSumProver returns a NewTypeAndSumProver as a function of the passed arguments

func (*TypeAndSumProver) Prove added in v0.4.0

func (p *TypeAndSumProver) Prove() (*TypeAndSumProof, error)

Prove returns a serialized TypeAndSumProof proof

type TypeAndSumVerifier added in v0.4.0

type TypeAndSumVerifier struct {
	// PedParams corresponds to the generators used to compute Pedersen commitments
	// (g_1, g_2, h)
	PedParams []*math.G1
	// Curve is the elliptic curve in which Pedersen commitments are computed
	Curve *math.Curve
	// Inputs are Pedersen commitments to (Type, Value) of the inputs to be spent
	Inputs []*math.G1
	// Outputs are Pedersen commitments to (Type, Value) of the outputs to be created
	// after the transfer
	Outputs []*math.G1
}

TypeAndSumVerifier checks the validity of TypeAndSumProof

func NewTypeAndSumVerifier added in v0.4.0

func NewTypeAndSumVerifier(pp []*math.G1, inputs []*math.G1, outputs []*math.G1, c *math.Curve) *TypeAndSumVerifier

NewTypeAndSumVerifier returns a TypeAndSumVerifier as a function of the passed arguments

func (*TypeAndSumVerifier) Verify added in v0.4.0

func (v *TypeAndSumVerifier) Verify(stp *TypeAndSumProof) error

Verify returns an error when TypeAndSumProof is not a valid

type TypeAndSumWitness added in v0.4.0

type TypeAndSumWitness struct {

	// Type is the token type of inputs and outputs
	Type *math.Zr
	// contains filtered or unexported fields
}

TypeAndSumWitness contains the secret information used to produce TypeAndSumProof

func NewTypeAndSumWitness added in v0.4.0

func NewTypeAndSumWitness(bf *math.Zr, in, out []*token.TokenDataWitness, c *math.Curve) *TypeAndSumWitness

NewTypeAndSumWitness returns a TypeAndSumWitness as a function of the passed arguments

type Verifier

type Verifier struct {
	TypeAndSum       *TypeAndSumVerifier
	RangeCorrectness *rp.RangeCorrectnessVerifier
}

Verifier verifies if a Action is valid

func NewVerifier

func NewVerifier(inputs, outputs []*math.G1, pp *crypto.PublicParams) *Verifier

NewVerifier returns a Action Verifier as a function of the passed parameters

func (*Verifier) Verify

func (v *Verifier) Verify(proof []byte) error

Verify checks validity of serialized Proof

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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