@metamask-previews/account-api 0.2.0-e017e7a → 0.5.0-0e28ac0

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 (56) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/api/group.cjs +13 -1
  3. package/dist/api/group.cjs.map +1 -1
  4. package/dist/api/group.d.cts +23 -3
  5. package/dist/api/group.d.cts.map +1 -1
  6. package/dist/api/group.d.mts +23 -3
  7. package/dist/api/group.d.mts.map +1 -1
  8. package/dist/api/group.mjs +12 -0
  9. package/dist/api/group.mjs.map +1 -1
  10. package/dist/api/multichain/group.cjs +42 -0
  11. package/dist/api/multichain/group.cjs.map +1 -0
  12. package/dist/api/multichain/group.d.cts +68 -0
  13. package/dist/api/multichain/group.d.cts.map +1 -0
  14. package/dist/api/multichain/group.d.mts +68 -0
  15. package/dist/api/multichain/group.d.mts.map +1 -0
  16. package/dist/api/multichain/group.mjs +37 -0
  17. package/dist/api/multichain/group.mjs.map +1 -0
  18. package/dist/api/multichain/index.cjs +1 -1
  19. package/dist/api/multichain/index.cjs.map +1 -1
  20. package/dist/api/multichain/index.d.cts +1 -1
  21. package/dist/api/multichain/index.d.cts.map +1 -1
  22. package/dist/api/multichain/index.d.mts +1 -1
  23. package/dist/api/multichain/index.d.mts.map +1 -1
  24. package/dist/api/multichain/index.mjs +1 -1
  25. package/dist/api/multichain/index.mjs.map +1 -1
  26. package/dist/api/multichain/wallet.cjs +1 -140
  27. package/dist/api/multichain/wallet.cjs.map +1 -1
  28. package/dist/api/multichain/wallet.d.cts +11 -45
  29. package/dist/api/multichain/wallet.d.cts.map +1 -1
  30. package/dist/api/multichain/wallet.d.mts +11 -45
  31. package/dist/api/multichain/wallet.d.mts.map +1 -1
  32. package/dist/api/multichain/wallet.mjs +2 -139
  33. package/dist/api/multichain/wallet.mjs.map +1 -1
  34. package/dist/api/provider.cjs.map +1 -1
  35. package/dist/api/provider.d.cts +2 -3
  36. package/dist/api/provider.d.cts.map +1 -1
  37. package/dist/api/provider.d.mts +2 -3
  38. package/dist/api/provider.d.mts.map +1 -1
  39. package/dist/api/provider.mjs.map +1 -1
  40. package/dist/api/wallet.cjs +19 -23
  41. package/dist/api/wallet.cjs.map +1 -1
  42. package/dist/api/wallet.d.cts +20 -19
  43. package/dist/api/wallet.d.cts.map +1 -1
  44. package/dist/api/wallet.d.mts +20 -19
  45. package/dist/api/wallet.d.mts.map +1 -1
  46. package/dist/api/wallet.mjs +18 -22
  47. package/dist/api/wallet.mjs.map +1 -1
  48. package/package.json +3 -3
  49. package/dist/api/multichain/account.cjs +0 -213
  50. package/dist/api/multichain/account.cjs.map +0 -1
  51. package/dist/api/multichain/account.d.cts +0 -103
  52. package/dist/api/multichain/account.d.cts.map +0 -1
  53. package/dist/api/multichain/account.d.mts +0 -103
  54. package/dist/api/multichain/account.d.mts.map +0 -1
  55. package/dist/api/multichain/account.mjs +0 -206
  56. package/dist/api/multichain/account.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,8 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.5.0]
