-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathaccount.ts
More file actions
115 lines (101 loc) · 2.49 KB
/
Copy pathaccount.ts
File metadata and controls
115 lines (101 loc) · 2.49 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
import { AccountIdStruct, object } from '@metamask/keyring-utils';
import type { Infer } from '@metamask/superstruct';
import { nonempty, array, enums, string } from '@metamask/superstruct';
import { KeyringAccountOptionsStruct } from './account-options';
import { CaipChainIdStruct } from './caip';
/**
* Supported Ethereum account types.
*/
export enum EthAccountType {
Eoa = 'eip155:eoa',
Erc4337 = 'eip155:erc4337',
}
/**
* Supported Bitcoin account types.
*/
export enum BtcAccountType {
P2pkh = 'bip122:p2pkh',
P2sh = 'bip122:p2sh',
P2wpkh = 'bip122:p2wpkh',
P2tr = 'bip122:p2tr',
}
/**
* Supported Solana account types.
*/
export enum SolAccountType {
DataAccount = 'solana:data-account',
}
/**
* Supported Tron account types.
*/
export enum TrxAccountType {
Eoa = 'tron:eoa',
}
/**
* A generic account type. It can be used to represent any account type that is
* not covered by the other account types. It only applies to non-EVM chains.
*/
export enum AnyAccountType {
Account = 'any:account',
}
/**
* Supported account types.
*/
export type KeyringAccountType =
| `${EthAccountType.Eoa}`
| `${EthAccountType.Erc4337}`
| `${BtcAccountType.P2pkh}`
| `${BtcAccountType.P2sh}`
| `${BtcAccountType.P2wpkh}`
| `${BtcAccountType.P2tr}`
| `${SolAccountType.DataAccount}`
| `${TrxAccountType.Eoa}`
| `${AnyAccountType.Account}`;
/**
* A struct which represents a Keyring account object. It is abstract enough to
* be used with any blockchain. Specific blockchain account types should extend
* this struct.
*
* See {@link KeyringAccount}.
*/
export const KeyringAccountStruct = object({
/**
* Account ID (UUIDv4).
*/
id: AccountIdStruct,
/**
* Account type.
*/
type: enums([
`${EthAccountType.Eoa}`,
`${EthAccountType.Erc4337}`,
`${BtcAccountType.P2pkh}`,
`${BtcAccountType.P2sh}`,
`${BtcAccountType.P2wpkh}`,
`${BtcAccountType.P2tr}`,
`${SolAccountType.DataAccount}`,
`${TrxAccountType.Eoa}`,
`${AnyAccountType.Account}`,
]),
/**
* Account main address.
*/
address: string(),
/**
* Account supported scopes (CAIP-2 chain IDs).
*/
scopes: nonempty(array(CaipChainIdStruct)),
/**
* Account options.
*/
options: KeyringAccountOptionsStruct,
/**
* Account supported methods.
*/
methods: array(string()),
});
/**
* Keyring Account type represents an account and its properties from the
* point of view of the keyring.
*/
export type KeyringAccount = Infer<typeof KeyringAccountStruct>;