59 lines
2.3 KiB
JavaScript
59 lines
2.3 KiB
JavaScript
"use strict";
|
|
import { Logger } from "@ethersproject/logger";
|
|
import { version } from "./_version";
|
|
const logger = new Logger(version);
|
|
import { UrlJsonRpcProvider } from "./url-json-rpc-provider";
|
|
const defaultApplicationId = "5f7f8547b90218002e9ce9dd";
|
|
export class PocketProvider extends UrlJsonRpcProvider {
|
|
static getApiKey(apiKey) {
|
|
const apiKeyObj = {
|
|
applicationId: defaultApplicationId,
|
|
applicationSecretKey: null
|
|
};
|
|
if (apiKey == null) {
|
|
return apiKeyObj;
|
|
}
|
|
// Parse applicationId and applicationSecretKey
|
|
if (typeof (apiKey) === "string") {
|
|
apiKeyObj.applicationId = apiKey;
|
|
}
|
|
else if (apiKey.applicationSecretKey != null) {
|
|
logger.assertArgument((typeof (apiKey.applicationId) === "string"), "applicationSecretKey requires an applicationId", "applicationId", apiKey.applicationId);
|
|
logger.assertArgument((typeof (apiKey.applicationSecretKey) === "string"), "invalid applicationSecretKey", "applicationSecretKey", "[REDACTED]");
|
|
apiKeyObj.applicationId = apiKey.applicationId;
|
|
apiKeyObj.applicationSecretKey = apiKey.applicationSecretKey;
|
|
}
|
|
else if (apiKey.applicationId) {
|
|
apiKeyObj.applicationId = apiKey.applicationId;
|
|
}
|
|
return apiKeyObj;
|
|
}
|
|
static getUrl(network, apiKey) {
|
|
let host = null;
|
|
switch (network ? network.name : "unknown") {
|
|
case "homestead":
|
|
host = "eth-mainnet.gateway.pokt.network";
|
|
break;
|
|
default:
|
|
logger.throwError("unsupported network", Logger.errors.INVALID_ARGUMENT, {
|
|
argument: "network",
|
|
value: network
|
|
});
|
|
}
|
|
const connection = {
|
|
url: (`https:/\/${host}/v1/${apiKey.applicationId}`),
|
|
};
|
|
// Initialize empty headers
|
|
connection.headers = {};
|
|
// Apply application secret key
|
|
if (apiKey.applicationSecretKey != null) {
|
|
connection.user = "";
|
|
connection.password = apiKey.applicationSecretKey;
|
|
}
|
|
return connection;
|
|
}
|
|
isCommunityResource() {
|
|
return (this.applicationId === defaultApplicationId);
|
|
}
|
|
}
|
|
//# sourceMappingURL=pocket-provider.js.map
|