@metamask-previews/account-api 0.9.0-a621908 → 0.10.0-9fbf2ff

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 (88) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/api/group.cjs +53 -1
  3. package/dist/api/group.cjs.map +1 -1
  4. package/dist/api/group.d.cts +41 -1
  5. package/dist/api/group.d.cts.map +1 -1
  6. package/dist/api/group.d.mts +41 -1
  7. package/dist/api/group.d.mts.map +1 -1
  8. package/dist/api/group.mjs +49 -0
  9. package/dist/api/group.mjs.map +1 -1
  10. package/dist/api/multichain/group.cjs +35 -10
  11. package/dist/api/multichain/group.cjs.map +1 -1
  12. package/dist/api/multichain/group.d.cts +27 -0
  13. package/dist/api/multichain/group.d.cts.map +1 -1
  14. package/dist/api/multichain/group.d.mts +27 -0
  15. package/dist/api/multichain/group.d.mts.map +1 -1
  16. package/dist/api/multichain/group.mjs +32 -9
  17. package/dist/api/multichain/group.mjs.map +1 -1
  18. package/dist/api/multichain/wallet.cjs +34 -0
  19. package/dist/api/multichain/wallet.cjs.map +1 -1
  20. package/dist/api/multichain/wallet.d.cts +57 -2
  21. package/dist/api/multichain/wallet.d.cts.map +1 -1
  22. package/dist/api/multichain/wallet.d.mts +57 -2
  23. package/dist/api/multichain/wallet.d.mts.map +1 -1
  24. package/dist/api/multichain/wallet.mjs +31 -0
  25. package/dist/api/multichain/wallet.mjs.map +1 -1
  26. package/dist/api/provider.cjs.map +1 -1
  27. package/dist/api/provider.d.cts +8 -0
  28. package/dist/api/provider.d.cts.map +1 -1
  29. package/dist/api/provider.d.mts +8 -0
  30. package/dist/api/provider.d.mts.map +1 -1
  31. package/dist/api/provider.mjs.map +1 -1
  32. package/dist/api/wallet.cjs +45 -1
  33. package/dist/api/wallet.cjs.map +1 -1
  34. package/dist/api/wallet.d.cts +91 -3
  35. package/dist/api/wallet.d.cts.map +1 -1
  36. package/dist/api/wallet.d.mts +91 -3
  37. package/dist/api/wallet.d.mts.map +1 -1
  38. package/dist/api/wallet.mjs +41 -0
  39. package/dist/api/wallet.mjs.map +1 -1
  40. package/dist/mocks/accounts.cjs +10 -27
  41. package/dist/mocks/accounts.cjs.map +1 -1
  42. package/dist/mocks/accounts.d.cts +0 -18
  43. package/dist/mocks/accounts.d.cts.map +1 -1
  44. package/dist/mocks/accounts.d.mts +0 -18
  45. package/dist/mocks/accounts.d.mts.map +1 -1
  46. package/dist/mocks/accounts.mjs +3 -20
  47. package/dist/mocks/accounts.mjs.map +1 -1
  48. package/dist/mocks/groups.cjs +9 -0
  49. package/dist/mocks/groups.cjs.map +1 -0
  50. package/dist/mocks/groups.d.cts +5 -0
  51. package/dist/mocks/groups.d.cts.map +1 -0
  52. package/dist/mocks/groups.d.mts +5 -0
  53. package/dist/mocks/groups.d.mts.map +1 -0
  54. package/dist/mocks/groups.mjs +6 -0
  55. package/dist/mocks/groups.mjs.map +1 -0
  56. package/dist/mocks/index.cjs +4 -0
  57. package/dist/mocks/index.cjs.map +1 -1
  58. package/dist/mocks/index.d.cts +4 -0
  59. package/dist/mocks/index.d.cts.map +1 -1
  60. package/dist/mocks/index.d.mts +4 -0
  61. package/dist/mocks/index.d.mts.map +1 -1
  62. package/dist/mocks/index.mjs +4 -0
  63. package/dist/mocks/index.mjs.map +1 -1
  64. package/dist/mocks/keyrings.cjs +7 -0
  65. package/dist/mocks/keyrings.cjs.map +1 -0
  66. package/dist/mocks/keyrings.d.cts +4 -0
  67. package/dist/mocks/keyrings.d.cts.map +1 -0
  68. package/dist/mocks/keyrings.d.mts +4 -0
  69. package/dist/mocks/keyrings.d.mts.map +1 -0
  70. package/dist/mocks/keyrings.mjs +4 -0
  71. package/dist/mocks/keyrings.mjs.map +1 -0
  72. package/dist/mocks/snaps.cjs +20 -0
  73. package/dist/mocks/snaps.cjs.map +1 -0
  74. package/dist/mocks/snaps.d.cts +17 -0
  75. package/dist/mocks/snaps.d.cts.map +1 -0
  76. package/dist/mocks/snaps.d.mts +17 -0
  77. package/dist/mocks/snaps.d.mts.map +1 -0
  78. package/dist/mocks/snaps.mjs +17 -0
  79. package/dist/mocks/snaps.mjs.map +1 -0
  80. package/dist/mocks/wallets.cjs +11 -0
  81. package/dist/mocks/wallets.cjs.map +1 -0
  82. package/dist/mocks/wallets.d.cts +5 -0
  83. package/dist/mocks/wallets.d.cts.map +1 -0
  84. package/dist/mocks/wallets.d.mts +5 -0
  85. package/dist/mocks/wallets.d.mts.map +1 -0
  86. package/dist/mocks/wallets.mjs +8 -0
  87. package/dist/mocks/wallets.mjs.map +1 -0
  88. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../../src/api/multichain/group.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C,MAAM,iCAAiC,GAAG,IAAI,MAAM,CAClD,IAAI,iBAAiB,CAAC,OAAO,0BAA0B,EACvD,GAAG,CACJ,CAAC;AAkCF;;;;;;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,yCAAyC,CACvD,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 { 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 groupIndex(): number;\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 getGroupIndexFromMultichainAccountGroupId(\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"]}
1
+ {"version":3,"file":"group.mjs","sourceRoot":"","sources":["../../../src/api/multichain/group.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAC5C,kFAAkF,CAAC;AAyCrF;;;;;;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;;;;;;;;GAQG;AACH,MAAM,UAAU,6BAA6B,CAC3C,OAAe;IAEf,MAAM,KAAK,GAAG,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,yCAAyC,OAAO,GAAG,CAAC,CAAC;IACvE,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,QAAqC,CAAC;IACpE,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,UAAuC,CAAC;IACxE,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,WAAqB,CAAC;IAEvD,OAAO;QACL,MAAM,EAAE;YACN,EAAE,EAAE,QAAQ;YACZ,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,WAAW;SACnB;QACD,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC;KAC5C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,yCAAyC,CACvD,EAA4B;IAE5B,OAAO,6BAA6B,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC;AACtD,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 { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account ID.\n */\nexport type MultichainAccountGroupId = `${MultichainAccountWalletId}/${number}`; // Use number for the account group index.\n\n/**\n * Regex to validate a valid multichain account group ID.\n */\nexport const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX =\n /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))\\/(?<groupIndex>[0-9]+)$/u;\n\n/**\n * Parsed account group ID with its parsed wallet component and its sub-ID.\n */\nexport type ParsedMultichainAccountGroupId = {\n wallet: {\n id: MultichainAccountWalletId;\n type: AccountWalletType.Entropy;\n subId: string;\n };\n groupIndex: number;\n};\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 groupIndex(): number;\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 * Parse a multichain account group ID to an object containing a multichain\n * wallet ID information (wallet type and wallet sub-ID), as well as\n * multichain account group ID information (group index).\n *\n * @param groupId - The multichain account group ID to validate and parse.\n * @returns The parsed multichain account group ID.\n * @throws When the group ID format is invalid.\n */\nexport function parseMultichainAccountGroupId(\n groupId: string,\n): ParsedMultichainAccountGroupId {\n const match = MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.exec(groupId);\n if (!match?.groups) {\n throw new Error(`Invalid multichain account group ID: \"${groupId}\"`);\n }\n\n const walletId = match.groups.walletId as MultichainAccountWalletId;\n const walletType = match.groups.walletType as AccountWalletType.Entropy;\n const walletSubId = match.groups.walletSubId as string;\n\n return {\n wallet: {\n id: walletId,\n type: walletType,\n subId: walletSubId,\n },\n groupIndex: Number(match.groups.groupIndex),\n };\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 * @throws When the group ID format is invalid.\n */\nexport function getGroupIndexFromMultichainAccountGroupId(\n id: MultichainAccountGroupId,\n): number {\n return parseMultichainAccountGroupId(id).groupIndex;\n}\n"]}
@@ -1,7 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX = void 0;
3
4
  exports.toMultichainAccountWalletId = toMultichainAccountWalletId;
5
+ exports.isMultichainAccountWalletId = isMultichainAccountWalletId;
6
+ exports.parseMultichainAccountWalletId = parseMultichainAccountWalletId;
4
7
  const wallet_1 = require("../wallet.cjs");
8
+ /**
9
+ * Regex to validate a valid multichain account wallet ID.
10
+ */
11
+ exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX = /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))$/u;
5
12
  /**
6
13
  * Gets the multichain account wallet ID from its entropy source.
7
14
  *
@@ -11,4 +18,31 @@ const wallet_1 = require("../wallet.cjs");
11
18
  function toMultichainAccountWalletId(entropySource) {
12
19
  return `${wallet_1.AccountWalletType.Entropy}:${entropySource}`;
13
20
  }
21
+ /**
22
+ * Checks if the given value is {@link MultichainAccountWalletId}.
23
+ *
24
+ * @param value - The value to check.
25
+ * @returns Whether the value is a {@link MultichainAccountWalletId}.
26
+ */
27
+ function isMultichainAccountWalletId(value) {
28
+ return exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.test(value);
29
+ }
30
+ /**
31
+ * Parse a multichain account wallet ID to an object containing wallet ID
32
+ * information (wallet type and sub-ID).
33
+ *
34
+ * @param walletId - The account wallet ID to validate and parse.
35
+ * @returns The parsed account wallet ID.
36
+ * @throws When the wallet ID format is invalid.
37
+ */
38
+ function parseMultichainAccountWalletId(walletId) {
39
+ const match = exports.MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.exec(walletId);
40
+ if (!match?.groups) {
41
+ throw new Error(`Invalid multichain account wallet ID: "${walletId}"`);
42
+ }
43
+ return {
44
+ type: match.groups.walletType,
45
+ subId: match.groups.walletSubId,
46
+ };
47
+ }
14
48
  //# sourceMappingURL=wallet.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;AA8DA,kEAIC;AA1DD,0CAA8C;AAgD9C;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,0BAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\n};\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
