@tradetrust-tt/dnsprove 2.15.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -16,12 +16,10 @@ Object.defineProperty(exports, "OpenAttestationDnsDidRecord", {
16
16
  }
17
17
  });
18
18
  exports.queryDns = exports.parseOpenAttestationRecord = exports.parseDocumentStoreResults = exports.parseDnsDidResults = exports.getDocumentStoreRecords = exports.getDnsDidRecords = exports.defaultDnsResolvers = void 0;
19
- var _axios = _interopRequireDefault(require("axios"));
20
19
  var _dnsTxt = require("./records/dnsTxt");
21
20
  var _dnsDid = require("./records/dnsDid");
22
21
  var _logger = require("./util/logger");
23
22
  var _error = require("./common/error");
24
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
26
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
27
25
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -39,29 +37,25 @@ const _getLogger = (0, _logger.getLogger)("index"),
39
37
  trace = _getLogger.trace;
40
38
  const defaultDnsResolvers = exports.defaultDnsResolvers = [( /*#__PURE__*/function () {
41
39
  var _ref = _asyncToGenerator(function* (domain) {
42
- const _yield$axios = yield (0, _axios.default)({
43
- method: "GET",
44
- url: `https://dns.google/resolve?name=${domain}&type=TXT`
45
- }),
46
- data = _yield$axios.data;
47
- return data;
40
+ const data = yield fetch(`https://dns.google/resolve?name=${domain}&type=TXT`, {
41
+ method: "GET"
42
+ });
43
+ return data.json();
48
44
  });
49
45
  return function (_x) {
50
46
  return _ref.apply(this, arguments);
51
47
  };
52
48
  }()), ( /*#__PURE__*/function () {
53
49
  var _ref2 = _asyncToGenerator(function* (domain) {
54
- const _yield$axios2 = yield (0, _axios.default)({
55
- method: "GET",
56
- url: `https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`,
57
- headers: {
58
- accept: "application/dns-json",
59
- contentType: "application/json",
60
- connection: "keep-alive"
61
- }
62
- }),
63
- data = _yield$axios2.data;
64
- return data;
50
+ const data = yield fetch(`https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`, {
51
+ method: "GET",
52
+ headers: {
53
+ accept: "application/dns-json",
54
+ contentType: "application/json",
55
+ connection: "keep-alive"
56
+ }
57
+ });
58
+ return data.json();
65
59
  });
66
60
  return function (_x2) {
67
61
  return _ref2.apply(this, arguments);
@@ -24,9 +24,10 @@ let EthereumNetworks = exports.EthereumNetworks = void 0;
24
24
  EthereumNetworks["xdcapothem"] = "51";
25
25
  EthereumNetworks["stabilityTestnet"] = "20180427";
26
26
  EthereumNetworks["stability"] = "101010";
27
+ EthereumNetworks["astronTestnet"] = "21002";
27
28
  EthereumNetworks["astron"] = "1338";
28
29
  })(EthereumNetworks || (exports.EthereumNetworks = EthereumNetworks = {}));
29
- const EthereumNetworkIdT = exports.EthereumNetworkIdT = (0, _runtypes.Union)((0, _runtypes.Literal)(EthereumNetworks.homestead), (0, _runtypes.Literal)(EthereumNetworks.ropsten), (0, _runtypes.Literal)(EthereumNetworks.rinkeby), (0, _runtypes.Literal)(EthereumNetworks.goerli), (0, _runtypes.Literal)(EthereumNetworks.sepolia), (0, _runtypes.Literal)(EthereumNetworks.polygon), (0, _runtypes.Literal)(EthereumNetworks.polygonAmoy), (0, _runtypes.Literal)(EthereumNetworks.xdc), (0, _runtypes.Literal)(EthereumNetworks.xdcapothem), (0, _runtypes.Literal)(EthereumNetworks.stabilityTestnet), (0, _runtypes.Literal)(EthereumNetworks.stability), (0, _runtypes.Literal)(EthereumNetworks.local), (0, _runtypes.Literal)(EthereumNetworks.astron));
30
+ const EthereumNetworkIdT = exports.EthereumNetworkIdT = (0, _runtypes.Union)((0, _runtypes.Literal)(EthereumNetworks.homestead), (0, _runtypes.Literal)(EthereumNetworks.ropsten), (0, _runtypes.Literal)(EthereumNetworks.rinkeby), (0, _runtypes.Literal)(EthereumNetworks.goerli), (0, _runtypes.Literal)(EthereumNetworks.sepolia), (0, _runtypes.Literal)(EthereumNetworks.polygon), (0, _runtypes.Literal)(EthereumNetworks.polygonAmoy), (0, _runtypes.Literal)(EthereumNetworks.xdc), (0, _runtypes.Literal)(EthereumNetworks.xdcapothem), (0, _runtypes.Literal)(EthereumNetworks.stabilityTestnet), (0, _runtypes.Literal)(EthereumNetworks.stability), (0, _runtypes.Literal)(EthereumNetworks.local), (0, _runtypes.Literal)(EthereumNetworks.astronTestnet), (0, _runtypes.Literal)(EthereumNetworks.astron));
30
31
  const OpenAttestationDNSTextRecordT = exports.OpenAttestationDNSTextRecordT = (0, _runtypes.Record)({
31
32
  type: RecordTypesT,
32
33
  net: BlockchainNetworkT,
@@ -15,13 +15,14 @@ export declare enum EthereumNetworks {
15
15
  xdcapothem = "51",
16
16
  stabilityTestnet = "20180427",
17
17
  stability = "101010",
18
+ astronTestnet = "21002",
18
19
  astron = "1338"
19
20
  }
20
- export declare const EthereumNetworkIdT: Union<[Literal<EthereumNetworks.homestead>, Literal<EthereumNetworks.ropsten>, Literal<EthereumNetworks.rinkeby>, Literal<EthereumNetworks.goerli>, Literal<EthereumNetworks.sepolia>, Literal<EthereumNetworks.polygon>, Literal<EthereumNetworks.polygonAmoy>, Literal<EthereumNetworks.xdc>, Literal<EthereumNetworks.xdcapothem>, Literal<EthereumNetworks.stabilityTestnet>, Literal<EthereumNetworks.stability>, Literal<EthereumNetworks.local>, Literal<EthereumNetworks.astron>]>;
21
+ export declare const EthereumNetworkIdT: Union<[Literal<EthereumNetworks.homestead>, Literal<EthereumNetworks.ropsten>, Literal<EthereumNetworks.rinkeby>, Literal<EthereumNetworks.goerli>, Literal<EthereumNetworks.sepolia>, Literal<EthereumNetworks.polygon>, Literal<EthereumNetworks.polygonAmoy>, Literal<EthereumNetworks.xdc>, Literal<EthereumNetworks.xdcapothem>, Literal<EthereumNetworks.stabilityTestnet>, Literal<EthereumNetworks.stability>, Literal<EthereumNetworks.local>, Literal<EthereumNetworks.astronTestnet>, Literal<EthereumNetworks.astron>]>;
21
22
  export declare const OpenAttestationDNSTextRecordT: import("runtypes").Intersect<[Record<{
22
23
  type: Literal<"openatts">;
23
24
  net: Literal<"ethereum">;
24
- netId: Union<[Literal<EthereumNetworks.homestead>, Literal<EthereumNetworks.ropsten>, Literal<EthereumNetworks.rinkeby>, Literal<EthereumNetworks.goerli>, Literal<EthereumNetworks.sepolia>, Literal<EthereumNetworks.polygon>, Literal<EthereumNetworks.polygonAmoy>, Literal<EthereumNetworks.xdc>, Literal<EthereumNetworks.xdcapothem>, Literal<EthereumNetworks.stabilityTestnet>, Literal<EthereumNetworks.stability>, Literal<EthereumNetworks.local>, Literal<EthereumNetworks.astron>]>;
25
+ netId: Union<[Literal<EthereumNetworks.homestead>, Literal<EthereumNetworks.ropsten>, Literal<EthereumNetworks.rinkeby>, Literal<EthereumNetworks.goerli>, Literal<EthereumNetworks.sepolia>, Literal<EthereumNetworks.polygon>, Literal<EthereumNetworks.polygonAmoy>, Literal<EthereumNetworks.xdc>, Literal<EthereumNetworks.xdcapothem>, Literal<EthereumNetworks.stabilityTestnet>, Literal<EthereumNetworks.stability>, Literal<EthereumNetworks.local>, Literal<EthereumNetworks.astronTestnet>, Literal<EthereumNetworks.astron>]>;
25
26
  addr: import("runtypes").Constraint<String, string, unknown>;
26
27
  }, false>, Partial<{
27
28
  dnssec: Boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradetrust-tt/dnsprove",
3
- "version": "2.15.0",
3
+ "version": "2.17.0",
4
4
  "description": "Helper utility for retrieving OpenAttestations document store address records from DNS",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.test.ts CHANGED
@@ -1,4 +1,3 @@
1
- import axios from "axios";
2
1
  import { setupServer, SetupServerApi } from "msw/node";
3
2
  import { http, HttpResponse } from "msw";
4
3
  import { CustomDnsResolver, getDocumentStoreRecords, queryDns, parseDocumentStoreResults, getDnsDidRecords } from ".";
@@ -211,20 +210,18 @@ describe("queryDns", () => {
211
210
 
212
211
  const testDnsResolvers: CustomDnsResolver[] = [
213
212
  async (domain) => {
214
- const { data } = await axios({
213
+ const data = await fetch(`https://dns.google/resolve?name=${domain}&type=TXT`, {
215
214
  method: "GET",
216
- url: `https://dns.google/resolve?name=${domain}&type=TXT`,
217
215
  });
218
216
 
219
- return data;
217
+ return data.json();
220
218
  },
221
219
  async (domain) => {
222
- const { data } = await axios({
220
+ const data = await fetch(`https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`, {
223
221
  method: "GET",
224
- url: `https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`,
225
222
  headers: { accept: "application/dns-json", contentType: "application/json", connection: "keep-alive" },
226
223
  });
227
- return data;
224
+ return data.json();
228
225
  },
229
226
  ];
230
227
 
@@ -244,7 +241,7 @@ describe("queryDns", () => {
244
241
 
245
242
  const records = await queryDns("https://donotuse.openattestation.com", testDnsResolvers);
246
243
  const sortedAnswer = records?.Answer.sort((a, b) => a.data.localeCompare(b.data));
247
- expect(sortedAnswer).toStrictEqual(sampleResponse.Answer);
244
+ expect(sortedAnswer).toMatchObject(sampleResponse.Answer);
248
245
  });
249
246
 
250
247
  test("Should fallback to second dns when first dns is down", async () => {
@@ -262,7 +259,7 @@ describe("queryDns", () => {
262
259
  const records = await queryDns("https://donotuse.openattestation.com", testDnsResolvers);
263
260
 
264
261
  const sortedAnswer = records?.Answer.sort((a, b) => a.data.localeCompare(b.data));
265
- expect(sortedAnswer).toStrictEqual(sampleResponse.Answer);
262
+ expect(sortedAnswer).toMatchObject(sampleResponse.Answer);
266
263
  });
267
264
 
268
265
  test("Should throw error when all dns provided are down", async () => {
@@ -284,6 +281,37 @@ describe("queryDns", () => {
284
281
  });
285
282
  });
286
283
 
284
+ describe("getDocumentStoreRecords for AstronTestnet", () => {
285
+ const sampleDnsTextRecord = [
286
+ {
287
+ type: "openatts",
288
+ net: "ethereum",
289
+ netId: "21002",
290
+ addr: "0xb1Bf514b3893357813F366282E887eE221D5C2dA",
291
+ dnssec: false,
292
+ },
293
+ {
294
+ type: "openatts",
295
+ net: "ethereum",
296
+ netId: "21002",
297
+ addr: "0xdAEe89A37fEEBCBFAc94aBA63Fb163808dAc38Fb",
298
+ dnssec: false,
299
+ },
300
+ ];
301
+
302
+ test("it should work with dev-astronlayer2.bitfactory.cn", async () => {
303
+ const records = (await getDocumentStoreRecords("dev-astronlayer2.bitfactory.cn")).sort((a, b) => {
304
+ if (a.netId < b.netId) return -1;
305
+ if (a.netId > b.netId) return 1;
306
+ if (a.addr < b.addr) return -1;
307
+ if (a.addr > b.addr) return 1;
308
+ return 0;
309
+ });
310
+
311
+ expect(records).toStrictEqual(sampleDnsTextRecord);
312
+ });
313
+ });
314
+
287
315
  describe("getDocumentStoreRecords for Astron", () => {
288
316
  const sampleDnsTextRecord = [
289
317
  {
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import axios from "axios";
2
1
  import { OpenAttestationDNSTextRecord, OpenAttestationDNSTextRecordT } from "./records/dnsTxt";
3
2
  import { OpenAttestationDnsDidRecord, OpenAttestationDnsDidRecordT } from "./records/dnsDid";
4
3
  import { getLogger } from "./util/logger";
@@ -26,20 +25,18 @@ export type CustomDnsResolver = (domain: string) => Promise<IDNSQueryResponse>;
26
25
 
27
26
  export const defaultDnsResolvers: CustomDnsResolver[] = [
28
27
  async (domain) => {
29
- const { data } = await axios({
28
+ const data = await fetch(`https://dns.google/resolve?name=${domain}&type=TXT`, {
30
29
  method: "GET",
31
- url: `https://dns.google/resolve?name=${domain}&type=TXT`,
32
30
  });
33
31
 
34
- return data;
32
+ return data.json();
35
33
  },
36
34
  async (domain) => {
37
- const { data } = await axios({
35
+ const data = await fetch(`https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`, {
38
36
  method: "GET",
39
- url: `https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`,
40
37
  headers: { accept: "application/dns-json", contentType: "application/json", connection: "keep-alive" },
41
38
  });
42
- return data;
39
+ return data.json();
43
40
  },
44
41
  ];
45
42
 
@@ -21,6 +21,7 @@ export enum EthereumNetworks {
21
21
  xdcapothem = "51",
22
22
  stabilityTestnet = "20180427",
23
23
  stability = "101010",
24
+ astronTestnet = "21002",
24
25
  astron = "1338",
25
26
  }
26
27
 
@@ -37,6 +38,7 @@ export const EthereumNetworkIdT = Union(
37
38
  Literal(EthereumNetworks.stabilityTestnet),
38
39
  Literal(EthereumNetworks.stability),
39
40
  Literal(EthereumNetworks.local),
41
+ Literal(EthereumNetworks.astronTestnet),
40
42
  Literal(EthereumNetworks.astron)
41
43
  );
42
44