@metamask/snaps-rpc-methods 12.4.0 → 13.1.0
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/CHANGELOG.md +18 -1
- package/dist/endowments/index.cjs +2 -0
- package/dist/endowments/index.cjs.map +1 -1
- package/dist/endowments/index.d.cts.map +1 -1
- package/dist/endowments/index.d.mts.map +1 -1
- package/dist/endowments/index.mjs +2 -0
- package/dist/endowments/index.mjs.map +1 -1
- package/dist/permitted/closeWebSocket.cjs +70 -0
- package/dist/permitted/closeWebSocket.cjs.map +1 -0
- package/dist/permitted/closeWebSocket.d.cts +19 -0
- package/dist/permitted/closeWebSocket.d.cts.map +1 -0
- package/dist/permitted/closeWebSocket.d.mts +19 -0
- package/dist/permitted/closeWebSocket.d.mts.map +1 -0
- package/dist/permitted/closeWebSocket.mjs +67 -0
- package/dist/permitted/closeWebSocket.mjs.map +1 -0
- package/dist/permitted/getWebSockets.cjs +42 -0
- package/dist/permitted/getWebSockets.cjs.map +1 -0
- package/dist/permitted/getWebSockets.d.cts +11 -0
- package/dist/permitted/getWebSockets.d.cts.map +1 -0
- package/dist/permitted/getWebSockets.d.mts +11 -0
- package/dist/permitted/getWebSockets.d.mts.map +1 -0
- package/dist/permitted/getWebSockets.mjs +39 -0
- package/dist/permitted/getWebSockets.mjs.map +1 -0
- package/dist/permitted/handlers.cjs +8 -0
- package/dist/permitted/handlers.cjs.map +1 -1
- package/dist/permitted/handlers.d.cts +6 -2
- package/dist/permitted/handlers.d.cts.map +1 -1
- package/dist/permitted/handlers.d.mts +6 -2
- package/dist/permitted/handlers.d.mts.map +1 -1
- package/dist/permitted/handlers.mjs +8 -0
- package/dist/permitted/handlers.mjs.map +1 -1
- package/dist/permitted/index.cjs.map +1 -1
- package/dist/permitted/index.d.cts +5 -1
- package/dist/permitted/index.d.cts.map +1 -1
- package/dist/permitted/index.d.mts +5 -1
- package/dist/permitted/index.d.mts.map +1 -1
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/openWebSocket.cjs +72 -0
- package/dist/permitted/openWebSocket.cjs.map +1 -0
- package/dist/permitted/openWebSocket.d.cts +21 -0
- package/dist/permitted/openWebSocket.d.cts.map +1 -0
- package/dist/permitted/openWebSocket.d.mts +21 -0
- package/dist/permitted/openWebSocket.d.mts.map +1 -0
- package/dist/permitted/openWebSocket.mjs +69 -0
- package/dist/permitted/openWebSocket.mjs.map +1 -0
- package/dist/permitted/scheduleBackgroundEvent.cjs +13 -15
- package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.mjs +15 -17
- package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/sendWebSocketMessage.cjs +72 -0
- package/dist/permitted/sendWebSocketMessage.cjs.map +1 -0
- package/dist/permitted/sendWebSocketMessage.d.cts +21 -0
- package/dist/permitted/sendWebSocketMessage.d.cts.map +1 -0
- package/dist/permitted/sendWebSocketMessage.d.mts +21 -0
- package/dist/permitted/sendWebSocketMessage.d.mts.map +1 -0
- package/dist/permitted/sendWebSocketMessage.mjs +69 -0
- package/dist/permitted/sendWebSocketMessage.mjs.map +1 -0
- package/package.json +7 -9
|
@@ -45,8 +45,12 @@ export declare const methodHandlers: {
|
|
|
45
45
|
snap_getBackgroundEvents: import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult>;
|
|
46
46
|
snap_setState: import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null>;
|
|
47
47
|
snap_trackEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.cjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>;
|
|
48
|
+
snap_openWebSocket: import("@metamask/permission-controller").PermittedHandlerExport<import("./openWebSocket.cjs").OpenWebSocketMethodHooks, import("@metamask/snaps-sdk").OpenWebSocketParams, string>;
|
|
49
|
+
snap_closeWebSocket: import("@metamask/permission-controller").PermittedHandlerExport<import("./closeWebSocket.cjs").CloseWebSocketMethodHooks, import("@metamask/snaps-sdk").CloseWebSocketParams, null>;
|
|
50
|
+
snap_sendWebSocketMessage: import("@metamask/permission-controller").PermittedHandlerExport<import("./sendWebSocketMessage.cjs").SendWebSocketMessageMethodHooks, import("@metamask/snaps-sdk").SendWebSocketMessageParams, null>;
|
|
51
|
+
snap_getWebSockets: import("@metamask/permission-controller").PermittedHandlerExport<import("./getWebSockets.cjs").GetWebSocketsMethodHooks, never, import("@metamask/snaps-sdk").GetWebSocketsResult>;
|
|
48
52
|
};
|
|
49
|
-
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.cjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
53
|
+
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.cjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./closeWebSocket.cjs").CloseWebSocketMethodHooks, import("@metamask/snaps-sdk").CloseWebSocketParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
50
54
|
addresses: `${string}:${string}:${string}`[];
|
|
51
55
|
accountId: string;
|
|
52
56
|
} | {
|
|
@@ -70,5 +74,5 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
|
|
|
70
74
|
symbol: string;
|
|
71
75
|
name: string;
|
|
72
76
|
asset: `${string}:${string}/${string}:${string}`;
|
|
73
|
-
} | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.cjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.cjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.cjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.cjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.cjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>)[];
|
|
77
|
+
} | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.cjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.cjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getWebSockets.cjs").GetWebSocketsMethodHooks, never, import("@metamask/snaps-sdk").GetWebSocketsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.cjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./openWebSocket.cjs").OpenWebSocketMethodHooks, import("@metamask/snaps-sdk").OpenWebSocketParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.cjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./sendWebSocketMessage.cjs").SendWebSocketMessageMethodHooks, import("@metamask/snaps-sdk").SendWebSocketMessageParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.cjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>)[];
|
|
74
78
|
//# sourceMappingURL=handlers.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;m9FAAgC,CAAC"}
|
|
@@ -45,8 +45,12 @@ export declare const methodHandlers: {
|
|
|
45
45
|
snap_getBackgroundEvents: import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult>;
|
|
46
46
|
snap_setState: import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null>;
|
|
47
47
|
snap_trackEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.mjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>;
|
|
48
|
+
snap_openWebSocket: import("@metamask/permission-controller").PermittedHandlerExport<import("./openWebSocket.mjs").OpenWebSocketMethodHooks, import("@metamask/snaps-sdk").OpenWebSocketParams, string>;
|
|
49
|
+
snap_closeWebSocket: import("@metamask/permission-controller").PermittedHandlerExport<import("./closeWebSocket.mjs").CloseWebSocketMethodHooks, import("@metamask/snaps-sdk").CloseWebSocketParams, null>;
|
|
50
|
+
snap_sendWebSocketMessage: import("@metamask/permission-controller").PermittedHandlerExport<import("./sendWebSocketMessage.mjs").SendWebSocketMessageMethodHooks, import("@metamask/snaps-sdk").SendWebSocketMessageParams, null>;
|
|
51
|
+
snap_getWebSockets: import("@metamask/permission-controller").PermittedHandlerExport<import("./getWebSockets.mjs").GetWebSocketsMethodHooks, never, import("@metamask/snaps-sdk").GetWebSocketsResult>;
|
|
48
52
|
};
|
|
49
|
-
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.mjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
53
|
+
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.mjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./closeWebSocket.mjs").CloseWebSocketMethodHooks, import("@metamask/snaps-sdk").CloseWebSocketParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
|
|
50
54
|
addresses: `${string}:${string}:${string}`[];
|
|
51
55
|
accountId: string;
|
|
52
56
|
} | {
|
|
@@ -70,5 +74,5 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
|
|
|
70
74
|
symbol: string;
|
|
71
75
|
name: string;
|
|
72
76
|
asset: `${string}:${string}/${string}:${string}`;
|
|
73
|
-
} | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.mjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.mjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.mjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.mjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.mjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>)[];
|
|
77
|
+
} | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.mjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.mjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getWebSockets.mjs").GetWebSocketsMethodHooks, never, import("@metamask/snaps-sdk").GetWebSocketsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.mjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./openWebSocket.mjs").OpenWebSocketMethodHooks, import("@metamask/snaps-sdk").OpenWebSocketParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.mjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./sendWebSocketMessage.mjs").SendWebSocketMessageMethodHooks, import("@metamask/snaps-sdk").SendWebSocketMessageParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.mjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>)[];
|
|
74
78
|
//# sourceMappingURL=handlers.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2B1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;m9FAAgC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { cancelBackgroundEventHandler } from "./cancelBackgroundEvent.mjs";
|
|
2
2
|
import { clearStateHandler } from "./clearState.mjs";
|
|
3
|
+
import { closeWebSocketHandler } from "./closeWebSocket.mjs";
|
|
3
4
|
import { createInterfaceHandler } from "./createInterface.mjs";
|
|
4
5
|
import { providerRequestHandler } from "./experimentalProviderRequest.mjs";
|
|
5
6
|
import { getAllSnapsHandler } from "./getAllSnaps.mjs";
|
|
@@ -11,12 +12,15 @@ import { getInterfaceContextHandler } from "./getInterfaceContext.mjs";
|
|
|
11
12
|
import { getInterfaceStateHandler } from "./getInterfaceState.mjs";
|
|
12
13
|
import { getSnapsHandler } from "./getSnaps.mjs";
|
|
13
14
|
import { getStateHandler } from "./getState.mjs";
|
|
15
|
+
import { getWebSocketsHandler } from "./getWebSockets.mjs";
|
|
14
16
|
import { invokeKeyringHandler } from "./invokeKeyring.mjs";
|
|
15
17
|
import { invokeSnapSugarHandler } from "./invokeSnapSugar.mjs";
|
|
16
18
|
import { listEntropySourcesHandler } from "./listEntropySources.mjs";
|
|
19
|
+
import { openWebSocketHandler } from "./openWebSocket.mjs";
|
|
17
20
|
import { requestSnapsHandler } from "./requestSnaps.mjs";
|
|
18
21
|
import { resolveInterfaceHandler } from "./resolveInterface.mjs";
|
|
19
22
|
import { scheduleBackgroundEventHandler } from "./scheduleBackgroundEvent.mjs";
|
|
23
|
+
import { sendWebSocketMessageHandler } from "./sendWebSocketMessage.mjs";
|
|
20
24
|
import { setStateHandler } from "./setState.mjs";
|
|
21
25
|
import { trackEventHandler } from "./trackEvent.mjs";
|
|
22
26
|
import { updateInterfaceHandler } from "./updateInterface.mjs";
|
|
@@ -44,6 +48,10 @@ export const methodHandlers = {
|
|
|
44
48
|
snap_getBackgroundEvents: getBackgroundEventsHandler,
|
|
45
49
|
snap_setState: setStateHandler,
|
|
46
50
|
snap_trackEvent: trackEventHandler,
|
|
51
|
+
snap_openWebSocket: openWebSocketHandler,
|
|
52
|
+
snap_closeWebSocket: closeWebSocketHandler,
|
|
53
|
+
snap_sendWebSocketMessage: sendWebSocketMessageHandler,
|
|
54
|
+
snap_getWebSockets: getWebSocketsHandler,
|
|
47
55
|
};
|
|
48
56
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
49
57
|
export const handlers = Object.values(methodHandlers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.mjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,oCAAgC;AACvE,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AACjD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAA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O,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AACjD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,mBAAmB;IACxC,iBAAiB,EAAE,sBAAsB;IACzC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,eAAe;IAC9B,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,wBAAwB,EAAE,0BAA0B;IACpD,uBAAuB,EAAE,yBAAyB;IAClD,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,gCAAgC,EAAE,sBAAsB;IACxD,4BAA4B,EAAE,8BAA8B;IAC5D,0BAA0B,EAAE,4BAA4B;IACxD,wBAAwB,EAAE,0BAA0B;IACpD,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,kBAAkB,EAAE,oBAAoB;IACxC,mBAAmB,EAAE,qBAAqB;IAC1C,yBAAyB,EAAE,2BAA2B;IACtD,kBAAkB,EAAE,oBAAoB;CACzC,CAAC;AACF,wDAAwD;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { cancelBackgroundEventHandler } from './cancelBackgroundEvent';\nimport { clearStateHandler } from './clearState';\nimport { closeWebSocketHandler } from './closeWebSocket';\nimport { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getBackgroundEventsHandler } from './getBackgroundEvents';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { getStateHandler } from './getState';\nimport { getWebSocketsHandler } from './getWebSockets';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { listEntropySourcesHandler } from './listEntropySources';\nimport { openWebSocketHandler } from './openWebSocket';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { scheduleBackgroundEventHandler } from './scheduleBackgroundEvent';\nimport { sendWebSocketMessageHandler } from './sendWebSocketMessage';\nimport { setStateHandler } from './setState';\nimport { trackEventHandler } from './trackEvent';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_clearState: clearStateHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_getState: getStateHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_listEntropySources: listEntropySourcesHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n snap_scheduleBackgroundEvent: scheduleBackgroundEventHandler,\n snap_cancelBackgroundEvent: cancelBackgroundEventHandler,\n snap_getBackgroundEvents: getBackgroundEventsHandler,\n snap_setState: setStateHandler,\n snap_trackEvent: trackEventHandler,\n snap_openWebSocket: openWebSocketHandler,\n snap_closeWebSocket: closeWebSocketHandler,\n snap_sendWebSocketMessage: sendWebSocketMessageHandler,\n snap_getWebSockets: getWebSocketsHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA4CA,iDAA2B;AAC3B,mDAA6B","sourcesContent":["import type { CancelBackgroundEventMethodHooks } from './cancelBackgroundEvent';\nimport type { ClearStateHooks } from './clearState';\nimport type { CloseWebSocketMethodHooks } from './closeWebSocket';\nimport type { CreateInterfaceMethodHooks } from './createInterface';\nimport type { ProviderRequestMethodHooks } from './experimentalProviderRequest';\nimport type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetBackgroundEventsMethodHooks } from './getBackgroundEvents';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetCurrencyRateMethodHooks } from './getCurrencyRate';\nimport type { GetInterfaceStateMethodHooks } from './getInterfaceState';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { GetStateHooks } from './getState';\nimport type { GetWebSocketsMethodHooks } from './getWebSockets';\nimport type { ListEntropySourcesHooks } from './listEntropySources';\nimport type { OpenWebSocketMethodHooks } from './openWebSocket';\nimport type { RequestSnapsHooks } from './requestSnaps';\nimport type { ResolveInterfaceMethodHooks } from './resolveInterface';\nimport type { ScheduleBackgroundEventMethodHooks } from './scheduleBackgroundEvent';\nimport type { SendWebSocketMessageMethodHooks } from './sendWebSocketMessage';\nimport type { SetStateHooks } from './setState';\nimport type { UpdateInterfaceMethodHooks } from './updateInterface';\n\nexport type PermittedRpcMethodHooks = ClearStateHooks &\n GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n GetStateHooks &\n ListEntropySourcesHooks &\n RequestSnapsHooks &\n CreateInterfaceMethodHooks &\n UpdateInterfaceMethodHooks &\n GetInterfaceStateMethodHooks &\n ResolveInterfaceMethodHooks &\n GetCurrencyRateMethodHooks &\n ProviderRequestMethodHooks &\n ScheduleBackgroundEventMethodHooks &\n CancelBackgroundEventMethodHooks &\n GetBackgroundEventsMethodHooks &\n SetStateHooks &\n OpenWebSocketMethodHooks &\n CloseWebSocketMethodHooks &\n SendWebSocketMessageMethodHooks &\n GetWebSocketsMethodHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CancelBackgroundEventMethodHooks } from "./cancelBackgroundEvent.cjs";
|
|
2
2
|
import type { ClearStateHooks } from "./clearState.cjs";
|
|
3
|
+
import type { CloseWebSocketMethodHooks } from "./closeWebSocket.cjs";
|
|
3
4
|
import type { CreateInterfaceMethodHooks } from "./createInterface.cjs";
|
|
4
5
|
import type { ProviderRequestMethodHooks } from "./experimentalProviderRequest.cjs";
|
|
5
6
|
import type { GetAllSnapsHooks } from "./getAllSnaps.cjs";
|
|
@@ -9,13 +10,16 @@ import type { GetCurrencyRateMethodHooks } from "./getCurrencyRate.cjs";
|
|
|
9
10
|
import type { GetInterfaceStateMethodHooks } from "./getInterfaceState.cjs";
|
|
10
11
|
import type { GetSnapsHooks } from "./getSnaps.cjs";
|
|
11
12
|
import type { GetStateHooks } from "./getState.cjs";
|
|
13
|
+
import type { GetWebSocketsMethodHooks } from "./getWebSockets.cjs";
|
|
12
14
|
import type { ListEntropySourcesHooks } from "./listEntropySources.cjs";
|
|
15
|
+
import type { OpenWebSocketMethodHooks } from "./openWebSocket.cjs";
|
|
13
16
|
import type { RequestSnapsHooks } from "./requestSnaps.cjs";
|
|
14
17
|
import type { ResolveInterfaceMethodHooks } from "./resolveInterface.cjs";
|
|
15
18
|
import type { ScheduleBackgroundEventMethodHooks } from "./scheduleBackgroundEvent.cjs";
|
|
19
|
+
import type { SendWebSocketMessageMethodHooks } from "./sendWebSocketMessage.cjs";
|
|
16
20
|
import type { SetStateHooks } from "./setState.cjs";
|
|
17
21
|
import type { UpdateInterfaceMethodHooks } from "./updateInterface.cjs";
|
|
18
|
-
export type PermittedRpcMethodHooks = ClearStateHooks & GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & GetStateHooks & ListEntropySourcesHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks & ProviderRequestMethodHooks & ScheduleBackgroundEventMethodHooks & CancelBackgroundEventMethodHooks & GetBackgroundEventsMethodHooks & SetStateHooks;
|
|
22
|
+
export type PermittedRpcMethodHooks = ClearStateHooks & GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & GetStateHooks & ListEntropySourcesHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks & ProviderRequestMethodHooks & ScheduleBackgroundEventMethodHooks & CancelBackgroundEventMethodHooks & GetBackgroundEventsMethodHooks & SetStateHooks & OpenWebSocketMethodHooks & CloseWebSocketMethodHooks & SendWebSocketMessageMethodHooks & GetWebSocketsMethodHooks;
|
|
19
23
|
export * from "./handlers.cjs";
|
|
20
24
|
export * from "./middleware.cjs";
|
|
21
25
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,oCAAgC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AACpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,0BAA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import type { CloseWebSocketMethodHooks } from "./closeWebSocket.mjs";
|
|
3
4
|
import type { CreateInterfaceMethodHooks } from "./createInterface.mjs";
|
|
4
5
|
import type { ProviderRequestMethodHooks } from "./experimentalProviderRequest.mjs";
|
|
5
6
|
import type { GetAllSnapsHooks } from "./getAllSnaps.mjs";
|
|
@@ -9,13 +10,16 @@ import type { GetCurrencyRateMethodHooks } from "./getCurrencyRate.mjs";
|
|
|
9
10
|
import type { GetInterfaceStateMethodHooks } from "./getInterfaceState.mjs";
|
|
10
11
|
import type { GetSnapsHooks } from "./getSnaps.mjs";
|
|
11
12
|
import type { GetStateHooks } from "./getState.mjs";
|
|
13
|
+
import type { GetWebSocketsMethodHooks } from "./getWebSockets.mjs";
|
|
12
14
|
import type { ListEntropySourcesHooks } from "./listEntropySources.mjs";
|
|
15
|
+
import type { OpenWebSocketMethodHooks } from "./openWebSocket.mjs";
|
|
13
16
|
import type { RequestSnapsHooks } from "./requestSnaps.mjs";
|
|
14
17
|
import type { ResolveInterfaceMethodHooks } from "./resolveInterface.mjs";
|
|
15
18
|
import type { ScheduleBackgroundEventMethodHooks } from "./scheduleBackgroundEvent.mjs";
|
|
19
|
+
import type { SendWebSocketMessageMethodHooks } from "./sendWebSocketMessage.mjs";
|
|
16
20
|
import type { SetStateHooks } from "./setState.mjs";
|
|
17
21
|
import type { UpdateInterfaceMethodHooks } from "./updateInterface.mjs";
|
|
18
|
-
export type PermittedRpcMethodHooks = ClearStateHooks & GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & GetStateHooks & ListEntropySourcesHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks & ProviderRequestMethodHooks & ScheduleBackgroundEventMethodHooks & CancelBackgroundEventMethodHooks & GetBackgroundEventsMethodHooks & SetStateHooks;
|
|
22
|
+
export type PermittedRpcMethodHooks = ClearStateHooks & GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & GetStateHooks & ListEntropySourcesHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks & ProviderRequestMethodHooks & ScheduleBackgroundEventMethodHooks & CancelBackgroundEventMethodHooks & GetBackgroundEventsMethodHooks & SetStateHooks & OpenWebSocketMethodHooks & CloseWebSocketMethodHooks & SendWebSocketMessageMethodHooks & GetWebSocketsMethodHooks;
|
|
19
23
|
export * from "./handlers.mjs";
|
|
20
24
|
export * from "./middleware.mjs";
|
|
21
25
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gCAAgC,EAAE,oCAAgC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AACpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,0CAAsC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAAsB;AACtD,OAAO,KAAK,EAAE,8BAA8B,EAAE,kCAA8B;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,gCAA4B;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,uBAAuB,EAAE,iCAA6B;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAuB;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,+BAA2B;AACtE,OAAO,KAAK,EAAE,kCAAkC,EAAE,sCAAkC;AACpF,OAAO,KAA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AO,KAAK,EAAE,kCAAkC,EAAE,sCAAkC;AACpF,OAAO,KAAK,EAAE,+BAA+B,EAAE,mCAA+B;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AAEpE,MAAM,MAAM,uBAAuB,GAAG,eAAe,GACnD,gBAAgB,GAChB,oBAAoB,GACpB,aAAa,GACb,aAAa,GACb,uBAAuB,GACvB,iBAAiB,GACjB,0BAA0B,GAC1B,0BAA0B,GAC1B,4BAA4B,GAC5B,2BAA2B,GAC3B,0BAA0B,GAC1B,0BAA0B,GAC1B,kCAAkC,GAClC,gCAAgC,GAChC,8BAA8B,GAC9B,aAAa,GACb,wBAAwB,GACxB,yBAAyB,GACzB,+BAA+B,GAC/B,wBAAwB,CAAC;AAE3B,+BAA2B;AAC3B,iCAA6B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AA4CA,+BAA2B;AAC3B,iCAA6B","sourcesContent":["import type { CancelBackgroundEventMethodHooks } from './cancelBackgroundEvent';\nimport type { ClearStateHooks } from './clearState';\nimport type { CloseWebSocketMethodHooks } from './closeWebSocket';\nimport type { CreateInterfaceMethodHooks } from './createInterface';\nimport type { ProviderRequestMethodHooks } from './experimentalProviderRequest';\nimport type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetBackgroundEventsMethodHooks } from './getBackgroundEvents';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetCurrencyRateMethodHooks } from './getCurrencyRate';\nimport type { GetInterfaceStateMethodHooks } from './getInterfaceState';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { GetStateHooks } from './getState';\nimport type { GetWebSocketsMethodHooks } from './getWebSockets';\nimport type { ListEntropySourcesHooks } from './listEntropySources';\nimport type { OpenWebSocketMethodHooks } from './openWebSocket';\nimport type { RequestSnapsHooks } from './requestSnaps';\nimport type { ResolveInterfaceMethodHooks } from './resolveInterface';\nimport type { ScheduleBackgroundEventMethodHooks } from './scheduleBackgroundEvent';\nimport type { SendWebSocketMessageMethodHooks } from './sendWebSocketMessage';\nimport type { SetStateHooks } from './setState';\nimport type { UpdateInterfaceMethodHooks } from './updateInterface';\n\nexport type PermittedRpcMethodHooks = ClearStateHooks &\n GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n GetStateHooks &\n ListEntropySourcesHooks &\n RequestSnapsHooks &\n CreateInterfaceMethodHooks &\n UpdateInterfaceMethodHooks &\n GetInterfaceStateMethodHooks &\n ResolveInterfaceMethodHooks &\n GetCurrencyRateMethodHooks &\n ProviderRequestMethodHooks &\n ScheduleBackgroundEventMethodHooks &\n CancelBackgroundEventMethodHooks &\n GetBackgroundEventsMethodHooks &\n SetStateHooks &\n OpenWebSocketMethodHooks &\n CloseWebSocketMethodHooks &\n SendWebSocketMessageMethodHooks &\n GetWebSocketsMethodHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openWebSocketHandler = void 0;
|
|
4
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
6
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
8
|
+
const endowments_1 = require("../endowments/index.cjs");
|
|
9
|
+
const hookNames = {
|
|
10
|
+
hasPermission: true,
|
|
11
|
+
openWebSocket: true,
|
|
12
|
+
};
|
|
13
|
+
const OpenWebSocketParametersStruct = (0, superstruct_1.object)({
|
|
14
|
+
url: (0, snaps_utils_1.uri)({ protocol: (0, snaps_sdk_1.union)([(0, snaps_sdk_1.literal)('wss:'), (0, snaps_sdk_1.literal)('ws:')]) }),
|
|
15
|
+
protocols: (0, superstruct_1.optional)((0, superstruct_1.array)((0, superstruct_1.string)())),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Handler for the `snap_openWebSocket` method.
|
|
19
|
+
*/
|
|
20
|
+
exports.openWebSocketHandler = {
|
|
21
|
+
methodNames: ['snap_openWebSocket'],
|
|
22
|
+
implementation: openWebSocketImplementation,
|
|
23
|
+
hookNames,
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* The `snap_openWebSocket` method implementation.
|
|
27
|
+
*
|
|
28
|
+
* @param req - The JSON-RPC request object.
|
|
29
|
+
* @param res - The JSON-RPC response object.
|
|
30
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this function.
|
|
31
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
32
|
+
* @param hooks - The RPC method hooks.
|
|
33
|
+
* @param hooks.hasPermission - The function to check if a snap has the `endowment:network-access` permission.
|
|
34
|
+
* @param hooks.openWebSocket - The function to open a WebSocket.
|
|
35
|
+
* @returns Nothing.
|
|
36
|
+
*/
|
|
37
|
+
async function openWebSocketImplementation(req, res, _next, end, { hasPermission, openWebSocket }) {
|
|
38
|
+
if (!hasPermission(endowments_1.SnapEndowments.NetworkAccess)) {
|
|
39
|
+
return end(rpc_errors_1.providerErrors.unauthorized());
|
|
40
|
+
}
|
|
41
|
+
const { params } = req;
|
|
42
|
+
try {
|
|
43
|
+
const { url, protocols } = getValidatedParams(params);
|
|
44
|
+
res.result = await openWebSocket(url, protocols);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return end(error);
|
|
48
|
+
}
|
|
49
|
+
return end();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validates the parameters for the snap_openWebSocket method.
|
|
53
|
+
*
|
|
54
|
+
* @param params - Parameters to validate.
|
|
55
|
+
* @returns Validated parameters.
|
|
56
|
+
* @throws Throws RPC error if validation fails.
|
|
57
|
+
*/
|
|
58
|
+
function getValidatedParams(params) {
|
|
59
|
+
try {
|
|
60
|
+
return (0, superstruct_1.create)(params, OpenWebSocketParametersStruct);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (error instanceof superstruct_1.StructError) {
|
|
64
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
65
|
+
message: `Invalid params: ${error.message}.`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/* istanbul ignore next */
|
|
69
|
+
throw rpc_errors_1.rpcErrors.internal();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=openWebSocket.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openWebSocket.cjs","sourceRoot":"","sources":["../../src/permitted/openWebSocket.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AACjE,mDAM6B;AAC7B,uDAAgE;AAChE,uDAO+B;AAG/B,wDAA+C;AAG/C,MAAM,SAAS,GAAgD;IAC7D,aAAa,EAAE,IAAI;IACnB,aAAa,EAAE,IAAI;CACpB,CAAC;AAOF,MAAM,6BAA6B,GAAG,IAAA,oBAAM,EAAC;IAC3C,GAAG,EAAE,IAAA,iBAAG,EAAC,EAAE,QAAQ,EAAE,IAAA,iBAAK,EAAC,CAAC,IAAA,mBAAO,EAAC,MAAM,CAAC,EAAE,IAAA,mBAAO,EAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC,CAAC;CACrC,CAAC,CAAC;AAOH;;GAEG;AACU,QAAA,oBAAoB,GAI7B;IACF,WAAW,EAAE,CAAC,oBAAoB,CAAC;IACnC,cAAc,EAAE,2BAA2B;IAC3C,SAAS;CACV,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,2BAA2B,CACxC,GAA4C,EAC5C,GAAgD,EAChD,KAAc,EACd,GAA6B,EAC7B,EAAE,aAAa,EAAE,aAAa,EAA4B;IAE1D,IAAI,CAAC,aAAa,CAAC,2BAAc,CAAC,aAAa,CAAC,EAAE,CAAC;QACjD,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QACtD,GAAG,CAAC,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n literal,\n union,\n type JsonRpcRequest,\n type OpenWebSocketParams,\n type OpenWebSocketResult,\n} from '@metamask/snaps-sdk';\nimport { uri, type InferMatching } from '@metamask/snaps-utils';\nimport {\n create,\n object,\n array,\n string,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<OpenWebSocketMethodHooks> = {\n hasPermission: true,\n openWebSocket: true,\n};\n\nexport type OpenWebSocketMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n openWebSocket: (url: string, protocols?: string[]) => Promise<string>;\n};\n\nconst OpenWebSocketParametersStruct = object({\n url: uri({ protocol: union([literal('wss:'), literal('ws:')]) }),\n protocols: optional(array(string())),\n});\n\nexport type OpenWebSocketParameters = InferMatching<\n typeof OpenWebSocketParametersStruct,\n OpenWebSocketParams\n>;\n\n/**\n * Handler for the `snap_openWebSocket` method.\n */\nexport const openWebSocketHandler: PermittedHandlerExport<\n OpenWebSocketMethodHooks,\n OpenWebSocketParams,\n OpenWebSocketResult\n> = {\n methodNames: ['snap_openWebSocket'],\n implementation: openWebSocketImplementation,\n hookNames,\n};\n\n/**\n * The `snap_openWebSocket` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if a snap has the `endowment:network-access` permission.\n * @param hooks.openWebSocket - The function to open a WebSocket.\n * @returns Nothing.\n */\nasync function openWebSocketImplementation(\n req: JsonRpcRequest<OpenWebSocketParameters>,\n res: PendingJsonRpcResponse<OpenWebSocketResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, openWebSocket }: OpenWebSocketMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.NetworkAccess)) {\n return end(providerErrors.unauthorized());\n }\n\n const { params } = req;\n\n try {\n const { url, protocols } = getValidatedParams(params);\n res.result = await openWebSocket(url, protocols);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validates the parameters for the snap_openWebSocket method.\n *\n * @param params - Parameters to validate.\n * @returns Validated parameters.\n * @throws Throws RPC error if validation fails.\n */\nfunction getValidatedParams(params: unknown): OpenWebSocketParameters {\n try {\n return create(params, OpenWebSocketParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
+
import { type OpenWebSocketParams, type OpenWebSocketResult } from "@metamask/snaps-sdk";
|
|
3
|
+
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
|
+
export type OpenWebSocketMethodHooks = {
|
|
5
|
+
hasPermission: (permissionName: string) => boolean;
|
|
6
|
+
openWebSocket: (url: string, protocols?: string[]) => Promise<string>;
|
|
7
|
+
};
|
|
8
|
+
declare const OpenWebSocketParametersStruct: import("@metamask/superstruct").Struct<{
|
|
9
|
+
url: string;
|
|
10
|
+
protocols?: string[] | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
url: import("@metamask/superstruct").Struct<string, null>;
|
|
13
|
+
protocols: import("@metamask/superstruct").Struct<string[] | undefined, import("@metamask/superstruct").Struct<string, null>>;
|
|
14
|
+
}>;
|
|
15
|
+
export type OpenWebSocketParameters = InferMatching<typeof OpenWebSocketParametersStruct, OpenWebSocketParams>;
|
|
16
|
+
/**
|
|
17
|
+
* Handler for the `snap_openWebSocket` method.
|
|
18
|
+
*/
|
|
19
|
+
export declare const openWebSocketHandler: PermittedHandlerExport<OpenWebSocketMethodHooks, OpenWebSocketParams, OpenWebSocketResult>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=openWebSocket.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openWebSocket.d.cts","sourceRoot":"","sources":["../../src/permitted/openWebSocket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,4BAA4B;AAC7B,OAAO,EAAO,KAAK,aAAa,EAAE,8BAA8B;AAmBhE,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,6BAA6B;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,aAAa,CACjD,OAAO,6BAA6B,EACpC,mBAAmB,CACpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,sBAAsB,CACvD,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,CAKpB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
+
import { type OpenWebSocketParams, type OpenWebSocketResult } from "@metamask/snaps-sdk";
|
|
3
|
+
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
|
+
export type OpenWebSocketMethodHooks = {
|
|
5
|
+
hasPermission: (permissionName: string) => boolean;
|
|
6
|
+
openWebSocket: (url: string, protocols?: string[]) => Promise<string>;
|
|
7
|
+
};
|
|
8
|
+
declare const OpenWebSocketParametersStruct: import("@metamask/superstruct").Struct<{
|
|
9
|
+
url: string;
|
|
10
|
+
protocols?: string[] | undefined;
|
|
11
|
+
}, {
|
|
12
|
+
url: import("@metamask/superstruct").Struct<string, null>;
|
|
13
|
+
protocols: import("@metamask/superstruct").Struct<string[] | undefined, import("@metamask/superstruct").Struct<string, null>>;
|
|
14
|
+
}>;
|
|
15
|
+
export type OpenWebSocketParameters = InferMatching<typeof OpenWebSocketParametersStruct, OpenWebSocketParams>;
|
|
16
|
+
/**
|
|
17
|
+
* Handler for the `snap_openWebSocket` method.
|
|
18
|
+
*/
|
|
19
|
+
export declare const openWebSocketHandler: PermittedHandlerExport<OpenWebSocketMethodHooks, OpenWebSocketParams, OpenWebSocketResult>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=openWebSocket.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openWebSocket.d.mts","sourceRoot":"","sources":["../../src/permitted/openWebSocket.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,4BAA4B;AAC7B,OAAO,EAAO,KAAK,aAAa,EAAE,8BAA8B;AAmBhE,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,6BAA6B;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,aAAa,CACjD,OAAO,6BAA6B,EACpC,mBAAmB,CACpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,sBAAsB,CACvD,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,CAKpB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
+
import { literal, union } from "@metamask/snaps-sdk";
|
|
3
|
+
import { uri } from "@metamask/snaps-utils";
|
|
4
|
+
import { create, object, array, string, optional, StructError } from "@metamask/superstruct";
|
|
5
|
+
import { SnapEndowments } from "../endowments/index.mjs";
|
|
6
|
+
const hookNames = {
|
|
7
|
+
hasPermission: true,
|
|
8
|
+
openWebSocket: true,
|
|
9
|
+
};
|
|
10
|
+
const OpenWebSocketParametersStruct = object({
|
|
11
|
+
url: uri({ protocol: union([literal('wss:'), literal('ws:')]) }),
|
|
12
|
+
protocols: optional(array(string())),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Handler for the `snap_openWebSocket` method.
|
|
16
|
+
*/
|
|
17
|
+
export const openWebSocketHandler = {
|
|
18
|
+
methodNames: ['snap_openWebSocket'],
|
|
19
|
+
implementation: openWebSocketImplementation,
|
|
20
|
+
hookNames,
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The `snap_openWebSocket` method implementation.
|
|
24
|
+
*
|
|
25
|
+
* @param req - The JSON-RPC request object.
|
|
26
|
+
* @param res - The JSON-RPC response object.
|
|
27
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this function.
|
|
28
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
29
|
+
* @param hooks - The RPC method hooks.
|
|
30
|
+
* @param hooks.hasPermission - The function to check if a snap has the `endowment:network-access` permission.
|
|
31
|
+
* @param hooks.openWebSocket - The function to open a WebSocket.
|
|
32
|
+
* @returns Nothing.
|
|
33
|
+
*/
|
|
34
|
+
async function openWebSocketImplementation(req, res, _next, end, { hasPermission, openWebSocket }) {
|
|
35
|
+
if (!hasPermission(SnapEndowments.NetworkAccess)) {
|
|
36
|
+
return end(providerErrors.unauthorized());
|
|
37
|
+
}
|
|
38
|
+
const { params } = req;
|
|
39
|
+
try {
|
|
40
|
+
const { url, protocols } = getValidatedParams(params);
|
|
41
|
+
res.result = await openWebSocket(url, protocols);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return end(error);
|
|
45
|
+
}
|
|
46
|
+
return end();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Validates the parameters for the snap_openWebSocket method.
|
|
50
|
+
*
|
|
51
|
+
* @param params - Parameters to validate.
|
|
52
|
+
* @returns Validated parameters.
|
|
53
|
+
* @throws Throws RPC error if validation fails.
|
|
54
|
+
*/
|
|
55
|
+
function getValidatedParams(params) {
|
|
56
|
+
try {
|
|
57
|
+
return create(params, OpenWebSocketParametersStruct);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof StructError) {
|
|
61
|
+
throw rpcErrors.invalidParams({
|
|
62
|
+
message: `Invalid params: ${error.message}.`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/* istanbul ignore next */
|
|
66
|
+
throw rpcErrors.internal();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=openWebSocket.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openWebSocket.mjs","sourceRoot":"","sources":["../../src/permitted/openWebSocket.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AACjE,OAAO,EACL,OAAO,EACP,KAAK,EAIN,4BAA4B;AAC7B,OAAO,EAAE,GAAG,EAAsB,8BAA8B;AAChE,OAAO,EACL,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,QAAQ,EACR,WAAW,EACZ,8BAA8B;AAG/B,OAAO,EAAE,cAAc,EAAE,gCAAsB;AAG/C,MAAM,SAAS,GAAgD;IAC7D,aAAa,EAAE,IAAI;IACnB,aAAa,EAAE,IAAI;CACpB,CAAC;AAOF,MAAM,6BAA6B,GAAG,MAAM,CAAC;IAC3C,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,MA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["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n literal,\n union,\n type JsonRpcRequest,\n type OpenWebSocketParams,\n type OpenWebSocketResult,\n} from '@metamask/snaps-sdk';\nimport { uri, type InferMatching } from '@metamask/snaps-utils';\nimport {\n create,\n object,\n array,\n string,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<OpenWebSocketMethodHooks> = {\n hasPermission: true,\n openWebSocket: true,\n};\n\nexport type OpenWebSocketMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n openWebSocket: (url: string, protocols?: string[]) => Promise<string>;\n};\n\nconst OpenWebSocketParametersStruct = object({\n url: uri({ protocol: union([literal('wss:'), literal('ws:')]) }),\n protocols: optional(array(string())),\n});\n\nexport type OpenWebSocketParameters = InferMatching<\n typeof OpenWebSocketParametersStruct,\n OpenWebSocketParams\n>;\n\n/**\n * Handler for the `snap_openWebSocket` method.\n */\nexport const openWebSocketHandler: PermittedHandlerExport<\n OpenWebSocketMethodHooks,\n OpenWebSocketParams,\n OpenWebSocketResult\n> = {\n methodNames: ['snap_openWebSocket'],\n implementation: openWebSocketImplementation,\n hookNames,\n};\n\n/**\n * The `snap_openWebSocket` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - The function to check if a snap has the `endowment:network-access` permission.\n * @param hooks.openWebSocket - The function to open a WebSocket.\n * @returns Nothing.\n */\nasync function openWebSocketImplementation(\n req: JsonRpcRequest<OpenWebSocketParameters>,\n res: PendingJsonRpcResponse<OpenWebSocketResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, openWebSocket }: OpenWebSocketMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.NetworkAccess)) {\n return end(providerErrors.unauthorized());\n }\n\n const { params } = req;\n\n try {\n const { url, protocols } = getValidatedParams(params);\n res.result = await openWebSocket(url, protocols);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validates the parameters for the snap_openWebSocket method.\n *\n * @param params - Parameters to validate.\n * @returns Validated parameters.\n * @throws Throws RPC error if validation fails.\n */\nfunction getValidatedParams(params: unknown): OpenWebSocketParameters {\n try {\n return create(params, OpenWebSocketParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -6,7 +6,6 @@ const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
|
6
6
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
7
|
const superstruct_1 = require("@metamask/superstruct");
|
|
8
8
|
const utils_1 = require("@metamask/utils");
|
|
9
|
-
const luxon_1 = require("luxon");
|
|
10
9
|
const endowments_1 = require("../endowments/index.cjs");
|
|
11
10
|
const methodName = 'snap_scheduleBackgroundEvent';
|
|
12
11
|
const hookNames = {
|
|
@@ -33,20 +32,17 @@ const ScheduleBackgroundEventParametersStruct = (0, snaps_sdk_1.selectiveUnion)(
|
|
|
33
32
|
return ScheduleBackgroundEventParametersWithDurationStruct;
|
|
34
33
|
});
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
35
|
+
* Get the schedule for a background event based on the provided parameters.
|
|
37
36
|
*
|
|
38
|
-
* @param params - The
|
|
39
|
-
* @returns
|
|
37
|
+
* @param params - The parameters for the background event.
|
|
38
|
+
* @returns The schedule parameters for the background event.
|
|
40
39
|
*/
|
|
41
|
-
function
|
|
42
|
-
if ('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const duration = parsed.as('seconds') >= 1 ? parsed : luxon_1.Duration.fromObject({ seconds: 1 });
|
|
46
|
-
return luxon_1.DateTime.fromJSDate(new Date()).toUTC().plus(duration).toISO();
|
|
40
|
+
function getSchedule(params) {
|
|
41
|
+
if ((0, utils_1.hasProperty)(params, 'date')) {
|
|
42
|
+
// TODO: Check why `params.date` is not a string.
|
|
43
|
+
return params.date;
|
|
47
44
|
}
|
|
48
|
-
|
|
49
|
-
return (0, snaps_utils_1.toCensoredISO8601String)(params.date);
|
|
45
|
+
return params.duration;
|
|
50
46
|
}
|
|
51
47
|
/**
|
|
52
48
|
* The `snap_scheduleBackgroundEvent` method implementation.
|
|
@@ -69,9 +65,11 @@ async function getScheduleBackgroundEventImplementation(req, res, _next, end, {
|
|
|
69
65
|
try {
|
|
70
66
|
const validatedParams = getValidatedParams(params);
|
|
71
67
|
const { request } = validatedParams;
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
const schedule = getSchedule(validatedParams);
|
|
69
|
+
const id = scheduleBackgroundEvent({
|
|
70
|
+
schedule,
|
|
71
|
+
request,
|
|
72
|
+
});
|
|
75
73
|
res.result = id;
|
|
76
74
|
}
|
|
77
75
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduleBackgroundEvent.cjs","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AACjE,mDAK6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"scheduleBackgroundEvent.cjs","sourceRoot":"","sources":["../../src/permitted/scheduleBackgroundEvent.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AACjE,mDAK6B;AAE7B,uDAI+B;AAC/B,uDAAoE;AACpE,2CAA2E;AAE3E,wDAA+C;AAG/C,MAAM,UAAU,GAAG,8BAA8B,CAAC;AAElD,MAAM,SAAS,GAA0D;IACvE,uBAAuB,EAAE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C,MAAM,CAAC,CAAC;QACnD,MAAM,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;QAE9C,MAAM,EAAE,GAAG,uBAAuB,CAAC;YACjC,QAAQ;YACR,OAAO;SACR,CAAC,CAAC;QAEH,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;IAClB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,MAAe;IAEf,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;IACjE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n selectiveUnion,\n type JsonRpcRequest,\n type ScheduleBackgroundEventParams,\n type ScheduleBackgroundEventResult,\n} from '@metamask/snaps-sdk';\nimport type { CronjobRpcRequest, InferMatching } from '@metamask/snaps-utils';\nimport {\n CronjobRpcRequestStruct,\n ISO8601DateStruct,\n ISO8601DurationStruct,\n} from '@metamask/snaps-utils';\nimport { StructError, create, object } from '@metamask/superstruct';\nimport { hasProperty, type PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_scheduleBackgroundEvent';\n\nconst hookNames: MethodHooksObject<ScheduleBackgroundEventMethodHooks> = {\n scheduleBackgroundEvent: true,\n hasPermission: true,\n};\n\ntype ScheduleBackgroundEventHookParams = {\n schedule: string;\n request: CronjobRpcRequest;\n};\n\nexport type ScheduleBackgroundEventMethodHooks = {\n scheduleBackgroundEvent: (\n snapEvent: ScheduleBackgroundEventHookParams,\n ) => string;\n\n hasPermission: (permissionName: string) => boolean;\n};\n\nexport const scheduleBackgroundEventHandler: PermittedHandlerExport<\n ScheduleBackgroundEventMethodHooks,\n ScheduleBackgroundEventParameters,\n ScheduleBackgroundEventResult\n> = {\n methodNames: [methodName],\n implementation: getScheduleBackgroundEventImplementation,\n hookNames,\n};\n\nconst ScheduleBackgroundEventParametersWithDateStruct = object({\n date: ISO8601DateStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst ScheduleBackgroundEventParametersWithDurationStruct = object({\n duration: ISO8601DurationStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst ScheduleBackgroundEventParametersStruct = selectiveUnion((val) => {\n if (hasProperty(val, 'date')) {\n return ScheduleBackgroundEventParametersWithDateStruct;\n }\n return ScheduleBackgroundEventParametersWithDurationStruct;\n});\n\nexport type ScheduleBackgroundEventParameters = InferMatching<\n typeof ScheduleBackgroundEventParametersStruct,\n ScheduleBackgroundEventParams\n>;\n\n/**\n * Get the schedule for a background event based on the provided parameters.\n *\n * @param params - The parameters for the background event.\n * @returns The schedule parameters for the background event.\n */\nfunction getSchedule(params: ScheduleBackgroundEventParameters): string {\n if (hasProperty(params, 'date')) {\n // TODO: Check why `params.date` is not a string.\n return params.date as string;\n }\n\n return params.duration;\n}\n\n/**\n * The `snap_scheduleBackgroundEvent` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.scheduleBackgroundEvent - The function to schedule a background event.\n * @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission.\n * @returns An id representing the background event.\n */\nasync function getScheduleBackgroundEventImplementation(\n req: JsonRpcRequest<ScheduleBackgroundEventParameters>,\n res: PendingJsonRpcResponse<ScheduleBackgroundEventResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n scheduleBackgroundEvent,\n hasPermission,\n }: ScheduleBackgroundEventMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n if (!hasPermission(SnapEndowments.Cronjob)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { request } = validatedParams;\n const schedule = getSchedule(validatedParams);\n\n const id = scheduleBackgroundEvent({\n schedule,\n request,\n });\n\n res.result = id;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the scheduleBackgroundEvent method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated resolveInterface method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n): ScheduleBackgroundEventParameters {\n try {\n return create(params, ScheduleBackgroundEventParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
|
2
2
|
import { type ScheduleBackgroundEventParams, type ScheduleBackgroundEventResult } from "@metamask/snaps-sdk";
|
|
3
3
|
import type { CronjobRpcRequest, InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
type ScheduleBackgroundEventHookParams = {
|
|
5
|
-
|
|
5
|
+
schedule: string;
|
|
6
6
|
request: CronjobRpcRequest;
|
|
7
7
|
};
|
|
8
8
|
export type ScheduleBackgroundEventMethodHooks = {
|