Documentation ¶
Overview ¶
Package jwz contains implementation of JSON WEB ZERO-Knowledge specification.
Index ¶
- Constants
- Variables
- func Hash(message []byte) (*big.Int, error)
- func RegisterProvingMethod(alg ProvingMethodAlg, f func() ProvingMethod)
- type HeaderKey
- type ProofInputsPreparerHandlerFunc
- type ProvingMethod
- type ProvingMethodAlg
- type ProvingMethodGroth16Auth
- func (m *ProvingMethodGroth16Auth) Alg() string
- func (m *ProvingMethodGroth16Auth) CircuitID() string
- func (m *ProvingMethodGroth16Auth) Prove(inputs, provingKey, wasm []byte) (*types.ZKProof, error)
- func (m *ProvingMethodGroth16Auth) Verify(messageHash []byte, proof *types.ZKProof, verificationKey []byte) error
- type ProvingMethodGroth16AuthV2
- func (m *ProvingMethodGroth16AuthV2) Alg() string
- func (m *ProvingMethodGroth16AuthV2) CircuitID() string
- func (m *ProvingMethodGroth16AuthV2) Prove(inputs, provingKey, wasm []byte) (*types.ZKProof, error)
- func (m *ProvingMethodGroth16AuthV2) Verify(messageHash []byte, proof *types.ZKProof, verificationKey []byte) error
- type Token
- func (token *Token) CompactSerialize() (string, error)
- func (token *Token) FullSerialize() (string, error)
- func (token *Token) GetHeader() map[HeaderKey]interface{}
- func (token *Token) GetMessageHash() ([]byte, error)
- func (token *Token) GetPayload() []byte
- func (token *Token) ParsePubSignals(out circuits.PubSignalsUnmarshaller) error
- func (token *Token) Prove(provingKey, wasm []byte) (string, error)
- func (token *Token) Verify(verificationKey []byte) (bool, error)
- func (token *Token) WithHeader(key HeaderKey, value interface{}) error
Constants ¶
const ( // Groth16 alg Groth16 string = "groth16" )
Variables ¶
var AuthGroth16Alg = ProvingMethodAlg{Groth16, string(circuits.AuthCircuitID)}
AuthGroth16Alg its first auth v1 alg (groth16 vs auth v1 circuit)
var AuthV2Groth16Alg = ProvingMethodAlg{Groth16, string(circuits.AuthV2CircuitID)}
AuthV2Groth16Alg its auth v2 alg (groth16 vs auth v2 circuit)
Functions ¶
func Hash ¶
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 ProvingMethodAlg, 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 ¶
ProofInputsPreparerHandlerFunc prepares inputs using hash message and circuit id
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 ProvingMethodAlg) (method ProvingMethod)
GetProvingMethod retrieves a proving method from an "alg" string
type ProvingMethodAlg ¶
ProvingMethodAlg defines proofs family and specific circuit
func GetAlgorithms ¶
func GetAlgorithms() (algs []ProvingMethodAlg)
GetAlgorithms returns a list of registered "alg" names
func NewProvingMethodAlg ¶
func NewProvingMethodAlg(alg, circuitID string) ProvingMethodAlg
NewProvingMethodAlg creates a new ProvingMethodAlg
type ProvingMethodGroth16Auth ¶
type ProvingMethodGroth16Auth struct {
ProvingMethodAlg
}
ProvingMethodGroth16Auth defines proofs family and specific circuit
var (
ProvingMethodGroth16AuthInstance *ProvingMethodGroth16Auth
)
ProvingMethodGroth16AuthInstance instance for Groth16 proving method with an auth circuit
func (*ProvingMethodGroth16Auth) Alg ¶
func (m *ProvingMethodGroth16Auth) Alg() string
Alg returns current zk alg
func (*ProvingMethodGroth16Auth) CircuitID ¶
func (m *ProvingMethodGroth16Auth) CircuitID() string
CircuitID returns name of circuit
type ProvingMethodGroth16AuthV2 ¶
type ProvingMethodGroth16AuthV2 struct { ProvingMethodAlg // contains filtered or unexported fields }
ProvingMethodGroth16AuthV2 instance for Groth16 proving method with an authV2 circuit
var (
ProvingMethodGroth16AuthV2Instance *ProvingMethodGroth16AuthV2
)
ProvingMethodGroth16AuthInstance instance for Groth16 proving method with an authV2 circuit
func (*ProvingMethodGroth16AuthV2) Alg ¶
func (m *ProvingMethodGroth16AuthV2) Alg() string
Alg returns current zk alg
func (*ProvingMethodGroth16AuthV2) CircuitID ¶
func (m *ProvingMethodGroth16AuthV2) CircuitID() string
CircuitID returns name of circuit
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 (*Token) CompactSerialize ¶
CompactSerialize returns token serialized in three parts: base64 encoded headers, payload and proof.
func (*Token) FullSerialize ¶
FullSerialize returns marshaled presentation of raw token as json string.
func (*Token) GetMessageHash ¶
GetMessageHash returns bytes of jwz message hash.
func (*Token) GetPayload ¶
GetPayload returns message payload
func (*Token) ParsePubSignals ¶
ParsePubSignals unmarshalls proof public signals to provided structure.
func (*Token) Prove ¶
Prove creates and returns a complete, proved JWZ. The token is proven using the Proving Method specified in the token.
func (*Token) WithHeader ¶
WithHeader allows to set or redefine default headers