alpha-wallet-android
alpha-wallet-android copied to clipboard
Add support for ENSIP-10
- [ ] ENSIP-10 [^1]
- [ ] Requires EIP3668 [^2] support
Relevant announcement: https://medium.com/the-ethereum-name-service/upgrade-ethers-js-to-5-6-1-to-activate-ens-l2-offchain-integration-40ee1a0fdf2a
I found the post from etherjs quite useful: https://blog.ricmoo.com/highlights-ethers-js-march-2022-f511fe1e88a1
0x41563129cDbbD0c5D3e1c86cf9563926b243834d
Sample data
offchainexample.eth -> 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045
1.offchainexample.eth -> 0x41563129cdbbd0c5d3e1c86cf9563926b243834d//This relies on wildcard resolution support
2.offchainexample.eth -> 0x41563129cdbbd0c5d3e1c86cf9563926b243834d too //This relies on wildcard resolution support
ricmoose.hatch.eth -> error
hweeboon.eth -> 0xbbce83173d5c1D122AE64856b4Af0D5AE07Fa362
ENSIP-10
Key part of ENSIP-10 spec starts at:
If a resolver implements this function, it MUST return true when supportsInterface() is called on it with the interface's ID, 0x9061b923.
Pre-ENSIP-10:
resolver = ensContract.resolver(originalName)
address = resolver.addr(originalName)
With ENSIP-10 wildcard resolution:
name = originalName
while name.notEmpty
resolver = ensContract.resolver(name)
if resolver != 0x
break //found it
end
name = parent(name) //`1.offchainexample.eth` -> `offchainexample.eth`
end
if resolver.supportsInterface("0x9061b923")
dnsEncodedName = dnsEncode(originalName)
calldata = addr's //as if calling resolver.addr()
address = resolver.resolve(dnsEncodedName, calldata)
else
address = resolver.addr(originalName)
end
The resolver.resolve(bytes,bytes) call is the one that might trigger EIP3668 with our test data.
EIP3668
This seems to add EIP3668 support to web3j:
The diagram at https://eips.ethereum.org/EIPS/eip-3668#overview describes the flow well. But basically, if a transaction call reverts with OffchainLookup(address,string[],bytes,bytes4,bytes) then we need to trigger EIP3668 support by:
- parsing the OffchainLookup error
- HTTP GET/POST against the gateway URL(s) specified in the OffchainLookup error
- call the contract with the function specified with data from the gateway response + data extracted from the OffchainLookup error
- result from (3) replaces the original smart contract call that triggered EIP3668
Step 3 might trigger EIP3668 again.
Pre-EIP3668 support:
func web3j.call(contract, func)
return contract.func
end
With EIP3668 support:
func web3j.call(contract, func)
result = contract.func
if result == OffchainLookup
//Trigger EIP3668
urls, sender, callBack, callData, extraData = extract(offchainLookup)
gatewayResult = httpGetOrPost(urls, sender, callData)
return contract.callback(gatewayResult, extraData) //This could trigger EIP3668 again
else
return result
end
end
I found etherjs's implementation great for understanding how to implement EIP3668. Look for the implementation of ccipReadFetch and where it is called: https://github.com/ethers-io/ethers.js/blob/bc400c7b87b03438abb2f9874ec136dbf7b6437c/packages/providers/src.ts/base-provider.ts#L854
iOS PRs for reference
- AlphaWallet iOS for ENSIP-10: https://github.com/AlphaWallet/alpha-wallet-ios/pull/4237
- web3Swift support EIP3668: https://github.com/AlphaWallet/web3swift/pull/10
[^1]: ENSIP-10 https://docs.ens.domains/ens-improvement-proposals/ensip-10-wildcard-resolution [^2]: EIP3668 https://eips.ethereum.org/EIPS/eip-3668#use-of-get-and-post-requests-for-the-gateway-interface
@JamesSmartCell I have updated the first comment because the addresses for these 2 aren't 0xb8c anymore:
1.offchainexample.eth -> 0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5 //This relies on wildcard resolution support
2.offchainexample.eth -> 0xb8c2C29ee19D8307cb7255e1Cd9CbDE883A267d5 too //This relies on wildcard resolution support