@metamask/snaps-rpc-methods 13.0.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 +9 -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/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 +3 -3
|
@@ -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,EAAE,0CAAsC;AACvE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AACnE,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AACnE,OAAO,EAAE,wBAAwB,EAAE,gCAA4B;AAC/D,OAAO,EAAE,eAAe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,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,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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EAAE,wBAAwB,EAAE,4BAAwB;AAChE,OAAO,KAAK,EAAE,uBAAuB,EAAE,iCAA6B;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,4BAAwB;AAChE,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAuB;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,+BAA2B;AACtE,OAAO,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,5 +1,6 @@
|
|
|
1
1
|
import type { CancelBackgroundEventMethodHooks } from "./cancelBackgroundEvent.mjs";
|
|
2
2
|
import type { ClearStateHooks } from "./clearState.mjs";
|
|
3
|
+
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,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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A0B,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,MAAM,EAAE,CAAC,CAAC;CACrC,CAAC,CAAC;AAOH;;GAEG;AACH,MAAM,CAAC,MAAM,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,cAAc,CAAC,aAAa,CAAC,EAAE,CAAC;QACjD,OAAO,GAAG,CAAC,cAAc,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,MAAM,CAAC,MAAM,EAAE,6BAA6B,CAAC,CAAC;IACvD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,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,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendWebSocketMessageHandler = void 0;
|
|
4
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
6
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
7
|
+
const endowments_1 = require("../endowments/index.cjs");
|
|
8
|
+
const hookNames = {
|
|
9
|
+
hasPermission: true,
|
|
10
|
+
sendWebSocketMessage: true,
|
|
11
|
+
};
|
|
12
|
+
const SendWebSocketMessageParametersStruct = (0, superstruct_1.object)({
|
|
13
|
+
id: (0, superstruct_1.string)(),
|
|
14
|
+
message: (0, snaps_sdk_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.array)((0, superstruct_1.number)())]),
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Handler for the `snap_sendWebSocketMessage` method.
|
|
18
|
+
*/
|
|
19
|
+
exports.sendWebSocketMessageHandler = {
|
|
20
|
+
methodNames: ['snap_sendWebSocketMessage'],
|
|
21
|
+
implementation: sendWebSocketMessageImplementation,
|
|
22
|
+
hookNames,
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The `snap_sendWebSocketMessage` method implementation.
|
|
26
|
+
*
|
|
27
|
+
* @param req - The JSON-RPC request object.
|
|
28
|
+
* @param res - The JSON-RPC response object.
|
|
29
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this function.
|
|
30
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
31
|
+
* @param hooks - The RPC method hooks.
|
|
32
|
+
* @param hooks.hasPermission - The function to check if a snap has the `endowment:network-access` permission.
|
|
33
|
+
* @param hooks.sendWebSocketMessage - The function to send a WebSocket message.
|
|
34
|
+
* @returns Nothing.
|
|
35
|
+
*/
|
|
36
|
+
function sendWebSocketMessageImplementation(req, res, _next, end, { hasPermission, sendWebSocketMessage }) {
|
|
37
|
+
if (!hasPermission(endowments_1.SnapEndowments.NetworkAccess)) {
|
|
38
|
+
return end(rpc_errors_1.providerErrors.unauthorized());
|
|
39
|
+
}
|
|
40
|
+
const { params } = req;
|
|
41
|
+
try {
|
|
42
|
+
const { id, message } = getValidatedParams(params);
|
|
43
|
+
sendWebSocketMessage(id, message);
|
|
44
|
+
res.result = null;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return end(error);
|
|
48
|
+
}
|
|
49
|
+
return end();
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Validates the parameters for the snap_sendWebSocketMessage 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, SendWebSocketMessageParametersStruct);
|
|
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=sendWebSocketMessage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendWebSocketMessage.cjs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;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,oCAAoC,CAAC,CAAC;IAC9D,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 type {\n JsonRpcRequest,\n SendWebSocketMessageParams,\n SendWebSocketMessageResult,\n} from '@metamask/snaps-sdk';\nimport { union } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport {\n create,\n object,\n number,\n string,\n array,\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<SendWebSocketMessageMethodHooks> = {\n hasPermission: true,\n sendWebSocketMessage: true,\n};\n\nexport type SendWebSocketMessageMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n sendWebSocketMessage: (id: string, data: string | number[]) => void;\n};\n\nconst SendWebSocketMessageParametersStruct = object({\n id: string(),\n message: union([string(), array(number())]),\n});\n\nexport type SendWebSocketMessageParameters = InferMatching<\n typeof SendWebSocketMessageParametersStruct,\n SendWebSocketMessageParams\n>;\n\n/**\n * Handler for the `snap_sendWebSocketMessage` method.\n */\nexport const sendWebSocketMessageHandler: PermittedHandlerExport<\n SendWebSocketMessageMethodHooks,\n SendWebSocketMessageParams,\n SendWebSocketMessageResult\n> = {\n methodNames: ['snap_sendWebSocketMessage'],\n implementation: sendWebSocketMessageImplementation,\n hookNames,\n};\n\n/**\n * The `snap_sendWebSocketMessage` 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.sendWebSocketMessage - The function to send a WebSocket message.\n * @returns Nothing.\n */\nfunction sendWebSocketMessageImplementation(\n req: JsonRpcRequest<SendWebSocketMessageParameters>,\n res: PendingJsonRpcResponse<SendWebSocketMessageResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, sendWebSocketMessage }: SendWebSocketMessageMethodHooks,\n): void {\n if (!hasPermission(SnapEndowments.NetworkAccess)) {\n return end(providerErrors.unauthorized());\n }\n\n const { params } = req;\n\n try {\n const { id, message } = getValidatedParams(params);\n sendWebSocketMessage(id, message);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validates the parameters for the snap_sendWebSocketMessage 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): SendWebSocketMessageParameters {\n try {\n return create(params, SendWebSocketMessageParametersStruct);\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 { SendWebSocketMessageParams, SendWebSocketMessageResult } from "@metamask/snaps-sdk";
|
|
3
|
+
import type { InferMatching } from "@metamask/snaps-utils";
|
|
4
|
+
export type SendWebSocketMessageMethodHooks = {
|
|
5
|
+
hasPermission: (permissionName: string) => boolean;
|
|
6
|
+
sendWebSocketMessage: (id: string, data: string | number[]) => void;
|
|
7
|
+
};
|
|
8
|
+
declare const SendWebSocketMessageParametersStruct: import("@metamask/superstruct").Struct<{
|
|
9
|
+
id: string;
|
|
10
|
+
message: string | number[];
|
|
11
|
+
}, {
|
|
12
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
13
|
+
message: import("@metamask/superstruct").Struct<string | number[], [head: import("@metamask/superstruct").Struct<string, null>, import("@metamask/superstruct").Struct<number[], import("@metamask/superstruct").Struct<number, null>>]>;
|
|
14
|
+
}>;
|
|
15
|
+
export type SendWebSocketMessageParameters = InferMatching<typeof SendWebSocketMessageParametersStruct, SendWebSocketMessageParams>;
|
|
16
|
+
/**
|
|
17
|
+
* Handler for the `snap_sendWebSocketMessage` method.
|
|
18
|
+
*/
|
|
19
|
+
export declare const sendWebSocketMessageHandler: PermittedHandlerExport<SendWebSocketMessageMethodHooks, SendWebSocketMessageParams, SendWebSocketMessageResult>;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=sendWebSocketMessage.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sendWebSocketMessage.d.cts","sourceRoot":"","sources":["../../src/permitted/sendWebSocketMessage.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAEV,0BAA0B,EAC1B,0BAA0B,EAC3B,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAmB3D,MAAM,MAAM,+BAA+B,GAAG;IAC5C,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IACnD,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC;CACrE,CAAC;AAEF,QAAA,MAAM,oCAAoC;;;;;;EAGxC,CAAC;AAEH,MAAM,MAAM,8BAA8B,GAAG,aAAa,CACxD,OAAO,oCAAoC,EAC3C,0BAA0B,CAC3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,EAAE,sBAAsB,CAC9D,+BAA+B,EAC/B,0BAA0B,EAC1B,0BAA0B,CAK3B,CAAC"}
|