@tradetrust-tt/dnsprove 2.12.3 → 2.13.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,7 +16,7 @@ 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"));
19
+ var _index = _interopRequireDefault(require("../node_modules/axios/index"));
20
20
  var _dnsTxt = require("./records/dnsTxt");
21
21
  var _dnsDid = require("./records/dnsDid");
22
22
  var _logger = require("./util/logger");
@@ -39,7 +39,7 @@ const _getLogger = (0, _logger.getLogger)("index"),
39
39
  trace = _getLogger.trace;
40
40
  const defaultDnsResolvers = exports.defaultDnsResolvers = [( /*#__PURE__*/function () {
41
41
  var _ref = _asyncToGenerator(function* (domain) {
42
- const _yield$axios = yield (0, _axios.default)({
42
+ const _yield$axios = yield (0, _index.default)({
43
43
  method: "GET",
44
44
  url: `https://dns.google/resolve?name=${domain}&type=TXT`
45
45
  }),
@@ -51,7 +51,7 @@ const defaultDnsResolvers = exports.defaultDnsResolvers = [( /*#__PURE__*/functi
51
51
  };
52
52
  }()), ( /*#__PURE__*/function () {
53
53
  var _ref2 = _asyncToGenerator(function* (domain) {
54
- const _yield$axios2 = yield (0, _axios.default)({
54
+ const _yield$axios2 = yield (0, _index.default)({
55
55
  method: "GET",
56
56
  url: `https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`,
57
57
  headers: {
@@ -113,6 +113,9 @@ const queryDns = exports.queryDns = /*#__PURE__*/function () {
113
113
  var _ref3 = _asyncToGenerator(function* (domain, customDnsResolvers) {
114
114
  let data;
115
115
  let i = 0;
116
+ if (domain.includes("://")) {
117
+ domain = domain.replace(/(^\w+:|^)\/\//, "");
118
+ }
116
119
  while (!data && i < customDnsResolvers.length) {
117
120
  try {
118
121
  const customDnsResolver = customDnsResolvers[i];
@@ -29,6 +29,8 @@ let EthereumNetworks = exports.EthereumNetworks = void 0;
29
29
  EthereumNetworks["xdcapothem"] = "51";
30
30
  EthereumNetworks["stabilityTestnet"] = "20180427";
31
31
  EthereumNetworks["stability"] = "101010";
32
+ EthereumNetworks["hedera"] = "295";
33
+ EthereumNetworks["hederatestnet"] = "296";
32
34
  })(EthereumNetworks || (exports.EthereumNetworks = EthereumNetworks = {}));
33
35
  let HederaNetworks = exports.HederaNetworks = void 0;
34
36
  (function (HederaNetworks) {
@@ -36,7 +38,7 @@ let HederaNetworks = exports.HederaNetworks = void 0;
36
38
  HederaNetworks["testnet"] = "296";
37
39
  })(HederaNetworks || (exports.HederaNetworks = HederaNetworks = {}));
38
40
  const HederaNetworkIdT = exports.HederaNetworkIdT = (0, _runtypes.Union)((0, _runtypes.Literal)(HederaNetworks.mainnet), (0, _runtypes.Literal)(HederaNetworks.testnet));
39
- 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));
41
+ 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.hedera), (0, _runtypes.Literal)(EthereumNetworks.hederatestnet));
40
42
  const OpenAttestationDNSTextRecordT = exports.OpenAttestationDNSTextRecordT = (0, _runtypes.Union)((0, _runtypes.Record)({
41
43
  type: RecordTypesT,
42
44
  net: (0, _runtypes.Literal)("ethereum"),
@@ -15,18 +15,20 @@ export declare enum EthereumNetworks {
15
15
  xdc = "50",
16
16
  xdcapothem = "51",
17
17
  stabilityTestnet = "20180427",
18
- stability = "101010"
18
+ stability = "101010",
19
+ hedera = "295",
20
+ hederatestnet = "296"
19
21
  }
20
22
  export declare enum HederaNetworks {
21
23
  mainnet = "295",
22
24
  testnet = "296"
23
25
  }
24
26
  export declare const HederaNetworkIdT: Union<[Literal<HederaNetworks.mainnet>, Literal<HederaNetworks.testnet>]>;
25
- 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>]>;
27
+ 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.hedera>, Literal<EthereumNetworks.hederatestnet>]>;
26
28
  export declare const OpenAttestationDNSTextRecordT: Union<[import("runtypes").Intersect<[Record<{
27
29
  type: Literal<"openatts">;
28
30
  net: Literal<"ethereum">;
29
- 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>]>;
31
+ 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.hedera>, Literal<EthereumNetworks.hederatestnet>]>;
30
32
  addr: import("runtypes").Constraint<String, string, unknown>;
31
33
  }, false>, Partial<{
32
34
  dnssec: Boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradetrust-tt/dnsprove",
3
- "version": "2.12.3",
3
+ "version": "2.13.0",
4
4
  "description": "Helper utility for retrieving OpenAttestations document store address records from DNS",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "generator-nod"
46
46
  ],
47
47
  "dependencies": {
48
- "axios": "0.21.1",
48
+ "axios": "1.7.2",
49
49
  "debug": "^4.3.1",
50
50
  "runtypes": "^6.3.0"
51
51
  },
package/src/index.test.ts CHANGED
@@ -172,15 +172,41 @@ describe("queryDns", () => {
172
172
  let server: SetupServerApi;
173
173
 
174
174
  const sampleResponse = {
175
- AD: false,
175
+ Status: 0,
176
+ TC: false,
177
+ RD: true,
178
+ RA: true,
179
+ AD: true,
180
+ CD: false,
181
+ Question: [{ name: "donotuse.openattestation.com.", type: 16 }],
176
182
  Answer: [
177
183
  {
178
- name: "google.com",
184
+ name: "donotuse.openattestation.com.",
179
185
  type: 16,
180
- TTL: 3529,
181
- data: '"docusign=1b0a6754-49b1-4db5-8540-d2c12664b289"',
186
+ TTL: 300,
187
+ data: "openatts a=dns-did; p=did:ethr:0xE712878f6E8d5d4F9e87E10DA604F9cB564C9a89#controller; v=1.0;",
188
+ },
189
+ {
190
+ name: "donotuse.openattestation.com.",
191
+ type: 16,
192
+ TTL: 300,
193
+ data:
194
+ "openatts DO NOT ADD ANY RECORDS BEYOND THIS AS THIS DOMAIN IS USED FOR DNSPROVE NPM LIBRARY INTEGRATION TESTS",
195
+ },
196
+ {
197
+ name: "donotuse.openattestation.com.",
198
+ type: 16,
199
+ TTL: 300,
200
+ data: "openatts fooooooobarrrrrrrrr this entry exists to ensure validation works",
201
+ },
202
+ {
203
+ name: "donotuse.openattestation.com.",
204
+ type: 16,
205
+ TTL: 300,
206
+ data: "openatts net=ethereum netId=3 addr=0x2f60375e8144e16Adf1979936301D8341D58C36C",
182
207
  },
183
208
  ],
209
+ Comment: "Response from 205.251.199.177.",
184
210
  };
185
211
 
186
212
  const testDnsResolvers: CustomDnsResolver[] = [
@@ -216,8 +242,9 @@ describe("queryDns", () => {
216
242
  server = setupServer(...handlers);
217
243
  server.listen();
218
244
 
219
- const records = await queryDns("https://google.com", testDnsResolvers);
220
- expect(sampleResponse).toStrictEqual(records);
245
+ const records = await queryDns("https://donotuse.openattestation.com", testDnsResolvers);
246
+ const sortedAnswer = records?.Answer.sort((a, b) => a.data.localeCompare(b.data));
247
+ expect(sortedAnswer).toStrictEqual(sampleResponse.Answer);
221
248
  });
222
249
 
223
250
  test("Should fallback to second dns when first dns is down", async () => {
@@ -232,9 +259,10 @@ describe("queryDns", () => {
232
259
  server = setupServer(...handlers);
233
260
  server.listen();
234
261
 
235
- const records = await queryDns("https://google.com", testDnsResolvers);
262
+ const records = await queryDns("https://donotuse.openattestation.com", testDnsResolvers);
236
263
 
237
- expect(sampleResponse).toStrictEqual(records);
264
+ const sortedAnswer = records?.Answer.sort((a, b) => a.data.localeCompare(b.data));
265
+ expect(sortedAnswer).toStrictEqual(sampleResponse.Answer);
238
266
  });
239
267
 
240
268
  test("Should throw error when all dns provided are down", async () => {
@@ -249,7 +277,7 @@ describe("queryDns", () => {
249
277
  server = setupServer(...handlers);
250
278
  server.listen();
251
279
  try {
252
- await queryDns("https://google.com", testDnsResolvers);
280
+ await queryDns("https://donotuse.openattestation.com", testDnsResolvers);
253
281
  } catch (e: any) {
254
282
  expect(e.code).toStrictEqual(DnsproveStatusCode.IDNS_QUERY_ERROR_GENERAL);
255
283
  }
@@ -261,35 +289,42 @@ describe("getDocumentStoreRecords for Hedera", () => {
261
289
  {
262
290
  type: "openatts",
263
291
  net: "hedera",
264
- netId: "296",
292
+ netId: "295",
293
+ addr: "0x222B69788e2e9B7FB93a3a0fE258D4604Dc7df21",
265
294
  dnssec: false,
266
- addr: "0x3DE43bfd3D771931E46CbBd4EDE0D3d95C85f81A",
267
295
  },
268
296
  {
297
+ type: "openatts",
298
+ net: "hedera",
299
+ netId: "296",
269
300
  addr: "0x222B69788e2e9B7FB93a3a0fE258D4604Dc7df21",
270
301
  dnssec: false,
271
- net: "hedera",
272
- netId: "295",
273
- type: "openatts",
274
302
  },
275
303
  {
276
- addr: "0xB9cf2eFcBeCdF96E6A7E46AECd79A784B41Bcf6B",
277
- dnssec: false,
304
+ type: "openatts",
278
305
  net: "hedera",
279
306
  netId: "296",
280
- type: "openatts",
307
+ addr: "0x3DE43bfd3D771931E46CbBd4EDE0D3d95C85f81A",
308
+ dnssec: false,
281
309
  },
282
310
  {
283
- addr: "0x222B69788e2e9B7FB93a3a0fE258D4604Dc7df21",
284
- dnssec: false,
311
+ type: "openatts",
285
312
  net: "hedera",
286
313
  netId: "296",
287
- type: "openatts",
314
+ addr: "0xB9cf2eFcBeCdF96E6A7E46AECd79A784B41Bcf6B",
315
+ dnssec: false,
288
316
  },
289
317
  ];
290
318
 
291
319
  test("it should work with trustlv.org", async () => {
292
- const records = await getDocumentStoreRecords("trustlv.org");
320
+ const records = (await getDocumentStoreRecords("trustlv.org")).sort((a, b) => {
321
+ if (a.netId < b.netId) return -1;
322
+ if (a.netId > b.netId) return 1;
323
+ if (a.addr < b.addr) return -1;
324
+ if (a.addr > b.addr) return 1;
325
+ return 0;
326
+ });
327
+
293
328
  expect(records).toStrictEqual(sampleDnsTextRecord);
294
329
  });
295
330
  });
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import axios from "axios";
1
+ import axios from "../node_modules/axios/index";
2
2
  import { OpenAttestationDNSTextRecord, OpenAttestationDNSTextRecordT } from "./records/dnsTxt";
3
3
  import { OpenAttestationDnsDidRecord, OpenAttestationDnsDidRecordT } from "./records/dnsDid";
4
4
  import { getLogger } from "./util/logger";
@@ -85,6 +85,10 @@ export const queryDns = async (domain: string, customDnsResolvers: CustomDnsReso
85
85
 
86
86
  let i = 0;
87
87
 
88
+ if (domain.includes("://")) {
89
+ domain = domain.replace(/(^\w+:|^)\/\//, "");
90
+ }
91
+
88
92
  while (!data && i < customDnsResolvers.length) {
89
93
  try {
90
94
  const customDnsResolver = customDnsResolvers[i];
@@ -26,6 +26,8 @@ export enum EthereumNetworks {
26
26
  xdcapothem = "51",
27
27
  stabilityTestnet = "20180427",
28
28
  stability = "101010",
29
+ hedera = "295",
30
+ hederatestnet = "296",
29
31
  }
30
32
 
31
33
  export enum HederaNetworks {
@@ -46,7 +48,9 @@ export const EthereumNetworkIdT = Union(
46
48
  Literal(EthereumNetworks.xdcapothem),
47
49
  Literal(EthereumNetworks.stabilityTestnet),
48
50
  Literal(EthereumNetworks.stability),
49
- Literal(EthereumNetworks.local)
51
+ Literal(EthereumNetworks.local),
52
+ Literal(EthereumNetworks.hedera),
53
+ Literal(EthereumNetworks.hederatestnet)
50
54
  );
51
55
 
52
56
  export const OpenAttestationDNSTextRecordT = Union(