feat(ens): add address_bytes() for raw ENSIP-9 multichain resolution#3854
Open
yashgo0018 wants to merge 1 commit into
Open
feat(ens): add address_bytes() for raw ENSIP-9 multichain resolution#3854yashgo0018 wants to merge 1 commit into
address_bytes() for raw ENSIP-9 multichain resolution#3854yashgo0018 wants to merge 1 commit into
Conversation
…lution Introduces the address_bytes() method in both ENS and AsyncENS classes to retrieve raw address bytes per ENSIP-9 without EIP-55 encoding. This allows for proper handling of non-Ethereum coin types. The existing address() method is updated to delegate to address_bytes() for coin type lookups. Tests are added to ensure functionality for various coin types, including Bitcoin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
ENS.address_bytes()andAsyncENS.address_bytes()to return resolveraddrrecords as raw bytes (per ENSIP-9), without applying EIP-55 checksumming. Refactorsaddress(coin_type=…)to resolve viaaddress_bytes()and then encode withto_checksum_address()for Ethereum-shaped records.This lets integrators resolve Bitcoin, Solana, and other coin types without copying Universal Resolver logic or hitting
ValueErrorfromto_checksum_address()on non–20-byte payloads.Motivation
When
coin_typeis set,address()decodes resolverbytesand unconditionally callsto_checksum_address(). That works for Ethereum (coin_type=60, 20 bytes) but fails for typical ENSIP-9 encodings (e.g. Bitcoin 25-byte scriptPubKey) withValueError: Unknown format ….Integrators currently have to override
AsyncENS.addressto encode non-EVM addresses themselves. The requested API shape is:address_bytes()— resolution only, returns raw bytes.address()— callsaddress_bytes()whencoin_typeis set, then EIP-55 encoding (unchanged behavior for ETH; still raises for non-EVM bytes).For display encoding of non-EVM bytes, ensdomains/address-encoder remains the recommended approach (same split as viem: resolve bytes → encode per coin type).
ENSIP-9 and ENSIP-11
ENSIP-9 defines
addr(node, coinType) → bytesusing each chain’s native binary encoding (Bitcoin scriptPubKey, Ethereum 20 bytes, Bech32 payloads, etc.).ENSIP-11 amends ENSIP-9 for EVM-compatible chains: coin types with the high bit set encode an EVM
chainId:coinType = 0x80000000 | chainId(e.g. mainnet ETH remains SLIP-4460; Arbitrum42161→2147483657)chainId = 0x7fffffff & coinTypeaddress(coin_type=0x80000000 | chainId)can work when the record is standard EVM bytesNon-EVM SLIP-44 types (e.g. Bitcoin
0, Solana) use variable-length encodings;address()is not appropriate there — useaddress_bytes()plus address-encoder (which implements ENSIP-9/11 conversion helpers such asconvertEVMChainIdToCoinType).Changes
ens/ens.py,ens/async_ens.py: newaddress_bytes(name, coin_type=None);address()delegates to it whencoin_typeis provided.ens/utils.py:resolved_address_to_bytes()helper for legacyaddr(node)→addressABI decoding.docs/ens_overview.rst: documentaddress_bytes()for multichain resolution.tests/ens/test_ens.py: coverage for Bitcoin ENSIP-9 bytes, delegation fromaddress(), and async parity.newsfragments/3854.feature.rst: release note fragment.Behavior notes
coin_type=None/60(ETH)coin_type=0x80000000 | chainId(ENSIP-11 EVM)coin_type=0(BTC, etc., ENSIP-9)address_bytes()address()_resolveoraddress_bytes+ EIP-55ValueError— not valid for EIP-55address()remains valid when the resolver stores 20-byte EVM addresses.address_bytes()+address-encoder(or a custom encoder), notaddress().Test plan
pytest tests/ens/test_ens.py— 32 passedpytest tests/ens/— full ENS suite passed locally76a914…88ac) returns bytes viaaddress_bytes()without erroraddress(coin_type=0)still raisesValueErroron Bitcoin bytes (documents current ETH-only encoding)coin_type=60and multichain setup tests unchanged