@metamask/snaps-sdk 1.3.2 → 2.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/cjs/types/handlers/index.js +2 -0
  3. package/dist/cjs/types/handlers/index.js.map +1 -1
  4. package/dist/cjs/types/handlers/signature.js +6 -0
  5. package/dist/cjs/types/handlers/signature.js.map +1 -0
  6. package/dist/cjs/types/handlers/transaction.js.map +1 -1
  7. package/dist/cjs/types/handlers/user-input.js +51 -0
  8. package/dist/cjs/types/handlers/user-input.js.map +1 -0
  9. package/dist/cjs/types/index.js +1 -0
  10. package/dist/cjs/types/index.js.map +1 -1
  11. package/dist/cjs/types/interface.js +26 -0
  12. package/dist/cjs/types/interface.js.map +1 -0
  13. package/dist/cjs/types/methods/create-interface.js +6 -0
  14. package/dist/cjs/types/methods/create-interface.js.map +1 -0
  15. package/dist/cjs/types/methods/dialog.js.map +1 -1
  16. package/dist/cjs/types/methods/get-client-status.js +10 -0
  17. package/dist/cjs/types/methods/get-client-status.js.map +1 -0
  18. package/dist/cjs/types/methods/get-interface-state.js +6 -0
  19. package/dist/cjs/types/methods/get-interface-state.js.map +1 -0
  20. package/dist/cjs/types/methods/index.js +4 -0
  21. package/dist/cjs/types/methods/index.js.map +1 -1
  22. package/dist/cjs/types/methods/update-interface.js +6 -0
  23. package/dist/cjs/types/methods/update-interface.js.map +1 -0
  24. package/dist/cjs/ui/components/button.js +59 -0
  25. package/dist/cjs/ui/components/button.js.map +1 -0
  26. package/dist/cjs/ui/components/form.js +41 -0
  27. package/dist/cjs/ui/components/form.js.map +1 -0
  28. package/dist/cjs/ui/components/index.js +3 -0
  29. package/dist/cjs/ui/components/index.js.map +1 -1
  30. package/dist/cjs/ui/components/input.js +52 -0
  31. package/dist/cjs/ui/components/input.js.map +1 -0
  32. package/dist/cjs/ui/components/panel.js +7 -1
  33. package/dist/cjs/ui/components/panel.js.map +1 -1
  34. package/dist/cjs/ui/nodes.js +3 -0
  35. package/dist/cjs/ui/nodes.js.map +1 -1
  36. package/dist/esm/types/handlers/home-page.js.map +1 -1
  37. package/dist/esm/types/handlers/index.js +2 -0
  38. package/dist/esm/types/handlers/index.js.map +1 -1
  39. package/dist/esm/types/handlers/name-lookup.js.map +1 -1
  40. package/dist/esm/types/handlers/signature.js +3 -0
  41. package/dist/esm/types/handlers/signature.js.map +1 -0
  42. package/dist/esm/types/handlers/transaction.js.map +1 -1
  43. package/dist/esm/types/handlers/user-input.js +24 -0
  44. package/dist/esm/types/handlers/user-input.js.map +1 -0
  45. package/dist/esm/types/index.js +1 -0
  46. package/dist/esm/types/index.js.map +1 -1
  47. package/dist/esm/types/interface.js +12 -0
  48. package/dist/esm/types/interface.js.map +1 -0
  49. package/dist/esm/types/methods/create-interface.js +3 -0
  50. package/dist/esm/types/methods/create-interface.js.map +1 -0
  51. package/dist/esm/types/methods/dialog.js.map +1 -1
  52. package/dist/esm/types/methods/get-client-status.js +7 -0
  53. package/dist/esm/types/methods/get-client-status.js.map +1 -0
  54. package/dist/esm/types/methods/get-interface-state.js +3 -0
  55. package/dist/esm/types/methods/get-interface-state.js.map +1 -0
  56. package/dist/esm/types/methods/index.js +4 -0
  57. package/dist/esm/types/methods/index.js.map +1 -1
  58. package/dist/esm/types/methods/methods.js.map +1 -1
  59. package/dist/esm/types/methods/update-interface.js +3 -0
  60. package/dist/esm/types/methods/update-interface.js.map +1 -0
  61. package/dist/esm/types/permissions.js.map +1 -1
  62. package/dist/esm/ui/components/button.js +50 -0
  63. package/dist/esm/ui/components/button.js.map +1 -0
  64. package/dist/esm/ui/components/form.js +39 -0
  65. package/dist/esm/ui/components/form.js.map +1 -0
  66. package/dist/esm/ui/components/index.js +3 -0
  67. package/dist/esm/ui/components/index.js.map +1 -1
  68. package/dist/esm/ui/components/input.js +47 -0
  69. package/dist/esm/ui/components/input.js.map +1 -0
  70. package/dist/esm/ui/components/panel.js +7 -1
  71. package/dist/esm/ui/components/panel.js.map +1 -1
  72. package/dist/esm/ui/nodes.js +3 -0
  73. package/dist/esm/ui/nodes.js.map +1 -1
  74. package/dist/types/types/handlers/home-page.d.ts +3 -0
  75. package/dist/types/types/handlers/index.d.ts +2 -0
  76. package/dist/types/types/handlers/name-lookup.d.ts +31 -10
  77. package/dist/types/types/handlers/signature.d.ts +111 -0
  78. package/dist/types/types/handlers/transaction.d.ts +4 -0
  79. package/dist/types/types/handlers/user-input.d.ts +64 -0
  80. package/dist/types/types/index.d.ts +1 -0
  81. package/dist/types/types/interface.d.ts +10 -0
  82. package/dist/types/types/methods/create-interface.d.ts +13 -0
  83. package/dist/types/types/methods/dialog.d.ts +14 -0
  84. package/dist/types/types/methods/get-client-status.d.ts +14 -0
  85. package/dist/types/types/methods/get-interface-state.d.ts +13 -0
  86. package/dist/types/types/methods/index.d.ts +4 -0
  87. package/dist/types/types/methods/methods.d.ts +8 -0
  88. package/dist/types/types/methods/update-interface.d.ts +15 -0
  89. package/dist/types/types/permissions.d.ts +41 -19
  90. package/dist/types/ui/components/button.d.ts +62 -0
  91. package/dist/types/ui/components/form.d.ts +144 -0
  92. package/dist/types/ui/components/index.d.ts +3 -0
  93. package/dist/types/ui/components/input.d.ts +69 -0
  94. package/dist/types/ui/components/panel.d.ts +150 -0
  95. package/dist/types/ui/nodes.d.ts +4 -1
  96. package/package.json +3 -3
