@metamask/snaps-rpc-methods 3.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.
Files changed (141) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/LICENSE +18 -0
  3. package/README.md +3 -0
  4. package/dist/cjs/index.js +43 -0
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/permitted/common/snapInstallation.js +33 -0
  7. package/dist/cjs/permitted/common/snapInstallation.js.map +1 -0
  8. package/dist/cjs/permitted/getFile.js +63 -0
  9. package/dist/cjs/permitted/getFile.js.map +1 -0
  10. package/dist/cjs/permitted/getSnaps.js +39 -0
  11. package/dist/cjs/permitted/getSnaps.js.map +1 -0
  12. package/dist/cjs/permitted/handlers.js +33 -0
  13. package/dist/cjs/permitted/handlers.js.map +1 -0
  14. package/dist/cjs/permitted/index.js +21 -0
  15. package/dist/cjs/permitted/index.js.map +1 -0
  16. package/dist/cjs/permitted/invokeKeyring.js +88 -0
  17. package/dist/cjs/permitted/invokeKeyring.js.map +1 -0
  18. package/dist/cjs/permitted/invokeSnapSugar.js +62 -0
  19. package/dist/cjs/permitted/invokeSnapSugar.js.map +1 -0
  20. package/dist/cjs/permitted/middleware.js +38 -0
  21. package/dist/cjs/permitted/middleware.js.map +1 -0
  22. package/dist/cjs/permitted/requestSnaps.js +122 -0
  23. package/dist/cjs/permitted/requestSnaps.js.map +1 -0
  24. package/dist/cjs/request.js +6 -0
  25. package/dist/cjs/request.js.map +1 -0
  26. package/dist/cjs/restricted/caveats/index.js +38 -0
  27. package/dist/cjs/restricted/caveats/index.js.map +1 -0
  28. package/dist/cjs/restricted/caveats/permittedCoinTypes.js +83 -0
  29. package/dist/cjs/restricted/caveats/permittedCoinTypes.js.map +1 -0
  30. package/dist/cjs/restricted/caveats/permittedDerivationPaths.js +67 -0
  31. package/dist/cjs/restricted/caveats/permittedDerivationPaths.js.map +1 -0
  32. package/dist/cjs/restricted/caveats/snapIds.js +59 -0
  33. package/dist/cjs/restricted/caveats/snapIds.js.map +1 -0
  34. package/dist/cjs/restricted/dialog.js +150 -0
  35. package/dist/cjs/restricted/dialog.js.map +1 -0
  36. package/dist/cjs/restricted/getBip32Entropy.js +76 -0
  37. package/dist/cjs/restricted/getBip32Entropy.js.map +1 -0
  38. package/dist/cjs/restricted/getBip32PublicKey.js +91 -0
  39. package/dist/cjs/restricted/getBip32PublicKey.js.map +1 -0
  40. package/dist/cjs/restricted/getBip44Entropy.js +77 -0
  41. package/dist/cjs/restricted/getBip44Entropy.js.map +1 -0
  42. package/dist/cjs/restricted/getEntropy.js +76 -0
  43. package/dist/cjs/restricted/getEntropy.js.map +1 -0
  44. package/dist/cjs/restricted/getLocale.js +49 -0
  45. package/dist/cjs/restricted/getLocale.js.map +1 -0
  46. package/dist/cjs/restricted/index.js +65 -0
  47. package/dist/cjs/restricted/index.js.map +1 -0
  48. package/dist/cjs/restricted/invokeSnap.js +99 -0
  49. package/dist/cjs/restricted/invokeSnap.js.map +1 -0
  50. package/dist/cjs/restricted/manageAccounts.js +68 -0
  51. package/dist/cjs/restricted/manageAccounts.js.map +1 -0
  52. package/dist/cjs/restricted/manageState.js +216 -0
  53. package/dist/cjs/restricted/manageState.js.map +1 -0
  54. package/dist/cjs/restricted/notify.js +94 -0
  55. package/dist/cjs/restricted/notify.js.map +1 -0
  56. package/dist/cjs/utils.js +98 -0
  57. package/dist/cjs/utils.js.map +1 -0
  58. package/dist/esm/index.js +6 -0
  59. package/dist/esm/index.js.map +1 -0
  60. package/dist/esm/permitted/common/snapInstallation.js +33 -0
  61. package/dist/esm/permitted/common/snapInstallation.js.map +1 -0
  62. package/dist/esm/permitted/getFile.js +45 -0
  63. package/dist/esm/permitted/getFile.js.map +1 -0
  64. package/dist/esm/permitted/getSnaps.js +31 -0
  65. package/dist/esm/permitted/getSnaps.js.map +1 -0
  66. package/dist/esm/permitted/handlers.js +15 -0
  67. package/dist/esm/permitted/handlers.js.map +1 -0
  68. package/dist/esm/permitted/index.js +4 -0
  69. package/dist/esm/permitted/index.js.map +1 -0
  70. package/dist/esm/permitted/invokeKeyring.js +80 -0
  71. package/dist/esm/permitted/invokeKeyring.js.map +1 -0
  72. package/dist/esm/permitted/invokeSnapSugar.js +60 -0
  73. package/dist/esm/permitted/invokeSnapSugar.js.map +1 -0
  74. package/dist/esm/permitted/middleware.js +34 -0
  75. package/dist/esm/permitted/middleware.js.map +1 -0
  76. package/dist/esm/permitted/requestSnaps.js +117 -0
  77. package/dist/esm/permitted/requestSnaps.js.map +1 -0
  78. package/dist/esm/request.js +3 -0
  79. package/dist/esm/request.js.map +1 -0
  80. package/dist/esm/restricted/caveats/index.js +20 -0
  81. package/dist/esm/restricted/caveats/index.js.map +1 -0
  82. package/dist/esm/restricted/caveats/permittedCoinTypes.js +77 -0
  83. package/dist/esm/restricted/caveats/permittedCoinTypes.js.map +1 -0
  84. package/dist/esm/restricted/caveats/permittedDerivationPaths.js +64 -0
  85. package/dist/esm/restricted/caveats/permittedDerivationPaths.js.map +1 -0
  86. package/dist/esm/restricted/caveats/snapIds.js +50 -0
  87. package/dist/esm/restricted/caveats/snapIds.js.map +1 -0
  88. package/dist/esm/restricted/dialog.js +137 -0
  89. package/dist/esm/restricted/dialog.js.map +1 -0
  90. package/dist/esm/restricted/getBip32Entropy.js +67 -0
  91. package/dist/esm/restricted/getBip32Entropy.js.map +1 -0
  92. package/dist/esm/restricted/getBip32PublicKey.js +79 -0
  93. package/dist/esm/restricted/getBip32PublicKey.js.map +1 -0
  94. package/dist/esm/restricted/getBip44Entropy.js +70 -0
  95. package/dist/esm/restricted/getBip44Entropy.js.map +1 -0
  96. package/dist/esm/restricted/getEntropy.js +58 -0
  97. package/dist/esm/restricted/getEntropy.js.map +1 -0
  98. package/dist/esm/restricted/getLocale.js +42 -0
  99. package/dist/esm/restricted/getLocale.js.map +1 -0
  100. package/dist/esm/restricted/index.js +29 -0
  101. package/dist/esm/restricted/index.js.map +1 -0
  102. package/dist/esm/restricted/invokeSnap.js +89 -0
  103. package/dist/esm/restricted/invokeSnap.js.map +1 -0
  104. package/dist/esm/restricted/manageAccounts.js +60 -0
  105. package/dist/esm/restricted/manageAccounts.js.map +1 -0
  106. package/dist/esm/restricted/manageState.js +221 -0
  107. package/dist/esm/restricted/manageState.js.map +1 -0
  108. package/dist/esm/restricted/notify.js +89 -0
  109. package/dist/esm/restricted/notify.js.map +1 -0
  110. package/dist/esm/utils.js +124 -0
  111. package/dist/esm/utils.js.map +1 -0
  112. package/dist/types/__fixtures__/entropy.d.ts +14 -0
  113. package/dist/types/__fixtures__/index.d.ts +1 -0
  114. package/dist/types/index.d.ts +6 -0
  115. package/dist/types/permitted/common/snapInstallation.d.ts +16 -0
  116. package/dist/types/permitted/getFile.d.ts +14 -0
  117. package/dist/types/permitted/getSnaps.d.ts +13 -0
  118. package/dist/types/permitted/handlers.d.ts +14 -0
  119. package/dist/types/permitted/index.d.ts +5 -0
  120. package/dist/types/permitted/invokeKeyring.d.ts +17 -0
  121. package/dist/types/permitted/invokeSnapSugar.d.ts +32 -0
  122. package/dist/types/permitted/middleware.d.ts +10 -0
  123. package/dist/types/permitted/requestSnaps.d.ts +50 -0
  124. package/dist/types/request.d.ts +99 -0
  125. package/dist/types/restricted/caveats/index.d.ts +8 -0
  126. package/dist/types/restricted/caveats/permittedCoinTypes.d.ts +29 -0
  127. package/dist/types/restricted/caveats/permittedDerivationPaths.d.ts +32 -0
  128. package/dist/types/restricted/caveats/snapIds.d.ts +21 -0
  129. package/dist/types/restricted/dialog.d.ts +113 -0
  130. package/dist/types/restricted/getBip32Entropy.d.ts +45 -0
  131. package/dist/types/restricted/getBip32PublicKey.d.ts +60 -0
  132. package/dist/types/restricted/getBip44Entropy.d.ts +49 -0
  133. package/dist/types/restricted/getEntropy.d.ts +60 -0
  134. package/dist/types/restricted/getLocale.d.ts +47 -0
  135. package/dist/types/restricted/index.d.ts +232 -0
  136. package/dist/types/restricted/invokeSnap.d.ts +62 -0
  137. package/dist/types/restricted/manageAccounts.d.ts +63 -0
  138. package/dist/types/restricted/manageState.d.ts +127 -0
  139. package/dist/types/restricted/notify.d.ts +81 -0
  140. package/dist/types/utils.d.ts +94 -0
  141. package/package.json +88 -0
