• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ENS Offchain Resolver

CI

This repository contains smart contracts and a node.js gateway server that together allow hosting ENS names offchain using EIP 3668 and ENSIP 10.

Overview

ENS resolution requests to the resolver implemented in this repository are responded to with a directive to query a gateway server for the answer. The gateway server generates and signs a response, which is sent back to the original resolver for decoding and verification. Full details of this request flow can be found in EIP 3668.

All of this happens transparently in supported clients (such as ethers.js with the ethers-ccip-read-provider plugin, or future versions of ethers.js which will have this functionality built-in).

Gateway Server

The gateway server implements CCIP Read (EIP 3668), and answers requests by looking up the names in a backing store. By default this is a JSON file, but the backend is pluggable and alternate backends can be provided by implementing a simple interface. Once a record is retrieved, it is signed using a user-provided key to assert its validity, and both record and signature are returned to the caller so they can be provided to the contract that initiated the request.

Contracts

The smart contract provides a resolver stub that implement CCIP Read (EIP 3668) and ENS wildcard resolution (ENSIP 10). When queried for a name, it directs the client to query the gateway server. When called back with the gateway server response, the resolver verifies the signature was produced by an authorised signer, and returns the response to the client.

Trying it out

Start by generating an Ethereum private key; this will be used as a signing key for any messages signed by your gateway service. You can use a variety of tools for this; for instance, this Python snippet will generate one for you:

python3 -c "import os; import binascii; print('0x%s' % binascii.hexlify(os.urandom(32)).decode('utf-8'))"

For the rest of this demo we will be using the standard test private key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80.

First, install dependencies and build all packages:

yarn && yarn build

Follow here to run gateway worker locally. ( Skip this step if cloudflare worker url will be used as a remote gateway )

Take a look at the data in test.eth.json under packages/gateway/; it specifies addresses for the name test.eth and the wildcard *.test.eth.

Next, edit packages/contracts/hardhat.config.js; replacing the address on line 64 with the one output when you ran the command above.

Then, in a new terminal, build and run a test node with an ENS registry and the offchain resolver deployed:

# If local cloudflare worker will be used
yarn start:node
# If remote cloudflare worker url will be used as gateway use the script below instead
export REMOTE_GATEWAY=https://offchain-gateway.ensdomains.workers.dev
yarn start:node

You will see output similar to the following:

Compilation finished successfully
deploying "ENSRegistry" (tx: 0x8b353610592763c0abd8b06305e9e82c1b14afeecac99b1ce1ee54f5271baa2c)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 1084532 gas
deploying "OffchainResolver" (tx: 0xdb3142c2c4d214b58378a5261859a7f104908a38b4b9911bb75f8f21aa28e896)...: deployed at 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 with 1533637 gas
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:9545/

Accounts
========

WARNING: These accounts, and their private keys, are publicly known.
Any funds sent to them on Mainnet or any other live network WILL BE LOST.

Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

(truncated for brevity)

Take note of the address to which the ENSRegistry was deployed (0x5FbDB...).

Finally, in a third terminal, run the example client to demonstrate resolving a name:

yarn start:client --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 test.eth
yarn start:client --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 foo.test.eth

You should see output similar to the following:

$ yarn start:client --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 test.eth
yarn run v1.22.17
$ node packages/client/dist/index.js --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 test.eth
resolver address 0x8464135c8F25Da09e49BC8782676a84730C318bC
eth address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
content null
email [email protected]
Done in 0.28s.

$ yarn start:client --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 foo.test.eth
yarn run v1.22.17
$ node packages/client/dist/index.js --registry 0x5FbDB2315678afecb367f032d93F642f64180aa3 foo.test.eth
resolver address 0x8464135c8F25Da09e49BC8782676a84730C318bC
eth address 0x70997970C51812dc3A010C7d01b50e0d17dc79C8
content null
email [email protected]
Done in 0.23s.

Check these addresses against the gateway's test.eth.json and you will see that they match.

Real-world usage

There are 5 main steps to using this in production:

  1. Optionally, write a new backend for the gateway that queries your own data store. Or, use the JSON one and write your records to a JSON file in the format described in the gateway repository.
  2. Generate one or more signing keys. Secure these appropriately; posession of the signing keys makes it possible to forge name resolution responses!
  3. Start up a gateway server using your name database and a signing key. Publish it on a publicly-accessible URL.
  4. Deploy OffchainResolver to Ethereum, providing it with the gateway URL and list of signing key addresses.
  5. Set the newly deployed resolver as the resolver for one or more ENS names.