1
+ {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":";;;AA2GA,kEAIC;AAQD,kEAIC;AAUD,wEAYC;AAzID,0CAA8C;AAQ9C;;GAEG;AACU,QAAA,kCAAkC,GAC7C,2DAA2D,CAAC;AAiF9D;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,0BAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,KAAa;IAEb,OAAO,0CAAkC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,8BAA8B,CAC5C,QAAgB;IAEhB,MAAM,KAAK,GAAG,0CAAkC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,0CAA0C,QAAQ,GAAG,CAAC,CAAC;IACzE,CAAC;IAED,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,UAAuC;QAC1D,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,WAAqB;KAC1C,CAAC;AACJ,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountWalletStatus, BaseAccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * Regex to validate a valid multichain account wallet ID.\n */\nexport const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX =\n /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))$/u;\n\n/**\n * Parsed multichain account wallet ID with its wallet type and sub-ID.\n */\nexport type ParsedMultichainAccountWalletId = {\n type: AccountWalletType.Entropy;\n subId: string;\n};\n\n/**\n * Wallet status.\n *\n * Those status are used to report in which \"state\" the wallet is currently\n * in. All of those operations cannot run concurrently, thus, the wallet\n * cannot have multiple status at once.\n */\nexport type MultichainAccountWalletStatus =\n | AccountWalletStatus\n /**\n * Discovery is in progress for this wallet. New account groups will be\n * automatically added based on the account provider discovery result.\n */\n | 'in-progress:discovery'\n /**\n * Alignment is in progress for this wallet. Account groups will be\n * automatically updated based on the active account providers.\n */\n | 'in-progress:alignment'\n /**\n * An on-going operation (creating/deleting) is in progress for this\n * wallet. Account groups will either be created or deleted during\n * this operation.\n */\n | 'in-progress:operation';\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = BaseAccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\n\n /**\n * Multichain account wallet status.\n */\n get status(): MultichainAccountWalletStatus;\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\n};\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n\n/**\n * Checks if the given value is {@link MultichainAccountWalletId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link MultichainAccountWalletId}.\n */\nexport function isMultichainAccountWalletId(\n value: string,\n): value is MultichainAccountWalletId {\n return MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.test(value);\n}\n\n/**\n * Parse a multichain account wallet ID to an object containing wallet ID\n * information (wallet type and sub-ID).\n *\n * @param walletId - The account wallet ID to validate and parse.\n * @returns The parsed account wallet ID.\n * @throws When the wallet ID format is invalid.\n */\nexport function parseMultichainAccountWalletId(\n walletId: string,\n): ParsedMultichainAccountWalletId {\n const match = MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.exec(walletId);\n if (!match?.groups) {\n throw new Error(`Invalid multichain account wallet ID: \"${walletId}\"`);\n }\n\n return {\n type: match.groups.walletType as AccountWalletType.Entropy,\n subId: match.groups.walletSubId as string,\n };\n}\n"]}
@@ -1,17 +1,52 @@
1
1
  import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
