@tradetrust-tt/dnsprove 2.19.0 → 2.21.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
@@ -58,7 +58,7 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
58
58
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
59
59
  const _getLogger = (0, _logger.getLogger)("index"),
60
60
  trace = _getLogger.trace;
61
- const defaultDnsResolvers = exports.defaultDnsResolvers = [_dnsResolvers.googleDnsResolver, _dnsResolvers.cloudflareDnsResolver, _dnsResolvers.aliDnsResolver];
61
+ const defaultDnsResolvers = exports.defaultDnsResolvers = [_dnsResolvers.googleDnsResolver, _dnsResolvers.cloudflareDnsResolver, _dnsResolvers.proxyDnsResolver, _dnsResolvers.aliDnsResolver];
62
62
 
63
63
  /**
64
64
  * Returns true for strings that are openattestation records
@@ -3,31 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.RecordTypesT = exports.OpenAttestationDNSTextRecordT = exports.EthereumNetworks = exports.EthereumNetworkIdT = exports.EthereumAddressT = exports.BlockchainNetworkT = void 0;
6
+ exports.RecordTypesT = exports.OpenAttestationDNSTextRecordT = exports.EthereumNetworkIdT = exports.EthereumAddressT = exports.BlockchainNetworkT = void 0;
7
7
  var _runtypes = require("runtypes");
8
8
  const RecordTypesT = exports.RecordTypesT = (0, _runtypes.Literal)("openatts");
9
9
  const BlockchainNetworkT = exports.BlockchainNetworkT = (0, _runtypes.Literal)("ethereum");
10
10
  const EthereumAddressT = exports.EthereumAddressT = _runtypes.String.withConstraint(maybeAddress => {
11
11
  return /0x[a-fA-F0-9]{40}/.test(maybeAddress) || `${maybeAddress} is not a valid ethereum address`;
12
12
  });
13
- let EthereumNetworks = exports.EthereumNetworks = void 0;
14
- (function (EthereumNetworks) {
15
- EthereumNetworks["homestead"] = "1";
16
- EthereumNetworks["ropsten"] = "3";
17
- EthereumNetworks["rinkeby"] = "4";
18
- EthereumNetworks["goerli"] = "5";
19
- EthereumNetworks["sepolia"] = "11155111";
20
- EthereumNetworks["polygon"] = "137";
21
- EthereumNetworks["polygonAmoy"] = "80002";
22
- EthereumNetworks["local"] = "1337";
23
- EthereumNetworks["xdc"] = "50";
24
- EthereumNetworks["xdcapothem"] = "51";
25
- EthereumNetworks["stabilityTestnet"] = "20180427";
26
- EthereumNetworks["stability"] = "101010";
27
- EthereumNetworks["astronTestnet"] = "21002";
28
- EthereumNetworks["astron"] = "1338";
29
- })(EthereumNetworks || (exports.EthereumNetworks = EthereumNetworks = {}));
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));
13
+ const EthereumNetworkIdT = exports.EthereumNetworkIdT = _runtypes.String.withConstraint(maybeNetId => /^\d+$/.test(maybeNetId) || `${maybeNetId} is not a valid numeric network id`);
31
14
  const OpenAttestationDNSTextRecordT = exports.OpenAttestationDNSTextRecordT = (0, _runtypes.Record)({
32
15
  type: RecordTypesT,
33
16
  net: BlockchainNetworkT,
@@ -1,28 +1,12 @@
1
- import { Static, Boolean, String, Literal, Record, Union, Partial } from "runtypes";
1
+ import { Static, Boolean, String, Literal, Record, Partial } from "runtypes";
2
2
  export declare const RecordTypesT: Literal<"openatts">;
3
3
  export declare const BlockchainNetworkT: Literal<"ethereum">;
4
4
  export declare const EthereumAddressT: import("runtypes").Constraint<String, string, unknown>;
5
- export declare enum EthereumNetworks {
6
- homestead = "1",
7
- ropsten = "3",
8
- rinkeby = "4",
9
- goerli = "5",
10
- sepolia = "11155111",
11
- polygon = "137",
12
- polygonAmoy = "80002",
13
- local = "1337",
14
- xdc = "50",
15
- xdcapothem = "51",
16
- stabilityTestnet = "20180427",
17
- stability = "101010",
18
- astronTestnet = "21002",
19
- astron = "1338"
20
- }
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>]>;
5
+ export declare const EthereumNetworkIdT: import("runtypes").Constraint<String, string, unknown>;
22
6
  export declare const OpenAttestationDNSTextRecordT: import("runtypes").Intersect<[Record<{
23
7
  type: Literal<"openatts">;
24
8
  net: Literal<"ethereum">;
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>]>;
9
+ netId: import("runtypes").Constraint<String, string, unknown>;
26
10
  addr: import("runtypes").Constraint<String, string, unknown>;
27
11
  }, false>, Partial<{
28
12
  dnssec: Boolean;
@@ -1,3 +1,4 @@
1
1
  export * from "./google-dns-resolver";
2
2
  export * from "./cloudflare-dns-resolver";
3
3
  export * from "./ali-dns-resolver";
4
+ export * from "./proxy-dns-resolver";
@@ -0,0 +1,3 @@
1
+ import type { CustomDnsResolver } from "../..";
2
+ /** Server-side DoH proxy that forwards to Google/Cloudflare upstream — reachable from regions where direct access to those endpoints is blocked. */
3
+ export declare const proxyDnsResolver: CustomDnsResolver;
@@ -35,4 +35,15 @@ Object.keys(_aliDnsResolver).forEach(function (key) {
35
35
  return _aliDnsResolver[key];
36
36
  }
37
37
  });
