@metamask/keyring-api 6.0.0 → 6.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.
@@ -2,110 +2,140 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
2
2
  method: "notify:accountCreated";
3
3
  params: {
4
4
  account: {
5
- type: "eip155:eoa" | "eip155:erc4337";
5
+ type: "bip122:p2wpkh";
6
6
  id: string;
7
7
  address: string;
8
8
  options: Record<string, import("@metamask/utils").Json>;
9
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
9
+ methods: "btc_sendmany"[];
10
+ } | {
11
+ type: "eip155:eoa";
12
+ id: string;
13
+ address: string;
14
+ options: Record<string, import("@metamask/utils").Json>;
15
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
16
+ } | {
17
+ type: "eip155:erc4337";
18
+ id: string;
19
+ address: string;
20
+ options: Record<string, import("@metamask/utils").Json>;
21
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
10
22
  };
11
23
  };
12
24
  }, {
13
25
  method: import("superstruct").Struct<"notify:accountCreated", "notify:accountCreated">;
14
26
  params: import("superstruct").Struct<{
15
27
  account: {
16
- type: "eip155:eoa" | "eip155:erc4337";
28
+ type: "bip122:p2wpkh";
17
29
  id: string;
18
30
  address: string;
19
31
  options: Record<string, import("@metamask/utils").Json>;
20
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
32
+ methods: "btc_sendmany"[];
33
+ } | {
34
+ type: "eip155:eoa";
35
+ id: string;
36
+ address: string;
37
+ options: Record<string, import("@metamask/utils").Json>;
38
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
39
+ } | {
40
+ type: "eip155:erc4337";
41
+ id: string;
42
+ address: string;
43
+ options: Record<string, import("@metamask/utils").Json>;
44
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
21
45
  };
22
46
  }, {
23
47
  /**
24
48
  * New account object.
25
49
  */
26
50
  account: import("superstruct").Struct<{
27
- type: "eip155:eoa" | "eip155:erc4337";
28
- id: string;
29
- address: string;
30
- options: Record<string, import("@metamask/utils").Json>;
31
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
32
- }, {
33
- id: import("superstruct").Struct<string, null>; /**
34
- * Request result.
35
- */
36
- address: import("superstruct").Struct<string, null>;
37
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
38
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
39
- personal_sign: "personal_sign";
40
- eth_sign: "eth_sign";
41
- eth_signTransaction: "eth_signTransaction";
42
- eth_signTypedData_v1: "eth_signTypedData_v1";
43
- eth_signTypedData_v3: "eth_signTypedData_v3";
44
- eth_signTypedData_v4: "eth_signTypedData_v4";
45
- eth_prepareUserOperation: "eth_prepareUserOperation";
46
- eth_patchUserOperation: "eth_patchUserOperation";
47
- eth_signUserOperation: "eth_signUserOperation";
48
- }>>;
49
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
50
- "eip155:eoa": "eip155:eoa";
51
- "eip155:erc4337": "eip155:erc4337";
52
- }>;
53
- }>;
51
+ type: "bip122:p2wpkh";
52
+ id: string;
53
+ address: string;
54
+ options: Record<string, import("@metamask/utils").Json>;
55
+ methods: "btc_sendmany"[];
56
+ } | {
57
+ type: "eip155:eoa";
58
+ id: string;
59
+ address: string;
60
+ options: Record<string, import("@metamask/utils").Json>;
61
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
62
+ } | {
63
+ type: "eip155:erc4337";
64
+ id: string;
65
+ address: string;
66
+ options: Record<string, import("@metamask/utils").Json>;
67
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
68
+ }, null>;
54
69
  }>;
55
70
  }>;
56
71
  export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
57
72
  method: "notify:accountUpdated";
58
73
  params: {
59
74
  account: {
60
- type: "eip155:eoa" | "eip155:erc4337";
75
+ type: "bip122:p2wpkh";
61
76
  id: string;
62
77
  address: string;
63
78
  options: Record<string, import("@metamask/utils").Json>;
64
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
79
+ methods: "btc_sendmany"[];
80
+ } | {
81
+ type: "eip155:eoa";
82
+ id: string;
83
+ address: string;
84
+ options: Record<string, import("@metamask/utils").Json>;
85
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
86
+ } | {
87
+ type: "eip155:erc4337";
88
+ id: string;
89
+ address: string;
90
+ options: Record<string, import("@metamask/utils").Json>;
91
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
65
92
  };
66
93
  };