2
2
  import type { MultichainAccountGroup } from "./group.cjs";
3
3
  import type { Bip44Account } from "../bip44.cjs";
4
- import type { AccountWallet } from "../wallet.cjs";
4
+ import type { AccountWalletStatus, BaseAccountWallet } from "../wallet.cjs";
5
5
  import { AccountWalletType } from "../wallet.cjs";
6
6
  /**
7
7
  * Multichain account wallet ID.
8
8
  */
9
9
  export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
10
+ /**
11
+ * Regex to validate a valid multichain account wallet ID.
12
+ */
13
+ export declare const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX: RegExp;
14
+ /**
15
+ * Parsed multichain account wallet ID with its wallet type and sub-ID.
16
+ */
17
+ export type ParsedMultichainAccountWalletId = {
18
+ type: AccountWalletType.Entropy;
19
+ subId: string;
20
+ };
21
+ /**
22
+ * Wallet status.
23
+ *
24
+ * Those status are used to report in which "state" the wallet is currently
25
+ * in. All of those operations cannot run concurrently, thus, the wallet
26
+ * cannot have multiple status at once.
27
+ */
28
+ export type MultichainAccountWalletStatus = AccountWalletStatus
29
+ /**
30
+ * Discovery is in progress for this wallet. New account groups will be
31
+ * automatically added based on the account provider discovery result.
32
+ */
33
+ | 'in-progress:discovery'
34
+ /**
35
+ * Alignment is in progress for this wallet. Account groups will be
36
+ * automatically updated based on the active account providers.
37
+ */
38
+ | 'in-progress:alignment'
39
+ /**
40
+ * An on-going operation (creating/deleting) is in progress for this
41
+ * wallet. Account groups will either be created or deleted during
42
+ * this operation.
43
+ */
44
+ | 'in-progress:operation';
10
45
  /**
11
46
  * A multichain account wallet that holds multiple multichain accounts (one multichain account per
12
47
  * group index).
13
48
  */
