@reclaimprotocol/attestor-core 5.0.1-beta.2 → 5.0.1-beta.22

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.
Files changed (145) hide show
  1. package/browser/resources/attestor-browser.min.mjs +4512 -0
  2. package/lib/avs/abis/avsDirectoryABI.js +338 -341
  3. package/lib/avs/abis/delegationABI.js +1 -4
  4. package/lib/avs/abis/registryABI.js +719 -722
  5. package/lib/avs/client/create-claim-on-avs.js +129 -157
  6. package/lib/avs/config.js +18 -24
  7. package/lib/avs/contracts/ReclaimServiceManager.js +1 -0
  8. package/lib/avs/contracts/common.js +1 -0
  9. package/lib/avs/contracts/factories/ReclaimServiceManager__factory.js +1139 -1156
  10. package/lib/avs/contracts/factories/index.js +4 -4
  11. package/lib/avs/contracts/index.js +2 -6
  12. package/lib/avs/types/index.js +1 -0
  13. package/lib/avs/utils/contracts.js +30 -50
  14. package/lib/avs/utils/register.js +75 -70
  15. package/lib/avs/utils/tasks.js +38 -45
  16. package/lib/client/create-claim.js +402 -431
  17. package/lib/client/tunnels/make-rpc-tcp-tunnel.js +46 -48
  18. package/lib/client/tunnels/make-rpc-tls-tunnel.js +125 -121
  19. package/lib/client/utils/attestor-pool.js +23 -22
  20. package/lib/client/utils/client-socket.js +86 -109
  21. package/lib/client/utils/message-handler.js +79 -89
  22. package/lib/config/index.js +40 -58
  23. package/lib/external-rpc/benchmark.js +61 -74
  24. package/lib/external-rpc/event-bus.js +12 -15
  25. package/lib/external-rpc/handle-incoming-msg.js +216 -225
  26. package/lib/external-rpc/jsc-polyfills/1.js +70 -68
  27. package/lib/external-rpc/jsc-polyfills/2.js +17 -12
  28. package/lib/external-rpc/jsc-polyfills/event.js +10 -15
  29. package/lib/external-rpc/jsc-polyfills/index.js +2 -2
  30. package/lib/external-rpc/jsc-polyfills/ws.js +77 -79
  31. package/lib/external-rpc/setup-browser.js +28 -28
  32. package/lib/external-rpc/setup-jsc.js +17 -17
  33. package/lib/external-rpc/types.js +1 -0
  34. package/lib/external-rpc/utils.js +89 -89
  35. package/lib/external-rpc/zk.js +55 -50
  36. package/lib/index.js +2 -6
  37. package/lib/mechain/abis/governanceABI.js +457 -460
  38. package/lib/mechain/abis/taskABI.js +502 -505
  39. package/lib/mechain/client/create-claim-on-mechain.js +24 -29
  40. package/lib/mechain/constants/index.js +3 -8
  41. package/lib/mechain/types/index.js +1 -0
  42. package/lib/proto/api.js +4200 -4087
  43. package/lib/proto/tee-bundle.js +1261 -1241
  44. package/lib/providers/http/index.js +616 -603
  45. package/lib/providers/http/patch-parse5-tree.js +27 -29
  46. package/lib/providers/http/utils.js +289 -248
  47. package/lib/providers/index.js +3 -6
  48. package/lib/server/create-server.js +89 -91
  49. package/lib/server/handlers/claimTeeBundle.js +231 -211
  50. package/lib/server/handlers/claimTunnel.js +66 -73
  51. package/lib/server/handlers/completeClaimOnChain.js +20 -25
  52. package/lib/server/handlers/createClaimOnChain.js +21 -27
  53. package/lib/server/handlers/createTaskOnMechain.js +40 -50
  54. package/lib/server/handlers/createTunnel.js +85 -90
  55. package/lib/server/handlers/disconnectTunnel.js +4 -7
  56. package/lib/server/handlers/fetchCertificateBytes.js +37 -53
  57. package/lib/server/handlers/index.js +21 -24
  58. package/lib/server/handlers/init.js +27 -28
  59. package/lib/server/handlers/toprf.js +13 -16
  60. package/lib/server/socket.js +97 -100
  61. package/lib/server/tunnels/make-tcp-tunnel.js +161 -186
  62. package/lib/server/utils/apm.js +32 -25
  63. package/lib/server/utils/assert-valid-claim-request.js +305 -334
  64. package/lib/server/utils/config-env.js +2 -2
  65. package/lib/server/utils/dns.js +12 -18
  66. package/lib/server/utils/gcp-attestation.js +233 -181
  67. package/lib/server/utils/generics.d.ts +1 -1
  68. package/lib/server/utils/generics.js +43 -37
  69. package/lib/server/utils/iso.js +253 -256
  70. package/lib/server/utils/keep-alive.js +36 -36
  71. package/lib/server/utils/nitro-attestation.js +295 -220
  72. package/lib/server/utils/oprf-raw.js +48 -55
  73. package/lib/server/utils/process-handshake.js +200 -218
  74. package/lib/server/utils/proxy-session.js +5 -5
  75. package/lib/server/utils/tee-oprf-mpc-verification.js +82 -78
  76. package/lib/server/utils/tee-oprf-verification.js +165 -142
  77. package/lib/server/utils/tee-transcript-reconstruction.js +176 -129
  78. package/lib/server/utils/tee-verification.js +397 -334
  79. package/lib/server/utils/validation.js +30 -37
  80. package/lib/types/bgp.js +1 -0
  81. package/lib/types/claims.js +1 -0
  82. package/lib/types/client.js +1 -0
  83. package/lib/types/general.js +1 -0
  84. package/lib/types/handlers.js +1 -0
  85. package/lib/types/providers.d.ts +3 -2
  86. package/lib/types/providers.gen.js +9 -15
  87. package/lib/types/providers.js +1 -0
  88. package/lib/types/rpc.js +1 -0
  89. package/lib/types/signatures.d.ts +1 -2
  90. package/lib/types/signatures.js +1 -0
  91. package/lib/types/tunnel.js +1 -0
  92. package/lib/types/zk.js +1 -0
  93. package/lib/utils/auth.js +54 -66
  94. package/lib/utils/b64-json.js +15 -15
  95. package/lib/utils/bgp-listener.js +107 -111
  96. package/lib/utils/claims.js +89 -80
  97. package/lib/utils/env.js +13 -17
  98. package/lib/utils/error.js +43 -47
  99. package/lib/utils/generics.js +284 -235
  100. package/lib/utils/http-parser.js +232 -187
  101. package/lib/utils/logger.js +80 -71
  102. package/lib/utils/prepare-packets.js +69 -67
  103. package/lib/utils/redactions.js +163 -121
  104. package/lib/utils/retries.js +22 -24
  105. package/lib/utils/signatures/eth.js +29 -28
  106. package/lib/utils/signatures/index.js +5 -10
  107. package/lib/utils/socket-base.js +84 -88
  108. package/lib/utils/tls.js +28 -28
  109. package/lib/utils/ws.js +19 -19
  110. package/lib/utils/zk.js +542 -582
  111. package/package.json +12 -5
  112. package/lib/external-rpc/global.d.js +0 -0
  113. package/lib/scripts/build-browser.d.ts +0 -1
  114. package/lib/scripts/build-jsc.d.ts +0 -1
  115. package/lib/scripts/build-lib.d.ts +0 -1
  116. package/lib/scripts/check-avs-registration.d.ts +0 -1
  117. package/lib/scripts/check-avs-registration.js +0 -28
  118. package/lib/scripts/fallbacks/crypto.d.ts +0 -1
  119. package/lib/scripts/fallbacks/crypto.js +0 -4
  120. package/lib/scripts/fallbacks/empty.d.ts +0 -3
  121. package/lib/scripts/fallbacks/empty.js +0 -4
  122. package/lib/scripts/fallbacks/re2.d.ts +0 -1
  123. package/lib/scripts/fallbacks/re2.js +0 -7
  124. package/lib/scripts/fallbacks/snarkjs.d.ts +0 -1
  125. package/lib/scripts/fallbacks/snarkjs.js +0 -10
  126. package/lib/scripts/fallbacks/stwo.d.ts +0 -6
  127. package/lib/scripts/fallbacks/stwo.js +0 -159
  128. package/lib/scripts/generate-provider-types.d.ts +0 -5
  129. package/lib/scripts/generate-provider-types.js +0 -101
  130. package/lib/scripts/generate-receipt.d.ts +0 -9
  131. package/lib/scripts/generate-receipt.js +0 -101
  132. package/lib/scripts/generate-toprf-keys.d.ts +0 -1
  133. package/lib/scripts/generate-toprf-keys.js +0 -24
  134. package/lib/scripts/jsc-cli-rpc.d.ts +0 -1
  135. package/lib/scripts/jsc-cli-rpc.js +0 -35
  136. package/lib/scripts/register-avs-operator.d.ts +0 -1
  137. package/lib/scripts/register-avs-operator.js +0 -3
  138. package/lib/scripts/start-server.d.ts +0 -1
  139. package/lib/scripts/start-server.js +0 -11
  140. package/lib/scripts/update-avs-metadata.d.ts +0 -1
  141. package/lib/scripts/update-avs-metadata.js +0 -20
  142. package/lib/scripts/utils.d.ts +0 -1
  143. package/lib/scripts/utils.js +0 -10
  144. package/lib/scripts/whitelist-operator.d.ts +0 -1
  145. package/lib/scripts/whitelist-operator.js +0 -16