@@ -0,0 +1,111 @@
1
+ import type { EnumToUnion } from '../../internals';
2
+ import type { Component } from '../../ui';
3
+ import type { SeverityLevel } from './transaction';
4
+ /**
5
+ * An eth_sign signature object.
6
+ *
7
+ * @property from - The address the signature is being sent from.
8
+ * @property data - The data (hex string) that is being signed.
9
+ * @property signatureMethod - The signature method, which in this case is eth_sign
10
+ */
11
+ export declare type EthSignature = {
12
+ from: string;
13
+ data: string;
14
+ signatureMethod: 'eth_sign';
15
+ };
16
+ /**
17
+ * A personal_sign signature object.
18
+ *
19
+ * @property from - The address the signature is being sent from.
20
+ * @property data - The data (hex string) that is being signed.
21
+ * @property signatureMethod - The signature method, which in this case is personal_sign
22
+ */
23
+ export declare type PersonalSignature = {
24
+ from: string;
25
+ data: string;
26
+ signatureMethod: 'personal_sign';
27
+ };
28
+ /**
29
+ * An eth_signTypedData signature object.
30
+ *
31
+ * @property from - The address the signature is being sent from.
32
+ * @property data - The data that is being signed.
33
+ * @property signatureMethod - The signature method, which in this case is eth_signTypedData
34
+ */
35
+ export declare type SignTypedDataSignature = {
36
+ from: string;
37
+ data: Record<string, any>[];
38
+ signatureMethod: 'eth_signTypedData';
39
+ };
40
+ /**
41
+ * An eth_signTypedData_v3 signature object.
42
+ *
43
+ * @property from - The address the signature is being sent from.
44
+ * @property data - The data that is being signed.
45
+ * @property signatureMethod - The signature method, which in this case is eth_signTypedData_v3
46
+ */
47
+ export declare type SignTypedDataV3Signature = {
48
+ from: string;
49
+ data: Record<string, any>;
50
+ signatureMethod: 'eth_signTypedData_v3';
51
+ };
52
+ /**
53
+ * An eth_signTypedData_v4 signature object.
54
+ *
55
+ * @property from - The address the signature is being sent from.
56
+ * @property data - The data that is being signed.
57
+ * @property signatureMethod - The signature method, which in this case is eth_signTypedData_v4
58
+ */
59
+ export declare type SignTypedDataV4Signature = {
60
+ from: string;
61
+ data: Record<string, any>;
62
+ signatureMethod: 'eth_signTypedData_v4';
63
+ };
64
+ /**
65
+ * A signature object. This can be one of the below signature methods.
66
+ *
67
+ * @see EthSignature
68
+ * @see PersonalSignature
69
+ * @see SignTypedDataSignature
70
+ * @see SignTypedDataV3Signature
71
+ * @see SignTypedDataV4Signature
72
+ */
73
+ export declare type Signature = EthSignature | PersonalSignature | SignTypedDataSignature | SignTypedDataV3Signature | SignTypedDataV4Signature;
74
+ /**
75
+ * The `onSignature` handler. This is called whenever a signature is
76
+ * submitted to the snap. It can return insights about the signature, which
77
+ * will be displayed to the user.
78
+ *
79
+ * Note that using this handler requires the `endowment:signature-insight`
80
+ * permission.
81
+ *
82
+ * @param args - The request arguments.
83
+ * @param args.signature - The signature object that contains the from address,
84
+ * data and signature method.
85
+ * @param args.signatureOrigin - The origin of the signature. This is the
86
+ * URL of the website that submitted the signature. This is only available if
87
+ * the Snap has enabled the `allowSignatureOrigin` option in the
88
+ * `endowment:signature-insight` permission.
89
+ * @returns An object containing insights about the signature. See
90
+ * {@link OnSignatureResponse}. Can also return `null` if no insights are
91
+ * available.
92
+ */
93
+ export declare type OnSignatureHandler = (args: {
94
+ signature: Signature;
95
+ signatureOrigin?: string;
96
+ }) => Promise<OnSignatureResponse | null>;
97
+ /**
98
+ * The response from a Snap's `onSignature` handler.
99
+ *
100
+ * @property component - A custom UI component, that will be shown in MetaMask.
101
+ * @property id - A Snap interface ID.
102
+ * @property severity - The severity level of the content. Currently only one
103
+ * level is supported: `critical`.
104
+ */
105
+ export declare type OnSignatureResponse = {
106
+ content: Component;
107
+ severity?: EnumToUnion<SeverityLevel>;
108
+ } | {
109
+ id: string;
110
+ severity?: EnumToUnion<SeverityLevel>;
111
+ };
@@ -101,10 +101,14 @@ export declare type OnTransactionHandler = (args: {
101
101
  * The response from a Snap's `onTransaction` handler.
102
102
  *
103
103
  * @property component - A custom UI component, that will be shown in MetaMask.
104
+ * @property id - A Snap interface ID.
104
105
  * @property severity - The severity level of the content. Currently only one
105
106
  * level is supported: `critical`.
106
107
  */
107
108
  export declare type OnTransactionResponse = {
108
109
  content: Component;
109
110
  severity?: EnumToUnion<SeverityLevel>;
111
+ } | {
112
+ id: string;
113
+ severity?: EnumToUnion<SeverityLevel>;
110
114
  };
@@ -0,0 +1,64 @@
1
+ import type { Infer } from 'superstruct';
2
+ /**
3
+ * The type of user input event fired.
4
+ * Currently only two events are supported:
5
+ *
6
+ * - `ButtonClickEvent` - A button has been clicked in the UI.
7
+ * - `FormSubmitEvent` - A Form has been submitted in the UI.
8
+ */
9
+ export declare enum UserInputEventType {
10
+ ButtonClickEvent = "ButtonClickEvent",
11
+ FormSubmitEvent = "FormSubmitEvent"
12
+ }
13
+ export declare const GenericEventStruct: import("superstruct").Struct<{
14
+ type: string;
15
+ name?: string | undefined;
16
+ }, {
17
+ type: import("superstruct").Struct<string, null>;
18
+ name: import("superstruct").Struct<string | undefined, null>;
19
+ }>;
20
+ export declare const ButtonClickEventStruct: import("superstruct").Struct<{
21
+ type: UserInputEventType.ButtonClickEvent;
22
+ name?: string | undefined;
23
+ }, {
24
+ type: import("superstruct").Struct<UserInputEventType.ButtonClickEvent, UserInputEventType.ButtonClickEvent>;
25
+ name: import("superstruct").Struct<string | undefined, null>;
26
+ }>;
27
+ export declare const FormSubmitEventStruct: import("superstruct").Struct<{
28
+ value: Record<string, string>;
29
+ type: UserInputEventType.FormSubmitEvent;
30
+ name: string;
31
+ }, {
32
+ type: import("superstruct").Struct<UserInputEventType.FormSubmitEvent, UserInputEventType.FormSubmitEvent>;
33
+ value: import("superstruct").Struct<Record<string, string>, null>;
34
+ name: import("superstruct").Struct<string, null>;
35
+ }>;
36
+ export declare const UserInputEventStruct: import("superstruct").Struct<{
37
+ type: UserInputEventType.ButtonClickEvent;
38
+ name?: string | undefined;
39
+ } | {
40
+ value: Record<string, string>;
41
+ type: UserInputEventType.FormSubmitEvent;
42
+ name: string;
43
+ }, null>;
44
+ /**
45
+ * A user input event fired in the UI. This is passed to the params of the `onUserInput` handler.
46
+ *
47
+ * @property type - The type of event fired. See {@link UserInputEventType} for the different types.
48
+ * @property name - The component name that fired the event. It is optional for an {@link UserInputEventType.ButtonClickEvent}.
49
+ * @property value - The value associated with the event. Only available when an {@link UserInputEventType.FormSubmitEvent} is fired.
50
+ * It contains the form values submitted.
51
+ */
52
+ declare type UserInputEvent = Infer<typeof UserInputEventStruct>;
53
+ /**
54
+ * The `onUserInput` handler. This is called when an user input event is fired in the UI.
55
+ *
56
+ * @param args - The user input event.
57
+ * @param args.id - The user interface id.
58
+ * @param args.event - The {@link UserInputEvent} object, containing the data about the fired event.
59
+ */
60
+ export declare type OnUserInputHandler = (args: {
61
+ id: string;
62
+ event: UserInputEvent;
63
+ }) => Promise<void>;
64
+ export {};
@@ -5,3 +5,4 @@ export * from './methods';
5
5
  export * from './permissions';
6
6
  export * from './provider';
7
7
  export * from './snap';
8
+ export * from './interface';
@@ -0,0 +1,10 @@
1
+ import type { Infer } from 'superstruct';
2
+ /**
3
+ * To avoid typing problems with the interface state when manipulating it we have to differentiate the state of
4
+ * a form (that will be contained inside the root state) and the root state since a key in the root stat can contain
5
+ * either the value of an input or a sub-state of a form.
6
+ */
7
+ export declare const FormStateStruct: import("superstruct").Struct<Record<string, string | null>, null>;
8
+ export declare const InterfaceStateStruct: import("superstruct").Struct<Record<string, string | Record<string, string | null> | null>, null>;
9
+ export declare type FormState = Infer<typeof FormStateStruct>;
10
+ export declare type InterfaceState = Infer<typeof InterfaceStateStruct>;
@@ -0,0 +1,13 @@
1
+ import type { Component } from '../../ui';
2
+ /**
3
+ * The request parameters for the `snap_createInterface` method.
4
+ *
5
+ * @property ui - The components to display in the interface.
6
+ */
7
+ export declare type CreateInterfaceParams = {
8
+ ui: Component;
9
+ };
10
+ /**
11
+ * The result returned by the `snap_createInterface` method, which is the id of the created interface.
12
+ */
13
+ export declare type CreateInterfaceResult = string;
@@ -18,26 +18,35 @@ export declare enum DialogType {
18
18
  *
19
19
  * @property type - The type of dialog. Must be `alert`.
20
20
  * @property content - The content to display in the dialog.
21
+ * @property id - The Snap interface ID.
21
22
  */
22
23
  export declare type AlertDialog = {
23
24
  type: EnumToUnion<DialogType.Alert>;
24
25
  content: Component;
26
+ } | {
27
+ type: EnumToUnion<DialogType.Alert>;
28
+ id: string;
25
29
  };
26
30
  /**
27
31
  * A confirmation dialog.
28
32
  *
29
33
  * @property type - The type of dialog. Must be `confirmation`.
30
34
  * @property content - The content to display in the dialog.
35
+ * @property id - The Snap interface ID.
31
36
  */
32
37
  export declare type ConfirmationDialog = {
33
38
  type: EnumToUnion<DialogType.Confirmation>;
34
39
  content: Component;
40
+ } | {
41
+ type: EnumToUnion<DialogType.Confirmation>;
42
+ id: string;
35
43
  };
36
44
  /**
37
45
  * A prompt dialog.
38
46
  *
39
47
  * @property type - The type of dialog. Must be `prompt`.
40
48
  * @property content - The content to display in the dialog.
49
+ * @property id - The Snap interface ID.
41
50
  * @property placeholder - An optional placeholder text to display in the text
42
51
  * input.
43
52
  */
@@ -45,12 +54,17 @@ export declare type PromptDialog = {
45
54
  type: EnumToUnion<DialogType.Prompt>;
46
55
  content: Component;
47
56
  placeholder?: string;
57
+ } | {
58
+ type: EnumToUnion<DialogType.Prompt>;
59
+ id: string;
60
+ placeholder?: string;
48
61
  };
49
62
  /**
50
63
  * The request parameters for the `snap_dialog` method.
51
64
  *
52
65
  * @property type - The type of dialog to display.
53
66
  * @property content - The content to display in the dialog.
67
+ * @property id - The Snap interface ID.
54
68
  * @property placeholder - The placeholder text to display in the dialog. Only
55
69
  * applicable for the `prompt` dialog.
56
70
  */
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The request parameters for the `snap_getClientStatus` method.
3
+ *
4
+ * This method does not accept any parameters.
5
+ */
6
+ export declare type GetClientStatusParams = never;
7
+ /**
8
+ * The result returned by the `snap_getClientStatus` method.
9
+ *
10
+ * It returns an object containing useful information about the client.
11
+ */
12
+ export declare type GetClientStatusResult = {
13
+ locked: boolean;
14
+ };
@@ -0,0 +1,13 @@
1
+ import type { InterfaceState } from '../interface';
2
+ /**
3
+ * The request parameters for the `snap_getInterfaceState` method.
4
+ *
5
+ * @property id - The interface id.
6
+ */
7
+ export declare type GetInterfaceStateParams = {
8
+ id: string;
9
+ };
10
+ /**
11
+ * The result returned by the `snap_getInterfaceState` method, which is the state of the interface.
12
+ */
13
+ export declare type GetInterfaceStateResult = InterfaceState;
@@ -1,9 +1,12 @@
1
+ export * from './create-interface';
1
2
  export * from './dialog';
2
3
  export * from './get-bip32-entropy';
3
4
  export * from './get-bip32-public-key';
4
5
  export * from './get-bip44-entropy';
6
+ export * from './get-client-status';
5
7
  export * from './get-entropy';
6
8
  export * from './get-file';
9
+ export * from './get-interface-state';
7
10
  export * from './get-locale';
8
11
  export * from './get-snaps';
9
12
  export * from './invoke-keyring';
@@ -13,3 +16,4 @@ export * from './manage-state';
13
16
  export * from './methods';
14
17
  export * from './notify';
15
18
  export * from './request-snaps';
19
+ export * from './update-interface';
@@ -1,10 +1,13 @@
1
1
  import type { Method } from '../../internals';
2
+ import type { CreateInterfaceParams, CreateInterfaceResult } from './create-interface';
2
3
  import type { DialogParams, DialogResult } from './dialog';
3
4
  import type { GetBip32EntropyParams, GetBip32EntropyResult } from './get-bip32-entropy';
4
5
  import type { GetBip32PublicKeyParams, GetBip32PublicKeyResult } from './get-bip32-public-key';
5
6
  import type { GetBip44EntropyParams, GetBip44EntropyResult } from './get-bip44-entropy';
7
+ import type { GetClientStatusParams, GetClientStatusResult } from './get-client-status';
6
8
  import type { GetEntropyParams, GetEntropyResult } from './get-entropy';
7
9
  import type { GetFileParams, GetFileResult } from './get-file';
10
+ import type { GetInterfaceStateParams, GetInterfaceStateResult } from './get-interface-state';
8
11
  import type { GetLocaleParams, GetLocaleResult } from './get-locale';
9
12
  import type { GetSnapsParams, GetSnapsResult } from './get-snaps';
10
13
  import type { InvokeKeyringParams, InvokeKeyringResult } from './invoke-keyring';
@@ -13,6 +16,7 @@ import type { ManageAccountsParams, ManageAccountsResult } from './manage-accoun
13
16
  import type { ManageStateParams, ManageStateResult } from './manage-state';
14
17
  import type { NotifyParams, NotifyResult } from './notify';
15
18
  import type { RequestSnapsParams, RequestSnapsResult } from './request-snaps';
19
+ import type { UpdateInterfaceParams, UpdateInterfaceResult } from './update-interface';
16
20
  /**
17
21
  * The methods that are available to the Snap. Each method is a tuple of the
18
22
  * request parameters and the result returned by the method.
@@ -22,12 +26,16 @@ export declare type SnapMethods = {
22
26
  snap_getBip32Entropy: [GetBip32EntropyParams, GetBip32EntropyResult];
23
27
  snap_getBip32PublicKey: [GetBip32PublicKeyParams, GetBip32PublicKeyResult];
24
28
  snap_getBip44Entropy: [GetBip44EntropyParams, GetBip44EntropyResult];
29
+ snap_getClientStatus: [GetClientStatusParams, GetClientStatusResult];
25
30
  snap_getEntropy: [GetEntropyParams, GetEntropyResult];
26
31
  snap_getFile: [GetFileParams, GetFileResult];
27
32
  snap_getLocale: [GetLocaleParams, GetLocaleResult];
28
33
  snap_manageAccounts: [ManageAccountsParams, ManageAccountsResult];
29
34
  snap_manageState: [ManageStateParams, ManageStateResult];
30
35
  snap_notify: [NotifyParams, NotifyResult];
36
+ snap_createInterface: [CreateInterfaceParams, CreateInterfaceResult];
37
+ snap_updateInterface: [UpdateInterfaceParams, UpdateInterfaceResult];
38
+ snap_getInterfaceState: [GetInterfaceStateParams, GetInterfaceStateResult];
31
39
  wallet_getSnaps: [GetSnapsParams, GetSnapsResult];
32
40
  wallet_invokeKeyring: [InvokeKeyringParams, InvokeKeyringResult];
33
41
  wallet_invokeSnap: [InvokeSnapParams, InvokeSnapResult];
@@ -0,0 +1,15 @@
1
+ import type { Component } from '../../ui';
2
+ /**
3
+ * The request parameters for the `snap_createInterface` method.
4
+ *
5
+ * @property id - The interface id.
6
+ * @property ui - The components to display in the interface.
7
+ */
8
+ export declare type UpdateInterfaceParams = {
9
+ id: string;
10
+ ui: Component;
11
+ };
12
+ /**
13
+ * The result returned by the `snap_updateInterface` method.
14
+ */
15
+ export declare type UpdateInterfaceResult = null;
@@ -15,32 +15,54 @@ export declare type Bip44Entropy = {
15
15
  export declare type RequestedSnap = {
16
16
  version?: string;
17
17
  };
18
- export declare type InitialPermissions = {
19
- 'endowment:cronjob'?: {
18
+ export declare type InitialPermissions = Partial<{
19
+ 'endowment:cronjob': {
20
20
  jobs: Cronjob[];
21
+ maxRequestTime?: number;
21
22
  };
22
- 'endowment:keyring'?: {
23
+ 'endowment:ethereum-provider': EmptyObject;
24
+ 'endowment:keyring': {
23
25
  allowedOrigins?: string[];
26
+ maxRequestTime?: number;
24
27
  };
25
- 'endowment:name-lookup'?: ChainId[];
26
- 'endowment:network-access'?: EmptyObject;
27
- 'endowment:rpc'?: {
28
+ 'endowment:lifecycle-hooks'?: {
29
+ maxRequestTime?: number;
30
+ };
31
+ 'endowment:name-lookup': {
32
+ chains?: ChainId[];
33
+ matchers?: {
34
+ tlds?: string[];
35
+ schemes?: string[];
36
+ };
37
+ maxRequestTime?: number;
38
+ };
39
+ 'endowment:network-access': EmptyObject;
40
+ 'endowment:page-home'?: {
41
+ maxRequestTime?: number;
42
+ };
43
+ 'endowment:rpc': {
28
44
  dapps?: boolean;
29
45
  snaps?: boolean;
30
46
  allowedOrigins?: string[];
47
+ maxRequestTime?: number;
31
48
  };
32
- 'endowment:transaction-insight'?: {
49
+ 'endowment:signature-insight': {
50
+ allowSignatureOrigin?: boolean;
51
+ maxRequestTime?: number;
52
+ };
53
+ 'endowment:transaction-insight': {
33
54
  allowTransactionOrigin?: boolean;
55
+ maxRequestTime?: number;
34
56
  };
35
- 'endowment:webassembly'?: EmptyObject;
36
- snap_confirm?: EmptyObject;
37
- snap_dialog?: EmptyObject;
38
- snap_getBip32Entropy?: Bip32Entropy[];
39
- snap_getBip32PublicKey?: Bip32Entropy[];
40
- snap_getBip44Entropy?: Bip44Entropy[];
41
- snap_getEntropy?: EmptyObject;
42
- snap_manageAccounts?: EmptyObject;
43
- snap_manageState?: EmptyObject;
44
- snap_notify?: EmptyObject;
45
- wallet_snap?: Record<string, RequestedSnap>;
46
- };
57
+ 'endowment:webassembly': EmptyObject;
58
+ snap_dialog: EmptyObject;
59
+ snap_getBip32Entropy: Bip32Entropy[];
60
+ snap_getBip32PublicKey: Bip32Entropy[];
61
+ snap_getBip44Entropy: Bip44Entropy[];
62
+ snap_getEntropy: EmptyObject;
63
+ snap_getLocale: EmptyObject;
64
+ snap_manageAccounts: EmptyObject;
65
+ snap_manageState: EmptyObject;
66
+ snap_notify: EmptyObject;
67
+ wallet_snap: Record<string, RequestedSnap>;
68
+ }>;
@@ -0,0 +1,62 @@
1
+ import type { Infer } from 'superstruct';
2
+ import { NodeType } from '../nodes';
3
+ export declare enum ButtonVariant {
4
+ Primary = "primary",
5
+ Secondary = "secondary"
6
+ }
7
+ export declare enum ButtonType {
8
+ Button = "button",
9
+ Submit = "submit"
10
+ }
11
+ export declare const ButtonStruct: import("superstruct").Struct<{
12
+ value: string;
13
+ type: NodeType.Button;
14
+ name?: string | undefined;
15
+ variant?: "primary" | "secondary" | undefined;
16
+ buttonType?: "button" | "submit" | undefined;
17
+ }, {
18
+ type: import("superstruct").Struct<NodeType.Button, NodeType.Button>;
19
+ value: import("superstruct").Struct<string, null>;
20
+ variant: import("superstruct").Struct<"primary" | "secondary" | undefined, null>;
21
+ buttonType: import("superstruct").Struct<"button" | "submit" | undefined, null>;
22
+ name: import("superstruct").Struct<string | undefined, null>;
23
+ }>;
24
+ /**
25
+ * A button node, that renders either a primary or a secondary button.
26
+ *
27
+ * @property type - The type of the node, must be the string 'button'.
28
+ * @property variant - The style variant of the node, must be either 'primary' or 'secondary'.
29
+ * @property value - The text content of the node as plain text.
30
+ * @property buttonType - The type of the button, must be either 'button' or 'submit'.
31
+ * @property name - An optional name to identify the button.
32
+ */
33
+ export declare type Button = Infer<typeof ButtonStruct>;
34
+ /**
35
+ * Create a {@link Button} node.
36
+ *
37
+ * @param args - The node arguments. This can be either a string, or an object
38
+ * with a `value` property. A set of optional properties can be passed.
39
+ * @param args.variant - The optional variant of the button.
40
+ * @param args.value - The text content of the node.
41
+ * @param args.name - The optional name of the button.
42
+ * @returns The text node as object.
43
+ * @example
44
+ * ```typescript
45
+ * const node = button({ variant: 'primary', text: 'Hello, world!', name: 'myButton' });
46
+ * const node = button('Hello, world!', 'button', 'myButton', 'primary');
47
+ * const node = button('Hello, world!');
48
+ * ```
49
+ */
50
+ export declare const button: (...args: [Omit<{
51
+ value: string;
52
+ type: NodeType.Button;
53
+ name?: string | undefined;
54
+ variant?: "primary" | "secondary" | undefined;
55
+ buttonType?: "button" | "submit" | undefined;
56
+ }, "type">] | (string | undefined)[]) => {
57
+ value: string;
58
+ type: NodeType.Button;
59
+ name?: string | undefined;
60
+ variant?: "primary" | "secondary" | undefined;
61
+ buttonType?: "button" | "submit" | undefined;
62
+ };
@@ -0,0 +1,144 @@
1
+ import type { Infer } from 'superstruct';
2
+ import { NodeType } from '../nodes';
3
+ export declare const FormComponentStruct: import("superstruct").Struct<{
4
+ type: NodeType.Input;
5
+ name: string;
6
+ value?: string | undefined;
7
+ label?: string | undefined;
8
+ inputType?: "number" | "text" | "password" | undefined;
9
+ placeholder?: string | undefined;
10
+ } | {
11
+ value: string;
12
+ type: NodeType.Button;
13
+ name?: string | undefined;
14
+ variant?: "primary" | "secondary" | undefined;
15
+ buttonType?: "button" | "submit" | undefined;
16
+ }, null>;
17
+ /**
18
+ * The subset of nodes allowed as children in the {@link Form} node.
19
+ */
20
+ export declare type FormComponent = Infer<typeof FormComponentStruct>;
21
+ export declare const FormStruct: import("superstruct").Struct<{
22
+ type: NodeType.Form;
23
+ name: string;
24
+ children: ({
25
+ type: NodeType.Input;
26
+ name: string;
27
+ value?: string | undefined;
28
+ label?: string | undefined;
29
+ inputType?: "number" | "text" | "password" | undefined;
30
+ placeholder?: string | undefined;
31
+ } | {
32
+ value: string;
33
+ type: NodeType.Button;
34
+ name?: string | undefined;
35
+ variant?: "primary" | "secondary" | undefined;
36
+ buttonType?: "button" | "submit" | undefined;
37
+ })[];
38
+ }, {
39
+ type: import("superstruct").Struct<NodeType.Form, NodeType.Form>;
40
+ children: import("superstruct").Struct<({
41
+ type: NodeType.Input;
42
+ name: string;
43
+ value?: string | undefined;
44
+ label?: string | undefined;
45
+ inputType?: "number" | "text" | "password" | undefined;
46
+ placeholder?: string | undefined;
47
+ } | {
48
+ value: string;
49
+ type: NodeType.Button;
50
+ name?: string | undefined;
51
+ variant?: "primary" | "secondary" | undefined;
52
+ buttonType?: "button" | "submit" | undefined;
53
+ })[], import("superstruct").Struct<{
54
+ type: NodeType.Input;
55
+ name: string;
56
+ value?: string | undefined;
57
+ label?: string | undefined;
58
+ inputType?: "number" | "text" | "password" | undefined;
59
+ placeholder?: string | undefined;
60
+ } | {
61
+ value: string;
62
+ type: NodeType.Button;
63
+ name?: string | undefined;
64
+ variant?: "primary" | "secondary" | undefined;
65
+ buttonType?: "button" | "submit" | undefined;
66
+ }, null>>;
67
+ name: import("superstruct").Struct<string, null>;
68
+ }>;
69
+ /**
70
+ * A form node that takes children {@link FormComponent} nodes and renders a form.
71
+ *
72
+ * @property type - The type of the node. Must be the string `form`.
73
+ * @property children - The children of the node. Only {@link FormComponent} nodes are allowed.
74
+ * @property name - The form name used to identify it.
75
+ */
76
+ export declare type Form = Infer<typeof FormStruct>;
77
+ /**
78
+ * Create a {@link Form} node.
79
+ *
80
+ * @param args - The node arguments. This can be either an array of children and a string, or
81
+ * an object with a `name` and `children` property.
82
+ * @param args.name - The form name used to identify it.
83
+ * @param args.children - The child nodes of the form. This can be any valid
84
+ * {@link FormComponent}.
85
+ * @returns The form node as object.
86
+ * @example
87
+ * const node = form({
88
+ * name: 'myForm',
89
+ * children: [
90
+ * input({ name: 'myInput' }),
91
+ * button({ value: 'Hello, world!' }),
92
+ * ],
93
+ * });
94
+ *
95
+ * const node = form('myForm', [input('myInput'), button('Hello, world!')]);
96
+ */
97
+ export declare const form: (...args: [Omit<{
98
+ type: NodeType.Form;
99
+ name: string;
100
+ children: ({
101
+ type: NodeType.Input;
102
+ name: string;
103
+ value?: string | undefined;
104
+ label?: string | undefined;
105
+ inputType?: "number" | "text" | "password" | undefined;
106
+ placeholder?: string | undefined;
107
+ } | {
108
+ value: string;
109
+ type: NodeType.Button;
110
+ name?: string | undefined;
111
+ variant?: "primary" | "secondary" | undefined;
112
+ buttonType?: "button" | "submit" | undefined;
113
+ })[];
114
+ }, "type">] | (string | ({
115
+ type: NodeType.Input;
116
+ name: string;
117
+ value?: string | undefined;
118
+ label?: string | undefined;
119
+ inputType?: "number" | "text" | "password" | undefined;
120
+ placeholder?: string | undefined;
121
+ } | {
122
+ value: string;
123
+ type: NodeType.Button;
124
+ name?: string | undefined;
125
+ variant?: "primary" | "secondary" | undefined;
126
+ buttonType?: "button" | "submit" | undefined;
127
+ })[])[]) => {
128
+ type: NodeType.Form;
129
+ name: string;
130
+ children: ({
131
+ type: NodeType.Input;
132
+ name: string;
133
+ value?: string | undefined;
134
+ label?: string | undefined;
135
+ inputType?: "number" | "text" | "password" | undefined;
136
+ placeholder?: string | undefined;
137
+ } | {
138
+ value: string;
139
+ type: NodeType.Button;
140
+ name?: string | undefined;
141
+ variant?: "primary" | "secondary" | undefined;
142
+ buttonType?: "button" | "submit" | undefined;
143
+ })[];
144
+ };
@@ -9,3 +9,6 @@ export { ComponentStruct, panel, PanelStruct } from './panel';
9
9
  export * from './spinner';
10
10
  export * from './text';
11
11
  export * from './row';
12
+ export * from './button';
13
+ export * from './input';
14
+ export * from './form';