@metamask/keyring-api 6.2.1 → 6.3.1

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 (73) hide show
  1. package/CHANGELOG.md +28 -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/caip.d.ts +37 -0
  11. package/dist/api/caip.js +48 -0
  12. package/dist/api/caip.js.map +1 -0
  13. package/dist/api/export.d.ts +8 -0
  14. package/dist/api/export.js +7 -0
  15. package/dist/api/export.js.map +1 -0
  16. package/dist/api/index.d.ts +7 -0
  17. package/dist/api/index.js +24 -0
  18. package/dist/api/index.js.map +1 -0
  19. package/dist/{api.d.ts → api/keyring.d.ts} +34 -125
  20. package/dist/api/keyring.js +3 -0
  21. package/dist/api/keyring.js.map +1 -0
  22. package/dist/api/request.d.ts +39 -0
  23. package/dist/api/request.js +29 -0
  24. package/dist/api/request.js.map +1 -0
  25. package/dist/api/response.d.ts +24 -0
  26. package/dist/api/response.js +44 -0
  27. package/dist/api/response.js.map +1 -0
  28. package/dist/btc/types.d.ts +4 -7
  29. package/dist/btc/types.js +10 -12
  30. package/dist/btc/types.js.map +1 -1
  31. package/dist/eth/erc4337/types.d.ts +1 -1
  32. package/dist/eth/erc4337/types.js +2 -1
  33. package/dist/eth/erc4337/types.js.map +1 -1
  34. package/dist/eth/types.d.ts +9 -15
  35. package/dist/eth/types.js +23 -29
  36. package/dist/eth/types.js.map +1 -1
  37. package/dist/eth/utils.d.ts +3 -2
  38. package/dist/eth/utils.js +3 -2
  39. package/dist/eth/utils.js.map +1 -1
  40. package/dist/internal/api.d.ts +94 -112
  41. package/dist/internal/api.js +35 -22
  42. package/dist/internal/api.js.map +1 -1
  43. package/dist/internal/events.d.ts +40 -92
  44. package/dist/internal/rpc.d.ts +1 -0
  45. package/dist/internal/rpc.js +1 -0
  46. package/dist/internal/rpc.js.map +1 -1
  47. package/dist/internal/types.d.ts +65 -6
  48. package/dist/internal/types.js +7 -9
  49. package/dist/internal/types.js.map +1 -1
  50. package/dist/rpc-handler.d.ts +12 -0
  51. package/dist/rpc-handler.js +40 -2
  52. package/dist/rpc-handler.js.map +1 -1
  53. package/dist/superstruct.d.ts +9 -4
  54. package/dist/superstruct.js +14 -14
  55. package/dist/superstruct.js.map +1 -1
  56. package/dist/utils/index.d.ts +2 -0
  57. package/dist/utils/index.js +19 -0
  58. package/dist/utils/index.js.map +1 -0
  59. package/dist/utils/types.d.ts +17 -0
  60. package/dist/utils/types.js +29 -0
  61. package/dist/utils/types.js.map +1 -0
  62. package/dist/utils/typing.d.ts +32 -0
  63. package/dist/utils/typing.js +21 -0
  64. package/dist/utils/typing.js.map +1 -0
  65. package/package.json +1 -1
  66. package/dist/api.js +0 -108
  67. package/dist/api.js.map +0 -1
  68. package/dist/base-types.d.ts +0 -62
  69. package/dist/base-types.js +0 -32
  70. package/dist/base-types.js.map +0 -1
  71. package/dist/utils.d.ts +0 -26
  72. package/dist/utils.js +0 -26
  73. package/dist/utils.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [6.3.1]
