UNPKG

2.77 kBJavaScriptView Raw
1"use strict";
2import { Logger } from "@ethersproject/logger";
3import { version } from "./_version";
4const logger = new Logger(version);
5import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
6const defaultApplicationId = "62e1ad51b37b8e00394bda3b";
7export class PocketProvider extends UrlJsonRpcProvider {
8 static getApiKey(apiKey) {
9 const apiKeyObj = {
10 applicationId: null,
11 loadBalancer: true,
12 applicationSecretKey: null
13 };
14 // Parse applicationId and applicationSecretKey
15 if (apiKey == null) {
16 apiKeyObj.applicationId = defaultApplicationId;
17 }
18 else if (typeof (apiKey) === "string") {
19 apiKeyObj.applicationId = apiKey;
20 }
21 else if (apiKey.applicationSecretKey != null) {
22 apiKeyObj.applicationId = apiKey.applicationId;
23 apiKeyObj.applicationSecretKey = apiKey.applicationSecretKey;
24 }
25 else if (apiKey.applicationId) {
26 apiKeyObj.applicationId = apiKey.applicationId;
27 }
28 else {
29 logger.throwArgumentError("unsupported PocketProvider apiKey", "apiKey", apiKey);
30 }
31 return apiKeyObj;
32 }
33 static getUrl(network, apiKey) {
34 let host = null;
35 switch (network ? network.name : "unknown") {
36 case "goerli":
37 host = "eth-goerli.gateway.pokt.network";
38 break;
39 case "homestead":
40 host = "eth-mainnet.gateway.pokt.network";
41 break;
42 case "kovan":
43 host = "poa-kovan.gateway.pokt.network";
44 break;
45 case "matic":
46 host = "poly-mainnet.gateway.pokt.network";
47 break;
48 case "maticmum":
49 host = "polygon-mumbai-rpc.gateway.pokt.network";
50 break;
51 case "rinkeby":
52 host = "eth-rinkeby.gateway.pokt.network";
53 break;
54 case "ropsten":
55 host = "eth-ropsten.gateway.pokt.network";
56 break;
57 default:
58 logger.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
59 argument: "network",
60 value: network
61 });
62 }
63 const url = `https:/\/${host}/v1/lb/${apiKey.applicationId}`;
64 const connection = { headers: {}, url };
65 if (apiKey.applicationSecretKey != null) {
66 connection.user = "";
67 connection.password = apiKey.applicationSecretKey;
68 }
69 return connection;
70 }
71 isCommunityResource() {
72 return (this.applicationId === defaultApplicationId);
73 }
74}
75//# sourceMappingURL=pocket-provider.js.map
\No newline at end of file