Add your own Custom Resolver

We are committed to continuous improvement

You can implement your resolver service and add pass it to RedefinedResolver.

Step 1. Extend ResolverService class

Please see GitHub for sources here

export abstract class ResolverService {
    abstract vendor: ResolverVendor;
    abstract resolve(domain: string, options?: ResolverServiceOptions, networks?: string[]): Promise<Account[]>;
}

Example:

export class KeyValueResolverService extends ResolverService {

    vendor: ResolverVendor = "keyvalue"
    
    registry = {
        "ivan": "0x1",
        "stepan": "0x2",
        "andrey": "0x3",
    }

    async resolve(domain: string, { throwErrorOnInvalidDomain }: ResolverServiceOptions = defaultResolverServiceOptions): Promise<Account[]> {
        const address = registry[domain];
        return address ? [{ address, network: "evm", from: this.vendor }] : [];
    }
}

Step 2. Register your ResolverService in RedefinedResolver

Initialize RedefinedResolver with your ResolverService only:

const resolver = new RedefinedResolver({
      resolvers: [new KeyValueResolverService()]
});

Or combine it with existing built-in resolver services:

const resolver = new RedefinedResolver({
      resolvers: [
            ...RedefinedResolver.createRedefinedResolvers(),
            new KeyValueResolverService(),
      ]
});

Step 3. Implement SupportReverse interface if your resolver is capable of domain lookup by address

export class KeyValueResolverService extends ResolverService implements SupportReverse {

    get vendor(): ResolverVendor {
        return "keyvalue";
    }

    async reverse(address: string): Promise<ReverseAccount[]> {
        try {
            return [{
                domain: "example",
                from: this.vendor
            }]
        } catch (e: any) {
            throw Error(`KeyValue Error: ${e.message}`);
        }
    }
}

Contribute!

Open a pull request with your new ResolverService in our GitHub and help the community!

Last updated