@metamask/keyring-api 21.5.0 → 22.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.
- package/CHANGELOG.md +21 -1
- package/dist/api/transaction.cjs +64 -1
- package/dist/api/transaction.cjs.map +1 -1
- package/dist/api/transaction.d.cts +135 -0
- package/dist/api/transaction.d.cts.map +1 -1
- package/dist/api/transaction.d.mts +135 -0
- package/dist/api/transaction.d.mts.map +1 -1
- package/dist/api/transaction.mjs +64 -1
- package/dist/api/transaction.mjs.map +1 -1
- package/dist/api/v2/index.cjs +0 -1
- package/dist/api/v2/index.cjs.map +1 -1
- package/dist/api/v2/index.d.cts +0 -1
- package/dist/api/v2/index.d.cts.map +1 -1
- package/dist/api/v2/index.d.mts +0 -1
- package/dist/api/v2/index.d.mts.map +1 -1
- package/dist/api/v2/index.mjs +0 -1
- package/dist/api/v2/index.mjs.map +1 -1
- package/dist/api/v2/keyring-type.cjs +4 -0
- package/dist/api/v2/keyring-type.cjs.map +1 -1
- package/dist/api/v2/keyring-type.d.cts +5 -1
- package/dist/api/v2/keyring-type.d.cts.map +1 -1
- package/dist/api/v2/keyring-type.d.mts +5 -1
- package/dist/api/v2/keyring-type.d.mts.map +1 -1
- package/dist/api/v2/keyring-type.mjs +4 -0
- package/dist/api/v2/keyring-type.mjs.map +1 -1
- package/dist/eth/index.cjs +0 -1
- package/dist/eth/index.cjs.map +1 -1
- package/dist/eth/index.d.cts +0 -1
- package/dist/eth/index.d.cts.map +1 -1
- package/dist/eth/index.d.mts +0 -1
- package/dist/eth/index.d.mts.map +1 -1
- package/dist/eth/index.mjs +0 -1
- package/dist/eth/index.mjs.map +1 -1
- package/dist/events.d.cts +12 -0
- package/dist/events.d.cts.map +1 -1
- package/dist/events.d.mts +12 -0
- package/dist/events.d.mts.map +1 -1
- package/dist/rpc.d.cts +23 -0
- package/dist/rpc.d.cts.map +1 -1
- package/dist/rpc.d.mts +23 -0
- package/dist/rpc.d.mts.map +1 -1
- package/package.json +2 -7
- package/dist/api/v2/wrapper/index.cjs +0 -19
- package/dist/api/v2/wrapper/index.cjs.map +0 -1
- package/dist/api/v2/wrapper/index.d.cts +0 -3
- package/dist/api/v2/wrapper/index.d.cts.map +0 -1
- package/dist/api/v2/wrapper/index.d.mts +0 -3
- package/dist/api/v2/wrapper/index.d.mts.map +0 -1
- package/dist/api/v2/wrapper/index.mjs +0 -3
- package/dist/api/v2/wrapper/index.mjs.map +0 -1
- package/dist/api/v2/wrapper/keyring-account-registry.cjs +0 -135
- package/dist/api/v2/wrapper/keyring-account-registry.cjs.map +0 -1
- package/dist/api/v2/wrapper/keyring-account-registry.d.cts +0 -88
- package/dist/api/v2/wrapper/keyring-account-registry.d.cts.map +0 -1
- package/dist/api/v2/wrapper/keyring-account-registry.d.mts +0 -88
- package/dist/api/v2/wrapper/keyring-account-registry.d.mts.map +0 -1
- package/dist/api/v2/wrapper/keyring-account-registry.mjs +0 -131
- package/dist/api/v2/wrapper/keyring-account-registry.mjs.map +0 -1
- package/dist/api/v2/wrapper/keyring-wrapper.cjs +0 -134
- package/dist/api/v2/wrapper/keyring-wrapper.cjs.map +0 -1
- package/dist/api/v2/wrapper/keyring-wrapper.d.cts +0 -154
- package/dist/api/v2/wrapper/keyring-wrapper.d.cts.map +0 -1
- package/dist/api/v2/wrapper/keyring-wrapper.d.mts +0 -154
- package/dist/api/v2/wrapper/keyring-wrapper.d.mts.map +0 -1
- package/dist/api/v2/wrapper/keyring-wrapper.mjs +0 -130
- package/dist/api/v2/wrapper/keyring-wrapper.mjs.map +0 -1
- package/dist/eth/v2/eth-keyring-wrapper.cjs +0 -165
- package/dist/eth/v2/eth-keyring-wrapper.cjs.map +0 -1
- package/dist/eth/v2/eth-keyring-wrapper.d.cts +0 -54
- package/dist/eth/v2/eth-keyring-wrapper.d.cts.map +0 -1
- package/dist/eth/v2/eth-keyring-wrapper.d.mts +0 -54
- package/dist/eth/v2/eth-keyring-wrapper.d.mts.map +0 -1
- package/dist/eth/v2/eth-keyring-wrapper.mjs +0 -161
- package/dist/eth/v2/eth-keyring-wrapper.mjs.map +0 -1
- package/dist/eth/v2/index.cjs +0 -18
- package/dist/eth/v2/index.cjs.map +0 -1
- package/dist/eth/v2/index.d.cts +0 -2
- package/dist/eth/v2/index.d.cts.map +0 -1
- package/dist/eth/v2/index.d.mts +0 -2
- package/dist/eth/v2/index.d.mts.map +0 -1
- package/dist/eth/v2/index.mjs +0 -2
- package/dist/eth/v2/index.mjs.map +0 -1
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { Keyring, AccountId } from "@metamask/keyring-utils";
|
|
2
|
-
import type { Json } from "@metamask/utils";
|
|
3
|
-
import { KeyringAccountRegistry } from "./keyring-account-registry.cjs";
|
|
4
|
-
import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount } from "../index.cjs";
|
|
5
|
-
import type { KeyringAccount } from "../../account.cjs";
|
|
6
|
-
import type { KeyringRequest } from "../../request.cjs";
|
|
7
|
-
import type { KeyringV2 } from "../keyring.cjs";
|
|
8
|
-
import type { KeyringCapabilities } from "../keyring-capabilities.cjs";
|
|
9
|
-
import type { KeyringType } from "../keyring-type.cjs";
|
|
10
|
-
/**
|
|
11
|
-
* Basic options for constructing a {@link KeyringWrapper}.
|
|
12
|
-
*/
|
|
13
|
-
export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
|
|
14
|
-
/**
|
|
15
|
-
* The underlying "old" keyring instance that this wrapper adapts.
|
|
16
|
-
*/
|
|
17
|
-
inner: InnerKeyring;
|
|
18
|
-
/**
|
|
19
|
-
* The concrete keyring type exposed through the V2 interface.
|
|
20
|
-
*/
|
|
21
|
-
type: KeyringType;
|
|
22
|
-
/**
|
|
23
|
-
* Capabilities of the underlying keyring.
|
|
24
|
-
*/
|
|
25
|
-
capabilities: KeyringCapabilities;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Generic adapter that turns an existing {@link Keyring} implementation into a
|
|
29
|
-
* {@link KeyringV2} instance.
|
|
30
|
-
*
|
|
31
|
-
* Consumers are expected to provide concrete mappings between high-level V2
|
|
32
|
-
* operations and the underlying keyring methods (for example BIP-44 account
|
|
33
|
-
* creation, private-key import, and request handling). This class focuses on
|
|
34
|
-
* the common mechanics required by all adapters: state serialization,
|
|
35
|
-
* account-ID/address mapping and basic account management.
|
|
36
|
-
*/
|
|
37
|
-
export declare abstract class KeyringWrapper<InnerKeyring extends Keyring, KeyringAccountType extends KeyringAccount = KeyringAccount> implements KeyringV2 {
|
|
38
|
-
#private;
|
|
39
|
-
readonly type: `${KeyringType}`;
|
|
40
|
-
protected readonly inner: InnerKeyring;
|
|
41
|
-
/**
|
|
42
|
-
* Registry for KeyringAccount objects.
|
|
43
|
-
* Provides O(1) lookups by AccountId or address.
|
|
44
|
-
*
|
|
45
|
-
* Subclasses should use this registry when creating accounts and
|
|
46
|
-
* clear/update it when deleting accounts or deserializing state.
|
|
47
|
-
*/
|
|
48
|
-
protected readonly registry: KeyringAccountRegistry<KeyringAccountType>;
|
|
49
|
-
constructor(options: KeyringWrapperOptions<InnerKeyring>);
|
|
50
|
-
/**
|
|
51
|
-
* Get the capabilities of this keyring.
|
|
52
|
-
*
|
|
53
|
-
* Subclasses can override this getter to return capabilities dynamically
|
|
54
|
-
* based on runtime state.
|
|
55
|
-
*
|
|
56
|
-
* @returns The keyring's capabilities.
|
|
57
|
-
*/
|
|
58
|
-
get capabilities(): KeyringCapabilities;
|
|
59
|
-
/**
|
|
60
|
-
* Execute an operation with exclusive access to the inner keyring.
|
|
61
|
-
*
|
|
62
|
-
* This method ensures thread-safety for operations that read or mutate
|
|
63
|
-
* the inner keyring state. All operations that modify the keyring
|
|
64
|
-
* (createAccounts, deleteAccount, deserialize) should use this method
|
|
65
|
-
* to prevent race conditions.
|
|
66
|
-
*
|
|
67
|
-
* Within the callback, use `this.inner` to access the inner keyring.
|
|
68
|
-
*
|
|
69
|
-
* @param callback - A function that performs the operation.
|
|
70
|
-
* @returns The result of the callback.
|
|
71
|
-
*/
|
|
72
|
-
protected withLock<Result>(callback: () => Promise<Result>): Promise<Result>;
|
|
73
|
-
/**
|
|
74
|
-
* Serialize the underlying keyring state to a JSON-serializable object.
|
|
75
|
-
*
|
|
76
|
-
* This simply delegates to the legacy keyring's {@link Keyring.serialize}
|
|
77
|
-
* implementation.
|
|
78
|
-
*
|
|
79
|
-
* @returns The serialized keyring state.
|
|
80
|
-
*/
|
|
81
|
-
serialize(): Promise<Json>;
|
|
82
|
-
/**
|
|
83
|
-
* Hydrate the underlying keyring from a previously serialized state.
|
|
84
|
-
*
|
|
85
|
-
* This clears the registry, delegates to the legacy keyring's
|
|
86
|
-
* {@link Keyring.deserialize} implementation, and rebuilds the registry
|
|
87
|
-
* by calling {@link getAccounts}.
|
|
88
|
-
*
|
|
89
|
-
* @param state - The serialized keyring state.
|
|
90
|
-
*/
|
|
91
|
-
deserialize(state: Json): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Return all accounts managed by this keyring.
|
|
94
|
-
*
|
|
95
|
-
* Concrete adapters are responsible for mapping the underlying keyring's
|
|
96
|
-
* notion of accounts (typically addresses returned by
|
|
97
|
-
* {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.
|
|
98
|
-
* Implementations should use the configured {@link KeyringAccountRegistry}
|
|
99
|
-
* to establish the account ID/address mapping so that
|
|
100
|
-
* {@link getAccount} works as expected.
|
|
101
|
-
*
|
|
102
|
-
* @returns The list of managed accounts.
|
|
103
|
-
*/
|
|
104
|
-
abstract getAccounts(): Promise<KeyringAccount[]>;
|
|
105
|
-
/**
|
|
106
|
-
* Look up a single account by its {@link AccountId}.
|
|
107
|
-
*
|
|
108
|
-
* This method first checks the registry for O(1) lookup.
|
|
109
|
-
* If not found, it falls back to calling {@link getAccounts} which
|
|
110
|
-
* should populate the registry as a side effect.
|
|
111
|
-
*
|
|
112
|
-
* @param accountId - The AccountId to look up.
|
|
113
|
-
* @returns The matching KeyringAccount.
|
|
114
|
-
*/
|
|
115
|
-
getAccount(accountId: AccountId): Promise<KeyringAccount>;
|
|
116
|
-
/**
|
|
117
|
-
* Create one or more new accounts managed by this keyring.
|
|
118
|
-
*
|
|
119
|
-
* Implementations are responsible for interpreting the
|
|
120
|
-
* {@link CreateAccountOptions} (for example BIP-44 derivation or
|
|
121
|
-
* private-key import) and returning the resulting {@link KeyringAccount}
|
|
122
|
-
* objects. Implementors should also ensure that the registry is updated so
|
|
123
|
-
* that {@link getAccount} works for newly created accounts.
|
|
124
|
-
*/
|
|
125
|
-
abstract createAccounts(options: CreateAccountOptions): Promise<KeyringAccount[]>;
|
|
126
|
-
/**
|
|
127
|
-
* Remove the account associated with the given {@link AccountId} from this
|
|
128
|
-
* keyring.
|
|
129
|
-
*
|
|
130
|
-
* Implementations are expected to translate the ID to an underlying
|
|
131
|
-
* address (typically via the registry) and then invoke the appropriate
|
|
132
|
-
* removal mechanism on the legacy keyring.
|
|
133
|
-
*/
|
|
134
|
-
abstract deleteAccount(accountId: AccountId): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Export the secrets associated with the given account in a format
|
|
137
|
-
* described by {@link ExportAccountOptions}.
|
|
138
|
-
*
|
|
139
|
-
* This method is optional, and concrete adapters should only
|
|
140
|
-
* implement it if the underlying keyring supports exporting
|
|
141
|
-
* accounts.
|
|
142
|
-
*/
|
|
143
|
-
exportAccount?(accountId: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
|
|
144
|
-
/**
|
|
145
|
-
* Handle a high-level {@link KeyringRequest} on behalf of this keyring.
|
|
146
|
-
*
|
|
147
|
-
* Concrete adapters are responsible for routing the request's method and
|
|
148
|
-
* parameters to the appropriate legacy keyring APIs (for example signing
|
|
149
|
-
* transactions or decrypting messages) and returning a JSON-serializable
|
|
150
|
-
* result.
|
|
151
|
-
*/
|
|
152
|
-
abstract submitRequest(request: KeyringRequest): Promise<Json>;
|
|
153
|
-
}
|
|
154
|
-
//# sourceMappingURL=keyring-wrapper.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyring-wrapper.d.cts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,gCAAgC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AACpE,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,qBAAW;AACZ,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAmB;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAgC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,4BAAwB;AAEnD;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,YAAY,SAAS,OAAO,IAAI;IAChE;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;OAEG;IACH,YAAY,EAAE,mBAAmB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;GASG;AACH,8BAAsB,cAAc,CAClC,YAAY,SAAS,OAAO,EAC5B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,YAAW,SAAS;;IAEpB,QAAQ,CAAC,IAAI,EAAE,GAAG,WAAW,EAAE,CAAC;IAIhC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAQvC;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,6CACwB;gBAEvC,OAAO,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAMxD;;;;;;;OAOG;IACH,IAAI,YAAY,IAAI,mBAAmB,CAEtC;IAED;;;;;;;;;;;;OAYG;cACa,QAAQ,CAAC,MAAM,EAC7B,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,MAAM,CAAC;IAIlB;;;;;;;OAOG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;;;;;OAQG;IACG,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7C;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAEjD;;;;;;;;;OASG;IACG,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC;IAkB/D;;;;;;;;OAQG;IACH,QAAQ,CAAC,cAAc,CACrB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC;IAE5B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3D;;;;;;;OAOG;IACH,aAAa,CAAC,CACZ,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAE3B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAC/D"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { Keyring, AccountId } from "@metamask/keyring-utils";
|
|
2
|
-
import type { Json } from "@metamask/utils";
|
|
3
|
-
import { KeyringAccountRegistry } from "./keyring-account-registry.mjs";
|
|
4
|
-
import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount } from "../index.mjs";
|
|
5
|
-
import type { KeyringAccount } from "../../account.mjs";
|
|
6
|
-
import type { KeyringRequest } from "../../request.mjs";
|
|
7
|
-
import type { KeyringV2 } from "../keyring.mjs";
|
|
8
|
-
import type { KeyringCapabilities } from "../keyring-capabilities.mjs";
|
|
9
|
-
import type { KeyringType } from "../keyring-type.mjs";
|
|
10
|
-
/**
|
|
11
|
-
* Basic options for constructing a {@link KeyringWrapper}.
|
|
12
|
-
*/
|
|
13
|
-
export type KeyringWrapperOptions<InnerKeyring extends Keyring> = {
|
|
14
|
-
/**
|
|
15
|
-
* The underlying "old" keyring instance that this wrapper adapts.
|
|
16
|
-
*/
|
|
17
|
-
inner: InnerKeyring;
|
|
18
|
-
/**
|
|
19
|
-
* The concrete keyring type exposed through the V2 interface.
|
|
20
|
-
*/
|
|
21
|
-
type: KeyringType;
|
|
22
|
-
/**
|
|
23
|
-
* Capabilities of the underlying keyring.
|
|
24
|
-
*/
|
|
25
|
-
capabilities: KeyringCapabilities;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Generic adapter that turns an existing {@link Keyring} implementation into a
|
|
29
|
-
* {@link KeyringV2} instance.
|
|
30
|
-
*
|
|
31
|
-
* Consumers are expected to provide concrete mappings between high-level V2
|
|
32
|
-
* operations and the underlying keyring methods (for example BIP-44 account
|
|
33
|
-
* creation, private-key import, and request handling). This class focuses on
|
|
34
|
-
* the common mechanics required by all adapters: state serialization,
|
|
35
|
-
* account-ID/address mapping and basic account management.
|
|
36
|
-
*/
|
|
37
|
-
export declare abstract class KeyringWrapper<InnerKeyring extends Keyring, KeyringAccountType extends KeyringAccount = KeyringAccount> implements KeyringV2 {
|
|
38
|
-
#private;
|
|
39
|
-
readonly type: `${KeyringType}`;
|
|
40
|
-
protected readonly inner: InnerKeyring;
|
|
41
|
-
/**
|
|
42
|
-
* Registry for KeyringAccount objects.
|
|
43
|
-
* Provides O(1) lookups by AccountId or address.
|
|
44
|
-
*
|
|
45
|
-
* Subclasses should use this registry when creating accounts and
|
|
46
|
-
* clear/update it when deleting accounts or deserializing state.
|
|
47
|
-
*/
|
|
48
|
-
protected readonly registry: KeyringAccountRegistry<KeyringAccountType>;
|
|
49
|
-
constructor(options: KeyringWrapperOptions<InnerKeyring>);
|
|
50
|
-
/**
|
|
51
|
-
* Get the capabilities of this keyring.
|
|
52
|
-
*
|
|
53
|
-
* Subclasses can override this getter to return capabilities dynamically
|
|
54
|
-
* based on runtime state.
|
|
55
|
-
*
|
|
56
|
-
* @returns The keyring's capabilities.
|
|
57
|
-
*/
|
|
58
|
-
get capabilities(): KeyringCapabilities;
|
|
59
|
-
/**
|
|
60
|
-
* Execute an operation with exclusive access to the inner keyring.
|
|
61
|
-
*
|
|
62
|
-
* This method ensures thread-safety for operations that read or mutate
|
|
63
|
-
* the inner keyring state. All operations that modify the keyring
|
|
64
|
-
* (createAccounts, deleteAccount, deserialize) should use this method
|
|
65
|
-
* to prevent race conditions.
|
|
66
|
-
*
|
|
67
|
-
* Within the callback, use `this.inner` to access the inner keyring.
|
|
68
|
-
*
|
|
69
|
-
* @param callback - A function that performs the operation.
|
|
70
|
-
* @returns The result of the callback.
|
|
71
|
-
*/
|
|
72
|
-
protected withLock<Result>(callback: () => Promise<Result>): Promise<Result>;
|
|
73
|
-
/**
|
|
74
|
-
* Serialize the underlying keyring state to a JSON-serializable object.
|
|
75
|
-
*
|
|
76
|
-
* This simply delegates to the legacy keyring's {@link Keyring.serialize}
|
|
77
|
-
* implementation.
|
|
78
|
-
*
|
|
79
|
-
* @returns The serialized keyring state.
|
|
80
|
-
*/
|
|
81
|
-
serialize(): Promise<Json>;
|
|
82
|
-
/**
|
|
83
|
-
* Hydrate the underlying keyring from a previously serialized state.
|
|
84
|
-
*
|
|
85
|
-
* This clears the registry, delegates to the legacy keyring's
|
|
86
|
-
* {@link Keyring.deserialize} implementation, and rebuilds the registry
|
|
87
|
-
* by calling {@link getAccounts}.
|
|
88
|
-
*
|
|
89
|
-
* @param state - The serialized keyring state.
|
|
90
|
-
*/
|
|
91
|
-
deserialize(state: Json): Promise<void>;
|
|
92
|
-
/**
|
|
93
|
-
* Return all accounts managed by this keyring.
|
|
94
|
-
*
|
|
95
|
-
* Concrete adapters are responsible for mapping the underlying keyring's
|
|
96
|
-
* notion of accounts (typically addresses returned by
|
|
97
|
-
* {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.
|
|
98
|
-
* Implementations should use the configured {@link KeyringAccountRegistry}
|
|
99
|
-
* to establish the account ID/address mapping so that
|
|
100
|
-
* {@link getAccount} works as expected.
|
|
101
|
-
*
|
|
102
|
-
* @returns The list of managed accounts.
|
|
103
|
-
*/
|
|
104
|
-
abstract getAccounts(): Promise<KeyringAccount[]>;
|
|
105
|
-
/**
|
|
106
|
-
* Look up a single account by its {@link AccountId}.
|
|
107
|
-
*
|
|
108
|
-
* This method first checks the registry for O(1) lookup.
|
|
109
|
-
* If not found, it falls back to calling {@link getAccounts} which
|
|
110
|
-
* should populate the registry as a side effect.
|
|
111
|
-
*
|
|
112
|
-
* @param accountId - The AccountId to look up.
|
|
113
|
-
* @returns The matching KeyringAccount.
|
|
114
|
-
*/
|
|
115
|
-
getAccount(accountId: AccountId): Promise<KeyringAccount>;
|
|
116
|
-
/**
|
|
117
|
-
* Create one or more new accounts managed by this keyring.
|
|
118
|
-
*
|
|
119
|
-
* Implementations are responsible for interpreting the
|
|
120
|
-
* {@link CreateAccountOptions} (for example BIP-44 derivation or
|
|
121
|
-
* private-key import) and returning the resulting {@link KeyringAccount}
|
|
122
|
-
* objects. Implementors should also ensure that the registry is updated so
|
|
123
|
-
* that {@link getAccount} works for newly created accounts.
|
|
124
|
-
*/
|
|
125
|
-
abstract createAccounts(options: CreateAccountOptions): Promise<KeyringAccount[]>;
|
|
126
|
-
/**
|
|
127
|
-
* Remove the account associated with the given {@link AccountId} from this
|
|
128
|
-
* keyring.
|
|
129
|
-
*
|
|
130
|
-
* Implementations are expected to translate the ID to an underlying
|
|
131
|
-
* address (typically via the registry) and then invoke the appropriate
|
|
132
|
-
* removal mechanism on the legacy keyring.
|
|
133
|
-
*/
|
|
134
|
-
abstract deleteAccount(accountId: AccountId): Promise<void>;
|
|
135
|
-
/**
|
|
136
|
-
* Export the secrets associated with the given account in a format
|
|
137
|
-
* described by {@link ExportAccountOptions}.
|
|
138
|
-
*
|
|
139
|
-
* This method is optional, and concrete adapters should only
|
|
140
|
-
* implement it if the underlying keyring supports exporting
|
|
141
|
-
* accounts.
|
|
142
|
-
*/
|
|
143
|
-
exportAccount?(accountId: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
|
|
144
|
-
/**
|
|
145
|
-
* Handle a high-level {@link KeyringRequest} on behalf of this keyring.
|
|
146
|
-
*
|
|
147
|
-
* Concrete adapters are responsible for routing the request's method and
|
|
148
|
-
* parameters to the appropriate legacy keyring APIs (for example signing
|
|
149
|
-
* transactions or decrypting messages) and returning a JSON-serializable
|
|
150
|
-
* result.
|
|
151
|
-
*/
|
|
152
|
-
abstract submitRequest(request: KeyringRequest): Promise<Json>;
|
|
153
|
-
}
|
|
154
|
-
//# sourceMappingURL=keyring-wrapper.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyring-wrapper.d.mts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,gCAAgC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AACpE,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EAChB,qBAAW;AACZ,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAmB;AAC5C,OAAO,KAAK,EAAE,mBAAmB,EAAE,oCAAgC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,4BAAwB;AAEnD;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,YAAY,SAAS,OAAO,IAAI;IAChE;;OAEG;IACH,KAAK,EAAE,YAAY,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;IAElB;;OAEG;IACH,YAAY,EAAE,mBAAmB,CAAC;CACnC,CAAC;AAEF;;;;;;;;;GASG;AACH,8BAAsB,cAAc,CAClC,YAAY,SAAS,OAAO,EAC5B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,YAAW,SAAS;;IAEpB,QAAQ,CAAC,IAAI,EAAE,GAAG,WAAW,EAAE,CAAC;IAIhC,SAAS,CAAC,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAQvC;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,6CACwB;gBAEvC,OAAO,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAMxD;;;;;;;OAOG;IACH,IAAI,YAAY,IAAI,mBAAmB,CAEtC;IAED;;;;;;;;;;;;OAYG;cACa,QAAQ,CAAC,MAAM,EAC7B,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAC9B,OAAO,CAAC,MAAM,CAAC;IAIlB;;;;;;;OAOG;IACG,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAIhC;;;;;;;;OAQG;IACG,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAe7C;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAEjD;;;;;;;;;OASG;IACG,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC;IAkB/D;;;;;;;;OAQG;IACH,QAAQ,CAAC,cAAc,CACrB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,cAAc,EAAE,CAAC;IAE5B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3D;;;;;;;OAOG;IACH,aAAa,CAAC,CACZ,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAE3B;;;;;;;OAOG;IACH,QAAQ,CAAC,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAC/D"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _KeyringWrapper_capabilities, _KeyringWrapper_lock;
|
|
13
|
-
import { Mutex } from "async-mutex";
|
|
14
|
-
import { KeyringAccountRegistry } from "./keyring-account-registry.mjs";
|
|
15
|
-
/**
|
|
16
|
-
* Generic adapter that turns an existing {@link Keyring} implementation into a
|
|
17
|
-
* {@link KeyringV2} instance.
|
|
18
|
-
*
|
|
19
|
-
* Consumers are expected to provide concrete mappings between high-level V2
|
|
20
|
-
* operations and the underlying keyring methods (for example BIP-44 account
|
|
21
|
-
* creation, private-key import, and request handling). This class focuses on
|
|
22
|
-
* the common mechanics required by all adapters: state serialization,
|
|
23
|
-
* account-ID/address mapping and basic account management.
|
|
24
|
-
*/
|
|
25
|
-
export class KeyringWrapper {
|
|
26
|
-
constructor(options) {
|
|
27
|
-
_KeyringWrapper_capabilities.set(this, void 0);
|
|
28
|
-
/**
|
|
29
|
-
* Mutex to ensure exclusive access to the inner keyring during
|
|
30
|
-
* operations that mutate its state.
|
|
31
|
-
*/
|
|
32
|
-
_KeyringWrapper_lock.set(this, new Mutex());
|
|
33
|
-
/**
|
|
34
|
-
* Registry for KeyringAccount objects.
|
|
35
|
-
* Provides O(1) lookups by AccountId or address.
|
|
36
|
-
*
|
|
37
|
-
* Subclasses should use this registry when creating accounts and
|
|
38
|
-
* clear/update it when deleting accounts or deserializing state.
|
|
39
|
-
*/
|
|
40
|
-
this.registry = new KeyringAccountRegistry();
|
|
41
|
-
this.inner = options.inner;
|
|
42
|
-
this.type = `${options.type}`;
|
|
43
|
-
__classPrivateFieldSet(this, _KeyringWrapper_capabilities, options.capabilities, "f");
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Get the capabilities of this keyring.
|
|
47
|
-
*
|
|
48
|
-
* Subclasses can override this getter to return capabilities dynamically
|
|
49
|
-
* based on runtime state.
|
|
50
|
-
*
|
|
51
|
-
* @returns The keyring's capabilities.
|
|
52
|
-
*/
|
|
53
|
-
get capabilities() {
|
|
54
|
-
return __classPrivateFieldGet(this, _KeyringWrapper_capabilities, "f");
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Execute an operation with exclusive access to the inner keyring.
|
|
58
|
-
*
|
|
59
|
-
* This method ensures thread-safety for operations that read or mutate
|
|
60
|
-
* the inner keyring state. All operations that modify the keyring
|
|
61
|
-
* (createAccounts, deleteAccount, deserialize) should use this method
|
|
62
|
-
* to prevent race conditions.
|
|
63
|
-
*
|
|
64
|
-
* Within the callback, use `this.inner` to access the inner keyring.
|
|
65
|
-
*
|
|
66
|
-
* @param callback - A function that performs the operation.
|
|
67
|
-
* @returns The result of the callback.
|
|
68
|
-
*/
|
|
69
|
-
async withLock(callback) {
|
|
70
|
-
return __classPrivateFieldGet(this, _KeyringWrapper_lock, "f").runExclusive(callback);
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Serialize the underlying keyring state to a JSON-serializable object.
|
|
74
|
-
*
|
|
75
|
-
* This simply delegates to the legacy keyring's {@link Keyring.serialize}
|
|
76
|
-
* implementation.
|
|
77
|
-
*
|
|
78
|
-
* @returns The serialized keyring state.
|
|
79
|
-
*/
|
|
80
|
-
async serialize() {
|
|
81
|
-
return this.inner.serialize();
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Hydrate the underlying keyring from a previously serialized state.
|
|
85
|
-
*
|
|
86
|
-
* This clears the registry, delegates to the legacy keyring's
|
|
87
|
-
* {@link Keyring.deserialize} implementation, and rebuilds the registry
|
|
88
|
-
* by calling {@link getAccounts}.
|
|
89
|
-
*
|
|
90
|
-
* @param state - The serialized keyring state.
|
|
91
|
-
*/
|
|
92
|
-
async deserialize(state) {
|
|
93
|
-
await this.withLock(async () => {
|
|
94
|
-
// Clear the registry when deserializing
|
|
95
|
-
this.registry.clear();
|
|
96
|
-
// Deserialize the legacy keyring
|
|
97
|
-
await this.inner.deserialize(state);
|
|
98
|
-
// Rebuild the registry by calling getAccounts().
|
|
99
|
-
// Subclass implementations of getAccounts() should populate the registry
|
|
100
|
-
// as a side effect (see the abstract method's documentation).
|
|
101
|
-
await this.getAccounts();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Look up a single account by its {@link AccountId}.
|
|
106
|
-
*
|
|
107
|
-
* This method first checks the registry for O(1) lookup.
|
|
108
|
-
* If not found, it falls back to calling {@link getAccounts} which
|
|
109
|
-
* should populate the registry as a side effect.
|
|
110
|
-
*
|
|
111
|
-
* @param accountId - The AccountId to look up.
|
|
112
|
-
* @returns The matching KeyringAccount.
|
|
113
|
-
*/
|
|
114
|
-
async getAccount(accountId) {
|
|
115
|
-
let cached = this.registry.get(accountId);
|
|
116
|
-
if (cached) {
|
|
117
|
-
return cached;
|
|
118
|
-
}
|
|
119
|
-
// Prime the registry by calling getAccounts
|
|
120
|
-
await this.getAccounts();
|
|
121
|
-
// Try registry again after priming
|
|
122
|
-
cached = this.registry.get(accountId);
|
|
123
|
-
if (!cached) {
|
|
124
|
-
throw new Error(`Account not found for id: ${accountId}`);
|
|
125
|
-
}
|
|
126
|
-
return cached;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
_KeyringWrapper_capabilities = new WeakMap(), _KeyringWrapper_lock = new WeakMap();
|
|
130
|
-
//# sourceMappingURL=keyring-wrapper.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keyring-wrapper.mjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-wrapper.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,OAAO,EAAE,KAAK,EAAE,oBAAoB;AAEpC,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AAgCpE;;;;;;;;;GASG;AACH,MAAM,OAAgB,cAAc;IA2BlC,YAAY,OAA4C;QApB/C,+CAAmC;QAI5C;;;WAGG;QACM,+BAAQ,IAAI,KAAK,EAAE,EAAC;QAE7B;;;;;;WAMG;QACgB,aAAQ,GACzB,IAAI,sBAAsB,EAAsB,CAAC;QAGjD,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9B,uBAAA,IAAI,gCAAiB,OAAO,CAAC,YAAY,MAAA,CAAC;IAC5C,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,YAAY;QACd,OAAO,uBAAA,IAAI,oCAAc,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;OAYG;IACO,KAAK,CAAC,QAAQ,CACtB,QAA+B;QAE/B,OAAO,uBAAA,IAAI,4BAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IAChC,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,WAAW,CAAC,KAAW;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE;YAC7B,wCAAwC;YACxC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YAEtB,iCAAiC;YACjC,MAAM,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAEpC,iDAAiD;YACjD,yEAAyE;YACzE,8DAA8D;YAC9D,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAgBD;;;;;;;;;OASG;IACH,KAAK,CAAC,UAAU,CAAC,SAAoB;QACnC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC1C,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,4CAA4C;QAC5C,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAEzB,mCAAmC;QACnC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACtC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CA+CF","sourcesContent":["import type { Keyring, AccountId } from '@metamask/keyring-utils';\nimport type { Json } from '@metamask/utils';\nimport { Mutex } from 'async-mutex';\n\nimport { KeyringAccountRegistry } from './keyring-account-registry';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n} from '..';\nimport type { KeyringAccount } from '../../account';\nimport type { KeyringRequest } from '../../request';\nimport type { KeyringV2 } from '../keyring';\nimport type { KeyringCapabilities } from '../keyring-capabilities';\nimport type { KeyringType } from '../keyring-type';\n\n/**\n * Basic options for constructing a {@link KeyringWrapper}.\n */\nexport type KeyringWrapperOptions<InnerKeyring extends Keyring> = {\n /**\n * The underlying \"old\" keyring instance that this wrapper adapts.\n */\n inner: InnerKeyring;\n\n /**\n * The concrete keyring type exposed through the V2 interface.\n */\n type: KeyringType;\n\n /**\n * Capabilities of the underlying keyring.\n */\n capabilities: KeyringCapabilities;\n};\n\n/**\n * Generic adapter that turns an existing {@link Keyring} implementation into a\n * {@link KeyringV2} instance.\n *\n * Consumers are expected to provide concrete mappings between high-level V2\n * operations and the underlying keyring methods (for example BIP-44 account\n * creation, private-key import, and request handling). This class focuses on\n * the common mechanics required by all adapters: state serialization,\n * account-ID/address mapping and basic account management.\n */\nexport abstract class KeyringWrapper<\n InnerKeyring extends Keyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> implements KeyringV2\n{\n readonly type: `${KeyringType}`;\n\n readonly #capabilities: KeyringCapabilities;\n\n protected readonly inner: InnerKeyring;\n\n /**\n * Mutex to ensure exclusive access to the inner keyring during\n * operations that mutate its state.\n */\n readonly #lock = new Mutex();\n\n /**\n * Registry for KeyringAccount objects.\n * Provides O(1) lookups by AccountId or address.\n *\n * Subclasses should use this registry when creating accounts and\n * clear/update it when deleting accounts or deserializing state.\n */\n protected readonly registry =\n new KeyringAccountRegistry<KeyringAccountType>();\n\n constructor(options: KeyringWrapperOptions<InnerKeyring>) {\n this.inner = options.inner;\n this.type = `${options.type}`;\n this.#capabilities = options.capabilities;\n }\n\n /**\n * Get the capabilities of this keyring.\n *\n * Subclasses can override this getter to return capabilities dynamically\n * based on runtime state.\n *\n * @returns The keyring's capabilities.\n */\n get capabilities(): KeyringCapabilities {\n return this.#capabilities;\n }\n\n /**\n * Execute an operation with exclusive access to the inner keyring.\n *\n * This method ensures thread-safety for operations that read or mutate\n * the inner keyring state. All operations that modify the keyring\n * (createAccounts, deleteAccount, deserialize) should use this method\n * to prevent race conditions.\n *\n * Within the callback, use `this.inner` to access the inner keyring.\n *\n * @param callback - A function that performs the operation.\n * @returns The result of the callback.\n */\n protected async withLock<Result>(\n callback: () => Promise<Result>,\n ): Promise<Result> {\n return this.#lock.runExclusive(callback);\n }\n\n /**\n * Serialize the underlying keyring state to a JSON-serializable object.\n *\n * This simply delegates to the legacy keyring's {@link Keyring.serialize}\n * implementation.\n *\n * @returns The serialized keyring state.\n */\n async serialize(): Promise<Json> {\n return this.inner.serialize();\n }\n\n /**\n * Hydrate the underlying keyring from a previously serialized state.\n *\n * This clears the registry, delegates to the legacy keyring's\n * {@link Keyring.deserialize} implementation, and rebuilds the registry\n * by calling {@link getAccounts}.\n *\n * @param state - The serialized keyring state.\n */\n async deserialize(state: Json): Promise<void> {\n await this.withLock(async () => {\n // Clear the registry when deserializing\n this.registry.clear();\n\n // Deserialize the legacy keyring\n await this.inner.deserialize(state);\n\n // Rebuild the registry by calling getAccounts().\n // Subclass implementations of getAccounts() should populate the registry\n // as a side effect (see the abstract method's documentation).\n await this.getAccounts();\n });\n }\n\n /**\n * Return all accounts managed by this keyring.\n *\n * Concrete adapters are responsible for mapping the underlying keyring's\n * notion of accounts (typically addresses returned by\n * {@link Keyring.getAccounts}) into {@link KeyringAccount} objects.\n * Implementations should use the configured {@link KeyringAccountRegistry}\n * to establish the account ID/address mapping so that\n * {@link getAccount} works as expected.\n *\n * @returns The list of managed accounts.\n */\n abstract getAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Look up a single account by its {@link AccountId}.\n *\n * This method first checks the registry for O(1) lookup.\n * If not found, it falls back to calling {@link getAccounts} which\n * should populate the registry as a side effect.\n *\n * @param accountId - The AccountId to look up.\n * @returns The matching KeyringAccount.\n */\n async getAccount(accountId: AccountId): Promise<KeyringAccount> {\n let cached = this.registry.get(accountId);\n if (cached) {\n return cached;\n }\n\n // Prime the registry by calling getAccounts\n await this.getAccounts();\n\n // Try registry again after priming\n cached = this.registry.get(accountId);\n if (!cached) {\n throw new Error(`Account not found for id: ${accountId}`);\n }\n\n return cached;\n }\n\n /**\n * Create one or more new accounts managed by this keyring.\n *\n * Implementations are responsible for interpreting the\n * {@link CreateAccountOptions} (for example BIP-44 derivation or\n * private-key import) and returning the resulting {@link KeyringAccount}\n * objects. Implementors should also ensure that the registry is updated so\n * that {@link getAccount} works for newly created accounts.\n */\n abstract createAccounts(\n options: CreateAccountOptions,\n ): Promise<KeyringAccount[]>;\n\n /**\n * Remove the account associated with the given {@link AccountId} from this\n * keyring.\n *\n * Implementations are expected to translate the ID to an underlying\n * address (typically via the registry) and then invoke the appropriate\n * removal mechanism on the legacy keyring.\n */\n abstract deleteAccount(accountId: AccountId): Promise<void>;\n\n /**\n * Export the secrets associated with the given account in a format\n * described by {@link ExportAccountOptions}.\n *\n * This method is optional, and concrete adapters should only\n * implement it if the underlying keyring supports exporting\n * accounts.\n */\n exportAccount?(\n accountId: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount>;\n\n /**\n * Handle a high-level {@link KeyringRequest} on behalf of this keyring.\n *\n * Concrete adapters are responsible for routing the request's method and\n * parameters to the appropriate legacy keyring APIs (for example signing\n * transactions or decrypting messages) and returning a JSON-serializable\n * result.\n */\n abstract submitRequest(request: KeyringRequest): Promise<Json>;\n}\n"]}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EthKeyringWrapper = exports.EthKeyringMethod = void 0;
|
|
4
|
-
const tx_1 = require("@ethereumjs/tx");
|
|
5
|
-
const eth_sig_util_1 = require("@metamask/eth-sig-util");
|
|
6
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
7
|
-
const utils_1 = require("@metamask/utils");
|
|
8
|
-
const keyring_wrapper_1 = require("../../api/v2/wrapper/keyring-wrapper.cjs");
|
|
9
|
-
const rpc_1 = require("../rpc/index.cjs");
|
|
10
|
-
const types_1 = require("../types.cjs");
|
|
11
|
-
/**
|
|
12
|
-
* Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
|
|
13
|
-
* These are primarily encryption and utility methods.
|
|
14
|
-
*/
|
|
15
|
-
var EthKeyringMethod;
|
|
16
|
-
(function (EthKeyringMethod) {
|
|
17
|
-
EthKeyringMethod["Decrypt"] = "eth_decrypt";
|
|
18
|
-
EthKeyringMethod["GetEncryptionPublicKey"] = "eth_getEncryptionPublicKey";
|
|
19
|
-
EthKeyringMethod["GetAppKeyAddress"] = "eth_getAppKeyAddress";
|
|
20
|
-
EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
|
|
21
|
-
})(EthKeyringMethod || (exports.EthKeyringMethod = EthKeyringMethod = {}));
|
|
22
|
-
/**
|
|
23
|
-
* Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
|
|
24
|
-
*
|
|
25
|
-
* This class provides common functionality for all Ethereum keyrings including:
|
|
26
|
-
* - Request handling for standard Ethereum signing methods
|
|
27
|
-
* - Helper methods for Hex address conversion
|
|
28
|
-
*
|
|
29
|
-
* Subclasses must implement:
|
|
30
|
-
* - `getAccounts()`: Return all managed accounts
|
|
31
|
-
* - `createAccounts()`: Create new accounts based on options
|
|
32
|
-
* - `deleteAccount()`: Remove an account from the keyring
|
|
33
|
-
* - `exportAccount()` (optional): Export private key in specified format
|
|
34
|
-
*/
|
|
35
|
-
class EthKeyringWrapper extends keyring_wrapper_1.KeyringWrapper {
|
|
36
|
-
/**
|
|
37
|
-
* Helper method to safely cast a KeyringAccount address to Hex type.
|
|
38
|
-
* The KeyringAccount.address is typed as string, but for Ethereum accounts
|
|
39
|
-
* it should always be a valid Hex address.
|
|
40
|
-
*
|
|
41
|
-
* @param address - The address from a KeyringAccount.
|
|
42
|
-
* @returns The address as Hex type.
|
|
43
|
-
*/
|
|
44
|
-
toHexAddress(address) {
|
|
45
|
-
return (0, utils_1.add0x)(address);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Handle an Ethereum signing request.
|
|
49
|
-
*
|
|
50
|
-
* Routes the request to the appropriate legacy keyring method based on
|
|
51
|
-
* the RPC method name.
|
|
52
|
-
*
|
|
53
|
-
* @param request - The keyring request containing method and params.
|
|
54
|
-
* @returns The result of the signing operation.
|
|
55
|
-
*/
|
|
56
|
-
async submitRequest(request) {
|
|
57
|
-
const { method, params } = request.request;
|
|
58
|
-
const { address, methods } = await this.getAccount(request.account);
|
|
59
|
-
const hexAddress = this.toHexAddress(address);
|
|
60
|
-
// Validate account can handle the method
|
|
61
|
-
if (!methods.includes(method)) {
|
|
62
|
-
throw new Error(`Account ${request.account} cannot handle method: ${method}`);
|
|
63
|
-
}
|
|
64
|
-
switch (method) {
|
|
65
|
-
case `${types_1.EthMethod.SignTransaction}`: {
|
|
66
|
-
if (!this.inner.signTransaction) {
|
|
67
|
-
throw new Error('Keyring does not support signTransaction');
|
|
68
|
-
}
|
|
69
|
-
(0, superstruct_1.assert)(params, rpc_1.EthSignTransactionParamsStruct);
|
|
70
|
-
const [txData] = params;
|
|
71
|
-
// Convert validated transaction data to TypedTransaction
|
|
72
|
-
// TODO: Improve typing to ensure txData matches TypedTxData
|
|
73
|
-
const tx = tx_1.TransactionFactory.fromTxData(txData);
|
|
74
|
-
// Note: Bigints are not directly representable in JSON
|
|
75
|
-
return (await this.inner.signTransaction(hexAddress, tx)); // FIXME: Should return type be unknown?
|
|
76
|
-
}
|
|
77
|
-
case `${types_1.EthMethod.Sign}`: {
|
|
78
|
-
if (!this.inner.signMessage) {
|
|
79
|
-
throw new Error('Keyring does not support signMessage');
|
|
80
|
-
}
|
|
81
|
-
(0, superstruct_1.assert)(params, rpc_1.EthSignParamsStruct);
|
|
82
|
-
const [, data] = params;
|
|
83
|
-
return this.inner.signMessage(hexAddress, data);
|
|
84
|
-
}
|
|
85
|
-
case `${types_1.EthMethod.PersonalSign}`: {
|
|
86
|
-
if (!this.inner.signPersonalMessage) {
|
|
87
|
-
throw new Error('Keyring does not support signPersonalMessage');
|
|
88
|
-
}
|
|
89
|
-
(0, superstruct_1.assert)(params, rpc_1.EthPersonalSignParamsStruct);
|
|
90
|
-
const [data] = params;
|
|
91
|
-
return this.inner.signPersonalMessage(hexAddress, data);
|
|
92
|
-
}
|
|
93
|
-
case `${types_1.EthMethod.SignTypedDataV1}`: {
|
|
94
|
-
if (!this.inner.signTypedData) {
|
|
95
|
-
throw new Error('Keyring does not support signTypedData');
|
|
96
|
-
}
|
|
97
|
-
(0, superstruct_1.assert)(params, rpc_1.EthSignTypedDataV1ParamsStruct);
|
|
98
|
-
const [, data] = params;
|
|
99
|
-
return this.inner.signTypedData(hexAddress, data, {
|
|
100
|
-
version: eth_sig_util_1.SignTypedDataVersion.V1,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
case `${types_1.EthMethod.SignTypedDataV3}`: {
|
|
104
|
-
if (!this.inner.signTypedData) {
|
|
105
|
-
throw new Error('Keyring does not support signTypedData');
|
|
106
|
-
}
|
|
107
|
-
(0, superstruct_1.assert)(params, rpc_1.EthSignTypedDataParamsStruct);
|
|
108
|
-
const [, data] = params;
|
|
109
|
-
return this.inner.signTypedData(hexAddress,
|
|
110
|
-
// TODO: Improve typing to ensure data matches MessageTypes
|
|
111
|
-
data, {
|
|
112
|
-
version: eth_sig_util_1.SignTypedDataVersion.V3,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
case `${types_1.EthMethod.SignTypedDataV4}`: {
|
|
116
|
-
if (!this.inner.signTypedData) {
|
|
117
|
-
throw new Error('Keyring does not support signTypedData');
|
|
118
|
-
}
|
|
119
|
-
(0, superstruct_1.assert)(params, rpc_1.EthSignTypedDataParamsStruct);
|
|
120
|
-
const [, data] = params;
|
|
121
|
-
return this.inner.signTypedData(hexAddress,
|
|
122
|
-
// TODO: Improve typing to ensure data matches MessageTypes
|
|
123
|
-
data, {
|
|
124
|
-
version: eth_sig_util_1.SignTypedDataVersion.V4,
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
case `${EthKeyringMethod.Decrypt}`: {
|
|
128
|
-
if (!this.inner.decryptMessage) {
|
|
129
|
-
throw new Error('Keyring does not support decryptMessage');
|
|
130
|
-
}
|
|
131
|
-
(0, superstruct_1.assert)(params, rpc_1.EthDecryptParamsStruct);
|
|
132
|
-
const [encryptedData] = params;
|
|
133
|
-
return this.inner.decryptMessage(hexAddress, encryptedData);
|
|
134
|
-
}
|
|
135
|
-
case `${EthKeyringMethod.GetEncryptionPublicKey}`: {
|
|
136
|
-
if (!this.inner.getEncryptionPublicKey) {
|
|
137
|
-
throw new Error('Keyring does not support getEncryptionPublicKey');
|
|
138
|
-
}
|
|
139
|
-
(0, superstruct_1.assert)(params, rpc_1.EthGetEncryptionPublicKeyParamsStruct);
|
|
140
|
-
const [, options] = params;
|
|
141
|
-
return this.inner.getEncryptionPublicKey(hexAddress, options);
|
|
142
|
-
}
|
|
143
|
-
case `${EthKeyringMethod.GetAppKeyAddress}`: {
|
|
144
|
-
if (!this.inner.getAppKeyAddress) {
|
|
145
|
-
throw new Error('Keyring does not support getAppKeyAddress');
|
|
146
|
-
}
|
|
147
|
-
(0, superstruct_1.assert)(params, rpc_1.EthGetAppKeyAddressParamsStruct);
|
|
148
|
-
const [origin] = params;
|
|
149
|
-
return this.inner.getAppKeyAddress(hexAddress, origin);
|
|
150
|
-
}
|
|
151
|
-
case `${EthKeyringMethod.SignEip7702Authorization}`: {
|
|
152
|
-
if (!this.inner.signEip7702Authorization) {
|
|
153
|
-
throw new Error('Keyring does not support signEip7702Authorization');
|
|
154
|
-
}
|
|
155
|
-
(0, superstruct_1.assert)(params, rpc_1.EthSignEip7702AuthorizationParamsStruct);
|
|
156
|
-
const [authorization] = params;
|
|
157
|
-
return this.inner.signEip7702Authorization(hexAddress, authorization);
|
|
158
|
-
}
|
|
159
|
-
default:
|
|
160
|
-
throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.EthKeyringWrapper = EthKeyringWrapper;
|
|
165
|
-
//# sourceMappingURL=eth-keyring-wrapper.cjs.map
|