14
- export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = AccountWallet<Account> & {
49
+ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = BaseAccountWallet<Account> & {
15
50
  /**
16
51
  * Multichain account wallet ID.
17
52
  */
@@ -24,6 +59,10 @@ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>
24
59
  * Multichain account wallet entropy source.
25
60
  */
26
61
  get entropySource(): EntropySourceId;
62
+ /**
63
+ * Multichain account wallet status.
64
+ */
65
+ get status(): MultichainAccountWalletStatus;
27
66
  /**
28
67
  * Gets multichain account for a given index.
29
68
  *
@@ -45,4 +84,20 @@ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>
45
84
  * @returns The multichain account wallet ID.
46
85
  */
47
86
  export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
87
+ /**
88
+ * Checks if the given value is {@link MultichainAccountWalletId}.
89
+ *
90
+ * @param value - The value to check.
91
+ * @returns Whether the value is a {@link MultichainAccountWalletId}.
92
+ */
93
+ export declare function isMultichainAccountWalletId(value: string): value is MultichainAccountWalletId;
94
+ /**
95
+ * Parse a multichain account wallet ID to an object containing wallet ID
96
+ * information (wallet type and sub-ID).
97
+ *
98
+ * @param walletId - The account wallet ID to validate and parse.
99
+ * @returns The parsed account wallet ID.
100
+ * @throws When the wallet ID format is invalid.
101
+ */
102
+ export declare function parseMultichainAccountWalletId(walletId: string): ParsedMultichainAccountWalletId;
48
103
  //# sourceMappingURL=wallet.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,aAAa,CAAC,OAAO,CAAC,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
1
+ {"version":3,"file":"wallet.d.cts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAkB;AACxE,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,kCAAkC,QACc,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GACrC,mBAAmB;AACrB;;;GAGG;GACD,uBAAuB;AACzB;;;GAGG;GACD,uBAAuB;AACzB;;;;GAIG;GACD,uBAAuB,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAC/B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;OAEG;IACH,IAAI,MAAM,IAAI,6BAA6B,CAAC;IAE5C;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,yBAAyB,CAEpC;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,GACf,+BAA+B,CAUjC"}
@@ -1,17 +1,52 @@
1
1
  import { type EntropySourceId, type KeyringAccount } from "@metamask/keyring-api";
2
2
  import type { MultichainAccountGroup } from "./group.mjs";
3
3
  import type { Bip44Account } from "../bip44.mjs";
4
- import type { AccountWallet } from "../wallet.mjs";
4
+ import type { AccountWalletStatus, BaseAccountWallet } from "../wallet.mjs";
5
5
  import { AccountWalletType } from "../wallet.mjs";
6
6
  /**
7
7
  * Multichain account wallet ID.
8
8
  */
9
9
  export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
10
+ /**
11
+ * Regex to validate a valid multichain account wallet ID.
12
+ */
13
+ export declare const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX: RegExp;
14
+ /**
15
+ * Parsed multichain account wallet ID with its wallet type and sub-ID.
16
+ */
17
+ export type ParsedMultichainAccountWalletId = {
18
+ type: AccountWalletType.Entropy;
19
+ subId: string;
20
+ };
21
+ /**
22
+ * Wallet status.
23
+ *
24
+ * Those status are used to report in which "state" the wallet is currently
25
+ * in. All of those operations cannot run concurrently, thus, the wallet
26
+ * cannot have multiple status at once.
27
+ */
28
+ export type MultichainAccountWalletStatus = AccountWalletStatus
29
+ /**
30
+ * Discovery is in progress for this wallet. New account groups will be
31
+ * automatically added based on the account provider discovery result.
32
+ */
33
+ | 'in-progress:discovery'
34
+ /**
35
+ * Alignment is in progress for this wallet. Account groups will be
36
+ * automatically updated based on the active account providers.
37
+ */
38
+ | 'in-progress:alignment'
39
+ /**
40
+ * An on-going operation (creating/deleting) is in progress for this
41
+ * wallet. Account groups will either be created or deleted during
42
+ * this operation.
43
+ */
44
+ | 'in-progress:operation';
10
45
  /**
11
46
  * A multichain account wallet that holds multiple multichain accounts (one multichain account per
12
47
  * group index).
13
48
  */
14
- export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = AccountWallet<Account> & {
49
+ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>> = BaseAccountWallet<Account> & {
15
50
  /**
16
51
  * Multichain account wallet ID.
17
52
  */
@@ -24,6 +59,10 @@ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>
24
59
  * Multichain account wallet entropy source.
25
60
  */
26
61
  get entropySource(): EntropySourceId;
62
+ /**
63
+ * Multichain account wallet status.
64
+ */
65
+ get status(): MultichainAccountWalletStatus;
27
66
  /**
28
67
  * Gets multichain account for a given index.
29
68
  *
@@ -45,4 +84,20 @@ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>
45
84
  * @returns The multichain account wallet ID.
46
85
  */
47
86
  export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
87
+ /**
88
+ * Checks if the given value is {@link MultichainAccountWalletId}.
89
+ *
90
+ * @param value - The value to check.
91
+ * @returns Whether the value is a {@link MultichainAccountWalletId}.
92
+ */
93
+ export declare function isMultichainAccountWalletId(value: string): value is MultichainAccountWalletId;
94
+ /**
95
+ * Parse a multichain account wallet ID to an object containing wallet ID
96
+ * information (wallet type and sub-ID).
97
+ *
98
+ * @param walletId - The account wallet ID to validate and parse.
99
+ * @returns The parsed account wallet ID.
100
+ * @throws When the wallet ID format is invalid.
101
+ */
102
+ export declare function parseMultichainAccountWalletId(walletId: string): ParsedMultichainAccountWalletId;
48
103
  //# sourceMappingURL=wallet.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,sBAAkB;AAC/C,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,aAAa,CAAC,OAAO,CAAC,GAAG;IAC3B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B"}
1
+ {"version":3,"file":"wallet.d.mts","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,8BAA8B;AAE/B,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAgB;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAiB;AAC7C,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,sBAAkB;AACxE,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAE9C;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACnC,GAAG,iBAAiB,CAAC,OAAO,IAAI,eAAe,EAAE,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,kCAAkC,QACc,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,iBAAiB,CAAC,OAAO,CAAC;IAChC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,6BAA6B,GACrC,mBAAmB;AACrB;;;GAGG;GACD,uBAAuB;AACzB;;;GAGG;GACD,uBAAuB;AACzB;;;;GAIG;GACD,uBAAuB,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,YAAY,CAAC,cAAc,CAAC,IAC1C,iBAAiB,CAAC,OAAO,CAAC,GAAG;IAC/B;;OAEG;IACH,IAAI,EAAE,IAAI,yBAAyB,CAAC;IAEpC;;OAEG;IACH,IAAI,IAAI,IAAI,iBAAiB,CAAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;OAEG;IACH,IAAI,MAAM,IAAI,6BAA6B,CAAC;IAE5C;;;;;OAKG;IACH,yBAAyB,CACvB,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAE/C;;;;OAIG;IACH,0BAA0B,IAAI,sBAAsB,CAAC,OAAO,CAAC,EAAE,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,eAAe,GAC7B,yBAAyB,CAE3B;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,MAAM,GACZ,KAAK,IAAI,yBAAyB,CAEpC;AAED;;;;;;;GAOG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,MAAM,GACf,+BAA+B,CAUjC"}
@@ -1,4 +1,8 @@
1
1
  import { AccountWalletType } from "../wallet.mjs";
2
+ /**
3
+ * Regex to validate a valid multichain account wallet ID.
4
+ */
5
+ export const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX = /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))$/u;
2
6
  /**
3
7
  * Gets the multichain account wallet ID from its entropy source.
4
8
  *
@@ -8,4 +12,31 @@ import { AccountWalletType } from "../wallet.mjs";
8
12
  export function toMultichainAccountWalletId(entropySource) {
9
13
  return `${AccountWalletType.Entropy}:${entropySource}`;
10
14
  }
15
+ /**
16
+ * Checks if the given value is {@link MultichainAccountWalletId}.
17
+ *
18
+ * @param value - The value to check.
19
+ * @returns Whether the value is a {@link MultichainAccountWalletId}.
20
+ */
21
+ export function isMultichainAccountWalletId(value) {
22
+ return MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.test(value);
23
+ }
24
+ /**
25
+ * Parse a multichain account wallet ID to an object containing wallet ID
26
+ * information (wallet type and sub-ID).
27
+ *
28
+ * @param walletId - The account wallet ID to validate and parse.
29
+ * @returns The parsed account wallet ID.
30
+ * @throws When the wallet ID format is invalid.
31
+ */
32
+ export function parseMultichainAccountWalletId(walletId) {
33
+ const match = MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.exec(walletId);
34
+ if (!match?.groups) {
35
+ throw new Error(`Invalid multichain account wallet ID: "${walletId}"`);
36
+ }
37
+ return {
38
+ type: match.groups.walletType,
39
+ subId: match.groups.walletSubId,
40
+ };
41
+ }
11
42
  //# sourceMappingURL=wallet.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAgD9C;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,iBAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = AccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\n};\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n"]}
1
+ {"version":3,"file":"wallet.mjs","sourceRoot":"","sources":["../../../src/api/multichain/wallet.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAQ9C;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC7C,2DAA2D,CAAC;AAiF9D;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,aAA8B;IAE9B,OAAO,GAAG,iBAAiB,CAAC,OAAO,IAAI,aAAa,EAAE,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CACzC,KAAa;IAEb,OAAO,kCAAkC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAC5C,QAAgB;IAEhB,MAAM,KAAK,GAAG,kCAAkC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,0CAA0C,QAAQ,GAAG,CAAC,CAAC;IACzE,CAAC;IAED,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,UAAuC;QAC1D,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,WAAqB;KAC1C,CAAC;AACJ,CAAC","sourcesContent":["import {\n type EntropySourceId,\n type KeyringAccount,\n} from '@metamask/keyring-api';\n\nimport type { MultichainAccountGroup } from './group';\nimport type { Bip44Account } from '../bip44';\nimport type { AccountWalletStatus, BaseAccountWallet } from '../wallet';\nimport { AccountWalletType } from '../wallet';\n\n/**\n * Multichain account wallet ID.\n */\nexport type MultichainAccountWalletId =\n `${AccountWalletType.Entropy}:${EntropySourceId}`;\n\n/**\n * Regex to validate a valid multichain account wallet ID.\n */\nexport const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX =\n /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))$/u;\n\n/**\n * Parsed multichain account wallet ID with its wallet type and sub-ID.\n */\nexport type ParsedMultichainAccountWalletId = {\n type: AccountWalletType.Entropy;\n subId: string;\n};\n\n/**\n * Wallet status.\n *\n * Those status are used to report in which \"state\" the wallet is currently\n * in. All of those operations cannot run concurrently, thus, the wallet\n * cannot have multiple status at once.\n */\nexport type MultichainAccountWalletStatus =\n | AccountWalletStatus\n /**\n * Discovery is in progress for this wallet. New account groups will be\n * automatically added based on the account provider discovery result.\n */\n | 'in-progress:discovery'\n /**\n * Alignment is in progress for this wallet. Account groups will be\n * automatically updated based on the active account providers.\n */\n | 'in-progress:alignment'\n /**\n * An on-going operation (creating/deleting) is in progress for this\n * wallet. Account groups will either be created or deleted during\n * this operation.\n */\n | 'in-progress:operation';\n\n/**\n * A multichain account wallet that holds multiple multichain accounts (one multichain account per\n * group index).\n */\nexport type MultichainAccountWallet<\n Account extends Bip44Account<KeyringAccount>,\n> = BaseAccountWallet<Account> & {\n /**\n * Multichain account wallet ID.\n */\n get id(): MultichainAccountWalletId;\n\n /**\n * Multichain account wallet type, which is always {@link AccountWalletType.Entropy}.\n */\n get type(): AccountWalletType.Entropy;\n\n /**\n * Multichain account wallet entropy source.\n */\n get entropySource(): EntropySourceId;\n\n /**\n * Multichain account wallet status.\n */\n get status(): MultichainAccountWalletStatus;\n\n /**\n * Gets multichain account for a given index.\n *\n * @param groupIndex - Multichain account index.\n * @returns The multichain account associated with the given index.\n */\n getMultichainAccountGroup(\n groupIndex: number,\n ): MultichainAccountGroup<Account> | undefined;\n\n /**\n * Gets all multichain accounts.\n *\n * @returns The multichain accounts.\n */\n getMultichainAccountGroups(): MultichainAccountGroup<Account>[];\n};\n\n/**\n * Gets the multichain account wallet ID from its entropy source.\n *\n * @param entropySource - Entropy source ID of that wallet.\n * @returns The multichain account wallet ID.\n */\nexport function toMultichainAccountWalletId(\n entropySource: EntropySourceId,\n): MultichainAccountWalletId {\n return `${AccountWalletType.Entropy}:${entropySource}`;\n}\n\n/**\n * Checks if the given value is {@link MultichainAccountWalletId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link MultichainAccountWalletId}.\n */\nexport function isMultichainAccountWalletId(\n value: string,\n): value is MultichainAccountWalletId {\n return MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.test(value);\n}\n\n/**\n * Parse a multichain account wallet ID to an object containing wallet ID\n * information (wallet type and sub-ID).\n *\n * @param walletId - The account wallet ID to validate and parse.\n * @returns The parsed account wallet ID.\n * @throws When the wallet ID format is invalid.\n */\nexport function parseMultichainAccountWalletId(\n walletId: string,\n): ParsedMultichainAccountWalletId {\n const match = MULTICHAIN_ACCOUNT_WALLET_ID_REGEX.exec(walletId);\n if (!match?.groups) {\n throw new Error(`Invalid multichain account wallet ID: \"${walletId}\"`);\n }\n\n return {\n type: match.groups.walletType as AccountWalletType.Entropy,\n subId: match.groups.walletSubId as string,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.cjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for this provider.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n\n /**\n * Creates accounts for a given entropy source and a given group\n * index.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of created accounts.\n */\n createAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n\n /**\n * Discover accounts for a given entropy source and a given group\n * index.\n *\n * NOTE: This method needs to also create the discovered accounts.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of discovered and created accounts.\n */\n discoverAndCreateAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n};\n"]}
1
+ {"version":3,"file":"provider.cjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\n\nimport type { Bip44Account } from './bip44';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for this provider.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n\n /**\n * Creates accounts for a given entropy source and a given group\n * index.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of created accounts.\n */\n createAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n\n /**\n * Discover accounts for a given entropy source and a given group\n * index.\n *\n * NOTE: This method needs to also create the discovered accounts.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of discovered and created accounts.\n */\n discoverAndCreateAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n};\n\n/**\n * A BIP-44 provider is a provider that can provide BIP-44 compatible accounts.\n *\n * Note: This is an alias for the `AccountProvider` type, but with a more specific\n * type for the account.\n */\nexport type Bip44AccountProvider = AccountProvider<\n Bip44Account<KeyringAccount>\n>;\n"]}
@@ -1,4 +1,5 @@
1
1
  import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
2
+ import type { Bip44Account } from "./bip44.cjs";
2
3
  /**
3
4
  * An account provider is reponsible of providing accounts to an account group.
4
5
  */
@@ -44,4 +45,11 @@ export type AccountProvider<Account extends KeyringAccount> = {
44
45
  groupIndex: number;
45
46
  }) => Promise<Account[]>;
46
47
  };
