Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dapper / ERC-1271 wallet signature validation in Ruby
require 'web3/eth'
ERC_1271_MAGIC_VALUE = '1626ba7e'
ERC_1271_ABI = <<~JSON
[
{
"constant": true,
"inputs": [
{
"name": "hash",
"type": "bytes32"
},
{
"name": "_signature",
"type": "bytes"
}
],
"name": "isValidSignature",
"outputs": [
{
"name": "magicValue",
"type": "bytes4"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
}
]
JSON
rpc_host = 'mainnet.infura.io'
rpc_path = '/v3/YOUR_RPC_PATH_HERE'
web3 = Web3::Eth::Rpc.new host: rpc_host,
port: 443,
connect_options: {
use_ssl: true,
rpc_path: rpc_path
}
address = '0x77f7111B2b211BC504dE66b13F3A8a04cD182842'
challenge = Web3::Eth::Abi::Utils.keccak256('Follow Niftytown.com!')
signature = ['051912aa60d32687c0e9dc37d335b1bb226c24a31fca40a23cce11e8b417bee11ca668ead2e901ab276eea194e70c4eec71908f10fecc1390f187fb56d7ce2c81bd17faa5de3424c79cfc2dc8b0b074229efedc40cbeac8c835a373589b0b122277bae737503b29ceedf735ab2148523854be4818bb66c13a0b3f28349357678801c'].pack('H*')
contract = web3.eth.contract(ERC_1271_ABI)
wallet = contract.at(address)
result = wallet.isValidSignature(challenge, signature)
if result.unpack('H*').first == ERC_1271_MAGIC_VALUE
puts 'Authorized'
else
puts 'Unauthorized'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.