@metamask-previews/account-api 0.9.0-a621908 → 0.10.0-8ac053c

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 (94) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/api/bip44.cjs +3 -4
  3. package/dist/api/bip44.cjs.map +1 -1
  4. package/dist/api/bip44.d.cts.map +1 -1
  5. package/dist/api/bip44.d.mts.map +1 -1
  6. package/dist/api/bip44.mjs +3 -4
  7. package/dist/api/bip44.mjs.map +1 -1
  8. package/dist/api/group.cjs +53 -1
  9. package/dist/api/group.cjs.map +1 -1
  10. package/dist/api/group.d.cts +41 -1
  11. package/dist/api/group.d.cts.map +1 -1
  12. package/dist/api/group.d.mts +41 -1
  13. package/dist/api/group.d.mts.map +1 -1
  14. package/dist/api/group.mjs +49 -0
  15. package/dist/api/group.mjs.map +1 -1
  16. package/dist/api/multichain/group.cjs +35 -10
  17. package/dist/api/multichain/group.cjs.map +1 -1
  18. package/dist/api/multichain/group.d.cts +27 -0
  19. package/dist/api/multichain/group.d.cts.map +1 -1
  20. package/dist/api/multichain/group.d.mts +27 -0
  21. package/dist/api/multichain/group.d.mts.map +1 -1
  22. package/dist/api/multichain/group.mjs +32 -9
  23. package/dist/api/multichain/group.mjs.map +1 -1
  24. package/dist/api/multichain/wallet.cjs +34 -0
  25. package/dist/api/multichain/wallet.cjs.map +1 -1
  26. package/dist/api/multichain/wallet.d.cts +70 -2
  27. package/dist/api/multichain/wallet.d.cts.map +1 -1
  28. package/dist/api/multichain/wallet.d.mts +70 -2
  29. package/dist/api/multichain/wallet.d.mts.map +1 -1
  30. package/dist/api/multichain/wallet.mjs +31 -0
  31. package/dist/api/multichain/wallet.mjs.map +1 -1
  32. package/dist/api/provider.cjs.map +1 -1
  33. package/dist/api/provider.d.cts +8 -0
  34. package/dist/api/provider.d.cts.map +1 -1
  35. package/dist/api/provider.d.mts +8 -0
  36. package/dist/api/provider.d.mts.map +1 -1
  37. package/dist/api/provider.mjs.map +1 -1
  38. package/dist/api/wallet.cjs +45 -1
  39. package/dist/api/wallet.cjs.map +1 -1
  40. package/dist/api/wallet.d.cts +96 -2
  41. package/dist/api/wallet.d.cts.map +1 -1
  42. package/dist/api/wallet.d.mts +96 -2
  43. package/dist/api/wallet.d.mts.map +1 -1
  44. package/dist/api/wallet.mjs +41 -0
  45. package/dist/api/wallet.mjs.map +1 -1
  46. package/dist/mocks/accounts.cjs +10 -27
  47. package/dist/mocks/accounts.cjs.map +1 -1
  48. package/dist/mocks/accounts.d.cts +0 -18
  49. package/dist/mocks/accounts.d.cts.map +1 -1
  50. package/dist/mocks/accounts.d.mts +0 -18
  51. package/dist/mocks/accounts.d.mts.map +1 -1
  52. package/dist/mocks/accounts.mjs +3 -20
  53. package/dist/mocks/accounts.mjs.map +1 -1
  54. package/dist/mocks/groups.cjs +9 -0
  55. package/dist/mocks/groups.cjs.map +1 -0
  56. package/dist/mocks/groups.d.cts +5 -0
  57. package/dist/mocks/groups.d.cts.map +1 -0
  58. package/dist/mocks/groups.d.mts +5 -0
  59. package/dist/mocks/groups.d.mts.map +1 -0
  60. package/dist/mocks/groups.mjs +6 -0
  61. package/dist/mocks/groups.mjs.map +1 -0
  62. package/dist/mocks/index.cjs +4 -0
  63. package/dist/mocks/index.cjs.map +1 -1
  64. package/dist/mocks/index.d.cts +4 -0
  65. package/dist/mocks/index.d.cts.map +1 -1
  66. package/dist/mocks/index.d.mts +4 -0
  67. package/dist/mocks/index.d.mts.map +1 -1
  68. package/dist/mocks/index.mjs +4 -0
  69. package/dist/mocks/index.mjs.map +1 -1
  70. package/dist/mocks/keyrings.cjs +7 -0
  71. package/dist/mocks/keyrings.cjs.map +1 -0
  72. package/dist/mocks/keyrings.d.cts +4 -0
  73. package/dist/mocks/keyrings.d.cts.map +1 -0
  74. package/dist/mocks/keyrings.d.mts +4 -0
  75. package/dist/mocks/keyrings.d.mts.map +1 -0
  76. package/dist/mocks/keyrings.mjs +4 -0
  77. package/dist/mocks/keyrings.mjs.map +1 -0
  78. package/dist/mocks/snaps.cjs +20 -0
  79. package/dist/mocks/snaps.cjs.map +1 -0
  80. package/dist/mocks/snaps.d.cts +17 -0
  81. package/dist/mocks/snaps.d.cts.map +1 -0
  82. package/dist/mocks/snaps.d.mts +17 -0
  83. package/dist/mocks/snaps.d.mts.map +1 -0
  84. package/dist/mocks/snaps.mjs +17 -0
  85. package/dist/mocks/snaps.mjs.map +1 -0
  86. package/dist/mocks/wallets.cjs +11 -0
  87. package/dist/mocks/wallets.cjs.map +1 -0
  88. package/dist/mocks/wallets.d.cts +5 -0
  89. package/dist/mocks/wallets.d.cts.map +1 -0
  90. package/dist/mocks/wallets.d.mts +5 -0
  91. package/dist/mocks/wallets.d.mts.map +1 -0
  92. package/dist/mocks/wallets.mjs +8 -0
  93. package/dist/mocks/wallets.mjs.map +1 -0
  94. package/package.json +2 -3
