forked from dm3-org/ENS-Bedrock-Resolver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
165 lines (117 loc) · 16.8 KB
/
test.ts
1
2
3
4
5
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import bodyParser from "body-parser";
import { expect } from "chai";
import express from "express";
import { ethers } from "hardhat";
import request from "supertest";
import { L2PublicResolver } from "typechain";
import { EnsBedrockHandler } from "../server/http/EnsBedrockHandler";
import { getResolverInterface } from "../server/utils/getResolverInterface";
const hre = require("hardhat");
import axios from "axios";
const GOERLI_CCIP_RESOLVER_ADDRESS = "0x49e0AeC78ec0dF50852E99116E524a43bE91B789";
// Name: somenewname2.eth
// Labelhash: 0x672cb77665527613c4edfd38f9927613fba749f47687b498a8f78605868a0815
// Namehash: 0x61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c
const ENS_NAME = "alice123.eth";
const dnsEncodedName = ethers.utils.dnsEncode(ENS_NAME);
async function doWork() {
const [signer] = await hre.ethers.getSigners();
const resolverAbi = [
"function getVerifierOfDomain(bytes) view returns (tuple(string[],address), bytes32)",
"function resolve(bytes,bytes) view returns (bytes)",
"function resolveWithProof(bytes,bytes) view returns (bytes)",
];
//Create a Resolver instance
const ccipResolver = new ethers.Contract(
GOERLI_CCIP_RESOLVER_ADDRESS,
resolverAbi,
signer
)
const addressInterface = ["function addr(bytes32)"];
const callInterface = new ethers.utils.Interface(addressInterface);
const node = ethers.utils.namehash(ENS_NAME);
let callData = callInterface.encodeFunctionData("addr", [
node
]);
try {
//Output gateway urls/verifier address for reference
const [ gatewayUrls, verifierAddress ] = await ccipResolver.getVerifierOfDomain(dnsEncodedName);
console.log("Gateway URLs", gatewayUrls);
//Instance of L2PublicResolverVerifier
//https://goerli.etherscan.io/address/0x67AfD6d796d9212541016A2D10b28CC55021Cade#code
//Implements resolveWithProof
console.log("Verifier Address", verifierAddress);
//Call resolve on the L1 CCIP Resolver
const response = await ccipResolver.resolve(dnsEncodedName, callData);
//It should return our ERC3368 error
} catch (e) {
//We parse the error
const ccipErrorInterface = new ethers.utils.Interface([
"error OffchainLookup(address sender, string[] urls, bytes callData, bytes4 callbackFunction, bytes extraData)",
]);
const errorData = ccipErrorInterface.decodeErrorResult("OffchainLookup", e.data);
console.log("Error Data", errorData);
//String replacement in the gateway URL
var gatewayUrl = errorData.urls[0].replace("{sender}", errorData.sender);
gatewayUrl = gatewayUrl.replace("{data}", errorData.extraData);
console.log("Gateway URL", gatewayUrl);
//Query the gateway URL. This is our Ccip-Resolver gateway
//This gets data from our app specific ENS-Bedrock-Resolver and then encodes
//both the result and a proof of the result
const gatewayResponse = await axios.get(gatewayUrl);
const gatewayResponseData = gatewayResponse.data.data;
console.log("Gateway Response Data", gatewayResponseData);
//Get the proven data
const provenResponseData = await ccipResolver.resolveWithProof(
gatewayResponseData,
errorData.extraData
);
console.log("Proven Response Data", provenResponseData);
//Decode the response data
const address = ethers.utils.defaultAbiCoder.decode(["address"], provenResponseData)[0];
console.log("Resolved Address", address);
}
}
doWork();
/*
const getCcipRequest = (sig: string, name: string, context: string, ...args: string[]) => {
const iface = getResolverInterface();
const innerReq = iface.encodeFunctionData(sig, args);
const outerReq = iface.encodeFunctionData("resolveWithContext", [name, innerReq, context]);
//console.log("test", outerReq);
return outerReq;
};
const name = ethers.utils.dnsEncode("somenewname2.eth");
const dnsName = ethers.utils.dnsEncode(name);
//const node = ethers.utils.namehash(name);
const node = "0x61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c";
console.log("node", node);
const contextAddress = "0xdbbc2c0fe2a1d0fb4056b35a22e543beb715e7fc";
const ccipRequest = getCcipRequest("addr", name, contextAddress, node);
console.log("ccipRequest", ccipRequest);
*/
/*
Example Data
Gateway URLs [
[ 'http://localhost:8081/{sender}/{data}' ],
'0x67AfD6d796d9212541016A2D10b28CC55021Cade'
]
Verifier Address 0x61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c
Error Data [
'0x49e0AeC78ec0dF50852E99116E524a43bE91B789',
[ 'http://localhost:8081/{sender}/{data}' ],
'0xf8c30f63000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120c736f6d656e65776e616d65320365746800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000243b3b57de61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000145a384227b65fa093dec03ec34e111db80a040615000000000000000000000000',
'0xf4d4d2f8',
'0xf8c30f63000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120c736f6d656e65776e616d65320365746800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000243b3b57de61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000145a384227b65fa093dec03ec34e111db80a040615000000000000000000000000',
sender: '0x49e0AeC78ec0dF50852E99116E524a43bE91B789',
urls: [ 'http://localhost:8081/{sender}/{data}' ],
callData: '0xf8c30f63000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120c736f6d656e65776e616d65320365746800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000243b3b57de61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000145a384227b65fa093dec03ec34e111db80a040615000000000000000000000000',
callbackFunction: '0xf4d4d2f8',
extraData: '0xf8c30f63000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120c736f6d656e65776e616d65320365746800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000243b3b57de61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000145a384227b65fa093dec03ec34e111db80a040615000000000000000000000000'
]
Gateway URL http://localhost:8081/0x49e0AeC78ec0dF50852E99116E524a43bE91B789/0xf8c30f63000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000120c736f6d656e65776e616d65320365746800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000243b3b57de61e815c0fcc646428776afb240a8852355c830ed41552bf6e5f058e214141f9c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000145a384227b65fa093dec03ec34e111db80a040615000000000000000000000000
Gateway Response: {"data":"0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000205a384227b65fa093dec03ec34e111db80a040615000000000000000000000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000000039dc8a3a607970fa9f417d284e958d4ca69296c8000000000000000000000000000000000000000000000000000000000000002012c14f051def46eff81d10aa0ea579ed78d32f87daff028ad51d5a0ca20038d800000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000011b610000000000000000000000000000000000000000000000000000000000000000e05194e8e2ed2d32e5382a00179b418ef28f2bbb731a0d8e0e05e54199f3eee45ef6f95dfdfea5429fade092bcaacb83c5bbd8cfe8c450f413a6e085ac9fd47f68a31585a5a83b4054e3af30f97ef4eacb608abff0f43c036e24cb77d9368b080000000000000000000000000000000000000000000000000000000000000d800000000000000000000000000000000000000000000000000000000000000bf8f90bf5b90214f90211a0822689f1ef33c59fb55ab6797921293e72b9822a1f83b30531c707f7ca24336ba06d6fd544fa9ae021e47ade0f94b019b4f0bc13e94a1a576fcfe271099d383753a0047741c4cdc767ade540eb127b37abd6ee62af9d6a47290be55f9abe8f321af6a0b878d97e1acb8874fd7e5ea9195a36982f41f3182a0c3f75ab1447e160225142a085d40278b6b8cd34a19469a781d6c92f924e75372943f13c05ea8766a0159a3aa0c2d2f0e138532b4444c60ad581ee3f686556abe10fee94e2c7fc08bcff358e33a0444512f7beaf7f96078bbe1dfe44ae5db75f2d09e4a88ce271068057843f750da005e4290774e69ef40f23f6675a5fe740e8a15040aa9d6304751b5922decec37ea0cc5529260512b3c8a925dd791edccca731b2644d0e485e26649d0cbe1b2f104fa0a8d621ed23e411872c98933642854c9a81ef981f8482cc06badfabbec4465127a0ebf3600602e07f08e9227e4f386323408d42c56b4aaf61bc37cb954b605f305da04dbd1359ced9d406179e2cd6c9657c5e2f32516326a5f1213d4e1c4fc35a3dc2a04b1285c34902c96fc11cbf5322dc61847005016f28dc94b0302b82622a5701c9a0eb1b8bb3c1f1acc64d4505ae448718bd71c579edf7889b144552c1bdd4da5a73a037ea17af2b65ca42f7f7a6a3f1451fdd68d886b53a7bc6a113a6de48e1576a99a0f9d510b03877e8cc0ec7304cb464589b33b9eed2b9351b634596fe28d8bf6e6c80b90214f90211a0de3a308a5d7ab7ec2491baf251f5088a2fbfb328b3a2d90b58c25f74413d8256a015732255821ba029c54b17cc8a825317f928a1f4cc6b0db4cbe8248d08aa277fa0703ba57f6864eaefb9f15b863a2e55f6d6154bc3a7ad8c40efde03ee946bf123a07af765505f9d1f4fa4cc80a1d725d6ed82d531a0f761811ab4daafae1f13d403a0bf287e1d2309252be4fad8e5de300ee5da0d0dcade24236ae4481b24df42a23aa0c31bc45f9e7b60d9808e950a978a40e1988515a90f2898e0b89a3819a7945881a0708d334bf53d411eecc9b876f1703f1b7376f6917804c99c40074b59acf9bae7a0aa04142207c2e1214107a294aac56f627719df844005dded7bb3c9340109d7b1a0399a3a51c5f7836207233a82b157455cd864ebc522509f8519d6717b4669c325a00183da05bc24b278cd3c3b7240bd9f500118f7d62d1682c4d293170ce81d1db8a065f4362d49625277ee7e5ed38e84d27817686d6fcef224497b46c6ce3c269e8ca02e63ade0a7983174af23f9a3959700b0f3a76a4b86b4ed7bfbc0d9dfe2734a24a0db050b068a60848e4ef99c8e1721739a76c865d2303f40a2fb24774ec2985352a015744a8021a448e8927373f22164c2e7653833f2431b8db08544a23e31278dc1a04a1196d645b852e2add4222da702854a22c08a0477cb99723fb6424b5f4e26a5a0f61773577af41181d9eb11b861d64e4e7231169437d522f4387e9e1c55b3350380b90214f90211a04e621029eb5601f024b21354bd1af44afcd3d512a01636c590c3c91b66e82c42a0cda8814f70549b326c9b359af6e3b9a1b686dc7d45e667293dc073e299f9a1f3a0f281cca9b9e23dcc1db75dff4b1663b5d6c1c886968122767211240c48f63599a026647d181f4d8a963952cf504d5d5c32fdfa718d2716fb21749dce8275f8b368a08ed3542a5527d5039c13fe492ab2f7c97694dff9b5c10d7dec8e9413d9688920a0f4de986ea7ccd97930d3158ebd00b5f202674380b4e65424ea663559dade168fa0d3fc7ae49458f7435ef77df34494560a5a7f33546b1703ecf2f1ec682c1c23baa03e9f9f974a54dd23d387427a264bb42947a35ec9b2745470eb251ca51c54f382a06c10b3240d4543550fd4a1f8a90ad1e4449a5d5325ada792f7ee906dd8a56516a023f1d817a8fbc5c1e1ecc6ce6db486b0b0a02fd9097a836c9ca245ff60a48b75a02c733ea846c8c714f5f681cf56944d22ffeb91c1b5664469ef6db10acfeb0985a0b4e47f5cdfa4539a75c64fc9335059db36ee004247f946a484ad9e7d8823e22ca06a3fc93a335659b47dd437c814be996cba6d84cf9d27c03cec741f4ef733254da026f98a25607a0e7e85b66be63041d4c6022aef32ce64703b89d0e45037561a11a0a30a6eb5363a19547899237ac46efeb2d279e6882f2fc8fab88424a822eb808aa0f29916ede7e4e34b40e1617689c2ce80d90339f00a96c82f1af5c312505ca08e80b90214f90211a09c8931b9693f93cf10f77b5515c1db84665ee981f1732b916595fe338491ff2aa09ade4567e20140acde8ea64e609e4c135aca266ab47662d29db7857a9b67f89ca0389228d41d03c2e9f778f4f034d0f1693b2d2f32cbc92e2b1dfae8cca3997ee9a0b5c351db2b668fe0c2978881194deedd9d41a8c9fc07df7b61f699d966414635a0df57c829a78bfea71d4416f1aa71323bd5ef41cf51778331938e7b0b3eedbd37a076dfa39255ea17efa1162aaebf3fe0aeb3bdf8dcd86ecf2592e01969d5fedbf2a0f198d9031efd450d4dba66c2bf6890fa3603c91066f65de1708ea04223100f61a0bd22454f7e6ad7038583b98b6f97c726b5b21609fb2aa08913584d8e26924902a0fa8690444ae163a6bf0a1230438ed63372c690c9792ba219d639702b0cdfd1dea06934cc740d979ce89003b3ff27c357bb3a01b98802f899d6f4d879bc1163ce00a0cb710bd87c75c6ba0b9ec296dde289773a303204cc0bb3ac05c7bb38ae849a9ca0f4d42db293be44b0bd53ebd6c986c9597f4004e3e315121f175d911f4755ee27a005fe21fc5a6938b45a3eceb7f9c4304eb31079afe15b7fb32d09af1a0573a6c7a029e7912154657500a70c54ec906983c4d8b66718da307f6ebc3cef4b09a8a88fa06a6ba11729057a820def902229a655a55a95be05ad2b43867ec52164f1fbd3f5a00822af976a1a92375e0bee4a305005b582fb8d1985494f049e3df33654c19a6d80b901f4f901f1a005163e96b34f5ccbd52363a25d746b974d75266af1aee47d871cf645ccbcef13a01ec07c0ff57ac7248860063ced2d29f088fa7563279ae92385dd32ef9f23fc32a03060b7bb33f85f9cce02352b613e446807d3e2addab93dd2cd176706bb52869ba00f86ca9327c6b6f7fd4f9915a6eca4db16d7186ef4f483f82ddd54ec09de6806a09351fdb0dfe2469a12966a500cf4dcd16c2f5c67b254bd828d87f698083076c3a003815339e548d892aa9aee8d5041b132afced7891f9c2c3c0761b0725f409e5ca0d8e95084911b1349870ef18f536adc54203d8839ce5982f9a33e4d7f33377f74a0ac8be9c62347fb1a743ae037ab536f1335768d4605ae6057ebd2b34d64f8d7b9a02031e2ed4a44bd6826306874424e4e113fa1949df60c3e8fd0782e83e0880ae980a0005f1f0d1f070f1c72ad44dbe6301bd5a5a24e4886d3592d00febc29a9b30731a0250c00998ab3d88f6a554f765bbb0b9d60be4d71ed54e753c92c67996a085b6ca0101f57f749c7a533407f40e468b76029e6ac0904af15edc66ea2f0954b9d3c90a04f74722344dd57f4b91a5bc8202385909dd214173f2ec3f4946f32c6ec341a7ba0f3e87cb34becdec776e3ecaf240f7290aa8ed8623c8b8d5513255d709a499c11a0526b4952a80195e138165c4d71528a1db5c73e4708a557cb96c27cbeecb1005180b90134f90131a0f8e5c309eda7ba581a26163e274a5e5564719f73e552dbe133bcf2d5aba8cccfa0de1d8843a22bacc37762f86fe6048e702b2243f02fc8a500bfa05fa7fb30a5638080a0578dcf2bb80bb9cd2e0da997fc45d294c62c3f789409bc27e1ea7c293629db5aa08b71ceb478d8a32fe6151b35ac4ff1f8c9e9ba988a75a8c2030fe2a124aeb6b480a0308d46c5367decb38bbae351976cd12fde8dd60e8a8096e2c448f419ce2646638080a0063f32a00890fe87838407a373ba88a680ea2a42a0a7f1c2e4f3747020eebde1a0a16b50cf6b85da86e8c5497678a0e5e7711674530cdf1d46526438ea17e22f28a072133b9f510a1e91ae20b5a334208af8d3802b534b2c3dc61ca3dd8f2c9406a780a019b63b2d6141a69f6b71ecd41e1c4941eab9dba6165a121dbe4ab3eb65a967768080b869f8679e20eb42978ab2474ea69328b7004635c8acd68463b9da71eb12b65cbd86f2b846f8440180a012c14f051def46eff81d10aa0ea579ed78d32f87daff028ad51d5a0ca20038d8a0c5867ebe45535435f1299c8f6b495081df2a47a8c9b44eccf21f03dcefdd414e000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020ac17dd3d791b5c244bfdf0ece315e1ff4abec677230b55c7133f1a9cdc1b7655000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001f4f901f1b8f3f8f1a04d727193c6171104115bebc91574f7b53b4ab97ee9e69988b515705b7fe2167a8080a0139142e205391fcb3da5574ee3ca320c503478f2595ea93fb1df517a19b10d4aa0c5010dd10e2bc36cc3759d0a540cb602bf405ae541d3cf021f4e8f400d08677a8080a0aecc63b85b33a4a65b719ff505ef37c01e668cbeb377ec37d3e13327ab719190a077a357d9d2266eb700ec5b6b09f4f95278af9328d72b5235f369e4675c5f2c64a0a2a2ab50f7abafe731ce0dceba47ac2c36e0ddf480249987ebb96bb850debc7d80808080a023a3b87092b647a67dbb2c74adad5c7c798ffcfc6238b547280a594fbda1cea88080b8b3f8b1808080808080a0ff85c097f4104074972decdb3e9f52377752ea9c135e7f8296d370f3a26892a8a09e37c4b184ebb22e132010e73b77c5d65713aa0f37edfbd581ff87caca3a3394808080a0d6d7efd3cb2d88fbdcfbd67eeafcaa64a37104d000c421438ed42f1d92d9071f80a0964210de409bee46e9f1701d6005d9a2eb4a1709e85ee2e403f2d622f61a3a5fa012628feca5fe17fe1560e48231a8f1ac5f111a03fef05a29f1269e711c8f55f08080b845f843a0201f7d63b211d54184f7204fe5f33109f18da9f4bcc8c2afc6f651987bbcfc18a1a05a384227b65fa093dec03ec34e111db80a040615000000000000000000000028000000000000000000000000"}
Proven Response Data 0x0000000000000000000000005a384227b65fa093dec03ec34e111db80a040615
Resolved Address 0x5A384227B65FA093DEC03Ec34e111Db80A040615
*/