@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
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { WalletRuleMatch } from "./WalletRule.cjs";
|
|
3
|
+
import { BaseWalletRule } from "./WalletRule.cjs";
|
|
4
|
+
import type { AccountTreeControllerMessenger } from "../AccountTreeController.cjs";
|
|
5
|
+
export declare class SnapWalletRule extends BaseWalletRule {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(messenger: AccountTreeControllerMessenger);
|
|
8
|
+
match(account: InternalAccount): WalletRuleMatch | undefined;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=SnapWalletRule.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapWalletRule.d.cts","sourceRoot":"","sources":["../../src/rules/SnapWalletRule.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAKtE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AACpD,OAAO,EAAE,cAAc,EAAE,yBAAqB;AAC9C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AA2B/E,qBAAa,cAAe,SAAQ,cAAc;;gBAGpC,SAAS,EAAE,8BAA8B;IAMrD,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;CA2B7D"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { WalletRuleMatch } from "./WalletRule.mjs";
|
|
3
|
+
import { BaseWalletRule } from "./WalletRule.mjs";
|
|
4
|
+
import type { AccountTreeControllerMessenger } from "../AccountTreeController.mjs";
|
|
5
|
+
export declare class SnapWalletRule extends BaseWalletRule {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(messenger: AccountTreeControllerMessenger);
|
|
8
|
+
match(account: InternalAccount): WalletRuleMatch | undefined;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=SnapWalletRule.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapWalletRule.d.mts","sourceRoot":"","sources":["../../src/rules/SnapWalletRule.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAKtE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AACpD,OAAO,EAAE,cAAc,EAAE,yBAAqB;AAC9C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AA2B/E,qBAAa,cAAe,SAAQ,cAAc;;gBAGpC,SAAS,EAAE,8BAA8B;IAMrD,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;CA2B7D"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _SnapWalletRule_wallets;
|
|
13
|
+
import { AccountWalletCategory, toAccountWalletId } from "@metamask/account-api";
|
|
14
|
+
import { KeyringTypes } from "@metamask/keyring-controller";
|
|
15
|
+
import { stripSnapPrefix } from "@metamask/snaps-utils";
|
|
16
|
+
import { hasKeyringType } from "./utils.mjs";
|
|
17
|
+
import { BaseWalletRule } from "./WalletRule.mjs";
|
|
18
|
+
import { MutableAccountTreeWallet } from "../AccountTreeWallet.mjs";
|
|
19
|
+
class SnapWallet extends MutableAccountTreeWallet {
|
|
20
|
+
constructor(messenger, snapId) {
|
|
21
|
+
super(messenger, AccountWalletCategory.Snap, snapId);
|
|
22
|
+
this.snapId = snapId;
|
|
23
|
+
}
|
|
24
|
+
static toAccountWalletId(snapId) {
|
|
25
|
+
return toAccountWalletId(AccountWalletCategory.Snap, snapId);
|
|
26
|
+
}
|
|
27
|
+
getDefaultName() {
|
|
28
|
+
const snap = this.messenger.call('SnapController:get', this.snapId);
|
|
29
|
+
const snapName = snap
|
|
30
|
+
? // TODO: Handle localization here, but that's a "client thing", so we don't have a `core` controller
|
|
31
|
+
// to refer to.
|
|
32
|
+
snap.manifest.proposedName
|
|
33
|
+
: stripSnapPrefix(this.snapId);
|
|
34
|
+
return snapName;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class SnapWalletRule extends BaseWalletRule {
|
|
38
|
+
constructor(messenger) {
|
|
39
|
+
super(messenger);
|
|
40
|
+
_SnapWalletRule_wallets.set(this, void 0);
|
|
41
|
+
__classPrivateFieldSet(this, _SnapWalletRule_wallets, new Map(), "f");
|
|
42
|
+
}
|
|
43
|
+
match(account) {
|
|
44
|
+
if (hasKeyringType(account, KeyringTypes.snap) &&
|
|
45
|
+
account.metadata.snap &&
|
|
46
|
+
account.metadata.snap.enabled) {
|
|
47
|
+
const { id } = account.metadata.snap;
|
|
48
|
+
const snapId = id;
|
|
49
|
+
// Check if a wallet already exists for that Snap ID.
|
|
50
|
+
let wallet = __classPrivateFieldGet(this, _SnapWalletRule_wallets, "f").get(SnapWallet.toAccountWalletId(snapId));
|
|
51
|
+
if (!wallet) {
|
|
52
|
+
wallet = new SnapWallet(this.messenger, snapId);
|
|
53
|
+
__classPrivateFieldGet(this, _SnapWalletRule_wallets, "f").set(wallet.id, wallet);
|
|
54
|
+
}
|
|
55
|
+
// This will automatically creates the group if it's missing.
|
|
56
|
+
const group = wallet.addAccount(account);
|
|
57
|
+
return {
|
|
58
|
+
wallet,
|
|
59
|
+
group,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
_SnapWalletRule_wallets = new WeakMap();
|
|
66
|
+
//# sourceMappingURL=SnapWalletRule.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnapWalletRule.mjs","sourceRoot":"","sources":["../../src/rules/SnapWalletRule.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EAClB,8BAA8B;AAC/B,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EAAE,eAAe,EAAE,8BAA8B;AAExD,OAAO,EAAE,cAAc,EAAE,oBAAgB;AAEzC,OAAO,EAAE,cAAc,EAAE,yBAAqB;AAE9C,OAAO,EAAE,wBAAwB,EAAE,iCAA6B;AAEhE,MAAM,UAAW,SAAQ,wBAAwB;IAG/C,YAAY,SAAyC,EAAE,MAAc;QACnE,KAAK,CAAC,SAAS,EAAE,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,MAAc;QACrC,OAAO,iBAAiB,CAAC,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/D,CAAC;IAED,cAAc;QACZ,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QACpE,MAAM,QAAQ,GAAG,IAAI;YACnB,CAAC,CAAC,oGAAoG;gBACpG,eAAe;gBACf,IAAI,CAAC,QAAQ,CAAC,YAAY;YAC5B,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED,MAAM,OAAO,cAAe,SAAQ,cAAc;IAGhD,YAAY,SAAyC;QACnD,KAAK,CAAC,SAAS,CAAC,CAAC;QAHV,0CAA2C;QAKlD,uBAAA,IAAI,2BAAY,IAAI,GAAG,EAAE,MAAA,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,OAAwB;QAC5B,IACE,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC;YAC1C,OAAO,CAAC,QAAQ,CAAC,IAAI;YACrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAC7B;YACA,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;YACrC,MAAM,MAAM,GAAG,EAAY,CAAC;YAE5B,qDAAqD;YACrD,IAAI,MAAM,GAAG,uBAAA,IAAI,+BAAS,CAAC,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;YACrE,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;gBAChD,uBAAA,IAAI,+BAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;aACtC;YAED,6DAA6D;YAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YAEzC,OAAO;gBACL,MAAM;gBACN,KAAK;aACN,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import type { AccountWalletId } from '@metamask/account-api';\nimport {\n AccountWalletCategory,\n toAccountWalletId,\n} from '@metamask/account-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { stripSnapPrefix } from '@metamask/snaps-utils';\n\nimport { hasKeyringType } from './utils';\nimport type { WalletRuleMatch } from './WalletRule';\nimport { BaseWalletRule } from './WalletRule';\nimport type { AccountTreeControllerMessenger } from '../AccountTreeController';\nimport { MutableAccountTreeWallet } from '../AccountTreeWallet';\n\nclass SnapWallet extends MutableAccountTreeWallet {\n readonly snapId: SnapId;\n\n constructor(messenger: AccountTreeControllerMessenger, snapId: SnapId) {\n super(messenger, AccountWalletCategory.Snap, snapId);\n this.snapId = snapId;\n }\n\n static toAccountWalletId(snapId: SnapId) {\n return toAccountWalletId(AccountWalletCategory.Snap, snapId);\n }\n\n getDefaultName(): string {\n const snap = this.messenger.call('SnapController:get', this.snapId);\n const snapName = snap\n ? // TODO: Handle localization here, but that's a \"client thing\", so we don't have a `core` controller\n // to refer to.\n snap.manifest.proposedName\n : stripSnapPrefix(this.snapId);\n\n return snapName;\n }\n}\n\nexport class SnapWalletRule extends BaseWalletRule {\n readonly #wallets: Map<AccountWalletId, SnapWallet>;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n super(messenger);\n\n this.#wallets = new Map();\n }\n\n match(account: InternalAccount): WalletRuleMatch | undefined {\n if (\n hasKeyringType(account, KeyringTypes.snap) &&\n account.metadata.snap &&\n account.metadata.snap.enabled\n ) {\n const { id } = account.metadata.snap;\n const snapId = id as SnapId;\n\n // Check if a wallet already exists for that Snap ID.\n let wallet = this.#wallets.get(SnapWallet.toAccountWalletId(snapId));\n if (!wallet) {\n wallet = new SnapWallet(this.messenger, snapId);\n this.#wallets.set(wallet.id, wallet);\n }\n\n // This will automatically creates the group if it's missing.\n const group = wallet.addAccount(account);\n\n return {\n wallet,\n group,\n };\n }\n\n return undefined;\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseWalletRule = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for {@link WalletRule}.
|
|
6
|
+
*/
|
|
7
|
+
class BaseWalletRule {
|
|
8
|
+
constructor(messenger) {
|
|
9
|
+
this.messenger = messenger;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.BaseWalletRule = BaseWalletRule;
|
|
13
|
+
//# sourceMappingURL=WalletRule.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletRule.cjs","sourceRoot":"","sources":["../../src/rules/WalletRule.ts"],"names":[],"mappings":";;;AAgCA;;GAEG;AACH,MAAsB,cAAc;IAGlC,YAAY,SAAyC;QACnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CAGF;AARD,wCAQC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountTreeControllerMessenger } from 'src/AccountTreeController';\n\nimport type { AccountTreeGroup } from '../AccountTreeGroup';\nimport type { AccountTreeWallet } from '../AccountTreeWallet';\n\nexport type WalletRuleMatch = {\n wallet: AccountTreeWallet;\n group: AccountTreeGroup;\n};\n\n/**\n * A rule that can be used to group account in their proper account wallet/group.\n */\nexport type WalletRule = {\n /**\n * Apply the rule and check if the account matches.\n *\n * If the account matches, then the rule will return a {@link WalletRuleMatch} 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 WalletRuleMatch}) 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 WalletRuleMatch} if this account is part of that rule/wallet, returns\n * `undefined` otherwise.\n */\n match(account: InternalAccount): WalletRuleMatch | undefined;\n};\n\n/**\n * Abstract base class for {@link WalletRule}.\n */\nexport abstract class BaseWalletRule implements WalletRule {\n protected readonly messenger: AccountTreeControllerMessenger;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n this.messenger = messenger;\n }\n\n abstract match(account: InternalAccount): WalletRuleMatch | undefined;\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { AccountTreeControllerMessenger } from "src/AccountTreeController";
|
|
3
|
+
import type { AccountTreeGroup } from "../AccountTreeGroup.cjs";
|
|
4
|
+
import type { AccountTreeWallet } from "../AccountTreeWallet.cjs";
|
|
5
|
+
export type WalletRuleMatch = {
|
|
6
|
+
wallet: AccountTreeWallet;
|
|
7
|
+
group: AccountTreeGroup;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A rule that can be used to group account in their proper account wallet/group.
|
|
11
|
+
*/
|
|
12
|
+
export type WalletRule = {
|
|
13
|
+
/**
|
|
14
|
+
* Apply the rule and check if the account matches.
|
|
15
|
+
*
|
|
16
|
+
* If the account matches, then the rule will return a {@link WalletRuleMatch} which means
|
|
17
|
+
* this account needs to be grouped within a wallet associated with this rule.
|
|
18
|
+
*
|
|
19
|
+
* If a wallet already exists for this account (based on {@link WalletRuleMatch}) then
|
|
20
|
+
* the account will be added to that wallet instance into its proper group (different for
|
|
21
|
+
* every wallets).
|
|
22
|
+
*
|
|
23
|
+
* @param account - The account to match.
|
|
24
|
+
* @returns A {@link WalletRuleMatch} if this account is part of that rule/wallet, returns
|
|
25
|
+
* `undefined` otherwise.
|
|
26
|
+
*/
|
|
27
|
+
match(account: InternalAccount): WalletRuleMatch | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Abstract base class for {@link WalletRule}.
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class BaseWalletRule implements WalletRule {
|
|
33
|
+
protected readonly messenger: AccountTreeControllerMessenger;
|
|
34
|
+
constructor(messenger: AccountTreeControllerMessenger);
|
|
35
|
+
abstract match(account: InternalAccount): WalletRuleMatch | undefined;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=WalletRule.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletRule.d.cts","sourceRoot":"","sources":["../../src/rules/WalletRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,8BAA8B,EAAE,kCAAkC;AAEhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAA4B;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,iCAA6B;AAE9D,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS,CAAC;CAC9D,CAAC;AAEF;;GAEG;AACH,8BAAsB,cAAe,YAAW,UAAU;IACxD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;gBAEjD,SAAS,EAAE,8BAA8B;IAIrD,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;CACtE"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
2
|
+
import type { AccountTreeControllerMessenger } from "src/AccountTreeController";
|
|
3
|
+
import type { AccountTreeGroup } from "../AccountTreeGroup.mjs";
|
|
4
|
+
import type { AccountTreeWallet } from "../AccountTreeWallet.mjs";
|
|
5
|
+
export type WalletRuleMatch = {
|
|
6
|
+
wallet: AccountTreeWallet;
|
|
7
|
+
group: AccountTreeGroup;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A rule that can be used to group account in their proper account wallet/group.
|
|
11
|
+
*/
|
|
12
|
+
export type WalletRule = {
|
|
13
|
+
/**
|
|
14
|
+
* Apply the rule and check if the account matches.
|
|
15
|
+
*
|
|
16
|
+
* If the account matches, then the rule will return a {@link WalletRuleMatch} which means
|
|
17
|
+
* this account needs to be grouped within a wallet associated with this rule.
|
|
18
|
+
*
|
|
19
|
+
* If a wallet already exists for this account (based on {@link WalletRuleMatch}) then
|
|
20
|
+
* the account will be added to that wallet instance into its proper group (different for
|
|
21
|
+
* every wallets).
|
|
22
|
+
*
|
|
23
|
+
* @param account - The account to match.
|
|
24
|
+
* @returns A {@link WalletRuleMatch} if this account is part of that rule/wallet, returns
|
|
25
|
+
* `undefined` otherwise.
|
|
26
|
+
*/
|
|
27
|
+
match(account: InternalAccount): WalletRuleMatch | undefined;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Abstract base class for {@link WalletRule}.
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class BaseWalletRule implements WalletRule {
|
|
33
|
+
protected readonly messenger: AccountTreeControllerMessenger;
|
|
34
|
+
constructor(messenger: AccountTreeControllerMessenger);
|
|
35
|
+
abstract match(account: InternalAccount): WalletRuleMatch | undefined;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=WalletRule.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletRule.d.mts","sourceRoot":"","sources":["../../src/rules/WalletRule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,8BAA8B,EAAE,kCAAkC;AAEhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,gCAA4B;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,iCAA6B;AAE9D,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS,CAAC;CAC9D,CAAC;AAEF;;GAEG;AACH,8BAAsB,cAAe,YAAW,UAAU;IACxD,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,8BAA8B,CAAC;gBAEjD,SAAS,EAAE,8BAA8B;IAIrD,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;CACtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WalletRule.mjs","sourceRoot":"","sources":["../../src/rules/WalletRule.ts"],"names":[],"mappings":"AAgCA;;GAEG;AACH,MAAM,OAAgB,cAAc;IAGlC,YAAY,SAAyC;QACnD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CAGF","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type { AccountTreeControllerMessenger } from 'src/AccountTreeController';\n\nimport type { AccountTreeGroup } from '../AccountTreeGroup';\nimport type { AccountTreeWallet } from '../AccountTreeWallet';\n\nexport type WalletRuleMatch = {\n wallet: AccountTreeWallet;\n group: AccountTreeGroup;\n};\n\n/**\n * A rule that can be used to group account in their proper account wallet/group.\n */\nexport type WalletRule = {\n /**\n * Apply the rule and check if the account matches.\n *\n * If the account matches, then the rule will return a {@link WalletRuleMatch} 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 WalletRuleMatch}) 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 WalletRuleMatch} if this account is part of that rule/wallet, returns\n * `undefined` otherwise.\n */\n match(account: InternalAccount): WalletRuleMatch | undefined;\n};\n\n/**\n * Abstract base class for {@link WalletRule}.\n */\nexport abstract class BaseWalletRule implements WalletRule {\n protected readonly messenger: AccountTreeControllerMessenger;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n this.messenger = messenger;\n }\n\n abstract match(account: InternalAccount): WalletRuleMatch | undefined;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./WalletRule.cjs"), exports);
|
|
18
|
+
__exportStar(require("./EntropySourceWalletRule.cjs"), exports);
|
|
19
|
+
__exportStar(require("./SnapWalletRule.cjs"), exports);
|
|
20
|
+
__exportStar(require("./KeyringWalletRule.cjs"), exports);
|
|
21
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAA6B;AAC7B,gEAA0C;AAC1C,uDAAiC;AACjC,0DAAoC","sourcesContent":["export * from './WalletRule';\nexport * from './EntropySourceWalletRule';\nexport * from './SnapWalletRule';\nexport * from './KeyringWalletRule';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,iCAA6B;AAC7B,8CAA0C;AAC1C,qCAAiC;AACjC,wCAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,iCAA6B;AAC7B,8CAA0C;AAC1C,qCAAiC;AACjC,wCAAoC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/rules/index.ts"],"names":[],"mappings":"AAAA,iCAA6B;AAC7B,8CAA0C;AAC1C,qCAAiC;AACjC,wCAAoC","sourcesContent":["export * from './WalletRule';\nexport * from './EntropySourceWalletRule';\nexport * from './SnapWalletRule';\nexport * from './KeyringWalletRule';\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasKeyringType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if an account uses the same keyring type.
|
|
6
|
+
*
|
|
7
|
+
* @param account - The account.
|
|
8
|
+
* @param type - The keyring type.
|
|
9
|
+
* @returns True if the account uses the same keyring type, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
function hasKeyringType(account, type) {
|
|
12
|
+
return account.metadata.keyring.type === type;
|
|
13
|
+
}
|
|
14
|
+
exports.hasKeyringType = hasKeyringType;
|
|
15
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/rules/utils.ts"],"names":[],"mappings":";;;AAGA;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,OAAwB,EACxB,IAAkB;IAElB,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,IAAe,CAAC;AAC5D,CAAC;AALD,wCAKC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\n/**\n * Check if an account uses the same keyring type.\n *\n * @param account - The account.\n * @param type - The keyring type.\n * @returns True if the account uses the same keyring type, false otherwise.\n */\nexport function hasKeyringType(\n account: InternalAccount,\n type: KeyringTypes,\n): boolean {\n return account.metadata.keyring.type === (type as string);\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KeyringTypes } from "@metamask/keyring-controller";
|
|
2
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
|
+
/**
|
|
4
|
+
* Check if an account uses the same keyring type.
|
|
5
|
+
*
|
|
6
|
+
* @param account - The account.
|
|
7
|
+
* @param type - The keyring type.
|
|
8
|
+
* @returns True if the account uses the same keyring type, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hasKeyringType(account: InternalAccount, type: KeyringTypes): boolean;
|
|
11
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/rules/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAqC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,YAAY,GACjB,OAAO,CAET"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KeyringTypes } from "@metamask/keyring-controller";
|
|
2
|
+
import type { InternalAccount } from "@metamask/keyring-internal-api";
|
|
3
|
+
/**
|
|
4
|
+
* Check if an account uses the same keyring type.
|
|
5
|
+
*
|
|
6
|
+
* @param account - The account.
|
|
7
|
+
* @param type - The keyring type.
|
|
8
|
+
* @returns True if the account uses the same keyring type, false otherwise.
|
|
9
|
+
*/
|
|
10
|
+
export declare function hasKeyringType(account: InternalAccount, type: KeyringTypes): boolean;
|
|
11
|
+
//# sourceMappingURL=utils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/rules/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,qCAAqC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,eAAe,EACxB,IAAI,EAAE,YAAY,GACjB,OAAO,CAET"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if an account uses the same keyring type.
|
|
3
|
+
*
|
|
4
|
+
* @param account - The account.
|
|
5
|
+
* @param type - The keyring type.
|
|
6
|
+
* @returns True if the account uses the same keyring type, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export function hasKeyringType(account, type) {
|
|
9
|
+
return account.metadata.keyring.type === type;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/rules/utils.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAwB,EACxB,IAAkB;IAElB,OAAO,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,IAAe,CAAC;AAC5D,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\n/**\n * Check if an account uses the same keyring type.\n *\n * @param account - The account.\n * @param type - The keyring type.\n * @returns True if the account uses the same keyring type, false otherwise.\n */\nexport function hasKeyringType(\n account: InternalAccount,\n type: KeyringTypes,\n): boolean {\n return account.metadata.keyring.type === (type as string);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/account-tree-controller",
|
|
3
|
-
"version": "0.6.0-preview-
|
|
3
|
+
"version": "0.6.0-preview-bd86fa14",
|
|
4
4
|
"description": "Controller to group account together based on some pre-defined rules",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"lodash": "^4.17.21"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@metamask/account-api": "^0.
|
|
56
|
+
"@metamask/account-api": "^0.2.0",
|
|
57
57
|
"@metamask/accounts-controller": "^32.0.0",
|
|
58
58
|
"@metamask/auto-changelog": "^3.4.4",
|
|
59
59
|
"@metamask/keyring-api": "^19.0.0",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"webextension-polyfill": "^0.12.0"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@metamask/account-api": "^0.
|
|
73
|
+
"@metamask/account-api": "^0.2.0",
|
|
74
74
|
"@metamask/accounts-controller": "^32.0.0",
|
|
75
75
|
"@metamask/keyring-controller": "^22.0.0",
|
|
76
76
|
"@metamask/providers": "^22.0.0",
|
package/dist/AccountTreeRule.cjs
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,53 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/AccountTreeRule.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|