@@ -2,10 +2,26 @@ import { type KeyringAccount } from "@metamask/keyring-api";
2
2
  import type { MultichainAccountWallet, MultichainAccountWalletId } from "./wallet.mjs";
3
3
  import type { Bip44Account } from "../bip44.mjs";
4
4
  import type { AccountGroup, AccountGroupType } from "../group.mjs";
5
+ import type { AccountWalletType } from "../wallet.mjs";
5
6
  /**
6
7
  * Multichain account ID.
7
8
  */
8
9
  export type MultichainAccountGroupId = `${MultichainAccountWalletId}/${number}`;
10
+ /**
11
+ * Regex to validate a valid multichain account group ID.
12
+ */
13
+ export declare const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX: RegExp;
14
+ /**
15
+ * Parsed account group ID with its parsed wallet component and its sub-ID.
16
+ */
17
+ export type ParsedMultichainAccountGroupId = {
18
+ wallet: {
19
+ id: MultichainAccountWalletId;
20
+ type: AccountWalletType.Entropy;
21
+ subId: string;
22
+ };
23
+ groupIndex: number;
24
+ };
9
25
  /**
10
26
  * A multichain account that holds multiple accounts.
11
27
  */
@@ -42,11 +58,22 @@ export declare function toMultichainAccountGroupId(walletId: MultichainAccountWa
42
58
  * @returns Whether the value is a {@link MultichainAccountGroupId}.
43
59
  */
44
60
  export declare function isMultichainAccountGroupId(value: string): value is MultichainAccountGroupId;
61
+ /**
62
+ * Parse a multichain account group ID to an object containing a multichain
63
+ * wallet ID information (wallet type and wallet sub-ID), as well as
64
+ * multichain account group ID information (group index).
65
+ *
66
+ * @param groupId - The multichain account group ID to validate and parse.
67
+ * @returns The parsed multichain account group ID.
68
+ * @throws When the group ID format is invalid.
69
+ */
70
+ export declare function parseMultichainAccountGroupId(groupId: string): ParsedMultichainAccountGroupId;
45
71
  /**
46
72
  * Gets the multichain account index from an account group ID.
47
73
  *
48
74
  * @param id - Multichain account ID.
49
75
  * @returns The multichain account index if extractable, undefined otherwise.
76
+ * @throws When the group ID format is invalid.
50
77
  */
51
78
  export declare function getGroupIndexFromMultichainAccountGroupId(id: MultichainAccountGroupId): number;
52
79
  //# sourceMappingURL=group.d.mts.map
@@ -1 +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;AAQ/D;;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,uBAAu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AAwB,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,UAAU,IAAI,MAAM,CAAC;CAC1B,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;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,MAAM,GACd,8BAA8B,CAkBhC;AAED;;;;;;GAMG;AACH,wBAAgB,yCAAyC,CACvD,EAAE,EAAE,wBAAwB,GAC3B,MAAM,CAER"}
@@ -1,5 +1,7 @@
1
- import { AccountWalletType } from "../wallet.mjs";
2
- const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = new RegExp(`^${AccountWalletType.Entropy}:.*/(?<groupIndex>\\d+)$`, 'u');
1
+ /**
2
+ * Regex to validate a valid multichain account group ID.
3
+ */
4
+ export const MULTICHAIN_ACCOUNT_GROUP_ID_REGEX = /^(?<walletId>(?<walletType>entropy):(?<walletSubId>.+))\/(?<groupIndex>[0-9]+)$/u;
3
5
  /**
4
6
  * Gets the multichain account group ID from its multichain account wallet ID and its index.
5
7
  *
@@ -19,19 +21,40 @@ export function toMultichainAccountGroupId(walletId, groupIndex) {
19
21
  export function isMultichainAccountGroupId(value) {
20
22
  return MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.test(value);
21
23
  }
24
+ /**
25
+ * Parse a multichain account group ID to an object containing a multichain
26
+ * wallet ID information (wallet type and wallet sub-ID), as well as
27
+ * multichain account group ID information (group index).
28
+ *
29
+ * @param groupId - The multichain account group ID to validate and parse.
30
+ * @returns The parsed multichain account group ID.
31
+ * @throws When the group ID format is invalid.
32
+ */
33
+ export function parseMultichainAccountGroupId(groupId) {
34
+ const match = MULTICHAIN_ACCOUNT_GROUP_ID_REGEX.exec(groupId);
35
+ if (!match?.groups) {
36
+ throw new Error(`Invalid multichain account group ID: "${groupId}"`);
37
+ }
38
+ const walletId = match.groups.walletId;
39
+ const walletType = match.groups.walletType;
40
+ const walletSubId = match.groups.walletSubId;
41
+ return {
42
+ wallet: {
43
+ id: walletId,
44
+ type: walletType,
45
+ subId: walletSubId,
46
+ },
47
+ groupIndex: Number(match.groups.groupIndex),
48
+ };
49
+ }
22
50
  /**
23
51
  * Gets the multichain account index from an account group ID.
24
52
  *
25
53
  * @param id - Multichain account ID.
26
54
  * @returns The multichain account index if extractable, undefined otherwise.
55
+ * @throws When the group ID format is invalid.
27
56
  */
28
57
  export function getGroupIndexFromMultichainAccountGroupId(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);
58
+ return parseMultichainAccountGroupId(id).groupIndex;
36
59
  }
