Skip to content

Commit e8f49c7

Browse files
fix: Add missing WS types and allow local URLs
1 parent 1f4fc7a commit e8f49c7

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

packages/snaps-rpc-methods/src/permitted/openWebSocket.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ describe('snap_openWebSocket', () => {
8888
id: 1,
8989
method: 'snap_openWebSocket',
9090
params: {
91-
url: 'ws://metamask.io',
91+
url: 'http://metamask.io',
9292
},
9393
});
9494

9595
expect(response).toStrictEqual({
9696
error: {
9797
code: -32602,
9898
message:
99-
'Invalid params: At path: url -- Expected URL, got "ws://metamask.io"..',
99+
'Invalid params: At path: url -- Expected URL, got "http://metamask.io"..',
100100
stack: expect.any(String),
101101
},
102102
id: 1,

packages/snaps-rpc-methods/src/permitted/openWebSocket.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { PermittedHandlerExport } from '@metamask/permission-controller';
33
import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
44
import {
55
literal,
6+
union,
67
type JsonRpcRequest,
78
type OpenWebSocketParams,
89
type OpenWebSocketResult,
@@ -32,7 +33,7 @@ export type OpenWebSocketMethodHooks = {
3233
};
3334

3435
const OpenWebSocketParametersStruct = object({
35-
url: uri({ protocol: literal('wss:') }),
36+
url: uri({ protocol: union([literal('wss:'), literal('ws:')]) }),
3637
protocols: optional(array(string())),
3738
});
3839

packages/snaps-sdk/src/types/methods/methods.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type {
33
CancelBackgroundEventResult,
44
} from './cancel-background-event';
55
import type { ClearStateParams, ClearStateResult } from './clear-state';
6+
import type {
7+
CloseWebSocketParams,
8+
CloseWebSocketResult,
9+
} from './close-web-socket';
610
import type {
711
CreateInterfaceParams,
812
CreateInterfaceResult,
@@ -49,6 +53,10 @@ import type {
4953
} from './get-preferences';
5054
import type { GetSnapsParams, GetSnapsResult } from './get-snaps';
5155
import type { GetStateParams, GetStateResult } from './get-state';
56+
import type {
57+
GetWebSocketsParams,
58+
GetWebSocketsResult,
59+
} from './get-web-sockets';
5260
import type {
5361
InvokeKeyringParams,
5462
InvokeKeyringResult,
@@ -64,6 +72,10 @@ import type {
6472
} from './manage-accounts';
6573
import type { ManageStateParams, ManageStateResult } from './manage-state';
6674
import type { NotifyParams, NotifyResult } from './notify';
75+
import type {
76+
OpenWebSocketParams,
77+
OpenWebSocketResult,
78+
} from './open-web-socket';
6779
import type { RequestSnapsParams, RequestSnapsResult } from './request-snaps';
6880
import type {
6981
ResolveInterfaceParams,
@@ -73,6 +85,10 @@ import type {
7385
ScheduleBackgroundEventParams,
7486
ScheduleBackgroundEventResult,
7587
} from './schedule-background-event';
88+
import type {
89+
SendWebSocketMessageParams,
90+
SendWebSocketMessageResult,
91+
} from './send-web-socket-message';
7692
import type { SetStateParams, SetStateResult } from './set-state';
7793
import type { TrackEventParams, TrackEventResult } from './track-event';
7894
import type {
@@ -125,6 +141,13 @@ export type SnapMethods = {
125141
snap_resolveInterface: [ResolveInterfaceParams, ResolveInterfaceResult];
126142
snap_setState: [SetStateParams, SetStateResult];
127143
snap_trackEvent: [TrackEventParams, TrackEventResult];
144+
snap_openWebSocket: [OpenWebSocketParams, OpenWebSocketResult];
145+
snap_closeWebSocket: [CloseWebSocketParams, CloseWebSocketResult];
146+
snap_getWebSockets: [GetWebSocketsParams, GetWebSocketsResult];
147+
snap_sendWebSocketMessage: [
148+
SendWebSocketMessageParams,
149+
SendWebSocketMessageResult,
150+
];
128151
wallet_getSnaps: [GetSnapsParams, GetSnapsResult];
129152
wallet_invokeKeyring: [InvokeKeyringParams, InvokeKeyringResult];
130153
wallet_invokeSnap: [InvokeSnapParams, InvokeSnapResult];

0 commit comments

Comments
 (0)