@octaflowlabs/onchain-sdk 1.2.0 → 1.2.2
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/README.md +16 -0
- package/dist/blockchain/broadcastTransaction.js +0 -3
- package/dist/blockchain/buildUnsignedTransferTx.js +0 -3
- package/dist/cjs/blockchain/broadcastTransaction.js +0 -3
- package/dist/cjs/blockchain/buildUnsignedTransferTx.js +0 -3
- package/dist/cjs/constants/NETWORKS_REGISTRY.d.ts +15 -0
- package/dist/cjs/constants/NETWORKS_REGISTRY.js +65 -0
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.js +3 -6
- package/dist/constants/NETWORKS_REGISTRY.d.ts +15 -0
- package/dist/constants/NETWORKS_REGISTRY.js +62 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/package.json +1 -1
- package/dist/cjs/rpc/index.d.ts +0 -3
- package/dist/cjs/rpc/index.js +0 -69
- package/dist/rpc/index.d.ts +0 -3
- package/dist/rpc/index.js +0 -60
package/README.md
CHANGED
|
@@ -47,6 +47,22 @@ ABIs and constants
|
|
|
47
47
|
- Multicall3 ABI and address for batched reads.
|
|
48
48
|
- Gas limit defaults per transaction type.
|
|
49
49
|
|
|
50
|
+
Networks registry
|
|
51
|
+
|
|
52
|
+
- The SDK includes a predefined networks registry in `src/constants/NETWORKS_REGISTRY.ts`.
|
|
53
|
+
- Networks are grouped by `category` (for example: `popular`, `custom`).
|
|
54
|
+
- Each network entry includes:
|
|
55
|
+
- `id`: stable internal identifier.
|
|
56
|
+
- `name`: human-readable network name.
|
|
57
|
+
- `chainId`: EVM chain ID.
|
|
58
|
+
- `rpcUrl`: primary RPC endpoint.
|
|
59
|
+
- `failoverRpcUrl` (optional): fallback RPC endpoint.
|
|
60
|
+
- `explorerUrl`: block explorer base URL.
|
|
61
|
+
- `iconUrl`: network icon URL.
|
|
62
|
+
- `symbol`: native currency symbol.
|
|
63
|
+
- This registry is useful for network selection UIs, chain metadata lookup, and RPC fallback handling.
|
|
64
|
+
- You can use `chainId` with SDK helpers and pass `rpcUrl` (or `failoverRpcUrl`) to provider-based calls.
|
|
65
|
+
|
|
50
66
|
## Design notes
|
|
51
67
|
|
|
52
68
|
- The SDK is stateless and transport-agnostic. It expects a caller-provided RPC URL.
|
|
@@ -3,10 +3,7 @@ import { Transaction } from 'ethers';
|
|
|
3
3
|
/** local imports */
|
|
4
4
|
import { getProvider } from './getProvider';
|
|
5
5
|
import { errorMessagesForBroadcast, handleErrorMessages } from '../utils/handleErrorMessages';
|
|
6
|
-
import { ensurePublicHost, testJsonRpc } from '../rpc';
|
|
7
6
|
export const broadcastTransaction = async ({ signedTx, rpcUrl, chainId, waitConfirmations = 0, }) => {
|
|
8
|
-
await ensurePublicHost(rpcUrl);
|
|
9
|
-
await testJsonRpc(rpcUrl, 'eth_chainId', []);
|
|
10
7
|
const provider = getProvider(rpcUrl, chainId);
|
|
11
8
|
if (!provider)
|
|
12
9
|
throw new Error('Could not create provider with given rpcUrl');
|
|
@@ -3,10 +3,7 @@ import { Interface, formatUnits, parseUnits } from 'ethers';
|
|
|
3
3
|
/** local imports */
|
|
4
4
|
import { getProvider } from './getProvider';
|
|
5
5
|
import { estimateGasLimitFromProvider } from './estimateGasLimitFromProvider';
|
|
6
|
-
import { ensurePublicHost, testJsonRpc } from '../rpc';
|
|
7
6
|
export const buildUnsignedTransferTx = async (options) => {
|
|
8
|
-
await ensurePublicHost(options.rpcUrl);
|
|
9
|
-
await testJsonRpc(options.rpcUrl, 'eth_chainId', []);
|
|
10
7
|
const provider = getProvider(options.rpcUrl, options.chainId);
|
|
11
8
|
if (!provider)
|
|
12
9
|
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
@@ -6,10 +6,7 @@ const ethers_1 = require("ethers");
|
|
|
6
6
|
/** local imports */
|
|
7
7
|
const getProvider_1 = require("./getProvider");
|
|
8
8
|
const handleErrorMessages_1 = require("../utils/handleErrorMessages");
|
|
9
|
-
const rpc_1 = require("../rpc");
|
|
10
9
|
const broadcastTransaction = async ({ signedTx, rpcUrl, chainId, waitConfirmations = 0, }) => {
|
|
11
|
-
await (0, rpc_1.ensurePublicHost)(rpcUrl);
|
|
12
|
-
await (0, rpc_1.testJsonRpc)(rpcUrl, 'eth_chainId', []);
|
|
13
10
|
const provider = (0, getProvider_1.getProvider)(rpcUrl, chainId);
|
|
14
11
|
if (!provider)
|
|
15
12
|
throw new Error('Could not create provider with given rpcUrl');
|
|
@@ -6,10 +6,7 @@ const ethers_1 = require("ethers");
|
|
|
6
6
|
/** local imports */
|
|
7
7
|
const getProvider_1 = require("./getProvider");
|
|
8
8
|
const estimateGasLimitFromProvider_1 = require("./estimateGasLimitFromProvider");
|
|
9
|
-
const rpc_1 = require("../rpc");
|
|
10
9
|
const buildUnsignedTransferTx = async (options) => {
|
|
11
|
-
await (0, rpc_1.ensurePublicHost)(options.rpcUrl);
|
|
12
|
-
await (0, rpc_1.testJsonRpc)(options.rpcUrl, 'eth_chainId', []);
|
|
13
10
|
const provider = (0, getProvider_1.getProvider)(options.rpcUrl, options.chainId);
|
|
14
11
|
if (!provider)
|
|
15
12
|
throw new Error('Could not create provider with given rpcUrl and chainId');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface NetworkField {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
chainId: number;
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
explorerUrl: string;
|
|
7
|
+
iconUrl: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
failoverRpcUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface NetworkRegistry {
|
|
12
|
+
category: string;
|
|
13
|
+
networks: NetworkField[];
|
|
14
|
+
}
|
|
15
|
+
export declare const NETWORKS_REGISTRY: NetworkRegistry[];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NETWORKS_REGISTRY = void 0;
|
|
4
|
+
exports.NETWORKS_REGISTRY = [
|
|
5
|
+
{
|
|
6
|
+
category: 'popular',
|
|
7
|
+
networks: [
|
|
8
|
+
{
|
|
9
|
+
id: 'ethereum-mainnet',
|
|
10
|
+
name: 'Ethereum Mainnet',
|
|
11
|
+
chainId: 1,
|
|
12
|
+
rpcUrl: 'https://ethereum-rpc.publicnode.com',
|
|
13
|
+
explorerUrl: 'https://etherscan.io',
|
|
14
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
|
|
15
|
+
symbol: 'ETH',
|
|
16
|
+
failoverRpcUrl: 'https://eth.llamarpc.com',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'bnb-smart-chain',
|
|
20
|
+
name: 'BNB Smart Chain',
|
|
21
|
+
chainId: 56,
|
|
22
|
+
rpcUrl: 'https://bsc-dataseed.bnbchain.org',
|
|
23
|
+
explorerUrl: 'https://bscscan.com/',
|
|
24
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/825/large/bnb-icon2_2x.png',
|
|
25
|
+
symbol: 'BNB',
|
|
26
|
+
failoverRpcUrl: 'https://bsc.llamarpc.com',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 'polygon-mainnet',
|
|
30
|
+
name: 'Polygon Mainnet',
|
|
31
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png',
|
|
32
|
+
chainId: 137,
|
|
33
|
+
rpcUrl: 'https://polygon.publicnode.com',
|
|
34
|
+
explorerUrl: 'https://polygonscan.com',
|
|
35
|
+
symbol: 'POL',
|
|
36
|
+
failoverRpcUrl: 'https://polygon.llamarpc.com',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: 'arbitrum-mainnet',
|
|
40
|
+
name: 'Arbitrum Mainnet',
|
|
41
|
+
chainId: 42161,
|
|
42
|
+
rpcUrl: 'https://public-arb-mainnet.fastnode.io',
|
|
43
|
+
explorerUrl: 'https://arbiscan.io',
|
|
44
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/16547/large/photo_2023-03-29_21.47.00.jpeg',
|
|
45
|
+
symbol: 'ARB',
|
|
46
|
+
failoverRpcUrl: 'https://arb.llamarpc.com',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
category: 'custom',
|
|
52
|
+
networks: [
|
|
53
|
+
{
|
|
54
|
+
id: 'sepolia-eth',
|
|
55
|
+
name: 'Sepolia Testnet',
|
|
56
|
+
chainId: 11155111,
|
|
57
|
+
rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
|
|
58
|
+
explorerUrl: 'https://sepolia.etherscan.io',
|
|
59
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
|
|
60
|
+
symbol: 'ETH',
|
|
61
|
+
failoverRpcUrl: 'https://eth-sepolia.llamarpc.com',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
];
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
|
|
|
3
3
|
export { ERC20_TOKEN_CONTRACT_ABI };
|
|
4
4
|
/** constants exports */
|
|
5
5
|
export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
|
|
6
|
+
export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
|
|
6
7
|
/** basic blockchain exports */
|
|
7
8
|
export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
8
9
|
export { broadcastTransaction } from './blockchain/broadcastTransaction';
|
|
@@ -22,7 +23,5 @@ export { NATIVE_TOKENS };
|
|
|
22
23
|
export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
|
|
23
24
|
export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
|
|
24
25
|
export { normalizeAddress } from './utils/normalizeAddress';
|
|
25
|
-
/** rpc exports */
|
|
26
|
-
export { validateRpcUrl, ensurePublicHost, testJsonRpc } from './rpc/index';
|
|
27
26
|
/** types exports */
|
|
28
27
|
export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildMaxNativeTransferTxResponse, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, TxStatusResponse, UnsignedTransferTxResponse, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.normalizeAddress = exports.errorMessagesForGasLimitEstimation = exports.errorMessagesForBroadcast = exports.handleErrorMessages = exports.parsedAmount = exports.formattedAmountForDisplay = exports.NATIVE_TOKENS = exports.transformBigInt = exports.getShortenData = exports.getShortenTransactionHashOrAddress = exports.signTransaction = exports.signMessage = exports.createWallet = exports.EvmWalletService = exports.getBalances = exports.getBalance = exports.txStatus = exports.getProvider = exports.estimateGasLimitFromProvider = exports.broadcastTransaction = exports.buildUnsignedTransferTx = exports.buildMaxNativeTransferTx = exports.NETWORKS_REGISTRY = exports.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
|
|
7
7
|
/** ABIs exports */
|
|
8
8
|
const ERC20_TOKEN_CONTRACT_ABI_1 = __importDefault(require("./ABIs/ERC20_TOKEN_CONTRACT_ABI"));
|
|
9
9
|
exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
|
|
@@ -11,6 +11,8 @@ exports.ERC20_TOKEN_CONTRACT_ABI = ERC20_TOKEN_CONTRACT_ABI_1.default;
|
|
|
11
11
|
var constants_1 = require("./constants/constants");
|
|
12
12
|
Object.defineProperty(exports, "GAS_LIMIT_PER_TX_TYPE", { enumerable: true, get: function () { return constants_1.GAS_LIMIT_PER_TX_TYPE; } });
|
|
13
13
|
Object.defineProperty(exports, "MULTICALL3_ADDRESS", { enumerable: true, get: function () { return constants_1.MULTICALL3_ADDRESS; } });
|
|
14
|
+
var NETWORKS_REGISTRY_1 = require("./constants/NETWORKS_REGISTRY");
|
|
15
|
+
Object.defineProperty(exports, "NETWORKS_REGISTRY", { enumerable: true, get: function () { return NETWORKS_REGISTRY_1.NETWORKS_REGISTRY; } });
|
|
14
16
|
/** basic blockchain exports */
|
|
15
17
|
var buildUnsignedTransferTx_1 = require("./blockchain/buildUnsignedTransferTx");
|
|
16
18
|
Object.defineProperty(exports, "buildMaxNativeTransferTx", { enumerable: true, get: function () { return buildUnsignedTransferTx_1.buildMaxNativeTransferTx; } });
|
|
@@ -50,8 +52,3 @@ Object.defineProperty(exports, "errorMessagesForBroadcast", { enumerable: true,
|
|
|
50
52
|
Object.defineProperty(exports, "errorMessagesForGasLimitEstimation", { enumerable: true, get: function () { return handleErrorMessages_1.errorMessagesForGasLimitEstimation; } });
|
|
51
53
|
var normalizeAddress_1 = require("./utils/normalizeAddress");
|
|
52
54
|
Object.defineProperty(exports, "normalizeAddress", { enumerable: true, get: function () { return normalizeAddress_1.normalizeAddress; } });
|
|
53
|
-
/** rpc exports */
|
|
54
|
-
var index_1 = require("./rpc/index");
|
|
55
|
-
Object.defineProperty(exports, "validateRpcUrl", { enumerable: true, get: function () { return index_1.validateRpcUrl; } });
|
|
56
|
-
Object.defineProperty(exports, "ensurePublicHost", { enumerable: true, get: function () { return index_1.ensurePublicHost; } });
|
|
57
|
-
Object.defineProperty(exports, "testJsonRpc", { enumerable: true, get: function () { return index_1.testJsonRpc; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface NetworkField {
|
|
2
|
+
id: string;
|
|
3
|
+
name: string;
|
|
4
|
+
chainId: number;
|
|
5
|
+
rpcUrl: string;
|
|
6
|
+
explorerUrl: string;
|
|
7
|
+
iconUrl: string;
|
|
8
|
+
symbol: string;
|
|
9
|
+
failoverRpcUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface NetworkRegistry {
|
|
12
|
+
category: string;
|
|
13
|
+
networks: NetworkField[];
|
|
14
|
+
}
|
|
15
|
+
export declare const NETWORKS_REGISTRY: NetworkRegistry[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export const NETWORKS_REGISTRY = [
|
|
2
|
+
{
|
|
3
|
+
category: 'popular',
|
|
4
|
+
networks: [
|
|
5
|
+
{
|
|
6
|
+
id: 'ethereum-mainnet',
|
|
7
|
+
name: 'Ethereum Mainnet',
|
|
8
|
+
chainId: 1,
|
|
9
|
+
rpcUrl: 'https://ethereum-rpc.publicnode.com',
|
|
10
|
+
explorerUrl: 'https://etherscan.io',
|
|
11
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
|
|
12
|
+
symbol: 'ETH',
|
|
13
|
+
failoverRpcUrl: 'https://eth.llamarpc.com',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: 'bnb-smart-chain',
|
|
17
|
+
name: 'BNB Smart Chain',
|
|
18
|
+
chainId: 56,
|
|
19
|
+
rpcUrl: 'https://bsc-dataseed.bnbchain.org',
|
|
20
|
+
explorerUrl: 'https://bscscan.com/',
|
|
21
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/825/large/bnb-icon2_2x.png',
|
|
22
|
+
symbol: 'BNB',
|
|
23
|
+
failoverRpcUrl: 'https://bsc.llamarpc.com',
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'polygon-mainnet',
|
|
27
|
+
name: 'Polygon Mainnet',
|
|
28
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png',
|
|
29
|
+
chainId: 137,
|
|
30
|
+
rpcUrl: 'https://polygon.publicnode.com',
|
|
31
|
+
explorerUrl: 'https://polygonscan.com',
|
|
32
|
+
symbol: 'POL',
|
|
33
|
+
failoverRpcUrl: 'https://polygon.llamarpc.com',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'arbitrum-mainnet',
|
|
37
|
+
name: 'Arbitrum Mainnet',
|
|
38
|
+
chainId: 42161,
|
|
39
|
+
rpcUrl: 'https://public-arb-mainnet.fastnode.io',
|
|
40
|
+
explorerUrl: 'https://arbiscan.io',
|
|
41
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/16547/large/photo_2023-03-29_21.47.00.jpeg',
|
|
42
|
+
symbol: 'ARB',
|
|
43
|
+
failoverRpcUrl: 'https://arb.llamarpc.com',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
category: 'custom',
|
|
49
|
+
networks: [
|
|
50
|
+
{
|
|
51
|
+
id: 'sepolia-eth',
|
|
52
|
+
name: 'Sepolia Testnet',
|
|
53
|
+
chainId: 11155111,
|
|
54
|
+
rpcUrl: 'https://ethereum-sepolia-rpc.publicnode.com',
|
|
55
|
+
explorerUrl: 'https://sepolia.etherscan.io',
|
|
56
|
+
iconUrl: 'https://assets.coingecko.com/coins/images/279/large/ethereum.png',
|
|
57
|
+
symbol: 'ETH',
|
|
58
|
+
failoverRpcUrl: 'https://eth-sepolia.llamarpc.com',
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
];
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
|
|
|
3
3
|
export { ERC20_TOKEN_CONTRACT_ABI };
|
|
4
4
|
/** constants exports */
|
|
5
5
|
export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
|
|
6
|
+
export { NETWORKS_REGISTRY, NetworkField, NetworkRegistry } from './constants/NETWORKS_REGISTRY';
|
|
6
7
|
/** basic blockchain exports */
|
|
7
8
|
export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
8
9
|
export { broadcastTransaction } from './blockchain/broadcastTransaction';
|
|
@@ -22,7 +23,5 @@ export { NATIVE_TOKENS };
|
|
|
22
23
|
export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
|
|
23
24
|
export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
|
|
24
25
|
export { normalizeAddress } from './utils/normalizeAddress';
|
|
25
|
-
/** rpc exports */
|
|
26
|
-
export { validateRpcUrl, ensurePublicHost, testJsonRpc } from './rpc/index';
|
|
27
26
|
/** types exports */
|
|
28
27
|
export { BroadcastTransactionOptions, BuildMaxNativeTransferTxOptions, BuildMaxNativeTransferTxResponse, BuildUnsignedTransferTxOptions, EstimateGasLimitFromProviderProps, GasEstimateResult, TxStatusOptions, TxStatusResponse, UnsignedTransferTxResponse, FormatAmountOptions, TransactionRequest, GetBalanceParams, GetBalancesParams, GetBalancesChainRequest, GetBalanceResult, ChainBalances, TokenBalance, ChainGroup, } from './types/common';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import ERC20_TOKEN_CONTRACT_ABI from './ABIs/ERC20_TOKEN_CONTRACT_ABI';
|
|
|
3
3
|
export { ERC20_TOKEN_CONTRACT_ABI };
|
|
4
4
|
/** constants exports */
|
|
5
5
|
export { GAS_LIMIT_PER_TX_TYPE, MULTICALL3_ADDRESS } from './constants/constants';
|
|
6
|
+
export { NETWORKS_REGISTRY } from './constants/NETWORKS_REGISTRY';
|
|
6
7
|
/** basic blockchain exports */
|
|
7
8
|
export { buildMaxNativeTransferTx, buildUnsignedTransferTx, } from './blockchain/buildUnsignedTransferTx';
|
|
8
9
|
export { broadcastTransaction } from './blockchain/broadcastTransaction';
|
|
@@ -21,5 +22,3 @@ export { NATIVE_TOKENS };
|
|
|
21
22
|
export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
|
|
22
23
|
export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
|
|
23
24
|
export { normalizeAddress } from './utils/normalizeAddress';
|
|
24
|
-
/** rpc exports */
|
|
25
|
-
export { validateRpcUrl, ensurePublicHost, testJsonRpc } from './rpc/index';
|
package/package.json
CHANGED
package/dist/cjs/rpc/index.d.ts
DELETED
package/dist/cjs/rpc/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.testJsonRpc = exports.ensurePublicHost = exports.validateRpcUrl = void 0;
|
|
7
|
-
/** npm imports */
|
|
8
|
-
const promises_1 = __importDefault(require("dns/promises"));
|
|
9
|
-
const net_1 = __importDefault(require("net"));
|
|
10
|
-
const PRIVATE_IP_RANGES = [
|
|
11
|
-
/^127\./,
|
|
12
|
-
/^10\./,
|
|
13
|
-
/^172\.(1[6-9]|2[0-9]|3[0-1])\./,
|
|
14
|
-
/^192\.168\./,
|
|
15
|
-
/^169\.254\./,
|
|
16
|
-
];
|
|
17
|
-
const validateRpcUrl = (rpcUrl, allowLocal = false) => {
|
|
18
|
-
let url;
|
|
19
|
-
try {
|
|
20
|
-
url = new URL(rpcUrl);
|
|
21
|
-
if (!allowLocal && ['localhost', '127.0.0.1', '::1'].includes(url.hostname))
|
|
22
|
-
throw new Error('Localhost URLs are not allowed');
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
throw new Error('Invalid RPC URL');
|
|
26
|
-
}
|
|
27
|
-
if (!['http:', 'https:', 'ws:', 'wss:'].includes(url.protocol))
|
|
28
|
-
throw new Error('Unsupported protocol. Only http, https, ws, and wss are allowed.');
|
|
29
|
-
if (['localhost', '127.0.0.1'].includes(url.hostname))
|
|
30
|
-
throw new Error('Localhost RPC not allowed');
|
|
31
|
-
return url;
|
|
32
|
-
};
|
|
33
|
-
exports.validateRpcUrl = validateRpcUrl;
|
|
34
|
-
const ensurePublicHost = async (rpcUrl) => {
|
|
35
|
-
const url = (0, exports.validateRpcUrl)(rpcUrl);
|
|
36
|
-
try {
|
|
37
|
-
const addresses = await promises_1.default.lookup(url.hostname, { all: true });
|
|
38
|
-
const hasPrivateIp = addresses
|
|
39
|
-
.filter((a) => net_1.default.isIP(a.address))
|
|
40
|
-
.some((a) => PRIVATE_IP_RANGES.some((r) => r.test(a.address)));
|
|
41
|
-
if (hasPrivateIp)
|
|
42
|
-
throw new Error('RPC URL resolves to a private IP address');
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error('Error validating RPC URL:', error);
|
|
47
|
-
throw new Error('Failed to validate RPC URL');
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
exports.ensurePublicHost = ensurePublicHost;
|
|
51
|
-
const testJsonRpc = async (rpcUrl, method = 'eth_chainId', params = []) => {
|
|
52
|
-
await (0, exports.ensurePublicHost)(rpcUrl);
|
|
53
|
-
const payload = { jsonrpc: '2.0', id: 1, method, params };
|
|
54
|
-
try {
|
|
55
|
-
const res = await fetch(rpcUrl, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: { 'Content-Type': 'application/json' },
|
|
58
|
-
body: JSON.stringify(payload),
|
|
59
|
-
signal: AbortSignal.timeout(5000),
|
|
60
|
-
});
|
|
61
|
-
const data = await res.json();
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
66
|
-
throw new Error(`RPC test failed: ${errorMessage}`);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
exports.testJsonRpc = testJsonRpc;
|
package/dist/rpc/index.d.ts
DELETED
package/dist/rpc/index.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/** npm imports */
|
|
2
|
-
import dns from 'dns/promises';
|
|
3
|
-
import net from 'net';
|
|
4
|
-
const PRIVATE_IP_RANGES = [
|
|
5
|
-
/^127\./,
|
|
6
|
-
/^10\./,
|
|
7
|
-
/^172\.(1[6-9]|2[0-9]|3[0-1])\./,
|
|
8
|
-
/^192\.168\./,
|
|
9
|
-
/^169\.254\./,
|
|
10
|
-
];
|
|
11
|
-
export const validateRpcUrl = (rpcUrl, allowLocal = false) => {
|
|
12
|
-
let url;
|
|
13
|
-
try {
|
|
14
|
-
url = new URL(rpcUrl);
|
|
15
|
-
if (!allowLocal && ['localhost', '127.0.0.1', '::1'].includes(url.hostname))
|
|
16
|
-
throw new Error('Localhost URLs are not allowed');
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
throw new Error('Invalid RPC URL');
|
|
20
|
-
}
|
|
21
|
-
if (!['http:', 'https:', 'ws:', 'wss:'].includes(url.protocol))
|
|
22
|
-
throw new Error('Unsupported protocol. Only http, https, ws, and wss are allowed.');
|
|
23
|
-
if (['localhost', '127.0.0.1'].includes(url.hostname))
|
|
24
|
-
throw new Error('Localhost RPC not allowed');
|
|
25
|
-
return url;
|
|
26
|
-
};
|
|
27
|
-
export const ensurePublicHost = async (rpcUrl) => {
|
|
28
|
-
const url = validateRpcUrl(rpcUrl);
|
|
29
|
-
try {
|
|
30
|
-
const addresses = await dns.lookup(url.hostname, { all: true });
|
|
31
|
-
const hasPrivateIp = addresses
|
|
32
|
-
.filter((a) => net.isIP(a.address))
|
|
33
|
-
.some((a) => PRIVATE_IP_RANGES.some((r) => r.test(a.address)));
|
|
34
|
-
if (hasPrivateIp)
|
|
35
|
-
throw new Error('RPC URL resolves to a private IP address');
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
console.error('Error validating RPC URL:', error);
|
|
40
|
-
throw new Error('Failed to validate RPC URL');
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
export const testJsonRpc = async (rpcUrl, method = 'eth_chainId', params = []) => {
|
|
44
|
-
await ensurePublicHost(rpcUrl);
|
|
45
|
-
const payload = { jsonrpc: '2.0', id: 1, method, params };
|
|
46
|
-
try {
|
|
47
|
-
const res = await fetch(rpcUrl, {
|
|
48
|
-
method: 'POST',
|
|
49
|
-
headers: { 'Content-Type': 'application/json' },
|
|
50
|
-
body: JSON.stringify(payload),
|
|
51
|
-
signal: AbortSignal.timeout(5000),
|
|
52
|
-
});
|
|
53
|
-
const data = await res.json();
|
|
54
|
-
return data;
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
58
|
-
throw new Error(`RPC test failed: ${errorMessage}`);
|
|
59
|
-
}
|
|
60
|
-
};
|