From c7b4b0251865fbaec06996abde316f3ce6664c8c Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 13 Nov 2024 12:39:27 +0100 Subject: [PATCH] use zkp unpacker params only (#63) use zkp unpacker params only --- packers/zkp.go | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/packers/zkp.go b/packers/zkp.go index 54431ad..4570932 100644 --- a/packers/zkp.go +++ b/packers/zkp.go @@ -263,33 +263,14 @@ func (p *ZKPPacker) MediaType() iden3comm.MediaType { return MediaTypeZKPMessage } -// DefaultZKPUnpackerOption is a function that sets the default ZKP unpacker options -type DefaultZKPUnpackerOption func(*zkUnpackerOpts) - -// WithAuthVerifyDelay sets the delay for the auth verification -func WithAuthVerifyDelay(delay time.Duration) DefaultZKPUnpackerOption { - return func(p *zkUnpackerOpts) { - p.authVerifyDelay = delay - } -} - -type zkUnpackerOpts struct { - authVerifyDelay time.Duration -} - type defaultZKPUnpacker struct { resolvers map[int]eth.Resolver - opts zkUnpackerOpts } // DefaultZKPUnpacker creates a default ZKP unpacker with the provided verification key and resolvers -func DefaultZKPUnpacker(verificationKey []byte, resolvers map[int]eth.Resolver, opts ...DefaultZKPUnpackerOption) *ZKPPacker { +func DefaultZKPUnpacker(verificationKey []byte, resolvers map[int]eth.Resolver) *ZKPPacker { def := &defaultZKPUnpacker{ resolvers: resolvers, - opts: zkUnpackerOpts{authVerifyDelay: time.Minute * 5}, - } - for _, opt := range opts { - opt(&def.opts) } verifications := make(map[jwz.ProvingMethodAlg]VerificationParams) verifications[jwz.AuthV2Groth16Alg] = NewVerificationParams(verificationKey, def.defaultZkpUnpackerVerificationFn) @@ -297,11 +278,6 @@ func DefaultZKPUnpacker(verificationKey []byte, resolvers map[int]eth.Resolver, } func (d *defaultZKPUnpacker) defaultZkpUnpackerVerificationFn(id circuits.CircuitID, pubsignals []string, opts ...ZKPPUnpackerParams) error { - authVerifyDelay := d.opts.authVerifyDelay - if len(opts) == 1 { - authVerifyDelay = opts[0].authVerifyDelay - } - if id != circuits.AuthV2CircuitID { return errors.Errorf("circuit ID '%s' is not supported", id) } @@ -346,6 +322,11 @@ func (d *defaultZKPUnpacker) defaultZkpUnpackerVerificationFn(id circuits.Circui globalState.String(), globalStateInfo.Root.String()) } + authVerifyDelay := time.Minute * 5 + if len(opts) > 0 { + authVerifyDelay = opts[0].authVerifyDelay + } + if (big.NewInt(0)).Cmp(globalStateInfo.ReplacedByRoot) != 0 && time.Since(time.Unix(globalStateInfo.ReplacedAtTimestamp.Int64(), 0)) > authVerifyDelay { return errors.Errorf("global state is too old, replaced timestamp is %v",