Cloudflare Worker development

Running locally

  1. Create a dev.vars file under packages/gateway/ folder
  2. Put gateway private key into it in between double quotes, as below;
OG_PRIVATE_KEY="PRIVATE_KEY_HERE"
  1. Run worker with wrangler dev --local command

Deployment

  1. Register private key as a worker secret.
# wrangler secret put <key> <value>
wrangler secret put OG_PRIVATE_KEY PRIVATE_KEY_HERE
  1. Build the gateway via yarn build
  2. Deploy the worker with wrangler publish

More Repositories

1

ens

Implementations for ENS core functionality: The registry, registrars, and public resolvers.
JavaScript
1,159
star
2

ens-contracts

The core contracts of the ENS protocol
TypeScript
576
star
3

ens-app

Legacy ENS manager app
JavaScript
223
star
4

ensjs-v2

Javascript bindings for the Ethereum Name Service
JavaScript
206
star
5

subdomain-registrar

A registrar that sells subdomains to users on behalf of their owners
CSS
185
star
6

governance-contracts

Governance contracts for the ENS DAO
JavaScript
160
star
7

address-encoder

Encodes and decodes address formats for various cryptocurrencies
TypeScript
148
star
8

docs

Main documentation site for the ENS protocol
TypeScript
136
star
9

evmgateway

This repository implements a generic CCIP-Read gateway for fetching state proofs of data on other EVM chains. The intended use is for contracts on L1 to be able to fetch and verify data from contracts on L2 in a read context.
TypeScript
132
star
10

ens-app-v3

The official ENS manager app. Register and manage your ENS names here.
TypeScript
126
star
11

ensjs

ENS javascript library for contract interaction
TypeScript
123
star
12

ensdomains-landing

ENS Homepage V2, the main homepage of the ENS protocol.
TypeScript
105
star
13

ethregistrar

Solidity
92
star
14

thorin

A web3 native design system.
TypeScript
81
star
15

ens-metadata-service

TypeScript
71
star
16

resolvers

A collection of resolvers for ENS domains
JavaScript
69
star
17

dnssec-oracle

A DNSSEC oracle for Ethereum
Solidity
57
star
18

react-ens-address

React Component to resolve ENS names or reverse resolve addresses
JavaScript
57
star
19

ui

UI components and reusable functions
JavaScript
55
star
20

l2gateway-demo

A simple demonstration of a proposed L2 gateway specification
JavaScript
52
star
21

name-wrapper

JavaScript
45
star
22

ens-avatar

ENS Avatar resolver library for both nodejs and browser.
TypeScript
40
star
23

solsha1

Pure-solidity implementation of the SHA1 hash function.
Solidity
39
star
24

ens.domains

JavaScript
31
star
25

reverse-records

JavaScript
27
star
26

dnsprovejs

A tool to convince an Ethereum DNSSEC oracle of the contents of DNS records
TypeScript
25
star
27

buffer

A library for working with mutable byte buffers in Solidity.
Solidity
25
star
28

governance-web-react

JavaScript
23
star
29

governance-docs

Governance documentation for the ENS DAO
22
star
30

offchain-resolver-example

CCIP Offchain ENS Resolver example implementation
TypeScript
21
star
31

dnsregistrar

DNS registrar for ENS
Solidity
21
star
32

ens-manager

JavaScript
19
star
33

ethers-ccip-read

Ethers-rs CCIP-Read Middleware
Rust
19
star
34

media-kit

ens media kit resources
CSS
17
star
35

ens-validation

TypeScript
17
star
36

root

New ENS root contract
JavaScript
16
star
37

op-resolver

JavaScript
15
star
38

ens-twitter-api

TypeScript
14
star
39

ens-avatar-worker

Cloudflare worker that facilitates gasless avatar record updates via the ENS manager app
TypeScript
13
star
40

dnssecoraclejs

TypeScript/JavaScript library for generating DNSSEC proofs for the ENS DNSSEC oracle contract
TypeScript
11
star
41

court

Basic smart contracts for the arbitration processes.
Solidity
11
star
42

docs-v2

