From 84375be92d32a2939cf4a2f713e4c554b5b54a32 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 13 Jun 2023 16:26:40 -0400 Subject: [PATCH] Add full support for MultiCoin plugins and automatic detection for EVM-compatible coin types (#3888, #4081). --- src.ts/providers/ens-resolver.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src.ts/providers/ens-resolver.ts b/src.ts/providers/ens-resolver.ts index e418f1dfe6..0dd37a9d6a 100644 --- a/src.ts/providers/ens-resolver.ts +++ b/src.ts/providers/ens-resolver.ts @@ -5,11 +5,12 @@ * @_section: api/providers/ens-resolver:ENS Resolver [about-ens-rsolver] */ +import { getAddress } from "../address/index.js"; import { ZeroAddress } from "../constants/index.js"; import { Contract } from "../contract/index.js"; import { dnsEncode, namehash } from "../hash/index.js"; import { - hexlify, toBeHex, + hexlify, isHexString, toBeHex, defineProperties, encodeBase58, assert, assertArgument, isError, FetchRequest @@ -184,7 +185,7 @@ export class EnsResolver { "function supportsInterface(bytes4) view returns (bool)", "function resolve(bytes, bytes) view returns (bytes)", "function addr(bytes32) view returns (address)", - "function addr(bytes32, uint) view returns (address)", + "function addr(bytes32, uint) view returns (bytes)", "function text(bytes32, string) view returns (string)", "function contenthash(bytes32) view returns (bytes)", ], provider); @@ -276,6 +277,14 @@ export class EnsResolver { } } + // Try decoding its EVM canonical chain as an EVM chain address first + if (coinType >= 0 && coinType < 0x80000000) { + let ethCoinType = coinType + 0x80000000; + + const data = await this.#fetch("addr(bytes32,uint)", [ ethCoinType ]); + if (isHexString(data, 20)) { return getAddress(data); } + } + let coinPlugin: null | MulticoinProviderPlugin = null; for (const plugin of this.provider.plugins) { if (!(plugin instanceof MulticoinProviderPlugin)) { continue; } @@ -294,7 +303,7 @@ export class EnsResolver { if (data == null || data === "0x") { return null; } // Compute the address - const address = await coinPlugin.encodeAddress(coinType, data); + const address = await coinPlugin.decodeAddress(coinType, data); if (address != null) { return address; }