Skip to content

Commit

Permalink
Add sign message criteria (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
samteb authored Jan 29, 2024
1 parent 56b292d commit 9ac2b60
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 157 deletions.
33 changes: 7 additions & 26 deletions apps/authz/src/opa/rego/__test__/criteria/contractCall_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,15 @@ package main
import future.keywords.in

test_contractCall {
contractCallTransactionRequest = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
"gas": "21000",
"data": "0x42842e0e000000000000000000000000ea7278a0d8306658dd6d38274dde084f24cd8a11000000000000000000000000b253f6156e64b12ba0dec3974062dbbaee139f0c000000000000000000000000000000000000000000000000000000000000a0d5",
"nonce": 192,
"type": "2",
}

contractCallIntent = {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "contractCall",
"contract": "eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"hexSignature": "0x12345",
}

contractCallRequest = {
"action": "signTransaction",
"transactionRequest": contractCallTransactionRequest,
"intent": contractCallIntent,
"principal": principalReq,
"resource": resourceReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "contractCall",
"contract": "eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"hexSignature": "0x12345",
},
}

checkContractCallType({"contractCall"}) with input as contractCallRequest
Expand Down
17 changes: 5 additions & 12 deletions apps/authz/src/opa/rego/__test__/criteria/contractDeploy_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@ package main
import future.keywords.in

test_contractDeploy {
contractDeployIntent = {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "deployContract",
"bytecode": "",
}

contractDeployRequest = {
"action": "signTransaction",
"transactionRequest": {},
"intent": contractDeployIntent,
"principal": principalReq,
"resource": resourceReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "deployContract",
"bytecode": "",
},
}

checkContractDeployType({"deployContract"}) with input as contractDeployRequest
Expand Down
15 changes: 14 additions & 1 deletion apps/authz/src/opa/rego/__test__/criteria/nonce_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ package main
import future.keywords.in

test_checkNonceExists {
checkNonceExists with input as request
requestWithNonce = {"transactionRequest": {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
"gas": "21000",
"value": "0xde0b6b3a7640000",
"data": "0x00000000",
"nonce": 192,
"type": "2",
}}

checkNonceExists with input as requestWithNonce
with data.entities as entities
}

Expand Down
108 changes: 108 additions & 0 deletions apps/authz/src/opa/rego/__test__/criteria/signMessage_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main

import future.keywords.in

test_checkSignMessage {
signMessageRequest = {
"action": "signTransaction",
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "signMessage",
"message": "Hello world!",
},
}

checkSignMessageIntent({"signMessage", "signRawMessage"}) with input as signMessageRequest
with data.entities as entities

signMessageEquals("Hello world!") with input as signMessageRequest
with data.entities as entities

signMessageContains("Hello") with input as signMessageRequest
with data.entities as entities
}

test_checkSignRawPayload {
signRawPayloadRequest = {
"action": "signTransaction",
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "signRawPayload",
"payload": "Hello world!",
},
}

checkSignRawPayloadIntent({"signRawPayload"}) with input as signRawPayloadRequest
with data.entities as entities

signRawPayloadEquals("Hello world!") with input as signRawPayloadRequest
with data.entities as entities

signRawPayloadContains("Hello") with input as signRawPayloadRequest
with data.entities as entities
}

test_checkSignTypedData {
typedData = {
"account": "0xA0Cf798816D4b9b9866b5330EEa46a18382f251e",
"domain": {
"name": "Ether Mail",
"version": "1",
"chainId": 1,
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
},
"types": {
"Person": [
{
"name": "name",
"type": "string",
},
{
"name": "wallet",
"type": "address",
},
],
"Mail": [
{
"name": "from",
"type": "Person",
},
{
"name": "to",
"type": "Person",
},
{
"name": "contents",
"type": "string",
},
],
},
"primaryType": "Mail",
"message": {
"from": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
},
"to": {
"name": "Bob",
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
},
"contents": "Hello, Bob!",
},
}

signTypedDataRequest = {
"action": "signTransaction",
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"type": "signTypedData",
"typedData": typedData,
},
}

checkSignTypedDataIntent({"signTypedData"}) with input as signTypedDataRequest
with data.entities as entities

signTypedDataEquals(typedData) with input as signTypedDataRequest
with data.entities as entities
}
92 changes: 27 additions & 65 deletions apps/authz/src/opa/rego/__test__/criteria/transferNft_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,15 @@ package main
import future.keywords.in

