Skip to content

Commit 3167ed1

Browse files
committed
remove admin methods
1 parent ab1960a commit 3167ed1

File tree

2 files changed

+0
-89
lines changed

2 files changed

+0
-89
lines changed

src/index.tsx

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ import {
2323
validate,
2424
} from './types';
2525
import {
26-
assertAdminOrigin,
2726
buildTransactionBlock,
2827
calcTotalGasFeesDec,
2928
getFullnodeUrlForChain,
3029
getStoredState,
3130
updateState,
32-
validateFullnodeUrl,
3331
} from './util';
3432
import { signPersonalMessage, signTxBlock, getAccountInfo, signAndExecuteTransaction } from './keypair-ops';
3533
import { genBalanceChangesSection, genOperationsSection } from './iota-utils';
@@ -212,55 +210,6 @@ export const onRpcRequest: OnRpcRequestHandler = async ({ origin, request }) =>
212210
return ret;
213211
}
214212

215-
case 'admin_getStoredState': {
216-
assertAdminOrigin(origin);
217-
const ret = await getStoredState();
218-
return ret;
219-
}
220-
221-
case 'admin_setFullnodeUrl': {
222-
assertAdminOrigin(origin);
223-
const [validationError, params] = validate(request.params, SerializedAdminSetFullnodeUrl);
224-
if (validationError !== undefined) {
225-
throw InvalidParamsError.asSimpleError(validationError.message);
226-
}
227-
try {
228-
validateFullnodeUrl(params.url);
229-
} catch (error) {
230-
throw InvalidParamsError.asSimpleError(`Invalid fullnode URL: ${(error as Error).message}`);
231-
}
232-
const response = await snap.request({
233-
method: 'snap_dialog',
234-
params: {
235-
type: 'confirmation',
236-
content: (
237-
<Box>
238-
<Heading>⚠️ Change Network Node URL</Heading>
239-
<Text>**{origin}** is requesting to change the **{params.network}** network node URL.</Text>
240-
<Divider />
241-
<Text>**New URL:** {params.url}</Text>
242-
<Divider />
243-
<Text>⚠️ **Warning**: Changing the node URL can affect your wallet's view of the blockchain. Only approve if you trust this source and the new URL.</Text>
244-
<Text>Malicious nodes could show incorrect balances or transaction data.</Text>
245-
</Box>
246-
),
247-
},
248-
});
249-
if (response !== true) {
250-
throw UserRejectionError.asSimpleError();
251-
}
252-
const state = await getStoredState();
253-
switch (params.network) {
254-
case 'mainnet': state.mainnetUrl = params.url; break;
255-
case 'testnet': state.testnetUrl = params.url; break;
256-
case 'devnet': state.devnetUrl = params.url; break;
257-
case 'localnet': state.localnetUrl = params.url; break;
258-
default: break;
259-
}
260-
await updateState(state);
261-
return { success: true };
262-
}
263-
264213
default:
265214
throw InvalidRequestMethodError.asSimpleError(request.method);
266215
}

src/util.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,44 +40,6 @@ const DEFAULT_TESTNET_URL = getFullnodeUrl('testnet');
4040
const DEFAULT_DEVNET_URL = getFullnodeUrl('devnet');
4141
const DEFAULT_LOCALNET_URL = getFullnodeUrl('localnet');
4242

43-
export function assertAdminOrigin(origin: string): void {
44-
if (origin !== 'http://localhost:8000') {
45-
throw new Error('Unauthorized: Admin-only method');
46-
}
47-
}
48-
49-
export function validateFullnodeUrl(url: string): void {
50-
try {
51-
const parsedUrl = new URL(url);
52-
if (!['https:', 'http:'].includes(parsedUrl.protocol)) {
53-
throw new Error('Invalid protocol: Only HTTP and HTTPS are allowed');
54-
}
55-
const hostname = parsedUrl.hostname.toLowerCase();
56-
if (hostname.length === 0) throw new Error('Invalid hostname');
57-
if (hostname === 'localhost') return;
58-
const isPrivateIP =
59-
hostname === '127.0.0.1' ||
60-
hostname.startsWith('192.168.') ||
61-
hostname.startsWith('10.') ||
62-
isPrivate172Range(hostname);
63-
if (isPrivateIP) throw new Error('Private IP addresses are not allowed for fullnode URLs');
64-
} catch (error) {
65-
if (error instanceof TypeError) {
66-
throw new Error('Invalid URL format');
67-
}
68-
throw error;
69-
}
70-
}
71-
72-
function isPrivate172Range(hostname: string): boolean {
73-
const parts = hostname.split('.');
74-
if (parts.length !== 4 || parts[0] !== '172') return false
75-
const secondOctet = parts[1];
76-
if (!secondOctet) return false;
77-
const octetNum = parseInt(secondOctet, 10);
78-
return !isNaN(octetNum) && octetNum >= 16 && octetNum <= 31;
79-
}
80-
8143
export async function getFullnodeUrlForChain(chain: string): Promise<string> {
8244
const state = await getStoredState();
8345
switch (chain) {

0 commit comments

Comments
 (0)