67
94
  }, {
68
95
  method: import("superstruct").Struct<"notify:accountUpdated", "notify:accountUpdated">;
69
96
  params: import("superstruct").Struct<{
70
97
  account: {
71
- type: "eip155:eoa" | "eip155:erc4337";
98
+ type: "bip122:p2wpkh";
72
99
  id: string;
73
100
  address: string;
74
101
  options: Record<string, import("@metamask/utils").Json>;
75
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
102
+ methods: "btc_sendmany"[];
103
+ } | {
104
+ type: "eip155:eoa";
105
+ id: string;
106
+ address: string;
107
+ options: Record<string, import("@metamask/utils").Json>;
108
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
109
+ } | {
110
+ type: "eip155:erc4337";
111
+ id: string;
112
+ address: string;
113
+ options: Record<string, import("@metamask/utils").Json>;
114
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
76
115
  };
77
116
  }, {
78
117
  /**
79
118
  * Updated account object.
80
119
  */
81
120
  account: import("superstruct").Struct<{
82
- type: "eip155:eoa" | "eip155:erc4337";
83
- id: string;
84
- address: string;
85
- options: Record<string, import("@metamask/utils").Json>;
86
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
87
- }, {
88
- id: import("superstruct").Struct<string, null>; /**
89
- * Request result.
90
- */
91
- address: import("superstruct").Struct<string, null>;
92
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
93
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
94
- personal_sign: "personal_sign";
95
- eth_sign: "eth_sign";
96
- eth_signTransaction: "eth_signTransaction";
97
- eth_signTypedData_v1: "eth_signTypedData_v1";
98
- eth_signTypedData_v3: "eth_signTypedData_v3";
99
- eth_signTypedData_v4: "eth_signTypedData_v4";
100
- eth_prepareUserOperation: "eth_prepareUserOperation";
101
- eth_patchUserOperation: "eth_patchUserOperation";
102
- eth_signUserOperation: "eth_signUserOperation";
103
- }>>;
104
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
105
- "eip155:eoa": "eip155:eoa";
106
- "eip155:erc4337": "eip155:erc4337";
107
- }>;
108
- }>;
121
+ type: "bip122:p2wpkh";
122
+ id: string;
123
+ address: string;
124
+ options: Record<string, import("@metamask/utils").Json>;
125
+ methods: "btc_sendmany"[];
126
+ } | {
127
+ type: "eip155:eoa";
128
+ id: string;
129
+ address: string;
130
+ options: Record<string, import("@metamask/utils").Json>;
131
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
132
+ } | {
133
+ type: "eip155:erc4337";
134
+ id: string;
135
+ address: string;
136
+ options: Record<string, import("@metamask/utils").Json>;
137
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
138
+ }, null>;
109
139
  }>;
110
140
  }>;