38
+ });
39
+ var _proxyDnsResolver = require("./proxy-dns-resolver");
40
+ Object.keys(_proxyDnsResolver).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _proxyDnsResolver[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _proxyDnsResolver[key];
47
+ }
48
+ });
38
49
  });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.proxyDnsResolver = void 0;
7
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
+ /** Server-side DoH proxy that forwards to Google/Cloudflare upstream — reachable from regions where direct access to those endpoints is blocked. */
10
+ const proxyDnsResolver = exports.proxyDnsResolver = /*#__PURE__*/function () {
11
+ var _ref = _asyncToGenerator(function* (domain) {
12
+ const url = new URL("https://dns.opencerts.io/resolve");
13
+ if (!domain) {
14
+ throw new Error("Domain is required");
15
+ }
16
+ url.searchParams.set("name", domain);
17
+ url.searchParams.set("type", "TXT");
18
+ const res = yield fetch(url);
19
+ if (!res.ok) {
20
+ throw new Error(`Proxy DNS request failed: HTTP ${res.status}`);
21
+ }
22
+ let data;
23
+ try {
24
+ data = yield res.json();
25
+ } catch (_unused) {
26
+ throw new Error("Failed to parse DNS response JSON");
27
+ }
28
+ return data;
29
+ });
30
+ return function proxyDnsResolver(_x) {
31
+ return _ref.apply(this, arguments);
32
+ };
33
+ }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradetrust-tt/dnsprove",
3
- "version": "2.19.0",
3
+ "version": "2.21.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
@@ -173,6 +173,76 @@ describe("parseDocumentStoreResults", () => {
173
173
  ];
174
174
  expect(parseDocumentStoreResults(sampleRecord, true)).toStrictEqual([]);
175
175
  });
176
+
177
+ test("it should accept any numeric netId (e.g. Mantle mainnet 5000)", () => {
178
+ const addr = "0x2f60375e8144e16Adf1979936301D8341D58C36C";
179
+ const sampleRecord = [
180
+ {
181
+ name: "example.example.com.",
182
+ type: 16,
183
+ TTL: 110,
184
+ data: `"openatts net=ethereum netId=5000 addr=${addr}"`,
185
+ dnssec: false,
186
+ },
187
+ ];
188
+ expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([
189
+ {
190
+ type: "openatts",
191
+ net: "ethereum",
192
+ netId: "5000",
193
+ addr,
194
+ dnssec: false,
195
+ },
196
+ ]);
197
+ });
198
+
199
+ test("it should accept an arbitrary previously-unknown numeric netId", () => {
200
+ const addr = "0x2f60375e8144e16Adf1979936301D8341D58C36C";
201
+ const sampleRecord = [
202
+ {
203
+ name: "example.example.com.",
204
+ type: 16,
205
+ TTL: 110,
206
+ data: `"openatts net=ethereum netId=99999 addr=${addr}"`,
207
+ dnssec: false,
208
+ },
209
+ ];
210
+ expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([
211
+ {
212
+ type: "openatts",
213
+ net: "ethereum",
214
+ netId: "99999",
215
+ addr,
216
+ dnssec: false,
217
+ },
218
+ ]);
219
+ });
220
+
221
+ test("it should reject a non-numeric netId", () => {
222
+ const sampleRecord = [
223
+ {
224
+ name: "example.example.com.",
225
+ type: 16,
226
+ TTL: 110,
227
+ data: '"openatts net=ethereum netId=abc addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"',
228
+ dnssec: false,
229
+ },
230
+ ];
231
+ expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([]);
232
+ });
233
+
234
+ test("it should reject an alphanumeric netId", () => {
235
+ const sampleRecord = [
236
+ {
237
+ name: "example.example.com.",
238
+ type: 16,
239
+ TTL: 110,
240
+ data: '"openatts net=ethereum netId=1abc addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"',
241
+ dnssec: false,
242
+ },
243
+ ];
244
+ expect(parseDocumentStoreResults(sampleRecord, false)).toStrictEqual([]);
245
+ });
176
246
  });
177
247
 
178
248
  describe("queryDns", () => {
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import { OpenAttestationDNSTextRecord, OpenAttestationDNSTextRecordT } from "./r
2
2
  import { OpenAttestationDnsDidRecord, OpenAttestationDnsDidRecordT } from "./records/dnsDid";
3
3
  import { getLogger } from "./util/logger";
4
4
  import { CodedError, DnsproveStatusCode } from "./common/error";
5
- import { aliDnsResolver, cloudflareDnsResolver, googleDnsResolver } from "./util/dns-resolvers";
5
+ import { aliDnsResolver, cloudflareDnsResolver, googleDnsResolver, proxyDnsResolver } from "./util/dns-resolvers";
6
6
 
7
7
  const { trace } = getLogger("index");
8
8
 
@@ -24,7 +24,12 @@ interface GenericObject {
24
24
 
25
25
  export type CustomDnsResolver = (domain: string) => Promise<IDNSQueryResponse>;
26
26
 
27
- export const defaultDnsResolvers: CustomDnsResolver[] = [googleDnsResolver, cloudflareDnsResolver, aliDnsResolver];
27
+ export const defaultDnsResolvers: CustomDnsResolver[] = [
28
+ googleDnsResolver,
29
+ cloudflareDnsResolver,
30
+ proxyDnsResolver,
31
+ aliDnsResolver,
32
+ ];
28
33
 
29
34
  /**
30
35
  * Returns true for strings that are openattestation records
@@ -1,4 +1,4 @@
1
- import { Static, Boolean, String, Literal, Record, Union, Partial } from "runtypes";
1
+ import { Static, Boolean, String, Literal, Record, Partial } from "runtypes";
2
2
 
3
3
  export const RecordTypesT = Literal("openatts");
4
4
 
@@ -8,38 +8,8 @@ export const EthereumAddressT = String.withConstraint((maybeAddress: string) =>
8
8
  return /0x[a-fA-F0-9]{40}/.test(maybeAddress) || `${maybeAddress} is not a valid ethereum address`;
9
9
  });
10
10
 
11
- export enum EthereumNetworks {
12
- homestead = "1",
13
- ropsten = "3",
14
- rinkeby = "4",
15
- goerli = "5",
16
- sepolia = "11155111",
17
- polygon = "137",
18
- polygonAmoy = "80002",
19
- local = "1337",
20
- xdc = "50",
21
- xdcapothem = "51",
22
- stabilityTestnet = "20180427",
23
- stability = "101010",
24
- astronTestnet = "21002",
25
- astron = "1338",
26
- }
27
-
28
- export const EthereumNetworkIdT = Union(
29
- Literal(EthereumNetworks.homestead),
30
- Literal(EthereumNetworks.ropsten),
31
- Literal(EthereumNetworks.rinkeby),
32
- Literal(EthereumNetworks.goerli),
33
- Literal(EthereumNetworks.sepolia),
34
- Literal(EthereumNetworks.polygon),
35
- Literal(EthereumNetworks.polygonAmoy),
36
- Literal(EthereumNetworks.xdc),
37
- Literal(EthereumNetworks.xdcapothem),
38
- Literal(EthereumNetworks.stabilityTestnet),
39
- Literal(EthereumNetworks.stability),
40
- Literal(EthereumNetworks.local),
41
- Literal(EthereumNetworks.astronTestnet),
42
- Literal(EthereumNetworks.astron)
11
+ export const EthereumNetworkIdT = String.withConstraint(
12
+ (maybeNetId: string) => /^\d+$/.test(maybeNetId) || `${maybeNetId} is not a valid numeric network id`
43
13
  );
44
14
 
45
15
  export const OpenAttestationDNSTextRecordT = Record({
@@ -3,6 +3,7 @@ import { http, HttpResponse } from "msw";
3
3
  import { aliDnsResolver } from "./ali-dns-resolver";
4
4
  import { cloudflareDnsResolver } from "./cloudflare-dns-resolver";
5
5
  import { googleDnsResolver } from "./google-dns-resolver";
6
+ import { proxyDnsResolver } from "./proxy-dns-resolver";
6
7
 
7
8
  const emptyDnsJson = {
8
9
  Status: 0,
@@ -118,3 +119,37 @@ describe("aliDnsResolver", () => {
118
119
  await expect(aliDnsResolver("")).rejects.toThrow("Domain is required");
119
120
  });
120
121
  });
122
+
123
+ describe("proxyDnsResolver", () => {
124
+ let server: SetupServerApi | undefined;
125
+
126
+ afterEach(() => {
127
+ server?.close();
128
+ });
129
+
130
+ test("requests proxy DNS JSON with name, TXT type, and encoded query", async () => {
131
+ server = setupServer(
132
+ http.get("https://dns.opencerts.io/resolve", ({ request }) => {
133
+ const url = new URL(request.url);
134
+ expect(url.searchParams.get("name")).toBe("oc example.test");
135
+ expect(url.searchParams.get("type")).toBe("TXT");
136
+ return HttpResponse.json(emptyDnsJson);
137
+ })
138
+ );
139
+ server.listen();
140
+
141
+ const out = await proxyDnsResolver("oc example.test");
142
+ expect(out).toMatchObject({ Status: 0, Answer: [] });
143
+ });
144
+
145
+ test("throws when proxy DNS returns non-2xx", async () => {
146
+ server = setupServer(http.get("https://dns.opencerts.io/resolve", () => new HttpResponse(null, { status: 502 })));
147
+ server.listen();
148
+
149
+ await expect(proxyDnsResolver("oc.example.test")).rejects.toThrow(/HTTP 502/);
150
+ });
151
+
152
+ test("throws when domain is empty", async () => {
153
+ await expect(proxyDnsResolver("")).rejects.toThrow("Domain is required");
154
+ });
155
+ });
@@ -1,3 +1,4 @@
1
1
  export * from "./google-dns-resolver";
2
2
  export * from "./cloudflare-dns-resolver";
3
3
  export * from "./ali-dns-resolver";
4
+ export * from "./proxy-dns-resolver";
@@ -0,0 +1,28 @@
1
+ import type { CustomDnsResolver, IDNSQueryResponse } from "../..";
2
+
3
+ /** Server-side DoH proxy that forwards to Google/Cloudflare upstream — reachable from regions where direct access to those endpoints is blocked. */
4
+ export const proxyDnsResolver: CustomDnsResolver = async (domain) => {
5
+ const url = new URL("https://dns.opencerts.io/resolve");
6
+
7
+ if (!domain) {
8
+ throw new Error("Domain is required");
9
+ }
10
+
11
+ url.searchParams.set("name", domain);
12
+ url.searchParams.set("type", "TXT");
13
+
14
+ const res = await fetch(url);
15
+
16
+ if (!res.ok) {
17
+ throw new Error(`Proxy DNS request failed: HTTP ${res.status}`);
18
+ }
19
+
20
+ let data;
21
+ try {
22
+ data = await res.json();
23
+ } catch {
24
+ throw new Error("Failed to parse DNS response JSON");
25
+ }
26
+
27
+ return data as IDNSQueryResponse;
28
+ };