48
+ /**
49
+ * A BIP-44 provider is a provider that can provide BIP-44 compatible accounts.
50
+ *
51
+ * Note: This is an alias for the `AccountProvider` type, but with a more specific
52
+ * type for the account.
53
+ */
54
+ export type Bip44AccountProvider = AccountProvider<Bip44Account<KeyringAccount>>;
47
55
  //# sourceMappingURL=provider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;IAE7B;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE;QACxB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE;QACnC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC1B,CAAC"}
1
+ {"version":3,"file":"provider.d.cts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAE5C;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;IAE7B;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE;QACxB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE;QACnC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAChD,YAAY,CAAC,cAAc,CAAC,CAC7B,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import type { EntropySourceId, KeyringAccount } from "@metamask/keyring-api";
2
+ import type { Bip44Account } from "./bip44.mjs";
2
3
  /**
3
4
  * An account provider is reponsible of providing accounts to an account group.
4
5
  */
@@ -44,4 +45,11 @@ export type AccountProvider<Account extends KeyringAccount> = {
44
45
  groupIndex: number;
45
46
  }) => Promise<Account[]>;
46
47
  };
48
+ /**
49
+ * A BIP-44 provider is a provider that can provide BIP-44 compatible accounts.
50
+ *
51
+ * Note: This is an alias for the `AccountProvider` type, but with a more specific
52
+ * type for the account.
53
+ */
54
+ export type Bip44AccountProvider = AccountProvider<Bip44Account<KeyringAccount>>;
47
55
  //# sourceMappingURL=provider.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.mts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;IAE7B;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE;QACxB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE;QACnC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC1B,CAAC"}
