@metamask-previews/keyring-api 21.1.0-8202c83 → 21.3.0-ca02a28

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 (191) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +11 -0
  3. package/dist/api/account.cjs +15 -1
  4. package/dist/api/account.cjs.map +1 -1
  5. package/dist/api/account.d.cts +14 -0
  6. package/dist/api/account.d.cts.map +1 -1
  7. package/dist/api/account.d.mts +14 -0
  8. package/dist/api/account.d.mts.map +1 -1
  9. package/dist/api/account.mjs +14 -0
  10. package/dist/api/account.mjs.map +1 -1
  11. package/dist/api/index.cjs +1 -0
  12. package/dist/api/index.cjs.map +1 -1
  13. package/dist/api/index.d.cts +1 -0
  14. package/dist/api/index.d.cts.map +1 -1
  15. package/dist/api/index.d.mts +1 -0
  16. package/dist/api/index.d.mts.map +1 -1
  17. package/dist/api/index.mjs +1 -0
  18. package/dist/api/index.mjs.map +1 -1
  19. package/dist/api/keyring.cjs +0 -2
  20. package/dist/api/keyring.cjs.map +1 -1
  21. package/dist/api/keyring.d.cts.map +1 -1
  22. package/dist/api/keyring.d.mts.map +1 -1
  23. package/dist/api/keyring.mjs +0 -2
  24. package/dist/api/keyring.mjs.map +1 -1
  25. package/dist/api/v2/create-account/bip44.cjs +57 -0
  26. package/dist/api/v2/create-account/bip44.cjs.map +1 -0
  27. package/dist/api/v2/create-account/bip44.d.cts +83 -0
  28. package/dist/api/v2/create-account/bip44.d.cts.map +1 -0
  29. package/dist/api/v2/create-account/bip44.d.mts +83 -0
  30. package/dist/api/v2/create-account/bip44.d.mts.map +1 -0
  31. package/dist/api/v2/create-account/bip44.mjs +54 -0
  32. package/dist/api/v2/create-account/bip44.mjs.map +1 -0
  33. package/dist/api/v2/create-account/index.cjs +72 -0
  34. package/dist/api/v2/create-account/index.cjs.map +1 -0
  35. package/dist/api/v2/create-account/index.d.cts +58 -0
  36. package/dist/api/v2/create-account/index.d.cts.map +1 -0
  37. package/dist/api/v2/create-account/index.d.mts +58 -0
  38. package/dist/api/v2/create-account/index.d.mts.map +1 -0
  39. package/dist/api/v2/create-account/index.mjs +55 -0
  40. package/dist/api/v2/create-account/index.mjs.map +1 -0
  41. package/dist/api/v2/create-account/private-key.cjs +28 -0
  42. package/dist/api/v2/create-account/private-key.cjs.map +1 -0
  43. package/dist/api/v2/create-account/private-key.d.cts +45 -0
  44. package/dist/api/v2/create-account/private-key.d.cts.map +1 -0
  45. package/dist/api/v2/create-account/private-key.d.mts +45 -0
  46. package/dist/api/v2/create-account/private-key.d.mts.map +1 -0
  47. package/dist/api/v2/create-account/private-key.mjs +25 -0
  48. package/dist/api/v2/create-account/private-key.mjs.map +1 -0
  49. package/dist/api/v2/export-account/index.cjs +38 -0
  50. package/dist/api/v2/export-account/index.cjs.map +1 -0
  51. package/dist/api/v2/export-account/index.d.cts +48 -0
  52. package/dist/api/v2/export-account/index.d.cts.map +1 -0
  53. package/dist/api/v2/export-account/index.d.mts +48 -0
  54. package/dist/api/v2/export-account/index.d.mts.map +1 -0
  55. package/dist/api/v2/export-account/index.mjs +21 -0
  56. package/dist/api/v2/export-account/index.mjs.map +1 -0
  57. package/dist/api/v2/export-account/private-key.cjs +36 -0
  58. package/dist/api/v2/export-account/private-key.cjs.map +1 -0
  59. package/dist/api/v2/export-account/private-key.d.cts +53 -0
  60. package/dist/api/v2/export-account/private-key.d.cts.map +1 -0
  61. package/dist/api/v2/export-account/private-key.d.mts +53 -0
  62. package/dist/api/v2/export-account/private-key.d.mts.map +1 -0
  63. package/dist/api/v2/export-account/private-key.mjs +33 -0
  64. package/dist/api/v2/export-account/private-key.mjs.map +1 -0
  65. package/dist/api/v2/index.cjs +23 -0
  66. package/dist/api/v2/index.cjs.map +1 -0
  67. package/dist/api/v2/index.d.cts +8 -0
  68. package/dist/api/v2/index.d.cts.map +1 -0
  69. package/dist/api/v2/index.d.mts +8 -0
  70. package/dist/api/v2/index.d.mts.map +1 -0
  71. package/dist/api/v2/index.mjs +7 -0
  72. package/dist/api/v2/index.mjs.map +1 -0
  73. package/dist/api/v2/keyring-capabilities.cjs +46 -0
  74. package/dist/api/v2/keyring-capabilities.cjs.map +1 -0
  75. package/dist/api/v2/keyring-capabilities.d.cts +128 -0
  76. package/dist/api/v2/keyring-capabilities.d.cts.map +1 -0
  77. package/dist/api/v2/keyring-capabilities.d.mts +128 -0
  78. package/dist/api/v2/keyring-capabilities.d.mts.map +1 -0
  79. package/dist/api/v2/keyring-capabilities.mjs +43 -0
  80. package/dist/api/v2/keyring-capabilities.mjs.map +1 -0
  81. package/dist/api/v2/keyring-type.cjs +44 -0
  82. package/dist/api/v2/keyring-type.cjs.map +1 -0
  83. package/dist/api/v2/keyring-type.d.cts +40 -0
  84. package/dist/api/v2/keyring-type.d.cts.map +1 -0
  85. package/dist/api/v2/keyring-type.d.mts +40 -0
  86. package/dist/api/v2/keyring-type.d.mts.map +1 -0
  87. package/dist/api/v2/keyring-type.mjs +41 -0
  88. package/dist/api/v2/keyring-type.mjs.map +1 -0
  89. package/dist/api/v2/keyring.cjs +3 -0
  90. package/dist/api/v2/keyring.cjs.map +1 -0
  91. package/dist/api/v2/keyring.d.cts +107 -0
  92. package/dist/api/v2/keyring.d.cts.map +1 -0
  93. package/dist/api/v2/keyring.d.mts +107 -0
  94. package/dist/api/v2/keyring.d.mts.map +1 -0
  95. package/dist/api/v2/keyring.mjs +2 -0
  96. package/dist/api/v2/keyring.mjs.map +1 -0
  97. package/dist/api/v2/private-key.cjs +53 -0
  98. package/dist/api/v2/private-key.cjs.map +1 -0
  99. package/dist/api/v2/private-key.d.cts +77 -0
  100. package/dist/api/v2/private-key.d.cts.map +1 -0
  101. package/dist/api/v2/private-key.d.mts +77 -0
  102. package/dist/api/v2/private-key.d.mts.map +1 -0
  103. package/dist/api/v2/private-key.mjs +50 -0
  104. package/dist/api/v2/private-key.mjs.map +1 -0
  105. package/dist/api/v2/wrapper/index.cjs +19 -0
  106. package/dist/api/v2/wrapper/index.cjs.map +1 -0
  107. package/dist/api/v2/wrapper/index.d.cts +3 -0
  108. package/dist/api/v2/wrapper/index.d.cts.map +1 -0
  109. package/dist/api/v2/wrapper/index.d.mts +3 -0
  110. package/dist/api/v2/wrapper/index.d.mts.map +1 -0
  111. package/dist/api/v2/wrapper/index.mjs +3 -0
  112. package/dist/api/v2/wrapper/index.mjs.map +1 -0
  113. package/dist/api/v2/wrapper/keyring-account-registry.cjs +135 -0
  114. package/dist/api/v2/wrapper/keyring-account-registry.cjs.map +1 -0
  115. package/dist/api/v2/wrapper/keyring-account-registry.d.cts +88 -0
  116. package/dist/api/v2/wrapper/keyring-account-registry.d.cts.map +1 -0
  117. package/dist/api/v2/wrapper/keyring-account-registry.d.mts +88 -0
  118. package/dist/api/v2/wrapper/keyring-account-registry.d.mts.map +1 -0
  119. package/dist/api/v2/wrapper/keyring-account-registry.mjs +131 -0
  120. package/dist/api/v2/wrapper/keyring-account-registry.mjs.map +1 -0
  121. package/dist/api/v2/wrapper/keyring-wrapper.cjs +116 -0
  122. package/dist/api/v2/wrapper/keyring-wrapper.cjs.map +1 -0
  123. package/dist/api/v2/wrapper/keyring-wrapper.d.cts +146 -0
  124. package/dist/api/v2/wrapper/keyring-wrapper.d.cts.map +1 -0
  125. package/dist/api/v2/wrapper/keyring-wrapper.d.mts +146 -0
  126. package/dist/api/v2/wrapper/keyring-wrapper.d.mts.map +1 -0
  127. package/dist/api/v2/wrapper/keyring-wrapper.mjs +112 -0
  128. package/dist/api/v2/wrapper/keyring-wrapper.mjs.map +1 -0
  129. package/dist/eth/erc4337/types.d.cts +4 -4
  130. package/dist/eth/erc4337/types.d.mts +4 -4
  131. package/dist/eth/index.cjs +2 -0
  132. package/dist/eth/index.cjs.map +1 -1
  133. package/dist/eth/index.d.cts +2 -0
  134. package/dist/eth/index.d.cts.map +1 -1
  135. package/dist/eth/index.d.mts +2 -0
  136. package/dist/eth/index.d.mts.map +1 -1
  137. package/dist/eth/index.mjs +2 -0
  138. package/dist/eth/index.mjs.map +1 -1
  139. package/dist/eth/rpc/index.cjs +18 -0
  140. package/dist/eth/rpc/index.cjs.map +1 -0
  141. package/dist/eth/rpc/index.d.cts +2 -0
  142. package/dist/eth/rpc/index.d.cts.map +1 -0
  143. package/dist/eth/rpc/index.d.mts +2 -0
  144. package/dist/eth/rpc/index.d.mts.map +1 -0
  145. package/dist/eth/rpc/index.mjs +2 -0
  146. package/dist/eth/rpc/index.mjs.map +1 -0
  147. package/dist/eth/rpc/params.cjs +151 -0
  148. package/dist/eth/rpc/params.cjs.map +1 -0
  149. package/dist/eth/rpc/params.d.cts +215 -0
  150. package/dist/eth/rpc/params.d.cts.map +1 -0
  151. package/dist/eth/rpc/params.d.mts +215 -0
  152. package/dist/eth/rpc/params.d.mts.map +1 -0
  153. package/dist/eth/rpc/params.mjs +148 -0
  154. package/dist/eth/rpc/params.mjs.map +1 -0
  155. package/dist/eth/types.cjs.map +1 -1
  156. package/dist/eth/types.d.cts +5 -5
  157. package/dist/eth/types.d.cts.map +1 -1
  158. package/dist/eth/types.d.mts +5 -5
  159. package/dist/eth/types.d.mts.map +1 -1
  160. package/dist/eth/types.mjs.map +1 -1
  161. package/dist/eth/v2/eth-keyring-wrapper.cjs +165 -0
  162. package/dist/eth/v2/eth-keyring-wrapper.cjs.map +1 -0
  163. package/dist/eth/v2/eth-keyring-wrapper.d.cts +54 -0
  164. package/dist/eth/v2/eth-keyring-wrapper.d.cts.map +1 -0
  165. package/dist/eth/v2/eth-keyring-wrapper.d.mts +54 -0
  166. package/dist/eth/v2/eth-keyring-wrapper.d.mts.map +1 -0
  167. package/dist/eth/v2/eth-keyring-wrapper.mjs +161 -0
  168. package/dist/eth/v2/eth-keyring-wrapper.mjs.map +1 -0
  169. package/dist/eth/v2/index.cjs +18 -0
  170. package/dist/eth/v2/index.cjs.map +1 -0
  171. package/dist/eth/v2/index.d.cts +2 -0
  172. package/dist/eth/v2/index.d.cts.map +1 -0
  173. package/dist/eth/v2/index.d.mts +2 -0
  174. package/dist/eth/v2/index.d.mts.map +1 -0
  175. package/dist/eth/v2/index.mjs +2 -0
  176. package/dist/eth/v2/index.mjs.map +1 -0
  177. package/dist/events.cjs +0 -2
  178. package/dist/events.cjs.map +1 -1
  179. package/dist/events.d.cts.map +1 -1
  180. package/dist/events.d.mts.map +1 -1
  181. package/dist/events.mjs +0 -2
  182. package/dist/events.mjs.map +1 -1
  183. package/dist/trx/types.cjs +4 -0
  184. package/dist/trx/types.cjs.map +1 -1
  185. package/dist/trx/types.d.cts +4 -0
  186. package/dist/trx/types.d.cts.map +1 -1
  187. package/dist/trx/types.d.mts +4 -0
  188. package/dist/trx/types.d.mts.map +1 -1
  189. package/dist/trx/types.mjs +4 -0
  190. package/dist/trx/types.mjs.map +1 -1
  191. package/package.json +7 -2
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExportPrivateKeyFormatStruct = exports.ImportPrivateKeyFormatStruct = exports.PrivateKeyEncodingStruct = exports.PrivateKeyEncoding = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const account_1 = require("../account.cjs");
6
+ /**
7
+ * Supported encoding formats for private keys.
8
+ */
9
+ var PrivateKeyEncoding;
10
+ (function (PrivateKeyEncoding) {
11
+ /**
12
+ * Hexadecimal encoding format.
13
+ */
14
+ PrivateKeyEncoding["Hexadecimal"] = "hexadecimal";
15
+ /**
16
+ * Base58 encoding format.
17
+ */
18
+ PrivateKeyEncoding["Base58"] = "base58";
19
+ })(PrivateKeyEncoding || (exports.PrivateKeyEncoding = PrivateKeyEncoding = {}));
20
+ /**
21
+ * Struct for {@link PrivateKeyEncoding}.
22
+ */
23
+ exports.PrivateKeyEncodingStruct = (0, superstruct_1.enums)([
24
+ `${PrivateKeyEncoding.Hexadecimal}`,
25
+ `${PrivateKeyEncoding.Base58}`,
26
+ ]);
27
+ /**
28
+ * Struct for {@link ImportPrivateKeyFormat}.
29
+ */
30
+ exports.ImportPrivateKeyFormatStruct = (0, superstruct_1.object)({
31
+ /**
32
+ * Format used to encode the private key as a string.
33
+ */
34
+ encoding: exports.PrivateKeyEncodingStruct,
35
+ /**
36
+ * Type of the account to be created.
37
+ *
38
+ * This field is necessary when there is ambiguity about the type of account
39
+ * to be created from the private key. For example, in Bitcoin, a private key
40
+ * can be used to create multiple types of accounts, such as P2WPKH, or P2TR.
41
+ */
42
+ type: (0, superstruct_1.exactOptional)(account_1.KeyringAccountTypeStruct),
43
+ });
44
+ /**
45
+ * Struct for {@link ExportPrivateKeyFormat}.
46
+ */
47
+ exports.ExportPrivateKeyFormatStruct = (0, superstruct_1.object)({
48
+ /**
49
+ * Format used to encode the private key as a string.
50
+ */
51
+ encoding: exports.PrivateKeyEncodingStruct,
52
+ });
53
+ //# sourceMappingURL=private-key.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-key.cjs","sourceRoot":"","sources":["../../../src/api/v2/private-key.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAE/B,4CAAsD;AAEtD;;GAEG;AACH,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC5B;;OAEG;IACH,iDAA2B,CAAA;IAE3B;;OAEG;IACH,uCAAiB,CAAA;AACnB,CAAC,EAVW,kBAAkB,kCAAlB,kBAAkB,QAU7B;AAED;;GAEG;AACU,QAAA,wBAAwB,GAAG,IAAA,mBAAK,EAAC;IAC5C,GAAG,kBAAkB,CAAC,WAAW,EAAE;IACnC,GAAG,kBAAkB,CAAC,MAAM,EAAE;CAC/B,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,4BAA4B,GAAG,IAAA,oBAAM,EAAC;IACjD;;OAEG;IACH,QAAQ,EAAE,gCAAwB;IAElC;;;;;;OAMG;IACH,IAAI,EAAE,IAAA,2BAAa,EAAC,kCAAwB,CAAC;CAC9C,CAAC,CAAC;AAOH;;GAEG;AACU,QAAA,4BAA4B,GAAG,IAAA,oBAAM,EAAC;IACjD;;OAEG;IACH,QAAQ,EAAE,gCAAwB;CACnC,CAAC,CAAC","sourcesContent":["import {\n enums,\n exactOptional,\n object,\n type Infer,\n} from '@metamask/superstruct';\n\nimport { KeyringAccountTypeStruct } from '../account';\n\n/**\n * Supported encoding formats for private keys.\n */\nexport enum PrivateKeyEncoding {\n /**\n * Hexadecimal encoding format.\n */\n Hexadecimal = 'hexadecimal',\n\n /**\n * Base58 encoding format.\n */\n Base58 = 'base58',\n}\n\n/**\n * Struct for {@link PrivateKeyEncoding}.\n */\nexport const PrivateKeyEncodingStruct = enums([\n `${PrivateKeyEncoding.Hexadecimal}`,\n `${PrivateKeyEncoding.Base58}`,\n]);\n\n/**\n * Struct for {@link ImportPrivateKeyFormat}.\n */\nexport const ImportPrivateKeyFormatStruct = object({\n /**\n * Format used to encode the private key as a string.\n */\n encoding: PrivateKeyEncodingStruct,\n\n /**\n * Type of the account to be created.\n *\n * This field is necessary when there is ambiguity about the type of account\n * to be created from the private key. For example, in Bitcoin, a private key\n * can be used to create multiple types of accounts, such as P2WPKH, or P2TR.\n */\n type: exactOptional(KeyringAccountTypeStruct),\n});\n\n/**\n * Represents the format for importing a private key into a keyring.\n */\nexport type ImportPrivateKeyFormat = Infer<typeof ImportPrivateKeyFormatStruct>;\n\n/**\n * Struct for {@link ExportPrivateKeyFormat}.\n */\nexport const ExportPrivateKeyFormatStruct = object({\n /**\n * Format used to encode the private key as a string.\n */\n encoding: PrivateKeyEncodingStruct,\n});\n\n/**\n * Represents the format for exporting a private key from a keyring.\n */\nexport type ExportPrivateKeyFormat = Infer<typeof ExportPrivateKeyFormatStruct>;\n"]}
@@ -0,0 +1,77 @@
1
+ import { type Infer } from "@metamask/superstruct";
2
+ /**
3
+ * Supported encoding formats for private keys.
4
+ */
5
+ export declare enum PrivateKeyEncoding {
6
+ /**
7
+ * Hexadecimal encoding format.
8
+ */
9
+ Hexadecimal = "hexadecimal",
10
+ /**
11
+ * Base58 encoding format.
12
+ */
13
+ Base58 = "base58"
14
+ }
15
+ /**
16
+ * Struct for {@link PrivateKeyEncoding}.
17
+ */
18
+ export declare const PrivateKeyEncodingStruct: import("@metamask/superstruct").Struct<"hexadecimal" | "base58", {
19
+ hexadecimal: "hexadecimal";
20
+ base58: "base58";
21
+ }>;
22
+ /**
23
+ * Struct for {@link ImportPrivateKeyFormat}.
24
+ */
25
+ export declare const ImportPrivateKeyFormatStruct: import("@metamask/superstruct").Struct<{
26
+ encoding: "hexadecimal" | "base58";
27
+ type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
28
+ }, {
29
+ /**
30
+ * Format used to encode the private key as a string.
31
+ */
32
+ encoding: import("@metamask/superstruct").Struct<"hexadecimal" | "base58", {
33
+ hexadecimal: "hexadecimal";
34
+ base58: "base58";
35
+ }>;
36
+ /**
37
+ * Type of the account to be created.
38
+ *
39
+ * This field is necessary when there is ambiguity about the type of account
40
+ * to be created from the private key. For example, in Bitcoin, a private key
41
+ * can be used to create multiple types of accounts, such as P2WPKH, or P2TR.
42
+ */
43
+ type: import("@metamask/superstruct").ExactOptionalStruct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account", {
44
+ "eip155:eoa": "eip155:eoa";
45
+ "eip155:erc4337": "eip155:erc4337";
46
+ "bip122:p2pkh": "bip122:p2pkh";
47
+ "bip122:p2sh": "bip122:p2sh";
48
+ "bip122:p2wpkh": "bip122:p2wpkh";
49
+ "bip122:p2tr": "bip122:p2tr";
50
+ "solana:data-account": "solana:data-account";
51
+ "tron:eoa": "tron:eoa";
52
+ "any:account": "any:account";
53
+ }>;
54
+ }>;
55
+ /**
56
+ * Represents the format for importing a private key into a keyring.
57
+ */
58
+ export type ImportPrivateKeyFormat = Infer<typeof ImportPrivateKeyFormatStruct>;
59
+ /**
60
+ * Struct for {@link ExportPrivateKeyFormat}.
61
+ */
62
+ export declare const ExportPrivateKeyFormatStruct: import("@metamask/superstruct").Struct<{
63
+ encoding: "hexadecimal" | "base58";
64
+ }, {
65
+ /**
66
+ * Format used to encode the private key as a string.
67
+ */
68
+ encoding: import("@metamask/superstruct").Struct<"hexadecimal" | "base58", {
69
+ hexadecimal: "hexadecimal";
70
+ base58: "base58";
71
+ }>;
72
+ }>;
73
+ /**
74
+ * Represents the format for exporting a private key from a keyring.
75
+ */
76
+ export type ExportPrivateKeyFormat = Infer<typeof ExportPrivateKeyFormatStruct>;
77
+ //# sourceMappingURL=private-key.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-key.d.cts","sourceRoot":"","sources":["../../../src/api/v2/private-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,KAAK,EACX,8BAA8B;AAI/B;;GAEG;AACH,oBAAY,kBAAkB;IAC5B;;OAEG;IACH,WAAW,gBAAgB;IAE3B;;OAEG;IACH,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;EAGnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;IACvC;;OAEG;;;;;IAGH;;;;;;OAMG;;;;;;;;;;;;EAEH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;IACvC;;OAEG;;;;;EAEH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC"}
@@ -0,0 +1,77 @@
1
+ import { type Infer } from "@metamask/superstruct";
2
+ /**
3
+ * Supported encoding formats for private keys.
4
+ */
5
+ export declare enum PrivateKeyEncoding {
6
+ /**
7
+ * Hexadecimal encoding format.
8
+ */
9
+ Hexadecimal = "hexadecimal",
10
+ /**
11
+ * Base58 encoding format.
12
+ */
13
+ Base58 = "base58"
14
+ }
15
+ /**
16
+ * Struct for {@link PrivateKeyEncoding}.
17
+ */
18
+ export declare const PrivateKeyEncodingStruct: import("@metamask/superstruct").Struct<"hexadecimal" | "base58", {
19
+ hexadecimal: "hexadecimal";
20
+ base58: "base58";
21
+ }>;
22
+ /**
23
+ * Struct for {@link ImportPrivateKeyFormat}.
24
+ */
25
+ export declare const ImportPrivateKeyFormatStruct: import("@metamask/superstruct").Struct<{
26
+ encoding: "hexadecimal" | "base58";
27
+ type?: "eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account";
28
+ }, {
29
+ /**
30
+ * Format used to encode the private key as a string.
31
+ */
32
+ encoding: import("@metamask/superstruct").Struct<"hexadecimal" | "base58", {
33
+ hexadecimal: "hexadecimal";
34
+ base58: "base58";
35
+ }>;
36
+ /**
37
+ * Type of the account to be created.
38
+ *
39
+ * This field is necessary when there is ambiguity about the type of account
40
+ * to be created from the private key. For example, in Bitcoin, a private key
41
+ * can be used to create multiple types of accounts, such as P2WPKH, or P2TR.
42
+ */
43
+ type: import("@metamask/superstruct").ExactOptionalStruct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2pkh" | "bip122:p2sh" | "bip122:p2wpkh" | "bip122:p2tr" | "solana:data-account" | "tron:eoa" | "any:account", {
44
+ "eip155:eoa": "eip155:eoa";
45
+ "eip155:erc4337": "eip155:erc4337";
46
+ "bip122:p2pkh": "bip122:p2pkh";
47
+ "bip122:p2sh": "bip122:p2sh";
48
+ "bip122:p2wpkh": "bip122:p2wpkh";
49
+ "bip122:p2tr": "bip122:p2tr";
50
+ "solana:data-account": "solana:data-account";
51
+ "tron:eoa": "tron:eoa";
52
+ "any:account": "any:account";
53
+ }>;
54
+ }>;
55
+ /**
56
+ * Represents the format for importing a private key into a keyring.
57
+ */
58
+ export type ImportPrivateKeyFormat = Infer<typeof ImportPrivateKeyFormatStruct>;
59
+ /**
60
+ * Struct for {@link ExportPrivateKeyFormat}.
61
+ */
62
+ export declare const ExportPrivateKeyFormatStruct: import("@metamask/superstruct").Struct<{
63
+ encoding: "hexadecimal" | "base58";
64
+ }, {
65
+ /**
66
+ * Format used to encode the private key as a string.
67
+ */
68
+ encoding: import("@metamask/superstruct").Struct<"hexadecimal" | "base58", {
69
+ hexadecimal: "hexadecimal";
70
+ base58: "base58";
71
+ }>;
72
+ }>;
73
+ /**
74
+ * Represents the format for exporting a private key from a keyring.
75
+ */
76
+ export type ExportPrivateKeyFormat = Infer<typeof ExportPrivateKeyFormatStruct>;
77
+ //# sourceMappingURL=private-key.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-key.d.mts","sourceRoot":"","sources":["../../../src/api/v2/private-key.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,KAAK,EACX,8BAA8B;AAI/B;;GAEG;AACH,oBAAY,kBAAkB;IAC5B;;OAEG;IACH,WAAW,gBAAgB;IAE3B;;OAEG;IACH,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;EAGnC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;;IACvC;;OAEG;;;;;IAGH;;;;;;OAMG;;;;;;;;;;;;EAEH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC;AAEhF;;GAEG;AACH,eAAO,MAAM,4BAA4B;;;IACvC;;OAEG;;;;;EAEH,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAC"}
@@ -0,0 +1,50 @@
1
+ import { enums, exactOptional, object } from "@metamask/superstruct";
2
+ import { KeyringAccountTypeStruct } from "../account.mjs";
3
+ /**
4
+ * Supported encoding formats for private keys.
5
+ */
6
+ export var PrivateKeyEncoding;
7
+ (function (PrivateKeyEncoding) {
8
+ /**
9
+ * Hexadecimal encoding format.
10
+ */
11
+ PrivateKeyEncoding["Hexadecimal"] = "hexadecimal";
12
+ /**
13
+ * Base58 encoding format.
14
+ */
15
+ PrivateKeyEncoding["Base58"] = "base58";
16
+ })(PrivateKeyEncoding || (PrivateKeyEncoding = {}));
17
+ /**
18
+ * Struct for {@link PrivateKeyEncoding}.
19
+ */
20
+ export const PrivateKeyEncodingStruct = enums([
21
+ `${PrivateKeyEncoding.Hexadecimal}`,
22
+ `${PrivateKeyEncoding.Base58}`,
23
+ ]);
24
+ /**
25
+ * Struct for {@link ImportPrivateKeyFormat}.
26
+ */
27
+ export const ImportPrivateKeyFormatStruct = object({
28
+ /**
29
+ * Format used to encode the private key as a string.
30
+ */
31
+ encoding: PrivateKeyEncodingStruct,
32
+ /**
33
+ * Type of the account to be created.
34
+ *
35
+ * This field is necessary when there is ambiguity about the type of account
36
+ * to be created from the private key. For example, in Bitcoin, a private key
37
+ * can be used to create multiple types of accounts, such as P2WPKH, or P2TR.
38
+ */
39
+ type: exactOptional(KeyringAccountTypeStruct),
40
+ });
41
+ /**
42
+ * Struct for {@link ExportPrivateKeyFormat}.
43
+ */
44
+ export const ExportPrivateKeyFormatStruct = object({
45
+ /**
46
+ * Format used to encode the private key as a string.
47
+ */
48
+ encoding: PrivateKeyEncodingStruct,
49
+ });
50
+ //# sourceMappingURL=private-key.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-key.mjs","sourceRoot":"","sources":["../../../src/api/v2/private-key.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,aAAa,EACb,MAAM,EAEP,8BAA8B;AAE/B,OAAO,EAAE,wBAAwB,EAAE,uBAAmB;AAEtD;;GAEG;AACH,MAAM,CAAN,IAAY,kBAUX;AAVD,WAAY,kBAAkB;IAC5B;;OAEG;IACH,iDAA2B,CAAA;IAE3B;;OAEG;IACH,uCAAiB,CAAA;AACnB,CAAC,EAVW,kBAAkB,KAAlB,kBAAkB,QAU7B;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;IAC5C,GAAG,kBAAkB,CAAC,WAAW,EAAE;IACnC,GAAG,kBAAkB,CAAC,MAAM,EAAE;CAC/B,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;IACjD;;OAEG;IACH,QAAQ,EAAE,wBAAwB;IAElC;;;;;;OAMG;IACH,IAAI,EAAE,aAAa,CAAC,wBAAwB,CAAC;CAC9C,CAAC,CAAC;AAOH;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;IACjD;;OAEG;IACH,QAAQ,EAAE,wBAAwB;CACnC,CAAC,CAAC","sourcesContent":["import {\n enums,\n exactOptional,\n object,\n type Infer,\n} from '@metamask/superstruct';\n\nimport { KeyringAccountTypeStruct } from '../account';\n\n/**\n * Supported encoding formats for private keys.\n */\nexport enum PrivateKeyEncoding {\n /**\n * Hexadecimal encoding format.\n */\n Hexadecimal = 'hexadecimal',\n\n /**\n * Base58 encoding format.\n */\n Base58 = 'base58',\n}\n\n/**\n * Struct for {@link PrivateKeyEncoding}.\n */\nexport const PrivateKeyEncodingStruct = enums([\n `${PrivateKeyEncoding.Hexadecimal}`,\n `${PrivateKeyEncoding.Base58}`,\n]);\n\n/**\n * Struct for {@link ImportPrivateKeyFormat}.\n */\nexport const ImportPrivateKeyFormatStruct = object({\n /**\n * Format used to encode the private key as a string.\n */\n encoding: PrivateKeyEncodingStruct,\n\n /**\n * Type of the account to be created.\n *\n * This field is necessary when there is ambiguity about the type of account\n * to be created from the private key. For example, in Bitcoin, a private key\n * can be used to create multiple types of accounts, such as P2WPKH, or P2TR.\n */\n type: exactOptional(KeyringAccountTypeStruct),\n});\n\n/**\n * Represents the format for importing a private key into a keyring.\n */\nexport type ImportPrivateKeyFormat = Infer<typeof ImportPrivateKeyFormatStruct>;\n\n/**\n * Struct for {@link ExportPrivateKeyFormat}.\n */\nexport const ExportPrivateKeyFormatStruct = object({\n /**\n * Format used to encode the private key as a string.\n */\n encoding: PrivateKeyEncodingStruct,\n});\n\n/**\n * Represents the format for exporting a private key from a keyring.\n */\nexport type ExportPrivateKeyFormat = Infer<typeof ExportPrivateKeyFormatStruct>;\n"]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./keyring-wrapper.cjs"), exports);
18
+ __exportStar(require("./keyring-account-registry.cjs"), exports);
19
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAkC;AAClC,iEAA2C","sourcesContent":["export * from './keyring-wrapper';\nexport * from './keyring-account-registry';\n"]}
@@ -0,0 +1,3 @@
1
+ export * from "./keyring-wrapper.cjs";
2
+ export * from "./keyring-account-registry.cjs";
3
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C"}
@@ -0,0 +1,3 @@
1
+ export * from "./keyring-wrapper.mjs";
2
+ export * from "./keyring-account-registry.mjs";
3
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C"}
@@ -0,0 +1,3 @@
1
+ export * from "./keyring-wrapper.mjs";
2
+ export * from "./keyring-account-registry.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/index.ts"],"names":[],"mappings":"AAAA,sCAAkC;AAClC,+CAA2C","sourcesContent":["export * from './keyring-wrapper';\nexport * from './keyring-account-registry';\n"]}
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var _KeyringAccountRegistry_accountById, _KeyringAccountRegistry_idByAddress;
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.KeyringAccountRegistry = void 0;
10
+ const uuid_1 = require("uuid");
11
+ /**
12
+ * In-memory registry for KeyringAccount objects.
13
+ *
14
+ * Provides O(1) lookups by account ID or address, and stores the full
15
+ * KeyringAccount objects for efficient retrieval.
16
+ */
17
+ class KeyringAccountRegistry {
18
+ constructor() {
19
+ _KeyringAccountRegistry_accountById.set(this, new Map());
20
+ _KeyringAccountRegistry_idByAddress.set(this, new Map());
21
+ }
22
+ /**
23
+ * Get an account by its account ID.
24
+ *
25
+ * @param accountId - The account ID to look up.
26
+ * @returns The KeyringAccount, or undefined if not found.
27
+ */
28
+ get(accountId) {
29
+ return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").get(accountId);
30
+ }
31
+ /**
32
+ * Get an account's address by its account ID.
33
+ *
34
+ * @param accountId - The account ID to look up.
35
+ * @returns The address, or undefined if not found.
36
+ */
37
+ getAddress(accountId) {
38
+ return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").get(accountId)?.address;
39
+ }
40
+ /**
41
+ * Get an account ID by the underlying address.
42
+ *
43
+ * @param address - The address to look up.
44
+ * @returns The account ID, or undefined if not found.
45
+ */
46
+ getAccountId(address) {
47
+ return __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").get(address);
48
+ }
49
+ /**
50
+ * Register a new address and generate an account ID for it.
51
+ * If the address is already registered, returns the existing account ID.
52
+ *
53
+ * @param address - The address to register.
54
+ * @returns The account ID for this address.
55
+ */
56
+ register(address) {
57
+ const existing = __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").get(address);
58
+ if (existing) {
59
+ return existing;
60
+ }
61
+ const id = (0, uuid_1.v4)();
62
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").set(address, id);
63
+ return id;
64
+ }
65
+ /**
66
+ * Add an account to the registry.
67
+ * Also registers the address → account ID mapping.
68
+ *
69
+ * ⚠️ If an address was previously registered via `register()` with a
70
+ * different account ID, calling `set()` with an account that has a new ID for
71
+ * the same address will overwrite the address → ID mapping. The old ID
72
+ * becomes "dangling" (i.e., `get(oldId)` will return undefined).
73
+ *
74
+ * @param account - The KeyringAccount to cache.
75
+ */
76
+ set(account) {
77
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").set(account.id, account);
78
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").set(account.address, account.id);
79
+ }
80
+ /**
81
+ * Remove an account from the registry.
82
+ *
83
+ * @param accountId - The account ID to remove.
84
+ */
85
+ delete(accountId) {
86
+ const account = __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").get(accountId);
87
+ if (account) {
88
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").delete(account.address);
89
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").delete(accountId);
90
+ }
91
+ }
92
+ /**
93
+ * Clear all accounts from the registry.
94
+ */
95
+ clear() {
96
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").clear();
97
+ __classPrivateFieldGet(this, _KeyringAccountRegistry_idByAddress, "f").clear();
98
+ }
99
+ /**
100
+ * Get all cached accounts as an array.
101
+ *
102
+ * @returns Array of all KeyringAccountType objects in the registry.
103
+ */
104
+ values() {
105
+ return Array.from(__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").values());
106
+ }
107
+ /**
108
+ * Get all account IDs in the registry.
109
+ *
110
+ * @returns Array of all account IDs.
111
+ */
112
+ keys() {
113
+ return Array.from(__classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").keys());
114
+ }
115
+ /**
116
+ * Check if an account exists in the registry.
117
+ *
118
+ * @param accountId - The account ID to check.
119
+ * @returns True if the account exists.
120
+ */
121
+ has(accountId) {
122
+ return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").has(accountId);
123
+ }
124
+ /**
125
+ * Get the number of accounts in the registry.
126
+ *
127
+ * @returns The number of accounts.
128
+ */
129
+ get size() {
130
+ return __classPrivateFieldGet(this, _KeyringAccountRegistry_accountById, "f").size;
131
+ }
132
+ }
133
+ exports.KeyringAccountRegistry = KeyringAccountRegistry;
134
+ _KeyringAccountRegistry_accountById = new WeakMap(), _KeyringAccountRegistry_idByAddress = new WeakMap();
135
+ //# sourceMappingURL=keyring-account-registry.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-account-registry.cjs","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-account-registry.ts"],"names":[],"mappings":";;;;;;;;;AACA,+BAAoC;AAIpC;;;;;GAKG;AACH,MAAa,sBAAsB;IAAnC;QAGW,8CAAe,IAAI,GAAG,EAAiC,EAAC;QAExD,8CAAe,IAAI,GAAG,EAAqB,EAAC;IA0HvD,CAAC;IAxHC;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,SAAoB;QAC7B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,OAAe;QAC1B,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,OAAe;QACtB,MAAM,QAAQ,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,MAAM,EAAE,GAAG,IAAA,SAAM,GAAE,CAAC;QACpB,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACnC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAA2B;QAC7B,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3C,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;IACrD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,SAAoB;QACzB,MAAM,OAAO,GAAG,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACjD,IAAI,OAAO,EAAE,CAAC;YACZ,uBAAA,IAAI,2CAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC1C,uBAAA,IAAI,2CAAa,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;QAC1B,uBAAA,IAAI,2CAAa,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACJ,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;;;OAIG;IACH,IAAI;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,uBAAA,IAAI,2CAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,SAAoB;QACtB,OAAO,uBAAA,IAAI,2CAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,IAAI,IAAI;QACN,OAAO,uBAAA,IAAI,2CAAa,CAAC,IAAI,CAAC;IAChC,CAAC;CACF;AA/HD,wDA+HC","sourcesContent":["import type { AccountId } from '@metamask/keyring-utils';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport type { KeyringAccount } from '../../account';\n\n/**\n * In-memory registry for KeyringAccount objects.\n *\n * Provides O(1) lookups by account ID or address, and stores the full\n * KeyringAccount objects for efficient retrieval.\n */\nexport class KeyringAccountRegistry<\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> {\n readonly #accountById = new Map<AccountId, KeyringAccountType>();\n\n readonly #idByAddress = new Map<string, AccountId>();\n\n /**\n * Get an account by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The KeyringAccount, or undefined if not found.\n */\n get(accountId: AccountId): KeyringAccountType | undefined {\n return this.#accountById.get(accountId);\n }\n\n /**\n * Get an account's address by its account ID.\n *\n * @param accountId - The account ID to look up.\n * @returns The address, or undefined if not found.\n */\n getAddress(accountId: AccountId): string | undefined {\n return this.#accountById.get(accountId)?.address;\n }\n\n /**\n * Get an account ID by the underlying address.\n *\n * @param address - The address to look up.\n * @returns The account ID, or undefined if not found.\n */\n getAccountId(address: string): AccountId | undefined {\n return this.#idByAddress.get(address);\n }\n\n /**\n * Register a new address and generate an account ID for it.\n * If the address is already registered, returns the existing account ID.\n *\n * @param address - The address to register.\n * @returns The account ID for this address.\n */\n register(address: string): AccountId {\n const existing = this.#idByAddress.get(address);\n if (existing) {\n return existing;\n }\n const id = uuidv4();\n this.#idByAddress.set(address, id);\n return id;\n }\n\n /**\n * Add an account to the registry.\n * Also registers the address → account ID mapping.\n *\n * ⚠️ If an address was previously registered via `register()` with a\n * different account ID, calling `set()` with an account that has a new ID for\n * the same address will overwrite the address → ID mapping. The old ID\n * becomes \"dangling\" (i.e., `get(oldId)` will return undefined).\n *\n * @param account - The KeyringAccount to cache.\n */\n set(account: KeyringAccountType): void {\n this.#accountById.set(account.id, account);\n this.#idByAddress.set(account.address, account.id);\n }\n\n /**\n * Remove an account from the registry.\n *\n * @param accountId - The account ID to remove.\n */\n delete(accountId: AccountId): void {\n const account = this.#accountById.get(accountId);\n if (account) {\n this.#idByAddress.delete(account.address);\n this.#accountById.delete(accountId);\n }\n }\n\n /**\n * Clear all accounts from the registry.\n */\n clear(): void {\n this.#accountById.clear();\n this.#idByAddress.clear();\n }\n\n /**\n * Get all cached accounts as an array.\n *\n * @returns Array of all KeyringAccountType objects in the registry.\n */\n values(): KeyringAccountType[] {\n return Array.from(this.#accountById.values());\n }\n\n /**\n * Get all account IDs in the registry.\n *\n * @returns Array of all account IDs.\n */\n keys(): AccountId[] {\n return Array.from(this.#accountById.keys());\n }\n\n /**\n * Check if an account exists in the registry.\n *\n * @param accountId - The account ID to check.\n * @returns True if the account exists.\n */\n has(accountId: AccountId): boolean {\n return this.#accountById.has(accountId);\n }\n\n /**\n * Get the number of accounts in the registry.\n *\n * @returns The number of accounts.\n */\n get size(): number {\n return this.#accountById.size;\n }\n}\n"]}
@@ -0,0 +1,88 @@
1
+ import type { AccountId } from "@metamask/keyring-utils";
2
+ import type { KeyringAccount } from "../../account.cjs";
3
+ /**
4
+ * In-memory registry for KeyringAccount objects.
5
+ *
6
+ * Provides O(1) lookups by account ID or address, and stores the full
7
+ * KeyringAccount objects for efficient retrieval.
8
+ */
9
+ export declare class KeyringAccountRegistry<KeyringAccountType extends KeyringAccount = KeyringAccount> {
10
+ #private;
11
+ /**
12
+ * Get an account by its account ID.
13
+ *
14
+ * @param accountId - The account ID to look up.
15
+ * @returns The KeyringAccount, or undefined if not found.
16
+ */
17
+ get(accountId: AccountId): KeyringAccountType | undefined;
18
+ /**
19
+ * Get an account's address by its account ID.
20
+ *
21
+ * @param accountId - The account ID to look up.
22
+ * @returns The address, or undefined if not found.
23
+ */
24
+ getAddress(accountId: AccountId): string | undefined;
25
+ /**
26
+ * Get an account ID by the underlying address.
27
+ *
28
+ * @param address - The address to look up.
29
+ * @returns The account ID, or undefined if not found.
30
+ */
31
+ getAccountId(address: string): AccountId | undefined;
32
+ /**
33
+ * Register a new address and generate an account ID for it.
34
+ * If the address is already registered, returns the existing account ID.
35
+ *
36
+ * @param address - The address to register.
37
+ * @returns The account ID for this address.
38
+ */
39
+ register(address: string): AccountId;
40
+ /**
41
+ * Add an account to the registry.
42
+ * Also registers the address → account ID mapping.
43
+ *
44
+ * ⚠️ If an address was previously registered via `register()` with a
45
+ * different account ID, calling `set()` with an account that has a new ID for
46
+ * the same address will overwrite the address → ID mapping. The old ID
47
+ * becomes "dangling" (i.e., `get(oldId)` will return undefined).
48
+ *
49
+ * @param account - The KeyringAccount to cache.
50
+ */
51
+ set(account: KeyringAccountType): void;
52
+ /**
53
+ * Remove an account from the registry.
54
+ *
55
+ * @param accountId - The account ID to remove.
56
+ */
57
+ delete(accountId: AccountId): void;
58
+ /**
59
+ * Clear all accounts from the registry.
60
+ */
61
+ clear(): void;
62
+ /**
63
+ * Get all cached accounts as an array.
64
+ *
65
+ * @returns Array of all KeyringAccountType objects in the registry.
66
+ */
67
+ values(): KeyringAccountType[];
68
+ /**
69
+ * Get all account IDs in the registry.
70
+ *
71
+ * @returns Array of all account IDs.
72
+ */
73
+ keys(): AccountId[];
74
+ /**
75
+ * Check if an account exists in the registry.
76
+ *
77
+ * @param accountId - The account ID to check.
78
+ * @returns True if the account exists.
79
+ */
80
+ has(accountId: AccountId): boolean;
81
+ /**
82
+ * Get the number of accounts in the registry.
83
+ *
84
+ * @returns The number of accounts.
85
+ */
86
+ get size(): number;
87
+ }
88
+ //# sourceMappingURL=keyring-account-registry.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring-account-registry.d.cts","sourceRoot":"","sources":["../../../../src/api/v2/wrapper/keyring-account-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAAsB;AAEpD;;;;;GAKG;AACH,qBAAa,sBAAsB,CACjC,kBAAkB,SAAS,cAAc,GAAG,cAAc;;IAM1D;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,kBAAkB,GAAG,SAAS;IAIzD;;;;;OAKG;IACH,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS;IAIpD;;;;;OAKG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAIpD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;IAUpC;;;;;;;;;;OAUG;IACH,GAAG,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI;IAKtC;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAQlC;;OAEG;IACH,KAAK,IAAI,IAAI;IAKb;;;;OAIG;IACH,MAAM,IAAI,kBAAkB,EAAE;IAI9B;;;;OAIG;IACH,IAAI,IAAI,SAAS,EAAE;IAInB;;;;;OAKG;IACH,GAAG,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO;IAIlC;;;;OAIG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;CACF"}