Constraint
Represents a single constraint that modifies a Rule.
Constraints are conditions that must be satisfied for a rule to be applicable. All constraints in a rule's constraint list must be met (AND logic). Constraints can use predefined types from the PD-REL vocabulary or custom URIs for domain-specific requirements.
Per the PD-REL v1.0 specification: "A condition that must be met for a Rule to be active. Constraints define the 'if' conditions of a policy (e.g., 'if the time is after X,' 'if the user holds token Y')."
Examples
// Time-based constraint limiting access to a specific period
const timeConstraint: Constraint = {
type: 'TIME_PERIOD',
value: {
start: 1704067200, // January 1, 2024 00:00 UTC
end: 1735689599 // December 31, 2024 23:59:59 UTC
}
};
// Token-gated constraint requiring NFT ownership
const tokenConstraint: Constraint = {
type: 'TOKEN_GATED',
value: {
chainId: 1,
contractAddress: '0x1234...',
minBalance: 1
}
};
// Custom constraint using a URI
const customConstraint: Constraint = {
type: 'https://example.com/constraints/verified-identity',
value: { verificationLevel: 'KYC_FULL' }
};
Definition
interface Constraint {
/**
* The type of constraint, from the core vocabulary or a custom URI. Use predefined types from ConstraintType for standard constraints, or provide a fully-qualified URI for custom constraint types.
*/
type: string;
/**
* The value of the constraint, which can be a primitive or an object. The structure of the value depends on the constraint type: - TIME_PERIOD: `{ start: number, end: number }` (Unix timestamps) - USAGE_COUNT: `number` (maximum usage count) - TOKEN_GATED: `{ chainId: number, contractAddress: string, minBalance: number }` - SPATIAL: `string` (location identifier) or complex object - Custom types: Any valid JSON value
*/
value: any;
}
Properties
type
The type of constraint, from the core vocabulary or a custom URI.
Use predefined types from ConstraintType for standard constraints, or provide a fully-qualified URI for custom constraint types.
Type: string
Examples
type: 'TIME_PERIOD' // Predefined type
type: 'https://myorg.com/constraints/age-restriction' // Custom URI
value
The value of the constraint, which can be a primitive or an object.
The structure of the value depends on the constraint type:
- TIME_PERIOD:
{ start: number, end: number }(Unix timestamps) - USAGE_COUNT:
number(maximum usage count) - TOKEN_GATED:
{ chainId: number, contractAddress: string, minBalance: number } - SPATIAL:
string(location identifier) or complex object - Custom types: Any valid JSON value
Type: any
See Also
-
- ConstraintType for predefined constraint types
- Rule for how constraints are applied to rules
Since
Version 1.0.0