transfer

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ProtocolV1 = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Inputs specify the identifiers in of the tokens to be spent
	Inputs []*ActionInput
	// Outputs are the new tokens resulting from the transfer
	Outputs []*token.Token
	// ZK Proof that shows that the transfer is correct
	Proof []byte
	// Metadata contains the transfer action's metadata
	Metadata map[string][]byte
	// Issuer contains the identity of the issuer to sign the transfer action
	Issuer driver.Identity
}

Action specifies a transfer of one or more tokens

func NewTransfer

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

NewTransfer returns the Action that matches the passed arguments

func (*Action) Deserialize

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

Deserialize un-marshals TransferAction

func (*Action) ExtraSigners

func (t *Action) ExtraSigners() []driver.Identity

func (*Action) GetInputs

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

GetInputs returns the inputs in the Action

func (*Action) GetIssuer

func (t *Action) GetIssuer() driver.Identity

GetIssuer returns the issuer to sign the transaction

func (*Action) GetMetadata

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

GetMetadata returns metadata of the Action

func (*Action) GetOutputCommitments

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

GetOutputCommitments returns the Pedersen commitments in the Action

func (*Action) GetOutputs

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

GetOutputs returns the outputs in the Action

func (*Action) GetProof

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

GetProof returns the proof in the Action

func (*Action) GetSerialNumbers

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

func (*Action) GetSerializedInputs

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

func (*Action) GetSerializedOutputs

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

GetSerializedOutputs returns the outputs in the Action serialized

func (*Action) InputTokens

func (t *Action) InputTokens() []*token.Token

func (*Action) IsGraphHiding

func (t *Action) IsGraphHiding() bool

IsGraphHiding returns false zkatdlog is not graph hiding

func (*Action) IsRedeem

func (t *Action) IsRedeem() bool

IsRedeem checks if this action is a Redeem Transfer

func (*Action) IsRedeemAt

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

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

func (*Action) NumInputs

func (t *Action) NumInputs() int

func (*Action) NumOutputs

func (t *Action) NumOutputs() int

NumOutputs returns the number of outputs in the Action

func (*Action) Serialize

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

Serialize marshal TransferAction

func (*Action) SerializeOutputAt

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

SerializeOutputAt marshals the output in the Action at the passed index

func (*Action) Validate

func (t *Action) Validate() error

type ActionInput

type ActionInput struct {
	ID             *token2.ID
	Token          *token.Token
	UpgradeWitness *token.UpgradeWitness
}

func (*ActionInput) FromProtos

func (a *ActionInput) FromProtos(input *actions.TransferActionInput) error

func (*ActionInput) ToProtos

func (a *ActionInput) ToProtos() (*actions.TransferActionInput, error)

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

func (*Proof) Validate

func (p *Proof) Validate(curve math.CurveID) error

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.Metadata, inputs, outputs []*math.G1, pp *v1.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 *v1.PublicParams
}

Sender produces a signed TokenRequest

func NewSender

func NewSender(signers []driver.Signer, tokens []*token.Token, ids []*token2.ID, inf []*token.Metadata, pp *v1.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) ([][]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

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

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

Deserialize un-marshals TypeAndSumProof

func (*TypeAndSumProof) Serialize

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

Serialize marshals TypeAndSumProof

func (*TypeAndSumProof) Validate

func (p *TypeAndSumProof) Validate(curveID math.CurveID) error

type TypeAndSumProofCommitments

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

TypeAndSumProofCommitments are commitments to the randomness used in TypeAndSumProof

type TypeAndSumProofRandomness

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

TypeAndSumProofRandomness is the randomness used in the generation of TypeAndSumProof

type TypeAndSumProver

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

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

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

Prove returns a serialized TypeAndSumProof proof

type TypeAndSumVerifier

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

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

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

Verify returns an error when TypeAndSumProof is not a valid

type TypeAndSumWitness

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

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

NewTypeAndSumWitness returns a TypeAndSumWitness as a function of the passed arguments

type Verifier

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

Verifier verifies if a Action is valid

func NewVerifier

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

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

func (*Verifier) Verify

func (v *Verifier) Verify(proofRaw []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