Search Apps Documentation Source Content File Folder Download Copy Actions Download

verifier.gno

1.36 Kb · 46 lines
 1// Package names enforces namespace permissions for package deployment.
 2// Only address-prefix (PA) namespaces are allowed.
 3package names
 4
 5import "chain/runtime"
 6
 7var (
 8	admin   = address("g1rp7cmetn27eqlpjpc4vuusf8kaj746tysc0qgh") // govdao t1 multisig
 9	enabled = false
10)
11
12// IsAuthorizedAddressForNamespace checks if the given address can deploy to the given namespace.
13// Only the address's own PA namespace is permitted.
14func IsAuthorizedAddressForNamespace(address_XXX address, namespace string) bool {
15	return verifier(enabled, address_XXX, namespace)
16}
17
18// Enable enables the namespace check for this realm.
19// The namespace check is disabled initially to ease txtar and other testing contexts,
20// but this function is meant to be called in the genesis of a chain.
21func Enable(cur realm) {
22	if runtime.PreviousRealm().Address() != admin {
23		panic("caller is not admin")
24	}
25	enabled = true
26}
27
28func IsEnabled() bool {
29	return enabled
30}
31
32// verifier checks namespace deployment permissions.
33// An address matching the namespace is the only allowed case.
34func verifier(isEnabled bool, address_XXX address, namespace string) bool {
35	if !isEnabled {
36		return true // only in pre-genesis cases
37	}
38
39	if namespace == "" || !address_XXX.IsValid() {
40		return false
41	}
42
43	// Allow user with their own address as namespace
44	// ie gno.land/{p,r}/{ADDRESS}/**
45	return address_XXX.String() == namespace
46}