Last active
October 15, 2023 15:36
-
-
Save moul/f3ae95981673f2f59b6c3b232c429666 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://twitter.com/jaekwon/status/1713308824269144423 | |
type Auth interface { | |
Owner() std.Address | |
Kind() string | |
Verify() bool | |
} | |
type origAuth struct{ addr std.Address } | |
func (a origAuth) Owner() std.Address { return a.addr } | |
func (a origAuth) Kind() string { return "orig" } | |
func (a origAuth) Verify() bool { return true } // Always return true for origAuth | |
func NewOrigAuth() Auth { return origAuth{std.GetOrigCaller()} } | |
type prevAuth struct{ addr std.Address } | |
func (a prevAuth) Owner() std.Address { return a.addr } | |
func (a prevAuth) Kind() string { return "prev" } | |
func (a prevAuth) Verify() bool { return true } // Always return true for prevAuth | |
func NewPrevAuth() Auth { return prevAuth{std.PrevRealm().Addr} } | |
type delegatedAuth struct { | |
owner std.Address | |
delegates map[std.Address]bool // Map to store approved delegates | |
} | |
func (a delegatedAuth) Owner() std.Address { return a.owner } | |
func (a delegatedAuth) Kind() string { return "delegated" } | |
func NewDelegatedAuth() Auth { | |
return &delegatedAuth{ | |
owner: std.GetOrigCaller(), | |
delegates: make(map[std.Address]bool), | |
} | |
} | |
func (a *delegatedAuth) Verify() bool { | |
return a.delegates[std.GetOrigCaller()] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment