Module: SafeEthRuby::Eip712

Defined in:
lib/safe_eth_ruby/eip712.rb

Class Method Summary collapse

Class Method Details

.build(transaction, chain_id, verifying_contract) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/safe_eth_ruby/eip712.rb', line 6

def build(transaction, chain_id, verifying_contract)
  transaction_copy = transaction.dup
  transaction_copy[:data] = Eth::Util.hex_to_bin(transaction[:data])
  typed_data = {
    types: {
      EIP712Domain: [
        { name: "chainId", type: "uint256" },
        { name: "verifyingContract", type: "address" },
      ],
      SafeTx: [
        { type: "address", name: "to" },
        { type: "uint256", name: "value" },
        { type: "bytes", name: "data" },
        { type: "uint8", name: "operation" },
        { type: "uint256", name: "safeTxGas" },
        { type: "uint256", name: "baseGas" },
        { type: "uint256", name: "gasPrice" },
        { type: "address", name: "gasToken" },
        { type: "address", name: "refundReceiver" },
        { type: "uint256", name: "nonce" },
      ],
    },
    domain: {
      verifyingContract: verifying_contract,
      chainId: chain_id,
    },
    primaryType: "SafeTx",
    message: transaction_copy,
  }

  Eth::Eip712.hash(typed_data)
end