@metamask-previews/account-tree-controller 0.6.0-preview-bd86fa14 → 0.7.0-preview-3f5f144a
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/AccountTreeController.cjs +195 -41
- package/dist/AccountTreeController.cjs.map +1 -1
- package/dist/AccountTreeController.d.cts +31 -40
- package/dist/AccountTreeController.d.cts.map +1 -1
- package/dist/AccountTreeController.d.mts +31 -40
- package/dist/AccountTreeController.d.mts.map +1 -1
- package/dist/AccountTreeController.mjs +193 -39
- package/dist/AccountTreeController.mjs.map +1 -1
- package/dist/AccountTreeGroup.cjs +44 -35
- package/dist/AccountTreeGroup.cjs.map +1 -1
- package/dist/AccountTreeGroup.d.cts +15 -22
- package/dist/AccountTreeGroup.d.cts.map +1 -1
- package/dist/AccountTreeGroup.d.mts +15 -22
- package/dist/AccountTreeGroup.d.mts.map +1 -1
- package/dist/AccountTreeGroup.mjs +42 -33
- package/dist/AccountTreeGroup.mjs.map +1 -1
- package/dist/AccountTreeRule.cjs +37 -0
- package/dist/AccountTreeRule.cjs.map +1 -0
- package/dist/AccountTreeRule.d.cts +53 -0
- package/dist/AccountTreeRule.d.cts.map +1 -0
- package/dist/AccountTreeRule.d.mts +53 -0
- package/dist/AccountTreeRule.d.mts.map +1 -0
- package/dist/AccountTreeRule.mjs +33 -0
- package/dist/AccountTreeRule.mjs.map +1 -0
- package/dist/AccountTreeWallet.cjs +53 -26
- package/dist/AccountTreeWallet.cjs.map +1 -1
- package/dist/AccountTreeWallet.d.cts +26 -21
- package/dist/AccountTreeWallet.d.cts.map +1 -1
- package/dist/AccountTreeWallet.d.mts +26 -21
- package/dist/AccountTreeWallet.d.mts.map +1 -1
- package/dist/AccountTreeWallet.mjs +52 -25
- 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/entropy.cjs +68 -0
- package/dist/rules/entropy.cjs.map +1 -0
- package/dist/rules/entropy.d.cts +13 -0
- package/dist/rules/entropy.d.cts.map +1 -0
- package/dist/rules/entropy.d.mts +13 -0
- package/dist/rules/entropy.d.mts.map +1 -0
- package/dist/rules/entropy.mjs +64 -0
- package/dist/rules/entropy.mjs.map +1 -0
- package/dist/rules/keyring.cjs +86 -0
- package/dist/rules/keyring.cjs.map +1 -0
- package/dist/rules/keyring.d.cts +21 -0
- package/dist/rules/keyring.d.cts.map +1 -0
- package/dist/rules/keyring.d.mts +21 -0
- package/dist/rules/keyring.d.mts.map +1 -0
- package/dist/rules/keyring.mjs +81 -0
- package/dist/rules/keyring.mjs.map +1 -0
- package/dist/rules/snap.cjs +58 -0
- package/dist/rules/snap.cjs.map +1 -0
- package/dist/rules/snap.d.cts +22 -0
- package/dist/rules/snap.d.cts.map +1 -0
- package/dist/rules/snap.d.mts +22 -0
- package/dist/rules/snap.d.mts.map +1 -0
- package/dist/rules/snap.mjs +54 -0
- package/dist/rules/snap.mjs.map +1 -0
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +83 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +83 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +4 -4
- package/dist/rules/EntropySourceWalletRule.cjs +0 -100
- package/dist/rules/EntropySourceWalletRule.cjs.map +0 -1
- package/dist/rules/EntropySourceWalletRule.d.cts +0 -19
- package/dist/rules/EntropySourceWalletRule.d.cts.map +0 -1
- package/dist/rules/EntropySourceWalletRule.d.mts +0 -19
- package/dist/rules/EntropySourceWalletRule.d.mts.map +0 -1
- package/dist/rules/EntropySourceWalletRule.mjs +0 -95
- package/dist/rules/EntropySourceWalletRule.mjs.map +0 -1
- package/dist/rules/KeyringWalletRule.cjs +0 -99
- package/dist/rules/KeyringWalletRule.cjs.map +0 -1
- package/dist/rules/KeyringWalletRule.d.cts +0 -18
- package/dist/rules/KeyringWalletRule.d.cts.map +0 -1
- package/dist/rules/KeyringWalletRule.d.mts +0 -18
- package/dist/rules/KeyringWalletRule.d.mts.map +0 -1
- package/dist/rules/KeyringWalletRule.mjs +0 -94
- package/dist/rules/KeyringWalletRule.mjs.map +0 -1
- package/dist/rules/SnapWalletRule.cjs +0 -70
- package/dist/rules/SnapWalletRule.cjs.map +0 -1
- package/dist/rules/SnapWalletRule.d.cts +0 -10
- package/dist/rules/SnapWalletRule.d.cts.map +0 -1
- package/dist/rules/SnapWalletRule.d.mts +0 -10
- package/dist/rules/SnapWalletRule.d.mts.map +0 -1
- package/dist/rules/SnapWalletRule.mjs +0 -66
- package/dist/rules/SnapWalletRule.mjs.map +0 -1
- package/dist/rules/WalletRule.cjs +0 -13
- package/dist/rules/WalletRule.cjs.map +0 -1
- package/dist/rules/WalletRule.d.cts +0 -37
- package/dist/rules/WalletRule.d.cts.map +0 -1
- package/dist/rules/WalletRule.d.mts +0 -37
- package/dist/rules/WalletRule.d.mts.map +0 -1
- package/dist/rules/WalletRule.mjs +0 -9
- package/dist/rules/WalletRule.mjs.map +0 -1
- package/dist/rules/index.cjs +0 -21
- package/dist/rules/index.cjs.map +0 -1
- package/dist/rules/index.d.cts +0 -5
- package/dist/rules/index.d.cts.map +0 -1
- package/dist/rules/index.d.mts +0 -5
- package/dist/rules/index.d.mts.map +0 -1
- package/dist/rules/index.mjs +0 -5
- package/dist/rules/index.mjs.map +0 -1
- package/dist/rules/utils.cjs +0 -15
- package/dist/rules/utils.cjs.map +0 -1
- package/dist/rules/utils.d.cts +0 -11
- package/dist/rules/utils.d.cts.map +0 -1
- package/dist/rules/utils.d.mts +0 -11
- package/dist/rules/utils.d.mts.map +0 -1
- package/dist/rules/utils.mjs +0 -11
- package/dist/rules/utils.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeGroup.d.mts","sourceRoot":"","sources":["../src/AccountTreeGroup.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"AccountTreeGroup.d.mts","sourceRoot":"","sources":["../src/AccountTreeGroup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,8BAA8B;AAC/E,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,gCAA4B;AAC7D,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC/B,oBAAgB;AAEjB,eAAO,MAAM,0BAA0B,EAAE,MAAkB,CAAC;AAE5D;;GAEG;AACH,qBAAa,gBAAiB,YAAW,YAAY,CAAC,eAAe,CAAC;;gBAOxD,EACV,SAAS,EACT,MAAM,EACN,KAAK,GACN,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,MAAM,EAAE,iBAAiB,CAAC;QAC1B,KAAK,EAAE,kBAAkB,CAAC;KAC3B;IAMD,IAAI,EAAE,IAAI,cAAc,CAEvB;IAED,IAAI,MAAM,IAAI,iBAAiB,CAE9B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,aAAa,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;IAIxC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAanD,WAAW,IAAI,eAAe,EAAE;IAIhC,cAAc,IAAI,eAAe;CAYlC"}
|
|
@@ -9,46 +9,55 @@ 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 { toAccountGroupId } from "@metamask/account-api";
|
|
12
|
+
var _AccountTreeGroup_instances, _AccountTreeGroup_messenger, _AccountTreeGroup_group, _AccountTreeGroup_wallet, _AccountTreeGroup_getAccount;
|
|
14
13
|
export const DEFAULT_ACCOUNT_GROUP_NAME = 'Default';
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this
|
|
22
|
-
this
|
|
23
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Account group coming from the {@link AccountTreeController}.
|
|
16
|
+
*/
|
|
17
|
+
export class AccountTreeGroup {
|
|
18
|
+
constructor({ messenger, wallet, group, }) {
|
|
19
|
+
_AccountTreeGroup_instances.add(this);
|
|
20
|
+
_AccountTreeGroup_messenger.set(this, void 0);
|
|
21
|
+
_AccountTreeGroup_group.set(this, void 0);
|
|
22
|
+
_AccountTreeGroup_wallet.set(this, void 0);
|
|
23
|
+
__classPrivateFieldSet(this, _AccountTreeGroup_messenger, messenger, "f");
|
|
24
|
+
__classPrivateFieldSet(this, _AccountTreeGroup_group, group, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _AccountTreeGroup_wallet, wallet, "f");
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
+
get id() {
|
|
28
|
+
return __classPrivateFieldGet(this, _AccountTreeGroup_group, "f").id;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
console.warn(`! Unable to get account: "${id}"`);
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
accounts.push(account);
|
|
40
|
-
}
|
|
41
|
-
return accounts;
|
|
30
|
+
get wallet() {
|
|
31
|
+
return __classPrivateFieldGet(this, _AccountTreeGroup_wallet, "f");
|
|
32
|
+
}
|
|
33
|
+
get name() {
|
|
34
|
+
return __classPrivateFieldGet(this, _AccountTreeGroup_group, "f").metadata.name;
|
|
35
|
+
}
|
|
36
|
+
getAccountIds() {
|
|
37
|
+
return __classPrivateFieldGet(this, _AccountTreeGroup_group, "f").accounts;
|
|
42
38
|
}
|
|
43
39
|
getAccount(id) {
|
|
44
|
-
return this.
|
|
40
|
+
return __classPrivateFieldGet(this, _AccountTreeGroup_messenger, "f").call('AccountsController:getAccount', id);
|
|
45
41
|
}
|
|
46
|
-
|
|
47
|
-
__classPrivateFieldGet(this,
|
|
42
|
+
getAccounts() {
|
|
43
|
+
return __classPrivateFieldGet(this, _AccountTreeGroup_group, "f").accounts.map((id) => __classPrivateFieldGet(this, _AccountTreeGroup_instances, "m", _AccountTreeGroup_getAccount).call(this, id));
|
|
48
44
|
}
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
getOnlyAccount() {
|
|
46
|
+
const accountIds = this.getAccountIds();
|
|
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]);
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
|
-
|
|
56
|
+
_AccountTreeGroup_messenger = new WeakMap(), _AccountTreeGroup_group = new WeakMap(), _AccountTreeGroup_wallet = new WeakMap(), _AccountTreeGroup_instances = new WeakSet(), _AccountTreeGroup_getAccount = function _AccountTreeGroup_getAccount(id) {
|
|
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
|
+
};
|
|
54
63
|
//# 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":";;;;;;;;;;;;AASA,MAAM,CAAC,MAAM,0BAA0B,GAAW,SAAS,CAAC;AAE5D;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAO3B,YAAY,EACV,SAAS,EACT,MAAM,EACN,KAAK,GAKN;;QAdQ,8CAA2C;QAE3C,0CAA2B;QAE3B,2CAA2B;QAWlC,uBAAA,IAAI,+BAAc,SAAS,MAAA,CAAC;QAC5B,uBAAA,IAAI,2BAAU,KAAK,MAAA,CAAC;QACpB,uBAAA,IAAI,4BAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,uBAAA,IAAI,+BAAO,CAAC,EAAE,CAAC;IACxB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,uBAAA,IAAI,gCAAQ,CAAC;IACtB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,+BAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;IACnC,CAAC;IAED,aAAa;QACX,OAAO,uBAAA,IAAI,+BAAO,CAAC,QAAQ,CAAC;IAC9B,CAAC;IAED,UAAU,CAAC,EAAU;QACnB,OAAO,uBAAA,IAAI,mCAAW,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAC;IACnE,CAAC;IAWD,WAAW;QACT,OAAO,uBAAA,IAAI,+BAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,uBAAA,IAAI,iEAAY,MAAhB,IAAI,EAAa,EAAE,CAAC,CAAC,CAAC;IAChE,CAAC;IAED,cAAc;QACZ,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAExC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;QACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,OAAO,uBAAA,IAAI,iEAAY,MAAhB,IAAI,EAAa,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;kPAzBa,EAAU;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAEpC,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { type AccountGroup, type AccountGroupId } from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountTreeWallet } from './AccountTreeWallet';\nimport type {\n AccountGroupObject,\n AccountTreeControllerMessenger,\n} from './types';\n\nexport const DEFAULT_ACCOUNT_GROUP_NAME: string = 'Default';\n\n/**\n * Account group coming from the {@link AccountTreeController}.\n */\nexport class AccountTreeGroup implements AccountGroup<InternalAccount> {\n readonly #messenger: AccountTreeControllerMessenger;\n\n readonly #group: AccountGroupObject;\n\n readonly #wallet: AccountTreeWallet;\n\n constructor({\n messenger,\n wallet,\n group,\n }: {\n messenger: AccountTreeControllerMessenger;\n wallet: AccountTreeWallet;\n group: AccountGroupObject;\n }) {\n this.#messenger = messenger;\n this.#group = group;\n this.#wallet = wallet;\n }\n\n get id(): AccountGroupId {\n return this.#group.id;\n }\n\n get wallet(): AccountTreeWallet {\n return this.#wallet;\n }\n\n get name(): string {\n return this.#group.metadata.name;\n }\n\n getAccountIds(): InternalAccount['id'][] {\n return this.#group.accounts;\n }\n\n getAccount(id: string): InternalAccount | undefined {\n return this.#messenger.call('AccountsController:getAccount', id);\n }\n\n #getAccount(id: string): InternalAccount {\n const account = this.getAccount(id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccounts(): InternalAccount[] {\n return this.#group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccount(): InternalAccount {\n const accountIds = this.getAccountIds();\n\n if (accountIds.length === 0) {\n throw new Error('Group contains no account');\n }\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n return this.#getAccount(accountIds[0]);\n }\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
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");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _AccountTreeRule_instances, _AccountTreeRule_getAccount;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.AccountTreeRule = void 0;
|
|
10
|
+
class AccountTreeRule {
|
|
11
|
+
constructor(messenger) {
|
|
12
|
+
_AccountTreeRule_instances.add(this);
|
|
13
|
+
this.messenger = messenger;
|
|
14
|
+
}
|
|
15
|
+
getAccountsFrom(group) {
|
|
16
|
+
return group.accounts.map((id) => __classPrivateFieldGet(this, _AccountTreeRule_instances, "m", _AccountTreeRule_getAccount).call(this, id));
|
|
17
|
+
}
|
|
18
|
+
getOnlyAccountFrom(group) {
|
|
19
|
+
const accountIds = group.accounts;
|
|
20
|
+
if (accountIds.length === 0) {
|
|
21
|
+
throw new Error('Group contains no account');
|
|
22
|
+
}
|
|
23
|
+
if (accountIds.length > 1) {
|
|
24
|
+
throw new Error('Group contains more than 1 account');
|
|
25
|
+
}
|
|
26
|
+
return __classPrivateFieldGet(this, _AccountTreeRule_instances, "m", _AccountTreeRule_getAccount).call(this, accountIds[0]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.AccountTreeRule = AccountTreeRule;
|
|
30
|
+
_AccountTreeRule_instances = new WeakSet(), _AccountTreeRule_getAccount = function _AccountTreeRule_getAccount(id) {
|
|
31
|
+
const account = this.messenger.call('AccountsController:getAccount', id);
|
|
32
|
+
if (!account) {
|
|
33
|
+
throw new Error(`Unable to get account with ID: "${id}"`);
|
|
34
|
+
}
|
|
35
|
+
return account;
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=AccountTreeRule.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountTreeRule.cjs","sourceRoot":"","sources":["../src/AccountTreeRule.ts"],"names":[],"mappings":";;;;;;;;;AAqBA,MAAsB,eAAe;IAKnC,YAAY,SAAyC;;QACnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IA6CD,eAAe,CAAC,KAAyB;QACvC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,uBAAA,IAAI,+DAAY,MAAhB,IAAI,EAAa,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,kBAAkB,CAAC,KAAyB;QAC1C,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;QAElC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;QACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,OAAO,uBAAA,IAAI,+DAAY,MAAhB,IAAI,EAAa,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AApED,0CAoEC;+GAzBa,EAAU;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAC;IAEzE,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { AccountWalletCategory } from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountTreeGroup, AccountTreeWallet } from '.';\nimport type {\n AccountGroupObject,\n AccountTreeControllerMessenger,\n AccountWalletCategoryMetadata,\n AccountWalletObject,\n} from './types';\n\nexport type AccountTreeRuleResult = {\n wallet: {\n id: AccountTreeWallet['id'];\n metadata: AccountWalletCategoryMetadata;\n };\n group: {\n id: AccountTreeGroup['id'];\n };\n};\n\nexport abstract class AccountTreeRule {\n abstract readonly category: AccountWalletCategory;\n\n protected readonly messenger: AccountTreeControllerMessenger;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Applies the rule and check if the account matches.\n *\n * If the account matches, then the rule will return a {@link AccountTreeRuleResult} which means\n * this account needs to be grouped within a wallet associated with this rule.\n *\n * If a wallet already exists for this account (based on {@link AccountTreeRuleResult}) then\n * the account will be added to that wallet instance into its proper group (different for\n * every wallets).\n *\n * @param account - The account to match.\n * @returns A {@link AccountTreeRuleResult} if this account is part of that rule/wallet, returns\n * `undefined` otherwise.\n */\n abstract match(account: InternalAccount): AccountTreeRuleResult | undefined;\n\n /**\n * Gets default name for a wallet.\n *\n * @param wallet - Wallet associated to this rule.\n * @param context - Rule context.\n * @returns The default name for that wallet.\n */\n abstract getDefaultAccountWalletName(wallet: AccountWalletObject): string;\n\n /**\n * Gets default name for a group.\n *\n * @param group - Group associated to this rule.\n * @param context - Rule context.\n * @returns The default name for that group.\n */\n abstract getDefaultAccountGroupName(group: AccountGroupObject): string;\n\n #getAccount(id: string): InternalAccount {\n const account = this.messenger.call('AccountsController:getAccount', id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccountsFrom(group: AccountGroupObject): InternalAccount[] {\n return group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccountFrom(group: AccountGroupObject): InternalAccount {\n const accountIds = group.accounts;\n\n if (accountIds.length === 0) {\n throw new Error('Group contains no account');\n }\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n return this.#getAccount(accountIds[0]);\n }\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AccountWalletCategory } from "@metamask/account-api";
|
|
2
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
|
+
import type { AccountTreeGroup, AccountTreeWallet } from "./index.cjs";
|
|
4
|
+
import type { AccountGroupObject, AccountTreeControllerMessenger, AccountWalletCategoryMetadata, AccountWalletObject } from "./types.cjs";
|
|
5
|
+
export type AccountTreeRuleResult = {
|
|
6
|
+
wallet: {
|
|
7
|
+
id: AccountTreeWallet['id'];
|
|
8
|
+
metadata: AccountWalletCategoryMetadata;
|
|
9
|
+
};
|
|
10
|
+
group: {
|
|
11
|
+
id: AccountTreeGroup['id'];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare abstract class AccountTreeRule {
|
|
15
|
+
#private;
|
|
16
|
+
abstract readonly category: AccountWalletCategory;
|
|
17
|
+
protected readonly messenger: AccountTreeControllerMessenger;
|
|
18
|
+
constructor(messenger: AccountTreeControllerMessenger);
|
|
19
|
+
/**
|
|
20
|
+
* Applies the rule and check if the account matches.
|
|
21
|
+
*
|
|
22
|
+
* If the account matches, then the rule will return a {@link AccountTreeRuleResult} which means
|
|
23
|
+
* this account needs to be grouped within a wallet associated with this rule.
|
|
24
|
+
*
|
|
25
|
+
* If a wallet already exists for this account (based on {@link AccountTreeRuleResult}) then
|
|
26
|
+
* the account will be added to that wallet instance into its proper group (different for
|
|
27
|
+
* every wallets).
|
|
28
|
+
*
|
|
29
|
+
* @param account - The account to match.
|
|
30
|
+
* @returns A {@link AccountTreeRuleResult} if this account is part of that rule/wallet, returns
|
|
31
|
+
* `undefined` otherwise.
|
|
32
|
+
*/
|
|
33
|
+
abstract match(account: InternalAccount): AccountTreeRuleResult | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Gets default name for a wallet.
|
|
36
|
+
*
|
|
37
|
+
* @param wallet - Wallet associated to this rule.
|
|
38
|
+
* @param context - Rule context.
|
|
39
|
+
* @returns The default name for that wallet.
|
|
40
|
+
*/
|
|
41
|
+
abstract getDefaultAccountWalletName(wallet: AccountWalletObject): string;
|
|
42
|
+
/**
|
|
43
|
+
* Gets default name for a group.
|
|
44
|
+
*
|
|
45
|
+
* @param group - Group associated to this rule.
|
|
46
|
+
* @param context - Rule context.
|
|
47
|
+
* @returns The default name for that group.
|
|
48
|
+
*/
|
|
49
|
+
abstract getDefaultAccountGroupName(group: AccountGroupObject): string;
|
|
50
|
+
getAccountsFrom(group: AccountGroupObject): InternalAccount[];
|
|
51
|
+
getOnlyAccountFrom(group: AccountGroupObject): InternalAccount;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=AccountTreeRule.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountTreeRule.d.cts","sourceRoot":"","sources":["../src/AccountTreeRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,8BAA8B;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,oBAAU;AAC7D,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,6BAA6B,EAC7B,mBAAmB,EACpB,oBAAgB;AAEjB,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE;QACN,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC5B,QAAQ,EAAE,6BAA6B,CAAC;KACzC,CAAC;IACF,KAAK,EAAE;QACL,EAAE,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC;CACH,CAAC;AAEF,8BAAsB,eAAe;;IACnC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IAElD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;gBAEjD,SAAS,EAAE,8BAA8B;IAIrD;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,qBAAqB,GAAG,SAAS;IAE3E;;;;;;OAMG;IACH,QAAQ,CAAC,2BAA2B,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM;IAEzE;;;;;;OAMG;IACH,QAAQ,CAAC,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM;IAWtE,eAAe,CAAC,KAAK,EAAE,kBAAkB,GAAG,eAAe,EAAE;IAI7D,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,eAAe;CAY/D"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AccountWalletCategory } from "@metamask/account-api";
|
|
2
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
|
+
import type { AccountTreeGroup, AccountTreeWallet } from "./index.mjs";
|
|
4
|
+
import type { AccountGroupObject, AccountTreeControllerMessenger, AccountWalletCategoryMetadata, AccountWalletObject } from "./types.mjs";
|
|
5
|
+
export type AccountTreeRuleResult = {
|
|
6
|
+
wallet: {
|
|
7
|
+
id: AccountTreeWallet['id'];
|
|
8
|
+
metadata: AccountWalletCategoryMetadata;
|
|
9
|
+
};
|
|
10
|
+
group: {
|
|
11
|
+
id: AccountTreeGroup['id'];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare abstract class AccountTreeRule {
|
|
15
|
+
#private;
|
|
16
|
+
abstract readonly category: AccountWalletCategory;
|
|
17
|
+
protected readonly messenger: AccountTreeControllerMessenger;
|
|
18
|
+
constructor(messenger: AccountTreeControllerMessenger);
|
|
19
|
+
/**
|
|
20
|
+
* Applies the rule and check if the account matches.
|
|
21
|
+
*
|
|
22
|
+
* If the account matches, then the rule will return a {@link AccountTreeRuleResult} which means
|
|
23
|
+
* this account needs to be grouped within a wallet associated with this rule.
|
|
24
|
+
*
|
|
25
|
+
* If a wallet already exists for this account (based on {@link AccountTreeRuleResult}) then
|
|
26
|
+
* the account will be added to that wallet instance into its proper group (different for
|
|
27
|
+
* every wallets).
|
|
28
|
+
*
|
|
29
|
+
* @param account - The account to match.
|
|
30
|
+
* @returns A {@link AccountTreeRuleResult} if this account is part of that rule/wallet, returns
|
|
31
|
+
* `undefined` otherwise.
|
|
32
|
+
*/
|
|
33
|
+
abstract match(account: InternalAccount): AccountTreeRuleResult | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Gets default name for a wallet.
|
|
36
|
+
*
|
|
37
|
+
* @param wallet - Wallet associated to this rule.
|
|
38
|
+
* @param context - Rule context.
|
|
39
|
+
* @returns The default name for that wallet.
|
|
40
|
+
*/
|
|
41
|
+
abstract getDefaultAccountWalletName(wallet: AccountWalletObject): string;
|
|
42
|
+
/**
|
|
43
|
+
* Gets default name for a group.
|
|
44
|
+
*
|
|
45
|
+
* @param group - Group associated to this rule.
|
|
46
|
+
* @param context - Rule context.
|
|
47
|
+
* @returns The default name for that group.
|
|
48
|
+
*/
|
|
49
|
+
abstract getDefaultAccountGroupName(group: AccountGroupObject): string;
|
|
50
|
+
getAccountsFrom(group: AccountGroupObject): InternalAccount[];
|
|
51
|
+
getOnlyAccountFrom(group: AccountGroupObject): InternalAccount;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=AccountTreeRule.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountTreeRule.d.mts","sourceRoot":"","sources":["../src/AccountTreeRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,8BAA8B;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,oBAAU;AAC7D,OAAO,KAAK,EACV,kBAAkB,EAClB,8BAA8B,EAC9B,6BAA6B,EAC7B,mBAAmB,EACpB,oBAAgB;AAEjB,MAAM,MAAM,qBAAqB,GAAG;IAClC,MAAM,EAAE;QACN,EAAE,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAC5B,QAAQ,EAAE,6BAA6B,CAAC;KACzC,CAAC;IACF,KAAK,EAAE;QACL,EAAE,EAAE,gBAAgB,CAAC,IAAI,CAAC,CAAC;KAC5B,CAAC;CACH,CAAC;AAEF,8BAAsB,eAAe;;IACnC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;IAElD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;gBAEjD,SAAS,EAAE,8BAA8B;IAIrD;;;;;;;;;;;;;OAaG;IACH,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,qBAAqB,GAAG,SAAS;IAE3E;;;;;;OAMG;IACH,QAAQ,CAAC,2BAA2B,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM;IAEzE;;;;;;OAMG;IACH,QAAQ,CAAC,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM;IAWtE,eAAe,CAAC,KAAK,EAAE,kBAAkB,GAAG,eAAe,EAAE;IAI7D,kBAAkB,CAAC,KAAK,EAAE,kBAAkB,GAAG,eAAe;CAY/D"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _AccountTreeRule_instances, _AccountTreeRule_getAccount;
|
|
7
|
+
export class AccountTreeRule {
|
|
8
|
+
constructor(messenger) {
|
|
9
|
+
_AccountTreeRule_instances.add(this);
|
|
10
|
+
this.messenger = messenger;
|
|
11
|
+
}
|
|
12
|
+
getAccountsFrom(group) {
|
|
13
|
+
return group.accounts.map((id) => __classPrivateFieldGet(this, _AccountTreeRule_instances, "m", _AccountTreeRule_getAccount).call(this, id));
|
|
14
|
+
}
|
|
15
|
+
getOnlyAccountFrom(group) {
|
|
16
|
+
const accountIds = group.accounts;
|
|
17
|
+
if (accountIds.length === 0) {
|
|
18
|
+
throw new Error('Group contains no account');
|
|
19
|
+
}
|
|
20
|
+
if (accountIds.length > 1) {
|
|
21
|
+
throw new Error('Group contains more than 1 account');
|
|
22
|
+
}
|
|
23
|
+
return __classPrivateFieldGet(this, _AccountTreeRule_instances, "m", _AccountTreeRule_getAccount).call(this, accountIds[0]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
_AccountTreeRule_instances = new WeakSet(), _AccountTreeRule_getAccount = function _AccountTreeRule_getAccount(id) {
|
|
27
|
+
const account = this.messenger.call('AccountsController:getAccount', id);
|
|
28
|
+
if (!account) {
|
|
29
|
+
throw new Error(`Unable to get account with ID: "${id}"`);
|
|
30
|
+
}
|
|
31
|
+
return account;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=AccountTreeRule.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccountTreeRule.mjs","sourceRoot":"","sources":["../src/AccountTreeRule.ts"],"names":[],"mappings":";;;;;;AAqBA,MAAM,OAAgB,eAAe;IAKnC,YAAY,SAAyC;;QACnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IA6CD,eAAe,CAAC,KAAyB;QACvC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,uBAAA,IAAI,+DAAY,MAAhB,IAAI,EAAa,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,kBAAkB,CAAC,KAAyB;QAC1C,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC;QAElC,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;SAC9C;QACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;YACzB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;SACvD;QAED,OAAO,uBAAA,IAAI,+DAAY,MAAhB,IAAI,EAAa,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;+GAzBa,EAAU;IACpB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,+BAA+B,EAAE,EAAE,CAAC,CAAC;IAEzE,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;KAC3D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { AccountWalletCategory } from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type { AccountTreeGroup, AccountTreeWallet } from '.';\nimport type {\n AccountGroupObject,\n AccountTreeControllerMessenger,\n AccountWalletCategoryMetadata,\n AccountWalletObject,\n} from './types';\n\nexport type AccountTreeRuleResult = {\n wallet: {\n id: AccountTreeWallet['id'];\n metadata: AccountWalletCategoryMetadata;\n };\n group: {\n id: AccountTreeGroup['id'];\n };\n};\n\nexport abstract class AccountTreeRule {\n abstract readonly category: AccountWalletCategory;\n\n protected readonly messenger: AccountTreeControllerMessenger;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n this.messenger = messenger;\n }\n\n /**\n * Applies the rule and check if the account matches.\n *\n * If the account matches, then the rule will return a {@link AccountTreeRuleResult} which means\n * this account needs to be grouped within a wallet associated with this rule.\n *\n * If a wallet already exists for this account (based on {@link AccountTreeRuleResult}) then\n * the account will be added to that wallet instance into its proper group (different for\n * every wallets).\n *\n * @param account - The account to match.\n * @returns A {@link AccountTreeRuleResult} if this account is part of that rule/wallet, returns\n * `undefined` otherwise.\n */\n abstract match(account: InternalAccount): AccountTreeRuleResult | undefined;\n\n /**\n * Gets default name for a wallet.\n *\n * @param wallet - Wallet associated to this rule.\n * @param context - Rule context.\n * @returns The default name for that wallet.\n */\n abstract getDefaultAccountWalletName(wallet: AccountWalletObject): string;\n\n /**\n * Gets default name for a group.\n *\n * @param group - Group associated to this rule.\n * @param context - Rule context.\n * @returns The default name for that group.\n */\n abstract getDefaultAccountGroupName(group: AccountGroupObject): string;\n\n #getAccount(id: string): InternalAccount {\n const account = this.messenger.call('AccountsController:getAccount', id);\n\n if (!account) {\n throw new Error(`Unable to get account with ID: \"${id}\"`);\n }\n return account;\n }\n\n getAccountsFrom(group: AccountGroupObject): InternalAccount[] {\n return group.accounts.map((id) => this.#getAccount(id));\n }\n\n getOnlyAccountFrom(group: AccountGroupObject): InternalAccount {\n const accountIds = group.accounts;\n\n if (accountIds.length === 0) {\n throw new Error('Group contains no account');\n }\n if (accountIds.length > 1) {\n throw new Error('Group contains more than 1 account');\n }\n\n return this.#getAccount(accountIds[0]);\n }\n}\n"]}
|
|
@@ -10,41 +10,68 @@ 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 _AccountTreeWallet_wallet;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
16
|
-
const account_api_1 = require("@metamask/account-api");
|
|
15
|
+
exports.AccountTreeWallet = void 0;
|
|
17
16
|
const AccountTreeGroup_1 = require("./AccountTreeGroup.cjs");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.category = category;
|
|
17
|
+
/**
|
|
18
|
+
* Account wallet coming from the {@link AccountTreeController}.
|
|
19
|
+
*/
|
|
20
|
+
class AccountTreeWallet {
|
|
21
|
+
constructor({ messenger, wallet, }) {
|
|
22
|
+
_AccountTreeWallet_wallet.set(this, void 0);
|
|
25
23
|
this.messenger = messenger;
|
|
26
|
-
__classPrivateFieldSet(this,
|
|
24
|
+
__classPrivateFieldSet(this, _AccountTreeWallet_wallet, wallet, "f");
|
|
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
|
+
}
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
return __classPrivateFieldGet(this,
|
|
34
|
+
get id() {
|
|
35
|
+
return __classPrivateFieldGet(this, _AccountTreeWallet_wallet, "f").id;
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
return
|
|
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;
|
|
33
42
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
getAccountGroup(groupId) {
|
|
50
|
+
return this.groups.get(groupId);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets account tree group for a given ID.
|
|
54
|
+
*
|
|
55
|
+
* @param groupId - Group ID.
|
|
56
|
+
* @throws If the account group is not found.
|
|
57
|
+
* @returns Account tree group.
|
|
58
|
+
*/
|
|
59
|
+
getAccountGroupOrThrow(groupId) {
|
|
60
|
+
const group = this.getAccountGroup(groupId);
|
|
39
61
|
if (!group) {
|
|
40
|
-
|
|
41
|
-
group = new AccountTreeGroup_1.MutableAccountTreeGroup(this.messenger, this, id);
|
|
42
|
-
__classPrivateFieldGet(this, _MutableAccountTreeWallet_groups, "f").set(group.id, group);
|
|
62
|
+
throw new Error('Unable to get account group');
|
|
43
63
|
}
|
|
44
|
-
group.addAccount(account);
|
|
45
64
|
return group;
|
|
46
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets all account tree groups.
|
|
68
|
+
*
|
|
69
|
+
* @returns Account tree groups.
|
|
70
|
+
*/
|
|
71
|
+
getAccountGroups() {
|
|
72
|
+
return Array.from(this.groups.values());
|
|
73
|
+
}
|
|
47
74
|
}
|
|
48
|
-
exports.
|
|
49
|
-
|
|
75
|
+
exports.AccountTreeWallet = AccountTreeWallet;
|
|
76
|
+
_AccountTreeWallet_wallet = new WeakMap();
|
|
50
77
|
//# 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":";;;;;;;;;;;;;;;AAOA,6DAAsD;AAItD;;GAEG;AACH,MAAa,iBAAiB;IAO5B,YAAY,EACV,SAAS,EACT,MAAM,GAIP;QAZQ,4CAA6B;QAapC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,uBAAA,IAAI,6BAAW,MAAM,MAAA,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QAExB,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,uBAAA,IAAI,iCAAQ,CAAC,MAAM,CAAC,EAAE;YAClE,IAAI,CAAC,MAAM,CAAC,GAAG,CACb,OAAyB,EACzB,IAAI,mCAAgB,CAAC;gBACnB,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,MAAM,EAAE,IAAI;gBACZ,KAAK;aACN,CAAC,CACH,CAAC;SACH;IACH,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,uBAAA,IAAI,iCAAQ,CAAC,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,uBAAA,IAAI,iCAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,iCAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC;IACpC,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,OAAuB;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;OAMG;IACH,sBAAsB,CAAC,OAAuB;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,EAAE;YACV,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;SAChD;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;OAIG;IACH,gBAAgB;QACd,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF;AA5ED,8CA4EC","sourcesContent":["import type {\n AccountWalletCategory,\n AccountWalletId,\n} from '@metamask/account-api';\nimport { type AccountGroupId, type AccountWallet } from '@metamask/account-api';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { AccountTreeGroup } from './AccountTreeGroup';\nimport type { AccountWalletObject } from './types';\nimport { type AccountTreeControllerMessenger } from './types';\n\n/**\n * Account wallet coming from the {@link AccountTreeController}.\n */\nexport class AccountTreeWallet implements AccountWallet<InternalAccount> {\n readonly #wallet: AccountWalletObject;\n\n protected messenger: AccountTreeControllerMessenger;\n\n protected groups: Map<AccountGroupId, AccountTreeGroup>;\n\n constructor({\n messenger,\n wallet,\n }: {\n messenger: AccountTreeControllerMessenger;\n wallet: AccountWalletObject;\n }) {\n this.messenger = messenger;\n this.#wallet = wallet;\n this.groups = new Map();\n\n for (const [groupId, group] of Object.entries(this.#wallet.groups)) {\n this.groups.set(\n groupId as AccountGroupId,\n new AccountTreeGroup({\n messenger: this.messenger,\n wallet: this,\n group,\n }),\n );\n }\n }\n\n get id(): AccountWalletId {\n return this.#wallet.id;\n }\n\n get category(): AccountWalletCategory {\n return this.#wallet.metadata.type;\n }\n\n get name(): string {\n return this.#wallet.metadata.name;\n }\n\n /**\n * Gets account tree group for a given ID.\n *\n * @param groupId - Group ID.\n * @returns Account tree group, or undefined if not found.\n */\n getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined {\n return this.groups.get(groupId);\n }\n\n /**\n * Gets account tree group for a given ID.\n *\n * @param groupId - Group ID.\n * @throws If the account group is not found.\n * @returns Account tree group.\n */\n getAccountGroupOrThrow(groupId: AccountGroupId): AccountTreeGroup {\n const group = this.getAccountGroup(groupId);\n if (!group) {\n throw new Error('Unable to get account group');\n }\n\n return group;\n }\n\n /**\n * Gets all account tree groups.\n *\n * @returns Account tree groups.\n */\n getAccountGroups(): AccountTreeGroup[] {\n return Array.from(this.groups.values());\n }\n}\n"]}
|
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AccountWalletCategory, AccountWalletId } from "@metamask/account-api";
|
|
2
|
+
import { type AccountGroupId, type AccountWallet } from "@metamask/account-api";
|
|
2
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
4
|
+
import { AccountTreeGroup } from "./AccountTreeGroup.cjs";
|
|
5
|
+
import type { AccountWalletObject } from "./types.cjs";
|
|
6
|
+
import { type AccountTreeControllerMessenger } from "./types.cjs";
|
|
6
7
|
/**
|
|
7
8
|
* Account wallet coming from the {@link AccountTreeController}.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export declare class AccountTreeWallet implements AccountWallet<InternalAccount> {
|
|
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;
|
|
10
21
|
/**
|
|
11
22
|
* Gets account tree group for a given ID.
|
|
12
23
|
*
|
|
13
|
-
* @
|
|
24
|
+
* @param groupId - Group ID.
|
|
25
|
+
* @returns Account tree group, or undefined if not found.
|
|
14
26
|
*/
|
|
15
27
|
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
16
28
|
/**
|
|
17
|
-
* Gets
|
|
29
|
+
* Gets account tree group for a given ID.
|
|
18
30
|
*
|
|
19
|
-
* @
|
|
31
|
+
* @param groupId - Group ID.
|
|
32
|
+
* @throws If the account group is not found.
|
|
33
|
+
* @returns Account tree group.
|
|
20
34
|
*/
|
|
21
|
-
|
|
35
|
+
getAccountGroupOrThrow(groupId: AccountGroupId): AccountTreeGroup;
|
|
22
36
|
/**
|
|
23
|
-
* Gets
|
|
37
|
+
* Gets all account tree groups.
|
|
38
|
+
*
|
|
39
|
+
* @returns Account tree groups.
|
|
24
40
|
*/
|
|
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
41
|
getAccountGroups(): AccountTreeGroup[];
|
|
35
|
-
addAccount(account: InternalAccount): MutableAccountTreeGroup;
|
|
36
|
-
abstract getDefaultName(): string;
|
|
37
42
|
}
|
|
38
43
|
//# sourceMappingURL=AccountTreeWallet.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeWallet.d.cts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"AccountTreeWallet.d.cts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAChB,8BAA8B;AAC/B,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AACnD,OAAO,EAAE,KAAK,8BAA8B,EAAE,oBAAgB;AAE9D;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa,CAAC,eAAe,CAAC;;IAGtE,SAAS,CAAC,SAAS,EAAE,8BAA8B,CAAC;IAEpD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;gBAE5C,EACV,SAAS,EACT,MAAM,GACP,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,MAAM,EAAE,mBAAmB,CAAC;KAC7B;IAiBD,IAAI,EAAE,IAAI,eAAe,CAExB;IAED,IAAI,QAAQ,IAAI,qBAAqB,CAEpC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB,GAAG,SAAS;IAItE;;;;;;OAMG;IACH,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB;IASjE;;;;OAIG;IACH,gBAAgB,IAAI,gBAAgB,EAAE;CAGvC"}
|
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { AccountWalletCategory, AccountWalletId } from "@metamask/account-api";
|
|
2
|
+
import { type AccountGroupId, type AccountWallet } from "@metamask/account-api";
|
|
2
3
|
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
4
|
+
import { AccountTreeGroup } from "./AccountTreeGroup.mjs";
|
|
5
|
+
import type { AccountWalletObject } from "./types.mjs";
|
|
6
|
+
import { type AccountTreeControllerMessenger } from "./types.mjs";
|
|
6
7
|
/**
|
|
7
8
|
* Account wallet coming from the {@link AccountTreeController}.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
+
export declare class AccountTreeWallet implements AccountWallet<InternalAccount> {
|
|
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;
|
|
10
21
|
/**
|
|
11
22
|
* Gets account tree group for a given ID.
|
|
12
23
|
*
|
|
13
|
-
* @
|
|
24
|
+
* @param groupId - Group ID.
|
|
25
|
+
* @returns Account tree group, or undefined if not found.
|
|
14
26
|
*/
|
|
15
27
|
getAccountGroup(groupId: AccountGroupId): AccountTreeGroup | undefined;
|
|
16
28
|
/**
|
|
17
|
-
* Gets
|
|
29
|
+
* Gets account tree group for a given ID.
|
|
18
30
|
*
|
|
19
|
-
* @
|
|
31
|
+
* @param groupId - Group ID.
|
|
32
|
+
* @throws If the account group is not found.
|
|
33
|
+
* @returns Account tree group.
|
|
20
34
|
*/
|
|
21
|
-
|
|
35
|
+
getAccountGroupOrThrow(groupId: AccountGroupId): AccountTreeGroup;
|
|
22
36
|
/**
|
|
23
|
-
* Gets
|
|
37
|
+
* Gets all account tree groups.
|
|
38
|
+
*
|
|
39
|
+
* @returns Account tree groups.
|
|
24
40
|
*/
|
|
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
41
|
getAccountGroups(): AccountTreeGroup[];
|
|
35
|
-
addAccount(account: InternalAccount): MutableAccountTreeGroup;
|
|
36
|
-
abstract getDefaultName(): string;
|
|
37
42
|
}
|
|
38
43
|
//# sourceMappingURL=AccountTreeWallet.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountTreeWallet.d.mts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"AccountTreeWallet.d.mts","sourceRoot":"","sources":["../src/AccountTreeWallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EAChB,8BAA8B;AAC/B,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAgB;AACnD,OAAO,EAAE,KAAK,8BAA8B,EAAE,oBAAgB;AAE9D;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa,CAAC,eAAe,CAAC;;IAGtE,SAAS,CAAC,SAAS,EAAE,8BAA8B,CAAC;IAEpD,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC;gBAE5C,EACV,SAAS,EACT,MAAM,GACP,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,MAAM,EAAE,mBAAmB,CAAC;KAC7B;IAiBD,IAAI,EAAE,IAAI,eAAe,CAExB;IAED,IAAI,QAAQ,IAAI,qBAAqB,CAEpC;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;OAKG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB,GAAG,SAAS;IAItE;;;;;;OAMG;IACH,sBAAsB,CAAC,OAAO,EAAE,cAAc,GAAG,gBAAgB;IASjE;;;;OAIG;IACH,gBAAgB,IAAI,gBAAgB,EAAE;CAGvC"}
|