jwz

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: AGPL-3.0 Imports: 16 Imported by: 5

README

jwz

Golang implementation of json web zeroknowledge

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAlgorithms

func GetAlgorithms() (algs []string)

GetAlgorithms returns a list of registered "alg" names

func Hash

func Hash(message []byte) (*big.Int, error)

Hash returns poseidon hash of big.Int that was created from sha256 hash of the message bytes if such big.Int is not in the Field, DivMod result is returned.

func RegisterProvingMethod

func RegisterProvingMethod(alg string, f func() ProvingMethod)

RegisterProvingMethod registers the "alg" name and a factory function for proving method. This is typically done during init() in the method's implementation

Types

type HeaderKey

type HeaderKey string

HeaderKey represents type for jwz headers keys

const (

	// HeaderType is 'typ' header, so we can set specific typ
	HeaderType HeaderKey = "typ" // we allow to set typ of token

)

type ProofInputsPreparerHandlerFunc

type ProofInputsPreparerHandlerFunc func(hash []byte, circuitID circuits.CircuitID) ([]byte, error)

ProofInputsPreparerHandlerFunc prepares inputs using hash message and circuit id

func (ProofInputsPreparerHandlerFunc) Prepare

func (f ProofInputsPreparerHandlerFunc) Prepare(hash []byte, circuitID circuits.CircuitID) ([]byte, error)

Prepare function is responsible to call provided handler for inputs preparation

type ProvingMethod

type ProvingMethod interface {
	Verify(messageHash []byte, proof *types.ZKProof, verificationKey []byte) error // Returns nil if proof is valid
	Prove(inputs []byte, provingKey []byte, wasm []byte) (*types.ZKProof, error)   // Returns proof or error
	Alg() string                                                                   // Returns the alg identifier for this method (example: 'AUTH-GROTH-16')
	CircuitID() string
}

ProvingMethod can be used add new methods for signing or verifying tokens.

func GetProvingMethod

func GetProvingMethod(alg string) (method ProvingMethod)

GetProvingMethod retrieves a proving method from an "alg" string

type ProvingMethodGroth16Auth

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

ProvingMethodGroth16Auth defines proofs family and specific circuit

var (
	ProvingMethodGroth16AuthInstance *ProvingMethodGroth16Auth
)

ProvingMethodGroth16AuthInstance instance for groth16 proving method with an auth circuit

func (*ProvingMethodGroth16Auth) Alg

Alg returns current zk alg

func (*ProvingMethodGroth16Auth) CircuitID

func (m *ProvingMethodGroth16Auth) CircuitID() string

CircuitID returns name of circuit

func (*ProvingMethodGroth16Auth) Prove

func (m *ProvingMethodGroth16Auth) Prove(inputs, provingKey, wasm []byte) (*types.ZKProof, error)

Prove generates proof using auth circuit and groth16 alg, checks that proven message hash is set as a part of circuit specific inputs

func (*ProvingMethodGroth16Auth) Verify

func (m *ProvingMethodGroth16Auth) Verify(messageHash []byte, proof *types.ZKProof, verificationKey []byte) error

Verify performs groth16 proof verification and checks equality of message hash and proven challenge public signals

type Token

type Token struct {
	ZkProof *types.ZKProof // The third segment of the token.  Populated when you Parse a token

	Alg       string // fields that are part of headers
	CircuitID string // id of circuit that will be used for proving

	Method ProvingMethod // proving method to create a zkp
	// contains filtered or unexported fields
}

Token represents a JWZ Token.

func NewWithPayload

func NewWithPayload(prover ProvingMethod, payload []byte, inputsPreparer ProofInputsPreparerHandlerFunc) (*Token, error)

NewWithPayload creates a new Token with the specified proving method and payload.

func Parse

func Parse(token string) (*Token, error)

Parse parses a jwz message in compact or full serialization format.

func (*Token) CompactSerialize

func (token *Token) CompactSerialize() (string, error)

CompactSerialize returns token serialized in three parts: base64 encoded headers, payload and proof.

func (*Token) FullSerialize

func (token *Token) FullSerialize() (string, error)

FullSerialize returns marshaled presentation of raw token as json string.

func (*Token) GetMessageHash

func (token *Token) GetMessageHash() ([]byte, error)

GetMessageHash returns bytes of jwz message hash.

func (*Token) GetPayload

func (token *Token) GetPayload() []byte

GetPayload returns message payload

func (*Token) ParsePubSignals

func (token *Token) ParsePubSignals(out circuits.PubSignalsUnmarshaller) error

ParsePubSignals unmarshalls proof public signals to provided structure.

func (*Token) Prove

func (token *Token) Prove(provingKey, wasm []byte) (string, error)

Prove creates and returns a complete, proved JWZ. The token is proven using the Proving Method specified in the token.

func (*Token) Verify

func (token *Token) Verify(verificationKey []byte) (bool, error)

Verify perform zero knowledge verification.

func (*Token) WithHeader

func (token *Token) WithHeader(key HeaderKey, value interface{}) error

WithHeader allows to set or redefine default headers

Jump to

Keyboard shortcuts

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