diff --git a/src/index.ts b/src/index.ts index e18b8c9..b5ed974 100644 --- a/src/index.ts +++ b/src/index.ts @@ -135,6 +135,20 @@ export default class extends Composer implements RNS { return this._resolutions.setContenthash(domain, content, options); } + /** + * Get decoded contenthash of a given domain. + * + * @throws DOMAIN_NOT_EXISTS if the given domain does not exists - KB012 + * @throws NO_RESOLVER when the domain doesn't have resolver - KB003 + * + * @param domain - Domain to be resolved + * + * @returns Address of the resolver associated with the given domain + */ + resolver(domain: string): Promise { + return this._resolutions.resolver(domain); + } + /** * Set resolver of a given domain. * diff --git a/src/resolutions.ts b/src/resolutions.ts index d0252f0..7c2e8ac 100644 --- a/src/resolutions.ts +++ b/src/resolutions.ts @@ -301,6 +301,25 @@ export default class extends Composer implements Resolutions { return this.estimateGasAndSendTransaction(contractMethod, options); } + async resolver(domain: string): Promise { + await this.compose(); + const node: string = namehash(domain); + + const domainOwner = await + this._contracts.registry.methods.owner(node).call(); + if (domainOwner === ZERO_ADDRESS) { + this._throw(DOMAIN_NOT_EXISTS); + } + + const resolverAddress: string = await + this._contracts.registry.methods.resolver(node).call(); + if (resolverAddress === ZERO_ADDRESS) { + this._throw(NO_RESOLVER); + } + + return resolverAddress; + } + async setResolver( domain: string, resolver: string, options?: TransactionOptions, ): Promise { diff --git a/src/types/resolutions.ts b/src/types/resolutions.ts index 1bd27bb..15d4f12 100644 --- a/src/types/resolutions.ts +++ b/src/types/resolutions.ts @@ -65,6 +65,13 @@ export interface Resolutions { */ setContenthash(domain: string, content: string, options?: TransactionOptions): any; + /** + * Get resolver of a given domain. + * + * @param domain - Domain to be resolved + */ + resolver(domain: string): Promise; + /** * Set resolver of a given domain. *