@metamask-previews/account-tree-controller 0.6.0-preview-0cb117e2 → 0.6.0-preview-bd86fa14
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 +0 -16
- package/dist/AccountTreeController.cjs +40 -194
- package/dist/AccountTreeController.cjs.map +1 -1
- package/dist/AccountTreeController.d.cts +40 -31
- package/dist/AccountTreeController.d.cts.map +1 -1
- package/dist/AccountTreeController.d.mts +40 -31
- package/dist/AccountTreeController.d.mts.map +1 -1
- package/dist/AccountTreeController.mjs +38 -192
- package/dist/AccountTreeController.mjs.map +1 -1
- package/dist/AccountTreeGroup.cjs +35 -44
- package/dist/AccountTreeGroup.cjs.map +1 -1
- package/dist/AccountTreeGroup.d.cts +22 -15
- package/dist/AccountTreeGroup.d.cts.map +1 -1
- package/dist/AccountTreeGroup.d.mts +22 -15
- package/dist/AccountTreeGroup.d.mts.map +1 -1
- package/dist/AccountTreeGroup.mjs +33 -42
- package/dist/AccountTreeGroup.mjs.map +1 -1
- package/dist/AccountTreeWallet.cjs +26 -53
- package/dist/AccountTreeWallet.cjs.map +1 -1
- package/dist/AccountTreeWallet.d.cts +21 -26
- package/dist/AccountTreeWallet.d.cts.map +1 -1
- package/dist/AccountTreeWallet.d.mts +21 -26
- package/dist/AccountTreeWallet.d.mts.map +1 -1
- package/dist/AccountTreeWallet.mjs +25 -52
- package/dist/AccountTreeWallet.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/rules/EntropySourceWalletRule.cjs +100 -0
- package/dist/rules/EntropySourceWalletRule.cjs.map +1 -0
- package/dist/rules/EntropySourceWalletRule.d.cts +19 -0
- package/dist/rules/EntropySourceWalletRule.d.cts.map +1 -0
- package/dist/rules/EntropySourceWalletRule.d.mts +19 -0
- package/dist/rules/EntropySourceWalletRule.d.mts.map +1 -0
- package/dist/rules/EntropySourceWalletRule.mjs +95 -0
- package/dist/rules/EntropySourceWalletRule.mjs.map +1 -0
- package/dist/rules/KeyringWalletRule.cjs +99 -0
- package/dist/rules/KeyringWalletRule.cjs.map +1 -0
- package/dist/rules/KeyringWalletRule.d.cts +18 -0
- package/dist/rules/KeyringWalletRule.d.cts.map +1 -0
- package/dist/rules/KeyringWalletRule.d.mts +18 -0
- package/dist/rules/KeyringWalletRule.d.mts.map +1 -0
- package/dist/rules/KeyringWalletRule.mjs +94 -0
- package/dist/rules/KeyringWalletRule.mjs.map +1 -0
- package/dist/rules/SnapWalletRule.cjs +70 -0
- package/dist/rules/SnapWalletRule.cjs.map +1 -0
- package/dist/rules/SnapWalletRule.d.cts +10 -0
- package/dist/rules/SnapWalletRule.d.cts.map +1 -0
- package/dist/rules/SnapWalletRule.d.mts +10 -0
- package/dist/rules/SnapWalletRule.d.mts.map +1 -0
- package/dist/rules/SnapWalletRule.mjs +66 -0
- package/dist/rules/SnapWalletRule.mjs.map +1 -0
- package/dist/rules/WalletRule.cjs +13 -0
- package/dist/rules/WalletRule.cjs.map +1 -0
- package/dist/rules/WalletRule.d.cts +37 -0
- package/dist/rules/WalletRule.d.cts.map +1 -0
- package/dist/rules/WalletRule.d.mts +37 -0
- package/dist/rules/WalletRule.d.mts.map +1 -0
- package/dist/rules/WalletRule.mjs +9 -0
- package/dist/rules/WalletRule.mjs.map +1 -0
- package/dist/rules/index.cjs +21 -0
- package/dist/rules/index.cjs.map +1 -0
- package/dist/rules/index.d.cts +5 -0
- package/dist/rules/index.d.cts.map +1 -0
- package/dist/rules/index.d.mts +5 -0
- package/dist/rules/index.d.mts.map +1 -0
- package/dist/rules/index.mjs +5 -0
- package/dist/rules/index.mjs.map +1 -0
- package/dist/rules/utils.cjs +15 -0
- package/dist/rules/utils.cjs.map +1 -0
- package/dist/rules/utils.d.cts +11 -0
- package/dist/rules/utils.d.cts.map +1 -0
- package/dist/rules/utils.d.mts +11 -0
- package/dist/rules/utils.d.mts.map +1 -0
- package/dist/rules/utils.mjs +11 -0
- package/dist/rules/utils.mjs.map +1 -0
- package/package.json +3 -3
- package/dist/AccountTreeRule.cjs +0 -37
- package/dist/AccountTreeRule.cjs.map +0 -1
- package/dist/AccountTreeRule.d.cts +0 -53
- package/dist/AccountTreeRule.d.cts.map +0 -1
- package/dist/AccountTreeRule.d.mts +0 -53
- package/dist/AccountTreeRule.d.mts.map +0 -1
- package/dist/AccountTreeRule.mjs +0 -33
- package/dist/AccountTreeRule.mjs.map +0 -1
- package/dist/rules/entropy.cjs +0 -68
- package/dist/rules/entropy.cjs.map +0 -1
- package/dist/rules/entropy.d.cts +0 -13
- package/dist/rules/entropy.d.cts.map +0 -1
- package/dist/rules/entropy.d.mts +0 -13
- package/dist/rules/entropy.d.mts.map +0 -1
- package/dist/rules/entropy.mjs +0 -64
- package/dist/rules/entropy.mjs.map +0 -1
- package/dist/rules/keyring.cjs +0 -86
- package/dist/rules/keyring.cjs.map +0 -1
- package/dist/rules/keyring.d.cts +0 -21
- package/dist/rules/keyring.d.cts.map +0 -1
- package/dist/rules/keyring.d.mts +0 -21
- package/dist/rules/keyring.d.mts.map +0 -1
- package/dist/rules/keyring.mjs +0 -81
- package/dist/rules/keyring.mjs.map +0 -1
- package/dist/rules/snap.cjs +0 -58
- package/dist/rules/snap.cjs.map +0 -1
- package/dist/rules/snap.d.cts +0 -22
- package/dist/rules/snap.d.cts.map +0 -1
- package/dist/rules/snap.d.mts +0 -22
- package/dist/rules/snap.d.mts.map +0 -1
- package/dist/rules/snap.mjs +0 -54
- package/dist/rules/snap.mjs.map +0 -1
- package/dist/types.cjs +0 -3
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -83
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -83
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
|
@@ -9,55 +9,46 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
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
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _MutableAccountTreeGroup_accounts;
|
|
13
|
+
import { toAccountGroupId } from "@metamask/account-api";
|
|
13
14
|
export const DEFAULT_ACCOUNT_GROUP_NAME = 'Default';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
__classPrivateFieldSet(this, _AccountTreeGroup_messenger, messenger, "f");
|
|
24
|
-
__classPrivateFieldSet(this, _AccountTreeGroup_group, group, "f");
|
|
25
|
-
__classPrivateFieldSet(this, _AccountTreeGroup_wallet, wallet, "f");
|
|
26
|
-
}
|
|
27
|
-
get id() {
|
|
28
|
-
return __classPrivateFieldGet(this, _AccountTreeGroup_group, "f").id;
|
|
29
|
-
}
|
|
30
|
-
get wallet() {
|
|
31
|
-
return __classPrivateFieldGet(this, _AccountTreeGroup_wallet, "f");
|
|
32
|
-
}
|
|
33
|
-
get name() {
|
|
34
|
-
return __classPrivateFieldGet(this, _AccountTreeGroup_group, "f").metadata.name;
|
|
15
|
+
// This class is meant to be used internally by every rules. It exposes mutable operations
|
|
16
|
+
// which should not leak outside of this package.
|
|
17
|
+
export class MutableAccountTreeGroup {
|
|
18
|
+
constructor(messenger, wallet, id) {
|
|
19
|
+
_MutableAccountTreeGroup_accounts.set(this, void 0);
|
|
20
|
+
this.id = toAccountGroupId(wallet.id, id);
|
|
21
|
+
this.wallet = wallet;
|
|
22
|
+
this.messenger = messenger;
|
|
23
|
+
__classPrivateFieldSet(this, _MutableAccountTreeGroup_accounts, new Set(), "f");
|
|
35
24
|
}
|
|
36
25
|
getAccountIds() {
|
|
37
|
-
return __classPrivateFieldGet(this,
|
|
26
|
+
return Array.from(__classPrivateFieldGet(this, _MutableAccountTreeGroup_accounts, "f")); // FIXME: Should we force the copy here?
|
|
27
|
+
}
|
|
28
|
+
getAccounts() {
|
|
29
|
+
const accounts = [];
|
|
30
|
+
for (const id of __classPrivateFieldGet(this, _MutableAccountTreeGroup_accounts, "f")) {
|
|
31
|
+
const account = this.getAccount(id);
|
|
32
|
+
// FIXME: I'm really not sure we should skip those but... We could be
|
|
33
|
+
// "de-sync" with the AccountsController and might have some dangling
|
|
34
|
+
// account IDs.
|
|
35
|
+
if (!account) {
|
|
36
|
+
console.warn(`! Unable to get account: "${id}"`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
accounts.push(account);
|
|
40
|
+
}
|
|
41
|
+
return accounts;
|
|
38
42
|
}
|
|
39
43
|
getAccount(id) {
|
|
40
|
-
return
|
|
44
|
+
return this.messenger.call('AccountsController:getAccount', id);
|
|
41
45
|
}
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
addAccount(account) {
|
|
47
|
+
__classPrivateFieldGet(this, _MutableAccountTreeGroup_accounts, "f").add(account.id);
|
|
44
48
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (accountIds.length === 0) {
|
|
48
|
-
throw new Error('Group contains no account');
|
|
49
|
-
}
|
|
50
|
-
if (accountIds.length > 1) {
|
|
51
|
-
throw new Error('Group contains more than 1 account');
|
|
52
|
-
}
|
|
53
|
-
return __classPrivateFieldGet(this, _AccountTreeGroup_instances, "m", _AccountTreeGroup_getAccount).call(this, accountIds[0]);
|
|
49
|
+
getDefaultName() {
|
|
50
|
+
return DEFAULT_ACCOUNT_GROUP_NAME;
|
|
54
51
|
}
|
|
55
52
|
}
|
|
56
|
-
|
|
57
|
-
const account = this.getAccount(id);
|
|
58
|
-
if (!account) {
|
|
59
|
-
throw new Error(`Unable to get account with ID: "${id}"`);
|
|
60
|
-
}
|
|
61
|
-
return account;
|
|
62
|
-
};
|
|
53
|
+
_MutableAccountTreeGroup_accounts = new WeakMap();
|
|
63
54
|
//# sourceMappingURL=AccountTreeGroup.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeGroup.mjs","sourceRoot":"","sources":["../src/AccountTreeGroup.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"AccountTreeGroup.mjs","sourceRoot":"","sources":["../src/AccountTreeGroup.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,gBAAgB,EAIjB,8BAA8B;AAK/B,MAAM,CAAC,MAAM,0BAA0B,GAAW,SAAS,CAAC;AAiB5D,0FAA0F;AAC1F,iDAAiD;AACjD,MAAM,OAAO,uBAAuB;IASlC,YACE,SAAyC,EACzC,MAAsC,EACtC,EAAU;QALH,oDAA0B;QAOjC,IAAI,CAAC,EAAE,GAAG,gBAAgB,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,uBAAA,IAAI,qCAAa,IAAI,GAAG,EAAE,MAAA,CAAC;IAC7B,CAAC;IAED,aAAa;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,yCAAU,CAAC,CAAC,CAAC,wCAAwC;IAC7E,CAAC;IAED,WAAW;QACT,MAAM,QAAQ,GAAG,EAAE,CAAC;QAEpB,KAAK,MAAM,EAAE,IAAI,uBAAA,IAAI,yCAAU,EAAE;YAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;YAEpC,qEAAqE;YACrE,qEAAqE;YACrE,eAAe;YACf,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,CAAC,IAAI,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;gBACjD,SAAS;aACV;YACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACxB;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,UAAU,CAAC,EAAa;QACtB,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,UAAU,CAAC,OAAwB;QACjC,uBAAA,IAAI,yCAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjC,CAAC;IAED,cAAc;QACZ,OAAO,0BAA0B,CAAC;IACpC,CAAC;CACF","sourcesContent":["import {\n toAccountGroupId,\n type AccountGroup,\n type AccountGroupId,\n type AccountWallet,\n} from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport type { AccountTreeControllerMessenger } from 'src';\n\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\n/**\n * Account group coming from the {@link AccountTreeController}.\n */\nexport type AccountTreeGroup = {\n /**\n * Account IDs for that account group.\n */\n getAccountIds(): AccountId[];\n\n /**\n * Gets the default name for that account group.\n */\n getDefaultName(): string;\n} & AccountGroup<InternalAccount>;\n\n// This class is meant to be used internally by every rules. It exposes mutable operations\n// which should not leak outside of this package.\nexport class MutableAccountTreeGroup implements AccountTreeGroup {\n readonly id: AccountGroupId;\n\n readonly wallet: AccountWallet<InternalAccount>;\n\n readonly messenger: AccountTreeControllerMessenger;\n\n readonly #accounts: Set<AccountId>;\n\n constructor(\n messenger: AccountTreeControllerMessenger,\n wallet: AccountWallet<InternalAccount>,\n id: string,\n ) {\n this.id = toAccountGroupId(wallet.id, id);\n this.wallet = wallet;\n this.messenger = messenger;\n\n this.#accounts = new Set();\n }\n\n getAccountIds(): AccountId[] {\n return Array.from(this.#accounts); // FIXME: Should we force the copy here?\n }\n\n getAccounts(): InternalAccount[] {\n const accounts = [];\n\n for (const id of this.#accounts) {\n const account = this.getAccount(id);\n\n // FIXME: I'm really not sure we should skip those but... We could be\n // \"de-sync\" with the AccountsController and might have some dangling\n // account IDs.\n if (!account) {\n console.warn(`! Unable to get account: \"${id}\"`);\n continue;\n }\n accounts.push(account);\n }\n return accounts;\n }\n\n getAccount(id: AccountId): InternalAccount | undefined {\n return this.messenger.call('AccountsController:getAccount', id);\n }\n\n addAccount(account: InternalAccount) {\n this.#accounts.add(account.id);\n }\n\n getDefaultName(): string {\n return DEFAULT_ACCOUNT_GROUP_NAME;\n }\n}\n"]}
|
|
@@ -10,68 +10,41 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
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");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _MutableAccountTreeWallet_groups;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.MutableAccountTreeWallet = void 0;
|
|
16
|
+
const account_api_1 = require("@metamask/account-api");
|
|
16
17
|
const AccountTreeGroup_1 = require("./AccountTreeGroup.cjs");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
// This class is meant to be used internally by every rules. It exposes mutable operations
|
|
19
|
+
// which should not leak outside of this package.
|
|
20
|
+
class MutableAccountTreeWallet {
|
|
21
|
+
constructor(messenger, category, id) {
|
|
22
|
+
_MutableAccountTreeWallet_groups.set(this, void 0);
|
|
23
|
+
this.id = (0, account_api_1.toAccountWalletId)(category, id);
|
|
24
|
+
this.category = category;
|
|
23
25
|
this.messenger = messenger;
|
|
24
|
-
__classPrivateFieldSet(this,
|
|
25
|
-
this.groups = new Map();
|
|
26
|
-
for (const [groupId, group] of Object.entries(__classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").groups)) {
|
|
27
|
-
this.groups.set(groupId, new AccountTreeGroup_1.AccountTreeGroup({
|
|
28
|
-
messenger: this.messenger,
|
|
29
|
-
wallet: this,
|
|
30
|
-
group,
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
get id() {
|
|
35
|
-
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").id;
|
|
36
|
-
}
|
|
37
|
-
get category() {
|
|
38
|
-
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").metadata.type;
|
|
39
|
-
}
|
|
40
|
-
get name() {
|
|
41
|
-
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").metadata.name;
|
|
26
|
+
__classPrivateFieldSet(this, _MutableAccountTreeWallet_groups, new Map(), "f");
|
|
42
27
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Gets account tree group for a given ID.
|
|
45
|
-
*
|
|
46
|
-
* @param groupId - Group ID.
|
|
47
|
-
* @returns Account tree group, or undefined if not found.
|
|
48
|
-
*/
|
|
49
28
|
getAccountGroup(groupId) {
|
|
50
|
-
return this.
|
|
29
|
+
return __classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").get(groupId);
|
|
51
30
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const group = this.getAccountGroup(groupId);
|
|
31
|
+
getAccountGroups() {
|
|
32
|
+
return Array.from(__classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").values()); // TODO: Should we avoid the copy here?
|
|
33
|
+
}
|
|
34
|
+
// NOTE: This method SHOULD BE overriden if a rule need to group things differently.
|
|
35
|
+
addAccount(account) {
|
|
36
|
+
const id = account_api_1.DEFAULT_ACCOUNT_GROUP_UNIQUE_ID;
|
|
37
|
+
// Use a single-group by default.
|
|
38
|
+
let group = __classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").get((0, account_api_1.toAccountGroupId)(this.id, id));
|
|
61
39
|
if (!group) {
|
|
62
|
-
|
|
40
|
+
// We create the account group and attach it to this wallet.
|
|
41
|
+
group = new AccountTreeGroup_1.MutableAccountTreeGroup(this.messenger, this, id);
|
|
42
|
+
__classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").set(group.id, group);
|
|
63
43
|
}
|
|
44
|
+
group.addAccount(account);
|
|
64
45
|
return group;
|
|
65
46
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Gets all account tree groups.
|
|
68
|
-
*
|
|
69
|
-
* @returns Account tree groups.
|
|
70
|
-
*/
|
|
71
|
-
getAccountGroups() {
|
|
72
|
-
return Array.from(this.groups.values());
|
|
73
|
-
}
|
|
74
47
|
}
|
|
75
|
-
exports.
|
|
76
|
-
|
|
48
|
+
exports.MutableAccountTreeWallet = MutableAccountTreeWallet;
|
|
49
|
+
_MutableAccountTreeWallet_groups = new WeakMap();
|
|
77
50
|
//# sourceMappingURL=AccountTreeWallet.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeWallet.cjs","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"AccountTreeWallet.cjs","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAQ+B;AAK/B,6DAA6D;AA0B7D,0FAA0F;AAC1F,iDAAiD;AACjD,MAAsB,wBAAwB;IAS5C,YACE,SAAyC,EACzC,QAA+B,EAC/B,EAAU;QALH,mDAAsD;QAO7D,IAAI,CAAC,EAAE,GAAG,IAAA,+BAAiB,EAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,uBAAA,IAAI,oCAAW,IAAI,GAAG,EAAE,MAAA,CAAC;IAC3B,CAAC;IAED,eAAe,CAAC,OAAuB;QACrC,OAAO,uBAAA,IAAI,wCAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,gBAAgB;QACd,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,wCAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,uCAAuC;IACnF,CAAC;IAED,oFAAoF;IACpF,UAAU,CAAC,OAAwB;QACjC,MAAM,EAAE,GAAG,6CAA+B,CAAC;QAE3C,iCAAiC;QACjC,IAAI,KAAK,GAAG,uBAAA,IAAI,wCAAQ,CAAC,GAAG,CAAC,IAAA,8BAAgB,EAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,KAAK,EAAE;YACV,4DAA4D;YAC5D,KAAK,GAAG,IAAI,0CAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YAC9D,uBAAA,IAAI,wCAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;SACnC;QAED,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO,KAAK,CAAC;IACf,CAAC;CAGF;AA/CD,4DA+CC","sourcesContent":["import {\n toAccountGroupId,\n toAccountWalletId,\n DEFAULT_ACCOUNT_GROUP_UNIQUE_ID,\n type AccountGroupId,\n type AccountWallet,\n type AccountWalletCategory,\n type AccountWalletId,\n} from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { type AccountTreeControllerMessenger } from './AccountTreeController';\nimport type { AccountTreeGroup } from './AccountTreeGroup';\nimport { MutableAccountTreeGroup } from './AccountTreeGroup';\n\n/**\n * Account wallet coming from the {@link AccountTreeController}.\n */\nexport type AccountTreeWallet = {\n /**\n * Gets account tree group for a given ID.\n *\n * @returns Account tree group.\n */\n getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;\n\n /**\n * Gets all account tree groups.\n *\n * @returns Account tree groups.\n */\n getAccountGroups(): AccountTreeGroup[];\n\n /**\n * Gets the default name for that account wallet.\n */\n getDefaultName(): string;\n} & AccountWallet<InternalAccount>;\n\n// This class is meant to be used internally by every rules. It exposes mutable operations\n// which should not leak outside of this package.\nexport abstract class MutableAccountTreeWallet implements AccountTreeWallet {\n readonly id: AccountWalletId;\n\n readonly category: AccountWalletCategory;\n\n readonly messenger: AccountTreeControllerMessenger;\n\n readonly #groups: Map<AccountGroupId, MutableAccountTreeGroup>;\n\n constructor(\n messenger: AccountTreeControllerMessenger,\n category: AccountWalletCategory,\n id: string,\n ) {\n this.id = toAccountWalletId(category, id);\n this.category = category;\n this.messenger = messenger;\n\n this.#groups = new Map();\n }\n\n getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined {\n return this.#groups.get(groupId);\n }\n\n getAccountGroups(): AccountTreeGroup[] {\n return Array.from(this.#groups.values()); // TODO: Should we avoid the copy here?\n }\n\n // NOTE: This method SHOULD BE overriden if a rule need to group things differently.\n addAccount(account: InternalAccount): MutableAccountTreeGroup {\n const id = DEFAULT_ACCOUNT_GROUP_UNIQUE_ID;\n\n // Use a single-group by default.\n let group = this.#groups.get(toAccountGroupId(this.id, id));\n if (!group) {\n // We create the account group and attach it to this wallet.\n group = new MutableAccountTreeGroup(this.messenger, this, id);\n this.#groups.set(group.id, group);\n }\n\n group.addAccount(account);\n\n return group;\n }\n\n abstract getDefaultName(): string;\n}\n"]}
|
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type AccountGroupId, type AccountWallet } from "@metamask/account-api";
|
|
1
|
+
import { type AccountGroupId, type AccountWallet, type AccountWalletCategory, type AccountWalletId } from "@metamask/account-api";
|
|
3
2
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
3
|
+
import { type AccountTreeControllerMessenger } from "./AccountTreeController.cjs";
|
|
4
|
+
import type { AccountTreeGroup } from "./AccountTreeGroup.cjs";
|
|
5
|
+
import { MutableAccountTreeGroup } from "./AccountTreeGroup.cjs";
|
|
7
6
|
/**
|
|
8
7
|
* Account wallet coming from the {@link AccountTreeController}.
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
11
|
-
#private;
|
|
12
|
-
protected messenger: AccountTreeControllerMessenger;
|
|
13
|
-
protected groups: Map<AccountGroupId, AccountTreeGroup>;
|
|
14
|
-
constructor({ messenger, wallet, }: {
|
|
15
|
-
messenger: AccountTreeControllerMessenger;
|
|
16
|
-
wallet: AccountWalletObject;
|
|
17
|
-
});
|
|
18
|
-
get id(): AccountWalletId;
|
|
19
|
-
get category(): AccountWalletCategory;
|
|
20
|
-
get name(): string;
|
|
21
|
-
/**
|
|
22
|
-
* Gets account tree group for a given ID.
|
|
23
|
-
*
|
|
24
|
-
* @param groupId - Group ID.
|
|
25
|
-
* @returns Account tree group, or undefined if not found.
|
|
26
|
-
*/
|
|
27
|
-
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
9
|
+
export type AccountTreeWallet = {
|
|
28
10
|
/**
|
|
29
11
|
* Gets account tree group for a given ID.
|
|
30
12
|
*
|
|
31
|
-
* @param groupId - Group ID.
|
|
32
|
-
* @throws If the account group is not found.
|
|
33
13
|
* @returns Account tree group.
|
|
34
14
|
*/
|
|
35
|
-
|
|
15
|
+
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
36
16
|
/**
|
|
37
17
|
* Gets all account tree groups.
|
|
38
18
|
*
|
|
39
19
|
* @returns Account tree groups.
|
|
40
20
|
*/
|
|
41
21
|
getAccountGroups(): AccountTreeGroup[];
|
|
22
|
+
/**
|
|
23
|
+
* Gets the default name for that account wallet.
|
|
24
|
+
*/
|
|
25
|
+
getDefaultName(): string;
|
|
26
|
+
} & AccountWallet<InternalAccount>;
|
|
27
|
+
export declare abstract class MutableAccountTreeWallet implements AccountTreeWallet {
|
|
28
|
+
#private;
|
|
29
|
+
readonly id: AccountWalletId;
|
|
30
|
+
readonly category: AccountWalletCategory;
|
|
31
|
+
readonly messenger: AccountTreeControllerMessenger;
|
|
32
|
+
constructor(messenger: AccountTreeControllerMessenger, category: AccountWalletCategory, id: string);
|
|
33
|
+
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
34
|
+
getAccountGroups(): AccountTreeGroup[];
|
|
35
|
+
addAccount(account: InternalAccount): MutableAccountTreeGroup;
|
|
36
|
+
abstract getDefaultName(): string;
|
|
42
37
|
}
|
|
43
38
|
//# sourceMappingURL=AccountTreeWallet.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeWallet.d.cts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"AccountTreeWallet.d.cts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,KAAK,8BAA8B,EAAE,oCAAgC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAC3D,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAE7D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,gBAAgB,EAAE,CAAC;IAEvC;;OAEG;IACH,cAAc,IAAI,MAAM,CAAC;CAC1B,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;AAInC,8BAAsB,wBAAyB,YAAW,iBAAiB;;IACzE,QAAQ,CAAC,EAAE,EAAE,eAAe,CAAC;IAE7B,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IAEzC,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;gBAKjD,SAAS,EAAE,8BAA8B,EACzC,QAAQ,EAAE,qBAAqB,EAC/B,EAAE,EAAE,MAAM;IASZ,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB,GAAG,SAAS;IAItE,gBAAgB,IAAI,gBAAgB,EAAE;IAKtC,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,uBAAuB;IAgB7D,QAAQ,CAAC,cAAc,IAAI,MAAM;CAClC"}
|
|
@@ -1,43 +1,38 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type AccountGroupId, type AccountWallet } from "@metamask/account-api";
|
|
1
|
+
import { type AccountGroupId, type AccountWallet, type AccountWalletCategory, type AccountWalletId } from "@metamask/account-api";
|
|
3
2
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
import {
|
|
3
|
+
import { type AccountTreeControllerMessenger } from "./AccountTreeController.mjs";
|
|
4
|
+
import type { AccountTreeGroup } from "./AccountTreeGroup.mjs";
|
|
5
|
+
import { MutableAccountTreeGroup } from "./AccountTreeGroup.mjs";
|
|
7
6
|
/**
|
|
8
7
|
* Account wallet coming from the {@link AccountTreeController}.
|
|
9
8
|
*/
|
|
10
|
-
export
|
|
11
|
-
#private;
|
|
12
|
-
protected messenger: AccountTreeControllerMessenger;
|
|
13
|
-
protected groups: Map<AccountGroupId, AccountTreeGroup>;
|
|
14
|
-
constructor({ messenger, wallet, }: {
|
|
15
|
-
messenger: AccountTreeControllerMessenger;
|
|
16
|
-
wallet: AccountWalletObject;
|
|
17
|
-
});
|
|
18
|
-
get id(): AccountWalletId;
|
|
19
|
-
get category(): AccountWalletCategory;
|
|
20
|
-
get name(): string;
|
|
21
|
-
/**
|
|
22
|
-
* Gets account tree group for a given ID.
|
|
23
|
-
*
|
|
24
|
-
* @param groupId - Group ID.
|
|
25
|
-
* @returns Account tree group, or undefined if not found.
|
|
26
|
-
*/
|
|
27
|
-
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
9
|
+
export type AccountTreeWallet = {
|
|
28
10
|
/**
|
|
29
11
|
* Gets account tree group for a given ID.
|
|
30
12
|
*
|
|
31
|
-
* @param groupId - Group ID.
|
|
32
|
-
* @throws If the account group is not found.
|
|
33
13
|
* @returns Account tree group.
|
|
34
14
|
*/
|
|
35
|
-
|
|
15
|
+
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
36
16
|
/**
|
|
37
17
|
* Gets all account tree groups.
|
|
38
18
|
*
|
|
39
19
|
* @returns Account tree groups.
|
|
40
20
|
*/
|
|
41
21
|
getAccountGroups(): AccountTreeGroup[];
|
|
22
|
+
/**
|
|
23
|
+
* Gets the default name for that account wallet.
|
|
24
|
+
*/
|
|
25
|
+
getDefaultName(): string;
|
|
26
|
+
} & AccountWallet<InternalAccount>;
|
|
27
|
+
export declare abstract class MutableAccountTreeWallet implements AccountTreeWallet {
|
|
28
|
+
#private;
|
|
29
|
+
readonly id: AccountWalletId;
|
|
30
|
+
readonly category: AccountWalletCategory;
|
|
31
|
+
readonly messenger: AccountTreeControllerMessenger;
|
|
32
|
+
constructor(messenger: AccountTreeControllerMessenger, category: AccountWalletCategory, id: string);
|
|
33
|
+
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
34
|
+
getAccountGroups(): AccountTreeGroup[];
|
|
35
|
+
addAccount(account: InternalAccount): MutableAccountTreeGroup;
|
|
36
|
+
abstract getDefaultName(): string;
|
|
42
37
|
}
|
|
43
38
|
//# sourceMappingURL=AccountTreeWallet.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeWallet.d.mts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"AccountTreeWallet.d.mts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,eAAe,EACrB,8BAA8B;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,KAAK,8BAA8B,EAAE,oCAAgC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,+BAA2B;AAC3D,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAE7D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,gBAAgB,EAAE,CAAC;IAEvC;;OAEG;IACH,cAAc,IAAI,MAAM,CAAC;CAC1B,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC;AAInC,8BAAsB,wBAAyB,YAAW,iBAAiB;;IACzE,QAAQ,CAAC,EAAE,EAAE,eAAe,CAAC;IAE7B,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IAEzC,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;gBAKjD,SAAS,EAAE,8BAA8B,EACzC,QAAQ,EAAE,qBAAqB,EAC/B,EAAE,EAAE,MAAM;IASZ,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB,GAAG,SAAS;IAItE,gBAAgB,IAAI,gBAAgB,EAAE;IAKtC,UAAU,CAAC,OAAO,EAAE,eAAe,GAAG,uBAAuB;IAgB7D,QAAQ,CAAC,cAAc,IAAI,MAAM;CAClC"}
|
|
@@ -9,65 +9,38 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
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
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export class
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
12
|
+
var _MutableAccountTreeWallet_groups;
|
|
13
|
+
import { toAccountGroupId, toAccountWalletId, DEFAULT_ACCOUNT_GROUP_UNIQUE_ID } from "@metamask/account-api";
|
|
14
|
+
import { MutableAccountTreeGroup } from "./AccountTreeGroup.mjs";
|
|
15
|
+
// This class is meant to be used internally by every rules. It exposes mutable operations
|
|
16
|
+
// which should not leak outside of this package.
|
|
17
|
+
export class MutableAccountTreeWallet {
|
|
18
|
+
constructor(messenger, category, id) {
|
|
19
|
+
_MutableAccountTreeWallet_groups.set(this, void 0);
|
|
20
|
+
this.id = toAccountWalletId(category, id);
|
|
21
|
+
this.category = category;
|
|
20
22
|
this.messenger = messenger;
|
|
21
|
-
__classPrivateFieldSet(this,
|
|
22
|
-
this.groups = new Map();
|
|
23
|
-
for (const [groupId, group] of Object.entries(__classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").groups)) {
|
|
24
|
-
this.groups.set(groupId, new AccountTreeGroup({
|
|
25
|
-
messenger: this.messenger,
|
|
26
|
-
wallet: this,
|
|
27
|
-
group,
|
|
28
|
-
}));
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
get id() {
|
|
32
|
-
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").id;
|
|
33
|
-
}
|
|
34
|
-
get category() {
|
|
35
|
-
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").metadata.type;
|
|
36
|
-
}
|
|
37
|
-
get name() {
|
|
38
|
-
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").metadata.name;
|
|
23
|
+
__classPrivateFieldSet(this, _MutableAccountTreeWallet_groups, new Map(), "f");
|
|
39
24
|
}
|
|
40
|
-
/**
|
|
41
|
-
* Gets account tree group for a given ID.
|
|
42
|
-
*
|
|
43
|
-
* @param groupId - Group ID.
|
|
44
|
-
* @returns Account tree group, or undefined if not found.
|
|
45
|
-
*/
|
|
46
25
|
getAccountGroup(groupId) {
|
|
47
|
-
return this.
|
|
26
|
+
return __classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").get(groupId);
|
|
48
27
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const group = this.getAccountGroup(groupId);
|
|
28
|
+
getAccountGroups() {
|
|
29
|
+
return Array.from(__classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").values()); // TODO: Should we avoid the copy here?
|
|
30
|
+
}
|
|
31
|
+
// NOTE: This method SHOULD BE overriden if a rule need to group things differently.
|
|
32
|
+
addAccount(account) {
|
|
33
|
+
const id = DEFAULT_ACCOUNT_GROUP_UNIQUE_ID;
|
|
34
|
+
// Use a single-group by default.
|
|
35
|
+
let group = __classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").get(toAccountGroupId(this.id, id));
|
|
58
36
|
if (!group) {
|
|
59
|
-
|
|
37
|
+
// We create the account group and attach it to this wallet.
|
|
38
|
+
group = new MutableAccountTreeGroup(this.messenger, this, id);
|
|
39
|
+
__classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").set(group.id, group);
|
|
60
40
|
}
|
|
41
|
+
group.addAccount(account);
|
|
61
42
|
return group;
|
|
62
43
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Gets all account tree groups.
|
|
65
|
-
*
|
|
66
|
-
* @returns Account tree groups.
|
|
67
|
-
*/
|
|
68
|
-
getAccountGroups() {
|
|
69
|
-
return Array.from(this.groups.values());
|
|
70
|
-
}
|
|
71
44
|
}
|
|
72
|
-
|
|
45
|
+
_MutableAccountTreeWallet_groups = new WeakMap();
|
|
73
46
|
//# sourceMappingURL=AccountTreeWallet.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeWallet.mjs","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"AccountTreeWallet.mjs","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,+BAA+B,EAKhC,8BAA8B;AAK/B,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AA0B7D,0FAA0F;AAC1F,iDAAiD;AACjD,MAAM,OAAgB,wBAAwB;IAS5C,YACE,SAAyC,EACzC,QAA+B,EAC/B,EAAU;QALH,mDAAsD;QAO7D,IAAI,CAAC,EAAE,GAAG,iBAAiB,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,uBAAA,IAAI,oCAAW,IAAI,GAAG,EAAE,MAAA,CAAC;IAC3B,CAAC;IAED,eAAe,CAAC,OAAuB;QACrC,OAAO,uBAAA,IAAI,wCAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;IAED,gBAAgB;QACd,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,wCAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,uCAAuC;IACnF,CAAC;IAED,oFAAoF;IACpF,UAAU,CAAC,OAAwB;QACjC,MAAM,EAAE,GAAG,+BAA+B,CAAC;QAE3C,iCAAiC;QACjC,IAAI,KAAK,GAAG,uBAAA,IAAI,wCAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;QAC5D,IAAI,CAAC,KAAK,EAAE;YACV,4DAA4D;YAC5D,KAAK,GAAG,IAAI,uBAAuB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;YAC9D,uBAAA,IAAI,wCAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;SACnC;QAED,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO,KAAK,CAAC;IACf,CAAC;CAGF","sourcesContent":["import {\n toAccountGroupId,\n toAccountWalletId,\n DEFAULT_ACCOUNT_GROUP_UNIQUE_ID,\n type AccountGroupId,\n type AccountWallet,\n type AccountWalletCategory,\n type AccountWalletId,\n} from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { type AccountTreeControllerMessenger } from './AccountTreeController';\nimport type { AccountTreeGroup } from './AccountTreeGroup';\nimport { MutableAccountTreeGroup } from './AccountTreeGroup';\n\n/**\n * Account wallet coming from the {@link AccountTreeController}.\n */\nexport type AccountTreeWallet = {\n /**\n * Gets account tree group for a given ID.\n *\n * @returns Account tree group.\n */\n getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;\n\n /**\n * Gets all account tree groups.\n *\n * @returns Account tree groups.\n */\n getAccountGroups(): AccountTreeGroup[];\n\n /**\n * Gets the default name for that account wallet.\n */\n getDefaultName(): string;\n} & AccountWallet<InternalAccount>;\n\n// This class is meant to be used internally by every rules. It exposes mutable operations\n// which should not leak outside of this package.\nexport abstract class MutableAccountTreeWallet implements AccountTreeWallet {\n readonly id: AccountWalletId;\n\n readonly category: AccountWalletCategory;\n\n readonly messenger: AccountTreeControllerMessenger;\n\n readonly #groups: Map<AccountGroupId, MutableAccountTreeGroup>;\n\n constructor(\n messenger: AccountTreeControllerMessenger,\n category: AccountWalletCategory,\n id: string,\n ) {\n this.id = toAccountWalletId(category, id);\n this.category = category;\n this.messenger = messenger;\n\n this.#groups = new Map();\n }\n\n getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined {\n return this.#groups.get(groupId);\n }\n\n getAccountGroups(): AccountTreeGroup[] {\n return Array.from(this.#groups.values()); // TODO: Should we avoid the copy here?\n }\n\n // NOTE: This method SHOULD BE overriden if a rule need to group things differently.\n addAccount(account: InternalAccount): MutableAccountTreeGroup {\n const id = DEFAULT_ACCOUNT_GROUP_UNIQUE_ID;\n\n // Use a single-group by default.\n let group = this.#groups.get(toAccountGroupId(this.id, id));\n if (!group) {\n // We create the account group and attach it to this wallet.\n group = new MutableAccountTreeGroup(this.messenger, this, id);\n this.#groups.set(group.id, group);\n }\n\n group.addAccount(account);\n\n return group;\n }\n\n abstract getDefaultName(): string;\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAYA,qEAGiC;AAF/B,8HAAA,qBAAqB,OAAA;AACrB,6IAAA,oCAAoC,OAAA","sourcesContent":["export type {\n AccountTreeControllerState,\n AccountTreeControllerGetStateAction,\n AccountTreeControllerActions,\n AccountTreeControllerStateChangeEvent,\n AccountTreeControllerEvents,\n AccountTreeControllerMessenger,\n AccountWalletObject,\n AccountWalletMetadata,\n AccountGroupObject,\n AccountGroupMetadata,\n} from './AccountTreeController';\nexport {\n AccountTreeController,\n getDefaultAccountTreeControllerState,\n} from './AccountTreeController';\nexport type { AccountTreeWallet } from './AccountTreeWallet';\nexport type { AccountTreeGroup } from './AccountTreeGroup';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AccountTreeControllerState, AccountTreeControllerGetStateAction, AccountTreeControllerActions,
|
|
1
|
+
export type { AccountTreeControllerState, AccountTreeControllerGetStateAction, AccountTreeControllerActions, AccountTreeControllerStateChangeEvent, AccountTreeControllerEvents, AccountTreeControllerMessenger, AccountWalletObject, AccountWalletMetadata, AccountGroupObject, AccountGroupMetadata, } from "./AccountTreeController.cjs";
|
|
2
2
|
export { AccountTreeController, getDefaultAccountTreeControllerState, } from "./AccountTreeController.cjs";
|
|
3
3
|
export type { AccountTreeWallet } from "./AccountTreeWallet.cjs";
|
|
4
4
|
export type { AccountTreeGroup } from "./AccountTreeGroup.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,qCAAqC,EACrC,2BAA2B,EAC3B,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,GACrB,oCAAgC;AACjC,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,oCAAgC;AACjC,YAAY,EAAE,iBAAiB,EAAE,gCAA4B;AAC7D,YAAY,EAAE,gBAAgB,EAAE,+BAA2B"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { AccountTreeControllerState, AccountTreeControllerGetStateAction, AccountTreeControllerActions,
|
|
1
|
+
export type { AccountTreeControllerState, AccountTreeControllerGetStateAction, AccountTreeControllerActions, AccountTreeControllerStateChangeEvent, AccountTreeControllerEvents, AccountTreeControllerMessenger, AccountWalletObject, AccountWalletMetadata, AccountGroupObject, AccountGroupMetadata, } from "./AccountTreeController.mjs";
|
|
2
2
|
export { AccountTreeController, getDefaultAccountTreeControllerState, } from "./AccountTreeController.mjs";
|
|
3
3
|
export type { AccountTreeWallet } from "./AccountTreeWallet.mjs";
|
|
4
4
|
export type { AccountTreeGroup } from "./AccountTreeGroup.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,qCAAqC,EACrC,2BAA2B,EAC3B,8BAA8B,EAC9B,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,GACrB,oCAAgC;AACjC,OAAO,EACL,qBAAqB,EACrB,oCAAoC,GACrC,oCAAgC;AACjC,YAAY,EAAE,iBAAiB,EAAE,gCAA4B;AAC7D,YAAY,EAAE,gBAAgB,EAAE,+BAA2B"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,qBAAqB,EACrB,oCAAoC,EACrC,oCAAgC","sourcesContent":["export type {\n AccountTreeControllerState,\n AccountTreeControllerGetStateAction,\n AccountTreeControllerActions,\n AccountTreeControllerStateChangeEvent,\n AccountTreeControllerEvents,\n AccountTreeControllerMessenger,\n AccountWalletObject,\n AccountWalletMetadata,\n AccountGroupObject,\n AccountGroupMetadata,\n} from './AccountTreeController';\nexport {\n AccountTreeController,\n getDefaultAccountTreeControllerState,\n} from './AccountTreeController';\nexport type { AccountTreeWallet } from './AccountTreeWallet';\nexport type { AccountTreeGroup } from './AccountTreeGroup';\n"]}
|