11
+
12
+ ### Fixed
13
+
14
+ - Export `Caip*` types used in the API ([#325](https://github.com/MetaMask/keyring-api/pull/325)).
15
+
16
+ ## [6.3.0]
17
+
18
+ ### Added
19
+
20
+ - Add `getAccountBalances` method to `Keyring` interface ([#320](https://github.com/MetaMask/keyring-api/pull/320)).
21
+ - Add CAIP-19 types to `utils` ([#321](https://github.com/MetaMask/keyring-api/pull/321)).
22
+
23
+ ### Changed
24
+
25
+ - Bump @metamask/snaps-sdk from 4.2.0 to 4.3.0 ([#323](https://github.com/MetaMask/keyring-api/pull/323)).
26
+ - Split `api.ts` into different files ([#319](https://github.com/MetaMask/keyring-api/pull/319)).
27
+ - Make the `KeyringAccount` type less rigid ([#311](https://github.com/MetaMask/keyring-api/pull/311)).
28
+
29
+ ### Fixed
30
+
31
+ - Ensure that errors are JSON-serializable ([#162](https://github.com/MetaMask/keyring-api/pull/162)).
32
+ - Don't use internal types in the public API ([#312](https://github.com/MetaMask/keyring-api/pull/312)).
33
+ - Keep all ETH methods in the same `enum` ([#313](https://github.com/MetaMask/keyring-api/pull/313)).
34
+
10
35
  ## [6.2.1]
11
36
 
12
37
  ### Changed
@@ -300,7 +325,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
300
325
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
301
326
  - Helper functions to create keyring handler in the snap.
302
327
 
303
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.2.1...HEAD
328
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v6.3.1...HEAD
329
+ [6.3.1]: https://github.com/MetaMask/keyring-api/compare/v6.3.0...v6.3.1
330
+ [6.3.0]: https://github.com/MetaMask/keyring-api/compare/v6.2.1...v6.3.0
304
331
  [6.2.1]: https://github.com/MetaMask/keyring-api/compare/v6.2.0...v6.2.1
305
332
  [6.2.0]: https://github.com/MetaMask/keyring-api/compare/v6.1.1...v6.2.0
306
333
  [6.1.1]: https://github.com/MetaMask/keyring-api/compare/v6.1.0...v6.1.1
@@ -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,wCAawB;AACxB,wCAAkD;AAElD,mCAAqC;AAMrC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,C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AE;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,EAAE;QAElC,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,EAAE,OAAO,EAAE;SAC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AO,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,CAAC,OAAuB;QACzC,OAAO,IAAA,wBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAgB,CAAC,aAAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,iCAA2B,CAC5B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,EAAU,EACV,OAA6B,EAAE;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 './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,37 @@
1
+ import { type Infer } from 'superstruct';
2
+ /**
3
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
4
+ */
5
+ export declare const CaipAssetTypeStruct: import("superstruct").Struct<string, null>;
6
+ export declare type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;
7
+ /**
8
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
9
+ */
10
+ export declare const CaipAssetIdStruct: import("superstruct").Struct<string, null>;
11
+ export declare type CaipAssetId = Infer<typeof CaipAssetIdStruct>;
12
+ /**
13
+ * Check if the given value is a {@link CaipAssetType}.
14
+ *
15
+ * @param value - The value to check.
16
+ * @returns Whether the value is a {@link CaipAssetType}.
17
+ * @example
18
+ * ```ts
19
+ * isCaipAssetType('eip155:1/slip44:60'); // true
20
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
21
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
22
+ * ```
23
+ */
24
+ export declare function isCaipAssetType(value: unknown): value is CaipAssetType;
25
+ /**
26
+ * Check if the given value is a {@link CaipAssetId}.
27
+ *
28
+ * @param value - The value to check.
29
+ * @returns Whether the value is a {@link CaipAssetId}.
30
+ * @example
31
+ * ```ts
32
+ * isCaipAssetType('eip155:1/slip44:60'); // false
33
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
34
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
35
+ * ```
36
+ */
37
+ export declare function isCaipAssetId(value: unknown): value is CaipAssetId;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCaipAssetId = exports.isCaipAssetType = exports.CaipAssetIdStruct = exports.CaipAssetTypeStruct = void 0;
4
+ const superstruct_1 = require("superstruct");
5
+ const superstruct_2 = require("../superstruct");
6
+ const CAIP_ASSET_TYPE_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;
7
+ const CAIP_ASSET_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;
8
+ /**
9
+ * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.
10
+ */
11
+ exports.CaipAssetTypeStruct = (0, superstruct_2.definePattern)('CaipAssetType', CAIP_ASSET_TYPE_REGEX);
12
+ /**
13
+ * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.
14
+ */
15
+ exports.CaipAssetIdStruct = (0, superstruct_2.definePattern)('CaipAssetId', CAIP_ASSET_ID_REGEX);
16
+ /**
17
+ * Check if the given value is a {@link CaipAssetType}.
18
+ *
19
+ * @param value - The value to check.
20
+ * @returns Whether the value is a {@link CaipAssetType}.
21
+ * @example
22
+ * ```ts
23
+ * isCaipAssetType('eip155:1/slip44:60'); // true
24
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true
25
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false
26
+ * ```
27
+ */
28
+ function isCaipAssetType(value) {
29
+ return (0, superstruct_1.is)(value, exports.CaipAssetTypeStruct);
30
+ }
31
+ exports.isCaipAssetType = isCaipAssetType;
32
+ /**
33
+ * Check if the given value is a {@link CaipAssetId}.
34
+ *
35
+ * @param value - The value to check.
36
+ * @returns Whether the value is a {@link CaipAssetId}.
37
+ * @example
38
+ * ```ts
39
+ * isCaipAssetType('eip155:1/slip44:60'); // false
40
+ * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false
41
+ * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true
42
+ * ```
43
+ */
44
+ function isCaipAssetId(value) {
45
+ return (0, superstruct_1.is)(value, exports.CaipAssetIdStruct);
46
+ }
47
+ exports.isCaipAssetId = isCaipAssetId;
48
+ //# sourceMappingURL=caip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caip.js","sourceRoot":"","sources":["../../src/api/caip.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAE7C,gDAA+C;AAE/C,MAAM,qBAAqB,GACzB,2JAA2J,CAAC;AAE9J,MAAM,mBAAmB,GACvB,6LAA6L,CAAC;AAEhM;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,2BAAa,EAC9C,eAAe,EACf,qBAAqB,CACtB,CAAC;AAGF;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,2BAAa,EAC5C,aAAa,EACb,mBAAmB,CACpB,CAAC;AAGF;;;;;;;;;;;GAWG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,2BAAmB,CAAC,CAAC;AACxC,CAAC;AAFD,0CAEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,yBAAiB,CAAC,CAAC;AACtC,CAAC;AAFD,sCAEC","sourcesContent":["import { is, type Infer } from 'superstruct';\n\nimport { definePattern } from '../superstruct';\n\nconst CAIP_ASSET_TYPE_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})$/u;\n\nconst CAIP_ASSET_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-_a-zA-Z0-9]{1,32}))\\/(?<assetNamespace>[-a-z0-9]{3,8}):(?<assetReference>[-.%a-zA-Z0-9]{1,128})\\/(?<tokenId>[-.%a-zA-Z0-9]{1,78})$/u;\n\n/**\n * A CAIP-19 asset type identifier, i.e., a human-readable type of asset identifier.\n */\nexport const CaipAssetTypeStruct = definePattern(\n 'CaipAssetType',\n CAIP_ASSET_TYPE_REGEX,\n);\nexport type CaipAssetType = Infer<typeof CaipAssetTypeStruct>;\n\n/**\n * A CAIP-19 asset ID identifier, i.e., a human-readable type of asset ID.\n */\nexport const CaipAssetIdStruct = definePattern(\n 'CaipAssetId',\n CAIP_ASSET_ID_REGEX,\n);\nexport type CaipAssetId = Infer<typeof CaipAssetIdStruct>;\n\n/**\n * Check if the given value is a {@link CaipAssetType}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetType}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // true\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // true\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // false\n * ```\n */\nexport function isCaipAssetType(value: unknown): value is CaipAssetType {\n return is(value, CaipAssetTypeStruct);\n}\n\n/**\n * Check if the given value is a {@link CaipAssetId}.\n *\n * @param value - The value to check.\n * @returns Whether the value is a {@link CaipAssetId}.\n * @example\n * ```ts\n * isCaipAssetType('eip155:1/slip44:60'); // false\n * isCaipAssetType('cosmos:cosmoshub-3/slip44:118'); // false\n * isCaipAssetType('hedera:mainnet/nft:0.0.55492/12'); // true\n * ```\n */\nexport function isCaipAssetId(value: unknown): value is CaipAssetId {\n return is(value, CaipAssetIdStruct);\n}\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,7 @@
1
+ export * from './account';
2
+ export * from './balance';
3
+ export * from './caip';
4
+ export * from './export';
5
+ export * from './keyring';
6
+ export * from './request';
7
+ export * from './response';
@@ -0,0 +1,24 @@
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("./caip"), exports);
20
+ __exportStar(require("./export"), exports);
21
+ __exportStar(require("./keyring"), exports);
22
+ __exportStar(require("./request"), exports);
23
+ __exportStar(require("./response"), exports);
24
+ //# 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,yCAAuB;AACvB,2CAAyB;AACzB,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B","sourcesContent":["export * from './account';\nexport * from './balance';\nexport * from './caip';\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 { KeyringAccount } from './account';
3
+ import type { Balance } from './balance';
4
+ import type { CaipAssetType } from './caip';
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