1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | };
|
9 | return function (d, b) {
|
10 | if (typeof b !== "function" && b !== null)
|
11 | throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12 | extendStatics(d, b);
|
13 | function __() { this.constructor = d; }
|
14 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15 | };
|
16 | })();
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.InfuraProvider = exports.InfuraWebSocketProvider = void 0;
|
19 | var properties_1 = require("@ethersproject/properties");
|
20 | var websocket_provider_1 = require("./websocket-provider");
|
21 | var formatter_1 = require("./formatter");
|
22 | var logger_1 = require("@ethersproject/logger");
|
23 | var _version_1 = require("./_version");
|
24 | var logger = new logger_1.Logger(_version_1.version);
|
25 | var url_json_rpc_provider_1 = require("./url-json-rpc-provider");
|
26 | var defaultProjectId = "84842078b09946638c03157f83405213";
|
27 | var InfuraWebSocketProvider = (function (_super) {
|
28 | __extends(InfuraWebSocketProvider, _super);
|
29 | function InfuraWebSocketProvider(network, apiKey) {
|
30 | var _this = this;
|
31 | var provider = new InfuraProvider(network, apiKey);
|
32 | var connection = provider.connection;
|
33 | if (connection.password) {
|
34 | logger.throwError("INFURA WebSocket project secrets unsupported", logger_1.Logger.errors.UNSUPPORTED_OPERATION, {
|
35 | operation: "InfuraProvider.getWebSocketProvider()"
|
36 | });
|
37 | }
|
38 | var url = connection.url.replace(/^http/i, "ws").replace("/v3/", "/ws/v3/");
|
39 | _this = _super.call(this, url, network) || this;
|
40 | (0, properties_1.defineReadOnly)(_this, "apiKey", provider.projectId);
|
41 | (0, properties_1.defineReadOnly)(_this, "projectId", provider.projectId);
|
42 | (0, properties_1.defineReadOnly)(_this, "projectSecret", provider.projectSecret);
|
43 | return _this;
|
44 | }
|
45 | InfuraWebSocketProvider.prototype.isCommunityResource = function () {
|
46 | return (this.projectId === defaultProjectId);
|
47 | };
|
48 | return InfuraWebSocketProvider;
|
49 | }(websocket_provider_1.WebSocketProvider));
|
50 | exports.InfuraWebSocketProvider = InfuraWebSocketProvider;
|
51 | var InfuraProvider = (function (_super) {
|
52 | __extends(InfuraProvider, _super);
|
53 | function InfuraProvider() {
|
54 | return _super !== null && _super.apply(this, arguments) || this;
|
55 | }
|
56 | InfuraProvider.getWebSocketProvider = function (network, apiKey) {
|
57 | return new InfuraWebSocketProvider(network, apiKey);
|
58 | };
|
59 | InfuraProvider.getApiKey = function (apiKey) {
|
60 | var apiKeyObj = {
|
61 | apiKey: defaultProjectId,
|
62 | projectId: defaultProjectId,
|
63 | projectSecret: null
|
64 | };
|
65 | if (apiKey == null) {
|
66 | return apiKeyObj;
|
67 | }
|
68 | if (typeof (apiKey) === "string") {
|
69 | apiKeyObj.projectId = apiKey;
|
70 | }
|
71 | else if (apiKey.projectSecret != null) {
|
72 | logger.assertArgument((typeof (apiKey.projectId) === "string"), "projectSecret requires a projectId", "projectId", apiKey.projectId);
|
73 | logger.assertArgument((typeof (apiKey.projectSecret) === "string"), "invalid projectSecret", "projectSecret", "[REDACTED]");
|
74 | apiKeyObj.projectId = apiKey.projectId;
|
75 | apiKeyObj.projectSecret = apiKey.projectSecret;
|
76 | }
|
77 | else if (apiKey.projectId) {
|
78 | apiKeyObj.projectId = apiKey.projectId;
|
79 | }
|
80 | apiKeyObj.apiKey = apiKeyObj.projectId;
|
81 | return apiKeyObj;
|
82 | };
|
83 | InfuraProvider.getUrl = function (network, apiKey) {
|
84 | var host = null;
|
85 | switch (network ? network.name : "unknown") {
|
86 | case "homestead":
|
87 | host = "mainnet.infura.io";
|
88 | break;
|
89 | case "ropsten":
|
90 | host = "ropsten.infura.io";
|
91 | break;
|
92 | case "rinkeby":
|
93 | host = "rinkeby.infura.io";
|
94 | break;
|
95 | case "kovan":
|
96 | host = "kovan.infura.io";
|
97 | break;
|
98 | case "goerli":
|
99 | host = "goerli.infura.io";
|
100 | break;
|
101 | case "matic":
|
102 | host = "polygon-mainnet.infura.io";
|
103 | break;
|
104 | case "maticmum":
|
105 | host = "polygon-mumbai.infura.io";
|
106 | break;
|
107 | case "optimism":
|
108 | host = "optimism-mainnet.infura.io";
|
109 | break;
|
110 | case "optimism-kovan":
|
111 | host = "optimism-kovan.infura.io";
|
112 | break;
|
113 | case "arbitrum":
|
114 | host = "arbitrum-mainnet.infura.io";
|
115 | break;
|
116 | case "arbitrum-rinkeby":
|
117 | host = "arbitrum-rinkeby.infura.io";
|
118 | break;
|
119 | default:
|
120 | logger.throwError("unsupported network", logger_1.Logger.errors.INVALID_ARGUMENT, {
|
121 | argument: "network",
|
122 | value: network
|
123 | });
|
124 | }
|
125 | var connection = {
|
126 | allowGzip: true,
|
127 | url: ("https:/" + "/" + host + "/v3/" + apiKey.projectId),
|
128 | throttleCallback: function (attempt, url) {
|
129 | if (apiKey.projectId === defaultProjectId) {
|
130 | (0, formatter_1.showThrottleMessage)();
|
131 | }
|
132 | return Promise.resolve(true);
|
133 | }
|
134 | };
|
135 | if (apiKey.projectSecret != null) {
|
136 | connection.user = "";
|
137 | connection.password = apiKey.projectSecret;
|
138 | }
|
139 | return connection;
|
140 | };
|
141 | InfuraProvider.prototype.isCommunityResource = function () {
|
142 | return (this.projectId === defaultProjectId);
|
143 | };
|
144 | return InfuraProvider;
|
145 | }(url_json_rpc_provider_1.UrlJsonRpcProvider));
|
146 | exports.InfuraProvider = InfuraProvider;
|
147 |
|
\ | No newline at end of file |