@unstoppabledomains/resolution
Advanced tools
Comparing version 1.10.4 to 1.11.0
import Resolution from '../Resolution'; | ||
export declare function tryInfo(method: () => any, response: Record<string, string>, name: string): Promise<boolean>; | ||
export declare function commaSeparatedList(value: string, dummyPrevious: unknown): string[]; | ||
export declare function signedInfuraLink(key: string): string; | ||
export declare function getEthereumUrl(): string; | ||
export declare function buildResolutionPackage(): Resolution; | ||
declare type Config = { | ||
type: string; | ||
value: string; | ||
}; | ||
export declare function parseConfig(value: string): Config; | ||
export declare function storeConfig(type: 'infura' | 'url', value: string): void; | ||
export declare function getConfig(): Config; | ||
export {}; | ||
export declare function commaSeparatedList(value: string): string[]; | ||
export declare function buildResolutionPackage(ethereumUrl?: string): Resolution; |
@@ -41,31 +41,24 @@ "use strict"; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Resolution_1 = __importDefault(require("../Resolution")); | ||
var fs = __importStar(require("fs")); | ||
var resolutionError_1 = require("../errors/resolutionError"); | ||
var __1 = require(".."); | ||
function tryInfo(method, response, name) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var field, resolvedPromise, err_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
var field, _a, _b, err_1; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
field = name; | ||
_a.label = 1; | ||
_c.label = 1; | ||
case 1: | ||
_a.trys.push([1, 3, , 4]); | ||
_c.trys.push([1, 3, , 4]); | ||
_a = response; | ||
_b = field; | ||
return [4 /*yield*/, method()]; | ||
case 2: | ||
resolvedPromise = _a.sent(); | ||
response[field] = resolvedPromise; | ||
_a[_b] = _c.sent(); | ||
return [2 /*return*/, true]; | ||
case 3: | ||
err_1 = _a.sent(); | ||
if (Object.values(resolutionError_1.ResolutionErrorCode).includes(err_1.code)) { | ||
err_1 = _c.sent(); | ||
if (Object.values(__1.ResolutionErrorCode).includes(err_1.code)) { | ||
response[field] = err_1.code; | ||
@@ -83,61 +76,30 @@ } | ||
exports.tryInfo = tryInfo; | ||
function commaSeparatedList(value, dummyPrevious) { | ||
function commaSeparatedList(value) { | ||
return value.split(',').map(function (v) { return v.toUpperCase(); }); | ||
} | ||
exports.commaSeparatedList = commaSeparatedList; | ||
function signedInfuraLink(key) { | ||
return "https://mainnet.infura.io/v3/" + key; | ||
} | ||
exports.signedInfuraLink = signedInfuraLink; | ||
var configObject = getConfig(); | ||
function getEthereumUrl() { | ||
switch (configObject.type) { | ||
case 'infura': | ||
return signedInfuraLink(configObject.value); | ||
case 'url': | ||
return configObject.value; | ||
default: | ||
return 'https://main-rpc.linkpool.io/'; | ||
function buildResolutionPackage(ethereumUrl) { | ||
if (ethereumUrl) { | ||
try { | ||
var url = (new URL(ethereumUrl)).toString(); | ||
return new Resolution_1.default({ | ||
blockchain: { | ||
ens: url, | ||
cns: url, | ||
}, | ||
}); | ||
} | ||
catch (e) { | ||
if (e instanceof TypeError) { | ||
console.warn("--ethereum-url option is not valid URL"); | ||
} | ||
else { | ||
console.error(e); | ||
} | ||
} | ||
} | ||
console.warn('This RPC is limited to 2,000 calls per 5 minutes. If that is exceeded, then the source IP address is blocked'); | ||
console.warn('To configure a different provider set --ethereum-url option with valid ethereum provider url'); | ||
return new Resolution_1.default(); | ||
} | ||
exports.getEthereumUrl = getEthereumUrl; | ||
function buildResolutionPackage() { | ||
return new Resolution_1.default({ | ||
blockchain: { | ||
ens: getEthereumUrl(), | ||
cns: getEthereumUrl(), | ||
}, | ||
}); | ||
} | ||
exports.buildResolutionPackage = buildResolutionPackage; | ||
function parseConfig(value) { | ||
var words = value.split(':'); | ||
return { type: words[0], value: words.slice(1).join(':') }; | ||
} | ||
exports.parseConfig = parseConfig; | ||
function storeConfig(type, value) { | ||
// eslint-disable-next-line no-undef | ||
fs.writeFile(process.env.HOME + "/.resolution", type + "=" + value, function () { | ||
return console.log(type + "=" + value + " record stored"); | ||
}); | ||
} | ||
exports.storeConfig = storeConfig; | ||
function getConfig() { | ||
try { | ||
var config = fs | ||
// eslint-disable-next-line no-undef | ||
.readFileSync(process.env.HOME + "/.resolution") | ||
.toString() | ||
.split('='); | ||
return { type: config[0], value: config[1] }; | ||
} | ||
catch (err) { | ||
if (err.code === 'ENOENT') { | ||
console.warn('Configuration file was not found. Default blockchain provider: "https://main-rpc.linkpool.io/" is being used'); | ||
console.warn('This RPC is limited to 2,000 calls per 5 minutes. If that is exceeded, then the source IP address is blocked.'); | ||
console.warn('To configure a different provider use -C flag '); | ||
} | ||
return { type: 'unknown', value: '' }; | ||
} | ||
} | ||
exports.getConfig = getConfig; |
@@ -47,5 +47,5 @@ #!/usr/bin/env node | ||
(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var options, _a, type, value, domain, resolution, response, commandTable, resolutionProcess; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
var options, domain, resolution, response, commandTable, resolutionProcess; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
@@ -56,3 +56,2 @@ commander_1.default | ||
.option('-c, --currencies <currencies>', 'comma separated list of currency tickers', cli_helpers_js_1.commaSeparatedList) | ||
.option('-C, --config <option>', "option in format <key>:<value>\n\tkey can be either \"infura\" or \"url\"", cli_helpers_js_1.parseConfig) | ||
.option('-s, --service', 'returns you a service name from the domain') | ||
@@ -70,2 +69,3 @@ .option('-i, --ipfs', 'get IpfsHash') | ||
.option('-a, --all', 'get all keys stored under a domain') | ||
.option('--ethereum-url <ethereumUrl>', 'specify custom ethereum provider/url') | ||
.description('resolution cli exports main usage of @unstoppabledomains/resolution library'); | ||
@@ -85,9 +85,2 @@ // eslint-disable-next-line no-undef | ||
} | ||
if (options.config) { | ||
_a = options.config, type = _a.type, value = _a.value; | ||
if (type == 'infura' || type == 'url') { | ||
cli_helpers_js_1.storeConfig(type, value); | ||
} | ||
delete options.config; | ||
} | ||
if (!options.domain) { | ||
@@ -98,3 +91,3 @@ return [2 /*return*/]; | ||
delete options.domain; | ||
resolution = cli_helpers_js_1.buildResolutionPackage(); | ||
resolution = cli_helpers_js_1.buildResolutionPackage(options.ethereumUrl); | ||
response = {}; | ||
@@ -203,2 +196,3 @@ commandTable = { | ||
} | ||
delete options.ethereumUrl; | ||
// Execute the rest of options | ||
@@ -208,3 +202,3 @@ Object.keys(options).forEach(function (option) { return resolutionProcess.push(commandTable[option]()); }); | ||
case 1: | ||
_b.sent(); | ||
_a.sent(); | ||
console.log(JSON.stringify(response, undefined, 4)); | ||
@@ -211,0 +205,0 @@ return [2 /*return*/]; |
{ | ||
"name": "@unstoppabledomains/resolution", | ||
"version": "1.10.3", | ||
"version": "1.10.4", | ||
"description": "Domain Resolution for blockchain domains", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
{ | ||
"name": "@unstoppabledomains/resolution", | ||
"version": "1.10.4", | ||
"version": "1.11.0", | ||
"description": "Domain Resolution for blockchain domains", | ||
@@ -5,0 +5,0 @@ "main": "./build/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
2
363128
9216