1
+ {"version":3,"file":"provider.d.mts","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,8BAA8B;AAE7E,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAgB;AAE5C;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,OAAO,SAAS,cAAc,IAAI;IAC5D;;;;OAIG;IACH,UAAU,EAAE,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,GAAG,SAAS,CAAC;IAEvD;;;;OAIG;IACH,WAAW,EAAE,MAAM,OAAO,EAAE,CAAC;IAE7B;;;;;;;;OAQG;IACH,cAAc,EAAE,CAAC,OAAO,EAAE;QACxB,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAEzB;;;;;;;;;;OAUG;IACH,yBAAyB,EAAE,CAAC,OAAO,EAAE;QACnC,aAAa,EAAE,eAAe,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;CAC1B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,eAAe,CAChD,YAAY,CAAC,cAAc,CAAC,CAC7B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"provider.mjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for this provider.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n\n /**\n * Creates accounts for a given entropy source and a given group\n * index.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of created accounts.\n */\n createAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n\n /**\n * Discover accounts for a given entropy source and a given group\n * index.\n *\n * NOTE: This method needs to also create the discovered accounts.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of discovered and created accounts.\n */\n discoverAndCreateAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n};\n"]}
1
+ {"version":3,"file":"provider.mjs","sourceRoot":"","sources":["../../src/api/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { EntropySourceId, KeyringAccount } from '@metamask/keyring-api';\n\nimport type { Bip44Account } from './bip44';\n\n/**\n * An account provider is reponsible of providing accounts to an account group.\n */\nexport type AccountProvider<Account extends KeyringAccount> = {\n /**\n * Gets an account for a given ID.\n *\n * @returns An account, or undefined if not found.\n */\n getAccount: (id: Account['id']) => Account | undefined;\n\n /**\n * Gets all accounts for this provider.\n *\n * @returns A list of all account for this provider.\n */\n getAccounts: () => Account[];\n\n /**\n * Creates accounts for a given entropy source and a given group\n * index.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of created accounts.\n */\n createAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n\n /**\n * Discover accounts for a given entropy source and a given group\n * index.\n *\n * NOTE: This method needs to also create the discovered accounts.\n *\n * @param options - Options.\n * @param options.entropySource - Entropy source to use.\n * @param options.groupIndex - Group index to use.\n * @returns The list of discovered and created accounts.\n */\n discoverAndCreateAccounts: (options: {\n entropySource: EntropySourceId;\n groupIndex: number;\n }) => Promise<Account[]>;\n};\n\n/**\n * A BIP-44 provider is a provider that can provide BIP-44 compatible accounts.\n *\n * Note: This is an alias for the `AccountProvider` type, but with a more specific\n * type for the account.\n */\nexport type Bip44AccountProvider = AccountProvider<\n Bip44Account<KeyringAccount>\n>;\n"]}
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccountWalletType = void 0;
3
+ exports.ACCOUNT_WALLET_ID_REGEX = exports.AccountWalletType = void 0;
4
4
  exports.toAccountWalletId = toAccountWalletId;
5
+ exports.isAccountWalletId = isAccountWalletId;
6
+ exports.parseAccountWalletId = parseAccountWalletId;
7
+ exports.stripAccountWalletType = stripAccountWalletType;
5
8
  /**
6
9
  * Wallet type.
7
10
  *
@@ -16,6 +19,10 @@ var AccountWalletType;
16
19
  /** Wallet grouping accounts associated with an account management Snap. */
17
20
  AccountWalletType["Snap"] = "snap";
18
21
  })(AccountWalletType || (exports.AccountWalletType = AccountWalletType = {}));
22
+ /**
23
+ * Regex to validate an account wallet ID.
24
+ */
25
+ exports.ACCOUNT_WALLET_ID_REGEX = /^(?<walletType>entropy|keyring|snap):(?<walletSubId>.+)$/u;
19
26
  /**
20
27
  * Convert a unique ID to a wallet ID for a given type.
21
28
  *
@@ -26,4 +33,41 @@ var AccountWalletType;
26
33
  function toAccountWalletId(type, id) {
27
34
  return `${type}:${id}`;
28
35
  }
36
+ /**
37
+ * Checks if the given value is {@link AccountWalletId}.
38
+ *
39
+ * @param value - The value to check.
40
+ * @returns Whether the value is a {@link AccountWalletId}.
41
+ */
42
+ function isAccountWalletId(value) {
43
+ return exports.ACCOUNT_WALLET_ID_REGEX.test(value);
44
+ }
45
+ /**
46
+ * Parse an account wallet ID to an object containing a wallet ID information
47
+ * (wallet type and wallet sub-ID).
48
+ *
49
+ * @param walletId - The account wallet ID to validate and parse.
50
+ * @returns The parsed account wallet ID.
51
+ * @throws When the wallet ID format is invalid.
52
+ */
53
+ function parseAccountWalletId(walletId) {
54
+ const match = exports.ACCOUNT_WALLET_ID_REGEX.exec(walletId);
55
+ if (!match?.groups) {
56
+ throw new Error(`Invalid account wallet ID: "${walletId}"`);
57
+ }
58
+ return {
59
+ type: match.groups.walletType,
60
+ subId: match.groups.walletSubId,
61
+ };
62
+ }
63
+ /**
64
+ * Strip the account wallet type from an account wallet ID.
65
+ *
66
+ * @param walletId - Account wallet ID.
67
+ * @returns Account wallet sub-ID.
68
+ * @throws When the wallet ID format is invalid.
69
+ */
70
+ function stripAccountWalletType(walletId) {
71
+ return parseAccountWalletId(walletId).subId;
72
+ }
29
73
  //# sourceMappingURL=wallet.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":";;;AAsEA,8CAKC;AAtED;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,2EAA2E;IAC3E,kCAAa,CAAA;AACf,CAAC,EATW,iBAAiB,iCAAjB,iBAAiB,QAS5B;AA4CD;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAAgB,EAChB,EAAU;IAEV,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { AccountGroup, AccountGroupId } from './group';\n\n/**\n * Wallet type.\n *\n * Each wallet types groups accounts using different criterias.\n */\nexport enum AccountWalletType {\n /** Wallet grouping accounts based on their entropy source. */\n Entropy = 'entropy',\n\n /** Wallet grouping accounts based on their keyring's type. */\n Keyring = 'keyring',\n\n /** Wallet grouping accounts associated with an account management Snap. */\n Snap = 'snap',\n}\n\n/**\n * Account wallet ID.\n */\nexport type AccountWalletId = `${AccountWalletType}:${string}`;\n\n/**\n * Account wallet that can hold multiple account groups.\n */\nexport type AccountWallet<Account extends KeyringAccount> = {\n /**\n * Account wallet ID.\n */\n get id(): AccountWalletId;\n\n /**\n * Account wallet type.\n */\n get type(): AccountWalletType;\n\n /**\n * Gets account group for a given ID.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;\n\n /**\n * Gets all account groups.\n *\n * @returns Account groups.\n */\n getAccountGroups(): AccountGroup<Account>[];\n};\n\n/**\n * Type utility to compute a constrained {@link AccountWalletId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountWalletIdOf<WalletType extends AccountWalletType> =\n `${WalletType}:${string}`;\n\n/**\n * Convert a unique ID to a wallet ID for a given type.\n *\n * @param type - A wallet type.\n * @param id - A unique ID.\n * @returns A wallet ID.\n */\nexport function toAccountWalletId<WalletType extends AccountWalletType>(\n type: WalletType,\n id: string,\n): AccountWalletIdOf<WalletType> {\n return `${type}:${id}`;\n}\n"]}
