Skip to content

Commit 8058826

Browse files
committed
chore: final pre-audit fixes
1 parent bb1c4c2 commit 8058826

File tree

9 files changed

+395
-44
lines changed

9 files changed

+395
-44
lines changed

packages/api/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import type http from 'http';
1313
import custodianRequests from './custodian/requests';
1414
import { methodMapping } from './method-mapping';
1515
import doc from './openrpc.json';
16+
import clearRequestsHandler from './routes/clearRequestsHandler';
1617
import listRequestsHandler from './routes/listRequestsHandler';
1718
import tokenHandler from './routes/token-handler';
1819
import type { UpdateSignedMessageRequest } from './routes/updateSignedMessageHandler';
1920
import updateSignedMessageHandler from './routes/updateSignedMessageHandler';
2021
import type { UpdateTransactionRequest } from './routes/updateTransactionHandler';
2122
import updateTransactionHandler from './routes/updateTransactionHandler';
22-
import clearRequestsHandler from './routes/clearRequestsHandler';
2323

2424
dotenv.config();
2525

packages/snap/src/features/homepage/components/CustodianList.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const CustodianList: SnapComponent<CustodianListProps> = ({
7070
solution
7171
</Text>
7272
{custodianMetadata
73-
.filter((custodian) => custodian.enabled)
73+
.filter((custodian) => custodian.production)
7474
.map((custodian) => (
7575
<Section
7676
key={custodian.name}

packages/snap/src/index.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
/* eslint-disable @typescript-eslint/no-throw-literal */
12
import type { JsonRpcRequest } from '@metamask/keyring-api';
23
import {
3-
MethodNotSupportedError,
4+
KeyringRequestStruct,
45
handleKeyringRequest,
56
} from '@metamask/keyring-api';
67
import {
@@ -9,6 +10,7 @@ import {
910
type OnUserInputHandler,
1011
type OnHomePageHandler,
1112
UnauthorizedError,
13+
MethodNotFoundError,
1214
} from '@metamask/snaps-sdk';
1315
import type {
1416
Json,
@@ -156,17 +158,17 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
156158
const requestManager = await getRequestManager();
157159
return await requestManager.clearAllRequests();
158160
}
159-
throw new MethodNotSupportedError(request.method);
161+
throw new MethodNotFoundError(request.method);
160162
}
161163

162164
default: {
163-
throw new MethodNotSupportedError(request.method); // @audit-info or MethodNotFoundError 👉 https://docs.metamask.io/snaps/how-to/communicate-errors/#import-and-throw-errors
165+
throw new MethodNotFoundError(request.method);
164166
}
165167
}
166168
};
167169

168170
export const onKeyringRequest: OnKeyringRequestHandler = async ({
169-
origin, // @audit specify ts types
171+
origin,
170172
request,
171173
}: {
172174
origin: string;
@@ -177,16 +179,17 @@ export const onKeyringRequest: OnKeyringRequestHandler = async ({
177179
JSON.stringify(request, undefined, 2),
178180
);
179181

182+
assert(request, KeyringRequestStruct);
183+
180184
// Check if origin is allowed to call method.
181185
if (!hasPermission(origin, request.method)) {
182-
// @audit - enforce runtime type/input validation! user superstruct from metamask
183186
throw new Error(
184187
`Origin '${origin}' is not allowed to call '${request.method}'`,
185188
);
186189
}
187190

188-
// Handle keyring methods.
189-
return handleKeyringRequest(await getKeyring(), request); // @audit - handleKeyringRequest is async, might req. await? (else returns promise of promise? dblcheck with MM team)
191+
const keyring = await getKeyring();
192+
return handleKeyringRequest(keyring, request);
190193
};
191194

192195
// Improved polling function

0 commit comments

Comments
 (0)