Skip to content

Instantly share code, notes, and snippets.

@moul
Last active October 15, 2023 15:36
Show Gist options
  • Save moul/f3ae95981673f2f59b6c3b232c429666 to your computer and use it in GitHub Desktop.
Save moul/f3ae95981673f2f59b6c3b232c429666 to your computer and use it in GitHub Desktop.
// 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