@metamask/snaps-controllers 9.3.1 → 9.5.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/{chunk-JLIW4CNS.js → chunk-2D5PGL7S.js} +7 -7
- package/dist/chunk-2D5PGL7S.js.map +1 -0
- package/dist/{chunk-6GMWL4JR.mjs → chunk-2SRKMEUV.mjs} +2 -2
- package/dist/chunk-2SRKMEUV.mjs.map +1 -0
- package/dist/{chunk-QYQLJCPR.js → chunk-36QDTCDZ.js} +2 -1
- package/dist/chunk-36QDTCDZ.js.map +1 -0
- package/dist/{chunk-POQSARDG.js → chunk-3WWZDKQL.js} +7 -7
- package/dist/{chunk-FKQTV3LO.js → chunk-6K4MATNG.js} +4 -4
- package/dist/chunk-6K4MATNG.js.map +1 -0
- package/dist/{chunk-LWBPKSU2.js → chunk-6Z4WDAVC.js} +3 -3
- package/dist/{chunk-WKQRCGUW.mjs → chunk-BAUQWPSP.mjs} +2 -2
- package/dist/chunk-BAUQWPSP.mjs.map +1 -0
- package/dist/{chunk-XFUP7RFI.js → chunk-DSOZPX7I.js} +1 -1
- package/dist/chunk-DSOZPX7I.js.map +1 -0
- package/dist/{chunk-G245VWEY.mjs → chunk-F3ZMDQ52.mjs} +2 -1
- package/dist/chunk-F3ZMDQ52.mjs.map +1 -0
- package/dist/{chunk-3T6W5VI2.mjs → chunk-HULNFJMA.mjs} +11 -3
- package/dist/chunk-HULNFJMA.mjs.map +1 -0
- package/dist/{chunk-CPUUURMT.js → chunk-I25KLPIS.js} +2 -2
- package/dist/chunk-I25KLPIS.js.map +1 -0
- package/dist/{chunk-6M4XK4PN.mjs → chunk-I5V56NYO.mjs} +2 -2
- package/dist/chunk-I5V56NYO.mjs.map +1 -0
- package/dist/{chunk-XWDEGRM5.js → chunk-K3TNQEM5.js} +2 -2
- package/dist/chunk-K3TNQEM5.js.map +1 -0
- package/dist/{chunk-2MH7QYBP.mjs → chunk-QWN3UOMA.mjs} +3 -3
- package/dist/chunk-QWN3UOMA.mjs.map +1 -0
- package/dist/{chunk-H7TB7I6Z.js → chunk-RZ2NHZXH.js} +11 -3
- package/dist/chunk-RZ2NHZXH.js.map +1 -0
- package/dist/{chunk-RDBT3ZJQ.js → chunk-TIURYSSR.js} +2 -2
- package/dist/{chunk-RDBT3ZJQ.js.map → chunk-TIURYSSR.js.map} +1 -1
- package/dist/{chunk-B3UTLNYS.mjs → chunk-UM4NFNEI.mjs} +2 -2
- package/dist/{chunk-33RRV7F4.mjs → chunk-Z4BUMSH3.mjs} +1 -1
- package/dist/chunk-Z4BUMSH3.mjs.map +1 -0
- package/dist/{chunk-23PVLQFV.mjs → chunk-Z5QWRDUN.mjs} +2 -2
- package/dist/chunk-Z5QWRDUN.mjs.map +1 -0
- package/dist/{chunk-2AEM5R2M.mjs → chunk-ZKG6FRKN.mjs} +4 -4
- package/dist/cronjob/CronjobController.js +11 -11
- package/dist/cronjob/CronjobController.mjs +10 -10
- package/dist/cronjob/index.js +11 -11
- package/dist/cronjob/index.mjs +10 -10
- package/dist/index.js +11 -11
- package/dist/index.mjs +10 -10
- package/dist/insights/SnapInsightsController.js +8 -8
- package/dist/insights/SnapInsightsController.mjs +7 -7
- package/dist/insights/index.js +8 -8
- package/dist/insights/index.mjs +7 -7
- package/dist/interface/SnapInterfaceController.js +3 -3
- package/dist/interface/SnapInterfaceController.mjs +2 -2
- package/dist/interface/index.js +3 -3
- package/dist/interface/index.mjs +2 -2
- package/dist/interface/utils.js +2 -2
- package/dist/interface/utils.mjs +1 -1
- package/dist/node.js +11 -11
- package/dist/node.mjs +10 -10
- package/dist/react-native.js +11 -11
- package/dist/react-native.mjs +10 -10
- package/dist/snaps/SnapController.js +7 -7
- package/dist/snaps/SnapController.mjs +6 -6
- package/dist/snaps/index.js +7 -7
- package/dist/snaps/index.mjs +6 -6
- package/dist/snaps/location/http.js +2 -2
- package/dist/snaps/location/http.mjs +1 -1
- package/dist/snaps/location/index.js +5 -5
- package/dist/snaps/location/index.mjs +4 -4
- package/dist/snaps/location/local.js +3 -3
- package/dist/snaps/location/local.mjs +2 -2
- package/dist/snaps/location/location.js +5 -5
- package/dist/snaps/location/location.mjs +4 -4
- package/dist/snaps/location/npm.js +2 -2
- package/dist/snaps/location/npm.mjs +1 -1
- package/dist/snaps/registry/index.js +2 -2
- package/dist/snaps/registry/index.mjs +1 -1
- package/dist/snaps/registry/json.js +2 -2
- package/dist/snaps/registry/json.mjs +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/cronjob/CronjobController.d.ts +10 -8
- package/dist/types/insights/SnapInsightsController.d.ts +12 -8
- package/dist/types/interface/SnapInterfaceController.d.ts +16 -13
- package/dist/types/services/AbstractExecutionService.d.ts +5 -5
- package/dist/types/services/ExecutionService.d.ts +16 -16
- package/dist/types/services/ProxyPostMessageStream.d.ts +2 -2
- package/dist/types/services/iframe/IframeExecutionService.d.ts +1 -1
- package/dist/types/services/offscreen/OffscreenExecutionService.d.ts +1 -1
- package/dist/types/services/proxy/ProxyExecutionService.d.ts +1 -1
- package/dist/types/services/webview/WebViewExecutionService.d.ts +1 -1
- package/dist/types/services/webview/WebViewMessageStream.d.ts +2 -2
- package/dist/types/services/webworker/WebWorkerExecutionService.d.ts +1 -1
- package/dist/types/snaps/SnapController.d.ts +52 -47
- package/dist/types/snaps/Timer.d.ts +1 -1
- package/dist/types/snaps/location/location.d.ts +1 -1
- package/dist/types/snaps/location/npm.d.ts +1 -1
- package/dist/types/snaps/registry/json.d.ts +13 -11
- package/dist/types/snaps/registry/registry.d.ts +5 -5
- package/dist/types/types/controllers.d.ts +8 -8
- package/dist/types/types/encryptor.d.ts +5 -5
- package/dist/types/utils.d.ts +14 -7
- package/package.json +5 -5
- package/dist/chunk-23PVLQFV.mjs.map +0 -1
- package/dist/chunk-2MH7QYBP.mjs.map +0 -1
- package/dist/chunk-33RRV7F4.mjs.map +0 -1
- package/dist/chunk-3T6W5VI2.mjs.map +0 -1
- package/dist/chunk-6GMWL4JR.mjs.map +0 -1
- package/dist/chunk-6M4XK4PN.mjs.map +0 -1
- package/dist/chunk-CPUUURMT.js.map +0 -1
- package/dist/chunk-FKQTV3LO.js.map +0 -1
- package/dist/chunk-G245VWEY.mjs.map +0 -1
- package/dist/chunk-H7TB7I6Z.js.map +0 -1
- package/dist/chunk-JLIW4CNS.js.map +0 -1
- package/dist/chunk-QYQLJCPR.js.map +0 -1
- package/dist/chunk-WKQRCGUW.mjs.map +0 -1
- package/dist/chunk-XFUP7RFI.js.map +0 -1
- package/dist/chunk-XWDEGRM5.js.map +0 -1
- /package/dist/{chunk-POQSARDG.js.map → chunk-3WWZDKQL.js.map} +0 -0
- /package/dist/{chunk-LWBPKSU2.js.map → chunk-6Z4WDAVC.js.map} +0 -0
- /package/dist/{chunk-B3UTLNYS.mjs.map → chunk-UM4NFNEI.mjs.map} +0 -0
- /package/dist/{chunk-2AEM5R2M.mjs.map → chunk-ZKG6FRKN.mjs.map} +0 -0
|
@@ -17,7 +17,7 @@ export interface SnapLocation {
|
|
|
17
17
|
fetch(path: string): Promise<VirtualFile>;
|
|
18
18
|
readonly shouldAlwaysReload?: boolean;
|
|
19
19
|
}
|
|
20
|
-
export
|
|
20
|
+
export type DetectSnapLocationOptions = NpmOptions & {
|
|
21
21
|
/**
|
|
22
22
|
* The function used to fetch data.
|
|
23
23
|
*
|
|
@@ -53,7 +53,7 @@ export declare class NpmLocation extends BaseNpmLocation {
|
|
|
53
53
|
*/
|
|
54
54
|
fetchNpmTarball(tarballUrl: URL): Promise<Map<string, VirtualFile<unknown>>>;
|
|
55
55
|
}
|
|
56
|
-
export
|
|
56
|
+
export type PartialNpmMetadata = {
|
|
57
57
|
versions: Record<string, {
|
|
58
58
|
dist: {
|
|
59
59
|
tarball: string;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedControllerMessenger } from '@metamask/base-controller';
|
|
2
2
|
import { BaseController } from '@metamask/base-controller';
|
|
3
3
|
import type { SnapsRegistryDatabase } from '@metamask/snaps-registry';
|
|
4
4
|
import type { Hex } from '@metamask/utils';
|
|
5
5
|
import type { SnapsRegistry } from './registry';
|
|
6
|
-
|
|
6
|
+
type JsonSnapsRegistryUrl = {
|
|
7
7
|
registry: string;
|
|
8
8
|
signature: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type JsonSnapsRegistryArgs = {
|
|
11
11
|
messenger: SnapsRegistryMessenger;
|
|
12
12
|
state?: SnapsRegistryState;
|
|
13
13
|
fetchFunction?: typeof fetch;
|
|
@@ -16,26 +16,28 @@ export declare type JsonSnapsRegistryArgs = {
|
|
|
16
16
|
refetchOnAllowlistMiss?: boolean;
|
|
17
17
|
publicKey?: Hex;
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type GetResult = {
|
|
20
20
|
type: `${typeof controllerName}:get`;
|
|
21
21
|
handler: SnapsRegistry['get'];
|
|
22
22
|
};
|
|
23
|
-
export
|
|
23
|
+
export type ResolveVersion = {
|
|
24
24
|
type: `${typeof controllerName}:resolveVersion`;
|
|
25
25
|
handler: SnapsRegistry['resolveVersion'];
|
|
26
26
|
};
|
|
27
|
-
export
|
|
27
|
+
export type GetMetadata = {
|
|
28
28
|
type: `${typeof controllerName}:getMetadata`;
|
|
29
29
|
handler: SnapsRegistry['getMetadata'];
|
|
30
30
|
};
|
|
31
|
-
export
|
|
31
|
+
export type Update = {
|
|
32
32
|
type: `${typeof controllerName}:update`;
|
|
33
33
|
handler: SnapsRegistry['update'];
|
|
34
34
|
};
|
|
35
|
-
export
|
|
36
|
-
export
|
|
37
|
-
export
|
|
38
|
-
export
|
|
35
|
+
export type SnapsRegistryGetStateAction = ControllerGetStateAction<typeof controllerName, SnapsRegistryState>;
|
|
36
|
+
export type SnapsRegistryActions = SnapsRegistryGetStateAction | GetResult | GetMetadata | Update | ResolveVersion;
|
|
37
|
+
export type SnapsRegistryStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, SnapsRegistryState>;
|
|
38
|
+
export type SnapsRegistryEvents = SnapsRegistryStateChangeEvent;
|
|
39
|
+
export type SnapsRegistryMessenger = RestrictedControllerMessenger<'SnapsRegistry', SnapsRegistryActions, SnapsRegistryEvents, SnapsRegistryActions['type'], SnapsRegistryEvents['type']>;
|
|
40
|
+
export type SnapsRegistryState = {
|
|
39
41
|
database: SnapsRegistryDatabase | null;
|
|
40
42
|
lastUpdated: number | null;
|
|
41
43
|
databaseUnavailable: boolean;
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import type { BlockReason, SnapsRegistryDatabase } from '@metamask/snaps-registry';
|
|
2
2
|
import type { SnapId } from '@metamask/snaps-sdk';
|
|
3
3
|
import type { SemVerRange, SemVerVersion } from '@metamask/utils';
|
|
4
|
-
export
|
|
4
|
+
export type SnapsRegistryInfo = {
|
|
5
5
|
version: SemVerVersion;
|
|
6
6
|
checksum: string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
export
|
|
8
|
+
export type SnapsRegistryRequest = Record<SnapId, SnapsRegistryInfo>;
|
|
9
|
+
export type SnapsRegistryMetadata = SnapsRegistryDatabase['verifiedSnaps'][SnapId]['metadata'];
|
|
10
10
|
export declare enum SnapsRegistryStatus {
|
|
11
11
|
Unverified = 0,
|
|
12
12
|
Blocked = 1,
|
|
13
13
|
Verified = 2,
|
|
14
14
|
Unavailable = 3
|
|
15
15
|
}
|
|
16
|
-
export
|
|
16
|
+
export type SnapsRegistryResult = {
|
|
17
17
|
status: SnapsRegistryStatus;
|
|
18
18
|
reason?: BlockReason;
|
|
19
19
|
};
|
|
20
|
-
export
|
|
20
|
+
export type SnapsRegistry = {
|
|
21
21
|
get(snaps: SnapsRegistryRequest): Promise<Record<SnapId, SnapsRegistryResult>>;
|
|
22
22
|
update(): Promise<void>;
|
|
23
23
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
2
|
import type { Hex, Json } from '@metamask/utils';
|
|
3
|
-
export
|
|
3
|
+
export type TransactionMeta = {
|
|
4
4
|
/**
|
|
5
5
|
* Generated UUID associated with this transaction.
|
|
6
6
|
*/
|
|
@@ -25,7 +25,7 @@ export declare type TransactionMeta = {
|
|
|
25
25
|
/**
|
|
26
26
|
* Standard data concerning a transaction to be processed by the blockchain.
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
28
|
+
export type TransactionParams = {
|
|
29
29
|
/**
|
|
30
30
|
* Network ID as per EIP-155.
|
|
31
31
|
*/
|
|
@@ -97,11 +97,11 @@ export declare type TransactionParams = {
|
|
|
97
97
|
*/
|
|
98
98
|
type?: string;
|
|
99
99
|
};
|
|
100
|
-
export
|
|
100
|
+
export type TransactionControllerUnapprovedTransactionAddedEvent = {
|
|
101
101
|
type: `TransactionController:unapprovedTransactionAdded`;
|
|
102
102
|
payload: [transactionMeta: TransactionMeta];
|
|
103
103
|
};
|
|
104
|
-
export
|
|
104
|
+
export type TransactionControllerTransactionStatusUpdatedEvent = {
|
|
105
105
|
type: `TransactionController:transactionStatusUpdated`;
|
|
106
106
|
payload: [
|
|
107
107
|
{
|
|
@@ -109,23 +109,23 @@ export declare type TransactionControllerTransactionStatusUpdatedEvent = {
|
|
|
109
109
|
}
|
|
110
110
|
];
|
|
111
111
|
};
|
|
112
|
-
export
|
|
112
|
+
export type StateSignatureParams = {
|
|
113
113
|
from: string;
|
|
114
114
|
origin?: string;
|
|
115
115
|
deferSetAsSigned?: boolean;
|
|
116
116
|
data: string | Record<string, Json>;
|
|
117
117
|
signatureMethod: string;
|
|
118
118
|
};
|
|
119
|
-
export
|
|
119
|
+
export type StateSignature = {
|
|
120
120
|
id: string;
|
|
121
121
|
msgParams: StateSignatureParams;
|
|
122
122
|
};
|
|
123
|
-
export
|
|
123
|
+
export type SignatureControllerState = {
|
|
124
124
|
unapprovedPersonalMsgs: Record<string, StateSignature>;
|
|
125
125
|
unapprovedTypedMessages: Record<string, StateSignature>;
|
|
126
126
|
unapprovedPersonalMsgCount: number;
|
|
127
127
|
unapprovedTypedMessagesCount: number;
|
|
128
128
|
};
|
|
129
129
|
declare const signatureControllerName = "SignatureController";
|
|
130
|
-
export
|
|
130
|
+
export type SignatureStateChange = ControllerStateChangeEvent<typeof signatureControllerName, SignatureControllerState>;
|
|
131
131
|
export {};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Json } from '@metamask/utils';
|
|
2
|
-
export
|
|
2
|
+
export type PBKDF2Params = {
|
|
3
3
|
iterations: number;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export type KeyDerivationOptions = {
|
|
6
6
|
algorithm: 'PBKDF2';
|
|
7
7
|
params: PBKDF2Params;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type EncryptionResult = {
|
|
10
10
|
data: string;
|
|
11
11
|
iv: string;
|
|
12
12
|
salt: string;
|
|
@@ -16,7 +16,7 @@ export declare type EncryptionResult = {
|
|
|
16
16
|
* A generic encryptor interface that supports encrypting and decrypting
|
|
17
17
|
* serializable data with a password.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export type GenericEncryptor = {
|
|
20
20
|
/**
|
|
21
21
|
* Encrypt the given object with the given password.
|
|
22
22
|
*
|
|
@@ -47,7 +47,7 @@ export declare type GenericEncryptor = {
|
|
|
47
47
|
* An encryptor interface that supports encrypting and decrypting
|
|
48
48
|
* serializable data with a password, and exporting and importing keys.
|
|
49
49
|
*/
|
|
50
|
-
export
|
|
50
|
+
export type ExportableKeyEncryptor = GenericEncryptor & {
|
|
51
51
|
/**
|
|
52
52
|
* Encrypt the given object with the given encryption key.
|
|
53
53
|
*
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -86,7 +86,7 @@ export declare function withTimeout<PromiseValue = void>(promise: Promise<Promis
|
|
|
86
86
|
* // t5 = false;
|
|
87
87
|
* ```
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
type IsLiteral<Type> = Type extends string | number | boolean | symbol ? Extract<string | number | boolean | symbol, Type> extends never ? true : false : false;
|
|
90
90
|
/**
|
|
91
91
|
* Returns all keys of an object, that are literal, as an union
|
|
92
92
|
*
|
|
@@ -97,7 +97,7 @@ declare type IsLiteral<Type> = Type extends string | number | boolean | symbol ?
|
|
|
97
97
|
* ```
|
|
98
98
|
* @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}
|
|
99
99
|
*/
|
|
100
|
-
|
|
100
|
+
type LiteralKeys<Type> = NonNullable<{
|
|
101
101
|
[Key in keyof Type]: IsLiteral<Key> extends true ? Key : never;
|
|
102
102
|
}[keyof Type]>;
|
|
103
103
|
/**
|
|
@@ -110,7 +110,7 @@ declare type LiteralKeys<Type> = NonNullable<{
|
|
|
110
110
|
* ```
|
|
111
111
|
* @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}
|
|
112
112
|
*/
|
|
113
|
-
|
|
113
|
+
type NonLiteralKeys<Type> = NonNullable<{
|
|
114
114
|
[Key in keyof Type]: IsLiteral<Key> extends false ? Key : never;
|
|
115
115
|
}[keyof Type]>;
|
|
116
116
|
/**
|
|
@@ -127,14 +127,14 @@ declare type NonLiteralKeys<Type> = NonNullable<{
|
|
|
127
127
|
* ```
|
|
128
128
|
* @see {@link setDiff} for the main use-case
|
|
129
129
|
*/
|
|
130
|
-
export
|
|
130
|
+
export type Diff<First, Second> = Omit<First, LiteralKeys<Second>> & Partial<Pick<First, Extract<keyof First, NonLiteralKeys<Second>>>>;
|
|
131
131
|
/**
|
|
132
132
|
* Makes every specified property of the specified object type mutable.
|
|
133
133
|
*
|
|
134
134
|
* @template Type - The object whose readonly properties to make mutable.
|
|
135
135
|
* @template TargetKey - The property key(s) to make mutable.
|
|
136
136
|
*/
|
|
137
|
-
export
|
|
137
|
+
export type Mutable<Type extends Record<string, unknown>, TargetKey extends string> = {
|
|
138
138
|
-readonly [Key in keyof Pick<Type, TargetKey>]: Type[Key];
|
|
139
139
|
} & {
|
|
140
140
|
[Key in keyof Omit<Type, TargetKey>]: Type[Key];
|
|
@@ -173,7 +173,14 @@ export declare function fetchSnap(snapId: SnapId, location: SnapLocation): Promi
|
|
|
173
173
|
files?: string[] | undefined;
|
|
174
174
|
locales?: string[] | undefined;
|
|
175
175
|
};
|
|
176
|
-
proposedName: string;
|
|
176
|
+
proposedName: string; /**
|
|
177
|
+
* A Promise that delays it's return by using a pausable Timer.
|
|
178
|
+
*
|
|
179
|
+
* @param timer - Timer used to control the delay.
|
|
180
|
+
* @param result - The result to return from the Promise after delay.
|
|
181
|
+
* @returns A promise that is void if no result provided, result otherwise.
|
|
182
|
+
* @template Result - The `result`.
|
|
183
|
+
*/
|
|
177
184
|
initialPermissions: Partial<{
|
|
178
185
|
'endowment:cronjob': {
|
|
179
186
|
jobs: import("@metamask/snaps-sdk").Cronjob[];
|
|
@@ -234,11 +241,11 @@ export declare function fetchSnap(snapId: SnapId, location: SnapLocation): Promi
|
|
|
234
241
|
svgIcon: import("@metamask/snaps-utils").VirtualFile<unknown> | undefined;
|
|
235
242
|
auxiliaryFiles: import("@metamask/snaps-utils").VirtualFile<unknown>[];
|
|
236
243
|
localizationFiles: import("@metamask/snaps-utils").VirtualFile<{
|
|
237
|
-
locale: string;
|
|
238
244
|
messages: Record<string, {
|
|
239
245
|
message: string;
|
|
240
246
|
description?: string | undefined;
|
|
241
247
|
}>;
|
|
248
|
+
locale: string;
|
|
242
249
|
}>[];
|
|
243
250
|
}>;
|
|
244
251
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-controllers",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"description": "Controllers for MetaMask Snaps.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"@metamask/post-message-stream": "^8.1.0",
|
|
64
64
|
"@metamask/rpc-errors": "^6.3.1",
|
|
65
65
|
"@metamask/snaps-registry": "^3.2.1",
|
|
66
|
-
"@metamask/snaps-rpc-methods": "^
|
|
67
|
-
"@metamask/snaps-sdk": "^6.
|
|
68
|
-
"@metamask/snaps-utils": "^
|
|
66
|
+
"@metamask/snaps-rpc-methods": "^11.0.0",
|
|
67
|
+
"@metamask/snaps-sdk": "^6.3.0",
|
|
68
|
+
"@metamask/snaps-utils": "^8.0.1",
|
|
69
69
|
"@metamask/utils": "^9.1.0",
|
|
70
70
|
"@xstate/fsm": "^2.0.0",
|
|
71
71
|
"browserify-zlib": "^0.2.0",
|
|
@@ -130,7 +130,7 @@
|
|
|
130
130
|
"rimraf": "^4.1.2",
|
|
131
131
|
"ts-node": "^10.9.1",
|
|
132
132
|
"tsup": "^8.0.1",
|
|
133
|
-
"typescript": "~
|
|
133
|
+
"typescript": "~5.0.4",
|
|
134
134
|
"vite": "^4.3.9",
|
|
135
135
|
"vite-tsconfig-paths": "^4.0.5",
|
|
136
136
|
"wdio-chromedriver-service": "^8.1.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interface/SnapInterfaceController.ts"],"sourcesContent":["import type {\n AcceptRequest,\n HasApprovalRequest,\n} from '@metamask/approval-controller';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n MaybeUpdateState,\n TestOrigin,\n} from '@metamask/phishing-controller';\nimport type {\n InterfaceState,\n SnapId,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { getJsonSizeUnsafe, validateJsxLinks } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n constructState,\n getJsxInterface,\n validateInterfaceContext,\n} from './utils';\n\nconst MAX_UI_CONTENT_SIZE = 10_000_000; // 10 mb\n\nconst controllerName = 'SnapInterfaceController';\n\nexport type CreateInterface = {\n type: `${typeof controllerName}:createInterface`;\n handler: SnapInterfaceController['createInterface'];\n};\n\nexport type GetInterface = {\n type: `${typeof controllerName}:getInterface`;\n handler: SnapInterfaceController['getInterface'];\n};\n\nexport type UpdateInterface = {\n type: `${typeof controllerName}:updateInterface`;\n handler: SnapInterfaceController['updateInterface'];\n};\n\nexport type DeleteInterface = {\n type: `${typeof controllerName}:deleteInterface`;\n handler: SnapInterfaceController['deleteInterface'];\n};\n\nexport type UpdateInterfaceState = {\n type: `${typeof controllerName}:updateInterfaceState`;\n handler: SnapInterfaceController['updateInterfaceState'];\n};\n\nexport type ResolveInterface = {\n type: `${typeof controllerName}:resolveInterface`;\n handler: SnapInterfaceController['resolveInterface'];\n};\n\nexport type SnapInterfaceControllerAllowedActions =\n | TestOrigin\n | MaybeUpdateState\n | HasApprovalRequest\n | AcceptRequest;\n\nexport type SnapInterfaceControllerActions =\n | CreateInterface\n | GetInterface\n | UpdateInterface\n | DeleteInterface\n | UpdateInterfaceState\n | ResolveInterface;\n\nexport type SnapInterfaceControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions,\n never,\n SnapInterfaceControllerAllowedActions['type'],\n never\n>;\n\nexport type StoredInterface = {\n snapId: SnapId;\n content: JSXElement;\n state: InterfaceState;\n context: InterfaceContext | null;\n};\n\nexport type SnapInterfaceControllerState = {\n interfaces: Record<string, StoredInterface>;\n};\n\nexport type SnapInterfaceControllerArgs = {\n messenger: SnapInterfaceControllerMessenger;\n state?: SnapInterfaceControllerState;\n};\n\n/**\n * Use this controller to manage snaps UI interfaces using RPC method hooks.\n */\nexport class SnapInterfaceController extends BaseController<\n typeof controllerName,\n SnapInterfaceControllerState,\n SnapInterfaceControllerMessenger\n> {\n constructor({ messenger, state }: SnapInterfaceControllerArgs) {\n super({\n messenger,\n metadata: {\n interfaces: { persist: false, anonymous: false },\n },\n name: controllerName,\n state: { interfaces: {}, ...state },\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:createInterface`,\n this.createInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getInterface`,\n this.getInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterface`,\n this.updateInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:deleteInterface`,\n this.deleteInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterfaceState`,\n this.updateInterfaceState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:resolveInterface`,\n this.resolveInterface.bind(this),\n );\n }\n\n /**\n * Create an interface in the controller state with the associated data.\n *\n * @param snapId - The snap id that created the interface.\n * @param content - The interface content.\n * @param context - An optional interface context object.\n * @returns The newly interface id.\n */\n async createInterface(\n snapId: SnapId,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) {\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n validateInterfaceContext(context);\n\n const id = nanoid();\n const componentState = constructState({}, element);\n\n this.update((draftState) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n draftState.interfaces[id] = {\n snapId,\n content: element,\n state: componentState,\n context: context ?? null,\n };\n });\n\n return id;\n }\n\n /**\n * Get the data of a given interface id.\n *\n * @param snapId - The snap id requesting the interface data.\n * @param id - The interface id.\n * @returns The interface state.\n */\n getInterface(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n return this.state.interfaces[id];\n }\n\n /**\n * Update the interface with the given content.\n *\n * @param snapId - The snap id requesting the update.\n * @param id - The interface id.\n * @param content - The new content.\n */\n async updateInterface(\n snapId: SnapId,\n id: string,\n content: ComponentOrElement,\n ) {\n this.#validateArgs(snapId, id);\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n\n const oldState = this.state.interfaces[id].state;\n const newState = constructState(oldState, element);\n\n this.update((draftState) => {\n draftState.interfaces[id].state = newState;\n draftState.interfaces[id].content = element;\n });\n }\n\n /**\n * Delete an interface from state.\n *\n * @param id - The interface id.\n */\n deleteInterface(id: string) {\n this.update((draftState) => {\n delete draftState.interfaces[id];\n });\n }\n\n /**\n * Update the interface state.\n *\n * @param id - The interface id.\n * @param state - The new state.\n */\n updateInterfaceState(id: string, state: InterfaceState) {\n this.update((draftState) => {\n draftState.interfaces[id].state = state;\n });\n }\n\n /**\n * Resolve the promise of a given interface approval request.\n * The approval needs to have the same ID as the interface.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async resolveInterface(snapId: SnapId, id: string, value: Json) {\n this.#validateArgs(snapId, id);\n this.#validateApproval(id);\n\n await this.#acceptApprovalRequest(id, value);\n\n this.deleteInterface(id);\n }\n\n /**\n * Utility function to validate the args passed to the other methods.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n */\n #validateArgs(snapId: SnapId, id: string) {\n const existingInterface = this.state.interfaces[id];\n\n assert(\n existingInterface !== undefined,\n `Interface with id '${id}' not found.`,\n );\n assert(\n existingInterface.snapId === snapId,\n `Interface not created by ${snapId}.`,\n );\n }\n\n /**\n * Utility function to validate that the approval request exists.\n *\n * @param id - The interface id.\n */\n #validateApproval(id: string) {\n assert(\n this.#hasApprovalRequest(id),\n `Approval request with id '${id}' not found.`,\n );\n }\n\n /**\n * Trigger a Phishing list update if needed.\n */\n async #triggerPhishingListUpdate() {\n await this.messagingSystem.call('PhishingController:maybeUpdateState');\n }\n\n /**\n * Check an origin against the phishing list.\n *\n * @param origin - The origin to check.\n * @returns True if the origin is on the phishing list, otherwise false.\n */\n #checkPhishingList(origin: string) {\n return this.messagingSystem.call('PhishingController:testOrigin', origin)\n .result;\n }\n\n /**\n * Check if an approval request exists for a given interface by looking up\n * if the ApprovalController has a request with the given interface ID.\n *\n * @param id - The interface id.\n * @returns True if an approval request exists, otherwise false.\n */\n #hasApprovalRequest(id: string) {\n return this.messagingSystem.call('ApprovalController:hasRequest', {\n id,\n });\n }\n\n /**\n * Accept an approval request for a given interface.\n *\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async #acceptApprovalRequest(id: string, value: Json) {\n await this.messagingSystem.call(\n 'ApprovalController:acceptRequest',\n id,\n value,\n );\n }\n\n /**\n * Utility function to validate the components of an interface.\n * Throws if something is invalid.\n *\n * @param element - The JSX element to verify.\n */\n async #validateContent(element: JSXElement) {\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(element);\n assert(\n size <= MAX_UI_CONTENT_SIZE,\n `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000000} MB.`,\n );\n\n await this.#triggerPhishingListUpdate();\n validateJsxLinks(element, this.#checkPhishingList.bind(this));\n }\n}\n"],"mappings":";;;;;;;;;;;AAKA,SAAS,sBAAsB;AAY/B,SAAS,mBAAmB,wBAAwB;AAEpD,SAAS,cAAc;AACvB,SAAS,cAAc;AAQvB,IAAM,sBAAsB;AAE5B,IAAM,iBAAiB;AA9BvB;AAuGO,IAAM,0BAAN,cAAsC,eAI3C;AAAA,EACA,YAAY,EAAE,WAAW,MAAM,GAAgC;AAC7D,UAAM;AAAA,MACJ;AAAA,MACA,UAAU;AAAA,QACR,YAAY,EAAE,SAAS,OAAO,WAAW,MAAM;AAAA,MACjD;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,YAAY,CAAC,GAAG,GAAG,MAAM;AAAA,IACpC,CAAC;AASH;AAAA;AAAA;AAAA;AAAA;AAsJA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAAA;AAAA;AAAA,uBAAM;A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