Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ledgerhq/domain-service

Package Overview
Dependencies
Maintainers
20
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ledgerhq/domain-service - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4-next.0

14

lib-es/hooks/index.js

@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import React, { createContext, useContext, useEffect, useMemo, useState, } from "react";
import React, { createContext, useContext, useEffect, useMemo, useState } from "react";
import { resolveAddress, resolveDomain } from "../resolvers";

@@ -17,3 +17,3 @@ import { getRegistriesForAddress } from "../registries";

import { isOutdated } from "./logic";
import { DomainEmpty, InvalidDomain, NoResolution, UnsupportedDomainOrAddress, } from "../errors";
import { DomainEmpty, InvalidDomain, NoResolution, UnsupportedDomainOrAddress } from "../errors";
const DomainServiceContext = createContext({

@@ -82,3 +82,3 @@ cache: {},

loadDomainServiceAPI: (addressOrDomain, registry) => __awaiter(this, void 0, void 0, function* () {
setState((oldState) => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: {
setState(oldState => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: {
status: "loading",

@@ -90,3 +90,3 @@ } }) })));

])
.then((res) => res.flat())
.then(res => res.flat())
.catch((e) => e);

@@ -113,11 +113,11 @@ const newEntry = (() => {

})();
setState((oldState) => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: newEntry }) })));
setState(oldState => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: newEntry }) })));
}),
clearCache: () => {
setState((oldState) => (Object.assign(Object.assign({}, oldState), { cache: {} })));
setState(oldState => (Object.assign(Object.assign({}, oldState), { cache: {} })));
},
}), []);
const value = Object.assign(Object.assign({}, state), api);
return (React.createElement(DomainServiceContext.Provider, { value: value }, children));
return React.createElement(DomainServiceContext.Provider, { value: value }, children);
}
//# sourceMappingURL=index.js.map

@@ -40,3 +40,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

const registries = yield getRegistries();
return registries.filter((registry) => registry.patterns.forward.test(domain));
return registries.filter(registry => registry.patterns.forward.test(domain));
});

