pub struct Permit<P: Permission> {
pub params: PermitParams<P>,
pub address: String,
}
Expand description
The type the represents a signed permit. You shouldn’t try to instantiate this type yourself unless you are writing test code. Rather you set this as a parameter in your contract query functions that you wish to authenticate.
Fields§
§params: PermitParams<P>
§address: String
Implementations§
source§impl<P: Permission> Permit<P>
impl<P: Permission> Permit<P>
sourcepub fn new(signer: impl Into<String>, params: PermitParams<P>) -> Self
pub fn new(signer: impl Into<String>, params: PermitParams<P>) -> Self
Creates a new instance using the given params
and signer
which
is the address that “signed” the permit. This method is only useful
in test code to create mock a permit.
source§impl<P: Permission> Permit<P>
impl<P: Permission> Permit<P>
sourcepub fn validate(
&self,
deps: Deps<'_>,
current_contract_addr: &str,
hrp: Option<&str>,
expected_permissions: &[P]
) -> StdResult<String>
pub fn validate( &self, deps: Deps<'_>, current_contract_addr: &str, hrp: Option<&str>, expected_permissions: &[P] ) -> StdResult<String>
Validates the permit by checking whether it contains
the expected permissions, the current_contract_addr
is
allowed, the permit hasn’t been revoked (based on its name)
and veryfing the cryptographic signature. If any of these
prerequisites fails, an error is returned. Otherwise, returns
the address that signed the permit.
Parameters:
deps
: Needed to check whether the permit has been revoked and verify signature.current_contract_addr
: The contract address that is calling this function i.eenv.contract.address
.hrp
: The address prefix i.e the “secret” part of the address “secret1k0jntykt7e4g3y88ltc60czgjuqdy4c9e8fzek”. Should be left asNone
most of the time.expected_permissions
: The permission set that the permit needs to contains in order to successfully pass verification. Pass an empty slice (&[]
) if you don’t need to check permissions.
sourcepub fn assert_not_revoked(
storage: &dyn Storage,
account: &str,
permit_name: &str
) -> StdResult<()>
pub fn assert_not_revoked( storage: &dyn Storage, account: &str, permit_name: &str ) -> StdResult<()>
Checks if the permit has been revoked based on the permit_name
parameter.
This is already being called by Permit::validate
.
sourcepub fn revoke(storage: &mut dyn Storage, account: &Addr, permit_name: &str)
pub fn revoke(storage: &mut dyn Storage, account: &Addr, permit_name: &str)
Mark any permit with permit_name
that is signed by account
as revoked.
Any such permit will fail verification.
sourcepub fn has_permission(&self, permission: &P) -> bool
pub fn has_permission(&self, permission: &P) -> bool
Check if the permit contains the given permission.
This is already being called by Permit::validate
.
sourcepub fn is_for_contract(&self, contract: &str) -> bool
pub fn is_for_contract(&self, contract: &str) -> bool
Check if the given contract address is allowed to use this permit.
This is already being called by Permit::validate
.
Trait Implementations§
source§impl<'de, P> Deserialize<'de> for Permit<P>where
P: Deserialize<'de> + Permission,
impl<'de, P> Deserialize<'de> for Permit<P>where P: Deserialize<'de> + Permission,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl<P: Permission + JsonSchema> JsonSchema for Permit<P>
impl<P: Permission + JsonSchema> JsonSchema for Permit<P>
source§fn schema_name() -> String
fn schema_name() -> String
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read more