Skip to content

Commit

Permalink
Add transfers to rego input eval
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Jan 19, 2024
1 parent 949b78d commit bbfebec
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions apps/authz/src/app/opa/rego/policies/e2e.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import future.keywords.in

permit[{"policyId": "test-permit-policy-1"}] := reason {
check_principal

input.action == "signTransaction"

check_principal_id({"matt@narval.xyz"})
check_transfer_token_type({"transferNative"})
check_transfer_token_operation({"operator": "lte", "value": "10000000000"})

approvalsRequired = [{
"approvalCount": 2,
"countPrincipal": false,
"approvalEntityType": "Narval::User",
"entityIds": ["aa@narval.xyz", "bb@narval.xyz"],
}]

approvals := getApprovalsResult(approvalsRequired)

reason := {
"type": "permit",
"policyId": "test-permit-policy-1",
"approvalsSatisfied": approvals.approvalsSatisfied,
"approvalsMissing": approvals.approvalsMissing,
}
}

forbid[{"policyId": "test-forbid-policy-1"}] := reason {
check_principal

input.action == "signTransaction"
tokens = {"eip155:137/slip44/966"}

check_principal_id({"matt@narval.xyz"})
check_transfer_token_type({"transferNative"})
check_transfer_token_address(tokens)

limit = to_number("5000000000")
start = nanoseconds_to_seconds(time.now_ns() - (((12 * 60) * 60) * 1000000000))

spendings = get_usd_spending_amount({"tokens": tokens, "start": start})
check_spending_limit_reached(spendings, transfer_token_amount, limit)

reason := {
"type": "forbid",
"policyId": "test-forbid-policy-1",
"approvalsSatisfied": [],
"approvalsMissing": [],
}
}

0 comments on commit bbfebec

Please sign in to comment.