The Ethereum Name Service (ENS) is a distributed, open, and extensible naming system based on the Ethereum blockchain. This repository contains documentation, examples, and much more.
HTML
11
star
43

blacklist

Blacklisting tools for ENS
Solidity
10
star
44

optimistic-dnssec

Optimistic Implementation of the DNSSEC Registrar
Solidity
10
star
45

ens-archived-contracts

Collection of compiled ENS smart contracts
Solidity
10
star
46

hackathon-registrar

A simple ENS registrar for Hackathons
Solidity
9
star
47

gas-estimate-worker

Cloudflare worker for estimating registration gas costs with tenderly
TypeScript
9
star
48

name-reservations

Repository for 3-6 character name reservations in .eth.
CSS
9
star
49

enschain

Solidity
9
star
50

frontend-template

Starter web app for web3 developers
TypeScript
8
star
51

offchain-gateway-rs

Offchain CCIP Gateway Resolver implementation in Rust
Rust
7
star
52

learn-docs

Documentation for learning about ENS domains
7
star
53

renewal-widget

ENS Renewal widget displays a popup window if there are any expiring ENS names.
JavaScript
7
star
54

arb-resolver

JavaScript
7
star
55

ensips

ENS Improvement Proposals
TypeScript
7
star
56

hack.ens.domains

JavaScript
7
star
57

k-ens

ENS formally verified
6
star
58

auction

An auction contract for a one-off vickery style auction of 3-6 character names
JavaScript
6
star
59

my-ens-app

HTML
6
star
60

ccip-read-dns-gateway

ENS CCIP-Read DNSSEC Gateway
TypeScript
5
star
61

dnssectool

JavaScript
5
star
62

short-name-claims-app

A webapp for submitting claims for ENS short names (3-6 characters)
TypeScript
5
star
63

blog

Official Ethereum Name Service Blog
TypeScript
5
star
64

hack2018

5
star
65

research

ENS relevant research.
5
star
66

ccip-tools

CCIP Multitool for testing your offchain resolver!
TypeScript
5
star
67

ens-support-docs

ENS Support Docs
CSS
4
star
68

ens-reclaim-deposit-subgraph

TypeScript
4
star
69

hackathon-registrar-app

JavaScript
4
star
70

renewal

JavaScript
4
star
71

ens-print

Micro App for printing ENS stickers
JavaScript
4
star
72

ethlink-request

It fetches newly created subdomain and send request to eth.link to add to the DoH proxy
TypeScript
4
star
73

mock

Module for mocking ENS locally
JavaScript
4
star
74

integrations

List of integrations for ENS
TypeScript
4
star
75

reclaim

TypeScript
3
star
76

moonpay-worker

JavaScript
3
star
77

normalise-refund

JavaScript
3
star
78

test-utils

ENS test utilities
JavaScript
3
star
79

tldclaims

JavaScript
3
star
80

verify-ratification

Code to verify the votes ratifying the ENS constitution
JavaScript
3
star
81

usd-oracle

USD oracle research
3
star
82

batch-gateway

3
star
83

short-name-claims-subgraph

A subgraph for indexing ENS .eth short name claims
TypeScript
3
star
84

migration-scripts

Python
3
star
85

ens-faucet-worker

Cloudflare worker to help distribute testnet ETH to ENS manager app users
TypeScript
3
star
86

ens-bigquery-udf

JavaScript
3
star
87

ens-evmgateway

TypeScript
3
star
88

crypto-addr-serialize

Encode/Decode various cryptocurrency addresses
JavaScript
3
star
89

ens-og-image

TypeScript
2
star
90

enscluster

Config files for the ensdomains Kubernetes clusters
Python
2
star
91

dnssec-oracle-anchors

JavaScript
2
star
92

dao-pm

Project management repository for the ENS DAO
2
star
93

context-resolver

TypeScript
2
star
94

constitution-book-claim

ENS DAO constitution book claim site
TypeScript
2
star
95

ens-avatar-fallback

JavaScript
2
star
96

arbitrum-resolver

JavaScript
1
star
97

pm

an place to hold ENS project issues which cannot be assigned to any existing repos
1
star
98

ens-cfw

TypeScript
1
star
99

rasterize-gcp

ENS NFT Rasterization Service
JavaScript
1
star
100

punycode

Solidity
1
star