@metamask/keyring-api 6.2.0 → 6.3.0

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 (75) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/dist/KeyringClient.js +9 -9
  3. package/dist/KeyringClient.js.map +1 -1
  4. package/dist/api/account.d.ts +62 -0
  5. package/dist/api/account.js +56 -0
  6. package/dist/api/account.js.map +1 -0
  7. package/dist/api/balance.d.ts +9 -0
  8. package/dist/api/balance.js +11 -0
  9. package/dist/api/balance.js.map +1 -0
  10. package/dist/api/export.d.ts +8 -0
  11. package/dist/api/export.js +7 -0
  12. package/dist/api/export.js.map +1 -0
  13. package/dist/api/index.d.ts +6 -0
  14. package/dist/api/index.js +23 -0
  15. package/dist/api/index.js.map +1 -0
  16. package/dist/{api.d.ts → api/keyring.d.ts} +34 -125
  17. package/dist/api/keyring.js +3 -0
  18. package/dist/api/keyring.js.map +1 -0
  19. package/dist/api/request.d.ts +39 -0
  20. package/dist/api/request.js +29 -0
  21. package/dist/api/request.js.map +1 -0
  22. package/dist/api/response.d.ts +24 -0
  23. package/dist/api/response.js +44 -0
  24. package/dist/api/response.js.map +1 -0
  25. package/dist/btc/types.d.ts +4 -7
  26. package/dist/btc/types.js +10 -12
  27. package/dist/btc/types.js.map +1 -1
  28. package/dist/eth/erc4337/types.d.ts +1 -1
  29. package/dist/eth/erc4337/types.js +2 -1
  30. package/dist/eth/erc4337/types.js.map +1 -1
  31. package/dist/eth/types.d.ts +9 -15
  32. package/dist/eth/types.js +23 -29
  33. package/dist/eth/types.js.map +1 -1
  34. package/dist/eth/utils.d.ts +3 -2
  35. package/dist/eth/utils.js +3 -2
  36. package/dist/eth/utils.js.map +1 -1
  37. package/dist/internal/api.d.ts +94 -112
  38. package/dist/internal/api.js +35 -22
  39. package/dist/internal/api.js.map +1 -1
  40. package/dist/internal/events.d.ts +44 -96
  41. package/dist/internal/events.js +10 -10
  42. package/dist/internal/events.js.map +1 -1
  43. package/dist/internal/rpc.d.ts +1 -0
  44. package/dist/internal/rpc.js +1 -0
  45. package/dist/internal/rpc.js.map +1 -1
  46. package/dist/internal/types.d.ts +65 -6
  47. package/dist/internal/types.js +7 -9
  48. package/dist/internal/types.js.map +1 -1
  49. package/dist/rpc-handler.d.ts +12 -0
  50. package/dist/rpc-handler.js +40 -2
  51. package/dist/rpc-handler.js.map +1 -1
  52. package/dist/superstruct.d.ts +9 -4
  53. package/dist/superstruct.js +14 -14
  54. package/dist/superstruct.js.map +1 -1
  55. package/dist/utils/caip.d.ts +37 -0
  56. package/dist/utils/caip.js +48 -0
  57. package/dist/utils/caip.js.map +1 -0
  58. package/dist/utils/index.d.ts +3 -0
  59. package/dist/utils/index.js +20 -0
  60. package/dist/utils/index.js.map +1 -0
  61. package/dist/utils/types.d.ts +17 -0
  62. package/dist/utils/types.js +29 -0
  63. package/dist/utils/types.js.map +1 -0
  64. package/dist/utils/typing.d.ts +32 -0
  65. package/dist/utils/typing.js +21 -0
  66. package/dist/utils/typing.js.map +1 -0
  67. package/package.json +26 -26
  68. package/dist/api.js +0 -108
  69. package/dist/api.js.map +0 -1
  70. package/dist/base-types.d.ts +0 -62
  71. package/dist/base-types.js +0 -32
  72. package/dist/base-types.js.map +0 -1
  73. package/dist/utils.d.ts +0 -26
  74. package/dist/utils.js +0 -26
  75. package/dist/utils.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.3.0]