37
60
  //# sourceMappingURL=group.mjs.map
@@ -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":";;;AA0HA,kEAIC;AAQD,kEAIC;AAUD,wEAYC;AAvJD,0CAA8C;AAQ9C;;GAEG;AACU,QAAA,kCAAkC,GAC7C,2DAA2D,CAAC;AA+F9D;;;;;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 { AccountGroup, AccountGroupId } from '../group';\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 * The wallet is creating new accounts. New account groups will be\n * added to the wallet automatically.\n */\n | 'in-progress:create-accounts';\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 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 * 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 { AccountGroup, AccountGroupId } from "../group.cjs";
5
+ import type { AccountWalletStatus, BaseAccountWallet } from "../wallet.cjs";
5
6
  import { AccountWalletType } from "../wallet.cjs";
6
7
  /**
7
8
  * Multichain account wallet ID.
8
9
  */
9
10
  export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
11
+ /**
12
+ * Regex to validate a valid multichain account wallet ID.
13
+ */
14
+ export declare const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX: RegExp;
15
+ /**
16
+ * Parsed multichain account wallet ID with its wallet type and sub-ID.
17
+ */
18
+ export type ParsedMultichainAccountWalletId = {
19
+ type: AccountWalletType.Entropy;
20
+ subId: string;
21
+ };
22
+ /**
23
+ * Wallet status.
24
+ *
25
+ * Those status are used to report in which "state" the wallet is currently
26
+ * in. All of those operations cannot run concurrently, thus, the wallet
27
+ * cannot have multiple status at once.
28
+ */
29
+ export type MultichainAccountWalletStatus = AccountWalletStatus
30
+ /**
31
+ * Discovery is in progress for this wallet. New account groups will be
32
+ * automatically added based on the account provider discovery result.
33
+ */
34
+ | 'in-progress:discovery'
35
+ /**
36
+ * Alignment is in progress for this wallet. Account groups will be
37
+ * automatically updated based on the active account providers.
38
+ */
39
+ | 'in-progress:alignment'
40
+ /**
41
+ * The wallet is creating new accounts. New account groups will be
42
+ * added to the wallet automatically.
43
+ */
44
+ | 'in-progress:create-accounts';
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,23 @@ 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;
66
+ /**
67
+ * Gets account group for a given ID.
68
+ *
69
+ * @param id - Account group ID.
70
+ * @returns Account group.
71
+ */
72
+ getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;
73
+ /**
74
+ * Gets all account groups.
75
+ *
76
+ * @returns Account groups.
77
+ */
78
+ getAccountGroups(): AccountGroup<Account>[];
27
79
  /**
28
80
  * Gets multichain account for a given index.
29
81
  *
@@ -45,4 +97,20 @@ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>
45
97
  * @returns The multichain account wallet ID.
46
98
  */
