@octaflowlabs/onchain-sdk 1.2.0 → 1.2.1

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.
@@ -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');
@@ -22,7 +22,5 @@ export { NATIVE_TOKENS };
22
22
  export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
23
23
  export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
24
24
  export { normalizeAddress } from './utils/normalizeAddress';
25
- /** rpc exports */
26
- export { validateRpcUrl, ensurePublicHost, testJsonRpc } from './rpc/index';
27
25
  /** types exports */
28
26
  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.testJsonRpc = exports.ensurePublicHost = exports.validateRpcUrl = 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.MULTICALL3_ADDRESS = exports.GAS_LIMIT_PER_TX_TYPE = exports.ERC20_TOKEN_CONTRACT_ABI = void 0;
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.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;
@@ -50,8 +50,3 @@ Object.defineProperty(exports, "errorMessagesForBroadcast", { enumerable: true,
50
50
  Object.defineProperty(exports, "errorMessagesForGasLimitEstimation", { enumerable: true, get: function () { return handleErrorMessages_1.errorMessagesForGasLimitEstimation; } });
51
51
  var normalizeAddress_1 = require("./utils/normalizeAddress");
52
52
  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; } });
package/dist/index.d.ts CHANGED
@@ -22,7 +22,5 @@ export { NATIVE_TOKENS };
22
22
  export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
23
23
  export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
24
24
  export { normalizeAddress } from './utils/normalizeAddress';
25
- /** rpc exports */
26
- export { validateRpcUrl, ensurePublicHost, testJsonRpc } from './rpc/index';
27
25
  /** types exports */
28
26
  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
@@ -21,5 +21,3 @@ export { NATIVE_TOKENS };
21
21
  export { formattedAmountForDisplay, parsedAmount } from './utils/formatAmount';
22
22
  export { handleErrorMessages, errorMessagesForBroadcast, errorMessagesForGasLimitEstimation, } from './utils/handleErrorMessages';
23
23
  export { normalizeAddress } from './utils/normalizeAddress';
24
- /** rpc exports */
25
- export { validateRpcUrl, ensurePublicHost, testJsonRpc } from './rpc/index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octaflowlabs/onchain-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "onchain methods for web3",
5
5
  "repository": "https://github.com/crisramb665/onchain-sdk.git",
6
6
  "license": "MIT",
@@ -1,3 +0,0 @@
1
- export declare const validateRpcUrl: (rpcUrl: string, allowLocal?: boolean) => URL;
2
- export declare const ensurePublicHost: (rpcUrl: string) => Promise<boolean>;
3
- export declare const testJsonRpc: (rpcUrl: string, method?: string, params?: any[]) => Promise<unknown>;
@@ -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;
@@ -1,3 +0,0 @@
1
- export declare const validateRpcUrl: (rpcUrl: string, allowLocal?: boolean) => URL;
2
- export declare const ensurePublicHost: (rpcUrl: string) => Promise<boolean>;
3
- export declare const testJsonRpc: (rpcUrl: string, method?: string, params?: any[]) => Promise<unknown>;
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
- };