11
+
12
+ ### Added
13
+
14
+ - Add `getAccountBalances` method to `Keyring` interface ([#320](https://github.com/MetaMask/keyring-api/pull/320)).
15
+ - Add CAIP-19 types to `utils` ([#321](https://github.com/MetaMask/keyring-api/pull/321)).
16
+
17
+ ### Changed
18
+
19
+ - Bump @metamask/snaps-sdk from 4.2.0 to 4.3.0 ([#323](https://github.com/MetaMask/keyring-api/pull/323)).
20
+ - Split `api.ts` into different files ([#319](https://github.com/MetaMask/keyring-api/pull/319)).
21
+ - Make the `KeyringAccount` type less rigid ([#311](https://github.com/MetaMask/keyring-api/pull/311)).
22
+
23
+ ### Fixed
24
+
25
+ - Ensure that errors are JSON-serializable ([#162](https://github.com/MetaMask/keyring-api/pull/162)).
26
+ - Don't use internal types in the public API ([#312](https://github.com/MetaMask/keyring-api/pull/312)).
27
+ - Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
28
+
29
+ ## [6.2.1]
30
+
31
+ ### Changed
32
+
33
+ - Bump @metamask/key-tree from 9.1.0 to 9.1.1 ([#310](https://github.com/MetaMask/keyring-api/pull/310)).
34
+
35
+ ### Fixed
36
+
37
+ - Use internal `object` function instead of the upstream one ([#316](https://github.com/MetaMask/keyring-api/pull/316)).
38
+
10
39
  ## [6.2.0]
11
40
 
12
41
  ### Added
@@ -290,7 +319,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
290
319
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
291
320
  - Helper functions to create keyring handler in the snap.
292
321
 
293
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.2.0...HEAD
322
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.3.0...HEAD
323
+ [6.3.0]: https://github.com/MetaMask/keyring-api/compare/v6.2.1...v6.3.0
324
+ [6.2.1]: https://github.com/MetaMask/keyring-api/compare/v6.2.0...v6.2.1
294
325
  [6.2.0]: https://github.com/MetaMask/keyring-api/compare/v6.1.1...v6.2.0
295
326
  [6.1.1]: https://github.com/MetaMask/keyring-api/compare/v6.1.0...v6.1.1
296
327
  [6.1.0]: https://github.com/MetaMask/keyring-api/compare/v6.0.0...v6.1.0
@@ -17,7 +17,7 @@ const superstruct_1 = require("superstruct");
17
17
  const uuid_1 = require("uuid");
18
18
  const api_1 = require("./internal/api");
19
19
  const rpc_1 = require("./internal/rpc");
20
- const utils_1 = require("./utils");
20
+ const superstruct_2 = require("./superstruct");
21
21
  class KeyringClient {
22
22
  /**
23
23
  * Create a new instance of `KeyringClient`.
@@ -30,24 +30,24 @@ class KeyringClient {
30
30
  __classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
31
31
  }
32
32
  async listAccounts() {
33
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
33
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
34
34
  method: rpc_1.KeyringRpcMethod.ListAccounts,
35
35
  }), api_1.ListAccountsResponseStruct);
36
36
  }
37
37
  async getAccount(id) {
38
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
38
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
39
39
  method: rpc_1.KeyringRpcMethod.GetAccount,
40
40
  params: { id },
41
41
  }), api_1.GetAccountResponseStruct);
42
42
  }
43
43
  async createAccount(options = {}) {
44
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
44
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
45
45
  method: rpc_1.KeyringRpcMethod.CreateAccount,
46
46
  params: { options },
47
47
  }), api_1.CreateAccountResponseStruct);
48
48
  }
49
49
  async filterAccountChains(id, chains) {
50
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
50
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
51
51
  method: rpc_1.KeyringRpcMethod.FilterAccountChains,
52
52
  params: { id, chains },
53
53
  }), api_1.FilterAccountChainsResponseStruct);
@@ -65,24 +65,24 @@ class KeyringClient {
65
65
  }), api_1.DeleteAccountResponseStruct);
66
66
  }
67
67
  async exportAccount(id) {
68
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
68
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
69
69
  method: rpc_1.KeyringRpcMethod.ExportAccount,
70
70
  params: { id },
71
71
  }), api_1.ExportAccountResponseStruct);
72
72
  }
73
73
  async listRequests() {
74
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
74
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
75
75
  method: rpc_1.KeyringRpcMethod.ListRequests,
76
76
  }), api_1.ListRequestsResponseStruct);
77
77
  }
78
78
  async getRequest(id) {
79
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
79
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
80
80
  method: rpc_1.KeyringRpcMethod.GetRequest,
81
81
  params: { id },
82
82
  }), api_1.GetRequestResponseStruct);
83
83
  }
84
84
  async submitRequest(request) {
85
- return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
85
+ return (0, superstruct_2.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
86
86
  method: rpc_1.KeyringRpcMethod.SubmitRequest,
87
87
  params: request,
88
88
  }), api_1.SubmitRequestResponseStruct);
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCA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;QAE/B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,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;AApJD,sCAoJC;;AAxIC;;;;;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 type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\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 './utils';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n #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 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 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"]}
1
+ {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AACxB,wCAAkD;AAElD,+CAA2C;AAM3C,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,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,aAAa,CACjB,UAAgC,EA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GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\nimport { v4 as uuid } from 'uuid';\n\nimport type {\n Keyring,\n KeyringAccount,\n KeyringRequest,\n KeyringAccountData,\n KeyringResponse,\n} from './api';\nimport {\n ApproveRequestResponseStruct,\n CreateAccountResponseStruct,\n DeleteAccountResponseStruct,\n ExportAccountResponseStruct,\n FilterAccountChainsResponseStruct,\n GetAccountResponseStruct,\n GetRequestResponseStruct,\n ListAccountsResponseStruct,\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';\n\nexport type Sender = {\n send(request: JsonRpcRequest): Promise<Json>;\n};\n\nexport class KeyringClient implements Keyring {\n #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 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 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,62 @@
1
+ import type { Infer } from 'superstruct';
2
+ /**
3
+ * Supported Ethereum account types.
4
+ */
5
+ export declare enum EthAccountType {
6
+ Eoa = "eip155:eoa",
7
+ Erc4337 = "eip155:erc4337"
8
+ }
9
+ /**
10
+ * Supported Bitcoin account types.
11
+ */
12
+ export declare enum BtcAccountType {
13
+ P2wpkh = "bip122:p2wpkh"
14
+ }
15
+ /**
16
+ * Supported account types.
17
+ */
18
+ export declare type KeyringAccountType = `${EthAccountType.Eoa}` | `${EthAccountType.Erc4337}` | `${BtcAccountType.P2wpkh}`;
19
+ /**
20
+ * A struct which represents a Keyring account object. It is abstract enough to
21
+ * be used with any blockchain. Specific blockchain account types should extend
22
+ * this struct.
23
+ *
24
+ * See {@link KeyringAccount}.
25
+ */
26
+ export declare const KeyringAccountStruct: import("superstruct").Struct<{
27
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
28
+ id: string;
29
+ address: string;
30
+ options: Record<string, import("@metamask/utils").Json>;
31
+ methods: string[];
32
+ }, {
33
+ /**
34
+ * Account ID (UUIDv4).
35
+ */
36
+ id: import("superstruct").Struct<string, null>;
37
+ /**
38
+ * Account type.
39
+ */
40
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
41
+ "eip155:eoa": "eip155:eoa";
42
+ "eip155:erc4337": "eip155:erc4337";
43
+ "bip122:p2wpkh": "bip122:p2wpkh";
44
+ }>;
45
+ /**
46
+ * Account main address.
47
+ */
48
+ address: import("superstruct").Struct<string, null>;
49
+ /**
50
+ * Account options.
51
+ */
52
+ options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
53
+ /**
54
+ * Account supported methods.
55
+ */
56
+ methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
57
+ }>;
58
+ /**
59
+ * Keyring Account type represents an account and its properties from the
60
+ * point of view of the keyring.
61
+ */
62
+ export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringAccountStruct = exports.BtcAccountType = exports.EthAccountType = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const superstruct_1 = require("superstruct");
6
+ const superstruct_2 = require("../superstruct");
7
+ const utils_2 = require("../utils");
8
+ /**
9
+ * Supported Ethereum account types.
10
+ */
11
+ var EthAccountType;
12
+ (function (EthAccountType) {
13
+ EthAccountType["Eoa"] = "eip155:eoa";
14
+ EthAccountType["Erc4337"] = "eip155:erc4337";
15
+ })(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
16
+ /**
17
+ * Supported Bitcoin account types.
18
+ */
19
+ var BtcAccountType;
20
+ (function (BtcAccountType) {
21
+ BtcAccountType["P2wpkh"] = "bip122:p2wpkh";
22
+ })(BtcAccountType = exports.BtcAccountType || (exports.BtcAccountType = {}));
23
+ /**
24
+ * A struct which represents a Keyring account object. It is abstract enough to
25
+ * be used with any blockchain. Specific blockchain account types should extend
26
+ * this struct.
27
+ *
28
+ * See {@link KeyringAccount}.
29
+ */
30
+ exports.KeyringAccountStruct = (0, superstruct_2.object)({
31
+ /**
32
+ * Account ID (UUIDv4).
33
+ */
34
+ id: utils_2.UuidStruct,
35
+ /**
36
+ * Account type.
37
+ */
38
+ type: (0, superstruct_1.enums)([
39
+ `${EthAccountType.Eoa}`,
40
+ `${EthAccountType.Erc4337}`,
41
+ `${BtcAccountType.P2wpkh}`,
42
+ ]),
43
+ /**
44
+ * Account main address.
45
+ */
46
+ address: (0, superstruct_1.string)(),
47
+ /**
48
+ * Account options.
49
+ */
50
+ options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
51
+ /**
52
+ * Account supported methods.
53
+ */
54
+ methods: (0, superstruct_1.array)((0, superstruct_1.string)()),
55
+ });
56
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/api/account.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA2D;AAE3D,gDAAwC;AACxC,oCAAsC;AAEtC;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAUD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC;QACV,GAAG,cAAc,CAAC,GAAG,EAAE;QACvB,GAAG,cAAc,CAAC,OAAO,EAAE;QAC3B,GAAG,cAAc,CAAC,MAAM,EAAE;KAC3B,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,GAAE;IAEjB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC;CACzB,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, record, string } from 'superstruct';\n\nimport { object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\n/**\n * Supported account types.\n */\nexport type KeyringAccountType =\n | `${EthAccountType.Eoa}`\n | `${EthAccountType.Erc4337}`\n | `${BtcAccountType.P2wpkh}`;\n\n/**\n * A struct which represents a Keyring account object. It is abstract enough to\n * be used with any blockchain. Specific blockchain account types should extend\n * this struct.\n *\n * See {@link KeyringAccount}.\n */\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account type.\n */\n type: enums([\n `${EthAccountType.Eoa}`,\n `${EthAccountType.Erc4337}`,\n `${BtcAccountType.P2wpkh}`,\n ]),\n\n /**\n * Account main address.\n */\n address: string(),\n\n /**\n * Account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(string()),\n});\n\n/**\n * Keyring Account type represents an account and its properties from the\n * point of view of the keyring.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n"]}
@@ -0,0 +1,9 @@
1
+ import type { Infer } from 'superstruct';
2
+ export declare const BalanceStruct: import("superstruct").Struct<{
3
+ amount: string;
4
+ unit: string;
5
+ }, {
6
+ amount: import("superstruct").Struct<string, null>;
7
+ unit: import("superstruct").Struct<string, null>;
8
+ }>;
9
+ export declare type Balance = Infer<typeof BalanceStruct>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BalanceStruct = void 0;
4
+ const superstruct_1 = require("superstruct");
5
+ const superstruct_2 = require("../superstruct");
6
+ const utils_1 = require("../utils");
7
+ exports.BalanceStruct = (0, superstruct_2.object)({
8
+ amount: utils_1.StringNumberStruct,
9
+ unit: (0, superstruct_1.string)(),
10
+ });
11
+ //# sourceMappingURL=balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balance.js","sourceRoot":"","sources":["../../src/api/balance.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAErC,gDAAwC;AACxC,oCAA8C;AAEjC,QAAA,aAAa,GAAG,IAAA,oBAAM,EAAC;IAClC,MAAM,EAAE,0BAAkB;IAC1B,IAAI,EAAE,IAAA,oBAAM,GAAE;CACf,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { string } from 'superstruct';\n\nimport { object } from '../superstruct';\nimport { StringNumberStruct } from '../utils';\n\nexport const BalanceStruct = object({\n amount: StringNumberStruct,\n unit: string(),\n});\n\nexport type Balance = Infer<typeof BalanceStruct>;\n"]}
@@ -0,0 +1,8 @@
1
+ import type { Infer } from 'superstruct';
2
+ export declare const KeyringAccountDataStruct: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
3
+ /**
4
+ * Response to a call to `exportAccount`.
5
+ *
6
+ * The exact response depends on the keyring implementation.
7
+ */
8
+ export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringAccountDataStruct = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const superstruct_1 = require("superstruct");
6
+ exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
7
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/api/export.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA6C;AAEhC,QAAA,wBAAwB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { record, string } from 'superstruct';\n\nexport const KeyringAccountDataStruct = record(string(), JsonStruct);\n\n/**\n * Response to a call to `exportAccount`.\n *\n * The exact response depends on the keyring implementation.\n */\nexport type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;\n"]}
@@ -0,0 +1,6 @@
1
+ export * from './account';
2
+ export * from './balance';
3
+ export * from './export';
4
+ export * from './keyring';
5
+ export * from './request';
6
+ export * from './response';
@@ -0,0 +1,23 @@
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("./account"), exports);
18
+ __exportStar(require("./balance"), exports);
19
+ __exportStar(require("./export"), exports);
20
+ __exportStar(require("./keyring"), exports);
21
+ __exportStar(require("./request"), exports);
22
+ __exportStar(require("./response"), exports);
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,4CAA0B;AAC1B,2CAAyB;AACzB,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B","sourcesContent":["export * from './account';\nexport * from './balance';\nexport * from './export';\nexport * from './keyring';\nexport * from './request';\nexport * from './response';\n"]}
@@ -1,129 +1,10 @@
1
1
  import type { Json } from '@metamask/utils';
2
- import type { Infer, Struct } from 'superstruct';
3
- import type { StaticAssertAbstractAccount } from './base-types';
4
- import type { BtcP2wpkhAccount } from './btc';
5
- import type { EthEoaAccount, EthErc4337Account } from './eth';
6
- /**
7
- * Type of supported accounts.
8
- */
9
- export declare type KeyringAccounts = StaticAssertAbstractAccount<EthEoaAccount | EthErc4337Account | BtcP2wpkhAccount>;
10
- /**
11
- * Mapping between account types and their matching `superstruct` schema.
12
- */
13
- export declare const KeyringAccountStructs: Record<string, Struct<EthEoaAccount> | Struct<EthErc4337Account> | Struct<BtcP2wpkhAccount>>;
14
- /**
15
- * Base type for `KeyringAccount` as a `superstruct.object`.
16
- */
17
- export declare const BaseKeyringAccountStruct: Struct<{
18
- type: "bip122:p2wpkh" | "eip155:eoa" | "eip155:erc4337";
19
- }, {
20
- /**
21
- * Account type.
22
- */
23
- type: Struct<"bip122:p2wpkh" | "eip155:eoa" | "eip155:erc4337", {
24
- "bip122:p2wpkh": "bip122:p2wpkh";
25
- "eip155:eoa": "eip155:eoa";
26
- "eip155:erc4337": "eip155:erc4337";
27
- }>;
28
- }>;
29
- /**
30
- * Account as a `superstruct.object`.
31
- *
32
- * See {@link KeyringAccount}.
33
- */
34
- export declare const KeyringAccountStruct: Struct<{
35
- type: "bip122:p2wpkh";
36
- id: string;
37
- address: string;
38
- options: Record<string, Json>;
39
- methods: "btc_sendmany"[];
40
- } | {
41
- type: "eip155:eoa";
42
- id: string;
43
- address: string;
44
- options: Record<string, Json>;
45
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
46
- } | {
47
- type: "eip155:erc4337";
48
- id: string;
49
- address: string;
50
- options: Record<string, Json>;
51
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
52
- }, null>;
53
- /**
54
- * Account object.
55
- *
56
- * Represents an account with its properties and capabilities.
57
- */
58
- export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
59
- export declare const KeyringRequestStruct: Struct<{
60
- id: string;
61
- account: string;
62
- scope: string;
63
- request: {
64
- method: string;
65
- params?: Json[] | Record<string, Json>;
66
- };
67
- }, {
68
- /**
69
- * Keyring request ID (UUIDv4).
70
- */
71
- id: Struct<string, null>;
72
- /**
73
- * Request's scope (CAIP-2 chain ID).
74
- */
75
- scope: Struct<string, null>;
76
- /**
77
- * Account ID (UUIDv4).
78
- */
79
- account: Struct<string, null>;
80
- /**
81
- * Inner request sent by the client application.
82
- */
83
- request: Struct<{
84
- method: string;
85
- params?: Json[] | Record<string, Json>;
86
- }, {
87
- method: Struct<string, null>;
88
- params: Struct<import("./superstruct").ExactOptionalTag | Json[] | Record<string, Json>, null>;
89
- }>;
90
- }>;
91
- /**
92
- * Keyring request.
93
- *
94
- * Represents a request made to the keyring for account-related operations.
95
- */
96
- export declare type KeyringRequest = Infer<typeof KeyringRequestStruct>;
97
- export declare const KeyringAccountDataStruct: Struct<Record<string, Json>, null>;
98
- /**
99
- * Response to a call to `exportAccount`.
100
- *
101
- * The exact response depends on the keyring implementation.
102
- */
103
- export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
104
- export declare const KeyringResponseStruct: Struct<{
105
- pending: true;
106
- redirect?: {
107
- message?: string;
108
- url?: string;
109
- };
110
- } | {
111
- pending: false;
112
- result: Json;
113
- }, null>;
114
- /**
115
- * Response to a call to `submitRequest`.
116
- *
117
- * Keyring implementations must return a response with `pending: true` if the
118
- * request will be handled asynchronously. Otherwise, the response must contain
119
- * the result of the request and `pending: false`.
120
- *
121
- * In the asynchronous case, the keyring can return a redirect URL and message
122
- * to be shown to the user. The user can choose to follow the link or cancel
123
- * the request. The main use case for this is to redirect the user to the snap
124
- * dapp to review the request.
125
- */
126
- export declare type KeyringResponse = Infer<typeof KeyringResponseStruct>;
2
+ import type { CaipAssetType } from '../utils';
3
+ import type { KeyringAccount } from './account';
4
+ import type { Balance } from './balance';
5
+ import type { KeyringAccountData } from './export';
6
+ import type { KeyringRequest } from './request';
7
+ import type { KeyringResponse } from './response';
127
8
  /**
128
9
  * Keyring interface.
129
10
  *
@@ -160,6 +41,34 @@ export declare type Keyring = {
160
41
  * object without any private information.
161
42
  */
162
43
  createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
44
+ /**
45
+ * Retrieve the balances of a given account.
46
+ *
47
+ * This method fetches the balances of specified assets for a given account
48
+ * ID. It returns a promise that resolves to an object where the keys are
49
+ * asset types and the values are balance objects containing the amount and
50
+ * unit.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * await keyring.getAccountBalances(
55
+ * '43550276-c7d6-4fac-87c7-00390ad0ce90',
56
+ * ['bip122:000000000019d6689c085ae165831e93/slip44:0']
57
+ * );
58
+ * // Returns something similar to:
59
+ * // {
60
+ * // 'bip122:000000000019d6689c085ae165831e93/slip44:0': {
61
+ * // amount: '0.0001',
62
+ * // unit: 'BTC',
63
+ * // }
64
+ * // }
65
+ * ```
66
+ * @param id - ID of the account to retrieve the balances for.
67
+ * @param assets - Array of asset types (CAIP-19) to retrieve balances for.
68
+ * @returns A promise that resolves to an object mapping asset types to their
69
+ * respective balances.
70
+ */
71
+ getAccountBalances?(id: string, assets: CaipAssetType[]): Promise<Record<CaipAssetType, Balance>>;
163
72
  /**
164
73
  * Filter supported chains for a given account.
165
74
  *
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring.js","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { CaipAssetType } from '../utils';\nimport type { KeyringAccount } from './account';\nimport type { Balance } from './balance';\nimport type { KeyringAccountData } from './export';\nimport type { KeyringRequest } from './request';\nimport type { KeyringResponse } from './response';\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Retrieve the balances of a given account.\n *\n * This method fetches the balances of specified assets for a given account\n * ID. It returns a promise that resolves to an object where the keys are\n * asset types and the values are balance objects containing the amount and\n * unit.\n *\n * @example\n * ```ts\n * await keyring.getAccountBalances(\n * '43550276-c7d6-4fac-87c7-00390ad0ce90',\n * ['bip122:000000000019d6689c085ae165831e93/slip44:0']\n * );\n * // Returns something similar to:\n * // {\n * // 'bip122:000000000019d6689c085ae165831e93/slip44:0': {\n * // amount: '0.0001',\n * // unit: 'BTC',\n * // }\n * // }\n * ```\n * @param id - ID of the account to retrieve the balances for.\n * @param assets - Array of asset types (CAIP-19) to retrieve balances for.\n * @returns A promise that resolves to an object mapping asset types to their\n * respective balances.\n */\n getAccountBalances?(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
@@ -0,0 +1,39 @@
1
+ import type { Infer } from 'superstruct';
2
+ export declare const KeyringRequestStruct: import("superstruct").Struct<{
3
+ id: string;
4
+ scope: string;
5
+ account: string;
6
+ request: {
7
+ method: string;
8
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
9
+ };
10
+ }, {
11
+ /**
12
+ * Keyring request ID (UUIDv4).
13
+ */
14
+ id: import("superstruct").Struct<string, null>;
15
+ /**
16
+ * Request's scope (CAIP-2 chain ID).
17
+ */
18
+ scope: import("superstruct").Struct<string, null>;
19
+ /**
20
+ * Account ID (UUIDv4).
21
+ */
22
+ account: import("superstruct").Struct<string, null>;
23
+ /**
24
+ * Inner request sent by the client application.
25
+ */
26
+ request: import("superstruct").Struct<{
27
+ method: string;
28
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
29
+ }, {
30
+ method: import("superstruct").Struct<string, null>;
31
+ params: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
32
+ }>;
33
+ }>;
34
+ /**
35
+ * Keyring request.
36
+ *
37
+ * Represents a request made to the keyring for account-related operations.
38
+ */
39
+ export declare type KeyringRequest = Infer<typeof KeyringRequestStruct>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringRequestStruct = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const superstruct_1 = require("superstruct");
6
+ const superstruct_2 = require("../superstruct");
7
+ const utils_2 = require("../utils");
8
+ exports.KeyringRequestStruct = (0, superstruct_2.object)({
9
+ /**
10
+ * Keyring request ID (UUIDv4).
11
+ */
12
+ id: utils_2.UuidStruct,
13
+ /**
14
+ * Request's scope (CAIP-2 chain ID).
15
+ */
16
+ scope: (0, superstruct_1.string)(),
17
+ /**
18
+ * Account ID (UUIDv4).
19
+ */
20
+ account: utils_2.UuidStruct,
21
+ /**
22
+ * Inner request sent by the client application.
23
+ */
24
+ request: (0, superstruct_2.object)({
25
+ method: (0, superstruct_1.string)(),
26
+ 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)])),
27
+ }),
28
+ });
29
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/api/request.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA2D;AAE3D,gDAAuD;AACvD,oCAAsC;AAEzB,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC;QACd,MAAM,EAAE,IAAA,oBAAM,GAAE;QAChB,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;KACF,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n"]}