test_transferERC721 {
erc721TransactionRequest = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
"gas": "21000",
"data": "0x42842e0e000000000000000000000000ea7278a0d8306658dd6d38274dde084f24cd8a11000000000000000000000000b253f6156e64b12ba0dec3974062dbbaee139f0c000000000000000000000000000000000000000000000000000000000000a0d5",
"nonce": 192,
"type": "2",
}

erc721Intent = {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferERC721",
"contract": "eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"nftId": "eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/41173",
}

erc721Request = {
"action": "signTransaction",
"transactionRequest": erc721TransactionRequest,
"intent": erc721Intent,
"principal": principalReq,
"resource": resourceReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferERC721",
"contract": "eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"nftId": "eip155:137/erc721:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/41173",
},
}

checkTransferNftType({"transferERC721"}) with input as erc721Request
Expand All @@ -44,47 +25,28 @@ test_transferERC721 {
}

test_transferERC1155 {
erc1155TransactionRequest = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
"gas": "21000",
"data": "0x42842e0e000000000000000000000000ea7278a0d8306658dd6d38274dde084f24cd8a11000000000000000000000000b253f6156e64b12ba0dec3974062dbbaee139f0c000000000000000000000000000000000000000000000000000000000000a0d5",
"nonce": 192,
"type": "2",
}

erc1155Intent = {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferERC1155",
"contract": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"transfers": [
{
"tokenId": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/41173",
"amount": "1",
},
{
"tokenId": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/44444",
"amount": "2",
},
{
"tokenId": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/55555",
"amount": "5",
},
],
}

erc1155Request = {
"action": "signTransaction",
"transactionRequest": erc1155TransactionRequest,
"intent": erc1155Intent,
"principal": principalReq,
"resource": resourceReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferERC1155",
"contract": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4",
"transfers": [
{
"tokenId": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/41173",
"amount": "1",
},
{
"tokenId": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/44444",
"amount": "2",
},
{
"tokenId": "eip155:137/erc1155:0x08a08d0504d4f3363a5b7fda1f5fff1c7bca8ad4/55555",
"amount": "5",
},
],
},
}

checkTransferNftType({"transferERC1155"}) with input as erc1155Request
Expand Down
67 changes: 14 additions & 53 deletions apps/authz/src/opa/rego/__test__/criteria/transferToken_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,15 @@ one_matic_value = "990000000000000000"
ten_matic_value = "9900000000000000000"

test_transferNative {
nativeTransactionRequest = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
"gas": "21000",
"value": "0xde0b6b3a7640000",
"data": "0x00000000",
"nonce": 192,
"type": "2",
}

nativeIntent = {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferNative",
"amount": "1000000000000000000",
"token": "eip155:137/slip44/966",
}

nativeRequest = {
"action": "signTransaction",
"transactionRequest": nativeTransactionRequest,
"intent": nativeIntent,
"principal": principalReq,
"resource": resourceReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferNative",
"amount": "1000000000000000000",
"token": "eip155:137/slip44/966",
},
}

checkTransferTokenType({"transferNative"}) with input as nativeRequest
Expand All @@ -54,34 +34,15 @@ test_transferNative {
}

test_transferERC20 {
erc20TransactionRequest = {
"from": "0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"chainId": 137,
"maxFeePerGas": "20000000000",
"maxPriorityFeePerGas": "3000000000",
"gas": "21000",
"data": "0xa9059cbb000000000000000000000000031d8c0ca142921c459bcb28104c0ff37928f9ed000000000000000000000000000000000000000000005ab7f55035d1e7b4fe6d",
"nonce": 192,
"type": "2",
}

erc20Intent = {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferERC20",
"amount": "1000000000000000000",
"contract": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
}

erc20Request = {
"action": "signTransaction",
"transactionRequest": erc20TransactionRequest,
"intent": erc20Intent,
"principal": principalReq,
"resource": resourceReq,
"approvals": approvalsReq,
"transfers": transfersReq,
"intent": {
"from": "eip155:eoa:0xddcf208f219a6e6af072f2cfdc615b2c1805f98e",
"to": "eip155:137:0xa45e21e9370ba031c5e1f47dedca74a7ce2ed7a3",
"type": "transferERC20",
"amount": "1000000000000000000",
"contract": "eip155:137/erc20:0x2791bca1f2de4661ed88a30c99a7a9449aa84174",
},
}

checkTransferTokenType({"transferERC20"}) with input as erc20Request
Expand Down
Loading

0 comments on commit 9ac2b60

Please sign in to comment.