-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtypes.ts
More file actions
153 lines (130 loc) · 4.4 KB
/
Copy pathtypes.ts
File metadata and controls
153 lines (130 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// FIXME: eslint is complaning about our account union even if those accounts
// types should all be different, so we disable this for now:
/* eslint-disable @typescript-eslint/no-duplicate-type-constituents */
import {
BtcAccountType,
EthAccountType,
KeyringAccountStruct,
SolAccountType,
BtcP2pkhAccountStruct,
BtcP2shAccountStruct,
BtcP2wpkhAccountStruct,
BtcP2trAccountStruct,
EthEoaAccountStruct,
EthErc4337AccountStruct,
SolDataAccountStruct,
TrxAccountType,
TrxEoaAccountStruct,
} from '@metamask/keyring-api';
import { exactOptional, object } from '@metamask/keyring-utils';
import type { Infer, Struct } from '@metamask/superstruct';
import { boolean, string, number } from '@metamask/superstruct';
export type InternalAccountType =
| EthAccountType
| BtcAccountType
| SolAccountType
| TrxAccountType;
export const InternalAccountMetadataStruct = object({
metadata: object({
name: string(),
nameLastUpdatedAt: exactOptional(number()),
snap: exactOptional(
object({
id: string(),
enabled: boolean(),
name: string(),
}),
),
lastSelected: exactOptional(number()),
importTime: number(),
keyring: object({
type: string(),
}),
}),
});
export const InternalEthEoaAccountStruct = object({
...EthEoaAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalEthErc4337AccountStruct = object({
...EthErc4337AccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalBtcP2pkhAccountStruct = object({
...BtcP2pkhAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalBtcP2shAccountStruct = object({
...BtcP2shAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalBtcP2wpkhAccountStruct = object({
...BtcP2wpkhAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalBtcP2trAccountStruct = object({
...BtcP2trAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalSolDataAccountStruct = object({
...SolDataAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export const InternalTrxEoaAccountStruct = object({
...TrxEoaAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
export type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;
export type InternalEthErc4337Account = Infer<
typeof InternalEthErc4337AccountStruct
>;
export type InternalBtcP2pkhAccount = Infer<
typeof InternalBtcP2pkhAccountStruct
>;
export type InternalBtcP2shAccount = Infer<typeof InternalBtcP2shAccountStruct>;
export type InternalBtcP2wpkhAccount = Infer<
typeof InternalBtcP2wpkhAccountStruct
>;
export type InternalBtcP2trAccount = Infer<typeof InternalBtcP2trAccountStruct>;
export type InternalSolDataAccount = Infer<typeof InternalSolDataAccountStruct>;
export type InternalTrxEoaAccount = Infer<typeof InternalTrxEoaAccountStruct>;
export const InternalAccountStructs: Record<
string,
| Struct<InternalEthEoaAccount>
| Struct<InternalEthErc4337Account>
| Struct<InternalBtcP2pkhAccount>
| Struct<InternalBtcP2shAccount>
| Struct<InternalBtcP2wpkhAccount>
| Struct<InternalBtcP2trAccount>
| Struct<InternalSolDataAccount>
| Struct<InternalTrxEoaAccount>
> = {
[`${EthAccountType.Eoa}`]: InternalEthEoaAccountStruct,
[`${EthAccountType.Erc4337}`]: InternalEthErc4337AccountStruct,
[`${BtcAccountType.P2pkh}`]: InternalBtcP2pkhAccountStruct,
[`${BtcAccountType.P2sh}`]: InternalBtcP2shAccountStruct,
[`${BtcAccountType.P2wpkh}`]: InternalBtcP2wpkhAccountStruct,
[`${BtcAccountType.P2tr}`]: InternalBtcP2trAccountStruct,
[`${SolAccountType.DataAccount}`]: InternalSolDataAccountStruct,
[`${TrxAccountType.Eoa}`]: InternalTrxEoaAccountStruct,
};
export type InternalAccountTypes =
| InternalEthEoaAccount
| InternalEthErc4337Account
| InternalBtcP2pkhAccount
| InternalBtcP2shAccount
| InternalBtcP2wpkhAccount
| InternalBtcP2trAccount
| InternalSolDataAccount
| InternalTrxEoaAccount;
export const InternalAccountStruct = object({
...KeyringAccountStruct.schema,
...InternalAccountMetadataStruct.schema,
});
/**
* Internal account representation.
*
* This type is used internally by MetaMask to add additional metadata to the
* account object. It's should not be used by external applications.
*/
export type InternalAccount = Infer<typeof InternalAccountStruct>;