0.4.1 • Published 1 year ago

@mvts/resolver-js v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@mvts/resolver-js

Installation

Using npm:

npm install @mvts/resolver-js

Using yarn:

yarn add @mvts/resolver-js

Once the package is installed, you can import the library using import or require approach:

// CommonJS
const {Resolver} = require('@mvts/resolver-js');

// ES6
import {Resolver} from '@mvts/resolver-js';

Usage

import {Resolver} from '@mvts/resolver-js';
import {JsonRpcProvider} from '@ethersproject/providers';


const resolver = new Resolver({
    rpcUrlsAndProviders: {
        1: 'https://example.com/rpc/ethereum-mainnet', // Ethereum Mainnet
        137: new JsonRpcProvider('https://example.com/rpc/polygon-mainnet') // Polygon Mainnet
    },
    useDefaultRpcUrls: false
});

resolver.getSipUri('30010645')
    .then((sipUri) => console.log('SIP URI:', sipUri))
    .catch((error) => console.log(`Failed to get SIP URI: ${error.message}`));

Options

NameTypeDefaultDescription
curator (optional)CuratorgetActualCurator()Custom curator. You can specify your curator, for example, for faster routing through your pool of numbers.
rpcUrlsAndProviders (optional){chainId: number: string | Provider}DEFAULT_RPC_URLS if useDefaultRpcUrlsDEFAULT_RPC_URLS are public so can be unreliable and slow, so you can specify your own RPC URLs and providers.
useDefaultRpcUrls (optional)booleantrueThis option allows you to disable the use of RPC URLs by default. By default are used.
useCache (optional)booleantrueThe resolver caches the data and uses it according to TTL. This option allows you to disable cache usage. The cache is used by default.

Methods

NameDescription
getUseCache(): booleanReturns the current value of the useCache flag, which enables/disables the use of the cache.
setUseCache(useCache: boolean): voidChanges the value of the useCache flag, which enables/disables the use of the cache.
clearCache(): voidClears the cache.
getSipUri(phoneNumber: string): PromiseReturns SIP URI for making a call.

Constants

NameTypeDescription
ACTUAL_CURATOR_CHAIN_IDnumberThe chain ID of the current smart contract Curator.
ACTUAL_CURATOR_ADDRESSstringThe address of the current smart contract Curator.
DEFAULT_RPC_URLSobjectDefault RPC URLs. It is guaranteed that this is enough to work with chains in which the curator and root router are deployed.

Utils

NameDescription
getActualCurator(signerOrProvider?: Signer | Provider): CuratorReturns the actual curator.
getActualRootRouter(getSignerOrProvider?: (chainId: number) => Signer | Provider): Promise<RootRouter>Returns the actual root router. The root router can change and be in any chain, so getSignerOrProvider is a function that returns the appropriate provider or signer depending on the current chainId of the root router. See example below.
nodeIsNumber(nodeData: Router.NodeDataStructOutput): booleanReturns true if the node is a number.
nodeIsPool(nodeData: Router.NodeDataStructOutput): booleanReturns true if the node is a pool.

getActualRootRouter usage example

import {getActualRootRouter, DEFAULT_RPC_URLS} from '@mvts/resolver-js';
import {JsonRpcProvider} from '@ethersproject/providers';


function getSignerOrProvider(chainId) {
    const rpcUrl =  DEFAULT_RPC_URLS[chainId];
    if (!rpcUrl) {
        throw new Error(`Missing provider for chain ${chainId}.`);
    }

    return new JsonRpcProvider(rpcUrl);
}


getActualRootRouter(getSignerOrProvider)
    .then((rootRouter) => console.log(`Address of the actual root router: ${rootRouter.address}`))
    .catch((error) => console.log(`Failed to get the actual root router: ${error.message}`));

License

MIT