111
141
  export declare const AccountDeletedEventStruct: import("superstruct").Struct<{
@@ -1,10 +1,60 @@
1
- import type { Infer } from 'superstruct';
2
- export declare const InternalAccountStruct: import("superstruct").Struct<{
3
- type: "eip155:eoa" | "eip155:erc4337";
1
+ import type { Infer, Struct } from 'superstruct';
2
+ import { BtcAccountType } from '../btc/types';
3
+ import { EthAccountType } from '../eth/types';
4
+ export declare type InternalAccountType = EthAccountType | BtcAccountType;
5
+ export declare const InternalAccountMetadataStruct: Struct<{
6
+ metadata: {
7
+ name: string;
8
+ importTime: number;
9
+ keyring: {
10
+ type: string;
11
+ };
12
+ snap?: {
13
+ id: string;
14
+ name: string;
15
+ enabled: boolean;
16
+ };
17
+ lastSelected?: number;
18
+ };
19
+ }, {
20
+ metadata: Struct<{
21
+ name: string;
22
+ importTime: number;
23
+ keyring: {
24
+ type: string;
25
+ };
26
+ snap?: {
27
+ id: string;
28
+ name: string;
29
+ enabled: boolean;
30
+ };
31
+ lastSelected?: number;
32
+ }, {
33
+ name: Struct<string, null>;
34
+ snap: Struct<import("../superstruct").ExactOptionalTag | {
35
+ id: string;
36
+ name: string;
37
+ enabled: boolean;
38
+ }, {
39
+ id: Struct<string, null>;
40
+ enabled: Struct<boolean, null>;
41
+ name: Struct<string, null>;
42
+ }>;
43
+ lastSelected: Struct<number | import("../superstruct").ExactOptionalTag, null>;
44
+ importTime: Struct<number, null>;
45
+ keyring: Struct<{
46
+ type: string;
47
+ }, {
48
+ type: Struct<string, null>;
49
+ }>;
50
+ }>;
51
+ }>;
52
+ export declare const InternalEthEoaAccountStruct: Struct<{
53
+ type: "eip155:eoa";
4
54
  id: string;
5
55
  address: string;
6
56
  options: Record<string, import("@metamask/utils").Json>;
7
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
57
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
8
58
  metadata: {
9
59
  name: string;
10
60
  importTime: number;
@@ -13,13 +63,26 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
13
63
  };
14
64
  snap?: {
15
65
  id: string;
16
- enabled: boolean;
17
66
  name: string;
67
+ enabled: boolean;
18
68
  };
19
69
  lastSelected?: number;
20
70
  };
21
71
  }, {
22
- metadata: import("superstruct").Struct<{
72
+ type: Struct<"eip155:eoa", "eip155:eoa">;
73
+ methods: Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
74
+ personal_sign: "personal_sign";
75
+ eth_sign: "eth_sign";
76
+ eth_signTransaction: "eth_signTransaction";
77
+ eth_signTypedData_v1: "eth_signTypedData_v1";
78
+ eth_signTypedData_v3: "eth_signTypedData_v3";
79
+ eth_signTypedData_v4: "eth_signTypedData_v4";
80
+ }>>;
81
+ id: Struct<string, null>;
82
+ address: Struct<string, null>;
83
+ options: Struct<Record<string, import("@metamask/utils").Json>, null>;
84
+ } & {
85
+ metadata: Struct<{
23
86
  name: string;
24
87
  importTime: number;
25
88
  keyring: {
@@ -27,36 +90,54 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
27
90
  };
28
91
  snap?: {
29
92
  id: string;
30
- enabled: boolean;
31
93
  name: string;
94
+ enabled: boolean;
32
95
  };
33
96
  lastSelected?: number;
34
97
  }, {
35
- name: import("superstruct").Struct<string, null>;
36
- snap: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | {
98
+ name: Struct<string, null>;
99
+ snap: Struct<import("../superstruct").ExactOptionalTag | {
37
100
  id: string;
38
- enabled: boolean;
39
101
  name: string;
102
+ enabled: boolean;
40
103
  }, {
41
- id: import("superstruct").Struct<string, null>;
42
- enabled: import("superstruct").Struct<boolean, null>;
43
- name: import("superstruct").Struct<string, null>;
104
+ id: Struct<string, null>;
105
+ enabled: Struct<boolean, null>;
106
+ name: Struct<string, null>;
44
107
  }>;
45
- lastSelected: import("superstruct").Struct<number | import("../superstruct").ExactOptionalTag, null>;
46
- importTime: import("superstruct").Struct<number, null>;
47
- keyring: import("superstruct").Struct<{
108
+ lastSelected: Struct<number | import("../superstruct").ExactOptionalTag, null>;
109
+ importTime: Struct<number, null>;
110
+ keyring: Struct<{
48
111
  type: string;
49
112
  }, {
50
- type: import("superstruct").Struct<string, null>;
113
+ type: Struct<string, null>;
51
114
  }>;
52
115
  }>;
53
- id: import("superstruct").Struct<string, null>;
54
- address: import("superstruct").Struct<string, null>;
55
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
56
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
116
+ }>;
117
+ export declare const InternalEthErc4337AccountStruct: Struct<{
118
+ type: "eip155:erc4337";
119
+ id: string;
120
+ address: string;
121
+ options: Record<string, import("@metamask/utils").Json>;
122
+ methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
123
+ metadata: {
124
+ name: string;
125
+ importTime: number;
126
+ keyring: {
127
+ type: string;
128
+ };
129
+ snap?: {
130
+ id: string;
131
+ name: string;
132
+ enabled: boolean;
133
+ };
134
+ lastSelected?: number;
135
+ };
136
+ }, {
137
+ type: Struct<"eip155:erc4337", "eip155:erc4337">;
138
+ methods: Struct<("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], Struct<"personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
57
139
  personal_sign: "personal_sign";
58
140
  eth_sign: "eth_sign";
59
- eth_signTransaction: "eth_signTransaction";
60
141
  eth_signTypedData_v1: "eth_signTypedData_v1";
61
142
  eth_signTypedData_v3: "eth_signTypedData_v3";
62
143
  eth_signTypedData_v4: "eth_signTypedData_v4";
@@ -64,11 +145,108 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
64
145
  eth_patchUserOperation: "eth_patchUserOperation";
65
146
  eth_signUserOperation: "eth_signUserOperation";
66
147
  }>>;
67
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
68
- "eip155:eoa": "eip155:eoa";
69
- "eip155:erc4337": "eip155:erc4337";
148
+ id: Struct<string, null>;
149
+ address: Struct<string, null>;
150
+ options: Struct<Record<string, import("@metamask/utils").Json>, null>;
151
+ } & {
152
+ metadata: Struct<{
153
+ name: string;
154
+ importTime: number;
155
+ keyring: {
156
+ type: string;
157
+ };
158
+ snap?: {
159
+ id: string;
160
+ name: string;
161
+ enabled: boolean;
162
+ };
163
+ lastSelected?: number;
164
+ }, {
165
+ name: Struct<string, null>;
166
+ snap: Struct<import("../superstruct").ExactOptionalTag | {
167
+ id: string;
168
+ name: string;
169
+ enabled: boolean;
170
+ }, {
171
+ id: Struct<string, null>;
172
+ enabled: Struct<boolean, null>;
173
+ name: Struct<string, null>;
174
+ }>;
175
+ lastSelected: Struct<number | import("../superstruct").ExactOptionalTag, null>;
176
+ importTime: Struct<number, null>;
177
+ keyring: Struct<{
178
+ type: string;
179
+ }, {
180
+ type: Struct<string, null>;
181
+ }>;
182
+ }>;
183
+ }>;
184
+ export declare const InternalBtcP2wpkhAccountStruct: Struct<{
185
+ type: "bip122:p2wpkh";
186
+ id: string;
187
+ address: string;
188
+ options: Record<string, import("@metamask/utils").Json>;
189
+ methods: "btc_sendmany"[];
190
+ metadata: {
191
+ name: string;
192
+ importTime: number;
193
+ keyring: {
194
+ type: string;
195
+ };
196
+ snap?: {
197
+ id: string;
198
+ name: string;
199
+ enabled: boolean;
200
+ };
201
+ lastSelected?: number;
202
+ };
203
+ }, {
204
+ type: Struct<"bip122:p2wpkh", "bip122:p2wpkh">;
205
+ methods: Struct<"btc_sendmany"[], Struct<"btc_sendmany", {
206
+ btc_sendmany: "btc_sendmany";
207
+ }>>;
208
+ id: Struct<string, null>;
209
+ address: Struct<string, null>;
210
+ options: Struct<Record<string, import("@metamask/utils").Json>, null>;
211
+ } & {
212
+ metadata: Struct<{
213
+ name: string;
214
+ importTime: number;
215
+ keyring: {
216
+ type: string;
217
+ };
218
+ snap?: {
219
+ id: string;
220
+ name: string;
221
+ enabled: boolean;
222
+ };
223
+ lastSelected?: number;
224
+ }, {
225
+ name: Struct<string, null>;
226
+ snap: Struct<import("../superstruct").ExactOptionalTag | {
227
+ id: string;
228
+ name: string;
229
+ enabled: boolean;
230
+ }, {
231
+ id: Struct<string, null>;
232
+ enabled: Struct<boolean, null>;
233
+ name: Struct<string, null>;
234
+ }>;
235
+ lastSelected: Struct<number | import("../superstruct").ExactOptionalTag, null>;
236
+ importTime: Struct<number, null>;
237
+ keyring: Struct<{
238
+ type: string;
239
+ }, {
240
+ type: Struct<string, null>;
241
+ }>;
70
242
  }>;
71
243
  }>;
244
+ export declare type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;
245
+ export declare type InternalEthErc4337Account = Infer<typeof InternalEthErc4337AccountStruct>;
246
+ export declare type InternalBtcP2wpkhAccount = Infer<typeof InternalBtcP2wpkhAccountStruct>;
247
+ export declare const InternalAccountStructs: Record<string, Struct<InternalEthEoaAccount> | Struct<InternalEthErc4337Account> | Struct<InternalBtcP2wpkhAccount>>;
248
+ export declare type InternalAccountTypes = InternalEthEoaAccount | InternalEthErc4337Account | InternalBtcP2wpkhAccount;
249
+ export declare const InternalAccountStruct: Struct<InternalAccountTypes, null>;
72
250
  /**
73
251
  * Internal account representation.
74
252
  *
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InternalAccountStruct = void 0;
3
+ exports.InternalAccountStruct = exports.InternalAccountStructs = exports.InternalBtcP2wpkhAccountStruct = exports.InternalEthErc4337AccountStruct = exports.InternalEthEoaAccountStruct = exports.InternalAccountMetadataStruct = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
5
  const api_1 = require("../api");
6
+ const types_1 = require("../btc/types");
7
+ const types_2 = require("../eth/types");
6
8
  const superstruct_2 = require("../superstruct");
7
- exports.InternalAccountStruct = (0, superstruct_2.object)({
8
- ...api_1.KeyringAccountStruct.schema,
9
+ exports.InternalAccountMetadataStruct = (0, superstruct_2.object)({
9
10
  metadata: (0, superstruct_2.object)({
10
11
  name: (0, superstruct_1.string)(),
11
12
  snap: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
@@ -20,4 +21,30 @@ exports.InternalAccountStruct = (0, superstruct_2.object)({
20
21
  }),
21
22
  }),
22
23
  });
24
+ /**
25
+ * Creates an `InternalAccount` from an existing account `superstruct` object.
26
+ *
27
+ * @param accountStruct - An account `superstruct` object.
28
+ * @returns The `InternalAccount` assocaited to `accountStruct`.
29
+ */
30
+ function asInternalAccountStruct(accountStruct) {
31
+ return (0, superstruct_2.object)({
32
+ ...accountStruct.schema,
33
+ ...exports.InternalAccountMetadataStruct.schema,
34
+ });
35
+ }
36
+ exports.InternalEthEoaAccountStruct = asInternalAccountStruct(types_2.EthEoaAccountStruct);
37
+ exports.InternalEthErc4337AccountStruct = asInternalAccountStruct(types_2.EthErc4337AccountStruct);
38
+ exports.InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(types_1.BtcP2wpkhAccountStruct);
39
+ exports.InternalAccountStructs = {
40
+ [`${types_2.EthAccountType.Eoa}`]: exports.InternalEthEoaAccountStruct,
41
+ [`${types_2.EthAccountType.Erc4337}`]: exports.InternalEthErc4337AccountStruct,
42
+ [`${types_1.BtcAccountType.P2wpkh}`]: exports.InternalBtcP2wpkhAccountStruct,
43
+ };
44
+ exports.InternalAccountStruct = (0, superstruct_1.define)('InternalAccount', (value) => {
45
+ const account = (0, superstruct_1.mask)(value, api_1.BaseKeyringAccountStruct);
46
+ // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`
47
+ const [error] = (0, superstruct_1.validate)(value, exports.InternalAccountStructs[account.type]);
48
+ return error ?? true;
49
+ });
23
50
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAAsD;AAEtD,gCAA8C;AAC9C,gDAAuD;AAE1C,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,2BAAa,EACjB,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,YAAY,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QACrC,UAAU,EAAE,IAAA,oBAAM,GAAE;QACpB,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { boolean, string, number } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\nimport { exactOptional, object } from '../superstruct';\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n metadata: object({\n name: string(),\n snap: exactOptional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n lastSelected: exactOptional(number()),\n importTime: number(),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAA8E;AAE9E,gCAAkD;AAClD,wCAAsE;AACtE,wCAIsB;AACtB,gDAAuD;AAI1C,QAAA,6BAA6B,GAAG,IAAA,oBAAM,EAAC;IAClD,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,2BAAa,EACjB,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,YAAY,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QACrC,UAAU,EAAE,IAAA,oBAAM,GAAE;QACpB,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAS,uBAAuB,CAC9B,aAA6C;IAE7C,OAAO,IAAA,oBAAM,EAAC;QACZ,GAAG,aAAa,CAAC,MAAM;QACvB,GAAG,qCAA6B,CAAC,MAAM;KACxC,CAAC,CAAC;AACL,CAAC;AAEY,QAAA,2BAA2B,GACtC,uBAAuB,CAAC,2BAAmB,CAAC,CAAC;AAElC,QAAA,+BAA+B,GAAG,uBAAuB,CACpE,+BAAuB,CACxB,CAAC;AAEW,QAAA,8BAA8B,GAAG,uBAAuB,CACnE,8BAAsB,CACvB,CAAC;AAYW,QAAA,sBAAsB,GAK/B;IACF,CAAC,GAAG,sBAAc,CAAC,GAAG,EAAE,CAAC,EAAE,mCAA2B;IACtD,CAAC,GAAG,sBAAc,CAAC,OAAO,EAAE,CAAC,EAAE,uCAA+B;IAC9D,CAAC,GAAG,sBAAc,CAAC,MAAM,EAAE,CAAC,EAAE,sCAA8B;CAC7D,CAAC;AAOW,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EACzC,iBAAiB,EACjB,CAAC,KAAc,EAAE,EAAE;IACjB,MAAM,OAAO,GAAG,IAAA,kBAAI,EAAC,KAAK,EAAE,8BAAwB,CAAC,CAAC;IAEtD,+FAA+F;IAC/F,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EACtB,KAAK,EACL,8BAAsB,CAAC,OAAO,CAAC,IAAI,CAAW,CAC/C,CAAC;IAEF,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CACF,CAAC","sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { boolean, string, number, define, mask, validate } from 'superstruct';\n\nimport { BaseKeyringAccountStruct } from '../api';\nimport { BtcP2wpkhAccountStruct, BtcAccountType } from '../btc/types';\nimport {\n EthEoaAccountStruct,\n EthErc4337AccountStruct,\n EthAccountType,\n} from '../eth/types';\nimport { exactOptional, object } from '../superstruct';\n\nexport type InternalAccountType = EthAccountType | BtcAccountType;\n\nexport const InternalAccountMetadataStruct = object({\n metadata: object({\n name: string(),\n snap: exactOptional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n lastSelected: exactOptional(number()),\n importTime: number(),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Creates an `InternalAccount` from an existing account `superstruct` object.\n *\n * @param accountStruct - An account `superstruct` object.\n * @returns The `InternalAccount` assocaited to `accountStruct`.\n */\nfunction asInternalAccountStruct<Account, AccountSchema>(\n accountStruct: Struct<Account, AccountSchema>,\n) {\n return object({\n ...accountStruct.schema,\n ...InternalAccountMetadataStruct.schema,\n });\n}\n\nexport const InternalEthEoaAccountStruct =\n asInternalAccountStruct(EthEoaAccountStruct);\n\nexport const InternalEthErc4337AccountStruct = asInternalAccountStruct(\n EthErc4337AccountStruct,\n);\n\nexport const InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(\n BtcP2wpkhAccountStruct,\n);\n\nexport type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;\n\nexport type InternalEthErc4337Account = Infer<\n typeof InternalEthErc4337AccountStruct\n>;\n\nexport type InternalBtcP2wpkhAccount = Infer<\n typeof InternalBtcP2wpkhAccountStruct\n>;\n\nexport const InternalAccountStructs: Record<\n string,\n | Struct<InternalEthEoaAccount>\n | Struct<InternalEthErc4337Account>\n | Struct<InternalBtcP2wpkhAccount>\n> = {\n [`${EthAccountType.Eoa}`]: InternalEthEoaAccountStruct,\n [`${EthAccountType.Erc4337}`]: InternalEthErc4337AccountStruct,\n [`${BtcAccountType.P2wpkh}`]: InternalBtcP2wpkhAccountStruct,\n};\n\nexport type InternalAccountTypes =\n | InternalEthEoaAccount\n | InternalEthErc4337Account\n | InternalBtcP2wpkhAccount;\n\nexport const InternalAccountStruct = define<InternalAccountTypes>(\n 'InternalAccount',\n (value: unknown) => {\n const account = mask(value, BaseKeyringAccountStruct);\n\n // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`\n const [error] = validate(\n value,\n InternalAccountStructs[account.type] as Struct,\n );\n\n return error ?? true;\n },\n);\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -41,6 +41,7 @@
41
41
  "@metamask/snaps-sdk": "^4.0.0",
42
42
  "@metamask/utils": "^8.3.0",
43
43
  "@types/uuid": "^9.0.1",
44
+ "bech32": "^2.0.0",
44
45
  "superstruct": "^1.0.3",
45
46
  "uuid": "^9.0.0"
46
47
  },