47
99
  export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
100
+ /**
101
+ * Checks if the given value is {@link MultichainAccountWalletId}.
102
+ *
103
+ * @param value - The value to check.
104
+ * @returns Whether the value is a {@link MultichainAccountWalletId}.
105
+ */
106
+ export declare function isMultichainAccountWalletId(value: string): value is MultichainAccountWalletId;
107
+ /**
108
+ * Parse a multichain account wallet ID to an object containing wallet ID
109
+ * information (wallet type and sub-ID).
110
+ *
111
+ * @param walletId - The account wallet ID to validate and parse.
112
+ * @returns The parsed account wallet ID.
113
+ * @throws When the wallet ID format is invalid.
114
+ */
115
+ export declare function parseMultichainAccountWalletId(walletId: string): ParsedMultichainAccountWalletId;
48
116
  //# 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,G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AAC,OAAO,CAAC;IAEtC;;OAEG;IACH,IAAI,aAAa,IAAI,eAAe,CAAC;IAErC;;OAEG;IACH,IAAI,MAAM,IAAI,6BAA6B,CAAC;IAE5C;;;;;OAKG;IACH,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,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 { AccountGroup, AccountGroupId } from "../group.mjs";
5
+ import type { AccountWalletStatus, BaseAccountWallet } from "../wallet.mjs";
5
6
  import { AccountWalletType } from "../wallet.mjs";
