2.10.6 • Published 6 months ago

@redefined/name-resolver-js v2.10.6

Weekly downloads
-
License
-
Repository
github
Last release
6 months ago

Usage

Installation

npm i @redefined/name-resolver-js

or download the lib from NPM registry manually: https://www.npmjs.com/package/@redefined/name-resolver-js

Full documentation

Usage

// initialize resolver
const resolver = new RedefinedResolver();

// resolve redefined names
const emailResult = await resolver.resolve("ik@e2xlabs.com");
/* {
    response: [
        {
            address: "0x6BdfC9Fb0102ddEFc2C7eb44cf62e96356D55d04",
            network: "evm",
            from: "redefined-email"
        }, {
            address: "0x6BdfC9Fb0102ddEFc2C7eb44cf62e96356D55d04",
            network: "bsc",
            from: "redefined-email"
        }
    ],
    errors: [
        {
            vendor: "ens",
            error: "Invalid domain",
        },
    ],
}*/
const nicknameResult = await resolver.resolve("gigachadivan");
/* {
    response: [{
        address: "GsYPSWAbXw4YsSEeowuTf7nqjExVxKS5tS1Yy9WwFAPG",
        network: "sol",
        from: "redefined-username"
    }],
    errors: [],
}*/

// resolve ENS names
const ensResult = await resolver.resolve("ivan.eth");
/* {
    response: [{
        address: "0x25428d29a6FA3629ff401c6DADe418B19CB2D615",
        network: "evm",
        from: "ens"
    }],
    errors: [
        {
            vendor: "redefiend-email",
            error: "Domain is not registered",
        },
    ],
}*/

// resolve Unstoppable names
const unstoppableResult = await resolver.resolve("nick.crypto");
/* {
    response: [{
        address: "0x16d94b922bF11981DBa2C4A6cAEd9938F00d5d0C",
        network: "evm",
        from: "unstoppable"
    }],
    errors: [],
}*/

// resolve specific network
const ethResult = await resolver.resolve("ik@e2xlabs.com", ["eth"]);
/* {
    response: [{
        address: "0x6BdfC9Fb0102ddEFc2C7eb44cf62e96356D55d04",
        network: "eth",
        from: "redefined-email"
    }],
    errors: [],
}*/
const bscFromUnstoppable = await resolver.resolve("nick.crypto", ["bsc"]);
/* {
    response: [{
        address: "0x16d94b922bF11981DBa2C4A6cAEd9938F00d5d0C",
        network: "evm",
        from: "unstoppable"
    }],
    errors: [],
}*/

Priorties of resolution of EVM-compatible

For example, you want to get a BSC or Polygon address, but there is no special mapping for them, we will fall back to default EVM mapping.

  1. If we do not find the address in the desired network, but find EVM, then we will give you EVM
  2. If we find the address in the desired network + EVM, then we will give you only the address in the desired network
  3. If desired network is not specified, we will return all known results
resolve.resolve("domain", ["eth"]);
// We found [{ address: "0x", network: "eth", from:"redefined" }, { address: "0x", network: "evm", from:"redefined" }]
// You receive [{ address: "0x", network: "eth", from:"redefined" }]

resolve.resolve("domain", ["eth"]);
// We found [{ address: "0x", network: "bsc", from:"redefined" }, { address: "0x", network: "evm", from:"redefined" }]
// You receive [{ address: "0x", network: "evm, from:"redefined" }]

resolve.resolve("domain");
// We found [{ address: "0x", network: "bsc", from:"redefined" }, { address: "0x", network: "evm", from:"redefined" }]
// You receive [{ address: "0x", network: "bsc, from:"redefined" }, { address: "0x", network: "evm", from:"redefined" }]

Recommended config for Production use

Each supported domain system is hosted on some blockhain, and lib needs corresponding JSON RPC nodes in order to resolve names.

Our lib comes with all necessary node URLs built-in, but we strongly recommend specifying your own JSON RPC node URLs in order to provide best availability of service.

Please follow set-your-own-node-urls.md documentation.

Set your own Node URLs

We recommend you to use your own JSON RPC URLs, especially for production: this will improve availability of service and will lower the load on our public nodes.

Pass node URLs on init

const options: ResolversParams = {
  redefined: {
      node: "https://evm.node.io/123abc",
  },
  unstoppable: {
      mainnetNode: "https://evm2.node.io/123abc",
      polygonMainnetNode: "https://evm-polygon.node.io/123abc",
  },
  ens: {
    node: "https://evm.node.io/123abc",
  },
}

const resolver = new RedefinedResolver({
      resolvers: RedefinedResolver.createDefaultResolvers(options)
});

Add your own Custom Resolver

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

Step 1. Extend ResolverService class

Please see github for sources: https://github.com/e2xlabs/redefined-name-resolver-js/blob/master/src/services/resolvers/resolver.service.ts

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

Example:

export class KeyValueResolverService extends ResolverService {

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

    async resolve(domain: string): Promise<Account[]> {
        const address = registry[domain];
        
        if (!address) throw Error("Domain is not registered")
        
        return [{ 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.createDefaultResolvers(),
            new KeyValueResolverService(),
      ]
});

Contribute!

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

Customization

Reference

export type EnsParams = { node: string };
export type UnstoppableParams = { mainnetNode?: string, polygonMainnetNode?: string };
export type RedefinedParams = { node?: string, allowDefaultEvmResolves?: boolean };

export type ResolversParams = {
    redefined?: RedefinedParams,
    unstoppable?: UnstoppableParams,
    ens?: EnsParams,
}

Set you own Nodes

Documented here.

Init with params

const resolver = new RedefinedResolver({
      resolvers: RedefinedResolver.createDefaultResolvers({
        // specify only params that you want to change
        redefined: {
          node: "https://evm.node.io/123",
          allowDefaultEvmResolves: false
        },
        // uncomment if you want to specify params for ens, otherwise defaults used
        // ens: { node: "https://evm.node.io/123abc" }
      })
});

Warning

Some of the libraries we use may not be properly configured. We try to minimize the damage to the users, but sometimes it doesn't work. If you are using Vite builder you may need to apply this code.

<!DOCTYPE html>
<html lang="en">
  <head>
    <script>window.require = () => {}</script>
    <script type="module">
        import { Buffer } from "buffer";
        window.Buffer = Buffer;
    </script>
    ....
  </head>
</html>
2.8.0

10 months ago

2.10.1

9 months ago

2.10.2

9 months ago

2.10.0

9 months ago

2.9.0

9 months ago

2.10.5

8 months ago

2.10.6

6 months ago

2.10.3

8 months ago

2.10.4

8 months ago

2.6.1

12 months ago

2.6.0

1 year ago

2.7.0

11 months ago

2.5.1

1 year ago

1.0.0

1 year ago

1.4.6

1 year ago

1.4.5

1 year ago

1.4.4

1 year ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.2.2

1 year ago

2.0.0

1 year ago

1.2.16

1 year ago

1.2.17

1 year ago

1.2.14

1 year ago

1.2.15

1 year ago

1.1.1

1 year ago

1.2.18

1 year ago

1.2.19

1 year ago

1.5.0

1 year ago

1.3.0

1 year ago

1.1.2

1 year ago

2.3.0

1 year ago

2.5.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.4

1 year ago

2.3.3

1 year ago

2.3.6

1 year ago

2.3.5

1 year ago

2.1.0

1 year ago

1.4.7

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago