@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.
Files changed (120) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/AccountTreeController.cjs +195 -41
  3. package/dist/AccountTreeController.cjs.map +1 -1
  4. package/dist/AccountTreeController.d.cts +31 -40
  5. package/dist/AccountTreeController.d.cts.map +1 -1
  6. package/dist/AccountTreeController.d.mts +31 -40
  7. package/dist/AccountTreeController.d.mts.map +1 -1
  8. package/dist/AccountTreeController.mjs +193 -39
  9. package/dist/AccountTreeController.mjs.map +1 -1
  10. package/dist/AccountTreeGroup.cjs +44 -35
  11. package/dist/AccountTreeGroup.cjs.map +1 -1
  12. package/dist/AccountTreeGroup.d.cts +15 -22
  13. package/dist/AccountTreeGroup.d.cts.map +1 -1
  14. package/dist/AccountTreeGroup.d.mts +15 -22
  15. package/dist/AccountTreeGroup.d.mts.map +1 -1
  16. package/dist/AccountTreeGroup.mjs +42 -33
  17. package/dist/AccountTreeGroup.mjs.map +1 -1
  18. package/dist/AccountTreeRule.cjs +37 -0
  19. package/dist/AccountTreeRule.cjs.map +1 -0
  20. package/dist/AccountTreeRule.d.cts +53 -0
  21. package/dist/AccountTreeRule.d.cts.map +1 -0
  22. package/dist/AccountTreeRule.d.mts +53 -0
  23. package/dist/AccountTreeRule.d.mts.map +1 -0
  24. package/dist/AccountTreeRule.mjs +33 -0
  25. package/dist/AccountTreeRule.mjs.map +1 -0
  26. package/dist/AccountTreeWallet.cjs +53 -26
  27. package/dist/AccountTreeWallet.cjs.map +1 -1
  28. package/dist/AccountTreeWallet.d.cts +26 -21
  29. package/dist/AccountTreeWallet.d.cts.map +1 -1
  30. package/dist/AccountTreeWallet.d.mts +26 -21
  31. package/dist/AccountTreeWallet.d.mts.map +1 -1
  32. package/dist/AccountTreeWallet.mjs +52 -25
  33. package/dist/AccountTreeWallet.mjs.map +1 -1
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +1 -1
  36. package/dist/index.d.cts.map +1 -1
  37. package/dist/index.d.mts +1 -1
  38. package/dist/index.d.mts.map +1 -1
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/rules/entropy.cjs +68 -0
  41. package/dist/rules/entropy.cjs.map +1 -0
  42. package/dist/rules/entropy.d.cts +13 -0
  43. package/dist/rules/entropy.d.cts.map +1 -0
  44. package/dist/rules/entropy.d.mts +13 -0
  45. package/dist/rules/entropy.d.mts.map +1 -0
  46. package/dist/rules/entropy.mjs +64 -0
  47. package/dist/rules/entropy.mjs.map +1 -0
  48. package/dist/rules/keyring.cjs +86 -0
  49. package/dist/rules/keyring.cjs.map +1 -0
  50. package/dist/rules/keyring.d.cts +21 -0
  51. package/dist/rules/keyring.d.cts.map +1 -0
  52. package/dist/rules/keyring.d.mts +21 -0
  53. package/dist/rules/keyring.d.mts.map +1 -0
  54. package/dist/rules/keyring.mjs +81 -0
  55. package/dist/rules/keyring.mjs.map +1 -0
  56. package/dist/rules/snap.cjs +58 -0
  57. package/dist/rules/snap.cjs.map +1 -0
  58. package/dist/rules/snap.d.cts +22 -0
  59. package/dist/rules/snap.d.cts.map +1 -0
  60. package/dist/rules/snap.d.mts +22 -0
  61. package/dist/rules/snap.d.mts.map +1 -0
  62. package/dist/rules/snap.mjs +54 -0
  63. package/dist/rules/snap.mjs.map +1 -0
  64. package/dist/types.cjs +3 -0
  65. package/dist/types.cjs.map +1 -0
  66. package/dist/types.d.cts +83 -0
  67. package/dist/types.d.cts.map +1 -0
  68. package/dist/types.d.mts +83 -0
  69. package/dist/types.d.mts.map +1 -0
  70. package/dist/types.mjs +2 -0
  71. package/dist/types.mjs.map +1 -0
  72. package/package.json +4 -4
  73. package/dist/rules/EntropySourceWalletRule.cjs +0 -100
  74. package/dist/rules/EntropySourceWalletRule.cjs.map +0 -1
  75. package/dist/rules/EntropySourceWalletRule.d.cts +0 -19
  76. package/dist/rules/EntropySourceWalletRule.d.cts.map +0 -1
  77. package/dist/rules/EntropySourceWalletRule.d.mts +0 -19
  78. package/dist/rules/EntropySourceWalletRule.d.mts.map +0 -1
  79. package/dist/rules/EntropySourceWalletRule.mjs +0 -95
  80. package/dist/rules/EntropySourceWalletRule.mjs.map +0 -1
  81. package/dist/rules/KeyringWalletRule.cjs +0 -99
  82. package/dist/rules/KeyringWalletRule.cjs.map +0 -1
  83. package/dist/rules/KeyringWalletRule.d.cts +0 -18
  84. package/dist/rules/KeyringWalletRule.d.cts.map +0 -1
  85. package/dist/rules/KeyringWalletRule.d.mts +0 -18
  86. package/dist/rules/KeyringWalletRule.d.mts.map +0 -1
  87. package/dist/rules/KeyringWalletRule.mjs +0 -94
  88. package/dist/rules/KeyringWalletRule.mjs.map +0 -1
  89. package/dist/rules/SnapWalletRule.cjs +0 -70
  90. package/dist/rules/SnapWalletRule.cjs.map +0 -1
  91. package/dist/rules/SnapWalletRule.d.cts +0 -10
  92. package/dist/rules/SnapWalletRule.d.cts.map +0 -1
  93. package/dist/rules/SnapWalletRule.d.mts +0 -10
  94. package/dist/rules/SnapWalletRule.d.mts.map +0 -1
  95. package/dist/rules/SnapWalletRule.mjs +0 -66
  96. package/dist/rules/SnapWalletRule.mjs.map +0 -1
  97. package/dist/rules/WalletRule.cjs +0 -13
  98. package/dist/rules/WalletRule.cjs.map +0 -1
  99. package/dist/rules/WalletRule.d.cts +0 -37
  100. package/dist/rules/WalletRule.d.cts.map +0 -1
  101. package/dist/rules/WalletRule.d.mts +0 -37
  102. package/dist/rules/WalletRule.d.mts.map +0 -1
  103. package/dist/rules/WalletRule.mjs +0 -9
  104. package/dist/rules/WalletRule.mjs.map +0 -1
  105. package/dist/rules/index.cjs +0 -21
  106. package/dist/rules/index.cjs.map +0 -1
  107. package/dist/rules/index.d.cts +0 -5
  108. package/dist/rules/index.d.cts.map +0 -1
  109. package/dist/rules/index.d.mts +0 -5
  110. package/dist/rules/index.d.mts.map +0 -1
  111. package/dist/rules/index.mjs +0 -5
  112. package/dist/rules/index.mjs.map +0 -1
  113. package/dist/rules/utils.cjs +0 -15
  114. package/dist/rules/utils.cjs.map +0 -1
  115. package/dist/rules/utils.d.cts +0 -11
  116. package/dist/rules/utils.d.cts.map +0 -1
  117. package/dist/rules/utils.d.mts +0 -11
  118. package/dist/rules/utils.d.mts.map +0 -1
  119. package/dist/rules/utils.mjs +0 -11
  120. package/dist/rules/utils.mjs.map +0 -1
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapRule = void 0;
4
+ const account_api_1 = require("@metamask/account-api");
5
+ const keyring_controller_1 = require("@metamask/keyring-controller");
6
+ const snaps_utils_1 = require("@metamask/snaps-utils");
7
+ const AccountTreeRule_1 = require("../AccountTreeRule.cjs");
8
+ class SnapRule extends AccountTreeRule_1.AccountTreeRule {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.category = account_api_1.AccountWalletCategory.Snap;
12
+ }
13
+ isSnapAccount(account) {
14
+ return (account.metadata.keyring.type === keyring_controller_1.KeyringTypes.snap &&
15
+ account.metadata.snap !== undefined &&
16
+ account.metadata.snap.enabled);
17
+ }
18
+ match(account) {
19
+ if (!this.isSnapAccount(account)) {
20
+ return undefined;
21
+ }
22
+ const { id: snapId } = account.metadata.snap;
23
+ const wallet = {
24
+ id: (0, account_api_1.toAccountWalletId)(this.category, snapId),
25
+ metadata: {
26
+ type: account_api_1.AccountWalletCategory.Snap,
27
+ snap: {
28
+ id: snapId,
29
+ },
30
+ },
31
+ };
32
+ const group = {
33
+ id: (0, account_api_1.toAccountGroupId)(wallet.id, account.address),
34
+ };
35
+ return {
36
+ wallet,
37
+ group,
38
+ };
39
+ }
40
+ getDefaultAccountWalletName(wallet) {
41
+ // Precondition: We assume the AccountTreeController will always use
42
+ // the proper wallet instance.
43
+ const metadata = wallet.metadata;
44
+ const snap = this.messenger.call('SnapController:get', metadata.snap.id);
45
+ const snapName = snap
46
+ ? // TODO: Handle localization here, but that's a "client thing", so we don't have a `core` controller
47
+ // to refer to.
48
+ snap.manifest.proposedName
49
+ : (0, snaps_utils_1.stripSnapPrefix)(metadata.snap.id);
50
+ return snapName;
51
+ }
52
+ getDefaultAccountGroupName(group) {
53
+ // Precondition: This account group should contain only 1 account.
54
+ return this.getOnlyAccountFrom(group).metadata.name;
55
+ }
56
+ }
57
+ exports.SnapRule = SnapRule;
58
+ //# sourceMappingURL=snap.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snap.cjs","sourceRoot":"","sources":["../../src/rules/snap.ts"],"names":[],"mappings":";;;AAAA,uDAI+B;AAC/B,qEAA4D;AAG5D,uDAAwD;AAQxD,4DAAqD;AAUrD,MAAa,QAAS,SAAQ,iCAAe;IAA7C;;QACW,aAAQ,GAAG,mCAAqB,CAAC,IAAI,CAAC;IA0DjD,CAAC;IAxDC,aAAa,CACX,OAAwB;QAExB,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,IAAe;YAC/D,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,SAAS;YACnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAC9B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAwB;QAC5B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE;YAChC,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC;QAE7C,MAAM,MAAM,GAAoC;YAC9C,EAAE,EAAE,IAAA,+BAAiB,EAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC;YAC5C,QAAQ,EAAE;gBACR,IAAI,EAAE,mCAAqB,CAAC,IAAI;gBAChC,IAAI,EAAE;oBACJ,EAAE,EAAE,MAAM;iBACX;aACF;SACF,CAAC;QAEF,MAAM,KAAK,GAAmC;YAC5C,EAAE,EAAE,IAAA,8BAAgB,EAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,OAAO,CAAC;SACjD,CAAC;QAEF,OAAO;YACL,MAAM;YACN,KAAK;SACN,CAAC;IACJ,CAAC;IAED,2BAA2B,CAAC,MAA2B;QACrD,oEAAoE;QACpE,8BAA8B;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAqC,CAAC;QAE9D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,IAAI;YACnB,CAAC,CAAC,oGAAoG;gBACpG,eAAe;gBACf,IAAI,CAAC,QAAQ,CAAC,YAAY;YAC5B,CAAC,CAAC,IAAA,6BAAe,EAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEtC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,0BAA0B,CAAC,KAAyB;QAClD,kEAAkE;QAClE,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtD,CAAC;CACF;AA3DD,4BA2DC","sourcesContent":["import {\n AccountWalletCategory,\n toAccountGroupId,\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';\nimport type {\n AccountGroupObject,\n AccountWalletObject,\n AccountWalletSnapMetadata,\n} from 'src/types';\n\nimport type { AccountTreeRuleResult } from '../AccountTreeRule';\nimport { AccountTreeRule } from '../AccountTreeRule';\n\ntype SnapAccount<Account extends InternalAccount> = Account & {\n metadata: Account['metadata'] & {\n snap: {\n id: SnapId;\n };\n };\n};\n\nexport class SnapRule extends AccountTreeRule {\n readonly category = AccountWalletCategory.Snap;\n\n isSnapAccount(\n account: InternalAccount,\n ): account is SnapAccount<InternalAccount> {\n return (\n account.metadata.keyring.type === (KeyringTypes.snap as string) &&\n account.metadata.snap !== undefined &&\n account.metadata.snap.enabled\n );\n }\n\n match(account: InternalAccount): AccountTreeRuleResult | undefined {\n if (!this.isSnapAccount(account)) {\n return undefined;\n }\n\n const { id: snapId } = account.metadata.snap;\n\n const wallet: AccountTreeRuleResult['wallet'] = {\n id: toAccountWalletId(this.category, snapId),\n metadata: {\n type: AccountWalletCategory.Snap,\n snap: {\n id: snapId,\n },\n },\n };\n\n const group: AccountTreeRuleResult['group'] = {\n id: toAccountGroupId(wallet.id, account.address),\n };\n\n return {\n wallet,\n group,\n };\n }\n\n getDefaultAccountWalletName(wallet: AccountWalletObject): string {\n // Precondition: We assume the AccountTreeController will always use\n // the proper wallet instance.\n const metadata = wallet.metadata as AccountWalletSnapMetadata;\n\n const snap = this.messenger.call('SnapController:get', metadata.snap.id);\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(metadata.snap.id);\n\n return snapName;\n }\n\n getDefaultAccountGroupName(group: AccountGroupObject): string {\n // Precondition: This account group should contain only 1 account.\n return this.getOnlyAccountFrom(group).metadata.name;\n }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { AccountWalletCategory } from "@metamask/account-api";
2
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
3
+ import type { SnapId } from "@metamask/snaps-sdk";
4
+ import type { AccountGroupObject, AccountWalletObject } from "src/types";
5
+ import type { AccountTreeRuleResult } from "../AccountTreeRule.cjs";
6
+ import { AccountTreeRule } from "../AccountTreeRule.cjs";
7
+ type SnapAccount<Account extends InternalAccount> = Account & {
8
+ metadata: Account['metadata'] & {
9
+ snap: {
10
+ id: SnapId;
11
+ };
12
+ };
13
+ };
14
+ export declare class SnapRule extends AccountTreeRule {
15
+ readonly category = AccountWalletCategory.Snap;
16
+ isSnapAccount(account: InternalAccount): account is SnapAccount<InternalAccount>;
17
+ match(account: InternalAccount): AccountTreeRuleResult | undefined;
18
+ getDefaultAccountWalletName(wallet: AccountWalletObject): string;
19
+ getDefaultAccountGroupName(group: AccountGroupObject): string;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=snap.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snap.d.cts","sourceRoot":"","sources":["../../src/rules/snap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAGtB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EAEpB,kBAAkB;AAEnB,OAAO,KAAK,EAAE,qBAAqB,EAAE,+BAA2B;AAChE,OAAO,EAAE,eAAe,EAAE,+BAA2B;AAErD,KAAK,WAAW,CAAC,OAAO,SAAS,eAAe,IAAI,OAAO,GAAG;IAC5D,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG;QAC9B,IAAI,EAAE;YACJ,EAAE,EAAE,MAAM,CAAC;SACZ,CAAC;KACH,CAAC;CACH,CAAC;AAEF,qBAAa,QAAS,SAAQ,eAAe;IAC3C,QAAQ,CAAC,QAAQ,8BAA8B;IAE/C,aAAa,CACX,OAAO,EAAE,eAAe,GACvB,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC;IAQ1C,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,qBAAqB,GAAG,SAAS;IA2BlE,2BAA2B,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM;IAehE,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM;CAI9D"}
@@ -0,0 +1,22 @@
1
+ import { AccountWalletCategory } from "@metamask/account-api";
2
+ import type { InternalAccount } from "@metamask/keyring-internal-api";
3
+ import type { SnapId } from "@metamask/snaps-sdk";
4
+ import type { AccountGroupObject, AccountWalletObject } from "src/types";
5
+ import type { AccountTreeRuleResult } from "../AccountTreeRule.mjs";
6
+ import { AccountTreeRule } from "../AccountTreeRule.mjs";
7
+ type SnapAccount<Account extends InternalAccount> = Account & {
8
+ metadata: Account['metadata'] & {
9
+ snap: {
10
+ id: SnapId;
11
+ };
12
+ };
13
+ };
14
+ export declare class SnapRule extends AccountTreeRule {
15
+ readonly category = AccountWalletCategory.Snap;
16
+ isSnapAccount(account: InternalAccount): account is SnapAccount<InternalAccount>;
17
+ match(account: InternalAccount): AccountTreeRuleResult | undefined;
18
+ getDefaultAccountWalletName(wallet: AccountWalletObject): string;
19
+ getDefaultAccountGroupName(group: AccountGroupObject): string;
20
+ }
21
+ export {};
22
+ //# sourceMappingURL=snap.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"snap.d.mts","sourceRoot":"","sources":["../../src/rules/snap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EAGtB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EAEpB,kBAAkB;AAEnB,OAAO,KAAK,EAAE,qBAAqB,EAAE,+BAA2B;AAChE,OAAO,EAAE,eAAe,EAAE,+BAA2B;AAErD,KAAK,WAAW,CAAC,OAAO,SAAS,eAAe,IAAI,OAAO,GAAG;IAC5D,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG;QAC9B,IAAI,EAAE;YACJ,EAAE,EAAE,MAAM,CAAC;SACZ,CAAC;KACH,CAAC;CACH,CAAC;AAEF,qBAAa,QAAS,SAAQ,eAAe;IAC3C,QAAQ,CAAC,QAAQ,8BAA8B;IAE/C,aAAa,CACX,OAAO,EAAE,eAAe,GACvB,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC;IAQ1C,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,qBAAqB,GAAG,SAAS;IA2BlE,2BAA2B,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM;IAehE,0BAA0B,CAAC,KAAK,EAAE,kBAAkB,GAAG,MAAM;CAI9D"}
@@ -0,0 +1,54 @@
1
+ import { AccountWalletCategory, toAccountGroupId, toAccountWalletId } from "@metamask/account-api";
2
+ import { KeyringTypes } from "@metamask/keyring-controller";
3
+ import { stripSnapPrefix } from "@metamask/snaps-utils";
4
+ import { AccountTreeRule } from "../AccountTreeRule.mjs";
5
+ export class SnapRule extends AccountTreeRule {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.category = AccountWalletCategory.Snap;
9
+ }
10
+ isSnapAccount(account) {
11
+ return (account.metadata.keyring.type === KeyringTypes.snap &&
12
+ account.metadata.snap !== undefined &&
13
+ account.metadata.snap.enabled);
14
+ }
15
+ match(account) {
16
+ if (!this.isSnapAccount(account)) {
17
+ return undefined;
18
+ }
19
+ const { id: snapId } = account.metadata.snap;
20
+ const wallet = {
21
+ id: toAccountWalletId(this.category, snapId),
22
+ metadata: {
23
+ type: AccountWalletCategory.Snap,
24
+ snap: {
25
+ id: snapId,
26
+ },
27
+ },
28
+ };
29
+ const group = {
30
+ id: toAccountGroupId(wallet.id, account.address),
31
+ };
32
+ return {
33
+ wallet,
34
+ group,
35
+ };
36
+ }
37
+ getDefaultAccountWalletName(wallet) {
38
+ // Precondition: We assume the AccountTreeController will always use
39
+ // the proper wallet instance.
40
+ const metadata = wallet.metadata;
41
+ const snap = this.messenger.call('SnapController:get', metadata.snap.id);
42
+ const snapName = snap
43
+ ? // TODO: Handle localization here, but that's a "client thing", so we don't have a `core` controller
44
+ // to refer to.
45
+ snap.manifest.proposedName
46
+ : stripSnapPrefix(metadata.snap.id);
47
+ return snapName;
48
+ }
49
+ getDefaultAccountGroupName(group) {
50
+ // Precondition: This account group should contain only 1 account.
51
+ return this.getOnlyAccountFrom(group).metadata.name;
52
+ }
53
+ }
54
+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CAAC;IAED,2BAA2B,CAAC,MAA2B;QACrD,oEAAoE;QACpE,8BAA8B;QAC9B,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAqC,CAAC;QAE9D,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,oBAAoB,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzE,MAAM,QAAQ,GAAG,IAAI;YACnB,CAAC,CAAC,oGAAoG;gBACpG,eAAe;gBACf,IAAI,CAAC,QAAQ,CAAC,YAAY;YAC5B,CAAC,CAAC,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEtC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,0BAA0B,CAAC,KAAyB;QAClD,kEAAkE;QAClE,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;IACtD,CAAC;CACF","sourcesContent":["import {\n AccountWalletCategory,\n toAccountGroupId,\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';\nimport type {\n AccountGroupObject,\n AccountWalletObject,\n AccountWalletSnapMetadata,\n} from 'src/types';\n\nimport type { AccountTreeRuleResult } from '../AccountTreeRule';\nimport { AccountTreeRule } from '../AccountTreeRule';\n\ntype SnapAccount<Account extends InternalAccount> = Account & {\n metadata: Account['metadata'] & {\n snap: {\n id: SnapId;\n };\n };\n};\n\nexport class SnapRule extends AccountTreeRule {\n readonly category = AccountWalletCategory.Snap;\n\n isSnapAccount(\n account: InternalAccount,\n ): account is SnapAccount<InternalAccount> {\n return (\n account.metadata.keyring.type === (KeyringTypes.snap as string) &&\n account.metadata.snap !== undefined &&\n account.metadata.snap.enabled\n );\n }\n\n match(account: InternalAccount): AccountTreeRuleResult | undefined {\n if (!this.isSnapAccount(account)) {\n return undefined;\n }\n\n const { id: snapId } = account.metadata.snap;\n\n const wallet: AccountTreeRuleResult['wallet'] = {\n id: toAccountWalletId(this.category, snapId),\n metadata: {\n type: AccountWalletCategory.Snap,\n snap: {\n id: snapId,\n },\n },\n };\n\n const group: AccountTreeRuleResult['group'] = {\n id: toAccountGroupId(wallet.id, account.address),\n };\n\n return {\n wallet,\n group,\n };\n }\n\n getDefaultAccountWalletName(wallet: AccountWalletObject): string {\n // Precondition: We assume the AccountTreeController will always use\n // the proper wallet instance.\n const metadata = wallet.metadata as AccountWalletSnapMetadata;\n\n const snap = this.messenger.call('SnapController:get', metadata.snap.id);\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(metadata.snap.id);\n\n return snapName;\n }\n\n getDefaultAccountGroupName(group: AccountGroupObject): string {\n // Precondition: This account group should contain only 1 account.\n return this.getOnlyAccountFrom(group).metadata.name;\n }\n}\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountWalletCategory } from '@metamask/account-api';\nimport type { AccountGroupId, AccountWalletId } from '@metamask/account-api';\nimport type {\n AccountId,\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerSelectedAccountChangeEvent,\n AccountsControllerSetSelectedAccountAction,\n} from '@metamask/accounts-controller';\nimport {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport type {\n KeyringControllerGetStateAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { GetSnap as SnapControllerGetSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport type {\n AccountTreeController,\n controllerName,\n} from './AccountTreeController';\n\n/**\n * Account wallet metadata for the \"entropy\" wallet category.\n */\nexport type AccountWalletEntropyMetadata = {\n type: AccountWalletCategory.Entropy;\n entropy: {\n id: EntropySourceId;\n index: number;\n };\n};\n\n/**\n * Account wallet metadata for the \"snap\" wallet category.\n */\nexport type AccountWalletSnapMetadata = {\n type: AccountWalletCategory.Snap;\n snap: {\n id: SnapId;\n };\n};\n\n/**\n * Account wallet metadata for the \"keyring\" wallet category.\n */\nexport type AccountWalletKeyringMetadata = {\n type: AccountWalletCategory.Keyring;\n keyring: {\n type: KeyringTypes;\n };\n};\n\n/**\n * Account wallet metadata for the \"keyring\" wallet category.\n */\nexport type AccountWalletCategoryMetadata =\n | AccountWalletEntropyMetadata\n | AccountWalletSnapMetadata\n | AccountWalletKeyringMetadata;\n\nexport type AccountWalletMetadata = {\n name: string;\n} & AccountWalletCategoryMetadata;\n\nexport type AccountGroupMetadata = {\n name: string;\n};\n\nexport type AccountGroupObject = {\n id: AccountGroupId;\n // Blockchain Accounts:\n accounts: AccountId[];\n metadata: AccountGroupMetadata;\n};\n\nexport type AccountWalletObject = {\n id: AccountWalletId;\n // Account groups OR Multichain accounts (once available).\n groups: {\n [groupId: AccountGroupId]: AccountGroupObject;\n };\n metadata: AccountWalletMetadata;\n};\n\nexport type AccountTreeControllerState = {\n accountTree: {\n wallets: {\n // Wallets:\n [walletId: AccountWalletId]: AccountWalletObject;\n };\n selectedAccountGroup: AccountGroupId | '';\n };\n};\n\nexport type AccountTreeControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountTreeControllerState\n>;\n\nexport type AccountTreeControllerSetSelectedAccountGroupAction = {\n type: `${typeof controllerName}:setSelectedAccountGroup`;\n handler: AccountTreeController['setSelectedAccountGroup'];\n};\n\nexport type AccountTreeControllerGetSelectedAccountGroupAction = {\n type: `${typeof controllerName}:getSelectedAccountGroup`;\n handler: AccountTreeController['getSelectedAccountGroup'];\n};\n\nexport type AllowedActions =\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedAccountAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetSelectedAccountAction\n | KeyringControllerGetStateAction\n | SnapControllerGetSnap;\n\nexport type AccountTreeControllerActions =\n | AccountTreeControllerGetStateAction\n | AccountTreeControllerSetSelectedAccountGroupAction\n | AccountTreeControllerGetSelectedAccountGroupAction;\n\nexport type AccountTreeControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountTreeControllerState\n>;\n\nexport type AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerSelectedAccountChangeEvent;\n\nexport type AccountTreeControllerEvents = AccountTreeControllerStateChangeEvent;\n\nexport type AccountTreeControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountTreeControllerActions | AllowedActions,\n AccountTreeControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n"]}
@@ -0,0 +1,83 @@
1
+ import type { AccountWalletCategory } from "@metamask/account-api";
2
+ import type { AccountGroupId, AccountWalletId } from "@metamask/account-api";
3
+ import type { AccountId, AccountsControllerAccountAddedEvent, AccountsControllerAccountRemovedEvent, AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, AccountsControllerListMultichainAccountsAction, AccountsControllerSelectedAccountChangeEvent, AccountsControllerSetSelectedAccountAction } from "@metamask/accounts-controller";
4
+ import { type ControllerGetStateAction, type ControllerStateChangeEvent, type RestrictedMessenger } from "@metamask/base-controller";
5
+ import type { EntropySourceId } from "@metamask/keyring-api";
6
+ import type { KeyringControllerGetStateAction, KeyringTypes } from "@metamask/keyring-controller";
7
+ import type { GetSnap as SnapControllerGetSnap } from "@metamask/snaps-controllers";
8
+ import type { SnapId } from "@metamask/snaps-sdk";
9
+ import type { AccountTreeController, controllerName } from "./AccountTreeController.cjs";
10
+ /**
11
+ * Account wallet metadata for the "entropy" wallet category.
12
+ */
13
+ export type AccountWalletEntropyMetadata = {
14
+ type: AccountWalletCategory.Entropy;
15
+ entropy: {
16
+ id: EntropySourceId;
17
+ index: number;
18
+ };
19
+ };
20
+ /**
21
+ * Account wallet metadata for the "snap" wallet category.
22
+ */
23
+ export type AccountWalletSnapMetadata = {
24
+ type: AccountWalletCategory.Snap;
25
+ snap: {
26
+ id: SnapId;
27
+ };
28
+ };
29
+ /**
30
+ * Account wallet metadata for the "keyring" wallet category.
31
+ */
32
+ export type AccountWalletKeyringMetadata = {
33
+ type: AccountWalletCategory.Keyring;
34
+ keyring: {
35
+ type: KeyringTypes;
36
+ };
37
+ };
38
+ /**
39
+ * Account wallet metadata for the "keyring" wallet category.
40
+ */
41
+ export type AccountWalletCategoryMetadata = AccountWalletEntropyMetadata | AccountWalletSnapMetadata | AccountWalletKeyringMetadata;
42
+ export type AccountWalletMetadata = {
43
+ name: string;
44
+ } & AccountWalletCategoryMetadata;
45
+ export type AccountGroupMetadata = {
46
+ name: string;
47
+ };
48
+ export type AccountGroupObject = {
49
+ id: AccountGroupId;
50
+ accounts: AccountId[];
51
+ metadata: AccountGroupMetadata;
52
+ };
53
+ export type AccountWalletObject = {
54
+ id: AccountWalletId;
55
+ groups: {
56
+ [groupId: AccountGroupId]: AccountGroupObject;
57
+ };
58
+ metadata: AccountWalletMetadata;
59
+ };
60
+ export type AccountTreeControllerState = {
61
+ accountTree: {
62
+ wallets: {
63
+ [walletId: AccountWalletId]: AccountWalletObject;
64
+ };
65
+ selectedAccountGroup: AccountGroupId | '';
66
+ };
67
+ };
68
+ export type AccountTreeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AccountTreeControllerState>;
69
+ export type AccountTreeControllerSetSelectedAccountGroupAction = {
70
+ type: `${typeof controllerName}:setSelectedAccountGroup`;
71
+ handler: AccountTreeController['setSelectedAccountGroup'];
72
+ };
73
+ export type AccountTreeControllerGetSelectedAccountGroupAction = {
74
+ type: `${typeof controllerName}:getSelectedAccountGroup`;
75
+ handler: AccountTreeController['getSelectedAccountGroup'];
76
+ };
77
+ export type AllowedActions = AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction | AccountsControllerListMultichainAccountsAction | AccountsControllerSetSelectedAccountAction | KeyringControllerGetStateAction | SnapControllerGetSnap;
78
+ export type AccountTreeControllerActions = AccountTreeControllerGetStateAction | AccountTreeControllerSetSelectedAccountGroupAction | AccountTreeControllerGetSelectedAccountGroupAction;
79
+ export type AccountTreeControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AccountTreeControllerState>;
80
+ export type AllowedEvents = AccountsControllerAccountAddedEvent | AccountsControllerAccountRemovedEvent | AccountsControllerSelectedAccountChangeEvent;
81
+ export type AccountTreeControllerEvents = AccountTreeControllerStateChangeEvent;
82
+ export type AccountTreeControllerMessenger = RestrictedMessenger<typeof controllerName, AccountTreeControllerActions | AllowedActions, AccountTreeControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
83
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,8BAA8B;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EACV,SAAS,EACT,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,0CAA0C,EAC1C,8CAA8C,EAC9C,4CAA4C,EAC5C,0CAA0C,EAC3C,sCAAsC;AACvC,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AA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a,CAAC,MAAM,CAAC,CACtB,CAAC"}
@@ -0,0 +1,83 @@
1
+ import type { AccountWalletCategory } from "@metamask/account-api";
2
+ import type { AccountGroupId, AccountWalletId } from "@metamask/account-api";
3
+ import type { AccountId, AccountsControllerAccountAddedEvent, AccountsControllerAccountRemovedEvent, AccountsControllerGetAccountAction, AccountsControllerGetSelectedAccountAction, AccountsControllerListMultichainAccountsAction, AccountsControllerSelectedAccountChangeEvent, AccountsControllerSetSelectedAccountAction } from "@metamask/accounts-controller";
4
+ import { type ControllerGetStateAction, type ControllerStateChangeEvent, type RestrictedMessenger } from "@metamask/base-controller";
5
+ import type { EntropySourceId } from "@metamask/keyring-api";
6
+ import type { KeyringControllerGetStateAction, KeyringTypes } from "@metamask/keyring-controller";
7
+ import type { GetSnap as SnapControllerGetSnap } from "@metamask/snaps-controllers";
8
+ import type { SnapId } from "@metamask/snaps-sdk";
9
+ import type { AccountTreeController, controllerName } from "./AccountTreeController.mjs";
10
+ /**
11
+ * Account wallet metadata for the "entropy" wallet category.
12
+ */
13
+ export type AccountWalletEntropyMetadata = {
14
+ type: AccountWalletCategory.Entropy;
15
+ entropy: {
16
+ id: EntropySourceId;
17
+ index: number;
18
+ };
19
+ };
20
+ /**
21
+ * Account wallet metadata for the "snap" wallet category.
22
+ */
23
+ export type AccountWalletSnapMetadata = {
24
+ type: AccountWalletCategory.Snap;
25
+ snap: {
26
+ id: SnapId;
27
+ };
28
+ };
29
+ /**
30
+ * Account wallet metadata for the "keyring" wallet category.
31
+ */
32
+ export type AccountWalletKeyringMetadata = {
33
+ type: AccountWalletCategory.Keyring;
34
+ keyring: {
35
+ type: KeyringTypes;
36
+ };
37
+ };
38
+ /**
39
+ * Account wallet metadata for the "keyring" wallet category.
40
+ */
41
+ export type AccountWalletCategoryMetadata = AccountWalletEntropyMetadata | AccountWalletSnapMetadata | AccountWalletKeyringMetadata;
42
+ export type AccountWalletMetadata = {
43
+ name: string;
44
+ } & AccountWalletCategoryMetadata;
45
+ export type AccountGroupMetadata = {
46
+ name: string;
47
+ };
48
+ export type AccountGroupObject = {
49
+ id: AccountGroupId;
50
+ accounts: AccountId[];
51
+ metadata: AccountGroupMetadata;
52
+ };
53
+ export type AccountWalletObject = {
54
+ id: AccountWalletId;
55
+ groups: {
56
+ [groupId: AccountGroupId]: AccountGroupObject;
57
+ };
58
+ metadata: AccountWalletMetadata;
59
+ };
60
+ export type AccountTreeControllerState = {
61
+ accountTree: {
62
+ wallets: {
63
+ [walletId: AccountWalletId]: AccountWalletObject;
64
+ };
65
+ selectedAccountGroup: AccountGroupId | '';
66
+ };
67
+ };
68
+ export type AccountTreeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AccountTreeControllerState>;
69
+ export type AccountTreeControllerSetSelectedAccountGroupAction = {
70
+ type: `${typeof controllerName}:setSelectedAccountGroup`;
71
+ handler: AccountTreeController['setSelectedAccountGroup'];
72
+ };
73
+ export type AccountTreeControllerGetSelectedAccountGroupAction = {
74
+ type: `${typeof controllerName}:getSelectedAccountGroup`;
75
+ handler: AccountTreeController['getSelectedAccountGroup'];
76
+ };
77
+ export type AllowedActions = AccountsControllerGetAccountAction | AccountsControllerGetSelectedAccountAction | AccountsControllerListMultichainAccountsAction | AccountsControllerSetSelectedAccountAction | KeyringControllerGetStateAction | SnapControllerGetSnap;
78
+ export type AccountTreeControllerActions = AccountTreeControllerGetStateAction | AccountTreeControllerSetSelectedAccountGroupAction | AccountTreeControllerGetSelectedAccountGroupAction;
79
+ export type AccountTreeControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AccountTreeControllerState>;
80
+ export type AllowedEvents = AccountsControllerAccountAddedEvent | AccountsControllerAccountRemovedEvent | AccountsControllerSelectedAccountChangeEvent;
81
+ export type AccountTreeControllerEvents = AccountTreeControllerStateChangeEvent;
82
+ export type AccountTreeControllerMessenger = RestrictedMessenger<typeof controllerName, AccountTreeControllerActions | AllowedActions, AccountTreeControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
83
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,8BAA8B;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,8BAA8B;AAC7E,OAAO,KAAK,EACV,SAAS,EACT,mCAAmC,EACnC,qCAAqC,EACrC,kCAAkC,EAClC,0CAA0C,EAC1C,8CAA8C,EAC9C,4CAA4C,EAC5C,0CAA0C,EAC3C,sCAAsC;AACvC,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAC7D,OAAO,KAAK,EACV,+BAA+B,EAC/B,YAAY,EACb,qCAAqC;AACtC,OAAO,KAAK,EAAE,OAAO,IAAI,qBAAqB,EAAE,oCAAoC;AACpF,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACf,oCAAgC;AAEjC;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC;IACpC,OAAO,EAAE;QACP,EAAE,EAAE,eAAe,CAAC;QACpB,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,EAAE,qBAAqB,CAAC,IAAI,CAAC;IACjC,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;KACZ,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC;IACpC,OAAO,EAAE;QACP,IAAI,EAAE,YAAY,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;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A8C,GAC9C,0CAA0C,GAC1C,+BAA+B,GAC/B,qBAAqB,CAAC;AAE1B,MAAM,MAAM,4BAA4B,GACpC,mCAAmC,GACnC,kDAAkD,GAClD,kDAAkD,CAAC;AAEvD,MAAM,MAAM,qCAAqC,GAAG,0BAA0B,CAC5E,OAAO,cAAc,EACrB,0BAA0B,CAC3B,CAAC;AAEF,MAAM,MAAM,aAAa,GACrB,mCAAmC,GACnC,qCAAqC,GACrC,4CAA4C,CAAC;AAEjD,MAAM,MAAM,2BAA2B,GAAG,qCAAqC,CAAC;AAEhF,MAAM,MAAM,8BAA8B,GAAG,mBAAmB,CAC9D,OAAO,cAAc,EACrB,4BAA4B,GAAG,cAAc,EAC7C,2BAA2B,GAAG,aAAa,EAC3C,cAAc,CAAC,MAAM,CAAC,EACtB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC"}
package/dist/types.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AccountWalletCategory } from '@metamask/account-api';\nimport type { AccountGroupId, AccountWalletId } from '@metamask/account-api';\nimport type {\n AccountId,\n AccountsControllerAccountAddedEvent,\n AccountsControllerAccountRemovedEvent,\n AccountsControllerGetAccountAction,\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerListMultichainAccountsAction,\n AccountsControllerSelectedAccountChangeEvent,\n AccountsControllerSetSelectedAccountAction,\n} from '@metamask/accounts-controller';\nimport {\n type ControllerGetStateAction,\n type ControllerStateChangeEvent,\n type RestrictedMessenger,\n} from '@metamask/base-controller';\nimport type { EntropySourceId } from '@metamask/keyring-api';\nimport type {\n KeyringControllerGetStateAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { GetSnap as SnapControllerGetSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\n\nimport type {\n AccountTreeController,\n controllerName,\n} from './AccountTreeController';\n\n/**\n * Account wallet metadata for the \"entropy\" wallet category.\n */\nexport type AccountWalletEntropyMetadata = {\n type: AccountWalletCategory.Entropy;\n entropy: {\n id: EntropySourceId;\n index: number;\n };\n};\n\n/**\n * Account wallet metadata for the \"snap\" wallet category.\n */\nexport type AccountWalletSnapMetadata = {\n type: AccountWalletCategory.Snap;\n snap: {\n id: SnapId;\n };\n};\n\n/**\n * Account wallet metadata for the \"keyring\" wallet category.\n */\nexport type AccountWalletKeyringMetadata = {\n type: AccountWalletCategory.Keyring;\n keyring: {\n type: KeyringTypes;\n };\n};\n\n/**\n * Account wallet metadata for the \"keyring\" wallet category.\n */\nexport type AccountWalletCategoryMetadata =\n | AccountWalletEntropyMetadata\n | AccountWalletSnapMetadata\n | AccountWalletKeyringMetadata;\n\nexport type AccountWalletMetadata = {\n name: string;\n} & AccountWalletCategoryMetadata;\n\nexport type AccountGroupMetadata = {\n name: string;\n};\n\nexport type AccountGroupObject = {\n id: AccountGroupId;\n // Blockchain Accounts:\n accounts: AccountId[];\n metadata: AccountGroupMetadata;\n};\n\nexport type AccountWalletObject = {\n id: AccountWalletId;\n // Account groups OR Multichain accounts (once available).\n groups: {\n [groupId: AccountGroupId]: AccountGroupObject;\n };\n metadata: AccountWalletMetadata;\n};\n\nexport type AccountTreeControllerState = {\n accountTree: {\n wallets: {\n // Wallets:\n [walletId: AccountWalletId]: AccountWalletObject;\n };\n selectedAccountGroup: AccountGroupId | '';\n };\n};\n\nexport type AccountTreeControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AccountTreeControllerState\n>;\n\nexport type AccountTreeControllerSetSelectedAccountGroupAction = {\n type: `${typeof controllerName}:setSelectedAccountGroup`;\n handler: AccountTreeController['setSelectedAccountGroup'];\n};\n\nexport type AccountTreeControllerGetSelectedAccountGroupAction = {\n type: `${typeof controllerName}:getSelectedAccountGroup`;\n handler: AccountTreeController['getSelectedAccountGroup'];\n};\n\nexport type AllowedActions =\n | AccountsControllerGetAccountAction\n | AccountsControllerGetSelectedAccountAction\n | AccountsControllerListMultichainAccountsAction\n | AccountsControllerSetSelectedAccountAction\n | KeyringControllerGetStateAction\n | SnapControllerGetSnap;\n\nexport type AccountTreeControllerActions =\n | AccountTreeControllerGetStateAction\n | AccountTreeControllerSetSelectedAccountGroupAction\n | AccountTreeControllerGetSelectedAccountGroupAction;\n\nexport type AccountTreeControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AccountTreeControllerState\n>;\n\nexport type AllowedEvents =\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRemovedEvent\n | AccountsControllerSelectedAccountChangeEvent;\n\nexport type AccountTreeControllerEvents = AccountTreeControllerStateChangeEvent;\n\nexport type AccountTreeControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AccountTreeControllerActions | AllowedActions,\n AccountTreeControllerEvents | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\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-bd86fa14",
3
+ "version": "0.7.0-preview-3f5f144a",
4
4
  "description": "Controller to group account together based on some pre-defined rules",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -53,8 +53,8 @@
53
53
  "lodash": "^4.17.21"
54
54
  },
55
55
  "devDependencies": {
56
- "@metamask/account-api": "^0.2.0",
57
- "@metamask/accounts-controller": "^32.0.0",
56
+ "@metamask/account-api": "^0.3.0",
57
+ "@metamask/accounts-controller": "^32.0.1",
58
58
  "@metamask/auto-changelog": "^3.4.4",
59
59
  "@metamask/keyring-api": "^19.0.0",
60
60
  "@metamask/keyring-controller": "^22.1.0",
@@ -70,7 +70,7 @@
70
70
  "webextension-polyfill": "^0.12.0"
71
71
  },
72
72
  "peerDependencies": {
73
- "@metamask/account-api": "^0.2.0",
73
+ "@metamask/account-api": "^0.3.0",
74
74
  "@metamask/accounts-controller": "^32.0.0",
75
75
  "@metamask/keyring-controller": "^22.0.0",
76
76
  "@metamask/providers": "^22.0.0",
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
- if (kind === "m") throw new TypeError("Private method is not writable");
4
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
- 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");
6
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
- };
8
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
- };
13
- var _EntropySourceWalletRule_wallets;
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.EntropySourceWalletRule = exports.EntropySourceWallet = void 0;
16
- const account_api_1 = require("@metamask/account-api");
17
- const keyring_controller_1 = require("@metamask/keyring-controller");
18
- const utils_1 = require("./utils.cjs");
19
- const WalletRule_1 = require("./WalletRule.cjs");
20
- const AccountTreeWallet_1 = require("../AccountTreeWallet.cjs");
21
- class EntropySourceWallet extends AccountTreeWallet_1.MutableAccountTreeWallet {
22
- constructor(messenger, entropySource) {
23
- super(messenger, account_api_1.AccountWalletCategory.Entropy, entropySource);
24
- this.entropySource = entropySource;
25
- }
26
- static toAccountWalletId(entropySource) {
27
- return (0, account_api_1.toAccountWalletId)(account_api_1.AccountWalletCategory.Entropy, entropySource);
28
- }
29
- static getEntropySourceIndex(keyrings, entropySource) {
30
- return keyrings
31
- .filter((keyring) => keyring.type === keyring_controller_1.KeyringTypes.hd)
32
- .findIndex((keyring) => keyring.metadata.id === entropySource);
33
- }
34
- getDefaultName() {
35
- const { keyrings } = this.messenger.call('KeyringController:getState');
36
- const index = EntropySourceWallet.getEntropySourceIndex(keyrings, this.entropySource);
37
- if (index === -1) {
38
- // NOTE: This should never really fail, as we checked for this precondition
39
- // during rule matching.
40
- throw new Error('Unable to get index for entropy source');
41
- }
42
- return `Wallet ${index + 1}`; // Use human indexing.
43
- }
44
- }
45
- exports.EntropySourceWallet = EntropySourceWallet;
46
- class EntropySourceWalletRule extends WalletRule_1.BaseWalletRule {
47
- constructor(messenger) {
48
- super(messenger);
49
- _EntropySourceWalletRule_wallets.set(this, void 0);
50
- __classPrivateFieldSet(this, _EntropySourceWalletRule_wallets, new Map(), "f");
51
- }
52
- match(account) {
53
- let entropySource;
54
- if ((0, utils_1.hasKeyringType)(account, keyring_controller_1.KeyringTypes.hd)) {
55
- // TODO: Maybe use superstruct to validate the structure of HD account since they are not strongly-typed for now?
56
- if (!account.options.entropySource) {
57
- console.warn("! Found an HD account with no entropy source: account won't be associated to its wallet");
58
- return undefined;
59
- }
60
- entropySource = account.options.entropySource;
61
- }
62
- // TODO: For now, we're not checking if the Snap is a preinstalled one, and we probably should...
63
- if ((0, utils_1.hasKeyringType)(account, keyring_controller_1.KeyringTypes.snap) &&
64
- account.metadata.snap?.enabled) {
65
- // Not all Snaps have an entropy-source and options are not typed yet, so we have to check manually here.
66
- if (account.options.entropySource) {
67
- // We blindly trust the `entropySource` for now, but it could be wrong since it comes from a Snap.
68
- entropySource = account.options.entropySource;
69
- }
70
- }
71
- if (!entropySource) {
72
- return undefined;
73
- }
74
- // NOTE: We make this check now, so that we are guaranteed that `getDefaultName` will never fail if we
75
- // pass that point:
76
- // ------------------------------------------------------------------------------------------------------
77
- // We check if we can get the name for that entropy source, if not this means this entropy does not match
78
- // any HD keyrings, thus, is invalid (this account will be grouped by another rule).
79
- const { keyrings } = this.messenger.call('KeyringController:getState');
80
- if (EntropySourceWallet.getEntropySourceIndex(keyrings, entropySource) === -1) {
81
- console.warn('! Tried to name a wallet using an unknown entropy, this should not be possible.');
82
- return undefined;
83
- }
84
- // Check if a wallet already exists for that entropy source.
85
- let wallet = __classPrivateFieldGet(this, _EntropySourceWalletRule_wallets, "f").get(EntropySourceWallet.toAccountWalletId(entropySource));
86
- if (!wallet) {
87
- wallet = new EntropySourceWallet(this.messenger, entropySource);
88
- __classPrivateFieldGet(this, _EntropySourceWalletRule_wallets, "f").set(wallet.id, wallet);
89
- }
90
- // This will automatically creates the group if it's missing.
91
- const group = wallet.addAccount(account);
92
- return {
93
- wallet,
94
- group,
95
- };
96
- }
97
- }
98
- exports.EntropySourceWalletRule = EntropySourceWalletRule;
99
- _EntropySourceWalletRule_wallets = new WeakMap();
100
- //# sourceMappingURL=EntropySourceWalletRule.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EntropySourceWalletRule.cjs","sourceRoot":"","sources":["../../src/rules/EntropySourceWalletRule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,uDAG+B;AAE/B,qEAA4D;AAG5D,uCAAyC;AAEzC,iDAA8C;AAE9C,gEAAgE;AAEhE,MAAa,mBAAoB,SAAQ,4CAAwB;IAG/D,YACE,SAAyC,EACzC,aAAqB;QAErB,KAAK,CAAC,SAAS,EAAE,mCAAqB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAC/D,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,aAAqB;QAC5C,OAAO,IAAA,+BAAiB,EAAC,mCAAqB,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,CAAC,qBAAqB,CAC1B,QAAyB,EACzB,aAAqB;QAErB,OAAO,QAAQ;aACZ,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAM,iCAAY,CAAC,EAAa,CAAC;aACjE,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,O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GAAG,OAAO,CAAC,OAAO,CAAC,aAAuB,CAAC;aACzD;SACF;QAED,IAAI,CAAC,aAAa,EAAE;YAClB,OAAO,SAAS,CAAC;SAClB;QAED,sGAAsG;QACtG,mBAAmB;QACnB,yGAAyG;QACzG,yGAAyG;QACzG,oFAAoF;QACpF,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACvE,IACE,mBAAmB,CAAC,qBAAqB,CAAC,QAAQ,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC,EACzE;YACA,OAAO,CAAC,IAAI,CACV,iFAAiF,CAClF,CAAC;YACF,OAAO,SAAS,CAAC;SAClB;QAED,4DAA4D;QAC5D,IAAI,MAAM,GAAG,uBAAA,IAAI,wCAAS,CAAC,GAAG,CAC5B,mBAAmB,CAAC,iBAAiB,CAAC,aAAa,CAAC,CACrD,CAAC;QACF,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;YAChE,uBAAA,IAAI,wCAAS,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;SACtC;QAED,6DAA6D;QAC7D,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QAEzC,OAAO;YACL,MAAM;YACN,KAAK;SACN,CAAC;IACJ,CAAC;CACF;AAxED,0DAwEC","sourcesContent":["import type { AccountWalletId } from '@metamask/account-api';\nimport {\n AccountWalletCategory,\n toAccountWalletId,\n} from '@metamask/account-api';\nimport type { KeyringObject } from '@metamask/keyring-controller';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport { hasKeyringType } from './utils';\nimport type { WalletRuleMatch } from './WalletRule';\nimport { BaseWalletRule } from './WalletRule';\nimport type { AccountTreeControllerMessenger } from '../AccountTreeController';\nimport { MutableAccountTreeWallet } from '../AccountTreeWallet';\n\nexport class EntropySourceWallet extends MutableAccountTreeWallet {\n readonly entropySource: string;\n\n constructor(\n messenger: AccountTreeControllerMessenger,\n entropySource: string,\n ) {\n super(messenger, AccountWalletCategory.Entropy, entropySource);\n this.entropySource = entropySource;\n }\n\n static toAccountWalletId(entropySource: string) {\n return toAccountWalletId(AccountWalletCategory.Entropy, entropySource);\n }\n\n static getEntropySourceIndex(\n keyrings: KeyringObject[],\n entropySource: string,\n ) {\n return keyrings\n .filter((keyring) => keyring.type === (KeyringTypes.hd as string))\n .findIndex((keyring) => keyring.metadata.id === entropySource);\n }\n\n getDefaultName(): string {\n const { keyrings } = this.messenger.call('KeyringController:getState');\n\n const index = EntropySourceWallet.getEntropySourceIndex(\n keyrings,\n this.entropySource,\n );\n if (index === -1) {\n // NOTE: This should never really fail, as we checked for this precondition\n // during rule matching.\n throw new Error('Unable to get index for entropy source');\n }\n\n return `Wallet ${index + 1}`; // Use human indexing.\n }\n}\n\nexport class EntropySourceWalletRule extends BaseWalletRule {\n readonly #wallets: Map<AccountWalletId, EntropySourceWallet>;\n\n constructor(messenger: AccountTreeControllerMessenger) {\n super(messenger);\n\n this.#wallets = new Map();\n }\n\n match(account: InternalAccount): WalletRuleMatch | undefined {\n let entropySource: string | undefined;\n\n if (hasKeyringType(account, KeyringTypes.hd)) {\n // TODO: Maybe use superstruct to validate the structure of HD account since they are not strongly-typed for now?\n if (!account.options.entropySource) {\n console.warn(\n \"! Found an HD account with no entropy source: account won't be associated to its wallet\",\n );\n return undefined;\n }\n\n entropySource = account.options.entropySource as string;\n }\n\n // TODO: For now, we're not checking if the Snap is a preinstalled one, and we probably should...\n if (\n hasKeyringType(account, KeyringTypes.snap) &&\n account.metadata.snap?.enabled\n ) {\n // Not all Snaps have an entropy-source and options are not typed yet, so we have to check manually here.\n if (account.options.entropySource) {\n // We blindly trust the `entropySource` for now, but it could be wrong since it comes from a Snap.\n entropySource = account.options.entropySource as string;\n }\n }\n\n if (!entropySource) {\n return undefined;\n }\n\n // NOTE: We make this check now, so that we are guaranteed that `getDefaultName` will never fail if we\n // pass that point:\n // ------------------------------------------------------------------------------------------------------\n // We check if we can get the name for that entropy source, if not this means this entropy does not match\n // any HD keyrings, thus, is invalid (this account will be grouped by another rule).\n const { keyrings } = this.messenger.call('KeyringController:getState');\n if (\n EntropySourceWallet.getEntropySourceIndex(keyrings, entropySource) === -1\n ) {\n console.warn(\n '! Tried to name a wallet using an unknown entropy, this should not be possible.',\n );\n return undefined;\n }\n\n // Check if a wallet already exists for that entropy source.\n let wallet = this.#wallets.get(\n EntropySourceWallet.toAccountWalletId(entropySource),\n );\n if (!wallet) {\n wallet = new EntropySourceWallet(this.messenger, entropySource);\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"]}
@@ -1,19 +0,0 @@
1
- import type { KeyringObject } from "@metamask/keyring-controller";
2
- import type { InternalAccount } from "@metamask/keyring-internal-api";
3
- import type { WalletRuleMatch } from "./WalletRule.cjs";
4
- import { BaseWalletRule } from "./WalletRule.cjs";
5
- import type { AccountTreeControllerMessenger } from "../AccountTreeController.cjs";
6
- import { MutableAccountTreeWallet } from "../AccountTreeWallet.cjs";
7
- export declare class EntropySourceWallet extends MutableAccountTreeWallet {
8
- readonly entropySource: string;
9
- constructor(messenger: AccountTreeControllerMessenger, entropySource: string);
10
- static toAccountWalletId(entropySource: string): `entropy:${string}` | `keyring:${string}` | `snap:${string}`;
11
- static getEntropySourceIndex(keyrings: KeyringObject[], entropySource: string): number;
12
- getDefaultName(): string;
13
- }
14
- export declare class EntropySourceWalletRule extends BaseWalletRule {
15
- #private;
16
- constructor(messenger: AccountTreeControllerMessenger);
17
- match(account: InternalAccount): WalletRuleMatch | undefined;
18
- }
19
- //# sourceMappingURL=EntropySourceWalletRule.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EntropySourceWalletRule.d.cts","sourceRoot":"","sources":["../../src/rules/EntropySourceWalletRule.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,qCAAqC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AACpD,OAAO,EAAE,cAAc,EAAE,yBAAqB;AAC9C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,iCAA6B;AAEhE,qBAAa,mBAAoB,SAAQ,wBAAwB;IAC/D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAG7B,SAAS,EAAE,8BAA8B,EACzC,aAAa,EAAE,MAAM;IAMvB,MAAM,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM;IAI9C,MAAM,CAAC,qBAAqB,CAC1B,QAAQ,EAAE,aAAa,EAAE,EACzB,aAAa,EAAE,MAAM;IAOvB,cAAc,IAAI,MAAM;CAezB;AAED,qBAAa,uBAAwB,SAAQ,cAAc;;gBAG7C,SAAS,EAAE,8BAA8B;IAMrD,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;CA+D7D"}
@@ -1,19 +0,0 @@
1
- import type { KeyringObject } from "@metamask/keyring-controller";
2
- import type { InternalAccount } from "@metamask/keyring-internal-api";
3
- import type { WalletRuleMatch } from "./WalletRule.mjs";
4
- import { BaseWalletRule } from "./WalletRule.mjs";
5
- import type { AccountTreeControllerMessenger } from "../AccountTreeController.mjs";
6
- import { MutableAccountTreeWallet } from "../AccountTreeWallet.mjs";
7
- export declare class EntropySourceWallet extends MutableAccountTreeWallet {
8
- readonly entropySource: string;
9
- constructor(messenger: AccountTreeControllerMessenger, entropySource: string);
10
- static toAccountWalletId(entropySource: string): `entropy:${string}` | `keyring:${string}` | `snap:${string}`;
11
- static getEntropySourceIndex(keyrings: KeyringObject[], entropySource: string): number;
12
- getDefaultName(): string;
13
- }
14
- export declare class EntropySourceWalletRule extends BaseWalletRule {
15
- #private;
16
- constructor(messenger: AccountTreeControllerMessenger);
17
- match(account: InternalAccount): WalletRuleMatch | undefined;
18
- }
19
- //# sourceMappingURL=EntropySourceWalletRule.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EntropySourceWalletRule.d.mts","sourceRoot":"","sources":["../../src/rules/EntropySourceWalletRule.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,qCAAqC;AAElE,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAGtE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAqB;AACpD,OAAO,EAAE,cAAc,EAAE,yBAAqB;AAC9C,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,iCAA6B;AAEhE,qBAAa,mBAAoB,SAAQ,wBAAwB;IAC/D,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;gBAG7B,SAAS,EAAE,8BAA8B,EACzC,aAAa,EAAE,MAAM;IAMvB,MAAM,CAAC,iBAAiB,CAAC,aAAa,EAAE,MAAM;IAI9C,MAAM,CAAC,qBAAqB,CAC1B,QAAQ,EAAE,aAAa,EAAE,EACzB,aAAa,EAAE,MAAM;IAOvB,cAAc,IAAI,MAAM;CAezB;AAED,qBAAa,uBAAwB,SAAQ,cAAc;;gBAG7C,SAAS,EAAE,8BAA8B;IAMrD,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe,GAAG,SAAS;CA+D7D"}