6
7
  /**
7
8
  * Multichain account wallet ID.
8
9
  */
9
10
  export type MultichainAccountWalletId = `${AccountWalletType.Entropy}:${EntropySourceId}`;
11
+ /**
12
+ * Regex to validate a valid multichain account wallet ID.
13
+ */
14
+ export declare const MULTICHAIN_ACCOUNT_WALLET_ID_REGEX: RegExp;
15
+ /**
16
+ * Parsed multichain account wallet ID with its wallet type and sub-ID.
17
+ */
18
+ export type ParsedMultichainAccountWalletId = {
19
+ type: AccountWalletType.Entropy;
20
+ subId: string;
21
+ };
22
+ /**
23
+ * Wallet status.
24
+ *
25
+ * Those status are used to report in which "state" the wallet is currently
26
+ * in. All of those operations cannot run concurrently, thus, the wallet
27
+ * cannot have multiple status at once.
28
+ */
29
+ export type MultichainAccountWalletStatus = AccountWalletStatus
30
+ /**
31
+ * Discovery is in progress for this wallet. New account groups will be
32
+ * automatically added based on the account provider discovery result.
33
+ */
34
+ | 'in-progress:discovery'
35
+ /**
36
+ * Alignment is in progress for this wallet. Account groups will be
37
+ * automatically updated based on the active account providers.
38
+ */
39
+ | 'in-progress:alignment'
40
+ /**
41
+ * The wallet is creating new accounts. New account groups will be
42
+ * added to the wallet automatically.
43
+ */
44
+ | 'in-progress:create-accounts';
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,23 @@ 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;
66
+ /**
67
+ * Gets account group for a given ID.
68
+ *
69
+ * @param id - Account group ID.
70
+ * @returns Account group.
71
+ */
72
+ getAccountGroup(id: AccountGroupId): AccountGroup<Account> | undefined;
73
+ /**
74
+ * Gets all account groups.
75
+ *
76
+ * @returns Account groups.
77
+ */
78
+ getAccountGroups(): AccountGroup<Account>[];
27
79
  /**
28
80
  * Gets multichain account for a given index.
29
81
  *
@@ -45,4 +97,20 @@ export type MultichainAccountWallet<Account extends Bip44Account<KeyringAccount>
45
97
  * @returns The multichain account wallet ID.
46
98
  */
47
99
  export declare function toMultichainAccountWalletId(entropySource: EntropySourceId): MultichainAccountWalletId;
100
+ /**
101
+ * Checks if the given value is {@link MultichainAccountWalletId}.
102
+ *
103
+ * @param value - The value to check.
104
+ * @returns Whether the value is a {@link MultichainAccountWalletId}.
105
+ */
106
+ export declare function isMultichainAccountWalletId(value: string): value is MultichainAccountWalletId;
107
+ /**
108
+ * Parse a multichain account wallet ID to an object containing wallet ID
109
+ * information (wallet type and sub-ID).
110
+ *
111
+ * @param walletId - The account wallet ID to validate and parse.
112
+ * @returns The parsed account wallet ID.
113
+ * @throws When the wallet ID format is invalid.
114
+ */
115
+ export declare function parseMultichainAccountWalletId(walletId: string): ParsedMultichainAccountWalletId;
48
116
  //# 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;I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AAC,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,eAAe,CAAC,EAAE,EAAE,cAAc,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvE;;;;OAIG;IACH,gBAAgB,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,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":"AASA,OAAO,EAAE,iBAAiB,EAAE,sBAAkB;AAQ9C;;GAEG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAC7C,2DAA2D,CAAC;AA+F9D;;;;;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 { AccountGroup, AccountGroupId } from '../group';\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 * The wallet is creating new accounts. New account groups will be\n * added to the wallet automatically.\n */\n | 'in-progress:create-accounts';\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 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 * 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,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C1B,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