ERC-1062 Storing an IPFS Hash in an ENS Resolver (Formalize IPFS hash into ENS(Ethereum Name Service) resolver)
Stagnant · Names & metadata · created 2018-05-02
A standard for registering the hash of a file stored on IPFS to an ENS name (resolver), allowing access to distributed content using only a human-readable name.
Why it is needed
IPFS identifies files using a base58-format multihash, while Ethereum and ENS resolver contracts handle binary data as hex. Without a common rule for how to convert between the two formats when storing to and retrieving from an ENS resolver, each service would end up creating its own conversion method, leaving wallets and browsers unable to interoperate with each other's implementations. As a result, users cannot access distributed websites or files using just a single ENS name and must handle long, complex IPFS hash strings directly every time.
What to implement
function setMultihash(bytes32 node, bytes hash) public only_owner(node);: Only the owner of the given ENS node can call this; it stores the hex-converted IPFS hash under that node.function multihash(bytes32 node) public view returns (bytes);: It looks up and returns the IPFS hash (in hex format) stored for the given ENS node.
In depth
Why convert through a binary buffer
IPFS encodes file fingerprints as base58, while the Ethereum API handles binary data as hex. Since there is no rule for converting directly between the two encodings, the base58 string is first decoded into a binary buffer, and that buffer is then re-encoded as a hex string for storage in the contract. Conversely, when retrieving, the stored hex is decoded into a buffer and then encoded as a base58 string to restore the original IPFS address. The binary buffer serves as the intermediate format bridging the two encodings.
The setMultihash method
setMultihash(bytes32 node, bytes hash) takes an ENS node and a hex-converted IPFS hash and stores them. It is restricted by only_owner(node), so only the owner of that ENS node can set this value. The base58 IPFS hash must be converted to hex format before calling it.
The multihash method
multihash(bytes32 node) is a view function that returns the IPFS hash stored for a given ENS node as-is in hex format (bytes). The caller then converts the returned hex value back into a base58 string to fetch the actual IPFS resource.
Example implementation of the multihash conversion
The source proposes using the npm multihashes library to convert between base58 and hex. The toHex function uses multihash.fromB58String to turn the base58 hash into a buffer, then multihash.toHexString to produce a hex string (prefixed with '0x'). The toBase58 function does the reverse, using multihash.fromHexString to turn a hex string (with 0x removed) into a buffer, then multihash.toB58String to restore the base58 string.
Use case: browser extension
The source presents a browser extension as an implementation example of this standard. After installing the extension, users can access distributed resources just by typing an ENS name into their browser, the same way they would type a DNS address. This aims to solve the problem of ordinary users not being able to easily visit fully distributed websites. The source links to the Portal Network's implementation repository as an example.
Proposal status
This ERC was written in May 2018 and is in Stagnant status, a proposal where the standardization process has stalled and not progressed further.