@@ -1,259 +1,256 @@
1
1
  const countries = {
2
- AF: "Afghanistan",
3
- AX: "\xC5land Islands",
4
- AL: "Albania",
5
- DZ: "Algeria",
6
- AS: "American Samoa",
7
- AD: "Andorra",
8
- AO: "Angola",
9
- AI: "Anguilla",
10
- AQ: "Antarctica",
11
- AG: "Antigua and Barbuda",
12
- AR: "Argentina",
13
- AM: "Armenia",
14
- AW: "Aruba",
15
- AU: "Australia",
16
- AT: "Austria",
17
- AZ: "Azerbaijan",
18
- BS: "Bahamas",
19
- BH: "Bahrain",
20
- BD: "Bangladesh",
21
- BB: "Barbados",
22
- BY: "Belarus",
23
- BE: "Belgium",
24
- BZ: "Belize",
25
- BJ: "Benin",
26
- BM: "Bermuda",
27
- BT: "Bhutan",
28
- BO: "Bolivia, Plurinational State of",
29
- BQ: "Bonaire, Sint Eustatius and Saba",
30
- BA: "Bosnia and Herzegovina",
31
- BW: "Botswana",
32
- BV: "Bouvet Island",
33
- BR: "Brazil",
34
- IO: "British Indian Ocean Territory",
35
- BN: "Brunei Darussalam",
36
- BG: "Bulgaria",
37
- BF: "Burkina Faso",
38
- BI: "Burundi",
39
- KH: "Cambodia",
40
- CM: "Cameroon",
41
- CA: "Canada",
42
- CV: "Cape Verde",
43
- KY: "Cayman Islands",
44
- CF: "Central African Republic",
45
- TD: "Chad",
46
- CL: "Chile",
47
- CN: "China",
48
- CX: "Christmas Island",
49
- CC: "Cocos (Keeling) Islands",
50
- CO: "Colombia",
51
- KM: "Comoros",
52
- CG: "Congo",
53
- CD: "Congo, the Democratic Republic of the",
54
- CK: "Cook Islands",
55
- CR: "Costa Rica",
56
- CI: "C\xF4te d'Ivoire",
57
- HR: "Croatia",
58
- CU: "Cuba",
59
- CW: "Cura\xE7ao",
60
- CY: "Cyprus",
61
- CZ: "Czech Republic",
62
- DK: "Denmark",
63
- DJ: "Djibouti",
64
- DM: "Dominica",
65
- DO: "Dominican Republic",
66
- EC: "Ecuador",
67
- EG: "Egypt",
68
- SV: "El Salvador",
69
- GQ: "Equatorial Guinea",
70
- ER: "Eritrea",
71
- EE: "Estonia",
72
- ET: "Ethiopia",
73
- FK: "Falkland Islands (Malvinas)",
74
- FO: "Faroe Islands",
75
- FJ: "Fiji",
76
- FI: "Finland",
77
- FR: "France",
78
- GF: "French Guiana",
79
- PF: "French Polynesia",
80
- TF: "French Southern Territories",
81
- GA: "Gabon",
82
- GM: "Gambia",
83
- GE: "Georgia",
84
- DE: "Germany",
85
- GH: "Ghana",
86
- GI: "Gibraltar",
87
- GR: "Greece",
88
- GL: "Greenland",
89
- GD: "Grenada",
90
- GP: "Guadeloupe",
91
- GU: "Guam",
92
- GT: "Guatemala",
93
- GG: "Guernsey",
94
- GN: "Guinea",
95
- GW: "Guinea-Bissau",
96
- GY: "Guyana",
97
- HT: "Haiti",
98
- HM: "Heard Island and McDonald Mcdonald Islands",
99
- VA: "Holy See (Vatican City State)",
100
- HN: "Honduras",
101
- HK: "Hong Kong",
102
- HU: "Hungary",
103
- IS: "Iceland",
104
- IN: "India",
105
- ID: "Indonesia",
106
- IR: "Iran, Islamic Republic of",
107
- IQ: "Iraq",
108
- IE: "Ireland",
109
- IM: "Isle of Man",
110
- IL: "Israel",
111
- IT: "Italy",
112
- JM: "Jamaica",
113
- JP: "Japan",
114
- JE: "Jersey",
115
- JO: "Jordan",
116
- KZ: "Kazakhstan",
117
- KE: "Kenya",
118
- KI: "Kiribati",
119
- XK: "Kosovo",
120
- KP: "Korea, Democratic People's Republic of",
121
- KR: "Korea, Republic of",
122
- KW: "Kuwait",
123
- KG: "Kyrgyzstan",
124
- LA: "Lao People's Democratic Republic",
125
- LV: "Latvia",
126
- LB: "Lebanon",
127
- LS: "Lesotho",
128
- LR: "Liberia",
129
- LY: "Libya",
130
- LI: "Liechtenstein",
131
- LT: "Lithuania",
132
- LU: "Luxembourg",
133
- MO: "Macao",
134
- MK: "North Macedonia",
135
- MG: "Madagascar",
136
- MW: "Malawi",
137
- MY: "Malaysia",
138
- MV: "Maldives",
139
- ML: "Mali",
140
- MT: "Malta",
141
- MH: "Marshall Islands",
142
- MQ: "Martinique",
143
- MR: "Mauritania",
144
- MU: "Mauritius",
145
- YT: "Mayotte",
146
- MX: "Mexico",
147
- FM: "Micronesia, Federated States of",
148
- MD: "Moldova, Republic of",
149
- MC: "Monaco",
150
- MN: "Mongolia",
151
- ME: "Montenegro",
152
- MS: "Montserrat",
153
- MA: "Morocco",
154
- MZ: "Mozambique",
155
- MM: "Myanmar",
156
- NA: "Namibia",
157
- NR: "Nauru",
158
- NP: "Nepal",
159
- NL: "Netherlands",
160
- AN: "Netherlands Antilles",
161
- NC: "New Caledonia",
162
- NZ: "New Zealand",
163
- NI: "Nicaragua",
164
- NE: "Niger",
165
- NG: "Nigeria",
166
- NU: "Niue",
167
- NF: "Norfolk Island",
168
- MP: "Northern Mariana Islands",
169
- NO: "Norway",
170
- OM: "Oman",
171
- PK: "Pakistan",
172
- PW: "Palau",
173
- PS: "Palestine, State of",
174
- PA: "Panama",
175
- PG: "Papua New Guinea",
176
- PY: "Paraguay",
177
- PE: "Peru",
178
- PH: "Philippines",
179
- PN: "Pitcairn",
180
- PL: "Poland",
181
- PT: "Portugal",
182
- PR: "Puerto Rico",
183
- QA: "Qatar",
184
- RE: "R\xE9union",
185
- RO: "Romania",
186
- RU: "Russian Federation",
187
- RW: "Rwanda",
188
- BL: "Saint Barth\xE9lemy",
189
- SH: "Saint Helena, Ascension and Tristan da Cunha",
190
- KN: "Saint Kitts and Nevis",
191
- LC: "Saint Lucia",
192
- MF: "Saint Martin (French part)",
193
- PM: "Saint Pierre and Miquelon",
194
- VC: "Saint Vincent and the Grenadines",
195
- WS: "Samoa",
196
- SM: "San Marino",
197
- ST: "Sao Tome and Principe",
198
- SA: "Saudi Arabia",
199
- SN: "Senegal",
200
- RS: "Serbia",
201
- SC: "Seychelles",
202
- SL: "Sierra Leone",
203
- SG: "Singapore",
204
- SX: "Sint Maarten (Dutch part)",
205
- SK: "Slovakia",
206
- SI: "Slovenia",
207
- SB: "Solomon Islands",
208
- SO: "Somalia",
209
- ZA: "South Africa",
210
- GS: "South Georgia and the South Sandwich Islands",
211
- SS: "South Sudan",
212
- ES: "Spain",
213
- LK: "Sri Lanka",
214
- SD: "Sudan",
215
- SR: "Suriname",
216
- SJ: "Svalbard and Jan Mayen",
217
- SZ: "Swaziland",
218
- SE: "Sweden",
219
- CH: "Switzerland",
220
- SY: "Syrian Arab Republic",
221
- TW: "Taiwan, Province of China",
222
- TJ: "Tajikistan",
223
- TZ: "Tanzania, United Republic of",
224
- TH: "Thailand",
225
- TL: "Timor-Leste",
226
- TG: "Togo",
227
- TK: "Tokelau",
228
- TO: "Tonga",
229
- TT: "Trinidad and Tobago",
230
- TN: "Tunisia",
231
- TR: "Turkey",
232
- TM: "Turkmenistan",
233
- TC: "Turks and Caicos Islands",
234
- TV: "Tuvalu",
235
- UG: "Uganda",
236
- UA: "Ukraine",
237
- AE: "United Arab Emirates",
238
- GB: "United Kingdom",
239
- US: "United States",
240
- UM: "United States Minor Outlying Islands",
241
- UY: "Uruguay",
242
- UZ: "Uzbekistan",
243
- VU: "Vanuatu",
244
- VE: "Venezuela, Bolivarian Republic of",
245
- VN: "Viet Nam",
246
- VG: "Virgin Islands, British",
247
- VI: "Virgin Islands, U.S.",
248
- WF: "Wallis and Futuna",
249
- EH: "Western Sahara",
250
- YE: "Yemen",
251
- ZM: "Zambia",
252
- ZW: "Zimbabwe"
2
+ AF: 'Afghanistan',
3
+ AX: 'Åland Islands',
4
+ AL: 'Albania',
5
+ DZ: 'Algeria',
6
+ AS: 'American Samoa',
7
+ AD: 'Andorra',
8
+ AO: 'Angola',
9
+ AI: 'Anguilla',
10
+ AQ: 'Antarctica',
11
+ AG: 'Antigua and Barbuda',
12
+ AR: 'Argentina',
13
+ AM: 'Armenia',
14
+ AW: 'Aruba',
15
+ AU: 'Australia',
16
+ AT: 'Austria',
17
+ AZ: 'Azerbaijan',
18
+ BS: 'Bahamas',
19
+ BH: 'Bahrain',
20
+ BD: 'Bangladesh',
21
+ BB: 'Barbados',
22
+ BY: 'Belarus',
23
+ BE: 'Belgium',
24
+ BZ: 'Belize',
25
+ BJ: 'Benin',
26
+ BM: 'Bermuda',
27
+ BT: 'Bhutan',
28
+ BO: 'Bolivia, Plurinational State of',
29
+ BQ: 'Bonaire, Sint Eustatius and Saba',
30
+ BA: 'Bosnia and Herzegovina',
31
+ BW: 'Botswana',
32
+ BV: 'Bouvet Island',
33
+ BR: 'Brazil',
34
+ IO: 'British Indian Ocean Territory',
35
+ BN: 'Brunei Darussalam',
36
+ BG: 'Bulgaria',
37
+ BF: 'Burkina Faso',
38
+ BI: 'Burundi',
39
+ KH: 'Cambodia',
40
+ CM: 'Cameroon',
41
+ CA: 'Canada',
42
+ CV: 'Cape Verde',
43
+ KY: 'Cayman Islands',
44
+ CF: 'Central African Republic',
45
+ TD: 'Chad',
46
+ CL: 'Chile',
47
+ CN: 'China',
48
+ CX: 'Christmas Island',
49
+ CC: 'Cocos (Keeling) Islands',
50
+ CO: 'Colombia',
51
+ KM: 'Comoros',
52
+ CG: 'Congo',
53
+ CD: 'Congo, the Democratic Republic of the',
54
+ CK: 'Cook Islands',
55
+ CR: 'Costa Rica',
56
+ CI: "Côte d'Ivoire",
57
+ HR: 'Croatia',
58
+ CU: 'Cuba',
59
+ CW: 'Curaçao',
60
+ CY: 'Cyprus',
61
+ CZ: 'Czech Republic',
62
+ DK: 'Denmark',
63
+ DJ: 'Djibouti',
64
+ DM: 'Dominica',
65
+ DO: 'Dominican Republic',
66
+ EC: 'Ecuador',
67
+ EG: 'Egypt',
68
+ SV: 'El Salvador',
69
+ GQ: 'Equatorial Guinea',
70
+ ER: 'Eritrea',
71
+ EE: 'Estonia',
72
+ ET: 'Ethiopia',
73
+ FK: 'Falkland Islands (Malvinas)',
74
+ FO: 'Faroe Islands',
75
+ FJ: 'Fiji',
76
+ FI: 'Finland',
77
+ FR: 'France',
78
+ GF: 'French Guiana',
79
+ PF: 'French Polynesia',
80
+ TF: 'French Southern Territories',
81
+ GA: 'Gabon',
82
+ GM: 'Gambia',
83
+ GE: 'Georgia',
84
+ DE: 'Germany',
85
+ GH: 'Ghana',
86
+ GI: 'Gibraltar',
87
+ GR: 'Greece',
88
+ GL: 'Greenland',
89
+ GD: 'Grenada',
90
+ GP: 'Guadeloupe',
91
+ GU: 'Guam',
92
+ GT: 'Guatemala',
93
+ GG: 'Guernsey',
94
+ GN: 'Guinea',
95
+ GW: 'Guinea-Bissau',
96
+ GY: 'Guyana',
97
+ HT: 'Haiti',
98
+ HM: 'Heard Island and McDonald Mcdonald Islands',
99
+ VA: 'Holy See (Vatican City State)',
100
+ HN: 'Honduras',
101
+ HK: 'Hong Kong',
102
+ HU: 'Hungary',
103
+ IS: 'Iceland',
104
+ IN: 'India',
105
+ ID: 'Indonesia',
106
+ IR: 'Iran, Islamic Republic of',
107
+ IQ: 'Iraq',
108
+ IE: 'Ireland',
109
+ IM: 'Isle of Man',
110
+ IL: 'Israel',
111
+ IT: 'Italy',
112
+ JM: 'Jamaica',
113
+ JP: 'Japan',
114
+ JE: 'Jersey',
115
+ JO: 'Jordan',
116
+ KZ: 'Kazakhstan',
117
+ KE: 'Kenya',
118
+ KI: 'Kiribati',
119
+ XK: 'Kosovo',
120
+ KP: "Korea, Democratic People's Republic of",
121
+ KR: 'Korea, Republic of',
122
+ KW: 'Kuwait',
123
+ KG: 'Kyrgyzstan',
124
+ LA: "Lao People's Democratic Republic",
125
+ LV: 'Latvia',
126
+ LB: 'Lebanon',
127
+ LS: 'Lesotho',
128
+ LR: 'Liberia',
129
+ LY: 'Libya',
130
+ LI: 'Liechtenstein',
131
+ LT: 'Lithuania',
132
+ LU: 'Luxembourg',
133
+ MO: 'Macao',
134
+ MK: 'North Macedonia',
135
+ MG: 'Madagascar',
136
+ MW: 'Malawi',
137
+ MY: 'Malaysia',
138
+ MV: 'Maldives',
139
+ ML: 'Mali',
140
+ MT: 'Malta',
141
+ MH: 'Marshall Islands',
142
+ MQ: 'Martinique',
143
+ MR: 'Mauritania',
144
+ MU: 'Mauritius',
145
+ YT: 'Mayotte',
146
+ MX: 'Mexico',
147
+ FM: 'Micronesia, Federated States of',
148
+ MD: 'Moldova, Republic of',
149
+ MC: 'Monaco',
150
+ MN: 'Mongolia',
151
+ ME: 'Montenegro',
152
+ MS: 'Montserrat',
153
+ MA: 'Morocco',
154
+ MZ: 'Mozambique',
155
+ MM: 'Myanmar',
156
+ NA: 'Namibia',
157
+ NR: 'Nauru',
158
+ NP: 'Nepal',
159
+ NL: 'Netherlands',
160
+ AN: 'Netherlands Antilles',
161
+ NC: 'New Caledonia',
162
+ NZ: 'New Zealand',
163
+ NI: 'Nicaragua',
164
+ NE: 'Niger',
165
+ NG: 'Nigeria',
166
+ NU: 'Niue',
167
+ NF: 'Norfolk Island',
168
+ MP: 'Northern Mariana Islands',
169
+ NO: 'Norway',
170
+ OM: 'Oman',
171
+ PK: 'Pakistan',
172
+ PW: 'Palau',
173
+ PS: 'Palestine, State of',
174
+ PA: 'Panama',
175
+ PG: 'Papua New Guinea',
176
+ PY: 'Paraguay',
177
+ PE: 'Peru',
178
+ PH: 'Philippines',
179
+ PN: 'Pitcairn',
180
+ PL: 'Poland',
181
+ PT: 'Portugal',
182
+ PR: 'Puerto Rico',
183
+ QA: 'Qatar',
184
+ RE: 'Réunion',
185
+ RO: 'Romania',
186
+ RU: 'Russian Federation',
187
+ RW: 'Rwanda',
188
+ BL: 'Saint Barthélemy',
189
+ SH: 'Saint Helena, Ascension and Tristan da Cunha',
190
+ KN: 'Saint Kitts and Nevis',
191
+ LC: 'Saint Lucia',
192
+ MF: 'Saint Martin (French part)',
193
+ PM: 'Saint Pierre and Miquelon',
194
+ VC: 'Saint Vincent and the Grenadines',
195
+ WS: 'Samoa',
196
+ SM: 'San Marino',
197
+ ST: 'Sao Tome and Principe',
198
+ SA: 'Saudi Arabia',
199
+ SN: 'Senegal',
200
+ RS: 'Serbia',
201
+ SC: 'Seychelles',
202
+ SL: 'Sierra Leone',
203
+ SG: 'Singapore',
204
+ SX: 'Sint Maarten (Dutch part)',
205
+ SK: 'Slovakia',
206
+ SI: 'Slovenia',
207
+ SB: 'Solomon Islands',
208
+ SO: 'Somalia',
209
+ ZA: 'South Africa',
210
+ GS: 'South Georgia and the South Sandwich Islands',
211
+ SS: 'South Sudan',
212
+ ES: 'Spain',
213
+ LK: 'Sri Lanka',
214
+ SD: 'Sudan',
215
+ SR: 'Suriname',
216
+ SJ: 'Svalbard and Jan Mayen',
217
+ SZ: 'Swaziland',
218
+ SE: 'Sweden',
219
+ CH: 'Switzerland',
220
+ SY: 'Syrian Arab Republic',
221
+ TW: 'Taiwan, Province of China',
222
+ TJ: 'Tajikistan',
223
+ TZ: 'Tanzania, United Republic of',
224
+ TH: 'Thailand',
225
+ TL: 'Timor-Leste',
226
+ TG: 'Togo',
227
+ TK: 'Tokelau',
228
+ TO: 'Tonga',
229
+ TT: 'Trinidad and Tobago',
230
+ TN: 'Tunisia',
231
+ TR: 'Turkey',
232
+ TM: 'Turkmenistan',
233
+ TC: 'Turks and Caicos Islands',
234
+ TV: 'Tuvalu',
235
+ UG: 'Uganda',
236
+ UA: 'Ukraine',
237
+ AE: 'United Arab Emirates',
238
+ GB: 'United Kingdom',
239
+ US: 'United States',
240
+ UM: 'United States Minor Outlying Islands',
241
+ UY: 'Uruguay',
242
+ UZ: 'Uzbekistan',
243
+ VU: 'Vanuatu',
244
+ VE: 'Venezuela, Bolivarian Republic of',
245
+ VN: 'Viet Nam',
246
+ VG: 'Virgin Islands, British',
247
+ VI: 'Virgin Islands, U.S.',
248
+ WF: 'Wallis and Futuna',
249
+ EH: 'Western Sahara',
250
+ YE: 'Yemen',
251
+ ZM: 'Zambia',
252
+ ZW: 'Zimbabwe'
253
253
  };