@@ -0,0 +1,113 @@
1
+ import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from '@metamask/permission-controller';
2
+ import { PermissionType } from '@metamask/permission-controller';
3
+ import type { Component } from '@metamask/snaps-ui';
4
+ import type { EnumToUnion } from '@metamask/snaps-utils';
5
+ import type { NonEmptyArray } from '@metamask/utils';
6
+ import type { Infer, Struct } from 'superstruct';
7
+ import type { MethodHooksObject } from '../utils';
8
+ declare const methodName = "snap_dialog";
9
+ export declare enum DialogType {
10
+ Alert = "alert",
11
+ Confirmation = "confirmation",
12
+ Prompt = "prompt"
13
+ }
14
+ declare const PlaceholderStruct: Struct<string | undefined, null>;
15
+ export declare type Placeholder = Infer<typeof PlaceholderStruct>;
16
+ declare type ShowDialog = (snapId: string, type: EnumToUnion<DialogType>, content: Component, placeholder?: Placeholder) => Promise<null | boolean | string>;
17
+ export declare type DialogMethodHooks = {
18
+ /**
19
+ * @param snapId - The ID of the Snap that created the alert.
20
+ * @param type - The dialog type.
21
+ * @param content - The dialog custom UI.
22
+ * @param placeholder - The placeholder for the Prompt dialog input.
23
+ */
24
+ showDialog: ShowDialog;
25
+ };
26
+ declare type DialogSpecificationBuilderOptions = {
27
+ allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
28
+ methodHooks: DialogMethodHooks;
29
+ };
30
+ export declare const dialogBuilder: Readonly<{
31
+ readonly targetName: "snap_dialog";
32
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, DialogSpecificationBuilderOptions, {
33
+ permissionType: PermissionType.RestrictedMethod;
34
+ targetName: typeof methodName;
35
+ methodImplementation: ReturnType<typeof getDialogImplementation>;
36
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
37
+ }>;
38
+ readonly methodHooks: MethodHooksObject<DialogMethodHooks>;
39
+ }>;
40
+ declare const DialogParametersStruct: Struct<{
41
+ type: "alert";
42
+ content: import("@metamask/snaps-ui").Panel | {
43
+ value: string;
44
+ type: import("@metamask/snaps-ui").NodeType.Copyable;
45
+ } | {
46
+ type: import("@metamask/snaps-ui").NodeType.Divider;
47
+ } | {
48
+ value: string;
49
+ type: import("@metamask/snaps-ui").NodeType.Heading;
50
+ } | {
51
+ type: import("@metamask/snaps-ui").NodeType.Spinner;
52
+ } | {
53
+ value: string;
54
+ type: import("@metamask/snaps-ui").NodeType.Text;
55
+ markdown?: boolean | undefined;
56
+ } | {
57
+ value: string;
58
+ type: import("@metamask/snaps-ui").NodeType.Image;
59
+ };
60
+ } | {
61
+ type: "confirmation";
62
+ content: import("@metamask/snaps-ui").Panel | {
63
+ value: string;
64
+ type: import("@metamask/snaps-ui").NodeType.Copyable;
65
+ } | {
66
+ type: import("@metamask/snaps-ui").NodeType.Divider;
67
+ } | {
68
+ value: string;
69
+ type: import("@metamask/snaps-ui").NodeType.Heading;
70
+ } | {
71
+ type: import("@metamask/snaps-ui").NodeType.Spinner;
72
+ } | {
73
+ value: string;
74
+ type: import("@metamask/snaps-ui").NodeType.Text;
75
+ markdown?: boolean | undefined;
76
+ } | {
77
+ value: string;
78
+ type: import("@metamask/snaps-ui").NodeType.Image;
79
+ };
80
+ } | {
81
+ type: "prompt";
82
+ content: import("@metamask/snaps-ui").Panel | {
83
+ value: string;
84
+ type: import("@metamask/snaps-ui").NodeType.Copyable;
85
+ } | {
86
+ type: import("@metamask/snaps-ui").NodeType.Divider;
87
+ } | {
88
+ value: string;
89
+ type: import("@metamask/snaps-ui").NodeType.Heading;
90
+ } | {
91
+ type: import("@metamask/snaps-ui").NodeType.Spinner;
92
+ } | {
93
+ value: string;
94
+ type: import("@metamask/snaps-ui").NodeType.Text;
95
+ markdown?: boolean | undefined;
96
+ } | {
97
+ value: string;
98
+ type: import("@metamask/snaps-ui").NodeType.Image;
99
+ };
100
+ placeholder?: string | undefined;
101
+ }, null>;
102
+ export declare type DialogParameters = Infer<typeof DialogParametersStruct>;
103
+ /**
104
+ * Builds the method implementation for `snap_dialog`.
105
+ *
106
+ * @param hooks - The RPC method hooks.
107
+ * @param hooks.showDialog - A function that shows the specified dialog in the
108
+ * MetaMask UI and returns the appropriate value for the dialog type.
109
+ * @returns The method implementation which return value depends on the dialog
110
+ * type, valid return types are: string, boolean, null.
111
+ */
112
+ export declare function getDialogImplementation({ showDialog }: DialogMethodHooks): (args: RestrictedMethodOptions<DialogParameters>) => Promise<boolean | null | string>;
113
+ export {};
@@ -0,0 +1,45 @@
1
+ import type { JsonSLIP10Node } from '@metamask/key-tree';
2
+ import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from '@metamask/permission-controller';
3
+ import { PermissionType } from '@metamask/permission-controller';
4
+ import type { Bip32Entropy } from '@metamask/snaps-utils';
5
+ import type { NonEmptyArray } from '@metamask/utils';
6
+ import type { MethodHooksObject } from '../utils';
7
+ declare const targetName = "snap_getBip32Entropy";
8
+ export declare type GetBip32EntropyMethodHooks = {
9
+ /**
10
+ * @returns The mnemonic of the user's primary keyring.
11
+ */
12
+ getMnemonic: () => Promise<Uint8Array>;
13
+ /**
14
+ * Waits for the extension to be unlocked.
15
+ *
16
+ * @returns A promise that resolves once the extension is unlocked.
17
+ */
18
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
19
+ };
20
+ declare type GetBip32EntropySpecificationBuilderOptions = {
21
+ methodHooks: GetBip32EntropyMethodHooks;
22
+ };
23
+ export declare const getBip32EntropyBuilder: Readonly<{
24
+ readonly targetName: "snap_getBip32Entropy";
25
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32EntropySpecificationBuilderOptions, {
26
+ permissionType: PermissionType.RestrictedMethod;
27
+ targetName: typeof targetName;
28
+ methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;
29
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
30
+ validator: PermissionValidatorConstraint;
31
+ }>;
32
+ readonly methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks>;
33
+ }>;
34
+ /**
35
+ * Builds the method implementation for `snap_getBip32Entropy`.
36
+ *
37
+ * @param hooks - The RPC method hooks.
38
+ * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
39
+ * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
40
+ * and prompts the user to unlock their MetaMask if it is locked.
41
+ * @returns The method implementation which returns a `JsonSLIP10Node`.
42
+ * @throws If the params are invalid.
43
+ */
44
+ export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<Bip32Entropy>) => Promise<JsonSLIP10Node>;
45
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from '@metamask/permission-controller';
2
+ import { PermissionType } from '@metamask/permission-controller';
3
+ import type { NonEmptyArray } from '@metamask/utils';
4
+ import type { MethodHooksObject } from '../utils';
5
+ declare const targetName = "snap_getBip32PublicKey";
6
+ export declare type GetBip32PublicKeyMethodHooks = {
7
+ /**
8
+ * @returns The mnemonic of the user's primary keyring.
9
+ */
10
+ getMnemonic: () => Promise<Uint8Array>;
11
+ /**
12
+ * Waits for the extension to be unlocked.
13
+ *
14
+ * @returns A promise that resolves once the extension is unlocked.
15
+ */
16
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
17
+ };
18
+ declare type GetBip32PublicKeySpecificationBuilderOptions = {
19
+ methodHooks: GetBip32PublicKeyMethodHooks;
20
+ };
21
+ declare type GetBip32PublicKeyParameters = {
22
+ path: ['m', ...(`${number}` | `${number}'`)[]];
23
+ curve: 'secp256k1' | 'ed25519';
24
+ compressed?: boolean;
25
+ };
26
+ export declare const Bip32PublicKeyArgsStruct: import("superstruct").Struct<{
27
+ path: string[];
28
+ curve: "ed25519" | "secp256k1";
29
+ compressed?: boolean | undefined;
30
+ }, {
31
+ path: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
32
+ curve: import("superstruct").Struct<"ed25519" | "secp256k1", {
33
+ ed25519: "ed25519";
34
+ secp256k1: "secp256k1";
35
+ }>;
36
+ compressed: import("superstruct").Struct<boolean | undefined, null>;
37
+ }>;
38
+ export declare const getBip32PublicKeyBuilder: Readonly<{
39
+ readonly targetName: "snap_getBip32PublicKey";
40
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32PublicKeySpecificationBuilderOptions, {
41
+ permissionType: PermissionType.RestrictedMethod;
42
+ targetName: typeof targetName;
43
+ methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;
44
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
45
+ validator: PermissionValidatorConstraint;
46
+ }>;
47
+ readonly methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks>;
48
+ }>;
49
+ /**
50
+ * Builds the method implementation for `snap_getBip32PublicKey`.
51
+ *
52
+ * @param hooks - The RPC method hooks.
53
+ * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
54
+ * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
55
+ * and prompts the user to unlock their MetaMask if it is locked.
56
+ * @returns The method implementation which returns a public key.
57
+ * @throws If the params are invalid.
58
+ */
59
+ export declare function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParameters>) => Promise<string>;
60
+ export {};
@@ -0,0 +1,49 @@
1
+ import type { JsonBIP44CoinTypeNode } from '@metamask/key-tree';
2
+ import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from '@metamask/permission-controller';
3
+ import { PermissionType } from '@metamask/permission-controller';
4
+ import type { NonEmptyArray } from '@metamask/utils';
5
+ import type { MethodHooksObject } from '../utils';
6
+ declare const targetName = "snap_getBip44Entropy";
7
+ export declare type GetBip44EntropyMethodHooks = {
8
+ /**
9
+ * @returns The mnemonic of the user's primary keyring.
10
+ */
11
+ getMnemonic: () => Promise<Uint8Array>;
12
+ /**
13
+ * Waits for the extension to be unlocked.
14
+ *
15
+ * @returns A promise that resolves once the extension is unlocked.
16
+ */
17
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
18
+ };
19
+ declare type GetBip44EntropySpecificationBuilderOptions = {
20
+ methodHooks: GetBip44EntropyMethodHooks;
21
+ };
22
+ export declare type GetBip44EntropyParams = {
23
+ coinType: number;
24
+ };
25
+ export declare const getBip44EntropyBuilder: Readonly<{
26
+ readonly targetName: "snap_getBip44Entropy";
27
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip44EntropySpecificationBuilderOptions, {
28
+ permissionType: PermissionType.RestrictedMethod;
29
+ targetName: typeof targetName;
30
+ methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;
31
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
32
+ validator: PermissionValidatorConstraint;
33
+ }>;
34
+ readonly methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks>;
35
+ }>;
36
+ /**
37
+ * Builds the method implementation for `snap_getBip44Entropy`.
38
+ *
39
+ * @param hooks - The RPC method hooks.
40
+ * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
41
+ * of the user.
42
+ * @param hooks.getUnlockPromise - A function that resolves once the MetaMask
43
+ * extension is unlocked and prompts the user to unlock their MetaMask if it is
44
+ * locked.
45
+ * @returns The method implementation which returns a `BIP44CoinTypeNode`.
46
+ * @throws If the params are invalid.
47
+ */
48
+ export declare function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip44EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip44EntropyParams>) => Promise<JsonBIP44CoinTypeNode>;
49
+ export {};
@@ -0,0 +1,60 @@
1
+ import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from '@metamask/permission-controller';
2
+ import { PermissionType } from '@metamask/permission-controller';
3
+ import type { Hex, NonEmptyArray } from '@metamask/utils';
4
+ import type { Infer } from 'superstruct';
5
+ import type { MethodHooksObject } from '../utils';
6
+ declare const targetName = "snap_getEntropy";
7
+ declare type GetEntropySpecificationBuilderOptions = {
8
+ allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
9
+ methodHooks: GetEntropyHooks;
10
+ };
11
+ export declare const GetEntropyArgsStruct: import("superstruct").Struct<{
12
+ version: 1;
13
+ salt?: string | undefined;
14
+ }, {
15
+ version: import("superstruct").Struct<1, 1>;
16
+ salt: import("superstruct").Struct<string | undefined, null>;
17
+ }>;
18
+ /**
19
+ * @property version - The version of the `snap_getEntropy` method. This must be
20
+ * the numeric literal `1`.
21
+ * @property salt - A string to use as the salt when deriving the entropy. If
22
+ * omitted, the salt will be an empty string.
23
+ */
24
+ export declare type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;
25
+ export declare const getEntropyBuilder: Readonly<{
26
+ readonly targetName: "snap_getEntropy";
27
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetEntropySpecificationBuilderOptions, {
28
+ permissionType: PermissionType.RestrictedMethod;
29
+ targetName: typeof targetName;
30
+ methodImplementation: ReturnType<typeof getEntropyImplementation>;
31
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
32
+ }>;
33
+ readonly methodHooks: MethodHooksObject<GetEntropyHooks>;
34
+ }>;
35
+ export declare type GetEntropyHooks = {
36
+ /**
37
+ * @returns The mnemonic of the user's primary keyring.
38
+ */
39
+ getMnemonic: () => Promise<Uint8Array>;
40
+ /**
41
+ * Waits for the extension to be unlocked.
42
+ *
43
+ * @returns A promise that resolves once the extension is unlocked.
44
+ */
45
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
46
+ };
47
+ /**
48
+ * Builds the method implementation for `snap_getEntropy`. The implementation
49
+ * is based on the reference implementation of
50
+ * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
51
+ *
52
+ * @param hooks - The RPC method hooks.
53
+ * @param hooks.getMnemonic - The method to get the mnemonic of the user's
54
+ * primary keyring.
55
+ * @param hooks.getUnlockPromise - The method to get a promise that resolves
56
+ * once the extension is unlocked.
57
+ * @returns The method implementation.
58
+ */
59
+ declare function getEntropyImplementation({ getMnemonic, getUnlockPromise, }: GetEntropyHooks): (options: RestrictedMethodOptions<GetEntropyArgs>) => Promise<Hex>;
60
+ export {};
@@ -0,0 +1,47 @@
1
+ import type { PermissionSpecificationBuilder, ValidPermissionSpecification, RestrictedMethodOptions, RestrictedMethodParameters } from '@metamask/permission-controller';
2
+ import { PermissionType } from '@metamask/permission-controller';
3
+ import type { NonEmptyArray } from '@metamask/utils';
4
+ import type { MethodHooksObject } from '../utils';
5
+ declare const methodName = "snap_getLocale";
6
+ export declare type GetLocaleMethodHooks = {
7
+ getLocale: () => Promise<string>;
8
+ };
9
+ declare type SpecificationBuilderOptions = {
10
+ allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
11
+ methodHooks: GetLocaleMethodHooks;
12
+ };
13
+ declare type Specification = ValidPermissionSpecification<{
14
+ permissionType: PermissionType.RestrictedMethod;
15
+ targetName: typeof methodName;
16
+ methodImplementation: ReturnType<typeof getImplementation>;
17
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
18
+ }>;
19
+ /**
20
+ * The specification builder for the `snap_getLocale` permission.
21
+ * `snap_getLocale` allows snaps to get the user selected locale.
22
+ *
23
+ * @param options - The specification builder options.
24
+ * @param options.allowedCaveats - The optional allowed caveats for the permission.
25
+ * @param options.methodHooks - The RPC method hooks needed by the method implementation.
26
+ * @returns The specification for the `snap_getLocale` permission.
27
+ */
28
+ export declare const specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, SpecificationBuilderOptions, Specification>;
29
+ export declare const getLocaleBuilder: Readonly<{
30
+ readonly targetName: "snap_getLocale";
31
+ readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, SpecificationBuilderOptions, {
32
+ permissionType: PermissionType.RestrictedMethod;
33
+ targetName: typeof methodName;
34
+ methodImplementation: ReturnType<typeof getImplementation>;
35
+ allowedCaveats: Readonly<NonEmptyArray<string>> | null;
36
+ }>;
37
+ readonly methodHooks: MethodHooksObject<GetLocaleMethodHooks>;
38
+ }>;
39
+ /**
40
+ * Builds the method implementation for `snap_getLocale`.
41
+ *
42
+ * @param hooks - The RPC method hooks.
43
+ * @param hooks.getLocale - A function that returns the user selected locale.
44
+ * @returns The user selected locale.
45
+ */
46
+ export declare function getImplementation({ getLocale }: GetLocaleMethodHooks): (_args: RestrictedMethodOptions<RestrictedMethodParameters>) => Promise<string>;
47
+ export {};
@@ -0,0 +1,232 @@
1
+ import type { DialogMethodHooks } from './dialog';
2
+ import type { GetBip32EntropyMethodHooks } from './getBip32Entropy';
3
+ import type { GetBip32PublicKeyMethodHooks } from './getBip32PublicKey';
4
+ import type { GetBip44EntropyMethodHooks } from './getBip44Entropy';
5
+ import type { GetEntropyHooks } from './getEntropy';
6
+ import type { GetLocaleMethodHooks } from './getLocale';
7
+ import type { InvokeSnapMethodHooks } from './invokeSnap';
8
+ import type { ManageAccountsMethodHooks } from './manageAccounts';
9
+ import type { ManageStateMethodHooks } from './manageState';
10
+ import type { NotifyMethodHooks } from './notify';
11
+ export type { DialogParameters } from './dialog';
12
+ export { DialogType } from './dialog';
13
+ export { ManageStateOperation } from './manageState';
14
+ export { WALLET_SNAP_PERMISSION_KEY } from './invokeSnap';
15
+ export type { NotificationArgs } from './notify';
16
+ export { NotificationType } from './notify';
17
+ export declare type RestrictedMethodHooks = DialogMethodHooks & GetBip32EntropyMethodHooks & GetBip32PublicKeyMethodHooks & GetBip44EntropyMethodHooks & GetEntropyHooks & InvokeSnapMethodHooks & ManageStateMethodHooks & NotifyMethodHooks & ManageAccountsMethodHooks & GetLocaleMethodHooks;
18
+ export declare const restrictedMethodPermissionBuilders: {
19
+ readonly snap_dialog: Readonly<{
20
+ readonly targetName: "snap_dialog";
21
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
22
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
23
+ methodHooks: DialogMethodHooks;
24
+ }, {
25
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
26
+ 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>;
89
+ allowedCaveats: readonly [string, ...string[]] | null;
90
+ }>;
91
+ readonly methodHooks: import("../utils").MethodHooksObject<DialogMethodHooks>;
92
+ }>;
93
+ readonly snap_getBip32Entropy: Readonly<{
94
+ readonly targetName: "snap_getBip32Entropy";
95
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
96
+ methodHooks: GetBip32EntropyMethodHooks;
97
+ }, {
98
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
99
+ 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>;
104
+ allowedCaveats: readonly [string, ...string[]] | null;
105
+ validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
106
+ }>;
107
+ readonly methodHooks: import("../utils").MethodHooksObject<GetBip32EntropyMethodHooks>;
108
+ }>;
109
+ readonly snap_getBip32PublicKey: Readonly<{
110
+ readonly targetName: "snap_getBip32PublicKey";
111
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
112
+ methodHooks: GetBip32PublicKeyMethodHooks;
113
+ }, {
114
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
115
+ 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>;
121
+ allowedCaveats: readonly [string, ...string[]] | null;
122
+ validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
123
+ }>;
124
+ readonly methodHooks: import("../utils").MethodHooksObject<GetBip32PublicKeyMethodHooks>;
125
+ }>;
126
+ readonly snap_getBip44Entropy: Readonly<{
127
+ readonly targetName: "snap_getBip44Entropy";
128
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
129
+ methodHooks: GetBip44EntropyMethodHooks;
130
+ }, {
131
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
132
+ targetName: "snap_getBip44Entropy";
133
+ methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("./getBip44Entropy").GetBip44EntropyParams>) => Promise<import("@metamask/key-tree").JsonBIP44CoinTypeNode>;
134
+ allowedCaveats: readonly [string, ...string[]] | null;
135
+ validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
136
+ }>;
137
+ readonly methodHooks: import("../utils").MethodHooksObject<GetBip44EntropyMethodHooks>;
138
+ }>;
139
+ readonly snap_getEntropy: Readonly<{
140
+ readonly targetName: "snap_getEntropy";
141
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
142
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
143
+ methodHooks: GetEntropyHooks;
144
+ }, {
145
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
146
+ targetName: "snap_getEntropy";
147
+ methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<{
148
+ version: 1;
149
+ salt?: string | undefined;
150
+ }>) => Promise<`0x${string}`>;
151
+ allowedCaveats: readonly [string, ...string[]] | null;
152
+ }>;
153
+ readonly methodHooks: import("../utils").MethodHooksObject<GetEntropyHooks>;
154
+ }>;
155
+ readonly wallet_snap: Readonly<{
156
+ readonly targetName: "wallet_snap";
157
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
158
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
159
+ methodHooks: InvokeSnapMethodHooks;
160
+ }, {
161
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
162
+ targetName: "wallet_snap";
163
+ methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<Record<string, import("@metamask/utils").Json>>) => Promise<import("@metamask/utils").Json>;
164
+ allowedCaveats: readonly [string, ...string[]] | null;
165
+ validator: import("@metamask/permission-controller").PermissionValidatorConstraint;
166
+ sideEffect: {
167
+ onPermitted: import("@metamask/permission-controller").SideEffectHandler<import("./invokeSnap").InstallSnaps | import("./invokeSnap").GetPermittedSnaps, never>;
168
+ };
169
+ }>;
170
+ readonly methodHooks: import("../utils").MethodHooksObject<InvokeSnapMethodHooks>;
171
+ }>;
172
+ readonly snap_manageState: Readonly<{
173
+ readonly targetName: "snap_manageState";
174
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
175
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
176
+ methodHooks: ManageStateMethodHooks;
177
+ }, {
178
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
179
+ targetName: "snap_manageState";
180
+ methodImplementation: (options: import("@metamask/permission-controller").RestrictedMethodOptions<import("./manageState").ManageStateArgs>) => Promise<Record<string, import("@metamask/utils").Json> | null>;
181
+ allowedCaveats: readonly [string, ...string[]] | null;
182
+ }>;
183
+ readonly methodHooks: import("../utils").MethodHooksObject<ManageStateMethodHooks>;
184
+ }>;
185
+ readonly snap_notify: Readonly<{
186
+ readonly targetName: "snap_notify";
187
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
188
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
189
+ methodHooks: NotifyMethodHooks;
190
+ }, {
191
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
192
+ targetName: "snap_notify";
193
+ methodImplementation: (args: import("@metamask/permission-controller").RestrictedMethodOptions<import("./notify").NotificationArgs>) => Promise<null>;
194
+ allowedCaveats: readonly [string, ...string[]] | null;
195
+ }>;
196
+ readonly methodHooks: import("../utils").MethodHooksObject<NotifyMethodHooks>;
197
+ }>;
198
+ readonly snap_manageAccounts: Readonly<{
199
+ readonly targetName: "snap_manageAccounts";
200
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
201
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
202
+ methodHooks: ManageAccountsMethodHooks;
203
+ }, {
204
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
205
+ 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>;
212
+ allowedCaveats: readonly [string, ...string[]] | null;
213
+ }>;
214
+ readonly methodHooks: {
215
+ readonly getSnapKeyring: true;
216
+ };
217
+ }>;
218
+ readonly snap_getLocale: Readonly<{
219
+ readonly targetName: "snap_getLocale";
220
+ readonly specificationBuilder: import("@metamask/permission-controller").PermissionSpecificationBuilder<import("@metamask/permission-controller").PermissionType.RestrictedMethod, {
221
+ allowedCaveats?: readonly [string, ...string[]] | null | undefined;
222
+ methodHooks: GetLocaleMethodHooks;
223
+ }, {
224
+ permissionType: import("@metamask/permission-controller").PermissionType.RestrictedMethod;
225
+ targetName: "snap_getLocale";
226
+ methodImplementation: (_args: import("@metamask/permission-controller").RestrictedMethodOptions<import("@metamask/permission-controller").RestrictedMethodParameters>) => Promise<string>;
227
+ allowedCaveats: readonly [string, ...string[]] | null;
228
+ }>;
229
+ readonly methodHooks: import("../utils").MethodHooksObject<GetLocaleMethodHooks>;
230
+ }>;
231
+ };
232
+ export * from './caveats';