Skip to content

Add types and storage for Intents and Intent Groups #2561

@JoeCap08055

Description

@JoeCap08055

Descrption

Implement types and pallet storage for now on-chain entities Intent and IntentGroup in the schemas pallet.

Intents

Intents represent a consistent data meaning or purpose for which a user may delegate permission. Intents may be associated with one or more Schemas, which comprise a version list. Via this mechanism, Intents are able to represent the evolution of a data format. An Intent may also be associated with no schemas at all; this allows us to create delegatable permissions or entitlements on-chain that may be checked by on- or off-chain applications.

Intents are mutable, but only in the sense that publication of new Schemas representing the same evolving data format may be associated with the same Intent. Intents are immutable once published.

When associated a payload_location, Intents also represent a storage location and other attributes. This approach allows on-chain data to evolve over time. Since the storage location of an Intent remains constant, and data is written with an indication of the specific SchemaId used to encode it, publication of a new Schema does not require wholesale data migration. Instead, on-chain data may be migrated by Provider applications opportunistically over time. Off-chain data may persist in its existing form and can always be read/decoded using the original Schema definition used to write it. Intents with a payload_location of None are considered "schemaless" Intents designated for off-chain interpretation.

The structures and types for Intents are envisioned as follows:

pub type IntentId = u16;

// Renamed from existing `SchemaSetting`
pub enum IntentSetting {
    /// Intent setting to enforce append-only behavior on payload.
    /// Applied to Intents with `payload_location: PayloadLocation::Itemized`.
    AppendOnly,
    /// Intent may enforce a signature requirement on payload.
    /// Applied to intents with `payload_location: PayloadLocation::Itemized` or `PayloadLocation::Paginated`.
    SignatureRequired,
}

pub struct IntentSettings(pub BitFlags<IntentSetting>);

pub struct IntentInfo {
    /// The payload location
    pub payload_location: Option<PayloadLocation>,
    /// additional control settings for the schema
    pub settings: IntentSettings,
}

Intent Groups

As mentioned above, other than changing the interpretation of a Delegation from SchemaId to IntentId, the semantics of Delegations does not change in the new design. However, to facilitate user provisioning and onboarding by Providers, we introduce here the concept of Intent Groups.

An IntentGroup is a list of IntentIds that are "bundled" together. These bundles may be resolved to the discrete contained IntentIds when a Provider seeks to request or verify delegations for a common purpose.

The structure for Intent Groups is proposed as follows:

pub type IntentGroupId = u16;

pub struct IntentGroup {
    /// List of Intents associated with this IntentGroup
    pub intent_ids: BoundedVec<IntentId, ConstU32<MAX_INTENTS_PER_GROUP>>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions