@metamask-previews/keyring-api 11.1.0-5143ee2 → 11.1.0-dde1dbb

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 (265) hide show
  1. package/dist/JsonRpcRequest.cjs +13 -0
  2. package/dist/JsonRpcRequest.cjs.map +1 -0
  3. package/dist/JsonRpcRequest.d.cts +17 -0
  4. package/dist/JsonRpcRequest.d.cts.map +1 -0
  5. package/dist/JsonRpcRequest.d.mts +17 -0
  6. package/dist/JsonRpcRequest.d.mts.map +1 -0
  7. package/dist/JsonRpcRequest.mjs +10 -0
  8. package/dist/JsonRpcRequest.mjs.map +1 -0
  9. package/dist/KeyringClient.cjs +130 -0
  10. package/dist/KeyringClient.cjs.map +1 -0
  11. package/dist/KeyringClient.d.cts +31 -0
  12. package/dist/KeyringClient.d.cts.map +1 -0
  13. package/dist/KeyringClient.d.mts +31 -0
  14. package/dist/KeyringClient.d.mts.map +1 -0
  15. package/dist/KeyringClient.mjs +126 -0
  16. package/dist/KeyringClient.mjs.map +1 -0
  17. package/dist/KeyringSnapRpcClient.cjs +68 -0
  18. package/dist/KeyringSnapRpcClient.cjs.map +1 -0
  19. package/dist/KeyringSnapRpcClient.d.cts +40 -0
  20. package/dist/KeyringSnapRpcClient.d.cts.map +1 -0
  21. package/dist/KeyringSnapRpcClient.d.mts +40 -0
  22. package/dist/KeyringSnapRpcClient.d.mts.map +1 -0
  23. package/dist/KeyringSnapRpcClient.mjs +63 -0
  24. package/dist/KeyringSnapRpcClient.mjs.map +1 -0
  25. package/dist/api/account.cjs +4 -3
  26. package/dist/api/account.cjs.map +1 -1
  27. package/dist/api/account.d.cts +1 -1
  28. package/dist/api/account.d.cts.map +1 -1
  29. package/dist/api/account.d.mts +1 -1
  30. package/dist/api/account.d.mts.map +1 -1
  31. package/dist/api/account.mjs +2 -1
  32. package/dist/api/account.mjs.map +1 -1
  33. package/dist/api/asset.cjs +6 -5
  34. package/dist/api/asset.cjs.map +1 -1
  35. package/dist/api/asset.d.cts +2 -2
  36. package/dist/api/asset.d.cts.map +1 -1
  37. package/dist/api/asset.d.mts +2 -2
  38. package/dist/api/asset.d.mts.map +1 -1
  39. package/dist/api/asset.mjs +2 -1
  40. package/dist/api/asset.mjs.map +1 -1
  41. package/dist/api/balance.cjs +4 -3
  42. package/dist/api/balance.cjs.map +1 -1
  43. package/dist/api/balance.d.cts.map +1 -1
  44. package/dist/api/balance.d.mts.map +1 -1
  45. package/dist/api/balance.mjs +2 -1
  46. package/dist/api/balance.mjs.map +1 -1
  47. package/dist/api/caip.cjs +3 -3
  48. package/dist/api/caip.cjs.map +1 -1
  49. package/dist/api/caip.d.cts.map +1 -1
  50. package/dist/api/caip.d.mts.map +1 -1
  51. package/dist/api/caip.mjs +1 -1
  52. package/dist/api/caip.mjs.map +1 -1
  53. package/dist/api/index.cjs +0 -1
  54. package/dist/api/index.cjs.map +1 -1
  55. package/dist/api/index.d.cts +0 -1
  56. package/dist/api/index.d.cts.map +1 -1
  57. package/dist/api/index.d.mts +0 -1
  58. package/dist/api/index.d.mts.map +1 -1
  59. package/dist/api/index.mjs +0 -1
  60. package/dist/api/index.mjs.map +1 -1
  61. package/dist/api/keyring.cjs +0 -2
  62. package/dist/api/keyring.cjs.map +1 -1
  63. package/dist/api/keyring.d.cts +1 -1
  64. package/dist/api/keyring.d.cts.map +1 -1
  65. package/dist/api/keyring.d.mts +1 -1
  66. package/dist/api/keyring.d.mts.map +1 -1
  67. package/dist/api/keyring.mjs +0 -2
  68. package/dist/api/keyring.mjs.map +1 -1
  69. package/dist/api/request.cjs +7 -6
  70. package/dist/api/request.cjs.map +1 -1
  71. package/dist/api/request.d.cts +5 -5
  72. package/dist/api/request.d.cts.map +1 -1
  73. package/dist/api/request.d.mts +5 -5
  74. package/dist/api/request.d.mts.map +1 -1
  75. package/dist/api/request.mjs +2 -1
  76. package/dist/api/request.mjs.map +1 -1
  77. package/dist/api/response.cjs +6 -6
  78. package/dist/api/response.cjs.map +1 -1
  79. package/dist/api/response.d.cts +1 -1
  80. package/dist/api/response.d.cts.map +1 -1
  81. package/dist/api/response.d.mts +1 -1
  82. package/dist/api/response.d.mts.map +1 -1
  83. package/dist/api/response.mjs +1 -1
  84. package/dist/api/response.mjs.map +1 -1
  85. package/dist/api/transaction.cjs +8 -7
  86. package/dist/api/transaction.cjs.map +1 -1
  87. package/dist/api/transaction.d.cts +65 -65
  88. package/dist/api/transaction.d.cts.map +1 -1
  89. package/dist/api/transaction.d.mts +65 -65
  90. package/dist/api/transaction.d.mts.map +1 -1
  91. package/dist/api/transaction.mjs +2 -1
  92. package/dist/api/transaction.mjs.map +1 -1
  93. package/dist/btc/types.cjs +2 -2
  94. package/dist/btc/types.cjs.map +1 -1
  95. package/dist/btc/types.d.cts +1 -1
  96. package/dist/btc/types.d.cts.map +1 -1
  97. package/dist/btc/types.d.mts +1 -1
  98. package/dist/btc/types.d.mts.map +1 -1
  99. package/dist/btc/types.mjs +2 -2
  100. package/dist/btc/types.mjs.map +1 -1
  101. package/dist/eth/erc4337/types.cjs +11 -10
  102. package/dist/eth/erc4337/types.cjs.map +1 -1
  103. package/dist/eth/erc4337/types.d.cts +5 -5
  104. package/dist/eth/erc4337/types.d.cts.map +1 -1
  105. package/dist/eth/erc4337/types.d.mts +5 -5
  106. package/dist/eth/erc4337/types.d.mts.map +1 -1
  107. package/dist/eth/erc4337/types.mjs +2 -1
  108. package/dist/eth/erc4337/types.mjs.map +1 -1
  109. package/dist/eth/types.cjs +6 -6
  110. package/dist/eth/types.cjs.map +1 -1
  111. package/dist/eth/types.d.cts +2 -2
  112. package/dist/eth/types.d.cts.map +1 -1
  113. package/dist/eth/types.d.mts +2 -2
  114. package/dist/eth/types.d.mts.map +1 -1
  115. package/dist/eth/types.mjs +1 -1
  116. package/dist/eth/types.mjs.map +1 -1
  117. package/dist/eth/utils.cjs.map +1 -1
  118. package/dist/eth/utils.d.cts.map +1 -1
  119. package/dist/eth/utils.d.mts.map +1 -1
  120. package/dist/eth/utils.mjs.map +1 -1
  121. package/dist/events.cjs +1 -67
  122. package/dist/events.cjs.map +1 -1
  123. package/dist/events.d.cts +0 -161
  124. package/dist/events.d.cts.map +1 -1
  125. package/dist/events.d.mts +0 -161
  126. package/dist/events.d.mts.map +1 -1
  127. package/dist/events.mjs +0 -66
  128. package/dist/events.mjs.map +1 -1
  129. package/dist/index.cjs +8 -2
  130. package/dist/index.cjs.map +1 -1
  131. package/dist/index.d.cts +9 -3
  132. package/dist/index.d.cts.map +1 -1
  133. package/dist/index.d.mts +9 -3
  134. package/dist/index.d.mts.map +1 -1
  135. package/dist/index.mjs +8 -2
  136. package/dist/index.mjs.map +1 -1
  137. package/dist/{rpc.cjs → internal/api.cjs} +42 -71
  138. package/dist/internal/api.cjs.map +1 -0
  139. package/dist/{rpc.d.cts → internal/api.d.cts} +104 -130
  140. package/dist/internal/api.d.cts.map +1 -0
  141. package/dist/{rpc.d.mts → internal/api.d.mts} +104 -130
  142. package/dist/internal/api.d.mts.map +1 -0
  143. package/dist/{rpc.mjs → internal/api.mjs} +5 -33
  144. package/dist/internal/api.mjs.map +1 -0
  145. package/dist/internal/eth/EthKeyring.cjs +3 -0
  146. package/dist/internal/eth/EthKeyring.cjs.map +1 -0
  147. package/dist/internal/eth/EthKeyring.d.cts +34 -0
  148. package/dist/internal/eth/EthKeyring.d.cts.map +1 -0
  149. package/dist/internal/eth/EthKeyring.d.mts +34 -0
  150. package/dist/internal/eth/EthKeyring.d.mts.map +1 -0
  151. package/dist/internal/eth/EthKeyring.mjs +2 -0
  152. package/dist/internal/eth/EthKeyring.mjs.map +1 -0
  153. package/dist/internal/eth/index.cjs +3 -0
  154. package/dist/internal/eth/index.cjs.map +1 -0
  155. package/dist/internal/eth/index.d.cts +2 -0
  156. package/dist/internal/eth/index.d.cts.map +1 -0
  157. package/dist/internal/eth/index.d.mts +2 -0
  158. package/dist/internal/eth/index.d.mts.map +1 -0
  159. package/dist/internal/eth/index.mjs +2 -0
  160. package/dist/internal/eth/index.mjs.map +1 -0
  161. package/dist/internal/events.cjs +72 -0
  162. package/dist/internal/events.cjs.map +1 -0
  163. package/dist/internal/events.d.cts +162 -0
  164. package/dist/internal/events.d.cts.map +1 -0
  165. package/dist/internal/events.d.mts +162 -0
  166. package/dist/internal/events.d.mts.map +1 -0
  167. package/dist/internal/events.mjs +69 -0
  168. package/dist/internal/events.mjs.map +1 -0
  169. package/dist/internal/index.cjs +21 -0
  170. package/dist/internal/index.cjs.map +1 -0
  171. package/dist/internal/index.d.cts +6 -0
  172. package/dist/internal/index.d.cts.map +1 -0
  173. package/dist/internal/index.d.mts +6 -0
  174. package/dist/internal/index.d.mts.map +1 -0
  175. package/dist/internal/index.mjs +5 -0
  176. package/dist/internal/index.mjs.map +1 -0
  177. package/dist/internal/rpc.cjs +34 -0
  178. package/dist/internal/rpc.cjs.map +1 -0
  179. package/dist/internal/rpc.d.cts +27 -0
  180. package/dist/internal/rpc.d.cts.map +1 -0
  181. package/dist/internal/rpc.d.mts +27 -0
  182. package/dist/internal/rpc.d.mts.map +1 -0
  183. package/dist/internal/rpc.mjs +30 -0
  184. package/dist/internal/rpc.mjs.map +1 -0
  185. package/dist/internal/types.cjs +52 -0
  186. package/dist/internal/types.cjs.map +1 -0
  187. package/dist/internal/types.d.cts +392 -0
  188. package/dist/internal/types.d.cts.map +1 -0
  189. package/dist/internal/types.d.mts +392 -0
  190. package/dist/internal/types.d.mts.map +1 -0
  191. package/dist/internal/types.mjs +49 -0
  192. package/dist/internal/types.mjs.map +1 -0
  193. package/dist/rpc-handler.cjs +143 -0
  194. package/dist/rpc-handler.cjs.map +1 -0
  195. package/dist/rpc-handler.d.cts +30 -0
  196. package/dist/rpc-handler.d.cts.map +1 -0
  197. package/dist/rpc-handler.d.mts +30 -0
  198. package/dist/rpc-handler.d.mts.map +1 -0
  199. package/dist/rpc-handler.mjs +138 -0
  200. package/dist/rpc-handler.mjs.map +1 -0
  201. package/dist/snap-utils.cjs +20 -0
  202. package/dist/snap-utils.cjs.map +1 -0
  203. package/dist/snap-utils.d.cts +12 -0
  204. package/dist/snap-utils.d.cts.map +1 -0
  205. package/dist/snap-utils.d.mts +12 -0
  206. package/dist/snap-utils.d.mts.map +1 -0
  207. package/dist/snap-utils.mjs +17 -0
  208. package/dist/snap-utils.mjs.map +1 -0
  209. package/dist/sol/types.cjs +3 -3
  210. package/dist/sol/types.cjs.map +1 -1
  211. package/dist/sol/types.d.cts +1 -1
  212. package/dist/sol/types.d.cts.map +1 -1
  213. package/dist/sol/types.d.mts +1 -1
  214. package/dist/sol/types.d.mts.map +1 -1
  215. package/dist/sol/types.mjs +1 -1
  216. package/dist/sol/types.mjs.map +1 -1
  217. package/dist/superstruct.cjs +109 -0
  218. package/dist/superstruct.cjs.map +1 -0
  219. package/dist/superstruct.d.cts +102 -0
  220. package/dist/superstruct.d.cts.map +1 -0
  221. package/dist/superstruct.d.mts +102 -0
  222. package/dist/superstruct.d.mts.map +1 -0
  223. package/dist/superstruct.mjs +102 -0
  224. package/dist/superstruct.mjs.map +1 -0
  225. package/dist/utils/index.cjs +20 -0
  226. package/dist/utils/index.cjs.map +1 -0
  227. package/dist/utils/index.d.cts +4 -0
  228. package/dist/utils/index.d.cts.map +1 -0
  229. package/dist/utils/index.d.mts +4 -0
  230. package/dist/utils/index.d.mts.map +1 -0
  231. package/dist/utils/index.mjs +4 -0
  232. package/dist/utils/index.mjs.map +1 -0
  233. package/dist/{api → utils}/pagination.cjs +3 -3
  234. package/dist/utils/pagination.cjs.map +1 -0
  235. package/dist/{api → utils}/pagination.d.cts +1 -1
  236. package/dist/utils/pagination.d.cts.map +1 -0
  237. package/dist/{api → utils}/pagination.d.mts +1 -1
  238. package/dist/utils/pagination.d.mts.map +1 -0
  239. package/dist/{api → utils}/pagination.mjs +1 -1
  240. package/dist/utils/pagination.mjs.map +1 -0
  241. package/dist/utils/types.cjs +29 -0
  242. package/dist/utils/types.cjs.map +1 -0
  243. package/dist/utils/types.d.cts +42 -0
  244. package/dist/utils/types.d.cts.map +1 -0
  245. package/dist/utils/types.d.mts +42 -0
  246. package/dist/utils/types.d.mts.map +1 -0
  247. package/dist/utils/types.mjs +26 -0
  248. package/dist/utils/types.mjs.map +1 -0
  249. package/dist/utils/typing.cjs +20 -0
  250. package/dist/utils/typing.cjs.map +1 -0
  251. package/dist/utils/typing.d.cts +33 -0
  252. package/dist/utils/typing.d.cts.map +1 -0
  253. package/dist/utils/typing.d.mts +33 -0
  254. package/dist/utils/typing.d.mts.map +1 -0
  255. package/dist/utils/typing.mjs +17 -0
  256. package/dist/utils/typing.mjs.map +1 -0
  257. package/package.json +12 -9
  258. package/dist/api/pagination.cjs.map +0 -1
  259. package/dist/api/pagination.d.cts.map +0 -1
  260. package/dist/api/pagination.d.mts.map +0 -1
  261. package/dist/api/pagination.mjs.map +0 -1
  262. package/dist/rpc.cjs.map +0 -1
  263. package/dist/rpc.d.cts.map +0 -1
  264. package/dist/rpc.d.mts.map +0 -1
  265. package/dist/rpc.mjs.map +0 -1
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonRpcRequestStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const utils_1 = require("@metamask/utils");
6
+ const superstruct_2 = require("./superstruct.cjs");
7
+ exports.JsonRpcRequestStruct = (0, superstruct_2.object)({
8
+ jsonrpc: (0, superstruct_1.literal)('2.0'),
9
+ id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
10
+ method: (0, superstruct_1.string)(),
11
+ params: (0, superstruct_2.exactOptional)((0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)])),
12
+ });
13
+ //# sourceMappingURL=JsonRpcRequest.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.cjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,uDAO+B;AAE/B,2CAA6C;AAE7C,mDAAsD;AAEzC,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,2BAAa,EACnB,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CACzD;CACF,CAAC,CAAC","sourcesContent":["import {\n array,\n literal,\n number,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { exactOptional, object } from './superstruct';\n\nexport const JsonRpcRequestStruct = object({\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n});\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
@@ -0,0 +1,17 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struct<{
3
+ jsonrpc: "2.0";
4
+ id: string | number | null;
5
+ method: string;
6
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
7
+ }, {
8
+ jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
9
+ id: import("@metamask/superstruct").Struct<string | number | null, null>;
10
+ method: import("@metamask/superstruct").Struct<string, null>;
11
+ params: import("@metamask/superstruct").Struct<import("./superstruct.cjs").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
12
+ }>;
13
+ /**
14
+ * JSON-RPC request type.
15
+ */
16
+ export type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;
17
+ //# sourceMappingURL=JsonRpcRequest.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.d.cts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ export declare const JsonRpcRequestStruct: import("@metamask/superstruct").Struct<{
3
+ jsonrpc: "2.0";
4
+ id: string | number | null;
5
+ method: string;
6
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
7
+ }, {
8
+ jsonrpc: import("@metamask/superstruct").Struct<"2.0", "2.0">;
9
+ id: import("@metamask/superstruct").Struct<string | number | null, null>;
10
+ method: import("@metamask/superstruct").Struct<string, null>;
11
+ params: import("@metamask/superstruct").Struct<import("./superstruct.mjs").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
12
+ }>;
13
+ /**
14
+ * JSON-RPC request type.
15
+ */
16
+ export type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;
17
+ //# sourceMappingURL=JsonRpcRequest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.d.mts","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAKnD,eAAO,MAAM,oBAAoB;;;;;;;;;;EAO/B,CAAC;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { array, literal, number, record, string, union } from "@metamask/superstruct";
2
+ import { JsonStruct } from "@metamask/utils";
3
+ import { exactOptional, object } from "./superstruct.mjs";
4
+ export const JsonRpcRequestStruct = object({
5
+ jsonrpc: literal('2.0'),
6
+ id: union([string(), number(), literal(null)]),
7
+ method: string(),
8
+ params: exactOptional(union([array(JsonStruct), record(string(), JsonStruct)])),
9
+ });
10
+ //# sourceMappingURL=JsonRpcRequest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonRpcRequest.mjs","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,KAAK,EACN,8BAA8B;AAE/B,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,0BAAsB;AAEtD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;IACzC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC;IACvB,EAAE,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,MAAM,EAAE,MAAM,EAAE;IAChB,MAAM,EAAE,aAAa,CACnB,KAAK,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,CACzD;CACF,CAAC,CAAC","sourcesContent":["import {\n array,\n literal,\n number,\n record,\n string,\n union,\n} from '@metamask/superstruct';\nimport type { Infer } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { exactOptional, object } from './superstruct';\n\nexport const JsonRpcRequestStruct = object({\n jsonrpc: literal('2.0'),\n id: union([string(), number(), literal(null)]),\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n});\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _KeyringClient_instances, _KeyringClient_sender, _KeyringClient_send;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.KeyringClient = void 0;
16
+ const superstruct_1 = require("@metamask/superstruct");
17
+ const uuid_1 = require("uuid");
18
+ const api_1 = require("./internal/api.cjs");
19
+ const rpc_1 = require("./internal/rpc.cjs");
20
+ const superstruct_2 = require("./superstruct.cjs");
21
+ class KeyringClient {
22
+ /**
23
+ * Create a new instance of `KeyringClient`.
24
+ *
25
+ * @param sender - The `Sender` instance to use to send requests to the snap.
26
+ */
27
+ constructor(sender) {
28
+ _KeyringClient_instances.add(this);
29
+ _KeyringClient_sender.set(this, void 0);
30
+ __classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
31
+ }
32
+ async listAccounts() {
33
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
34
+ method: rpc_1.KeyringRpcMethod.ListAccounts,
35
+ }), api_1.ListAccountsResponseStruct);
36
+ }
37
+ async getAccount(id) {
38
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
39
+ method: rpc_1.KeyringRpcMethod.GetAccount,
40
+ params: { id },
41
+ }), api_1.GetAccountResponseStruct);
42
+ }
43
+ async getAccountBalances(id, assets) {
44
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
45
+ method: rpc_1.KeyringRpcMethod.GetAccountBalances,
46
+ params: { id, assets },
47
+ }), api_1.GetAccountBalancesResponseStruct);
48
+ }
49
+ async createAccount(options = {}) {
50
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
51
+ method: rpc_1.KeyringRpcMethod.CreateAccount,
52
+ params: { options },
53
+ }), api_1.CreateAccountResponseStruct);
54
+ }
55
+ async listAccountTransactions(id, pagination) {
56
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
57
+ method: rpc_1.KeyringRpcMethod.ListAccountTransactions,
58
+ params: { id, pagination },
59
+ }), api_1.ListAccountTransactionsResponseStruct);
60
+ }
61
+ async filterAccountChains(id, chains) {
62
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
63
+ method: rpc_1.KeyringRpcMethod.FilterAccountChains,
64
+ params: { id, chains },
65
+ }), api_1.FilterAccountChainsResponseStruct);
66
+ }
67
+ async updateAccount(account) {
68
+ (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
69
+ method: rpc_1.KeyringRpcMethod.UpdateAccount,
70
+ params: { account },
71
+ }), api_1.UpdateAccountResponseStruct);
72
+ }
73
+ async deleteAccount(id) {
74
+ (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
75
+ method: rpc_1.KeyringRpcMethod.DeleteAccount,
76
+ params: { id },
77
+ }), api_1.DeleteAccountResponseStruct);
78
+ }
79
+ async exportAccount(id) {
80
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
81
+ method: rpc_1.KeyringRpcMethod.ExportAccount,
82
+ params: { id },
83
+ }), api_1.ExportAccountResponseStruct);
84
+ }
85
+ async listRequests() {
86
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
87
+ method: rpc_1.KeyringRpcMethod.ListRequests,
88
+ }), api_1.ListRequestsResponseStruct);
89
+ }
90
+ async getRequest(id) {
91
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
92
+ method: rpc_1.KeyringRpcMethod.GetRequest,
93
+ params: { id },
94
+ }), api_1.GetRequestResponseStruct);
95
+ }
96
+ async submitRequest(request) {
97
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
98
+ method: rpc_1.KeyringRpcMethod.SubmitRequest,
99
+ params: request,
100
+ }), api_1.SubmitRequestResponseStruct);
101
+ }
102
+ async approveRequest(id, data = {}) {
103
+ (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
104
+ method: rpc_1.KeyringRpcMethod.ApproveRequest,
105
+ params: { id, data },
106
+ }), api_1.ApproveRequestResponseStruct);
107
+ }
108
+ async rejectRequest(id) {
109
+ (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
110
+ method: rpc_1.KeyringRpcMethod.RejectRequest,
111
+ params: { id },
112
+ }), api_1.RejectRequestResponseStruct);
113
+ }
114
+ }
115
+ exports.KeyringClient = KeyringClient;
116
+ _KeyringClient_sender = new WeakMap(), _KeyringClient_instances = new WeakSet(), _KeyringClient_send =
117
+ /**
118
+ * Send a request to the snap and return the response.
119
+ *
120
+ * @param partial - A partial JSON-RPC request (method and params).
121
+ * @returns A promise that resolves to the response to the request.
122
+ */
123
+ async function _KeyringClient_send(partial) {
124
+ return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
125
+ jsonrpc: '2.0',
126
+ id: (0, uuid_1.v4)(),
127
+ ...partial,
128
+ });
129
+ };
130
+ //# sourceMappingURL=KeyringClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.cjs","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA+C;AAE/C,+BAAkC;AAYlC,4CAewB;AACxB,4CAAkD;AAElD,mDAA2C;AAO3C,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAgBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,YAAY;SACtC,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,UAAU;YACnC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,kBAAkB,CACtB,EAAU,EACV,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AAgB,CAAC,cAAc;YACvC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE;SACrB,CAAC,EACF,kCAA4B,CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AA9KD,sCA8KC;;AAlKC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,IAAA,SAAI,GAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n TransactionsPage,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListAccountTransactionsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { strictMask } from './superstruct';\nimport type { Pagination } from './utils';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async listAccountTransactions(\n id: string,\n pagination: Pagination,\n ): Promise<TransactionsPage> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccountTransactions,\n params: { id, pagination },\n }),\n ListAccountTransactionsResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import type { Json } from "@metamask/utils";
2
+ import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance, TransactionsPage } from "./api/index.cjs";
3
+ import type { JsonRpcRequest } from "./JsonRpcRequest.cjs";
4
+ import type { Pagination } from "./utils/index.cjs";
5
+ export type Sender = {
6
+ send(request: JsonRpcRequest): Promise<Json>;
7
+ };
8
+ export declare class KeyringClient implements Keyring {
9
+ #private;
10
+ /**
11
+ * Create a new instance of `KeyringClient`.
12
+ *
13
+ * @param sender - The `Sender` instance to use to send requests to the snap.
14
+ */
15
+ constructor(sender: Sender);
16
+ listAccounts(): Promise<KeyringAccount[]>;
17
+ getAccount(id: string): Promise<KeyringAccount>;
18
+ getAccountBalances(id: string, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
19
+ createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
20
+ listAccountTransactions(id: string, pagination: Pagination): Promise<TransactionsPage>;
21
+ filterAccountChains(id: string, chains: string[]): Promise<string[]>;
22
+ updateAccount(account: KeyringAccount): Promise<void>;
23
+ deleteAccount(id: string): Promise<void>;
24
+ exportAccount(id: string): Promise<KeyringAccountData>;
25
+ listRequests(): Promise<KeyringRequest[]>;
26
+ getRequest(id: string): Promise<KeyringRequest>;
27
+ submitRequest(request: KeyringRequest): Promise<KeyringResponse>;
28
+ approveRequest(id: string, data?: Record<string, Json>): Promise<void>;
29
+ rejectRequest(id: string): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=KeyringClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.d.cts","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACP,gBAAgB,EACjB,wBAAc;AAkBf,OAAO,KAAK,EAAE,cAAc,EAAE,6BAAyB;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,0BAAgB;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,qBAAa,aAAc,YAAW,OAAO;;IAG3C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAkBpB,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,aAAa,EAAE,GACtB,OAAO,CAAC,MAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAUpC,aAAa,CACjB,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GACjC,OAAO,CAAC,cAAc,CAAC;IAUpB,uBAAuB,CAC3B,EAAE,EAAE,MAAM,EACV,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,gBAAgB,CAAC;IAUtB,mBAAmB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAUpE,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAUtD,YAAY,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IASzC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAU/C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAUhE,cAAc,CAClB,EAAE,EAAE,MAAM,EACV,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAM,GAC9B,OAAO,CAAC,IAAI,CAAC;IAUV,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS/C"}
@@ -0,0 +1,31 @@
1
+ import type { Json } from "@metamask/utils";
2
+ import type { Keyring, KeyringAccount, KeyringRequest, KeyringAccountData, KeyringResponse, CaipAssetType, Balance, TransactionsPage } from "./api/index.mjs";
3
+ import type { JsonRpcRequest } from "./JsonRpcRequest.mjs";
4
+ import type { Pagination } from "./utils/index.mjs";
5
+ export type Sender = {
6
+ send(request: JsonRpcRequest): Promise<Json>;
7
+ };
8
+ export declare class KeyringClient implements Keyring {
9
+ #private;
10
+ /**
11
+ * Create a new instance of `KeyringClient`.
12
+ *
13
+ * @param sender - The `Sender` instance to use to send requests to the snap.
14
+ */
15
+ constructor(sender: Sender);
16
+ listAccounts(): Promise<KeyringAccount[]>;
17
+ getAccount(id: string): Promise<KeyringAccount>;
18
+ getAccountBalances(id: string, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
19
+ createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
20
+ listAccountTransactions(id: string, pagination: Pagination): Promise<TransactionsPage>;
21
+ filterAccountChains(id: string, chains: string[]): Promise<string[]>;
22
+ updateAccount(account: KeyringAccount): Promise<void>;
23
+ deleteAccount(id: string): Promise<void>;
24
+ exportAccount(id: string): Promise<KeyringAccountData>;
25
+ listRequests(): Promise<KeyringRequest[]>;
26
+ getRequest(id: string): Promise<KeyringRequest>;
27
+ submitRequest(request: KeyringRequest): Promise<KeyringResponse>;
28
+ approveRequest(id: string, data?: Record<string, Json>): Promise<void>;
29
+ rejectRequest(id: string): Promise<void>;
30
+ }
31
+ //# sourceMappingURL=KeyringClient.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringClient.d.mts","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,OAAO,EACP,gBAAgB,EACjB,wBAAc;AAkBf,OAAO,KAAK,EAAE,cAAc,EAAE,6BAAyB;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,0BAAgB;AAE1C,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C,CAAC;AAEF,qBAAa,aAA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__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _KeyringClient_instances, _KeyringClient_sender, _KeyringClient_send;
13
+ import { assert } from "@metamask/superstruct";
14
+ import { v4 as uuid } from "uuid";
15
+ import { ApproveRequestResponseStruct, CreateAccountResponseStruct, DeleteAccountResponseStruct, ExportAccountResponseStruct, FilterAccountChainsResponseStruct, GetAccountBalancesResponseStruct, GetAccountResponseStruct, GetRequestResponseStruct, ListAccountsResponseStruct, ListAccountTransactionsResponseStruct, ListRequestsResponseStruct, RejectRequestResponseStruct, SubmitRequestResponseStruct, UpdateAccountResponseStruct } from "./internal/api.mjs";
16
+ import { KeyringRpcMethod } from "./internal/rpc.mjs";
17
+ import { strictMask } from "./superstruct.mjs";
18
+ export class KeyringClient {
19
+ /**
20
+ * Create a new instance of `KeyringClient`.
21
+ *
22
+ * @param sender - The `Sender` instance to use to send requests to the snap.
23
+ */
24
+ constructor(sender) {
25
+ _KeyringClient_instances.add(this);
26
+ _KeyringClient_sender.set(this, void 0);
27
+ __classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
28
+ }
29
+ async listAccounts() {
30
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
31
+ method: KeyringRpcMethod.ListAccounts,
32
+ }), ListAccountsResponseStruct);
33
+ }
34
+ async getAccount(id) {
35
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
36
+ method: KeyringRpcMethod.GetAccount,
37
+ params: { id },
38
+ }), GetAccountResponseStruct);
39
+ }
40
+ async getAccountBalances(id, assets) {
41
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
42
+ method: KeyringRpcMethod.GetAccountBalances,
43
+ params: { id, assets },
44
+ }), GetAccountBalancesResponseStruct);
45
+ }
46
+ async createAccount(options = {}) {
47
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
48
+ method: KeyringRpcMethod.CreateAccount,
49
+ params: { options },
50
+ }), CreateAccountResponseStruct);
51
+ }
52
+ async listAccountTransactions(id, pagination) {
53
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
54
+ method: KeyringRpcMethod.ListAccountTransactions,
55
+ params: { id, pagination },
56
+ }), ListAccountTransactionsResponseStruct);
57
+ }
58
+ async filterAccountChains(id, chains) {
59
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
60
+ method: KeyringRpcMethod.FilterAccountChains,
61
+ params: { id, chains },
62
+ }), FilterAccountChainsResponseStruct);
63
+ }
64
+ async updateAccount(account) {
65
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
66
+ method: KeyringRpcMethod.UpdateAccount,
67
+ params: { account },
68
+ }), UpdateAccountResponseStruct);
69
+ }
70
+ async deleteAccount(id) {
71
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
72
+ method: KeyringRpcMethod.DeleteAccount,
73
+ params: { id },
74
+ }), DeleteAccountResponseStruct);
75
+ }
76
+ async exportAccount(id) {
77
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
78
+ method: KeyringRpcMethod.ExportAccount,
79
+ params: { id },
80
+ }), ExportAccountResponseStruct);
81
+ }
82
+ async listRequests() {
83
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
84
+ method: KeyringRpcMethod.ListRequests,
85
+ }), ListRequestsResponseStruct);
86
+ }
87
+ async getRequest(id) {
88
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
89
+ method: KeyringRpcMethod.GetRequest,
90
+ params: { id },
91
+ }), GetRequestResponseStruct);
92
+ }
93
+ async submitRequest(request) {
94
+ return strictMask(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
95
+ method: KeyringRpcMethod.SubmitRequest,
96
+ params: request,
97
+ }), SubmitRequestResponseStruct);
98
+ }
99
+ async approveRequest(id, data = {}) {
100
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
101
+ method: KeyringRpcMethod.ApproveRequest,
102
+ params: { id, data },
103
+ }), ApproveRequestResponseStruct);
104
+ }
105
+ async rejectRequest(id) {
106
+ assert(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
107
+ method: KeyringRpcMethod.RejectRequest,
108
+ params: { id },
109
+ }), RejectRequestResponseStruct);
110
+ }
111
+ }
112
+ _KeyringClient_sender = new WeakMap(), _KeyringClient_instances = new WeakSet(), _KeyringClient_send =
113
+ /**
114
+ * Send a request to the snap and return the response.
115
+ *
116
+ * @param partial - A partial JSON-RPC request (method and params).
117
+ * @returns A promise that resolves to the response to the request.
118
+ */
119
+ async function _KeyringClient_send(partial) {
120
+ return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
121
+ jsonrpc: '2.0',
122
+ id: uuid(),
123
+ ...partial,
124
+ });
125
+ };
126
+ //# sourceM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MAAV,IAAI,EAAO;YACf,MAAM,EAAE,gBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;;AAlKC;;;;;GAKG;AACH,KAAK,8BAAO,OAA+C;IACzD,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;QACvB,OAAO,EAAE,KAAK;QACd,EAAE,EAAE,IAAI,EAAE;QACV,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n CaipAssetType,\n Balance,\n TransactionsPage,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountBalancesResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\n ListAccountTransactionsResponseStruct,\n ListRequestsResponseStruct,\n RejectRequestResponseStruct,\n SubmitRequestResponseStruct,\n UpdateAccountResponseStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { strictMask } from './superstruct';\nimport type { Pagination } from './utils';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param partial - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n async #send(partial: Omit<JsonRpcRequest, 'jsonrpc' | 'id'>): Promise<Json> {\n return this.#sender.send({\n jsonrpc: '2.0',\n id: uuid(),\n ...partial,\n });\n }\n\n async listAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccounts,\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async getAccountBalances(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetAccountBalances,\n params: { id, assets },\n }),\n GetAccountBalancesResponseStruct,\n );\n }\n\n async createAccount(\n options: Record<string, Json> = {},\n ): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.CreateAccount,\n params: { options },\n }),\n CreateAccountResponseStruct,\n );\n }\n\n async listAccountTransactions(\n id: string,\n pagination: Pagination,\n ): Promise<TransactionsPage> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListAccountTransactions,\n params: { id, pagination },\n }),\n ListAccountTransactionsResponseStruct,\n );\n }\n\n async filterAccountChains(id: string, chains: string[]): Promise<string[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.FilterAccountChains,\n params: { id, chains },\n }),\n FilterAccountChainsResponseStruct,\n );\n }\n\n async updateAccount(account: KeyringAccount): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.UpdateAccount,\n params: { account },\n }),\n UpdateAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async exportAccount(id: string): Promise<KeyringAccountData> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ExportAccount,\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.ListRequests,\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.GetRequest,\n params: { id },\n }),\n GetRequestResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<KeyringResponse> {\n return strictMask(\n await this.#send({\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n\n async approveRequest(\n id: string,\n data: Record<string, Json> = {},\n ): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.ApproveRequest,\n params: { id, data },\n }),\n ApproveRequestResponseStruct,\n );\n }\n\n async rejectRequest(id: string): Promise<void> {\n assert(\n await this.#send({\n method: KeyringRpcMethod.RejectRequest,\n params: { id },\n }),\n RejectRequestResponseStruct,\n );\n }\n}\n"]}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _SnapRpcSender_origin, _SnapRpcSender_provider;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.KeyringSnapRpcClient = exports.SnapRpcSender = void 0;
16
+ const KeyringClient_1 = require("./KeyringClient.cjs");
17
+ /**
18
+ * Implementation of the `Sender` interface that can be used to send requests
19
+ * to a snap through the snap JSON-RPC API.
20
+ */
21
+ class SnapRpcSender {
22
+ /**
23
+ * Create a new instance of `SnapRpcSender`.
24
+ *
25
+ * @param origin - The caller's origin.
26
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
27
+ */
28
+ constructor(origin, provider) {
29
+ _SnapRpcSender_origin.set(this, void 0);
30
+ _SnapRpcSender_provider.set(this, void 0);
31
+ __classPrivateFieldSet(this, _SnapRpcSender_origin, origin, "f");
32
+ __classPrivateFieldSet(this, _SnapRpcSender_provider, provider, "f");
33
+ }
34
+ /**
35
+ * Send a request to the snap and return the response.
36
+ *
37
+ * @param request - The JSON-RPC request to send to the snap.
38
+ * @returns A promise that resolves to the response of the request.
39
+ */
40
+ async send(request) {
41
+ return __classPrivateFieldGet(this, _SnapRpcSender_provider, "f").request({
42
+ method: 'wallet_invokeKeyring',
43
+ params: {
44
+ snapId: __classPrivateFieldGet(this, _SnapRpcSender_origin, "f"),
45
+ request,
46
+ },
47
+ });
48
+ }
49
+ }
50
+ exports.SnapRpcSender = SnapRpcSender;
51
+ _SnapRpcSender_origin = new WeakMap(), _SnapRpcSender_provider = new WeakMap();
52
+ /**
53
+ * A `KeyringClient` that allows the communication with a snap through the snap
54
+ * JSON-RPC API.
55
+ */
56
+ class KeyringSnapRpcClient extends KeyringClient_1.KeyringClient {
57
+ /**
58
+ * Create a new instance of `KeyringSnapRpcClient`.
59
+ *
60
+ * @param origin - Caller's origin.
61
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
62
+ */
63
+ constructor(origin, provider) {
64
+ super(new SnapRpcSender(origin, provider));
65
+ }
66
+ }
67
+ exports.KeyringSnapRpcClient = KeyringSnapRpcClient;
68
+ //# sourceMappingURL=KeyringSnapRpcClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.cjs","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,uDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAVnD,wCAAgB;QAEhB,0CAAkC;QASzC,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;QACtB,uBAAA,IAAI,2BAAa,QAAQ,MAAA,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAC,OAAuB;QAChC,OAAO,uBAAA,IAAI,+BAAU,CAAC,OAAO,CAAC;YAC5B,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE;gBACN,MAAM,EAAE,uBAAA,IAAI,6BAAQ;gBACpB,OAAO;aACR;SACF,CAAkB,CAAC;IACtB,CAAC;CACF;AA/BD,sCA+BC;;AAED;;;GAGG;AACH,MAAa,oBAAqB,SAAQ,6BAAa;IACrD;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAC1D,KAAK,CAAC,IAAI,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC7C,CAAC;CACF;AAVD,oDAUC","sourcesContent":["import type { MetaMaskInpageProvider } from '@metamask/providers';\nimport type { Json } from '@metamask/utils';\n\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport type { Sender } from './KeyringClient';\nimport { KeyringClient } from './KeyringClient';\n\n/**\n * Implementation of the `Sender` interface that can be used to send requests\n * to a snap through the snap JSON-RPC API.\n */\nexport class SnapRpcSender implements Sender {\n readonly #origin: string;\n\n readonly #provider: MetaMaskInpageProvider;\n\n /**\n * Create a new instance of `SnapRpcSender`.\n *\n * @param origin - The caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n this.#origin = origin;\n this.#provider = provider;\n }\n\n /**\n * Send a request to the snap and return the response.\n *\n * @param request - The JSON-RPC request to send to the snap.\n * @returns A promise that resolves to the response of the request.\n */\n async send(request: JsonRpcRequest): Promise<Json> {\n return this.#provider.request({\n method: 'wallet_invokeKeyring',\n params: {\n snapId: this.#origin,\n request,\n },\n }) as Promise<Json>;\n }\n}\n\n/**\n * A `KeyringClient` that allows the communication with a snap through the snap\n * JSON-RPC API.\n */\nexport class KeyringSnapRpcClient extends KeyringClient {\n /**\n * Create a new instance of `KeyringSnapRpcClient`.\n *\n * @param origin - Caller's origin.\n * @param provider - The `MetaMaskInpageProvider` instance to use.\n */\n constructor(origin: string, provider: MetaMaskInpageProvider) {\n super(new SnapRpcSender(origin, provider));\n }\n}\n"]}
@@ -0,0 +1,40 @@
1
+ import type { MetaMaskInpageProvider } from "@metamask/providers";
2
+ import type { Json } from "@metamask/utils";
3
+ import type { JsonRpcRequest } from "./JsonRpcRequest.cjs";
4
+ import type { Sender } from "./KeyringClient.cjs";
5
+ import { KeyringClient } from "./KeyringClient.cjs";
6
+ /**
7
+ * Implementation of the `Sender` interface that can be used to send requests
8
+ * to a snap through the snap JSON-RPC API.
9
+ */
10
+ export declare class SnapRpcSender implements Sender {
11
+ #private;
12
+ /**
13
+ * Create a new instance of `SnapRpcSender`.
14
+ *
15
+ * @param origin - The caller's origin.
16
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
17
+ */
18
+ constructor(origin: string, provider: MetaMaskInpageProvider);
19
+ /**
20
+ * Send a request to the snap and return the response.
21
+ *
22
+ * @param request - The JSON-RPC request to send to the snap.
23
+ * @returns A promise that resolves to the response of the request.
24
+ */
25
+ send(request: JsonRpcRequest): Promise<Json>;
26
+ }
27
+ /**
28
+ * A `KeyringClient` that allows the communication with a snap through the snap
29
+ * JSON-RPC API.
30
+ */
31
+ export declare class KeyringSnapRpcClient extends KeyringClient {
32
+ /**
33
+ * Create a new instance of `KeyringSnapRpcClient`.
34
+ *
35
+ * @param origin - Caller's origin.
36
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
37
+ */
38
+ constructor(origin: string, provider: MetaMaskInpageProvider);
39
+ }
40
+ //# sourceMappingURL=KeyringSnapRpcClient.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.d.cts","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,4BAA4B;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,6BAAyB;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,4BAAwB;AAC9C,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD;;;GAGG;AACH,qBAAa,aAAc,YAAW,MAAM;;IAK1C;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAK5D;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASnD;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;CAG7D"}
@@ -0,0 +1,40 @@
1
+ import type { MetaMaskInpageProvider } from "@metamask/providers";
2
+ import type { Json } from "@metamask/utils";
3
+ import type { JsonRpcRequest } from "./JsonRpcRequest.mjs";
4
+ import type { Sender } from "./KeyringClient.mjs";
5
+ import { KeyringClient } from "./KeyringClient.mjs";
6
+ /**
7
+ * Implementation of the `Sender` interface that can be used to send requests
8
+ * to a snap through the snap JSON-RPC API.
9
+ */
10
+ export declare class SnapRpcSender implements Sender {
11
+ #private;
12
+ /**
13
+ * Create a new instance of `SnapRpcSender`.
14
+ *
15
+ * @param origin - The caller's origin.
16
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
17
+ */
18
+ constructor(origin: string, provider: MetaMaskInpageProvider);
19
+ /**
20
+ * Send a request to the snap and return the response.
21
+ *
22
+ * @param request - The JSON-RPC request to send to the snap.
23
+ * @returns A promise that resolves to the response of the request.
24
+ */
25
+ send(request: JsonRpcRequest): Promise<Json>;
26
+ }
27
+ /**
28
+ * A `KeyringClient` that allows the communication with a snap through the snap
29
+ * JSON-RPC API.
30
+ */
31
+ export declare class KeyringSnapRpcClient extends KeyringClient {
32
+ /**
33
+ * Create a new instance of `KeyringSnapRpcClient`.
34
+ *
35
+ * @param origin - Caller's origin.
36
+ * @param provider - The `MetaMaskInpageProvider` instance to use.
37
+ */
38
+ constructor(origin: string, provider: MetaMaskInpageProvider);
39
+ }
40
+ //# sourceMappingURL=KeyringSnapRpcClient.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyringSnapRpcClient.d.mts","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,4BAA4B;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,6BAAyB;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,4BAAwB;AAC9C,OAAO,EAAE,aAAa,EAAE,4BAAwB;AAEhD;;;GAGG;AACH,qBAAa,aAAc,YAAW,MAAM;;IAK1C;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAK5D;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CASnD;AAED;;;GAGG;AACH,qBAAa,oBAAqB,SAAQ,aAAa;IACrD;;;;;OAKG;gBACS,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;CAG7D"}