@metamask/keyring-api 0.2.1 → 0.2.3

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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.2.3]
10
+ ### Added
11
+ - Add redirection message to snap async response ([#102](https://github.com/MetaMask/keyring-api/pull/102))
12
+
13
+ ### Changed
14
+ - Use `Omit` instead of `OmitUnion` ([#106](https://github.com/MetaMask/keyring-api/pull/106))
15
+ - Update `KeyringResponse` comment ([#103](https://github.com/MetaMask/keyring-api/pull/103))
16
+ - Use `KeyringRpcMethod` enum instead of string ([#105](https://github.com/MetaMask/keyring-api/pull/105))
17
+ - Refactor tests to match superstruct examples ([#104](https://github.com/MetaMask/keyring-api/pull/104))
18
+ - Add `exactOptional()` superstruct type ([#100](https://github.com/MetaMask/keyring-api/pull/100))
19
+ - Bump @metamask/providers from 11.1.2 to 12.0.0 ([#99](https://github.com/MetaMask/keyring-api/pull/99))
20
+ - Bump @metamask/providers from 11.1.1 to 11.1.2 ([#98](https://github.com/MetaMask/keyring-api/pull/98))
21
+
22
+ ## [0.2.2]
23
+ ### Added
24
+ - Add architecture and EVM methods docs ([#86](https://github.com/MetaMask/keyring-api/pull/86))
25
+ - Add `lastSelected` and `lastActive` to metadata ([#92](https://github.com/MetaMask/keyring-api/pull/92))
26
+
27
+ ### Changed
28
+ - Make request `params` optional ([#96](https://github.com/MetaMask/keyring-api/pull/96))
29
+ - Remove `lastActive` field from internal account model ([#95](https://github.com/MetaMask/keyring-api/pull/95))
30
+ - Move request ID to outer request ([#94](https://github.com/MetaMask/keyring-api/pull/94))
31
+
9
32
  ## [0.2.1]
10
33
  ### Changed
11
34
  - Set `snap` object keys to be mandatory and move `name` to `metadata` ([#87](https://github.com/MetaMask/keyring-api/pull/87))
@@ -52,7 +75,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
52
75
  - SnapController keyring client. It is intended to be used by MetaMask to talk to the snap.
53
76
  - Helper functions to create keyring handler in the snap.
54
77
 
55
- [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.1...HEAD
78
+ [Unreleased]: https://github.com/MetaMask/keyring-api/compare/v0.2.3...HEAD
79
+ [0.2.3]: https://github.com/MetaMask/keyring-api/compare/v0.2.2...v0.2.3
80
+ [0.2.2]: https://github.com/MetaMask/keyring-api/compare/v0.2.1...v0.2.2
56
81
  [0.2.1]: https://github.com/MetaMask/keyring-api/compare/v0.2.0...v0.2.1
57
82
  [0.2.0]: https://github.com/MetaMask/keyring-api/compare/v0.1.3...v0.2.0
58
83
  [0.1.3]: https://github.com/MetaMask/keyring-api/compare/v0.1.2...v0.1.3
@@ -1,14 +1,15 @@
1
- import { type Infer } from 'superstruct';
1
+ import type { Infer } from 'superstruct';
2
2
  export declare const JsonRpcRequestStruct: import("superstruct").Struct<{
3
3
  jsonrpc: "2.0";
4
4
  id: string | number | null;
5
5
  method: string;
6
- } | {
7
- jsonrpc: "2.0";
8
- id: string | number | null;
9
- method: string;
10
- params: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
11
- }, null>;
6
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
7
+ }, {
8
+ jsonrpc: import("superstruct").Struct<"2.0", "2.0">;
9
+ id: import("superstruct").Struct<string | number | null, null>;
10
+ method: import("superstruct").Struct<string, null>;
11
+ params: import("superstruct").Struct<import("./superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
12
+ }>;
12
13
  /**
13
14
  * JSON-RPC request type.
14
15
  */
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonRpcRequestStruct = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  const superstruct_1 = require("superstruct");
6
- const Common = {
6
+ const superstruct_2 = require("./superstruct");
7
+ exports.JsonRpcRequestStruct = (0, superstruct_2.object)({
7
8
  jsonrpc: (0, superstruct_1.literal)('2.0'),
8
- id: (0, superstruct_1.nullable)((0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)()])),
9
+ id: (0, superstruct_1.union)([(0, superstruct_1.string)(), (0, superstruct_1.number)(), (0, superstruct_1.literal)(null)]),
9
10
  method: (0, superstruct_1.string)(),
10
- };
11
- const Params = {
12
- params: (0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)]),
13
- };
14
- exports.JsonRpcRequestStruct = (0, superstruct_1.union)([
15
- (0, superstruct_1.object)({ ...Common }),
16
- (0, superstruct_1.object)({ ...Common, ...Params }),
17
- ]);
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
+ });
18
13
  //# sourceMappingURL=JsonRpcRequest.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,6CAUqB;AAErB,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IACvB,EAAE,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,CAAC,IAAA,oBAAM,GAAE,EAAE,IAAA,oBAAM,GAAE,CAAC,CAAC,CAAC;IACzC,MAAM,EAAE,IAAA,oBAAM,GAAE;CACjB,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,MAAM,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC;CACjE,CAAC;AAEW,QAAA,oBAAoB,GAAG,IAAA,mBAAK,EAAC;IACxC,IAAA,oBAAM,EAAC,EAAE,GAAG,MAAM,EAAE,CAAC;IACrB,IAAA,oBAAM,EAAC,EAAE,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC;CACjC,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport {\n type Infer,\n array,\n literal,\n nullable,\n number,\n object,\n record,\n string,\n union,\n} from 'superstruct';\n\nconst Common = {\n jsonrpc: literal('2.0'),\n id: nullable(union([string(), number()])),\n method: string(),\n};\n\nconst Params = {\n params: union([array(JsonStruct), record(string(), JsonStruct)]),\n};\n\nexport const JsonRpcRequestStruct = union([\n object({ ...Common }),\n object({ ...Common, ...Params }),\n]);\n\n/**\n * JSON-RPC request type.\n */\nexport type JsonRpcRequest = Infer<typeof JsonRpcRequestStruct>;\n"]}
1
+ {"version":3,"file":"JsonRpcRequest.js","sourceRoot":"","sources":["../src/JsonRpcRequest.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA4E;AAE5E,+CAAsD;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 { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, literal, number, record, string, union } from 'superstruct';\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"]}
@@ -16,6 +16,7 @@ exports.KeyringClient = void 0;
16
16
  const superstruct_1 = require("superstruct");
17
17
  const uuid_1 = require("uuid");
18
18
  const api_1 = require("./internal/api");
19
+ const rpc_handler_1 = require("./rpc-handler");
19
20
  const utils_1 = require("./utils");
20
21
  class KeyringClient {
21
22
  /**
@@ -30,71 +31,71 @@ class KeyringClient {
30
31
  }
31
32
  async listAccounts() {
32
33
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
33
- method: 'keyring_listAccounts',
34
+ method: rpc_handler_1.KeyringRpcMethod.ListAccounts,
34
35
  }), api_1.ListAccountsResponseStruct);
35
36
  }
36
37
  async getAccount(id) {
37
38
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
38
- method: 'keyring_getAccount',
39
+ method: rpc_handler_1.KeyringRpcMethod.GetAccount,
39
40
  params: { id },
40
41
  }), api_1.GetAccountResponseStruct);
41
42
  }
42
43
  async createAccount(options = {}) {
43
44
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
44
- method: 'keyring_createAccount',
45
+ method: rpc_handler_1.KeyringRpcMethod.CreateAccount,
45
46
  params: { options },
46
47
  }), api_1.CreateAccountResponseStruct);
47
48
  }
48
49
  async filterAccountChains(id, chains) {
49
50
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
50
- method: 'keyring_filterAccountChains',
51
+ method: rpc_handler_1.KeyringRpcMethod.FilterAccountChains,
51
52
  params: { id, chains },
52
53
  }), api_1.FilterAccountChainsResponseStruct);
53
54
  }
54
55
  async updateAccount(account) {
55
56
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
56
- method: 'keyring_updateAccount',
57
+ method: rpc_handler_1.KeyringRpcMethod.UpdateAccount,
57
58
  params: { account },
58
59
  }), api_1.UpdateAccountResponseStruct);
59
60
  }
60
61
  async deleteAccount(id) {
61
62
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
62
- method: 'keyring_deleteAccount',
63
+ method: rpc_handler_1.KeyringRpcMethod.DeleteAccount,
63
64
  params: { id },
64
65
  }), api_1.DeleteAccountResponseStruct);
65
66
  }
66
67
  async exportAccount(id) {
67
68
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
68
- method: 'keyring_exportAccount',
69
+ method: rpc_handler_1.KeyringRpcMethod.ExportAccount,
69
70
  params: { id },
70
71
  }), api_1.ExportAccountResponseStruct);
71
72
  }
72
73
  async listRequests() {
73
74
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
74
- method: 'keyring_listRequests',
75
+ method: rpc_handler_1.KeyringRpcMethod.ListRequests,
75
76
  }), api_1.ListRequestsResponseStruct);
76
77
  }
77
78
  async getRequest(id) {
78
79
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
79
- method: 'keyring_getRequest',
80
+ method: rpc_handler_1.KeyringRpcMethod.GetRequest,
80
81
  params: { id },
81
82
  }), api_1.GetRequestResponseStruct);
82
83
  }
83
84
  async submitRequest(request) {
84
85
  return (0, utils_1.strictMask)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
85
- method: 'keyring_submitRequest',
86
+ method: rpc_handler_1.KeyringRpcMethod.SubmitRequest,
86
87
  params: request,
87
88
  }), api_1.SubmitRequestResponseStruct);
88
89
  }
89
90
  async approveRequest(id, data = {}) {
90
91
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
91
- method: 'keyring_approveRequest',
92
+ method: rpc_handler_1.KeyringRpcMethod.ApproveRequest,
92
93
  params: { id, data },
93
94
  }), api_1.ApproveRequestResponseStruct);
94
95
  }
95
96
  async rejectRequest(id) {
96
97
  (0, superstruct_1.assert)(await __classPrivateFieldGet(this, _KeyringClient_instances, "m", _KeyringClient_send).call(this, {
97
- method: 'keyring_rejectRequest',
98
+ method: rpc_handler_1.KeyringRpcMethod.RejectRequest,
98
99
  params: { id },
99
100
  }), api_1.RejectRequestResponseStruct);
100
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringClient.js","sourceRoot":"","sources":["../src/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAqC;AACrC,+BAAkC;AASlC,wCAawB;AAExB,mCAAqD;AAMrD,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAkBD,KAAK,CAAC,YAAY;QAChB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,sBAAsB;SAC/B,CAAC,EACF,gCAA0B,CAC3B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,kBAAU,EACf,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,oBAAoB;YAC5B,MAAM,EAAE,EAAE,EAAE,EAAE;SACf,CAAC,EACF,8BAAwB,CACzB,CAAC;IACJ,CAAC;IAED,KAA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struct';\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 type { JsonRpcRequest } from './JsonRpcRequest';\nimport { type OmitUnion, 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(\n partial: OmitUnion<JsonRpcRequest, 'jsonrpc' | 'id'>,\n ): 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: 'keyring_listAccounts',\n }),\n ListAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.#send({\n method: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_exportAccount',\n params: { id },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async listRequests(): Promise<KeyringRequest[]> {\n return strictMask(\n await this.#send({\n method: 'keyring_listRequests',\n }),\n ListRequestsResponseStruct,\n );\n }\n\n async getRequest(id: string): Promise<KeyringRequest> {\n return strictMask(\n await this.#send({\n method: 'keyring_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: 'keyring_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: 'keyring_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: 'keyring_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;AAExB,+CAAiD;AACjD,mCAAqC;AAMrC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;;QAP1B,wCAAgB;QAQd,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAgBD,KAAK,CAAC,YAAY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CAC7B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,IAAA,oBAAM,EACJ,MAAM,uBAAA,IAAI,qDAAM,MAAV,IAAI,EAAO;YACf,MAAM,EAAE,8BAAgB,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 type { JsonRpcRequest } from './JsonRpcRequest';\nimport { KeyringRpcMethod } from './rpc-handler';\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,7 +1,8 @@
1
1
  import type { MetaMaskInpageProvider } from '@metamask/providers';
2
2
  import type { Json } from '@metamask/utils';
3
3
  import type { JsonRpcRequest } from './JsonRpcRequest';
4
- import { KeyringClient, type Sender } from './KeyringClient';
4
+ import type { Sender } from './KeyringClient';
5
+ import { KeyringClient } from './KeyringClient';
5
6
  /**
6
7
  * Implementation of the `Sender` interface that can be used to send requests
7
8
  * to a snap through the snap JSON-RPC API.
@@ -1 +1 @@
1
- {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAIA,mDAA6D;AAE7D;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAV5D,wCAAgB;QAEhB,0CAAkC;QAShC,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,mBAAmB;YAC3B,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 { KeyringClient, type Sender } 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 #origin: string;\n\n #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_invokeSnap',\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"]}
1
+ {"version":3,"file":"KeyringSnapRpcClient.js","sourceRoot":"","sources":["../src/KeyringSnapRpcClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,mDAAgD;AAEhD;;;GAGG;AACH,MAAa,aAAa;IAKxB;;;;;OAKG;IACH,YAAY,MAAc,EAAE,QAAgC;QAV5D,wCAAgB;QAEhB,0CAAkC;QAShC,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,mBAAmB;YAC3B,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 #origin: string;\n\n #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_invokeSnap',\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"]}
package/dist/api.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type Json } from '@metamask/utils';
2
- import { type Infer } from 'superstruct';
1
+ import type { Json } from '@metamask/utils';
2
+ import type { Infer } from 'superstruct';
3
3
  /**
4
4
  * Supported Ethereum methods.
5
5
  */
@@ -20,11 +20,11 @@ export declare enum EthAccountType {
20
20
  Eip4337 = "eip155:eip4337"
21
21
  }
22
22
  export declare const KeyringAccountStruct: import("superstruct").Struct<{
23
+ type: "eip155:eoa" | "eip155:eip4337";
23
24
  id: string;
24
25
  address: string;
25
26
  options: Record<string, Json>;
26
27
  methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
27
- type: "eip155:eoa" | "eip155:eip4337";
28
28
  }, {
29
29
  /**
30
30
  * Account ID (UUIDv4).
@@ -65,42 +65,36 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
65
65
  */
66
66
  export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
67
67
  export declare const KeyringRequestStruct: import("superstruct").Struct<{
68
- account: string;
68
+ id: string;
69
69
  scope: string;
70
+ account: string;
70
71
  request: {
71
- jsonrpc: "2.0";
72
- id: string | number | null;
73
72
  method: string;
74
- } | {
75
- jsonrpc: "2.0";
76
- id: string | number | null;
77
- method: string;
78
- params: Json[] | Record<string, Json>;
73
+ params?: Json[] | Record<string, Json>;
79
74
  };
80
75
  }, {
81
76
  /**
82
- * Account ID (UUIDv4).
77
+ * Keyring request ID (UUIDv4).
83
78
  */
84
- account: import("superstruct").Struct<string, null>;
79
+ id: import("superstruct").Struct<string, null>;
85
80
  /**
86
81
  * Request's scope (CAIP-2 chain ID).
87
82
  */
88
83
  scope: import("superstruct").Struct<string, null>;
89
84
  /**
90
- * JSON-RPC request sent by the client application.
91
- *
92
- * Note: The request ID must be a string.
85
+ * Account ID (UUIDv4).
86
+ */
87
+ account: import("superstruct").Struct<string, null>;
88
+ /**
89
+ * Inner request sent by the client application.
93
90
  */
94
91
  request: import("superstruct").Struct<{
95
- jsonrpc: "2.0";
96
- id: string | number | null;
97
- method: string;
98
- } | {
99
- jsonrpc: "2.0";
100
- id: string | number | null;
101
92
  method: string;
102
- params: Json[] | Record<string, Json>;
103
- }, null>;
93
+ params?: Json[] | Record<string, Json>;
94
+ }, {
95
+ method: import("superstruct").Struct<string, null>;
96
+ params: import("superstruct").Struct<import("./superstruct").ExactOptionalTag | Json[] | Record<string, Json>, null>;
97
+ }>;
104
98
  }>;
105
99
  /**
106
100
  * Keyring request.
@@ -117,7 +111,10 @@ export declare const KeyringAccountDataStruct: import("superstruct").Struct<Reco
117
111
  export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
118
112
  export declare const KeyringResponseStruct: import("superstruct").Struct<{
119
113
  pending: true;
120
- redirect: string | null;
114
+ redirect?: {
115
+ message?: string;
116
+ url?: string;
117
+ };
121
118
  } | {
122
119
  pending: false;
123
120
  result: Json;
@@ -129,10 +126,10 @@ export declare const KeyringResponseStruct: import("superstruct").Struct<{
129
126
  * request will be handled asynchronously. Otherwise, the response must contain
130
127
  * the result of the request and `pending: false`.
131
128
  *
132
- * In the asynchronous case, the keyring can return a redirect URL to be shown
133
- * to the user. The user can choose to follow the link or cancel the request.
134
- * The main use case for this is to redirect the user to a third-party service
135
- * to approve the request.
129
+ * In the asynchronous case, the keyring can return a redirect URL and message
130
+ * to be shown to the user. The user can choose to follow the link or cancel
131
+ * the request. The main use case for this is to redirect the user to the snap
132
+ * dapp to review the request.
136
133
  */
137
134
  export declare type KeyringResponse = Infer<typeof KeyringResponseStruct>;
138
135
  /**
package/dist/api.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.EthAccountType = exports.EthMethod = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  const superstruct_1 = require("superstruct");
6
- const JsonRpcRequest_1 = require("./JsonRpcRequest");
6
+ const superstruct_2 = require("./superstruct");
7
7
  const utils_2 = require("./utils");
8
8
  /**
9
9
  * Supported Ethereum methods.
@@ -26,7 +26,7 @@ var EthAccountType;
26
26
  EthAccountType["Eoa"] = "eip155:eoa";
27
27
  EthAccountType["Eip4337"] = "eip155:eip4337";
28
28
  })(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
29
- exports.KeyringAccountStruct = (0, superstruct_1.object)({
29
+ exports.KeyringAccountStruct = (0, superstruct_2.object)({
30
30
  /**
31
31
  * Account ID (UUIDv4).
32
32
  */
@@ -56,25 +56,30 @@ exports.KeyringAccountStruct = (0, superstruct_1.object)({
56
56
  */
57
57
  type: (0, superstruct_1.enums)([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),
58
58
  });
59
- exports.KeyringRequestStruct = (0, superstruct_1.object)({
59
+ exports.KeyringRequestStruct = (0, superstruct_2.object)({
60
60
  /**
61
- * Account ID (UUIDv4).
61
+ * Keyring request ID (UUIDv4).
62
62
  */
63
- account: utils_2.UuidStruct,
63
+ id: utils_2.UuidStruct,
64
64
  /**
65
65
  * Request's scope (CAIP-2 chain ID).
66
66
  */
67
67
  scope: (0, superstruct_1.string)(),
68
68
  /**
69
- * JSON-RPC request sent by the client application.
70
- *
71
- * Note: The request ID must be a string.
69
+ * Account ID (UUIDv4).
70
+ */
71
+ account: utils_2.UuidStruct,
72
+ /**
73
+ * Inner request sent by the client application.
72
74
  */
73
- request: JsonRpcRequest_1.JsonRpcRequestStruct,
75
+ request: (0, superstruct_2.object)({
76
+ method: (0, superstruct_1.string)(),
77
+ 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)])),
78
+ }),
74
79
  });
75
80
  exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
76
81
  exports.KeyringResponseStruct = (0, superstruct_1.union)([
77
- (0, superstruct_1.object)({
82
+ (0, superstruct_2.object)({
78
83
  /**
79
84
  * Pending flag.
80
85
  *
@@ -90,9 +95,12 @@ exports.KeyringResponseStruct = (0, superstruct_1.union)([
90
95
  * with a link to the redirect URL. The user can choose to follow the link
91
96
  * or cancel the request.
92
97
  */
93
- redirect: (0, superstruct_1.nullable)((0, superstruct_1.string)()),
98
+ redirect: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
99
+ message: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
100
+ url: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
101
+ })),
94
102
  }),
95
- (0, superstruct_1.object)({
103
+ (0, superstruct_2.object)({
96
104
  /**
97
105
  * Pending flag.
98
106
  *
package/dist/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,6CAUqB;AAErB,qDAAwD;AACxD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAA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,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;KAC7B,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { type Json, JsonStruct } from '@metamask/utils';\nimport {\n type Infer,\n array,\n enums,\n literal,\n object,\n record,\n string,\n union,\n nullable,\n} from 'superstruct';\n\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedData = 'eth_signTypedData',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedData}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\n\nexport const KeyringRequestStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * JSON-RPC request sent by the client application.\n *\n * Note: The request ID must be a string.\n */\n request: JsonRpcRequestStruct,\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\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\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: nullable(string()),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL to be shown\n * to the user. The user can choose to follow the link or cancel the request.\n * The main use case for this is to redirect the user to a third-party service\n * to approve the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\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 * 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"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AACA,2CAA6C;AAE7C,6CAA2E;AAE3E,+CAAsD;AACtD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB;AAED;;GAEG;AACH,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,oCAAkB,CAAA;IAClB,4CAA0B,CAAA;AAC5B,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAEY,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;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,EACZ,IAAA,mBAAK,EAAC;QACJ,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AAE,CAAC;YAChC,GAAG,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;SAC7B,CAAC,CACH;KACF,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, enums, literal, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from './superstruct';\nimport { UuidStruct } from './utils';\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedData = 'eth_signTypedData',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Eip4337 = 'eip155:eip4337',\n}\n\nexport const KeyringAccountStruct = object({\n /**\n * Account ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Account address or next receive address (UTXO).\n */\n address: string(),\n\n /**\n * Keyring-dependent account options.\n */\n options: record(string(), JsonStruct),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedData}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n\n /**\n * Account type.\n */\n type: enums([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),\n});\n\n/**\n * Account object.\n *\n * Represents an account with its properties and capabilities.\n */\nexport type KeyringAccount = Infer<typeof KeyringAccountStruct>;\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\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\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\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 * 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"]}
package/dist/index.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from './rpc-handler';
4
4
  export * from './KeyringSnapControllerClient';
5
5
  export * from './KeyringSnapRpcClient';
6
6
  export * from './internal';
7
+ export * from './snap-utils';
8
+ export * from './superstruct';
package/dist/index.js CHANGED
@@ -20,4 +20,6 @@ __exportStar(require("./rpc-handler"), exports);
20
20
  __exportStar(require("./KeyringSnapControllerClient"), exports);
21
21
  __exportStar(require("./KeyringSnapRpcClient"), exports);
22
22
  __exportStar(require("./internal"), exports);
23
+ __exportStar(require("./snap-utils"), exports);
24
+ __exportStar(require("./superstruct"), exports);
23
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,gEAA8C;AAC9C,yDAAuC;AACvC,6CAA2B","sourcesContent":["export * from './api';\nexport * from './KeyringClient';\nexport * from './rpc-handler';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './internal';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,gEAA8C;AAC9C,yDAAuC;AACvC,6CAA2B;AAC3B,+CAA6B;AAC7B,gDAA8B","sourcesContent":["export * from './api';\nexport * from './KeyringClient';\nexport * from './rpc-handler';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './internal';\nexport * from './snap-utils';\nexport * from './superstruct';\n"]}