@metamask/snaps-rpc-methods 3.2.1 → 4.0.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/cjs/index.js.map +1 -1
- package/dist/cjs/permitted/common/snapInstallation.js.map +1 -1
- package/dist/cjs/permitted/getFile.js +5 -4
- package/dist/cjs/permitted/getFile.js.map +1 -1
- package/dist/cjs/permitted/getSnaps.js.map +1 -1
- package/dist/cjs/permitted/invokeKeyring.js.map +1 -1
- package/dist/cjs/permitted/invokeSnapSugar.js.map +1 -1
- package/dist/cjs/permitted/requestSnaps.js.map +1 -1
- package/dist/cjs/restricted/caveats/permittedCoinTypes.js.map +1 -1
- package/dist/cjs/restricted/dialog.js +16 -25
- package/dist/cjs/restricted/dialog.js.map +1 -1
- package/dist/cjs/restricted/getBip32Entropy.js.map +1 -1
- package/dist/cjs/restricted/getBip32PublicKey.js.map +1 -1
- package/dist/cjs/restricted/getBip44Entropy.js +0 -1
- package/dist/cjs/restricted/getBip44Entropy.js.map +1 -1
- package/dist/cjs/restricted/getEntropy.js.map +1 -1
- package/dist/cjs/restricted/getLocale.js.map +1 -1
- package/dist/cjs/restricted/index.js +0 -9
- package/dist/cjs/restricted/index.js.map +1 -1
- package/dist/cjs/restricted/invokeSnap.js.map +1 -1
- package/dist/cjs/restricted/manageAccounts.js.map +1 -1
- package/dist/cjs/restricted/manageState.js +32 -31
- package/dist/cjs/restricted/manageState.js.map +1 -1
- package/dist/cjs/restricted/notify.js +6 -13
- package/dist/cjs/restricted/notify.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/permitted/common/snapInstallation.js.map +1 -1
- package/dist/esm/permitted/getFile.js +2 -1
- package/dist/esm/permitted/getFile.js.map +1 -1
- package/dist/esm/permitted/getSnaps.js.map +1 -1
- package/dist/esm/permitted/invokeKeyring.js.map +1 -1
- package/dist/esm/permitted/invokeSnapSugar.js.map +1 -1
- package/dist/esm/permitted/requestSnaps.js.map +1 -1
- package/dist/esm/restricted/caveats/permittedCoinTypes.js.map +1 -1
- package/dist/esm/restricted/dialog.js +3 -9
- package/dist/esm/restricted/dialog.js.map +1 -1
- package/dist/esm/restricted/getBip32Entropy.js.map +1 -1
- package/dist/esm/restricted/getBip32PublicKey.js.map +1 -1
- package/dist/esm/restricted/getBip44Entropy.js +0 -1
- package/dist/esm/restricted/getBip44Entropy.js.map +1 -1
- package/dist/esm/restricted/getEntropy.js.map +1 -1
- package/dist/esm/restricted/getLocale.js.map +1 -1
- package/dist/esm/restricted/index.js +0 -3
- package/dist/esm/restricted/index.js.map +1 -1
- package/dist/esm/restricted/invokeSnap.js.map +1 -1
- package/dist/esm/restricted/manageAccounts.js.map +1 -1
- package/dist/esm/restricted/manageState.js +28 -24
- package/dist/esm/restricted/manageState.js.map +1 -1
- package/dist/esm/restricted/notify.js +3 -7
- package/dist/esm/restricted/notify.js.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/permitted/common/snapInstallation.d.ts +3 -5
- package/dist/types/permitted/getFile.d.ts +5 -4
- package/dist/types/permitted/getSnaps.d.ts +3 -3
- package/dist/types/permitted/handlers.d.ts +6 -12
- package/dist/types/permitted/invokeKeyring.d.ts +5 -7
- package/dist/types/permitted/invokeSnapSugar.d.ts +5 -8
- package/dist/types/permitted/requestSnaps.d.ts +3 -2
- package/dist/types/restricted/caveats/permittedCoinTypes.d.ts +1 -1
- package/dist/types/restricted/dialog.d.ts +34 -35
- package/dist/types/restricted/getBip32Entropy.d.ts +2 -3
- package/dist/types/restricted/getBip32PublicKey.d.ts +2 -6
- package/dist/types/restricted/getBip44Entropy.d.ts +2 -5
- package/dist/types/restricted/getEntropy.d.ts +3 -2
- package/dist/types/restricted/getLocale.d.ts +2 -1
- package/dist/types/restricted/index.d.ts +9 -90
- package/dist/types/restricted/invokeSnap.d.ts +8 -7
- package/dist/types/restricted/manageAccounts.d.ts +4 -3
- package/dist/types/restricted/manageState.d.ts +6 -15
- package/dist/types/restricted/notify.d.ts +4 -7
- package/package.json +4 -5
- package/dist/cjs/request.js +0 -6
- package/dist/cjs/request.js.map +0 -1
- package/dist/esm/request.js +0 -3
- package/dist/esm/request.js.map +0 -1
- package/dist/types/request.d.ts +0 -99
|
@@ -8,12 +8,7 @@ import type { InvokeSnapMethodHooks } from './invokeSnap';
|
|
|
8
8
|
import type { ManageAccountsMethodHooks } from './manageAccounts';
|
|
9
9
|
import type { ManageStateMethodHooks } from './manageState';
|
|
10
10
|
import type { NotifyMethodHooks } from './notify';
|
|
11
|
-
export type { DialogParameters } from './dialog';
|
|
12
|
-
export { DialogType } from './dialog';
|
|
13
|
-
export { ManageStateOperation } from './manageState';
|
|
14
11
|
export { WALLET_SNAP_PERMISSION_KEY } from './invokeSnap';
|
|
15
|
-
export type { NotificationArgs } from './notify';
|
|
16
|
-
export { NotificationType } from './notify';
|
|
17
12
|
export declare type RestrictedMethodHooks = DialogMethodHooks & GetBip32EntropyMethodHooks & GetBip32PublicKeyMethodHooks & GetBip44EntropyMethodHooks & GetEntropyHooks & InvokeSnapMethodHooks & ManageStateMethodHooks & NotifyMethodHooks & ManageAccountsMethodHooks & GetLocaleMethodHooks;
|
|
18
13
|
export declare const restrictedMethodPermissionBuilders: {
|
|
19
14
|
readonly snap_dialog: Readonly<{
|
|
@@ -24,68 +19,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
24
19
|
}, {
|
|
25
20
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
26
21
|
targetName: "snap_dialog";
|
|
27
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<
|
|
28
|
-
type: "alert";
|
|
29
|
-
content: import("@metamask/snaps-ui").Panel | {
|
|
30
|
-
value: string;
|
|
31
|
-
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
32
|
-
} | {
|
|
33
|
-
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
34
|
-
} | {
|
|
35
|
-
value: string;
|
|
36
|
-
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
37
|
-
} | {
|
|
38
|
-
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
39
|
-
} | {
|
|
40
|
-
value: string;
|
|
41
|
-
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
42
|
-
markdown?: boolean | undefined;
|
|
43
|
-
} | {
|
|
44
|
-
value: string;
|
|
45
|
-
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
46
|
-
};
|
|
47
|
-
} | {
|
|
48
|
-
type: "confirmation";
|
|
49
|
-
content: import("@metamask/snaps-ui").Panel | {
|
|
50
|
-
value: string;
|
|
51
|
-
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
52
|
-
} | {
|
|
53
|
-
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
54
|
-
} | {
|
|
55
|
-
value: string;
|
|
56
|
-
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
57
|
-
} | {
|
|
58
|
-
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
59
|
-
} | {
|
|
60
|
-
value: string;
|
|
61
|
-
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
62
|
-
markdown?: boolean | undefined;
|
|
63
|
-
} | {
|
|
64
|
-
value: string;
|
|
65
|
-
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
66
|
-
};
|
|
67
|
-
} | {
|
|
68
|
-
type: "prompt";
|
|
69
|
-
content: import("@metamask/snaps-ui").Panel | {
|
|
70
|
-
value: string;
|
|
71
|
-
type: import("@metamask/snaps-ui").NodeType.Copyable;
|
|
72
|
-
} | {
|
|
73
|
-
type: import("@metamask/snaps-ui").NodeType.Divider;
|
|
74
|
-
} | {
|
|
75
|
-
value: string;
|
|
76
|
-
type: import("@metamask/snaps-ui").NodeType.Heading;
|
|
77
|
-
} | {
|
|
78
|
-
type: import("@metamask/snaps-ui").NodeType.Spinner;
|
|
79
|
-
} | {
|
|
80
|
-
value: string;
|
|
81
|
-
type: import("@metamask/snaps-ui").NodeType.Text;
|
|
82
|
-
markdown?: boolean | undefined;
|
|
83
|
-
} | {
|
|
84
|
-
value: string;
|
|
85
|
-
type: import("@metamask/snaps-ui").NodeType.Image;
|
|
86
|
-
};
|
|
87
|
-
placeholder?: string | undefined;
|
|
88
|
-
}>) => Promise<string | boolean | null>;
|
|
22
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").DialogParams>) => Promise<string | boolean | null>;
|
|
89
23
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
90
24
|
}>;
|
|
91
25
|
readonly methodHooks: import("../utils").MethodHooksObject<DialogMethodHooks>;
|
|
@@ -97,10 +31,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
97
31
|
}, {
|
|
98
32
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
99
33
|
targetName: "snap_getBip32Entropy";
|
|
100
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<
|
|
101
|
-
path: string[];
|
|
102
|
-
curve: "ed25519" | "secp256k1";
|
|
103
|
-
}>) => Promise<import("@metamask/key-tree").JsonSLIP10Node>;
|
|
34
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").Bip32Entropy>) => Promise<import("@metamask/key-tree").JsonSLIP10Node>;
|
|
104
35
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
105
36
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
106
37
|
}>;
|
|
@@ -113,11 +44,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
113
44
|
}, {
|
|
114
45
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
115
46
|
targetName: "snap_getBip32PublicKey";
|
|
116
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<
|
|
117
|
-
path: ["m", ...(`${number}` | `${number}'`)[]];
|
|
118
|
-
curve: "ed25519" | "secp256k1";
|
|
119
|
-
compressed?: boolean | undefined;
|
|
120
|
-
}>) => Promise<string>;
|
|
47
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").GetBip32PublicKeyParams>) => Promise<string>;
|
|
121
48
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
122
49
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
123
50
|
}>;
|
|
@@ -130,7 +57,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
130
57
|
}, {
|
|
131
58
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
132
59
|
targetName: "snap_getBip44Entropy";
|
|
133
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("
|
|
60
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").Bip44Entropy>) => Promise<import("@metamask/key-tree").JsonBIP44CoinTypeNode>;
|
|
134
61
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
135
62
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
136
63
|
}>;
|
|
@@ -144,10 +71,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
144
71
|
}, {
|
|
145
72
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
146
73
|
targetName: "snap_getEntropy";
|
|
147
|
-
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<{
|
|
148
|
-
version: 1;
|
|
149
|
-
salt?: string | undefined;
|
|
150
|
-
}>) => Promise<`0x${string}`>;
|
|
74
|
+
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").GetEntropyParams>) => Promise<`0x${string}`>;
|
|
151
75
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
152
76
|
}>;
|
|
153
77
|
readonly methodHooks: import("../utils").MethodHooksObject<GetEntropyHooks>;
|
|
@@ -160,7 +84,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
160
84
|
}, {
|
|
161
85
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
162
86
|
targetName: "wallet_snap";
|
|
163
|
-
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<
|
|
87
|
+
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<import("./invokeSnap").InvokeSnapParams>) => Promise<import("@metamask/utils").Json>;
|
|
164
88
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
165
89
|
validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
|
|
166
90
|
sideEffect: {
|
|
@@ -177,7 +101,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
177
101
|
}, {
|
|
178
102
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
179
103
|
targetName: "snap_manageState";
|
|
180
|
-
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<import("
|
|
104
|
+
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").ManageStateParams>) => Promise<import("@metamask/snaps-sdk").ManageStateResult>;
|
|
181
105
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
182
106
|
}>;
|
|
183
107
|
readonly methodHooks: import("../utils").MethodHooksObject<ManageStateMethodHooks>;
|
|
@@ -190,7 +114,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
190
114
|
}, {
|
|
191
115
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
192
116
|
targetName: "snap_notify";
|
|
193
|
-
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("
|
|
117
|
+
methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").NotifyParams>) => Promise<null>;
|
|
194
118
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
195
119
|
}>;
|
|
196
120
|
readonly methodHooks: import("../utils").MethodHooksObject<NotifyMethodHooks>;
|
|
@@ -203,12 +127,7 @@ export declare const restrictedMethodPermissionBuilders: {
|
|
|
203
127
|
}, {
|
|
204
128
|
permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
|
|
205
129
|
targetName: "snap_manageAccounts";
|
|
206
|
-
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<
|
|
207
|
-
method: string;
|
|
208
|
-
} | {
|
|
209
|
-
params: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[];
|
|
210
|
-
method: string;
|
|
211
|
-
}>) => Promise<import("@metamask/utils").Json>;
|
|
130
|
+
methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/snaps-sdk").ManageAccountsParams>) => Promise<import("@metamask/utils").Json>;
|
|
212
131
|
allowedCaveats: readonly [string, ...string[]] | null;
|
|
213
132
|
}>;
|
|
214
133
|
readonly methodHooks: {
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, PermissionValidatorConstraint, PermissionSideEffect } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
-
import type {
|
|
3
|
+
import type { InvokeSnapResult, RequestSnapsParams, RequestSnapsResult } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { Snap, SnapRpcHookArgs } from '@metamask/snaps-utils';
|
|
4
5
|
import type { Json, NonEmptyArray } from '@metamask/utils';
|
|
5
6
|
import type { MethodHooksObject } from '../utils';
|
|
6
7
|
export declare const WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
7
8
|
export declare type InstallSnaps = {
|
|
8
9
|
type: `SnapController:install`;
|
|
9
|
-
handler: (origin: string, requestedSnaps:
|
|
10
|
+
handler: (origin: string, requestedSnaps: RequestSnapsParams) => Promise<RequestSnapsResult>;
|
|
10
11
|
};
|
|
11
12
|
export declare type GetPermittedSnaps = {
|
|
12
13
|
type: `SnapController:getPermitted`;
|
|
13
|
-
handler: (origin: string) =>
|
|
14
|
+
handler: (origin: string) => RequestSnapsResult;
|
|
14
15
|
};
|
|
15
16
|
declare type AllowedActions = InstallSnaps | GetPermittedSnaps;
|
|
16
17
|
export declare type InvokeSnapMethodHooks = {
|
|
17
|
-
getSnap: (snapId:
|
|
18
|
+
getSnap: (snapId: string) => Snap | undefined;
|
|
18
19
|
handleSnapRpcRequest: ({ snapId, origin, handler, request, }: SnapRpcHookArgs & {
|
|
19
|
-
snapId:
|
|
20
|
+
snapId: string;
|
|
20
21
|
}) => Promise<unknown>;
|
|
21
22
|
};
|
|
22
23
|
declare type InvokeSnapSpecificationBuilderOptions = {
|
|
@@ -25,7 +26,7 @@ declare type InvokeSnapSpecificationBuilderOptions = {
|
|
|
25
26
|
};
|
|
26
27
|
export declare type InvokeSnapParams = {
|
|
27
28
|
snapId: string;
|
|
28
|
-
request: Record<string,
|
|
29
|
+
request: Record<string, Json>;
|
|
29
30
|
};
|
|
30
31
|
/**
|
|
31
32
|
* The side-effect method to handle the snap install.
|
|
@@ -58,5 +59,5 @@ export declare const invokeSnapBuilder: Readonly<{
|
|
|
58
59
|
* @returns The method implementation which returns the result of `handleSnapRpcRequest`.
|
|
59
60
|
* @throws If the params are invalid.
|
|
60
61
|
*/
|
|
61
|
-
export declare function getInvokeSnapImplementation({ getSnap, handleSnapRpcRequest, }: InvokeSnapMethodHooks): (options: RestrictedMethodOptions<
|
|
62
|
+
export declare function getInvokeSnapImplementation({ getSnap, handleSnapRpcRequest, }: InvokeSnapMethodHooks): (options: RestrictedMethodOptions<InvokeSnapParams>) => Promise<InvokeSnapResult>;
|
|
62
63
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { RestrictedMethodOptions, ValidPermissionSpecification, PermissionSpecificationBuilder } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
+
import type { ManageAccountsParams, ManageAccountsResult } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { InferMatching } from '@metamask/snaps-utils';
|
|
3
5
|
import type { Json, NonEmptyArray } from '@metamask/utils';
|
|
4
|
-
import type { Infer } from 'superstruct';
|
|
5
6
|
declare const SnapMessageStruct: import("superstruct").Struct<{
|
|
6
7
|
method: string;
|
|
7
8
|
} | {
|
|
8
9
|
params: Record<string, Json> | Json[];
|
|
9
10
|
method: string;
|
|
10
11
|
}, null>;
|
|
11
|
-
declare type Message =
|
|
12
|
+
declare type Message = InferMatching<typeof SnapMessageStruct, ManageAccountsParams>;
|
|
12
13
|
export declare const methodName = "snap_manageAccounts";
|
|
13
14
|
export declare type ManageAccountsMethodHooks = {
|
|
14
15
|
/**
|
|
@@ -47,7 +48,7 @@ export declare const specificationBuilder: PermissionSpecificationBuilder<Permis
|
|
|
47
48
|
* successful state update/deletion or returns the decrypted state.
|
|
48
49
|
* @throws If the params are invalid.
|
|
49
50
|
*/
|
|
50
|
-
export declare function manageAccountsImplementation({ getSnapKeyring, }: ManageAccountsMethodHooks): (options: RestrictedMethodOptions<
|
|
51
|
+
export declare function manageAccountsImplementation({ getSnapKeyring, }: ManageAccountsMethodHooks): (options: RestrictedMethodOptions<ManageAccountsParams>) => Promise<ManageAccountsResult>;
|
|
51
52
|
export declare const manageAccountsBuilder: Readonly<{
|
|
52
53
|
readonly targetName: "snap_manageAccounts";
|
|
53
54
|
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, ManageAccountsSpecificationBuilderOptions, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';
|
|
4
4
|
import type { Json, NonEmptyArray, Hex } from '@metamask/utils';
|
|
5
5
|
import type { MethodHooksObject } from '../utils';
|
|
6
6
|
export declare const STATE_ENCRYPTION_SALT = "snap_manageState encryption";
|
|
@@ -19,19 +19,19 @@ export declare type ManageStateMethodHooks = {
|
|
|
19
19
|
/**
|
|
20
20
|
* A function that clears the state of the requesting Snap.
|
|
21
21
|
*/
|
|
22
|
-
clearSnapState: (snapId: string) =>
|
|
22
|
+
clearSnapState: (snapId: string, encrypted: boolean) => void;
|
|
23
23
|
/**
|
|
24
24
|
* A function that gets the encrypted state of the requesting Snap.
|
|
25
25
|
*
|
|
26
26
|
* @returns The current state of the Snap.
|
|
27
27
|
*/
|
|
28
|
-
getSnapState: (snapId: string) =>
|
|
28
|
+
getSnapState: (snapId: string, encrypted: boolean) => string;
|
|
29
29
|
/**
|
|
30
30
|
* A function that updates the state of the requesting Snap.
|
|
31
31
|
*
|
|
32
32
|
* @param newState - The new state of the Snap.
|
|
33
33
|
*/
|
|
34
|
-
updateSnapState: (snapId: string, newState: string) =>
|
|
34
|
+
updateSnapState: (snapId: string, newState: string, encrypted: boolean) => void;
|
|
35
35
|
/**
|
|
36
36
|
* Encrypts data with a key. This is assumed to perform symmetric encryption.
|
|
37
37
|
*
|
|
@@ -82,15 +82,6 @@ export declare const manageStateBuilder: Readonly<{
|
|
|
82
82
|
}>;
|
|
83
83
|
readonly methodHooks: MethodHooksObject<ManageStateMethodHooks>;
|
|
84
84
|
}>;
|
|
85
|
-
export declare enum ManageStateOperation {
|
|
86
|
-
ClearState = "clear",
|
|
87
|
-
GetState = "get",
|
|
88
|
-
UpdateState = "update"
|
|
89
|
-
}
|
|
90
|
-
export declare type ManageStateArgs = {
|
|
91
|
-
operation: EnumToUnion<ManageStateOperation>;
|
|
92
|
-
newState?: Record<string, Json>;
|
|
93
|
-
};
|
|
94
85
|
export declare const STORAGE_SIZE_LIMIT = 104857600;
|
|
95
86
|
/**
|
|
96
87
|
* Builds the method implementation for `snap_manageState`.
|
|
@@ -113,7 +104,7 @@ export declare const STORAGE_SIZE_LIMIT = 104857600;
|
|
|
113
104
|
* successful state update/deletion or returns the decrypted state.
|
|
114
105
|
* @throws If the params are invalid.
|
|
115
106
|
*/
|
|
116
|
-
export declare function getManageStateImplementation({ getMnemonic, getUnlockPromise, clearSnapState, getSnapState, updateSnapState, encrypt, decrypt, }: ManageStateMethodHooks): (options: RestrictedMethodOptions<
|
|
107
|
+
export declare function getManageStateImplementation({ getMnemonic, getUnlockPromise, clearSnapState, getSnapState, updateSnapState, encrypt, decrypt, }: ManageStateMethodHooks): (options: RestrictedMethodOptions<ManageStateParams>) => Promise<ManageStateResult>;
|
|
117
108
|
/**
|
|
118
109
|
* Validates the manageState method `params` and returns them cast to the correct
|
|
119
110
|
* type. Throws if validation fails.
|
|
@@ -123,5 +114,5 @@ export declare function getManageStateImplementation({ getMnemonic, getUnlockPro
|
|
|
123
114
|
* @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.
|
|
124
115
|
* @returns The validated method parameter object.
|
|
125
116
|
*/
|
|
126
|
-
export declare function getValidatedParams(params: unknown, method: string, storageSizeLimit?: number):
|
|
117
|
+
export declare function getValidatedParams(params: unknown, method: string, storageSizeLimit?: number): ManageStateParams;
|
|
127
118
|
export {};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from '@metamask/permission-controller';
|
|
2
2
|
import { PermissionType } from '@metamask/permission-controller';
|
|
3
|
-
import
|
|
3
|
+
import { NotificationType } from '@metamask/snaps-sdk';
|
|
4
|
+
import type { NotifyParams, NotifyResult, EnumToUnion } from '@metamask/snaps-sdk';
|
|
4
5
|
import type { NonEmptyArray } from '@metamask/utils';
|
|
5
6
|
import { type MethodHooksObject } from '../utils';
|
|
6
7
|
declare const methodName = "snap_notify";
|
|
7
|
-
export declare enum NotificationType {
|
|
8
|
-
InApp = "inApp",
|
|
9
|
-
Native = "native"
|
|
10
|
-
}
|
|
11
8
|
export declare type NotificationArgs = {
|
|
12
9
|
/**
|
|
13
10
|
* Enum type to determine notification type.
|
|
@@ -73,7 +70,7 @@ export declare const notifyBuilder: Readonly<{
|
|
|
73
70
|
* @returns The method implementation which returns `null` on success.
|
|
74
71
|
* @throws If the params are invalid.
|
|
75
72
|
*/
|
|
76
|
-
export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }: NotifyMethodHooks): (args: RestrictedMethodOptions<
|
|
73
|
+
export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }: NotifyMethodHooks): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
|
|
77
74
|
/**
|
|
78
75
|
* Validates the notify method `params` and returns them cast to the correct
|
|
79
76
|
* type. Throws if validation fails.
|
|
@@ -81,5 +78,5 @@ export declare function getImplementation({ showNativeNotification, showInAppNot
|
|
|
81
78
|
* @param params - The unvalidated params object from the method request.
|
|
82
79
|
* @returns The validated method parameter object.
|
|
83
80
|
*/
|
|
84
|
-
export declare function getValidatedParams(params: unknown):
|
|
81
|
+
export declare function getValidatedParams(params: unknown): NotifyParams;
|
|
85
82
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rpc-methods",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "MetaMask Snaps JSON-RPC method implementations.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -39,15 +39,15 @@
|
|
|
39
39
|
"@metamask/key-tree": "^9.0.0",
|
|
40
40
|
"@metamask/permission-controller": "^5.0.0",
|
|
41
41
|
"@metamask/rpc-errors": "^6.1.0",
|
|
42
|
-
"@metamask/snaps-
|
|
43
|
-
"@metamask/snaps-utils": "^
|
|
42
|
+
"@metamask/snaps-sdk": "^1.0.0",
|
|
43
|
+
"@metamask/snaps-utils": "^4.0.0",
|
|
44
44
|
"@metamask/utils": "^8.1.0",
|
|
45
45
|
"@noble/hashes": "^1.3.1",
|
|
46
46
|
"superstruct": "^1.0.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@lavamoat/allow-scripts": "^2.5.1",
|
|
50
|
-
"@metamask/auto-changelog": "^3.3
|
|
50
|
+
"@metamask/auto-changelog": "^3.4.3",
|
|
51
51
|
"@metamask/browser-passworder": "^4.1.0",
|
|
52
52
|
"@metamask/eslint-config": "^12.1.0",
|
|
53
53
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"eslint-plugin-n": "^15.7.0",
|
|
71
71
|
"eslint-plugin-prettier": "^4.2.1",
|
|
72
72
|
"eslint-plugin-promise": "^6.1.1",
|
|
73
|
-
"expect-type": "^0.15.0",
|
|
74
73
|
"jest": "^29.0.2",
|
|
75
74
|
"jest-it-up": "^2.0.0",
|
|
76
75
|
"prettier": "^2.7.1",
|
package/dist/cjs/request.js
DELETED
package/dist/cjs/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/request.ts"],"names":[],"mappings":""}
|
package/dist/esm/request.js
DELETED
package/dist/esm/request.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/request.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionType,\n RestrictedMethodOptions,\n PermittedHandlerExport,\n} from '@metamask/permission-controller';\nimport type { JsonRpcParams } from '@metamask/utils';\n\nimport type { methodHandlers } from './permitted';\nimport type { restrictedMethodPermissionBuilders } from './restricted';\n\n/**\n * Get the method implementation from a {@link PermittedHandlerExport}.\n *\n * @template Handler - A permitted handler export.\n */\ntype PermittedMethodImplementation<Handler> =\n Handler extends PermittedHandlerExport<any, infer Args, infer Result>\n ? (args: Args) => Promise<Result>\n : never;\n\n/**\n * Get a JSON-RPC method type from a {@link PermittedHandlerExport} and a method\n * name.\n *\n * @template MethodName - The name of the method.\n * @template Handler - A permitted handler export.\n */\ntype PermittedMethod<\n MethodName extends string,\n Handler,\n> = PermittedMethodImplementation<Handler> extends (\n args: infer Args,\n) => infer Return\n ? (args: { method: MethodName; params?: Args }) => Return\n : never;\n\n/**\n * Get a restricted method implementation from a\n * {@link PermissionSpecificationBuilder}.\n *\n * @template Builder - A permission specification builder.\n */\ntype RestrictedMethodImplementation<Builder> = Builder extends {\n specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n any,\n infer Specification\n >;\n}\n ? Specification['methodImplementation']\n : never;\n\n/**\n * Get a JSON-RPC method type from a {@link PermissionSpecificationBuilder}.\n *\n * @template Builder - A permission specification builder.\n */\ntype RestrictedMethod<Builder extends { targetName: string }> =\n RestrictedMethodImplementation<Builder> extends (\n args: infer Args,\n ) => infer Return\n ? Args extends RestrictedMethodOptions<infer Params>\n ? (args: { method: Builder['targetName']; params?: Params }) => Return\n : never\n : never;\n\n/**\n * A type containing all permitted JSON-RPC methods as functions.\n */\ntype PermittedMethodFunction = {\n [MethodName in keyof typeof methodHandlers]: PermittedMethod<\n MethodName,\n (typeof methodHandlers)[MethodName]\n >;\n};\n\n/**\n * A type containing all restricted JSON-RPC methods as functions.\n */\ntype RestrictedMethodFunction = {\n [Builder in keyof typeof restrictedMethodPermissionBuilders]: RestrictedMethod<\n (typeof restrictedMethodPermissionBuilders)[Builder]\n >;\n};\n\n/**\n * A type containing all supported JSON-RPC methods as functions.\n */\ntype MethodFunction = RestrictedMethodFunction & PermittedMethodFunction;\n\n/**\n * Fallback method name. `wallet_*` is supported by Snaps, but these functions\n * are not implemented in `@metamask/snaps-rpc-methods`, so we don't have a type for\n * them.\n */\ntype WalletMethodName = `wallet_${string}`;\n\n/**\n * Get a typed function if the method is defined in {@link MethodFunction}, or\n * a generic function if the method name extends {@link WalletMethodName}.\n * Otherwise, this returns `never`.\n */\ntype MethodFunctionFallback<MethodName> =\n MethodName extends keyof MethodFunction\n ? MethodFunction[MethodName]\n : MethodName extends WalletMethodName\n ? (args: { method: MethodName; params?: JsonRpcParams }) => Promise<unknown>\n : never;\n\n/**\n * Get the JSON-RPC object from a method name.\n *\n * @template MethodName - The name of the method. In most cases this is inferred\n * from the args.\n */\nexport type ObjectFromMethodName<\n MethodName extends keyof MethodFunction | WalletMethodName,\n> = {\n method: MethodName;\n params?: Parameters<MethodFunctionFallback<MethodName>>[0] extends {\n params?: infer Params;\n }\n ? Params\n : never;\n};\n\nexport type MethodReturnType<\n MethodName extends keyof MethodFunction | WalletMethodName,\n> = ReturnType<MethodFunctionFallback<MethodName>>;\n\n/**\n * A function that takes a JSON-RPC request and returns a JSON-RPC response.\n *\n * @template MethodName - The name of the method. In most cases this is inferred\n * from the args.\n */\nexport type RequestFunction = <\n MethodName extends keyof MethodFunction | WalletMethodName,\n>(\n args: ObjectFromMethodName<MethodName>,\n) => MethodReturnType<MethodName>;\n\n/**\n * The global `snap` object. This is injected into the global scope of a snap.\n */\nexport type SnapsGlobalObject = {\n request: RequestFunction;\n};\n"],"names":[],"mappings":"AAAA,WAoJE"}
|
package/dist/types/request.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import type { PermissionSpecificationBuilder, PermissionType, RestrictedMethodOptions, PermittedHandlerExport } from '@metamask/permission-controller';
|
|
2
|
-
import type { JsonRpcParams } from '@metamask/utils';
|
|
3
|
-
import type { methodHandlers } from './permitted';
|
|
4
|
-
import type { restrictedMethodPermissionBuilders } from './restricted';
|
|
5
|
-
/**
|
|
6
|
-
* Get the method implementation from a {@link PermittedHandlerExport}.
|
|
7
|
-
*
|
|
8
|
-
* @template Handler - A permitted handler export.
|
|
9
|
-
*/
|
|
10
|
-
declare type PermittedMethodImplementation<Handler> = Handler extends PermittedHandlerExport<any, infer Args, infer Result> ? (args: Args) => Promise<Result> : never;
|
|
11
|
-
/**
|
|
12
|
-
* Get a JSON-RPC method type from a {@link PermittedHandlerExport} and a method
|
|
13
|
-
* name.
|
|
14
|
-
*
|
|
15
|
-
* @template MethodName - The name of the method.
|
|
16
|
-
* @template Handler - A permitted handler export.
|
|
17
|
-
*/
|
|
18
|
-
declare type PermittedMethod<MethodName extends string, Handler> = PermittedMethodImplementation<Handler> extends (args: infer Args) => infer Return ? (args: {
|
|
19
|
-
method: MethodName;
|
|
20
|
-
params?: Args;
|
|
21
|
-
}) => Return : never;
|
|
22
|
-
/**
|
|
23
|
-
* Get a restricted method implementation from a
|
|
24
|
-
* {@link PermissionSpecificationBuilder}.
|
|
25
|
-
*
|
|
26
|
-
* @template Builder - A permission specification builder.
|
|
27
|
-
*/
|
|
28
|
-
declare type RestrictedMethodImplementation<Builder> = Builder extends {
|
|
29
|
-
specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, any, infer Specification>;
|
|
30
|
-
} ? Specification['methodImplementation'] : never;
|
|
31
|
-
/**
|
|
32
|
-
* Get a JSON-RPC method type from a {@link PermissionSpecificationBuilder}.
|
|
33
|
-
*
|
|
34
|
-
* @template Builder - A permission specification builder.
|
|
35
|
-
*/
|
|
36
|
-
declare type RestrictedMethod<Builder extends {
|
|
37
|
-
targetName: string;
|
|
38
|
-
}> = RestrictedMethodImplementation<Builder> extends (args: infer Args) => infer Return ? Args extends RestrictedMethodOptions<infer Params> ? (args: {
|
|
39
|
-
method: Builder['targetName'];
|
|
40
|
-
params?: Params;
|
|
41
|
-
}) => Return : never : never;
|
|
42
|
-
/**
|
|
43
|
-
* A type containing all permitted JSON-RPC methods as functions.
|
|
44
|
-
*/
|
|
45
|
-
declare type PermittedMethodFunction = {
|
|
46
|
-
[MethodName in keyof typeof methodHandlers]: PermittedMethod<MethodName, (typeof methodHandlers)[MethodName]>;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* A type containing all restricted JSON-RPC methods as functions.
|
|
50
|
-
*/
|
|
51
|
-
declare type RestrictedMethodFunction = {
|
|
52
|
-
[Builder in keyof typeof restrictedMethodPermissionBuilders]: RestrictedMethod<(typeof restrictedMethodPermissionBuilders)[Builder]>;
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* A type containing all supported JSON-RPC methods as functions.
|
|
56
|
-
*/
|
|
57
|
-
declare type MethodFunction = RestrictedMethodFunction & PermittedMethodFunction;
|
|
58
|
-
/**
|
|
59
|
-
* Fallback method name. `wallet_*` is supported by Snaps, but these functions
|
|
60
|
-
* are not implemented in `@metamask/snaps-rpc-methods`, so we don't have a type for
|
|
61
|
-
* them.
|
|
62
|
-
*/
|
|
63
|
-
declare type WalletMethodName = `wallet_${string}`;
|
|
64
|
-
/**
|
|
65
|
-
* Get a typed function if the method is defined in {@link MethodFunction}, or
|
|
66
|
-
* a generic function if the method name extends {@link WalletMethodName}.
|
|
67
|
-
* Otherwise, this returns `never`.
|
|
68
|
-
*/
|
|
69
|
-
declare type MethodFunctionFallback<MethodName> = MethodName extends keyof MethodFunction ? MethodFunction[MethodName] : MethodName extends WalletMethodName ? (args: {
|
|
70
|
-
method: MethodName;
|
|
71
|
-
params?: JsonRpcParams;
|
|
72
|
-
}) => Promise<unknown> : never;
|
|
73
|
-
/**
|
|
74
|
-
* Get the JSON-RPC object from a method name.
|
|
75
|
-
*
|
|
76
|
-
* @template MethodName - The name of the method. In most cases this is inferred
|
|
77
|
-
* from the args.
|
|
78
|
-
*/
|
|
79
|
-
export declare type ObjectFromMethodName<MethodName extends keyof MethodFunction | WalletMethodName> = {
|
|
80
|
-
method: MethodName;
|
|
81
|
-
params?: Parameters<MethodFunctionFallback<MethodName>>[0] extends {
|
|
82
|
-
params?: infer Params;
|
|
83
|
-
} ? Params : never;
|
|
84
|
-
};
|
|
85
|
-
export declare type MethodReturnType<MethodName extends keyof MethodFunction | WalletMethodName> = ReturnType<MethodFunctionFallback<MethodName>>;
|
|
86
|
-
/**
|
|
87
|
-
* A function that takes a JSON-RPC request and returns a JSON-RPC response.
|
|
88
|
-
*
|
|
89
|
-
* @template MethodName - The name of the method. In most cases this is inferred
|
|
90
|
-
* from the args.
|
|
91
|
-
*/
|
|
92
|
-
export declare type RequestFunction = <MethodName extends keyof MethodFunction | WalletMethodName>(args: ObjectFromMethodName<MethodName>) => MethodReturnType<MethodName>;
|
|
93
|
-
/**
|
|
94
|
-
* The global `snap` object. This is injected into the global scope of a snap.
|
|
95
|
-
*/
|
|
96
|
-
export declare type SnapsGlobalObject = {
|
|
97
|
-
request: RequestFunction;
|
|
98
|
-
};
|
|
99
|
-
export {};
|