254
- function isValidCountryCode(countryCode) {
255
- return countryCode.toUpperCase() in countries;
254
+ export function isValidCountryCode(countryCode) {
255
+ return (countryCode.toUpperCase() in countries);
256
256
  }
257
- export {
258
- isValidCountryCode
259
- };
@@ -1,38 +1,38 @@
1
1
  import { MAX_NO_DATA_INTERVAL_MS, PING_INTERVAL_MS } from "../../config/index.js";
2
- function addKeepAlive(ws, logger) {
3
- let sendTimeout;
4
- let killTimeout;
5
- ws.on("message", () => {
6
- logger.trace("data recv, resetting timer");
7
- resetTimer();
8
- });
9
- ws.on("pong", () => {
10
- logger.trace("pong received, resetting timer");
11
- resetTimer();
12
- });
13
- ws.on("error", cleanup);
14
- ws.on("close", cleanup);
15
- function resetTimer() {
16
- cleanup();
17
- resetSendTimeout();
18
- killTimeout = setTimeout(() => {
19
- logger.warn(
20
- "no data received in a while, closing connection"
21
- );
22
- ws.close();
23
- }, MAX_NO_DATA_INTERVAL_MS);
24
- }
25
- function resetSendTimeout() {
26
- sendTimeout = setTimeout(() => {
27
- ws.ping();
28
- resetSendTimeout();
29
- }, PING_INTERVAL_MS);
30
- }
31
- function cleanup() {
32
- clearTimeout(killTimeout);
33
- clearTimeout(sendTimeout);
34
- }
2
+ /**
3
+ * Adds a keep-alive mechanism to the WebSocket
4
+ * client
5
+ */
6
+ export function addKeepAlive(ws, logger) {
7
+ let sendTimeout;
8
+ let killTimeout;
9
+ ws.on('message', () => {
10
+ logger.trace('data recv, resetting timer');
11
+ resetTimer();
12
+ });
13
+ ws.on('pong', () => {
14
+ logger.trace('pong received, resetting timer');
15
+ resetTimer();
16
+ });
17
+ ws.on('error', cleanup);
18
+ ws.on('close', cleanup);
19
+ function resetTimer() {
20
+ cleanup();
21
+ resetSendTimeout();
22
+ killTimeout = setTimeout(() => {
23
+ logger.warn('no data received in a while, closing connection');
24
+ ws.close();
25
+ }, MAX_NO_DATA_INTERVAL_MS);
26
+ }
27
+ function resetSendTimeout() {
28
+ // reset ping
29
+ sendTimeout = setTimeout(() => {
30
+ ws.ping();
31
+ resetSendTimeout();
32
+ }, PING_INTERVAL_MS);
33
+ }
34
+ function cleanup() {
35
+ clearTimeout(killTimeout);
36
+ clearTimeout(sendTimeout);
37
+ }
35
38
  }
36
- export {
37
- addKeepAlive
38
- };