Skip to content

Commit

Permalink
Fix sign message
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb committed Jan 30, 2024
1 parent 51f7b74 commit 23cd4c7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ test_checkSignTypedData {
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "signTypedData",
"typedData": {},
"domain": {
"version": "2",
"chainId": 137,
"name": "LINK",
"verifyingContract": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
},
},
}

Expand All @@ -61,4 +66,10 @@ test_checkSignTypedData {

checkSourceAddress({"eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e"}) with input as signTypedDataRequest
with data.entities as entities

checkIntentDomain({
"chainId": {1, 137},
"name": {"UNI", "LINK"},
"verifyingContract": {"eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3"},
}) with input as signTypedDataRequest with data.entities as entities
}
22 changes: 0 additions & 22 deletions apps/authz/src/opa/rego/lib/criteria/intent/intent.rego
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,4 @@ checkIntentHexSignature(values) {
input.intent.hexSignature in values
}

# Intent message

checkIntentMessage(operator, value) {
operator == "equals"
value == input.intent.message
}

checkIntentMessage(operator, value) {
operator == "contains"
contains(input.intent.message, value)
}

# Intent payload

checkIntentPayload(operator, value) {
operator == "equals"
value == input.intent.payload
}

checkIntentPayload(operator, value) {
operator == "contains"
contains(input.intent.payload, value)
}
65 changes: 65 additions & 0 deletions apps/authz/src/opa/rego/lib/criteria/intent/signMessage.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package main

import future.keywords.in

# Intent Sign Message

checkIntentMessage(operator, value) {
operator == "equals"
value == input.intent.message
}

checkIntentMessage(operator, value) {
operator == "contains"
contains(input.intent.message, value)
}

# Intent Sign Raw Payload

checkIntentPayload(operator, value) {
operator == "equals"
value == input.intent.payload
}

checkIntentPayload(operator, value) {
operator == "contains"
contains(input.intent.payload, value)
}

# Intent Sign Raw Payload Algorithm

checkIntentAlgorithm(values) {
values == wildcard
}

checkIntentAlgorithm(values) {
input.intent.algorithm in values
}

# Intent Sign Typed Data Domain

checkDomainCondition(value, set) {
set == wildcard
}

checkDomainCondition(value, set) {
set != wildcard
value in set
}

checkIntentDomain(filters) {
conditions = object.union(
{
"version": wildcard,
"chainId": wildcard,
"name": wildcard,
"verifyingContract": wildcard,
},
filters,
)

checkDomainCondition(input.intent.domain.version, conditions.version)
checkDomainCondition(input.intent.domain.chainId, conditions.chainId)
checkDomainCondition(input.intent.domain.name, conditions.name)
checkDomainCondition(input.intent.domain.verifyingContract, conditions.verifyingContract)
}

0 comments on commit 23cd4c7

Please sign in to comment.