1
+ {"version":3,"file":"wallet.cjs","sourceRoot":"","sources":["../../src/api/wallet.ts"],"names":[],"mappings":";;;AAwJA,8CAKC;AAQD,8CAEC;AAUD,oDAUC;AASD,wDAEC;AA/LD;;;;GAIG;AACH,IAAY,iBASX;AATD,WAAY,iBAAiB;IAC3B,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,8DAA8D;IAC9D,wCAAmB,CAAA;IAEnB,2EAA2E;IAC3E,kCAAa,CAAA;AACf,CAAC,EATW,iBAAiB,iCAAjB,iBAAiB,QAS5B;AAOD;;GAEG;AACU,QAAA,uBAAuB,GAClC,2DAA2D,CAAC;AAiH9D;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,IAAgB,EAChB,EAAU;IAEV,OAAO,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;AACzB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAa;IAC7C,OAAO,+BAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAAC,QAAgB;IACnD,MAAM,KAAK,GAAG,+BAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,+BAA+B,QAAQ,GAAG,CAAC,CAAC;IAC9D,CAAC;IAED,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,UAA+B;QAClD,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,WAAqB;KAC1C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAAC,QAAgB;IACrD,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;AAC9C,CAAC","sourcesContent":["import type { KeyringAccount } from '@metamask/keyring-api';\n\n// Circular import are allowed when using `import type`.\nimport type { Bip44Account } from './bip44';\nimport type { AccountGroup, AccountGroupId } from './group';\nimport type { MultichainAccountWallet } from './multichain';\n\n/**\n * Wallet type.\n *\n * Each wallet types groups accounts using different criterias.\n */\nexport enum AccountWalletType {\n /** Wallet grouping accounts based on their entropy source. */\n Entropy = 'entropy',\n\n /** Wallet grouping accounts based on their keyring's type. */\n Keyring = 'keyring',\n\n /** Wallet grouping accounts associated with an account management Snap. */\n Snap = 'snap',\n}\n\n/**\n * Account wallet ID.\n */\nexport type AccountWalletId = `${AccountWalletType}:${string}`;\n\n/**\n * Regex to validate an account wallet ID.\n */\nexport const ACCOUNT_WALLET_ID_REGEX =\n /^(?<walletType>entropy|keyring|snap):(?<walletSubId>.+)$/u;\n\n/**\n * Wallet status.\n *\n * Those status are used to report in which \"state\" the wallet is currently\n * in. All of those operations cannot run concurrently, thus, the wallet\n * cannot have multiple status at once.\n */\nexport type AccountWalletStatus =\n /**\n * The wallet is not initialized yet.\n */\n | 'uninitialized'\n /**\n * The wallet is ready to run any operation.\n */\n | 'ready';\n\n/**\n * Parsed account wallet ID with its wallet type and sub-ID.\n */\nexport type ParsedAccountWalletId = {\n type: AccountWalletType;\n subId: string;\n};\n\n/**\n * Keyring account wallet that can hold multiple account groups.\n */\nexport type BaseAccountWallet<Account extends KeyringAccount> = {\n /**\n * Account wallet ID.\n */\n get id(): AccountWalletId;\n\n /**\n * Keyring account wallet type.\n */\n get type(): AccountWalletType;\n\n /**\n * Account wallet status.\n */\n get status(): AccountWalletStatus;\n\n /**\n * Gets account group for a given ID.\n *\n * @param id - Account group ID.\n * @returns Account group.\n */\n getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;\n\n /**\n * Gets all account groups.\n *\n * @returns Account groups.\n */\n getAccountGroups(): AccountGroup<Account>[];\n};\n\n/**\n * Keyring account wallet that can hold multiple account groups.\n */\nexport type KeyringAccountWallet<Account extends KeyringAccount> =\n BaseAccountWallet<Account> & {\n /**\n * Keyring account wallet type.\n */\n get type(): AccountWalletType.Keyring;\n };\n\n/**\n * Snap keyring account wallet that can hold multiple account groups.\n */\nexport type SnapAccountWallet<Account extends KeyringAccount> =\n BaseAccountWallet<Account> & {\n /**\n * Snap account wallet type.\n */\n get type(): AccountWalletType.Snap;\n };\n\n/**\n * Type constraint for a {@link AccountGroupObject}. If one of its union-members\n * does not match this contraint, {@link AccountGroupObject} will resolve\n * to `never`.\n */\ntype IsAccountWallet<\n Wallet extends BaseAccountWallet<Account> & {\n get type(): AccountWalletType;\n },\n Account extends KeyringAccount,\n> = Wallet;\n\n/**\n * Account wallet that can hold multiple account groups.\n */\nexport type AccountWallet<Account extends KeyringAccount> = IsAccountWallet<\n | KeyringAccountWallet<Account>\n | SnapAccountWallet<Account>\n | MultichainAccountWallet<Bip44Account<Account>>,\n Account\n>;\n\n/**\n * Type utility to compute a constrained {@link AccountWalletId} type given a\n * specifc {@link AccountWalletType}.\n */\nexport type AccountWalletIdOf<WalletType extends AccountWalletType> =\n `${WalletType}:${string}`;\n\n/**\n * Convert a unique ID to a wallet ID for a given type.\n *\n * @param type - A wallet type.\n * @param id - A unique ID.\n * @returns A wallet ID.\n */\nexport function toAccountWalletId<WalletType extends AccountWalletType>(\n type: WalletType,\n id: string,\n): AccountWalletIdOf<WalletType> {\n return `${type}:${id}`;\n}\n\n/**\n * Checks if the given value is {@link AccountWalletId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link AccountWalletId}.\n */\nexport function isAccountWalletId(value: string): value is AccountWalletId {\n return ACCOUNT_WALLET_ID_REGEX.test(value);\n}\n\n/**\n * Parse an account wallet ID to an object containing a wallet ID information\n * (wallet type and wallet sub-ID).\n *\n * @param walletId - The account wallet ID to validate and parse.\n * @returns The parsed account wallet ID.\n * @throws When the wallet ID format is invalid.\n */\nexport function parseAccountWalletId(walletId: string): ParsedAccountWalletId {\n const match = ACCOUNT_WALLET_ID_REGEX.exec(walletId);\n if (!match?.groups) {\n throw new Error(`Invalid account wallet ID: \"${walletId}\"`);\n }\n\n return {\n type: match.groups.walletType as AccountWalletType,\n subId: match.groups.walletSubId as string,\n };\n}\n\n/**\n * Strip the account wallet type from an account wallet ID.\n *\n * @param walletId - Account wallet ID.\n * @returns Account wallet sub-ID.\n * @throws When the wallet ID format is invalid.\n */\nexport function stripAccountWalletType(walletId: string): string {\n return parseAccountWalletId(walletId).subId;\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import type { KeyringAccount } from "@metamask/keyring-api";
2
+ import type { Bip44Account } from "./bip44.cjs";
2
3
  import type { AccountGroup, AccountGroupId } from "./group.cjs";
4
+ import type { MultichainAccountWallet } from "./multichain/index.cjs";
3
5
  /**
4
6
  * Wallet type.
5
7
  *
@@ -18,17 +20,48 @@ export declare enum AccountWalletType {
18
20
  */
19
21
  export type AccountWalletId = `${AccountWalletType}:${string}`;
20
22
  /**
21
- * Account wallet that can hold multiple account groups.
23
+ * Regex to validate an account wallet ID.
24
+ */
25
+ export declare const ACCOUNT_WALLET_ID_REGEX: RegExp;
26
+ /**
27
+ * Wallet status.
28
+ *
29
+ * Those status are used to report in which "state" the wallet is currently
30
+ * in. All of those operations cannot run concurrently, thus, the wallet
31
+ * cannot have multiple status at once.
32
+ */
33
+ export type AccountWalletStatus =
34
+ /**
35
+ * The wallet is not initialized yet.
36
+ */
37
+ 'uninitialized'
38
+ /**
39
+ * The wallet is ready to run any operation.
40
+ */
41
+ | 'ready';
42
+ /**
43
+ * Parsed account wallet ID with its wallet type and sub-ID.
22
44
  */
23
- export type AccountWallet<Account extends KeyringAccount> = {
45
+ export type ParsedAccountWalletId = {
46
+ type: AccountWalletType;
47
+ subId: string;
48
+ };
49
+ /**
50
+ * Keyring account wallet that can hold multiple account groups.
51
+ */
52
+ export type BaseAccountWallet<Account extends KeyringAccount> = {
24
53
  /**
25
54
  * Account wallet ID.
26
55
  */
27
56
  get id(): AccountWalletId;
28
57
  /**
29
- * Account wallet type.
58
+ * Keyring account wallet type.
30
59
  */
31
60
  get type(): AccountWalletType;
61
+ /**
62
+ * Account wallet status.
63
+ */
64
+ get status(): AccountWalletStatus;
32
65
  /**
33
66
  * Gets account group for a given ID.
34
67
  *
@@ -43,6 +76,36 @@ export type AccountWallet<Account extends KeyringAccount> = {
43
76
  */
44
77
  getAccountGroups(): AccountGroup<Account>[];
45
78
  };
79
+ /**
80
+ * Keyring account wallet that can hold multiple account groups.
81
+ */
82
+ export type KeyringAccountWallet<Account extends KeyringAccount> = BaseAccountWallet<Account> & {
83
+ /**
84
+ * Keyring account wallet type.
85
+ */
86
+ get type(): AccountWalletType.Keyring;
87
+ };
88
+ /**
89
+ * Snap keyring account wallet that can hold multiple account groups.
90
+ */
91
+ export type SnapAccountWallet<Account extends KeyringAccount> = BaseAccountWallet<Account> & {
92
+ /**
93
+ * Snap account wallet type.
94
+ */
95
+ get type(): AccountWalletType.Snap;
96
+ };
97
+ /**
98
+ * Type constraint for a {@link AccountGroupObject}. If one of its union-members
99
+ * does not match this contraint, {@link AccountGroupObject} will resolve
100
+ * to `never`.
101
+ */
102
+ type IsAccountWallet<Wallet extends BaseAccountWallet<Account> & {
103
+ get type(): AccountWalletType;
104
+ }, Account extends KeyringAccount> = Wallet;
105
+ /**
106
+ * Account wallet that can hold multiple account groups.
107
+ */
108
+ export type AccountWallet<Account extends KeyringAccount> = IsAccountWallet<KeyringAccountWallet<Account> | SnapAccountWallet<Account> | MultichainAccountWallet<Bip44Account<Account>>, Account>;
46
109
  /**
47
110
  * Type utility to compute a constrained {@link AccountWalletId} type given a
48
111
  * specifc {@link AccountWalletType}.
@@ -56,4 +119,29 @@ export type AccountWalletIdOf<WalletType extends AccountWalletType> = `${WalletT
56
119
  * @returns A wallet ID.
57
120
  */
58
121
  export declare function toAccountWalletId<WalletType extends AccountWalletType>(type: WalletType, id: string): AccountWalletIdOf<WalletType>;
122
+ /**
123
+ * Checks if the given value is {@link AccountWalletId}.
124
+ *
125
+ * @param value - The value to check.
126
+ * @returns Whether the value is a {@link AccountWalletId}.
127
+ */
128
+ export declare function isAccountWalletId(value: string): value is AccountWalletId;
129
+ /**
130
+ * Parse an account wallet ID to an object containing a wallet ID information
131
+ * (wallet type and wallet sub-ID).
132
+ *
133
+ * @param walletId - The account wallet ID to validate and parse.
134
+ * @returns The parsed account wallet ID.
135
+ * @throws When the wallet ID format is invalid.
136
+ */
137
+ export declare function parseAccountWalletId(walletId: string): ParsedAccountWalletId;
138
+ /**
139
+ * Strip the account wallet type from an account wallet ID.
140
+ *
141
+ * @param walletId - Account wallet ID.
142
+ * @returns Account wallet sub-ID.
143
+ * @throws When the wallet ID format is invalid.
144
+ */
145
+ export declare function stripAccountWalletType(walletId: string): string;
146
+ export {};
59
147
  //# sourceMappingURL=wallet.d.cts.map