11
+
12
+ ### Added
13
+
14
+ - Add `Account{Wallet,Group}IdOf` type utility ([#331](https://github.com/MetaMask/accounts/pull/331))
15
+
16
+ ### Changed
17
+
18
+ - Use generic type for `toAccount{Wallet,Group}Id` ([#331](https://github.com/MetaMask/accounts/pull/331))
19
+
20
+ ## [0.4.0]
21
+
22
+ ### Added
23
+
24
+ - Add `AccountGroupType` + `AccountGroup.type` ([#329](https://github.com/MetaMask/accounts/pull/329))
25
+
26
+ ### Changed
27
+
28
+ - **BREAKING:** Rename `AccountWalletCategory` to `AccountWalletType` + `category` to `type` ([#328](https://github.com/MetaMask/accounts/pull/328))
29
+ - This name better reflects other patterns we already have in place elsewhere.
30
+
31
+ ## [0.3.0]
32
+
10
33
  ### Added
11
34
 
35
+ - Add `Bip44Account<Account>` type + `isBip44Account` helper ([#319](https://github.com/MetaMask/accounts/pull/319))
12
36
  - Add `MultichainAccountWallet.sync` method ([#321](https://github.com/MetaMask/accounts/pull/321))
13
37
  - This can be used to force wallet synchronization if new accounts are available on the account providers.
14
38
 
@@ -35,6 +59,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
35
59
 
36
60
  - Add `AccountGroup` and `AccountWallet` ([#307](https://github.com/MetaMask/accounts/pull/307))
37
61
 
38
- [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.2.0...HEAD
62
+ [Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.5.0...HEAD
63
+ [0.5.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.4.0...@metamask/account-api@0.5.0
64
+ [0.4.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.3.0...@metamask/account-api@0.4.0
65
+ [0.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.2.0...@metamask/account-api@0.3.0
39
66
  [0.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.1.0...@metamask/account-api@0.2.0
40
67
  [0.1.0]: https://github.com/MetaMask/accounts/releases/tag/@metamask/account-api@0.1.0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_ACCOUNT_GROUP_UNIQUE_ID = void 0;
3
+ exports.AccountGroupType = exports.DEFAULT_ACCOUNT_GROUP_UNIQUE_ID = void 0;
4
4
  exports.toAccountGroupId = toAccountGroupId;
5
5
  exports.toDefaultAccountGroupId = toDefaultAccountGroupId;
6
6
  /**
@@ -10,6 +10,18 @@ exports.toDefaultAccountGroupId = toDefaultAccountGroupId;
10
10
  * an account wallet.
11
11
  */
12
12
  exports.DEFAULT_ACCOUNT_GROUP_UNIQUE_ID = 'default';
13
+ /**
14
+ * Account group object.
15
+ *
16
+ * Each group types groups accounts using different criterias.
17
+ */
18
+ var AccountGroupType;
19
+ (function (AccountGroupType) {
20
+ /** Group that represents a multichain account. */
21
+ AccountGroupType["MultichainAccount"] = "multichain-account";
22
+ /** Group that represents a single account. */
23
+ AccountGroupType["SingleAccount"] = "single-account";
24
+ })(AccountGroupType || (exports.AccountGroupType = AccountGroupType = {}));
13
25
  /**
14
26
  * Convert a wallet ID and a unique ID, to a group ID.
15
27
  *
@@ -1 +1 @@
1
- {"version":3,"file":"group.cjs","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":";;;AAuDA,4CAKC;AAQD,0DAIC;AAnED;;;;;GAKG;AACU,QAAA,+BAA+B,GAAW,SAAS,CAAC;AAqCjE;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,QAAyB,EACzB,EAAU;IAEV,OAAO,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,QAAyB;IAEzB,OAAO,gBAAgB,CAAC,QAAQ,EAAE,uCAA+B,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountWallet, AccountWalletId } from './wallet';\n\n/**\n * Default account group unique ID.\n *\n * This constant can be used to reference the \"default\" group from\n * an account wallet.\n */\nexport const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string = 'default';\n\n/**\n * Account group ID.\n */\nexport type AccountGroupId = `${AccountWalletId}/${string}`;\n\n/**\n * Account group that can hold multiple accounts.\n */\nexport type AccountGroup<Account extends KeyringAccount> = {\n /**\n * Account group ID.\n */\n get id(): AccountGroupId;\n\n /**\n * Account wallet (parent).\n */\n get wallet(): AccountWallet<Account>;\n\n /**\n * Gets the accounts for this account group.\n *\n * @returns The accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The account or undefined if not found.\n */\n getAccount(id: Account['id']): Account | undefined;\n};\n\n/**\n * Convert a wallet ID and a unique ID, to a group ID.\n *\n * @param walletId - A wallet ID.\n * @param id - A unique ID.\n * @returns A group ID.\n */\nexport function toAccountGroupId(\n walletId: AccountWalletId,\n id: string,\n): AccountGroupId {\n return `${walletId}/${id}`;\n}\n\n/**\n * Convert a wallet ID to the default group ID.\n *\n * @param walletId - A wallet ID.\n * @returns The default group ID.\n */\nexport function toDefaultAccountGroupId(\n walletId: AccountWalletId,\n): AccountGroupId {\n return toAccountGroupId(walletId, DEFAULT_ACCOUNT_GROUP_UNIQUE_ID);\n}\n"]}
1
+ {"version":3,"file":"group.cjs","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":";;;AAqFA,4CAKC;AAQD,0DAOC;AA/FD;;;;;GAKG;AACU,QAAA,+BAA+B,GAAW,SAAS,CAAC;AAEjE;;;;GAIG;AACH,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,kDAAkD;IAClD,4DAAwC,CAAA;IAExC,8CAA8C;IAC9C,oDAAgC,CAAA;AAClC,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAiDD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,QAAuC,EACvC,EAAU;IAEV,OAAO,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,QAAuC;IAEvC,OAAO,gBAAgB,CACrB,QAAQ,EACR,uCAA+B,CAChC,CAAC;AACJ,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type {\n AccountWallet,\n AccountWalletId,\n AccountWalletIdOf,\n AccountWalletType,\n} from './wallet';\n\n/**\n * Default account group unique ID.\n *\n * This constant can be used to reference the \"default\" group from\n * an account wallet.\n */\nexport const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string = 'default';\n\n/**\n * Account group object.\n *\n * Each group types groups accounts using different criterias.\n */\nexport enum AccountGroupType {\n /** Group that represents a multichain account. */\n MultichainAccount = 'multichain-account',\n\n /** Group that represents a single account. */\n SingleAccount = 'single-account',\n}\n\n/**\n * Account group ID.\n */\nexport type AccountGroupId = `${AccountWalletId}/${string}`;\n\n/**\n * Account group that can hold multiple accounts.\n */\nexport type AccountGroup<Account extends KeyringAccount> = {\n /**\n * Account group ID.\n */\n get id(): AccountGroupId;\n\n /**\n * Account group type.\n */\n get type(): AccountGroupType;\n\n /**\n * Account wallet (parent).\n */\n get wallet(): AccountWallet<Account>;\n\n /**\n * Gets the accounts for this account group.\n *\n * @returns The accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The account or undefined if not found.\n */\n getAccount(id: Account['id']): Account | undefined;\n};\n\n/**\n * Type utility to compute a constrained {@link AccountGroupId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountGroupIdOf<WalletType extends AccountWalletType> =\n `${AccountWalletIdOf<WalletType>}/${string}`;\n\n/**\n * Convert a wallet ID and a unique ID, to a group ID.\n *\n * @param walletId - A wallet ID.\n * @param id - A unique ID.\n * @returns A group ID.\n */\nexport function toAccountGroupId<WalletType extends AccountWalletType>(\n walletId: AccountWalletIdOf<WalletType>,\n id: string,\n): AccountGroupIdOf<WalletType> {\n return `${walletId}/${id}`;\n}\n\n/**\n * Convert a wallet ID to the default group ID.\n *\n * @param walletId - A wallet ID.\n * @returns The default group ID.\n */\nexport function toDefaultAccountGroupId<WalletType extends AccountWalletType>(\n walletId: AccountWalletIdOf<WalletType>,\n): AccountGroupIdOf<WalletType> {\n return toAccountGroupId<WalletType>(\n walletId,\n DEFAULT_ACCOUNT_GROUP_UNIQUE_ID,\n );\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { KeyringAccount } from "@metamask/keyring-api";
2
- import type { AccountWallet, AccountWalletId } from "./wallet.cjs";
2
+ import type { AccountWallet, AccountWalletId, AccountWalletIdOf, AccountWalletType } from "./wallet.cjs";
3
3
  /**
4
4
  * Default account group unique ID.
5
5
  *
@@ -7,6 +7,17 @@ import type { AccountWallet, AccountWalletId } from "./wallet.cjs";
7
7
  * an account wallet.
8
8
  */
9
9
  export declare const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string;
10
+ /**
11
+ * Account group object.
12
+ *
13
+ * Each group types groups accounts using different criterias.
14
+ */
15
+ export declare enum AccountGroupType {
16
+ /** Group that represents a multichain account. */
17
+ MultichainAccount = "multichain-account",
18
+ /** Group that represents a single account. */
19
+ SingleAccount = "single-account"
20
+ }
10
21
  /**
11
22
  * Account group ID.
12
23
  */
@@ -19,6 +30,10 @@ export type AccountGroup<Account extends KeyringAccount> = {
19
30
  * Account group ID.
20
31
  */
21
32
  get id(): AccountGroupId;
33
+ /**
34
+ * Account group type.
35
+ */
36
+ get type(): AccountGroupType;
22
37
  /**
23
38
  * Account wallet (parent).
24
39
  */
@@ -37,6 +52,11 @@ export type AccountGroup<Account extends KeyringAccount> = {
37
52
  */
38
53
  getAccount(id: Account['id']): Account | undefined;
39
54
  };
55
+ /**
56
+ * Type utility to compute a constrained {@link AccountGroupId} type given a
57
+ * specifc {@link AccountWalletType}.
58
+ */
59
+ export type AccountGroupIdOf<WalletType extends AccountWalletType> = `${AccountWalletIdOf<WalletType>}/${string}`;
40
60
  /**
41
61
  * Convert a wallet ID and a unique ID, to a group ID.
42
62
  *
@@ -44,12 +64,12 @@ export type AccountGroup<Account extends KeyringAccount> = {
44
64
  * @param id - A unique ID.
45
65
  * @returns A group ID.
46
66
  */
47
- export declare function toAccountGroupId(walletId: AccountWalletId, id: string): AccountGroupId;
67
+ export declare function toAccountGroupId<WalletType extends AccountWalletType>(walletId: AccountWalletIdOf<WalletType>, id: string): AccountGroupIdOf<WalletType>;
48
68
  /**
49
69
  * Convert a wallet ID to the default group ID.
50
70
  *
51
71
  * @param walletId - A wallet ID.
52
72
  * @returns The default group ID.
53
73
  */
54
- export declare function toDefaultAccountGroupId(walletId: AccountWalletId): AccountGroupId;
74
+ export declare function toDefaultAccountGroupId<WalletType extends AccountWalletType>(walletId: AccountWalletIdOf<WalletType>): AccountGroupIdOf<WalletType>;
55
75
  //# sourceMappingURL=group.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.cts","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAiB;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAkB,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,cAAc,IAAI;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI,cAAc,CAAC;IAEzB;;OAEG;IACH,IAAI,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IAErC;;;;OAIG;IACH,WAAW,IAAI,OAAO,EAAE,CAAC;IAEzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,EACzB,EAAE,EAAE,MAAM,GACT,cAAc,CAEhB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,eAAe,GACxB,cAAc,CAEhB"}
1
+ {"version":3,"file":"group.d.cts","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,qBAAiB;AAElB;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAkB,CAAC;AAEjE;;;;GAIG;AACH,oBAAY,gBAAgB;IAC1B,kDAAkD;IAClD,iBAAiB,uBAAuB;IAExC,8CAA8C;IAC9C,aAAa,mBAAmB;CACjC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,cAAc,IAAI;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI,cAAc,CAAC;IAEzB;;OAEG;IACH,IAAI,IAAI,IAAI,gBAAgB,CAAC;IAE7B;;OAEG;IACH,IAAI,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IAErC;;;;OAIG;IACH,WAAW,IAAI,OAAO,EAAE,CAAC;IAEzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,UAAU,SAAS,iBAAiB,IAC/D,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,iBAAiB,EACnE,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,EACvC,EAAE,EAAE,MAAM,GACT,gBAAgB,CAAC,UAAU,CAAC,CAE9B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,SAAS,iBAAiB,EAC1E,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,GACtC,gBAAgB,CAAC,UAAU,CAAC,CAK9B"}
@@ -1,5 +1,5 @@
1
1
  import type { KeyringAccount } from "@metamask/keyring-api";
2
- import type { AccountWallet, AccountWalletId } from "./wallet.mjs";
2
+ import type { AccountWallet, AccountWalletId, AccountWalletIdOf, AccountWalletType } from "./wallet.mjs";
3
3
  /**
4
4
  * Default account group unique ID.
5
5
  *
@@ -7,6 +7,17 @@ import type { AccountWallet, AccountWalletId } from "./wallet.mjs";
7
7
  * an account wallet.
8
8
  */
9
9
  export declare const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string;
10
+ /**
11
+ * Account group object.
12
+ *
13
+ * Each group types groups accounts using different criterias.
14
+ */
15
+ export declare enum AccountGroupType {
16
+ /** Group that represents a multichain account. */
17
+ MultichainAccount = "multichain-account",
18
+ /** Group that represents a single account. */
19
+ SingleAccount = "single-account"
20
+ }
10
21
  /**
11
22
  * Account group ID.
12
23
  */
@@ -19,6 +30,10 @@ export type AccountGroup<Account extends KeyringAccount> = {
19
30
  * Account group ID.
20
31
  */
21
32
  get id(): AccountGroupId;
33
+ /**
34
+ * Account group type.
35
+ */
36
+ get type(): AccountGroupType;
22
37
  /**
23
38
  * Account wallet (parent).
24
39
  */
@@ -37,6 +52,11 @@ export type AccountGroup<Account extends KeyringAccount> = {
37
52
  */
38
53
  getAccount(id: Account['id']): Account | undefined;
39
54
  };
55
+ /**
56
+ * Type utility to compute a constrained {@link AccountGroupId} type given a
57
+ * specifc {@link AccountWalletType}.
58
+ */
59
+ export type AccountGroupIdOf<WalletType extends AccountWalletType> = `${AccountWalletIdOf<WalletType>}/${string}`;
40
60
  /**
41
61
  * Convert a wallet ID and a unique ID, to a group ID.
42
62
  *
@@ -44,12 +64,12 @@ export type AccountGroup<Account extends KeyringAccount> = {
44
64
  * @param id - A unique ID.
45
65
  * @returns A group ID.
46
66
  */
47
- export declare function toAccountGroupId(walletId: AccountWalletId, id: string): AccountGroupId;
67
+ export declare function toAccountGroupId<WalletType extends AccountWalletType>(walletId: AccountWalletIdOf<WalletType>, id: string): AccountGroupIdOf<WalletType>;
48
68
  /**
49
69
  * Convert a wallet ID to the default group ID.
50
70
  *
51
71
  * @param walletId - A wallet ID.
52
72
  * @returns The default group ID.
53
73
  */
54
- export declare function toDefaultAccountGroupId(walletId: AccountWalletId): AccountGroupId;
74
+ export declare function toDefaultAccountGroupId<WalletType extends AccountWalletType>(walletId: AccountWalletIdOf<WalletType>): AccountGroupIdOf<WalletType>;
55
75
  //# sourceMappingURL=group.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"group.d.mts","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAiB;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAkB,CAAC;AAEjE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,cAAc,IAAI;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI,cAAc,CAAC;IAEzB;;OAEG;IACH,IAAI,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IAErC;;;;OAIG;IACH,WAAW,IAAI,OAAO,EAAE,CAAC;IAEzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,EACzB,EAAE,EAAE,MAAM,GACT,cAAc,CAEhB;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,eAAe,GACxB,cAAc,CAEhB"}
1
+ {"version":3,"file":"group.d.mts","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA8B;AAG5D,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,qBAAiB;AAElB;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,EAAE,MAAkB,CAAC;AAEjE;;;;GAIG;AACH,oBAAY,gBAAgB;IAC1B,kDAAkD;IAClD,iBAAiB,uBAAuB;IAExC,8CAA8C;IAC9C,aAAa,mBAAmB;CACjC;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,eAAe,IAAI,MAAM,EAAE,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,OAAO,SAAS,cAAc,IAAI;IACzD;;OAEG;IACH,IAAI,EAAE,IAAI,cAAc,CAAC;IAEzB;;OAEG;IACH,IAAI,IAAI,IAAI,gBAAgB,CAAC;IAE7B;;OAEG;IACH,IAAI,MAAM,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC;IAErC;;;;OAIG;IACH,WAAW,IAAI,OAAO,EAAE,CAAC;IAEzB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;CACpD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,UAAU,SAAS,iBAAiB,IAC/D,GAAG,iBAAiB,CAAC,UAAU,CAAC,IAAI,MAAM,EAAE,CAAC;AAE/C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,iBAAiB,EACnE,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,EACvC,EAAE,EAAE,MAAM,GACT,gBAAgB,CAAC,UAAU,CAAC,CAE9B;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,SAAS,iBAAiB,EAC1E,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,GACtC,gBAAgB,CAAC,UAAU,CAAC,CAK9B"}
@@ -5,6 +5,18 @@
5
5
  * an account wallet.
6
6
  */
7
7
  export const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID = 'default';
8
+ /**
9
+ * Account group object.
10
+ *
11
+ * Each group types groups accounts using different criterias.
12
+ */
13
+ export var AccountGroupType;
14
+ (function (AccountGroupType) {
15
+ /** Group that represents a multichain account. */
16
+ AccountGroupType["MultichainAccount"] = "multichain-account";
17
+ /** Group that represents a single account. */
18
+ AccountGroupType["SingleAccount"] = "single-account";
19
+ })(AccountGroupType || (AccountGroupType = {}));
8
20
  /**
9
21
  * Convert a wallet ID and a unique ID, to a group ID.
10
22
  *
@@ -1 +1 @@
1
- {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAW,SAAS,CAAC;AAqCjE;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAyB,EACzB,EAAU;IAEV,OAAO,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAyB;IAEzB,OAAO,gBAAgB,CAAC,QAAQ,EAAE,+BAA+B,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountWallet, AccountWalletId } from './wallet';\n\n/**\n * Default account group unique ID.\n *\n * This constant can be used to reference the \"default\" group from\n * an account wallet.\n */\nexport const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string = 'default';\n\n/**\n * Account group ID.\n */\nexport type AccountGroupId = `${AccountWalletId}/${string}`;\n\n/**\n * Account group that can hold multiple accounts.\n */\nexport type AccountGroup<Account extends KeyringAccount> = {\n /**\n * Account group ID.\n */\n get id(): AccountGroupId;\n\n /**\n * Account wallet (parent).\n */\n get wallet(): AccountWallet<Account>;\n\n /**\n * Gets the accounts for this account group.\n *\n * @returns The accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The account or undefined if not found.\n */\n getAccount(id: Account['id']): Account | undefined;\n};\n\n/**\n * Convert a wallet ID and a unique ID, to a group ID.\n *\n * @param walletId - A wallet ID.\n * @param id - A unique ID.\n * @returns A group ID.\n */\nexport function toAccountGroupId(\n walletId: AccountWalletId,\n id: string,\n): AccountGroupId {\n return `${walletId}/${id}`;\n}\n\n/**\n * Convert a wallet ID to the default group ID.\n *\n * @param walletId - A wallet ID.\n * @returns The default group ID.\n */\nexport function toDefaultAccountGroupId(\n walletId: AccountWalletId,\n): AccountGroupId {\n return toAccountGroupId(walletId, DEFAULT_ACCOUNT_GROUP_UNIQUE_ID);\n}\n"]}
1
+ {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../src/api/group.ts"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAW,SAAS,CAAC;AAEjE;;;;GAIG;AACH,MAAM,CAAN,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,kDAAkD;IAClD,4DAAwC,CAAA;IAExC,8CAA8C;IAC9C,oDAAgC,CAAA;AAClC,CAAC,EANW,gBAAgB,KAAhB,gBAAgB,QAM3B;AAiDD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,QAAuC,EACvC,EAAU;IAEV,OAAO,GAAG,QAAQ,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,QAAuC;IAEvC,OAAO,gBAAgB,CACrB,QAAQ,EACR,+BAA+B,CAChC,CAAC;AACJ,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type {\n AccountWallet,\n AccountWalletId,\n AccountWalletIdOf,\n AccountWalletType,\n} from './wallet';\n\n/**\n * Default account group unique ID.\n *\n * This constant can be used to reference the \"default\" group from\n * an account wallet.\n */\nexport const DEFAULT_ACCOUNT_GROUP_UNIQUE_ID: string = 'default';\n\n/**\n * Account group object.\n *\n * Each group types groups accounts using different criterias.\n */\nexport enum AccountGroupType {\n /** Group that represents a multichain account. */\n MultichainAccount = 'multichain-account',\n\n /** Group that represents a single account. */\n SingleAccount = 'single-account',\n}\n\n/**\n * Account group ID.\n */\nexport type AccountGroupId = `${AccountWalletId}/${string}`;\n\n/**\n * Account group that can hold multiple accounts.\n */\nexport type AccountGroup<Account extends KeyringAccount> = {\n /**\n * Account group ID.\n */\n get id(): AccountGroupId;\n\n /**\n * Account group type.\n */\n get type(): AccountGroupType;\n\n /**\n * Account wallet (parent).\n */\n get wallet(): AccountWallet<Account>;\n\n /**\n * Gets the accounts for this account group.\n *\n * @returns The accounts.\n */\n getAccounts(): Account[];\n\n /**\n * Gets the account for a given account ID.\n *\n * @param id - Account ID.\n * @returns The account or undefined if not found.\n */\n getAccount(id: Account['id']): Account | undefined;\n};\n\n/**\n * Type utility to compute a constrained {@link AccountGroupId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountGroupIdOf<WalletType extends AccountWalletType> =\n `${AccountWalletIdOf<WalletType>}/${string}`;\n\n/**\n * Convert a wallet ID and a unique ID, to a group ID.\n *\n * @param walletId - A wallet ID.\n * @param id - A unique ID.\n * @returns A group ID.\n */\nexport function toAccountGroupId<WalletType extends AccountWalletType>(\n walletId: AccountWalletIdOf<WalletType>,\n id: string,\n): AccountGroupIdOf<WalletType> {\n return `${walletId}/${id}`;\n}\n\n/**\n * Convert a wallet ID to the default group ID.\n *\n * @param walletId - A wallet ID.\n * @returns The default group ID.\n */\nexport function toDefaultAccountGroupId<WalletType extends AccountWalletType>(\n walletId: AccountWalletIdOf<WalletType>,\n): AccountGroupIdOf<WalletType> {\n return toAccountGroupId<WalletType>(\n walletId,\n DEFAULT_ACCOUNT_GROUP_UNIQUE_ID,\n );\n}\n"]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toMultichainAccountGroupId = toMultichainAccountGroupId;
4
+ exports.isMultichainAccountGroupId = isMultichainAccountGroupId;
5
+ exports.getGroupIndexFromMultichainAccountId = getGroupIndexFromMultichainAccountId;
6
+ const wallet_1 = require("../wallet.cjs");
7
+ const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = new RegExp(`^${wallet_1.AccountWalletType.Entropy}:.*/(?<groupIndex>\\d+)$`, 'u');
8
+ /**
9
+ * Gets the multichain account group ID from its multichain account wallet ID and its index.
10
+ *
11
+ * @param walletId - Multichain account wallet ID.
12
+ * @param groupIndex - Index of that multichain account.
13
+ * @returns The multichain account ID.
14
+ */
15
+ function toMultichainAccountGroupId(walletId, groupIndex) {
16
+ return `${walletId}/${groupIndex}`;
17
+ }
18
+ /**
19
+ * Checks if the given value is {@link MultichainAccountGroupId}.
20
+ *
21
+ * @param value - The value to check.
22
+ * @returns Whether the value is a {@link MultichainAccountGroupId}.
23
+ */
24
+ function isMultichainAccountGroupId(value) {
25
+ return MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.test(value);
26
+ }
27
+ /**
28
+ * Gets the multichain account index from an account group ID.
29
+ *
30
+ * @param id - Multichain account ID.
31
+ * @returns The multichain account index if extractable, undefined otherwise.
32
+ */
33
+ function getGroupIndexFromMultichainAccountId(id) {
34
+ const matched = id.match(MULTICHAIN_ACCOUNT_GROUP_ID_REGEX);
35
+ if (matched?.groups?.groupIndex === undefined) {
36
+ // Unable to extract group index, even though, type wise, this should not
37
+ // be possible!
38
+ throw new Error('Unable to extract group index');
39
+ }
40
+ return Number(matched.groups.groupIndex);
41
+ }
42
+ //# sourceMappingURL=group.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.cjs","sourceRoot":"","sources":["../../../src/api/multichain/group.ts"],"names":[],"mappings":";;AAwEA,gEAKC;AAQD,gEAIC;AAQD,oFAWC;AAnGD,0CAA8C;AAE9C,MAAM,iCAAiC,GAAG,IAAI,MAAM,CAClD,IAAI,0BAAiB,CAAC,OAAO,0BAA0B,EACvD,GAAG,CACJ,CAAC;AAmDF;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACxC,QAAmC,EACnC,UAAkB;IAElB,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,0BAA0B,CACxC,KAAa;IAEb,OAAO,iCAAiC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,oCAAoC,CAClD,EAA4B;IAE5B,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC5D,IAAI,OAAO,EAAE,MAAM,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9C,yEAAyE;QACzE,eAAe;QACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { type KeyringAccount } from '@metamask/keyring-api';\n\nimport type {\n MultichainAccountWallet,\n MultichainAccountWalletId,\n} from './wallet';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroup, AccountGroupType } from '../group';\nimport type { AccountSelector } from '../selector';\nimport { AccountWalletType } from '../wallet';\n\nconst MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = new RegExp(\n `^${AccountWalletType.Entropy}:.*/(?<groupIndex>\\\\d+)$`,\n 'u',\n);\n\n/**\n * Multichain account ID.\n */\nexport type MultichainAccountGroupId = `${MultichainAccountWalletId}/${number}`; // Use number for the account group index.\n\n/**\n * A multichain account that holds multiple accounts.\n */\nexport type MultichainAccountGroup<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountGroup<Account> & {\n /**\n * Multichain account group ID.\n */\n get id(): MultichainAccountGroupId;\n\n /**\n * Multichain account type.\n */\n get type(): AccountGroupType.MultichainAccount;\n\n /**\n * Multichain account's wallet reference (parent).\n */\n get wallet(): MultichainAccountWallet<Account>;\n\n /**\n * Multichain account group index.\n */\n get index(): number;\n\n /**\n * Query an account matching the selector.\n *\n * @param selector - Query selector.\n * @returns The account matching the selector or undefined if not matching.\n * @throws If multiple accounts match the selector.\n */\n get(selector: AccountSelector<Account>): Account | undefined;\n\n /**\n * Query accounts matching the selector.\n *\n * @param selector - Query selector.\n * @returns The accounts matching the selector.\n */\n select(selector: AccountSelector<Account>): Account[];\n};\n\n/**\n * Gets the multichain account group ID from its multichain account wallet ID and its index.\n *\n * @param walletId - Multichain account wallet ID.\n * @param groupIndex - Index of that multichain account.\n * @returns The multichain account ID.\n */\nexport function toMultichainAccountGroupId(\n walletId: MultichainAccountWalletId,\n groupIndex: number,\n): MultichainAccountGroupId {\n return `${walletId}/${groupIndex}`;\n}\n\n/**\n * Checks if the given value is {@link MultichainAccountGroupId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link MultichainAccountGroupId}.\n */\nexport function isMultichainAccountGroupId(\n value: string,\n): value is MultichainAccountGroupId {\n return MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.test(value);\n}\n\n/**\n * Gets the multichain account index from an account group ID.\n *\n * @param id - Multichain account ID.\n * @returns The multichain account index if extractable, undefined otherwise.\n */\nexport function getGroupIndexFromMultichainAccountId(\n id: MultichainAccountGroupId,\n): number {\n const matched = id.match(MULTICHAIN_ACCOUNT_GROUP_ID_REGEX);\n if (matched?.groups?.groupIndex === undefined) {\n // Unable to extract group index, even though, type wise, this should not\n // be possible!\n throw new Error('Unable to extract group index');\n }\n\n return Number(matched.groups.groupIndex);\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import { type KeyringAccount } from "@metamask/keyring-api";
2
+ import type { MultichainAccountWallet, MultichainAccountWalletId } from "./wallet.cjs";
3
+ import type { Bip44Account } from "../bip44.cjs";
4
+ import type { AccountGroup, AccountGroupType } from "../group.cjs";
5
+ import type { AccountSelector } from "../selector.cjs";
6
+ /**
7
+ * Multichain account ID.
8
+ */
9
+ export type MultichainAccountGroupId = `${MultichainAccountWalletId}/${number}`;
10
+ /**
11
+ * A multichain account that holds multiple accounts.
12
+ */
13
+ export type MultichainAccountGroup<Account extends Bip44Account<KeyringAccount>> = AccountGroup<Account> & {
14
+ /**
15
+ * Multichain account group ID.
16
+ */
17
+ get id(): MultichainAccountGroupId;
18
+ /**
19
+ * Multichain account type.
20
+ */
21
+ get type(): AccountGroupType.MultichainAccount;
22
+ /**
23
+ * Multichain account's wallet reference (parent).
24
+ */
25
+ get wallet(): MultichainAccountWallet<Account>;
26
+ /**
27
+ * Multichain account group index.
28
+ */
29
+ get index(): number;
30
+ /**
31
+ * Query an account matching the selector.
32
+ *
33
+ * @param selector - Query selector.
34
+ * @returns The account matching the selector or undefined if not matching.
35
+ * @throws If multiple accounts match the selector.
36
+ */
37
+ get(selector: AccountSelector<Account>): Account | undefined;
38
+ /**
39
+ * Query accounts matching the selector.
40
+ *
41
+ * @param selector - Query selector.
42
+ * @returns The accounts matching the selector.
43
+ */
44
+ select(selector: AccountSelector<Account>): Account[];
45
+ };
46
+ /**
47
+ * Gets the multichain account group ID from its multichain account wallet ID and its index.
48
+ *
49
+ * @param walletId - Multichain account wallet ID.
50
+ * @param groupIndex - Index of that multichain account.
51
+ * @returns The multichain account ID.
52
+ */
53
+ export declare function toMultichainAccountGroupId(walletId: MultichainAccountWalletId, groupIndex: number): MultichainAccountGroupId;
54
+ /**
55
+ * Checks if the given value is {@link MultichainAccountGroupId}.
56
+ *
57
+ * @param value - The value to check.
58
+ * @returns Whether the value is a {@link MultichainAccountGroupId}.
59
+ */
60
+ export declare function isMultichainAccountGroupId(value: string): value is MultichainAccountGroupId;
61
+ /**
62
+ * Gets the multichain account index from an account group ID.
63
+ *
64
+ * @param id - Multichain account ID.
65
+ * @returns The multichain account index if extractable, undefined otherwise.
66
+ */
67
+ export declare function getGroupIndexFromMultichainAccountId(id: MultichainAccountGroupId): number;
68
+ //# sourceMappingURL=group.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,8BAA8B;AAE5D,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EAC1B,qBAAiB;AAClB,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,qBAAiB;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AAQnD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,GAAG,yBAAyB,IAAI,MAAM,EAAE,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAChC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,YAAY,CAAC,OAAO,CAAC,GAAG;IAC1B;;OAEG;IACH,IAAI,EAAE,IAAI,wBAAwB,CAAC;IAEnC;;OAEG;IACH,IAAI,IAAI,IAAI,gBAAgB,CAAC,iBAAiB,CAAC;IAE/C;;OAEG;IACH,IAAI,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAE/C;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;IAE7D;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;CACvD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,yBAAyB,EACnC,UAAU,EAAE,MAAM,GACjB,wBAAwB,CAE1B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,wBAAwB,CAEnC;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,EAAE,EAAE,wBAAwB,GAC3B,MAAM,CASR"}
@@ -0,0 +1,68 @@
1
+ import { type KeyringAccount } from "@metamask/keyring-api";
2
+ import type { MultichainAccountWallet, MultichainAccountWalletId } from "./wallet.mjs";
3
+ import type { Bip44Account } from "../bip44.mjs";
4
+ import type { AccountGroup, AccountGroupType } from "../group.mjs";
5
+ import type { AccountSelector } from "../selector.mjs";
6
+ /**
7
+ * Multichain account ID.
8
+ */
9
+ export type MultichainAccountGroupId = `${MultichainAccountWalletId}/${number}`;
10
+ /**
11
+ * A multichain account that holds multiple accounts.
12
+ */
13
+ export type MultichainAccountGroup<Account extends Bip44Account<KeyringAccount>> = AccountGroup<Account> & {
14
+ /**
15
+ * Multichain account group ID.
16
+ */
17
+ get id(): MultichainAccountGroupId;
18
+ /**
19
+ * Multichain account type.
20
+ */
21
+ get type(): AccountGroupType.MultichainAccount;
22
+ /**
23
+ * Multichain account's wallet reference (parent).
24
+ */
25
+ get wallet(): MultichainAccountWallet<Account>;
26
+ /**
27
+ * Multichain account group index.
28
+ */
29
+ get index(): number;
30
+ /**
31
+ * Query an account matching the selector.
32
+ *
33
+ * @param selector - Query selector.
34
+ * @returns The account matching the selector or undefined if not matching.
35
+ * @throws If multiple accounts match the selector.
36
+ */
37
+ get(selector: AccountSelector<Account>): Account | undefined;
38
+ /**
39
+ * Query accounts matching the selector.
40
+ *
41
+ * @param selector - Query selector.
42
+ * @returns The accounts matching the selector.
43
+ */
44
+ select(selector: AccountSelector<Account>): Account[];
45
+ };
46
+ /**
47
+ * Gets the multichain account group ID from its multichain account wallet ID and its index.
48
+ *
49
+ * @param walletId - Multichain account wallet ID.
50
+ * @param groupIndex - Index of that multichain account.
51
+ * @returns The multichain account ID.
52
+ */
53
+ export declare function toMultichainAccountGroupId(walletId: MultichainAccountWalletId, groupIndex: number): MultichainAccountGroupId;
54
+ /**
55
+ * Checks if the given value is {@link MultichainAccountGroupId}.
56
+ *
57
+ * @param value - The value to check.
58
+ * @returns Whether the value is a {@link MultichainAccountGroupId}.
59
+ */
60
+ export declare function isMultichainAccountGroupId(value: string): value is MultichainAccountGroupId;
61
+ /**
62
+ * Gets the multichain account index from an account group ID.
63
+ *
64
+ * @param id - Multichain account ID.
65
+ * @returns The multichain account index if extractable, undefined otherwise.
66
+ */
67
+ export declare function getGroupIndexFromMultichainAccountId(id: MultichainAccountGroupId): number;
68
+ //# sourceMappingURL=group.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/group.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,8BAA8B;AAE5D,OAAO,KAAK,EACV,uBAAuB,EACvB,yBAAyB,EAC1B,qBAAiB;AAClB,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,qBAAiB;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,wBAAoB;AAQnD;;GAEG;AACH,MAAM,MAAM,wBAAwB,GAAG,GAAG,yBAAyB,IAAI,MAAM,EAAE,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAChC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,YAAY,CAAC,OAAO,CAAC,GAAG;IAC1B;;OAEG;IACH,IAAI,EAAE,IAAI,wBAAwB,CAAC;IAEnC;;OAEG;IACH,IAAI,IAAI,IAAI,gBAAgB,CAAC,iBAAiB,CAAC;IAE/C;;OAEG;IACH,IAAI,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAE/C;;OAEG;IACH,IAAI,KAAK,IAAI,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,GAAG,SAAS,CAAC;IAE7D;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;CACvD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,yBAAyB,EACnC,UAAU,EAAE,MAAM,GACjB,wBAAwB,CAE1B;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,wBAAwB,CAEnC;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,EAAE,EAAE,wBAAwB,GAC3B,MAAM,CASR"}
@@ -0,0 +1,37 @@
1
+ import { AccountWalletType } from "../wallet.mjs";
2
+ const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = new RegExp(`^${AccountWalletType.Entropy}:.*/(?<groupIndex>\\d+)$`, 'u');
3
+ /**
4
+ * Gets the multichain account group ID from its multichain account wallet ID and its index.
5
+ *
6
+ * @param walletId - Multichain account wallet ID.
7
+ * @param groupIndex - Index of that multichain account.
8
+ * @returns The multichain account ID.
9
+ */
10
+ export function toMultichainAccountGroupId(walletId, groupIndex) {
11
+ return `${walletId}/${groupIndex}`;
12
+ }
13
+ /**
14
+ * Checks if the given value is {@link MultichainAccountGroupId}.
15
+ *
16
+ * @param value - The value to check.
17
+ * @returns Whether the value is a {@link MultichainAccountGroupId}.
18
+ */
19
+ export function isMultichainAccountGroupId(value) {
20
+ return MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.test(value);
21
+ }
22
+ /**
23
+ * Gets the multichain account index from an account group ID.
24
+ *
25
+ * @param id - Multichain account ID.
26
+ * @returns The multichain account index if extractable, undefined otherwise.
27
+ */
28
+ export function getGroupIndexFromMultichainAccountId(id) {
29
+ const matched = id.match(MULTICHAIN_ACCOUNT_GROUP_ID_REGEX);
30
+ if (matched?.groups?.groupIndex === undefined) {
31
+ // Unable to extract group index, even though, type wise, this should not
32
+ // be possible!
33
+ throw new Error('Unable to extract group index');
34
+ }
35
+ return Number(matched.groups.groupIndex);
36
+ }
37
+ //# sourceMappingURL=group.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../../src/api/multichain/group.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C,MAAM,iCAAiC,GAAG,IAAI,MAAM,CAClD,IAAI,iBAAiB,CAAC,OAAO,0BAA0B,EACvD,GAAG,CACJ,CAAC;AAmDF;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAmC,EACnC,UAAkB;IAElB,OAAO,GAAG,QAAQ,IAAI,UAAU,EAAE,CAAC;AACrC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAAa;IAEb,OAAO,iCAAiC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACvD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oCAAoC,CAClD,EAA4B;IAE5B,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAC5D,IAAI,OAAO,EAAE,MAAM,EAAE,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9C,yEAAyE;QACzE,eAAe;QACf,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;IACnD,CAAC;IAED,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { type KeyringAccount } from '@metamask/keyring-api';\n\nimport type {\n MultichainAccountWallet,\n MultichainAccountWalletId,\n} from './wallet';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountGroup, AccountGroupType } from '../group';\nimport type { AccountSelector } from '../selector';\nimport { AccountWalletType } from '../wallet';\n\nconst MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = new RegExp(\n `^${AccountWalletType.Entropy}:.*/(?<groupIndex>\\\\d+)$`,\n 'u',\n);\n\n/**\n * Multichain account ID.\n */\nexport type MultichainAccountGroupId = `${MultichainAccountWalletId}/${number}`; // Use number for the account group index.\n\n/**\n * A multichain account that holds multiple accounts.\n */\nexport type MultichainAccountGroup<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountGroup<Account> & {\n /**\n * Multichain account group ID.\n */\n get id(): MultichainAccountGroupId;\n\n /**\n * Multichain account type.\n */\n get type(): AccountGroupType.MultichainAccount;\n\n /**\n * Multichain account's wallet reference (parent).\n */\n get wallet(): MultichainAccountWallet<Account>;\n\n /**\n * Multichain account group index.\n */\n get index(): number;\n\n /**\n * Query an account matching the selector.\n *\n * @param selector - Query selector.\n * @returns The account matching the selector or undefined if not matching.\n * @throws If multiple accounts match the selector.\n */\n get(selector: AccountSelector<Account>): Account | undefined;\n\n /**\n * Query accounts matching the selector.\n *\n * @param selector - Query selector.\n * @returns The accounts matching the selector.\n */\n select(selector: AccountSelector<Account>): Account[];\n};\n\n/**\n * Gets the multichain account group ID from its multichain account wallet ID and its index.\n *\n * @param walletId - Multichain account wallet ID.\n * @param groupIndex - Index of that multichain account.\n * @returns The multichain account ID.\n */\nexport function toMultichainAccountGroupId(\n walletId: MultichainAccountWalletId,\n groupIndex: number,\n): MultichainAccountGroupId {\n return `${walletId}/${groupIndex}`;\n}\n\n/**\n * Checks if the given value is {@link MultichainAccountGroupId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link MultichainAccountGroupId}.\n */\nexport function isMultichainAccountGroupId(\n value: string,\n): value is MultichainAccountGroupId {\n return MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.test(value);\n}\n\n/**\n * Gets the multichain account index from an account group ID.\n *\n * @param id - Multichain account ID.\n * @returns The multichain account index if extractable, undefined otherwise.\n */\nexport function getGroupIndexFromMultichainAccountId(\n id: MultichainAccountGroupId,\n): number {\n const matched = id.match(MULTICHAIN_ACCOUNT_GROUP_ID_REGEX);\n if (matched?.groups?.groupIndex === undefined) {\n // Unable to extract group index, even though, type wise, this should not\n // be possible!\n throw new Error('Unable to extract group index');\n }\n\n return Number(matched.groups.groupIndex);\n}\n"]}
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./account.cjs"), exports);
17
+ __exportStar(require("./group.cjs"), exports);
18
18
  __exportStar(require("./wallet.cjs"), exports);
19
19
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA0B;AAC1B,+CAAyB","sourcesContent":["export * from './account';\nexport * from './wallet';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,+CAAyB","sourcesContent":["export * from './group';\nexport * from './wallet';\n"]}
@@ -1,3 +1,3 @@
1
- export * from "./account.cjs";
1
+ export * from "./group.cjs";
2
2
  export * from "./wallet.cjs";
3
3
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,8BAA0B;AAC1B,6BAAyB"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB"}
@@ -1,3 +1,3 @@
1
- export * from "./account.mjs";
1
+ export * from "./group.mjs";
2
2
  export * from "./wallet.mjs";
3
3
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,8BAA0B;AAC1B,6BAAyB"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB"}
@@ -1,3 +1,3 @@
1
- export * from "./account.mjs";
1
+ export * from "./group.mjs";
2
2
  export * from "./wallet.mjs";
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,8BAA0B;AAC1B,6BAAyB","sourcesContent":["export * from './account';\nexport * from './wallet';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/api/multichain/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,6BAAyB","sourcesContent":["export * from './group';\nexport * from './wallet';\n"]}