Modules & Files
A module is one policy file.- Must start with a package
- Optional imports
- Then one or more rules
Rules
Value Rules (with if/else bodies)
- Branching with else
- Each block is a query of literals
Default Rules
- Sets a fallback value if no other rule branch applies
Function Rules
- Rules can take arguments, like functions
Set & Object Rules
Comprehension Rules
Expressions & Queries
Literals
- Expressions, not exprs
someexistential,everyuniversal
Assignments & Comparisons
Arithmetic & Boolean
References & Calls
With Modifiers
Collections & Scalars
Arrays, Objects, Sets
Scalars & Variables
Quantifiers
some/every
Negation
not
Membership
in
Builtins (Supported Categories)
Aggregates
Arrays
Sets
Objects
Strings
Numbers
Time
Conversions & Encoding
Regex
Semver
Newton Crypto Extensions
Newton extends the standard Rego runtime with custom cryptographic builtins for signature recovery. These are available in the Newton Regorus engine used by operators and thenewton-cli regorus eval command.
newton.crypto.ecdsa_recover_signer
Recovers the signer address from a raw message hash and ECDSA signature.
Returns: Hex-encoded Ethereum address of the signer.
newton.crypto.ecdsa_recover_signer_personal
Recovers the signer address from a personal message and ECDSA signature. Applies the EIP-191 \x19Ethereum Signed Message:\n prefix before recovery.
Returns: Hex-encoded Ethereum address of the signer.
Example
Newton Identity Extensions
Newton extends the Rego runtime with identity verification built-ins for checking user identity data within policies. Identity data is domain-namespaced — theidentity_domain (bytes32) stored on-chain determines which schema and built-ins apply. Domain is always required.
Two APIs are available:
- Domain-namespaced built-ins (primary):
newton.identity.kyc.age_gte(21). Type-safe with input validation and specific error messages. - Generic field accessor (escape hatch):
newton.identity.get("field_name"). Returns the raw field value from the current domain’s data. Useful for rapid prototyping with new domains before dedicated built-ins exist.
Identity data is injected by Newton operators at evaluation time from the on-chain IdentityRegistry. Policy authors do not have direct access to personally identifying information — only the built-in check results (booleans) are exposed to the policy.
KYC Domain (newton.identity.kyc.*)
The KYC domain provides 8 built-ins for verifying Know Your Customer identity data.
KYC Data Fields
newton.identity.kyc.check_approved
Returns true if the identity status is "approved".
bool.
newton.identity.kyc.address_in_countries
Checks if the document’s address country code is in the provided list.
Returns
bool. Errors if the array is empty or the stored country code is empty.
newton.identity.kyc.address_in_subdivision
Checks if the document’s address subdivision is in the provided list.
Returns
bool. The check concatenates address_country_code + - + address_subdivision and matches against the list. Errors if the array is empty or country/subdivision fields are empty.
newton.identity.kyc.address_not_in_subdivision
Inverse of address_in_subdivision. Returns true if the address is NOT in the list.
Returns
bool. Useful when combined with address_in_countries to include a country but exclude specific states.
newton.identity.kyc.age_gte
Checks if the person’s age (calculated from birthdate to reference_date) is at least the specified years.
Returns
bool. Errors if min_age is not positive or dates cannot be parsed.
newton.identity.kyc.not_expired
Returns true if the document expiration date has not passed relative to reference_date.
bool.
newton.identity.kyc.valid_for
Checks if the document will remain valid for at least the specified number of days.
Returns
bool. Compares (expiration_date - reference_date) against the provided day count.
newton.identity.kyc.issued_since
Checks if the document was issued at least the specified number of days ago.
Returns
bool. Compares (reference_date - issue_date) against the provided day count.
Generic Field Accessor (newton.identity.get)
Works across any identity domain. Returns the raw field value by name from the current domain’s data. Returns undefined if the field does not exist, allowing Rego default patterns.
Returns the field value (any type), or
undefined if not found.
When multiple identity domains are registered, all domains’ fields are accessible through this single accessor.
KYC Policy Example
Mixed Domain and Generic Accessor Example
Adding New Identity Domains
The identity extension system is designed for new domains beyond KYC. Each domain (social, credit, professional, etc.) defines its own data struct, Rego built-ins, and field accessors. New domains register undernewton.identity.<domain>.* and merge their fields into the shared newton.identity.get accessor.
Until domain-specific built-ins are available for a new domain, policy authors can use newton.identity.get("field_name") to access any field from the domain’s data.
Privacy Extensions (newton.privacy.*)
Provider-managed confidential data (blacklists, allowlists, sanctions lists) uploaded via the ConfidentialDataRegistry. Operators fetch and decrypt this data at task time based on the confidential_domain in policyParams.
Two access patterns:
- Domain-namespaced builtins (primary):
newton.privacy.blacklist.contains(addr). Type-safe with address normalization. - Generic field accessor (escape hatch):
newton.privacy.get("field_name"). Returns raw field values across all registered privacy domains.
Blacklist Domain (newton.privacy.blacklist.*)
newton.privacy.blacklist.contains
true if address is in the provider’s blacklist. Addresses are normalized to lowercase hex before comparison.
newton.privacy.blacklist.count
Allowlist Domain (newton.privacy.allowlist.*)
newton.privacy.allowlist.contains
true if address is in the provider’s allowlist.
newton.privacy.allowlist.count
Generic Field Accessor (newton.privacy.get)
undefined if the field does not exist, which allows default rules to apply.
Privacy Policy Examples
Blacklist check (deny blacklisted senders)
Allowlist check (only allow approved addresses)
Combined identity + privacy check
Time Extensions (newton.time.*)
Date arithmetic builtins for time-based policy checks. All dates use YYYY-MM-DD format strings.
newton.time.days_between
newton.time.days_since
past_date is before reference_date.
newton.time.is_within_days
true if the absolute difference between date and reference_date is at most max_days.
newton.time.is_before / newton.time.is_after
newton.time.age_years
birthdate and reference_date. Useful for age verification without the KYC identity domain.
Time Policy Example
Not Yet Supported
- Standard Crypto / Tokens / JWT:
crypto.*,jwtverify*,jwtencode*— use Newton crypto extensions instead - HTTP:
http.send— not implemented (use PolicyData WASM oracles for external data) - GraphQL:
graphql.*— not implemented - Glob matching:
regex.globs_match— not implemented - JSON Patch:
json.patch— not implemented - Networking:
net.*— not implemented - AWS Providers:
providers.aws.*— not implemented - Rego Meta:
rego.metadata.*,rego.parse_module— not implemented - Template rendering:
strings.render_template— not implemented