-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathkeyring-capabilities.ts
More file actions
107 lines (104 loc) · 2.75 KB
/
Copy pathkeyring-capabilities.ts
File metadata and controls
107 lines (104 loc) · 2.75 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
import {
array,
boolean,
exactOptional,
nonempty,
object,
partial,
type Infer,
} from '@metamask/superstruct';
import {
ExportPrivateKeyFormatStruct,
ImportPrivateKeyFormatStruct,
} from './private-key';
import { CaipChainIdStruct } from '../caip';
/**
* Struct for {@link KeyringCapabilities}.
*/
export const KeyringCapabilitiesStruct = object({
/**
* List of CAIP-2 chain IDs that this keyring supports.
*/
scopes: nonempty(array(CaipChainIdStruct)),
/**
* BIP-44 capabilities supported by this keyring.
*/
bip44: exactOptional(
object({
/**
* Whether the keyring supports deriving accounts from a specific BIP-44 path.
*/
derivePath: exactOptional(boolean()),
/**
* Whether the keyring supports deriving accounts from a BIP-44 account index.
*/
deriveIndex: exactOptional(boolean()),
/**
* Whether the keyring supports deriving accounts from a range of BIP-44 account indices.
*/
deriveIndexRange: exactOptional(boolean()),
/**
* Whether the keyring supports BIP-44 account discovery.
*/
discover: exactOptional(boolean()),
}),
),
/**
* Private key capabilities supported by this keyring.
*/
privateKey: exactOptional(
object({
/**
* List of supported formats for importing private keys.
*/
importFormats: exactOptional(array(ImportPrivateKeyFormatStruct)),
/**
* List of supported formats for exporting private keys.
*/
exportFormats: exactOptional(array(ExportPrivateKeyFormatStruct)),
}),
),
/**
* Indicates which KeyringV2 methods accept non-standard options.
*
* When a method is set to `true`, it signals that the keyring implementation
* accepts custom options for that method, different from the standard API.
* This is a workaround for keyrings with very specific requirements.
*/
custom: exactOptional(
partial(
object({
createAccounts: boolean(),
}),
),
),
});
/**
* Type representing the capabilities supported by a keyring.
*
* @example
* ```ts
* const capabilities: KeyringCapabilities = {
* scopes: ['bip122:_'],
* bip44: {
* derivePath: true,
* deriveIndex: true,
* deriveIndexRange: true,
* discover: true,
* },
* privateKey: {
* importFormats: [
* { encoding: 'base58', type: 'bip122:p2sh' },
* { encoding: 'base58', type: 'bip122:p2tr' },
* { encoding: 'base58', type: 'bip122:p2pkh' },
* { encoding: 'base58', type: 'bip122:p2wpkh' },
* ],
* exportFormats: [
* { encoding: 'base58' },
* { encoding: 'base58' },
* ],
* },
* };
* ```
*/
export type KeyringCapabilities = Infer<typeof KeyringCapabilitiesStruct>;