ConstraintType
Standard constraint types defined in the PD-REL vocabulary.
Constraints define conditions that must be met for a rule to apply. They enable sophisticated access control based on time, usage limits, token ownership, location, and more. Custom constraints can be defined using URIs for domain-specific requirements.
Per the PD-REL v1.0 specification, constraints follow the principle of "Parameterization over On-Chain Logic" - focusing on declarative, parameter-driven conditions rather than arbitrary computation.
Examples
import { ConstraintType } from '@pd-institute/pd-rel-sdk';
// Time-based access
const timeConstraint = {
type: ConstraintType.TIME_PERIOD,
value: {
start: Date.now() / 1000,
end: Date.now() / 1000 + 86400 // 24 hours
}
};
// Token gating
const nftConstraint = {
type: ConstraintType.TOKEN_GATED,
value: {
chainId: 1,
contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
minBalance: 1
}
};
// Combining multiple constraints (AND logic)
const rule = {
action: 'USE',
effect: 'permit',
constraints: [timeConstraint, nftConstraint] // Both must be satisfied
};
Definition
const ConstraintType: object
Properties
ConstraintType.TIME_PERIOD
Defines a valid time window (Unix timestamps in seconds).
TIME_PERIOD enables temporal access control:
- Temporary licenses or trials
- Event-based access windows
- Subscription periods
- Embargo or release dates
Value structure: { start: integer, end: integer }
Per specification: "Defines a valid time window (Unix timestamps in seconds)."
Type: 'TIME_PERIOD'
Value: 'TIME_PERIOD'
Examples
// 30-day access window
{
type: ConstraintType.TIME_PERIOD,
value: {
start: 1704067200, // Jan 1, 2024 00:00 UTC
end: 1706745599 // Jan 31, 2024 23:59:59 UTC
}
}
ConstraintType.USAGE_COUNT
Defines a maximum number of times the action can be performed.
USAGE_COUNT enables quantity-based restrictions:
- Limited downloads or views
- Restricted API calls
- Finite reproductions
- Usage quotas
Value type: number (maximum count)
Type: 'USAGE_COUNT'
Value: 'USAGE_COUNT'
Examples
// Allow 100 downloads
{
type: ConstraintType.USAGE_COUNT,
value: 100
}
ConstraintType.TOKEN_GATED
Requires the assignee to hold a minimum balance of a specific token.
TOKEN_GATED enables blockchain-based access control:
- NFT holder benefits
- DAO membership requirements
- Token-weighted permissions
- Staking requirements
Value structure: { chainId: number, contractAddress: string, minBalance: number }
Type: 'TOKEN_GATED'
Value: 'TOKEN_GATED'
Examples
// Require BAYC NFT ownership
{
type: ConstraintType.TOKEN_GATED,
value: {
chainId: 1, // Ethereum mainnet
contractAddress: '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
minBalance: 1
}
}
// Require 1000 governance tokens
{
type: ConstraintType.TOKEN_GATED,
value: {
chainId: 137, // Polygon
contractAddress: '0xGovToken...',
minBalance: 1000
}
}
ConstraintType.SPATIAL
Restricts the action to a location (physical or virtual).
SPATIAL enables location-based access control:
- Geographic restrictions (countries, regions)
- Virtual world boundaries
- Domain-specific access
- IP-based geofencing
Value type: string (location identifier) or complex object
Type: 'SPATIAL'
Value: 'SPATIAL'
Examples
// Country restriction
{
type: ConstraintType.SPATIAL,
value: 'US' // ISO country code
}
// Virtual world location
{
type: ConstraintType.SPATIAL,
value: 'https://decentraland.org/parcels/23,42'
}
// Complex spatial constraint
{
type: ConstraintType.SPATIAL,
value: {
type: 'polygon',
coordinates: [[...]],
world: 'sandbox'
}
}
ConstraintType.PAYMENT_AMOUNT_LTE
Buyer’s acceptable maximum payment amount. The policy's required amount must be less than or equal to this value for a match.
Value structure (recommended): { amount: string, currency: string }
Type: 'PAYMENT_AMOUNT_LTE'
Value: 'PAYMENT_AMOUNT_LTE'
ConstraintType.PAYMENT_AMOUNT_GTE
Buyer’s acceptable minimum payment amount. The policy's required amount must be greater than or equal to this value for a match.
Value structure (recommended): { amount: string, currency: string }
Type: 'PAYMENT_AMOUNT_GTE'
Value: 'PAYMENT_AMOUNT_GTE'
See Also
-
- Constraint for constraint structure
- Rule.constraints for usage in rules
Since
Version 1.0.0