-
Notifications
You must be signed in to change notification settings - Fork 58
Labels
vm-languageIssues related to the VM & Language TeamIssues related to the VM & Language Team
Description
After the validation of a package, if some functions were found using the #[authenticator] attribute, an immutable object can be automatically created. This object must be of type PackageMetadata:
public struct PackageMetadataV1 has key {
// PackageMetadata (derived) id
id: UID,
// Package id
package_id: ID,
// Package version
package_version: u64, //TODO check max num of versions and change u64 accordingly
// Package name
package_name: ascii::String,
// Package modules
module_handles: Vec<ascii::String>,
/// Handles to external and internal functions.
function_handles: Vec<FunctionHandle>,
}
public struct FunctionHandle has copy, drop, store {
/// The module that defines the function.
module_handle: u16, // index of the module_handles vector
/// The name of the function.
name: ascii::String,
/// Flag for authenticator functions.
is_authenticator: bool,
}During the publishing/updating of a package including at least one #[authenticator] attribute, an immutable PackageMetadataV1 object is automatically created.
An AuthenticatorInfoV1 can be created using this function from PackageMetadataV1:
public fun create_auth_info_v1(
self: &PackageMetadataV1,
module_name: ascii::String,
function_name: ascii::String,
): AuthenticatorInfoV1 {
// Find module
let module_handle = self.module_handles.find_index!(|m| m == module_name);
assert!(module_handle.is_some(), EModuleNotFound);
// Find function
let function_handle = self.function_handles.find_index!(
|f|
f.module_handle == *module_handle.borrow()
&& f.name == function_name
&& f.is_authenticator
);
assert!(function_handle.is_some(), EFunctionNotFoundOrNotAuthenticator);
AuthenticatorInfoV1 { package: self.package_id(), module_name, function_name }
}Metadata
Metadata
Assignees
Labels
vm-languageIssues related to the VM & Language TeamIssues related to the VM & Language Team