@@ -7,100 +7,16 @@ import type { EntropySourceId } from '@metamask/keyring-api';
77import type { InternalAccount } from '@metamask/keyring-internal-api' ;
88import type { AccountId } from '@metamask/keyring-utils' ;
99import { isScopeEqualToAny } from '@metamask/keyring-utils' ;
10- import type { CaipChainId } from '@metamask/utils' ;
1110
12- export type AccountType = string ;
13-
14- export type AccountMethod = string ;
15-
16- export type AccountProvider = {
17- getEntropySources : ( ) => EntropySourceId [ ] ;
18-
19- getAccounts : ( opts : {
20- entropySource : EntropySourceId ;
21- groupIndex : number ;
22- } ) => InternalAccount [ ] ;
23-
24- createAccounts : ( opts : {
25- entropySource : EntropySourceId ;
26- groupIndex : number ;
27- } ) => Promise < InternalAccount [ ] > ;
28-
29- discoverAndCreateAccounts : ( opts : {
30- entropySource : EntropySourceId ;
31- groupIndex : number ;
32- } ) => Promise < InternalAccount [ ] > ;
33- } ;
34-
35- export type MultichainAccountWalletId = `multichain-account-wallet:${string } `;
36-
37- export type MultichainAccountId = `${MultichainAccountWalletId } :${number } `; // Use number for the account group index.
38-
39- export type MultichainAccountSelector = {
40- id ?: AccountId ;
41- address ?: string ;
42- type ?: AccountType ;
43- methods ?: AccountMethod [ ] ;
44- scopes ?: CaipChainId [ ] ;
45- } ;
46-
47- export type MultichainAccount = {
48- get id ( ) : MultichainAccountId ;
49- get wallet ( ) : MultichainAccountWallet ;
50- get index ( ) : number ;
51- get accounts ( ) : InternalAccount [ ] ;
52-
53- /**
54- * Gets the "blockchain" account for a given account ID.
55- *
56- * @param id - Account ID.
57- * @returns The "blockchain" account or undefined if not found.
58- */
59- getAccount ( id : AccountId ) : InternalAccount | undefined ;
60-
61- /**
62- * Query a "blockchain" account matching the selector.
63- *
64- * @param selector - Query selector.
65- * @returns The "blockchain" account matching the selector or undefined if not matching.
66- * @throws If multiple accounts match the selector.
67- */
68- get ( selector : MultichainAccountSelector ) : InternalAccount | undefined ;
69-
70- /**
71- * Query "blockchain" accounts matching the selector.
72- *
73- * @param selector - Query selector.
74- * @returns The "blockchain" accounts matching the selector.
75- */
76- select ( selector : MultichainAccountSelector ) : InternalAccount [ ] ;
77- } ;
78-
79- /**
80- * Gets the multichain account wallet ID from its entropy source.
81- *
82- * @param entropySource - Entropy source ID of that wallet.
83- * @returns The multichain account wallet ID.
84- */
85- export function toMultichainAccountWalletId (
86- entropySource : EntropySourceId ,
87- ) : MultichainAccountWalletId {
88- return `multichain-account-wallet:${ entropySource } ` ;
89- }
90-
91- /**
92- * Gets the multichain account ID from its multichain account wallet ID and its index.
93- *
94- * @param walletId - Multichain account wallet ID.
95- * @param groupIndex - Index of that multichain account.
96- * @returns The multichain account ID.
97- */
98- export function toMultichainAccountId (
99- walletId : MultichainAccountWalletId ,
100- groupIndex : number ,
101- ) : MultichainAccountId {
102- return `${ walletId } :${ groupIndex } ` ;
103- }
11+ import type {
12+ AccountProvider ,
13+ MultichainAccount ,
14+ MultichainAccountId ,
15+ MultichainAccountSelector ,
16+ MultichainAccountWallet ,
17+ MultichainAccountWalletId ,
18+ } from './api' ;
19+ import { toMultichainAccountId , toMultichainAccountWalletId } from './api' ;
10420
10521export class MultichainAccountAdapter implements MultichainAccount {
10622 readonly #id: MultichainAccountId ;
@@ -197,45 +113,6 @@ export class MultichainAccountAdapter implements MultichainAccount {
197113 }
198114}
199115
200- export type MultichainAccountWallet = {
201- get id ( ) : MultichainAccountWalletId ;
202-
203- get entropySource ( ) : EntropySourceId ;
204-
205- get accounts ( ) : MultichainAccount [ ] ;
206-
207- /**
208- * Gets the next available account index (named group index internally).
209- *
210- * @returns Next available group index.
211- */
212- getNextGroupIndex ( ) : number ;
213-
214- /**
215- * Creates a new multichain account on a given group index.
216- *
217- * NOTE: This method is idempotent.
218- *
219- * @param groupIndex - Next available group index.
220- * @returns New (or existing) multichain account for the given group index.
221- */
222- createMultichainAccount ( groupIndex : number ) : Promise < MultichainAccount > ;
223-
224- /**
225- * Creates a new multichain account for the next available group index.
226- *
227- * @returns Next multichain account.
228- */
229- createNextMultichainAccount ( ) : Promise < MultichainAccount > ;
230-
231- /**
232- * Discovers and automatically create multichain accounts for that wallet.
233- *
234- * @returns List of all multichain accounts that got discovered or automatically created.
235- */
236- discoverAndCreateMultichainAccounts ( ) : Promise < MultichainAccount [ ] > ;
237- } ;
238-
239116export class MultichainAccountWalletAdapter implements MultichainAccountWallet {
240117 readonly #id: MultichainAccountWalletId ;
241118
0 commit comments