Оценить запрос политиками
Ядро policy engine (deny-overrides):
- Собираются все политики пользователя в Vault (через членства в группах)
- Фильтр: enabled=true и actionType = action
- Применимость: одно булево дерево condition (and/or/not/лист). condition=null → политика применима всегда
- Резолюция (Ф2): block → нарушенный лимит (отказ или эскалация в подпись) → требования подписи → allow → deny (default-deny). Требования СОБИРАЮТСЯ со всех применимых политик (requirements[]), а не выбирается одно с максимальным порогом — так выражается «CFO И комплаенс»
Вызывается внутренне из createAddress/createTransaction, но доступен и напрямую — для dry-run проверок из UI.
curl -X POST "https://policy-engine-rest.ezig.workers.dev/api/v1/evaluate" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
"vaultId": "example_string",
"userId": "user-1",
"action": "transfer",
"context": {
"derivationPath": "m/44/195/0/0/1/1/0",
"destinationAddress": "123 Main St",
"destinationNetwork": "tron",
"amount": {
"value": "1.5",
"asset": "usdt"
},
"totalSpent": {
"value": "example_string",
"asset": "example_string"
},
"tokenCode": "example_string",
"signersConfig": {
"mode": "example_string"
}
}
}'
import requests
import json
url = "https://policy-engine-rest.ezig.workers.dev/api/v1/evaluate"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN"
}
data = {
"vaultId": "example_string",
"userId": "user-1",
"action": "transfer",
"context": {
"derivationPath": "m/44/195/0/0/1/1/0",
"destinationAddress": "123 Main St",
"destinationNetwork": "tron",
"amount": {
"value": "1.5",
"asset": "usdt"
},
"totalSpent": {
"value": "example_string",
"asset": "example_string"
},
"tokenCode": "example_string",
"signersConfig": {
"mode": "example_string"
}
}
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const response = await fetch("https://policy-engine-rest.ezig.workers.dev/api/v1/evaluate", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN"
},
body: JSON.stringify({
"vaultId": "example_string",
"userId": "user-1",
"action": "transfer",
"context": {
"derivationPath": "m/44/195/0/0/1/1/0",
"destinationAddress": "123 Main St",
"destinationNetwork": "tron",
"amount": {
"value": "1.5",
"asset": "usdt"
},
"totalSpent": {
"value": "example_string",
"asset": "example_string"
},
"tokenCode": "example_string",
"signersConfig": {
"mode": "example_string"
}
}
})
});
const data = await response.json();
console.log(data);
package main
import (
"fmt"
"net/http"
"bytes"
"encoding/json"
)
func main() {
data := []byte(`{
"vaultId": "example_string",
"userId": "user-1",
"action": "transfer",
"context": {
"derivationPath": "m/44/195/0/0/1/1/0",
"destinationAddress": "123 Main St",
"destinationNetwork": "tron",
"amount": {
"value": "1.5",
"asset": "usdt"
},
"totalSpent": {
"value": "example_string",
"asset": "example_string"
},
"tokenCode": "example_string",
"signersConfig": {
"mode": "example_string"
}
}
}`)
req, err := http.NewRequest("POST", "https://policy-engine-rest.ezig.workers.dev/api/v1/evaluate", bytes.NewBuffer(data))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}
require 'net/http'
require 'json'
uri = URI('https://policy-engine-rest.ezig.workers.dev/api/v1/evaluate')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
request.body = '{
"vaultId": "example_string",
"userId": "user-1",
"action": "transfer",
"context": {
"derivationPath": "m/44/195/0/0/1/1/0",
"destinationAddress": "123 Main St",
"destinationNetwork": "tron",
"amount": {
"value": "1.5",
"asset": "usdt"
},
"totalSpent": {
"value": "example_string",
"asset": "example_string"
},
"tokenCode": "example_string",
"signersConfig": {
"mode": "example_string"
}
}
}'
response = http.request(request)
puts response.body
{
"decision": "example_string",
"matchedPolicyIds": [
"example_string"
],
"trace": [
{
"policyId": "example_string",
"policyCode": "example_string",
"policyName": "John Doe",
"effect": "example_string",
"applied": true,
"skipReason": "excluded",
"failedSelector": {
"conditionType": "example_string",
"selectorType": "example_string",
"detail": "траты у инициатора за 24 ч с учётом текущей операции — 11000 usdt, лимит 10000 usdt"
}
}
]
}
{
"decision": "example_string",
"reason": "AMOUNT_EXCEEDED",
"policyId": "example_string",
"policyCode": "example_string",
"trace": [
{
"policyId": "example_string",
"policyCode": "example_string",
"policyName": "John Doe",
"effect": "example_string",
"applied": true,
"skipReason": "excluded",
"failedSelector": {
"conditionType": "example_string",
"selectorType": "example_string",
"detail": "траты у инициатора за 24 ч с учётом текущей операции — 11000 usdt, лимит 10000 usdt"
}
}
]
}
{
"decision": "example_string",
"policyId": "example_string",
"policyCode": "example_string",
"approvers": [
"example_string"
],
"threshold": 42,
"adminBypass": true,
"allowInitiatorApproval": true,
"trace": [
{
"policyId": "example_string",
"policyCode": "example_string",
"policyName": "John Doe",
"effect": "example_string",
"applied": true,
"skipReason": "excluded",
"failedSelector": {
"conditionType": "example_string",
"selectorType": "example_string",
"detail": "траты у инициатора за 24 ч с учётом текущей операции — 11000 usdt, лимит 10000 usdt"
}
}
]
}
{
"decision": "example_string",
"reason": "example_string",
"trace": [
{
"policyId": "example_string",
"policyCode": "example_string",
"policyName": "John Doe",
"effect": "example_string",
"applied": true,
"skipReason": "excluded",
"failedSelector": {
"conditionType": "example_string",
"selectorType": "example_string",
"detail": "траты у инициатора за 24 ч с учётом текущей операции — 11000 usdt, лимит 10000 usdt"
}
}
]
}
{
"error": "Bad Request",
"message": "The request contains invalid parameters or malformed data",
"code": 400,
"details": [
{
"field": "email",
"message": "Invalid email format"
}
]
}
{
"error": "Unauthorized",
"message": "Authentication required. Please provide a valid API token",
"code": 401
}
{
"error": "Internal Server Error",
"message": "An unexpected error occurred on the server",
"code": 500,
"requestId": "req_1234567890"
}
/api/v1/evaluate
Target server for requests. Edit to use your own host.
better-auth session token. Мобилка/сервисы. Веб использует cookie.
API key (sent in cookie)
The media type of the request body
Тип действия, к которому применяется политика. Видимость участников СЮДА не входит: это грант (/vaults/:code/visibility-grants), а не политика
Контекст запроса — заполняются только поля, релевантные для action. Какие именно кладут боевые вызовы, закреплено метатестом tests/selectorContextParity.test.ts: селектор нельзя разрешить, если контекст его не питает (иначе политика молча перестаёт применяться)
Request Preview
Response
Response will appear here after sending the request
Authentication
Bearer token. better-auth session token. Мобилка/сервисы. Веб использует cookie.
API Key for authentication. Provide your API key in the cookie.
Body
user-1Тип действия, к которому применяется политика. Видимость участников СЮДА не входит: это грант (/vaults/:code/visibility-grants), а не политика
transfercreate_addresscounterparty_createcounterparty_updatecounterparty_archivecounterparty_group_createcounterparty_group_updatecounterparty_group_archivecounterparty_group_addcounterparty_group_removeКонтекст запроса — заполняются только поля, релевантные для action. Какие именно кладут боевые вызовы, закреплено метатестом tests/selectorContextParity.test.ts: селектор нельзя разрешить, если контекст его не питает (иначе политика молча перестаёт применяться)