diff --git a/apps/authz/src/opa/rego/__test__/criteria/intent/contractDeploy_test.rego b/apps/authz/src/opa/rego/__test__/criteria/intent/contractDeploy_test.rego index 18c4c8b0d..ecec94846 100644 --- a/apps/authz/src/opa/rego/__test__/criteria/intent/contractDeploy_test.rego +++ b/apps/authz/src/opa/rego/__test__/criteria/intent/contractDeploy_test.rego @@ -6,7 +6,7 @@ test_contractDeploy { "intent": { "from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", "type": "deployContract", - "bytecode": "", + "chainId": 137, }, } @@ -15,4 +15,6 @@ test_contractDeploy { checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as contractDeployRequest with data.entities as entities + + checkIntentChainId({1, 137}) with input as contractDeployRequest with data.entities as entities } diff --git a/apps/authz/src/opa/rego/__test__/criteria/intent/permit_test.rego b/apps/authz/src/opa/rego/__test__/criteria/intent/permit_test.rego new file mode 100644 index 000000000..4c8999eae --- /dev/null +++ b/apps/authz/src/opa/rego/__test__/criteria/intent/permit_test.rego @@ -0,0 +1,48 @@ +package main + +test_permit { + permitRequest = { + "action": "signTransaction", + "intent": { + "type": "permit", + "from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e", + "spender": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3", + "token": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174", + "amount": "1000000000000000000", + "deadline": "1634025600", # in ms + }, + } + + checkIntentType({"permit", "permit2"}) with input as permitRequest + with data.entities as entities + + checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as permitRequest + with data.entities as entities + + checkIntentSpenderAddress({"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"}) with input as permitRequest + with data.entities as entities + + checkIntentTokenAddress({"eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174"}) with input as permitRequest + with data.entities as entities + + checkIntentAmount({"currency": wildcard, "operator": "lte", "value": "1000000000000000000"}) with input as permitRequest + with data.entities as entities + + checkPermitDeadline({"operator": "eq", "value": "1634025600"}) with input as permitRequest + with data.entities as entities + + checkPermitDeadline({"operator": "neq", "value": "111111111"}) with input as permitRequest + with data.entities as entities + + checkPermitDeadline({"operator": "lte", "value": "1634025600"}) with input as permitRequest + with data.entities as entities + + checkPermitDeadline({"operator": "gte", "value": "1634025600"}) with input as permitRequest + with data.entities as entities + + checkPermitDeadline({"operator": "lt", "value": "16340256000"}) with input as permitRequest + with data.entities as entities + + checkPermitDeadline({"operator": "gt", "value": "163402560"}) with input as permitRequest + with data.entities as entities +} diff --git a/apps/authz/src/opa/rego/lib/criteria/intent/amount.rego b/apps/authz/src/opa/rego/lib/criteria/intent/amount.rego index f8fcaddc1..02f9c5687 100644 --- a/apps/authz/src/opa/rego/lib/criteria/intent/amount.rego +++ b/apps/authz/src/opa/rego/lib/criteria/intent/amount.rego @@ -14,30 +14,30 @@ intentAmount(currency) = result { checkIntentAmount(condition) { condition.operator == "eq" - to_number(condition.value) == intentAmount(condition.currency) + intentAmount(condition.currency) == to_number(condition.value) } checkIntentAmount(condition) { condition.operator == "neq" - to_number(condition.value) != intentAmount(condition.currency) + intentAmount(condition.currency) != to_number(condition.value) } checkIntentAmount(condition) { condition.operator == "gt" - to_number(condition.value) < intentAmount(condition.currency) + intentAmount(condition.currency) > to_number(condition.value) } checkIntentAmount(condition) { condition.operator == "lt" - to_number(condition.value) > intentAmount(condition.currency) + intentAmount(condition.currency) < to_number(condition.value) } checkIntentAmount(condition) { condition.operator == "gte" - to_number(condition.value) <= intentAmount(condition.currency) + intentAmount(condition.currency) >= to_number(condition.value) } checkIntentAmount(condition) { condition.operator == "lte" - to_number(condition.value) >= intentAmount(condition.currency) + intentAmount(condition.currency) <= to_number(condition.value) } diff --git a/apps/authz/src/opa/rego/lib/criteria/intent/permit.rego b/apps/authz/src/opa/rego/lib/criteria/intent/permit.rego new file mode 100644 index 000000000..366842ed6 --- /dev/null +++ b/apps/authz/src/opa/rego/lib/criteria/intent/permit.rego @@ -0,0 +1,36 @@ +package main + +import future.keywords.in + +# convert ms to ns +permitDeadlineMs = to_number(input.intent.deadline) + +checkPermitDeadline(condition) { + condition.operator == "eq" + permitDeadlineMs == to_number(condition.value) +} + +checkPermitDeadline(condition) { + condition.operator == "neq" + permitDeadlineMs != to_number(condition.value) +} + +checkPermitDeadline(condition) { + condition.operator == "lte" + permitDeadlineMs <= to_number(condition.value) +} + +checkPermitDeadline(condition) { + condition.operator == "gte" + permitDeadlineMs >= to_number(condition.value) +} + +checkPermitDeadline(condition) { + condition.operator == "lt" + permitDeadlineMs < to_number(condition.value) +} + +checkPermitDeadline(condition) { + condition.operator == "gt" + permitDeadlineMs > to_number(condition.value) +}