@@ -51,4 +51,4 @@ /**

const registries = yield getRegistries();
return registries.filter((registry) => registry.patterns.reverse.test(address));
return registries.filter(registry => registry.patterns.reverse.test(address));
});
//# sourceMappingURL=index.js.map

@@ -14,3 +14,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

import { allSettled } from "../utils";
import { getRegistries, getRegistriesForAddress, getRegistriesForDomain, } from "../registries";
import { getRegistries, getRegistriesForAddress, getRegistriesForDomain } from "../registries";
/**

@@ -26,3 +26,3 @@ * Get an array of addresses for a domain

const registries = yield getRegistries();
const registry = registries.find((r) => r.name === registryName && r.patterns.forward.test(domain));
const registry = registries.find(r => r.name === registryName && r.patterns.forward.test(domain));
return registry

@@ -34,7 +34,7 @@ ? [registry]

}))();
const responses = allSettled(registries.map((registry) => axios.request({
const responses = allSettled(registries.map(registry => axios.request({
method: "GET",
url: registry.resolvers.forward.replace("{name}", domain),
})));
return responses.then((promises) => promises.reduce((result, promise, index) => {
return responses.then(promises => promises.reduce((result, promise, index) => {
var _a;

@@ -44,4 +44,3 @@ if (promise.status !== "fulfilled") {

/* istanbul ignore next: don't test logs */
if (axios.isAxiosError(promise.reason) &&
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
if (axios.isAxiosError(promise.reason) && ((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
log("domain-service", "failed to resolve a domain", {

@@ -83,3 +82,3 @@ domain,

const registries = yield getRegistries();
const registry = registries.find((r) => r.name === registryName && r.patterns.reverse.test(address));
const registry = registries.find(r => r.name === registryName && r.patterns.reverse.test(address));
return registry

@@ -99,7 +98,7 @@ ? [registry]

})();
const responses = allSettled(registries.map((registry) => axios.request({
const responses = allSettled(registries.map(registry => axios.request({
method: "GET",
url: registry.resolvers.reverse.replace("{address}", address),
})));
return responses.then((promises) => promises.reduce((result, promise, index) => {
return responses.then(promises => promises.reduce((result, promise, index) => {
var _a;

@@ -109,4 +108,3 @@ if (promise.status !== "fulfilled") {

/* istanbul ignore next: don't test logs */
if (axios.isAxiosError(promise.reason) &&
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
if (axios.isAxiosError(promise.reason) && ((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
log("domain-service", "failed to resolve a address", {

@@ -113,0 +111,0 @@ address,

@@ -27,3 +27,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

const registries = yield getRegistries();
const registry = registries.find((r) => r.name === registryName);
const registry = registries.find(r => r.name === registryName);
if (!registry)

@@ -40,3 +40,3 @@ return null;

.then(({ data }) => data.payload)
.catch((error) => {
.catch(error => {
/* istanbul ignore next: don't test logs */

@@ -62,3 +62,3 @@ if (error.status !== 404) {

const registries = yield getRegistries();
const registry = registries.find((r) => r.name === registryName);
const registry = registries.find(r => r.name === registryName);
if (!registry)

@@ -75,3 +75,3 @@ return null;

.then(({ data }) => data.payload)
.catch((error) => {
.catch(error => {
/* istanbul ignore next: don't test logs */

@@ -78,0 +78,0 @@ if (error.status !== 404) {

/* istanbul ignore file: this file can be ignored in tests as long as it's only for debugging purpose & not touching userland */
const TLVs = {
"01": { typeName: "STRUCTURE_TYPE", parser: (input) => parseInt(input, 16) },
"02": { typeName: "VERSION", parser: (input) => parseInt(input, 16) },
"12": { typeName: "CHALLENGE", parser: (input) => input },
"13": { typeName: "SIGNER_KEY_ID", parser: (input) => input },
"14": { typeName: "SIGNER_ALGO", parser: (input) => input },
"01": { typeName: "STRUCTURE_TYPE", parser: input => parseInt(input, 16) },
"02": { typeName: "VERSION", parser: input => parseInt(input, 16) },
"12": { typeName: "CHALLENGE", parser: input => input },
"13": { typeName: "SIGNER_KEY_ID", parser: input => input },
"14": { typeName: "SIGNER_ALGO", parser: input => input },
"20": {
typeName: "TRUSTED_NAME",
parser: (input) => Buffer.from(input, "hex").toString(),
parser: input => Buffer.from(input, "hex").toString(),
},
"21": { typeName: "COIN_TYPE", parser: (input) => parseInt(input, 16) },
"22": { typeName: "ADDRESS", parser: (input) => `0x${input}` },
"15": { typeName: "SIGNATURE", parser: (input) => input },
"21": { typeName: "COIN_TYPE", parser: input => parseInt(input, 16) },
"22": { typeName: "ADDRESS", parser: input => `0x${input}` },
"15": { typeName: "SIGNATURE", parser: input => input },
};

@@ -16,0 +16,0 @@ /**

@@ -5,5 +5,5 @@ /**

export const allSettled = (promises) => {
return Promise.all(promises.map((p) => {
return Promise.all(promises.map(p => {
return p
.then((value) => {
.then(value => {
return {

@@ -10,0 +10,0 @@ status: "fulfilled",

@@ -107,3 +107,3 @@ "use strict";

loadDomainServiceAPI: (addressOrDomain, registry) => __awaiter(this, void 0, void 0, function* () {
setState((oldState) => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: {
setState(oldState => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: {
status: "loading",

@@ -115,3 +115,3 @@ } }) })));

])
.then((res) => res.flat())
.then(res => res.flat())
.catch((e) => e);

@@ -138,12 +138,12 @@ const newEntry = (() => {

})();
setState((oldState) => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: newEntry }) })));
setState(oldState => (Object.assign(Object.assign({}, oldState), { cache: Object.assign(Object.assign({}, oldState.cache), { [addressOrDomain]: newEntry }) })));
}),
clearCache: () => {
setState((oldState) => (Object.assign(Object.assign({}, oldState), { cache: {} })));
setState(oldState => (Object.assign(Object.assign({}, oldState), { cache: {} })));
},
}), []);
const value = Object.assign(Object.assign({}, state), api);
return (react_1.default.createElement(DomainServiceContext.Provider, { value: value }, children));
return react_1.default.createElement(DomainServiceContext.Provider, { value: value }, children);
}
exports.DomainServiceProvider = DomainServiceProvider;
//# sourceMappingURL=index.js.map

@@ -44,3 +44,3 @@ "use strict";

const registries = yield (0, exports.getRegistries)();
return registries.filter((registry) => registry.patterns.forward.test(domain));
return registries.filter(registry => registry.patterns.forward.test(domain));
});

@@ -56,5 +56,5 @@ exports.getRegistriesForDomain = getRegistriesForDomain;

const registries = yield (0, exports.getRegistries)();
return registries.filter((registry) => registry.patterns.reverse.test(address));
return registries.filter(registry => registry.patterns.reverse.test(address));
});
exports.getRegistriesForAddress = getRegistriesForAddress;
//# sourceMappingURL=index.js.map

@@ -31,3 +31,3 @@ "use strict";

const registries = yield (0, registries_1.getRegistries)();
const registry = registries.find((r) => r.name === registryName && r.patterns.forward.test(domain));
const registry = registries.find(r => r.name === registryName && r.patterns.forward.test(domain));
return registry

@@ -39,7 +39,7 @@ ? [registry]

}))();
const responses = (0, utils_1.allSettled)(registries.map((registry) => axios_1.default.request({
const responses = (0, utils_1.allSettled)(registries.map(registry => axios_1.default.request({
method: "GET",
url: registry.resolvers.forward.replace("{name}", domain),
})));
return responses.then((promises) => promises.reduce((result, promise, index) => {
return responses.then(promises => promises.reduce((result, promise, index) => {
var _a;

@@ -49,4 +49,3 @@ if (promise.status !== "fulfilled") {

/* istanbul ignore next: don't test logs */
if (axios_1.default.isAxiosError(promise.reason) &&
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
if (axios_1.default.isAxiosError(promise.reason) && ((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
(0, logs_1.log)("domain-service", "failed to resolve a domain", {

@@ -89,3 +88,3 @@ domain,

const registries = yield (0, registries_1.getRegistries)();
const registry = registries.find((r) => r.name === registryName && r.patterns.reverse.test(address));
const registry = registries.find(r => r.name === registryName && r.patterns.reverse.test(address));
return registry

@@ -105,7 +104,7 @@ ? [registry]

})();
const responses = (0, utils_1.allSettled)(registries.map((registry) => axios_1.default.request({
const responses = (0, utils_1.allSettled)(registries.map(registry => axios_1.default.request({
method: "GET",
url: registry.resolvers.reverse.replace("{address}", address),
})));
return responses.then((promises) => promises.reduce((result, promise, index) => {
return responses.then(promises => promises.reduce((result, promise, index) => {
var _a;

@@ -115,4 +114,3 @@ if (promise.status !== "fulfilled") {

/* istanbul ignore next: don't test logs */
if (axios_1.default.isAxiosError(promise.reason) &&
((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
if (axios_1.default.isAxiosError(promise.reason) && ((_a = promise.reason.response) === null || _a === void 0 ? void 0 : _a.status) !== 404) {
(0, logs_1.log)("domain-service", "failed to resolve a address", {

@@ -119,0 +117,0 @@ address,

@@ -33,3 +33,3 @@ "use strict";

const registries = yield (0, registries_1.getRegistries)();
const registry = registries.find((r) => r.name === registryName);
const registry = registries.find(r => r.name === registryName);
if (!registry)

@@ -46,3 +46,3 @@ return null;

.then(({ data }) => data.payload)
.catch((error) => {
.catch(error => {
/* istanbul ignore next: don't test logs */

@@ -69,3 +69,3 @@ if (error.status !== 404) {

const registries = yield (0, registries_1.getRegistries)();
const registry = registries.find((r) => r.name === registryName);
const registry = registries.find(r => r.name === registryName);
if (!registry)

@@ -82,3 +82,3 @@ return null;

.then(({ data }) => data.payload)
.catch((error) => {
.catch(error => {
/* istanbul ignore next: don't test logs */

@@ -85,0 +85,0 @@ if (error.status !== 404) {

@@ -6,14 +6,14 @@ "use strict";

const TLVs = {
"01": { typeName: "STRUCTURE_TYPE", parser: (input) => parseInt(input, 16) },
"02": { typeName: "VERSION", parser: (input) => parseInt(input, 16) },
"12": { typeName: "CHALLENGE", parser: (input) => input },
"13": { typeName: "SIGNER_KEY_ID", parser: (input) => input },
"14": { typeName: "SIGNER_ALGO", parser: (input) => input },
"01": { typeName: "STRUCTURE_TYPE", parser: input => parseInt(input, 16) },
"02": { typeName: "VERSION", parser: input => parseInt(input, 16) },
"12": { typeName: "CHALLENGE", parser: input => input },
"13": { typeName: "SIGNER_KEY_ID", parser: input => input },
"14": { typeName: "SIGNER_ALGO", parser: input => input },
"20": {
typeName: "TRUSTED_NAME",
parser: (input) => Buffer.from(input, "hex").toString(),
parser: input => Buffer.from(input, "hex").toString(),
},
"21": { typeName: "COIN_TYPE", parser: (input) => parseInt(input, 16) },
"22": { typeName: "ADDRESS", parser: (input) => `0x${input}` },
"15": { typeName: "SIGNATURE", parser: (input) => input },
"21": { typeName: "COIN_TYPE", parser: input => parseInt(input, 16) },
"22": { typeName: "ADDRESS", parser: input => `0x${input}` },
"15": { typeName: "SIGNATURE", parser: input => input },
};

@@ -20,0 +20,0 @@ /**

@@ -8,5 +8,5 @@ "use strict";

const allSettled = (promises) => {
return Promise.all(promises.map((p) => {
return Promise.all(promises.map(p => {
return p
.then((value) => {
.then(value => {
return {

@@ -13,0 +13,0 @@ status: "fulfilled",

{
"name": "@ledgerhq/domain-service",
"description": "Ledger service responsible for domain handling",
"version": "1.1.3",
"version": "1.1.4-next.0",
"license": "Apache-2.0",

@@ -61,6 +61,6 @@ "repository": {

"react-dom": "^17.0.2",
"@ledgerhq/cryptoassets": "^9.7.0",
"@ledgerhq/errors": "^6.12.6",
"@ledgerhq/cryptoassets": "^9.8.0-next.0",
"@ledgerhq/errors": "^6.12.7-next.0",
"@ledgerhq/logs": "^6.10.1",
"@ledgerhq/types-live": "^6.35.0"
"@ledgerhq/types-live": "^6.35.1-next.0"
},

@@ -74,17 +74,9 @@ "devDependencies": {

"@types/testing-library__jest-dom": "^5.14.5",
"@typescript-eslint/eslint-plugin": "^5.46.1",
"@typescript-eslint/parser": "^5.46.1",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-typescript": "^3.0.0",
"eslint-formatter-pretty": "^3.0.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-typescript": "^0.14.0",
"eslint-plugin-jest": "^27.2.1",
"jest": "^28.1.3",
"jest-environment-jsdom": "^28.1.3",
"prettier": "^2.8.1",
"react-test-renderer": "^17.0.2",
"ts-jest": "^28.0.8",
"@ledgerhq/types-cryptoassets": "^7.2.0"
"@ledgerhq/types-cryptoassets": "^7.2.1-next.0"
},

@@ -96,3 +88,3 @@ "scripts": {

"watch": "tsc --watch",
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx",
"lint": "eslint ./src --no-error-on-unmatched-pattern --ext .ts,.tsx --cache",
"lint:fix": "pnpm lint --fix",

@@ -99,0 +91,0 @@ "test": "cross-env TZ=America/New_York jest"

@@ -1,5 +0,2 @@

import {
getRegistriesForAddress,
getRegistriesForDomain,
} from "../../registries";
import { getRegistriesForAddress, getRegistriesForDomain } from "../../registries";

@@ -14,5 +11,3 @@ describe("Domain Service", () => {

it("should return an empty array for an unsupported domain", async () => {
expect(await getRegistriesForDomain("vitalik.notsupport")).toHaveLength(
0
);
expect(await getRegistriesForDomain("vitalik.notsupport")).toHaveLength(0);
expect(await getRegistriesForDomain("vitaliketh")).toHaveLength(0);

@@ -25,5 +20,3 @@ });

expect(
await getRegistriesForAddress(
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
)
await getRegistriesForAddress("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"),
).toHaveLength(1);

@@ -30,0 +23,0 @@ });

@@ -12,10 +12,8 @@ import axios from "axios";

jest.restoreAllMocks();
jest
.spyOn(mockedAxios, "request")
.mockImplementation(async ({ url }) => {
if (url?.endsWith("vitalik.eth")) {
return { data: "0x123" } as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
jest.spyOn(mockedAxios, "request").mockImplementation(async ({ url }) => {
if (url?.endsWith("vitalik.eth")) {
return { data: "0x123" } as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
});

@@ -56,16 +54,12 @@

jest.restoreAllMocks();
jest
.spyOn(mockedAxios, "request")
.mockImplementation(async ({ url }) => {
if (url?.endsWith("0xd8da6bf26964af9d7eed9e03e53415d37aa96045")) {
return { data: "vitalik.eth" } as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
jest.spyOn(mockedAxios, "request").mockImplementation(async ({ url }) => {
if (url?.endsWith("0xd8da6bf26964af9d7eed9e03e53415d37aa96045")) {
return { data: "vitalik.eth" } as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
});
it("should resolve an address with a reverse record ENS by inferring registries", async () => {
const resolutions = await resolveAddress(
"0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
);
const resolutions = await resolveAddress("0xd8da6bf26964af9d7eed9e03e53415d37aa96045");
expect(resolutions).toEqual([

@@ -84,3 +78,3 @@ {

"0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
"ens"
"ens",
);

@@ -87,0 +81,0 @@ expect(resolutions).toEqual([

@@ -13,16 +13,14 @@ import axios from "axios";

jest.restoreAllMocks();
jest
.spyOn(mockedAxios, "request")
.mockImplementation(async ({ url }) => {
const regex = /.*ens.*forward.*vitalik.eth/;
if (url && regex.test(url)) {
return {
data: {
payload:
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d",
},
} as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
jest.spyOn(mockedAxios, "request").mockImplementation(async ({ url }) => {
const regex = /.*ens.*forward.*vitalik.eth/;
if (url && regex.test(url)) {
return {
data: {
payload:
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d",
},
} as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
});

@@ -32,3 +30,3 @@

expect(await signDomainResolution("vitalik.eth", "ens", "123")).toEqual(
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d"
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d",
);

@@ -38,5 +36,3 @@ });

it("should return null for an unknown registry", async () => {
expect(
await signDomainResolution("vitalik.eth", "test" as any, "123")
).toEqual(null);
expect(await signDomainResolution("vitalik.eth", "test" as any, "123")).toEqual(null);
});

@@ -71,17 +67,14 @@

jest.restoreAllMocks();
jest
.spyOn(mockedAxios, "request")
.mockImplementation(async ({ url }) => {
const regex =
/.*ens.*reverse.*0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045/;
if (url && regex.test(url)) {
return {
data: {
payload:
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d",
},
} as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
jest.spyOn(mockedAxios, "request").mockImplementation(async ({ url }) => {
const regex = /.*ens.*reverse.*0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045/;
if (url && regex.test(url)) {
return {
data: {
payload:
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d",
},
} as any;
}
return Promise.reject({ response: { status: 404 } }) as any;
});
});

@@ -91,9 +84,5 @@

expect(
await signAddressResolution(
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"ens",
"123"
)
await signAddressResolution("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "ens", "123"),
).toEqual(
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d"
"010103020101130103140101120021013c200b766974616c696b2e6574682214d8da6bf26964af9d7eed9e03e53415d37aa9604515473045022100eb0b71c3bc69990eb98a4518473f49821554b1fd3e29f9994246902edbab2e3f02204c1480d8d1d1ef5e7e545d31a95484a84da4a1827e4288d0efa888c664faf03d",
);

@@ -107,4 +96,4 @@ });

"test" as any,
"123"
)
"123",
),
).toEqual(null);

@@ -111,0 +100,0 @@ });

@@ -68,8 +68,6 @@ import { validateDomain } from "../../utils/index";

// @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode#parameters
new Array(0xffff)
.fill(null)
.map((_, i) => ({ code: i, value: String.fromCharCode(i) }))
new Array(0xffff).fill(null).map((_, i) => ({ code: i, value: String.fromCharCode(i) })),
)(
"should accept or reject a domain depending on if it's containing ASCII or non ASCII caracters. Testing: {%o}",
(char) => {
char => {
if (validCharCodes.includes(char.code)) {

@@ -81,3 +79,3 @@ // 127 => "~" everything after that caracter is refused

}
}
},
);

@@ -84,0 +82,0 @@ });

@@ -6,4 +6,2 @@ import { createCustomErrorClass } from "@ledgerhq/errors";

export const NoResolution = createCustomErrorClass("NoResolution");
export const UnsupportedDomainOrAddress = createCustomErrorClass(
"UnsupportedDomainOrAddress"
);
export const UnsupportedDomainOrAddress = createCustomErrorClass("UnsupportedDomainOrAddress");

@@ -22,8 +22,6 @@ import {

export const isLoaded = (
domain: DomainServiceStatus
): domain is DomainServiceResponseLoaded => domain.status === "loaded";
export const isLoaded = (domain: DomainServiceStatus): domain is DomainServiceResponseLoaded =>
domain.status === "loaded";
export const isError = (
domain: DomainServiceStatus
): domain is DomainServiceResponseError => domain.status === "error";
export const isError = (domain: DomainServiceStatus): domain is DomainServiceResponseError =>
domain.status === "error";

@@ -27,10 +27,6 @@ import { DomainServiceResolution, SupportedRegistries } from "../types";

export type DomainServiceContextAPI = {
loadDomainServiceAPI: (
domainOrAddress: string,
registry?: SupportedRegistries
) => Promise<void>;
loadDomainServiceAPI: (domainOrAddress: string, registry?: SupportedRegistries) => Promise<void>;
clearCache: () => void;
};
export type DomainServiceContextType = DomainServiceContextState &
DomainServiceContextAPI;
export type DomainServiceContextType = DomainServiceContextState & DomainServiceContextAPI;

@@ -7,4 +7,3 @@ import { Registry } from "../types";

resolvers: {
forward:
"https://explorers.api.live.ledger.com/blockchain/v4/eth/ens/resolve/{name}",
forward: "https://explorers.api.live.ledger.com/blockchain/v4/eth/ens/resolve/{name}",
reverse:

@@ -14,4 +13,3 @@ "https://explorers.api.live.ledger.com/blockchain/v4/eth/ens/reverse-resolve/{address}",

signatures: {
forward:
"https://nft.api.live.ledger.com/v1/names/ens/forward/{name}?challenge={challenge}",
forward: "https://nft.api.live.ledger.com/v1/names/ens/forward/{name}?challenge={challenge}",
reverse:

@@ -39,10 +37,6 @@ "https://nft.api.live.ledger.com/v1/names/ens/reverse/{address}?challenge={challenge}",

*/
export const getRegistriesForDomain = async (
domain: string
): Promise<Registry[]> => {
export const getRegistriesForDomain = async (domain: string): Promise<Registry[]> => {
const registries = await getRegistries();
return registries.filter((registry) =>
registry.patterns.forward.test(domain)
);
return registries.filter(registry => registry.patterns.forward.test(domain));
};

@@ -56,10 +50,6 @@

*/
export const getRegistriesForAddress = async (
address: string
): Promise<Registry[]> => {
export const getRegistriesForAddress = async (address: string): Promise<Registry[]> => {
const registries = await getRegistries();
return registries.filter((registry) =>
registry.patterns.reverse.test(address)
);
return registries.filter(registry => registry.patterns.reverse.test(address));
};

@@ -6,7 +6,3 @@ import axios from "axios";

import { allSettled } from "../utils";
import {
getRegistries,
getRegistriesForAddress,
getRegistriesForDomain,
} from "../registries";
import { getRegistries, getRegistriesForAddress, getRegistriesForDomain } from "../registries";

@@ -21,3 +17,3 @@ /**

domain: string,
registryName?: SupportedRegistries
registryName?: SupportedRegistries,
): Promise<DomainServiceResolution[]> => {

@@ -28,3 +24,3 @@ const registries = await (async () => {

const registry = registries.find(
(r) => r.name === registryName && r.patterns.forward.test(domain)
r => r.name === registryName && r.patterns.forward.test(domain),
);

@@ -39,11 +35,11 @@ return registry

const responses = allSettled(
registries.map((registry) =>
registries.map(registry =>
axios.request<string>({
method: "GET",
url: registry.resolvers.forward.replace("{name}", domain),
})
)
}),
),
);
return responses.then((promises) =>
return responses.then(promises =>
promises.reduce((result, promise, index) => {

@@ -53,6 +49,3 @@ if (promise.status !== "fulfilled") {

/* istanbul ignore next: don't test logs */
if (
axios.isAxiosError(promise.reason) &&
promise.reason.response?.status !== 404
) {
if (axios.isAxiosError(promise.reason) && promise.reason.response?.status !== 404) {
log("domain-service", "failed to resolve a domain", {

@@ -83,3 +76,3 @@ domain,

return result;
}, [] as DomainServiceResolution[])
}, [] as DomainServiceResolution[]),
);

@@ -96,3 +89,3 @@ };

address: string,
registryName?: SupportedRegistries
registryName?: SupportedRegistries,
): Promise<DomainServiceResolution[]> => {

@@ -103,3 +96,3 @@ const registries = await (async () => {

const registry = registries.find(
(r) => r.name === registryName && r.patterns.reverse.test(address)
r => r.name === registryName && r.patterns.reverse.test(address),
);

@@ -122,11 +115,11 @@ return registry

const responses = allSettled(
registries.map((registry) =>
registries.map(registry =>
axios.request<string>({
method: "GET",
url: registry.resolvers.reverse.replace("{address}", address),
})
)
}),
),
);
return responses.then((promises) =>
return responses.then(promises =>
promises.reduce((result, promise, index) => {

@@ -136,6 +129,3 @@ if (promise.status !== "fulfilled") {

/* istanbul ignore next: don't test logs */
if (
axios.isAxiosError(promise.reason) &&
promise.reason.response?.status !== 404
) {
if (axios.isAxiosError(promise.reason) && promise.reason.response?.status !== 404) {
log("domain-service", "failed to resolve a address", {

@@ -158,4 +148,4 @@ address,

return result;
}, [] as DomainServiceResolution[])
}, [] as DomainServiceResolution[]),
);
};

@@ -18,11 +18,11 @@ import axios from "axios";

registryName: SupportedRegistries,
challenge: string
challenge: string,
): Promise<string | null> => {
if (!validateDomain(domain)) {
throw new Error(
`Domains with more than 255 caracters or with unicode are not supported on the nano. Domain: ${domain}`
`Domains with more than 255 caracters or with unicode are not supported on the nano. Domain: ${domain}`,
);
}
const registries = await getRegistries();
const registry = registries.find((r) => r.name === registryName);
const registry = registries.find(r => r.name === registryName);
if (!registry) return null;

@@ -40,3 +40,3 @@

.then(({ data }) => data.payload)
.catch((error) => {
.catch(error => {
/* istanbul ignore next: don't test logs */

@@ -64,6 +64,6 @@ if (error.status !== 404) {

registryName: SupportedRegistries,
challenge: string
challenge: string,
): Promise<string | null> => {
const registries = await getRegistries();
const registry = registries.find((r) => r.name === registryName);
const registry = registries.find(r => r.name === registryName);
if (!registry) return null;

@@ -81,3 +81,3 @@

.then(({ data }) => data.payload)
.catch((error) => {
.catch(error => {
/* istanbul ignore next: don't test logs */

@@ -84,0 +84,0 @@ if (error.status !== 404) {

@@ -23,18 +23,15 @@ /* istanbul ignore file: this file can be ignored in tests as long as it's only for debugging purpose & not touching userland */

const TLVs: Record<
TLV_IDS,
{ typeName: TLV_TYPES; parser: (input: string) => string | number }
> = {
"01": { typeName: "STRUCTURE_TYPE", parser: (input) => parseInt(input, 16) },
"02": { typeName: "VERSION", parser: (input) => parseInt(input, 16) },
"12": { typeName: "CHALLENGE", parser: (input) => input },
"13": { typeName: "SIGNER_KEY_ID", parser: (input) => input },
"14": { typeName: "SIGNER_ALGO", parser: (input) => input },
const TLVs: Record<TLV_IDS, { typeName: TLV_TYPES; parser: (input: string) => string | number }> = {
"01": { typeName: "STRUCTURE_TYPE", parser: input => parseInt(input, 16) },
"02": { typeName: "VERSION", parser: input => parseInt(input, 16) },
"12": { typeName: "CHALLENGE", parser: input => input },
"13": { typeName: "SIGNER_KEY_ID", parser: input => input },
"14": { typeName: "SIGNER_ALGO", parser: input => input },
"20": {
typeName: "TRUSTED_NAME",
parser: (input) => Buffer.from(input, "hex").toString(),
parser: input => Buffer.from(input, "hex").toString(),
},
"21": { typeName: "COIN_TYPE", parser: (input) => parseInt(input, 16) },
"22": { typeName: "ADDRESS", parser: (input) => `0x${input}` },
"15": { typeName: "SIGNATURE", parser: (input) => input },
"21": { typeName: "COIN_TYPE", parser: input => parseInt(input, 16) },
"22": { typeName: "ADDRESS", parser: input => `0x${input}` },
"15": { typeName: "SIGNATURE", parser: input => input },
};

@@ -46,6 +43,5 @@

export const tlvParser = (
apdu: string
apdu: string,
): { T: TLV_TYPES; L: string; V: string | number | null }[] => {
const parsedApdu: { T: TLV_TYPES; L: string; V: string | number | null }[] =
[];
const parsedApdu: { T: TLV_TYPES; L: string; V: string | number | null }[] = [];

@@ -52,0 +48,0 @@ let apduLeft = apdu;

import { CoinType } from "@ledgerhq/types-cryptoassets";
import type {
SupportedRegistries,
DomainServiceResolution,
} from "@ledgerhq/types-live/lib/domain";
import type { SupportedRegistries, DomainServiceResolution } from "@ledgerhq/types-live/lib/domain";

@@ -32,6 +29,4 @@ export type Registry = {

}
export type PromiseResult<T, E = unknown> =
| PromiseResolution<T>
| PromiseRejection<E>;
export type PromiseResult<T, E = unknown> = PromiseResolution<T> | PromiseRejection<E>;
export { SupportedRegistries, DomainServiceResolution };

@@ -6,9 +6,7 @@ import { PromiseResult } from "../types";

*/
export const allSettled = <T>(
promises: Promise<T>[]
): Promise<PromiseResult<T>[]> => {
export const allSettled = <T>(promises: Promise<T>[]): Promise<PromiseResult<T>[]> => {
return Promise.all(
promises.map((p) => {
promises.map(p => {
return p
.then((value) => {
.then(value => {
return {

@@ -25,3 +23,3 @@ status: "fulfilled" as const,

});
})
}),
);

@@ -42,7 +40,5 @@ };

const lengthIsValid = domain.length > 0 && Number(domain.length) < 30;
const containsOnlyValidChars = new RegExp("^[a-zA-Z0-9\\-\\_\\.]+$").test(
domain
);
const containsOnlyValidChars = new RegExp("^[a-zA-Z0-9\\-\\_\\.]+$").test(domain);
return lengthIsValid && containsOnlyValidChars;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc