@tradetrust-tt/dnsprove 2.8.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/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2020 Government Technology Agency, Singapore
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # Open Attestation (dnsprove)
2
+
3
+ A helper library to retrieve OpenAttestation DNS-TXT records from domains using Google's public DNS service.
4
+
5
+ A valid OpenAttestation DNS-TXT record looks like:
6
+
7
+ ```js
8
+ [
9
+ {
10
+ name: "example.openattestation.com.",
11
+ type: 16,
12
+ TTL: 110,
13
+ data: '"openatts net=ethereum netId=3 addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"',
14
+ },
15
+ ];
16
+ ```
17
+
18
+ Validation is run on all retrieved records to ensure they conform to the expected format, and records that fail validation will simply be omitted from the returned results.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm i @tradetrust/dnsprove
24
+ ```
25
+
26
+ ***
27
+
28
+ ## Debug
29
+
30
+ To see validation failures run the library with the debug flag turned on, either
31
+
32
+ In Browser:
33
+
34
+ `localStorage.debug="dnsprove*"`
35
+
36
+ In NodeJS:
37
+
38
+ ```sh
39
+ DEBUG="dnsprove*" npm run test
40
+ ```
41
+
42
+ ## Types
43
+
44
+ This library uses [runtypes](https://github.com/pelotom/runtypes) for compile time static type checking as well as run time input validation. The generated documentation below is inaccurate for any Runtypes generated types due to documentation generator limitations.
45
+
46
+ ## API
47
+
48
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
49
+
50
+ #### Table of Contents
51
+
52
+ * [OpenAttestationDNSTextRecord](#openattestationdnstextrecord)
53
+ * [OpenAttestationDnsDidRecord](#openattestationdnsdidrecord)
54
+ * [IDNSRecord](#idnsrecord)
55
+ * [IDNSQueryResponse](#idnsqueryresponse)
56
+ * [CustomDnsResolver](#customdnsresolver)
57
+ * [defaultDnsResolvers](#defaultdnsresolvers)
58
+ * [queryDns](#querydns)
59
+ * [Parameters](#parameters)
60
+ * [parseOpenAttestationRecord](#parseopenattestationrecord)
61
+ * [Parameters](#parameters-1)
62
+ * [parseDocumentStoreResults](#parsedocumentstoreresults)
63
+ * [Parameters](#parameters-2)
64
+ * [parseDnsDidResults](#parsednsdidresults)
65
+ * [Parameters](#parameters-3)
66
+ * [getDocumentStoreRecords](#getdocumentstorerecords)
67
+ * [Parameters](#parameters-4)
68
+ * [Examples](#examples)
69
+ * [getDnsDidRecords](#getdnsdidrecords)
70
+ * [Parameters](#parameters-5)
71
+
72
+ ### OpenAttestationDNSTextRecord
73
+
74
+ ### OpenAttestationDnsDidRecord
75
+
76
+ ### IDNSRecord
77
+
78
+ ### IDNSQueryResponse
79
+
80
+ ### CustomDnsResolver
81
+
82
+ Type: function (domain: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)): [Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[IDNSQueryResponse](#idnsqueryresponse)>
83
+
84
+ ### defaultDnsResolvers
85
+
86
+ Type: [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CustomDnsResolver](#customdnsresolver)>
87
+
88
+ ### queryDns
89
+
90
+ #### Parameters
91
+
92
+ * `domain` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
93
+ * `customDnsResolvers` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CustomDnsResolver](#customdnsresolver)>**
94
+
95
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[IDNSQueryResponse](#idnsqueryresponse)>**
96
+
97
+ ### parseOpenAttestationRecord
98
+
99
+ Parses one openattestation DNS-TXT record and turns it into an OpenAttestationsDNSTextRecord object
100
+
101
+ #### Parameters
102
+
103
+ * `record` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** e.g: '"openatts net=ethereum netId=3 addr=0x0c9d5E6C766030cc6f0f49951D275Ad0701F81EC"'
104
+
105
+ Returns **GenericObject**
106
+
107
+ ### parseDocumentStoreResults
108
+
109
+ Takes a DNS-TXT Record set and returns openattestation document store records if any
110
+
111
+ #### Parameters
112
+
113
+ * `recordSet` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[IDNSRecord](#idnsrecord)>** Refer to tests for examples (optional, default `[]`)
114
+ * `dnssec` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
115
+
116
+ Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[OpenAttestationDNSTextRecord](#openattestationdnstextrecord)>**
117
+
118
+ ### parseDnsDidResults
119
+
120
+ #### Parameters
121
+
122
+ * `recordSet` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[IDNSRecord](#idnsrecord)>** (optional, default `[]`)
123
+ * `dnssec` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
124
+
125
+ Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[OpenAttestationDnsDidRecord](#openattestationdnsdidrecord)>**
126
+
127
+ ### getDocumentStoreRecords
128
+
129
+ Queries a given domain and parses the results to retrieve openattestation document store records if any
130
+
131
+ #### Parameters
132
+
133
+ * `domain` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** e.g: "example.openattestation.com"
134
+ * `customDnsResolvers` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CustomDnsResolver](#customdnsresolver)>?**
135
+
136
+ #### Examples
137
+
138
+ ```javascript
139
+ > getDocumentStoreRecords("example.openattestation.com")
140
+ > [ { type: 'openatts',
141
+ net: 'ethereum',
142
+ netId: '3',
143
+ addr: '0x2f60375e8144e16Adf1979936301D8341D58C36C',
144
+ dnssec: true } ]
145
+ ```
146
+
147
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[OpenAttestationDNSTextRecord](#openattestationdnstextrecord)>>**
148
+
149
+ ### getDnsDidRecords
150
+
151
+ #### Parameters
152
+
153
+ * `domain` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
154
+ * `customDnsResolvers` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[CustomDnsResolver](#customdnsresolver)>?**
155
+
156
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[OpenAttestationDnsDidRecord](#openattestationdnsdidrecord)>>**
157
+
158
+ ## License
159
+
160
+ MIT
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.CodedError = exports.DnsproveStatusCode = void 0;
7
+
8
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+
10
+ let DnsproveStatusCode;
11
+ exports.DnsproveStatusCode = DnsproveStatusCode;
12
+
13
+ (function (DnsproveStatusCode) {
14
+ DnsproveStatusCode[DnsproveStatusCode["IDNS_QUERY_ERROR_GENERAL"] = 0] = "IDNS_QUERY_ERROR_GENERAL";
15
+ })(DnsproveStatusCode || (exports.DnsproveStatusCode = DnsproveStatusCode = {}));
16
+
17
+ class CodedError extends Error {
18
+ constructor(message, code, codeString) {
19
+ super(message);
20
+
21
+ _defineProperty(this, "code", void 0);
22
+
23
+ _defineProperty(this, "codeString", void 0);
24
+
25
+ this.code = code;
26
+ this.codeString = codeString;
27
+ }
28
+
29
+ }
30
+
31
+ exports.CodedError = CodedError;
package/dist/index.js ADDED
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "OpenAttestationDNSTextRecord", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _dnsTxt.OpenAttestationDNSTextRecord;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "OpenAttestationDnsDidRecord", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _dnsDid.OpenAttestationDnsDidRecord;
16
+ }
17
+ });
18
+ exports.getDnsDidRecords = exports.getDocumentStoreRecords = exports.parseDnsDidResults = exports.parseDocumentStoreResults = exports.parseOpenAttestationRecord = exports.queryDns = exports.defaultDnsResolvers = void 0;
19
+
20
+ var _axios = _interopRequireDefault(require("axios"));
21
+
22
+ var _dnsTxt = require("./records/dnsTxt");
23
+
24
+ var _dnsDid = require("./records/dnsDid");
25
+
26
+ var _logger = require("./util/logger");
27
+
28
+ var _error = require("./common/error");
29
+
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+
32
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
33
+
34
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
35
+
36
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
37
+
38
+ function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
39
+
40
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
41
+
42
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
43
+
44
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
45
+
46
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
47
+
48
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
49
+
50
+ 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); } }
51
+
52
+ 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); }); }; }
53
+
54
+ const _getLogger = (0, _logger.getLogger)("index"),
55
+ trace = _getLogger.trace;
56
+
57
+ const defaultDnsResolvers = [/*#__PURE__*/function () {
58
+ var _ref = _asyncToGenerator(function* (domain) {
59
+ const _yield$axios = yield (0, _axios.default)({
60
+ method: "GET",
61
+ url: `https://dns.google/resolve?name=${domain}&type=TXT`
62
+ }),
63
+ data = _yield$axios.data;
64
+
65
+ return data;
66
+ });
67
+
68
+ return function (_x) {
69
+ return _ref.apply(this, arguments);
70
+ };
71
+ }(), /*#__PURE__*/function () {
72
+ var _ref2 = _asyncToGenerator(function* (domain) {
73
+ const _yield$axios2 = yield (0, _axios.default)({
74
+ method: "GET",
75
+ url: `https://cloudflare-dns.com/dns-query?name=${domain}&type=TXT`,
76
+ headers: {
77
+ accept: "application/dns-json",
78
+ contentType: "application/json",
79
+ connection: "keep-alive"
80
+ }
81
+ }),
82
+ data = _yield$axios2.data;
83
+
84
+ return data;
85
+ });
86
+
87
+ return function (_x2) {
88
+ return _ref2.apply(this, arguments);
89
+ };
90
+ }()];
91
+ /**
92
+ * Returns true for strings that are openattestation records
93
+ * @param txtDataString e.g: '"openatts net=ethereum netId=3 addr=0x0c9d5E6C766030cc6f0f49951D275Ad0701F81EC"'
94
+ */
95
+
96
+ exports.defaultDnsResolvers = defaultDnsResolvers;
97
+
98
+ const isOpenAttestationRecord = txtDataString => {
99
+ return txtDataString.startsWith("openatts");
100
+ };
101
+
102
+ const trimValue = str => {
103
+ return str.endsWith(";") ? str.substring(0, str.length - 1).trim() : str.trim();
104
+ };
105
+ /**
106
+ * Takes a string in the format of "key=value" and adds it to a JS object as key: value
107
+ * @param obj Object that will be modified
108
+ * @param keyValuePair A key value pair to add to the given object
109
+ * @example addKeyValuePairToObject(objectToModify, "foo=bar")
110
+ */
111
+
112
+
113
+ const addKeyValuePairToObject = (obj, keyValuePair) => {
114
+ const _keyValuePair$split = keyValuePair.split("="),
115
+ _keyValuePair$split2 = _toArray(_keyValuePair$split),
116
+ key = _keyValuePair$split2[0],
117
+ values = _keyValuePair$split2.slice(1);
118
+
119
+ const value = values.join("="); // in case there were values with = in them
120
+
121
+ /* eslint-disable no-param-reassign */
122
+ // this is necessary because we modify the accumulator in .reduce
123
+
124
+ obj[key.trim()] = trimValue(value);
125
+ return obj;
126
+ };
127
+
128
+ const formatDnsDidRecord = ({
129
+ a,
130
+ v,
131
+ p,
132
+ type
133
+ }) => {
134
+ return {
135
+ type,
136
+ algorithm: a,
137
+ publicKey: p,
138
+ version: v
139
+ };
140
+ };
141
+
142
+ const queryDns = /*#__PURE__*/function () {
143
+ var _ref3 = _asyncToGenerator(function* (domain, customDnsResolvers) {
144
+ let data;
145
+ let i = 0;
146
+
147
+ while (!data && i < customDnsResolvers.length) {
148
+ try {
149
+ const customDnsResolver = customDnsResolvers[i]; // eslint-disable-next-line no-await-in-loop
150
+
151
+ data = yield customDnsResolver(domain);
152
+ } catch (e) {
153
+ i += 1;
154
+ }
155
+ }
156
+
157
+ if (!data) {
158
+ throw new _error.CodedError("Unable to query DNS", _error.DnsproveStatusCode.IDNS_QUERY_ERROR_GENERAL, "IDNS_QUERY_ERROR_GENERAL");
159
+ }
160
+
161
+ return data;
162
+ });
163
+
164
+ return function queryDns(_x3, _x4) {
165
+ return _ref3.apply(this, arguments);
166
+ };
167
+ }();
168
+ /**
169
+ * Parses one openattestation DNS-TXT record and turns it into an OpenAttestationsDNSTextRecord object
170
+ * @param record e.g: '"openatts net=ethereum netId=3 addr=0x0c9d5E6C766030cc6f0f49951D275Ad0701F81EC"'
171
+ */
172
+
173
+
174
+ exports.queryDns = queryDns;
175
+
176
+ const parseOpenAttestationRecord = record => {
177
+ trace(`Parsing record: ${record}`);
178
+ const keyValuePairs = record.trim().split(" "); // tokenize into key=value elements
179
+
180
+ const recordObject = {}; // @ts-ignore: we already checked for this token
181
+
182
+ recordObject.type = keyValuePairs.shift();
183
+ keyValuePairs.reduce(addKeyValuePairToObject, recordObject);
184
+ return recordObject;
185
+ };
186
+ /**
187
+ * Currying function that applies a given dnssec result
188
+ */
189
+
190
+
191
+ exports.parseOpenAttestationRecord = parseOpenAttestationRecord;
192
+
193
+ const applyDnssecResults = dnssecStatus => record => {
194
+ return _objectSpread(_objectSpread({}, record), {}, {
195
+ dnssec: dnssecStatus
196
+ });
197
+ };
198
+ /**
199
+ * Some DNS servers return TXT records with quoted strings, others don't :D
200
+ * @param record
201
+ * @returns unquoted DNS record
202
+ */
203
+
204
+
205
+ const trimDoubleQuotes = record => {
206
+ return record.startsWith('"') ? record.slice(1, -1) : record;
207
+ };
208
+ /**
209
+ * Takes a record set and breaks that info array of key value pairs
210
+ * @param recordSet e.g: [{name: "google.com", type: 16, TTL: 3599, data: '"openatts net=ethereum netId=3 addr=0x2f60375e8144e16Adf1979936301D8341D58C36C"}]
211
+ */
212
+
213
+
214
+ const parseOpenAttestationRecords = (recordSet = []) => {
215
+ trace(`Parsing DNS results: ${JSON.stringify(recordSet)}`);
216
+ return recordSet.map(record => record.data).map(trimDoubleQuotes) // removing leading and trailing quotes if they exist
217
+ .filter(isOpenAttestationRecord).map(parseOpenAttestationRecord);
218
+ };
219
+ /**
220
+ * Takes a DNS-TXT Record set and returns openattestation document store records if any
221
+ * @param recordSet Refer to tests for examples
222
+ */
223
+
224
+
225
+ const parseDocumentStoreResults = (recordSet = [], dnssec) => {
226
+ return parseOpenAttestationRecords(recordSet).reduce((prev, curr) => {
227
+ return _dnsTxt.OpenAttestationDNSTextRecordT.guard(curr) ? [...prev, curr] : prev;
228
+ }, []).map(applyDnssecResults(dnssec));
229
+ };
230
+
231
+ exports.parseDocumentStoreResults = parseDocumentStoreResults;
232
+
233
+ const parseDnsDidResults = (recordSet = [], dnssec) => {
234
+ return parseOpenAttestationRecords(recordSet).map(formatDnsDidRecord).reduce((prev, curr) => {
235
+ return _dnsDid.OpenAttestationDnsDidRecordT.guard(curr) ? [...prev, curr] : prev;
236
+ }, []).map(applyDnssecResults(dnssec));
237
+ };
238
+ /**
239
+ * Queries a given domain and parses the results to retrieve openattestation document store records if any
240
+ * @param domain e.g: "example.openattestation.com"
241
+ * @example
242
+ * > getDocumentStoreRecords("example.openattestation.com")
243
+ * > [ { type: 'openatts',
244
+ net: 'ethereum',
245
+ netId: '3',
246
+ addr: '0x2f60375e8144e16Adf1979936301D8341D58C36C',
247
+ dnssec: true } ]
248
+ */
249
+
250
+
251
+ exports.parseDnsDidResults = parseDnsDidResults;
252
+
253
+ const getDocumentStoreRecords = /*#__PURE__*/function () {
254
+ var _ref4 = _asyncToGenerator(function* (domain, customDnsResolvers) {
255
+ trace(`Received request to resolve ${domain}`);
256
+ const dnsResolvers = customDnsResolvers || defaultDnsResolvers;
257
+ const results = yield queryDns(domain, dnsResolvers);
258
+ const answers = results.Answer || [];
259
+ trace(`Lookup results: ${JSON.stringify(answers)}`);
260
+ return parseDocumentStoreResults(answers, results.AD);
261
+ });
262
+
263
+ return function getDocumentStoreRecords(_x5, _x6) {
264
+ return _ref4.apply(this, arguments);
265
+ };
266
+ }();
267
+
268
+ exports.getDocumentStoreRecords = getDocumentStoreRecords;
269
+
270
+ const getDnsDidRecords = /*#__PURE__*/function () {
271
+ var _ref5 = _asyncToGenerator(function* (domain, customDnsResolvers) {
272
+ trace(`Received request to resolve ${domain}`);
273
+ const dnsResolvers = customDnsResolvers || defaultDnsResolvers;
274
+ const results = yield queryDns(domain, dnsResolvers);
275
+ const answers = results.Answer || [];
276
+ trace(`Lookup results: ${JSON.stringify(answers)}`);
277
+ return parseDnsDidResults(answers, results.AD);
278
+ });
279
+
280
+ return function getDnsDidRecords(_x7, _x8) {
281
+ return _ref5.apply(this, arguments);
282
+ };
283
+ }();
284
+
285
+ exports.getDnsDidRecords = getDnsDidRecords;