@metamask/keyring-api 8.0.0 → 8.0.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 (50) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/JsonRpcRequest.d.ts +6 -6
  3. package/dist/JsonRpcRequest.js +1 -1
  4. package/dist/JsonRpcRequest.js.map +1 -1
  5. package/dist/KeyringClient.js +1 -1
  6. package/dist/KeyringClient.js.map +1 -1
  7. package/dist/api/account.d.ts +7 -7
  8. package/dist/api/account.js +1 -1
  9. package/dist/api/account.js.map +1 -1
  10. package/dist/api/balance.d.ts +4 -4
  11. package/dist/api/balance.js +1 -1
  12. package/dist/api/balance.js.map +1 -1
  13. package/dist/api/caip.d.ts +3 -3
  14. package/dist/api/caip.js +1 -1
  15. package/dist/api/caip.js.map +1 -1
  16. package/dist/api/export.d.ts +2 -2
  17. package/dist/api/export.js +1 -1
  18. package/dist/api/export.js.map +1 -1
  19. package/dist/api/request.d.ts +8 -8
  20. package/dist/api/request.js +1 -1
  21. package/dist/api/request.js.map +1 -1
  22. package/dist/api/response.d.ts +2 -2
  23. package/dist/api/response.js +1 -1
  24. package/dist/api/response.js.map +1 -1
  25. package/dist/btc/types.d.ts +8 -8
  26. package/dist/btc/types.js +1 -1
  27. package/dist/btc/types.js.map +1 -1
  28. package/dist/eth/erc4337/types.d.ts +33 -33
  29. package/dist/eth/erc4337/types.js.map +1 -1
  30. package/dist/eth/types.d.ts +16 -16
  31. package/dist/eth/types.js +1 -1
  32. package/dist/eth/types.js.map +1 -1
  33. package/dist/internal/api.d.ts +130 -130
  34. package/dist/internal/api.js +1 -1
  35. package/dist/internal/api.js.map +1 -1
  36. package/dist/internal/events.d.ts +33 -33
  37. package/dist/internal/events.js +1 -1
  38. package/dist/internal/events.js.map +1 -1
  39. package/dist/internal/types.d.ts +1 -1
  40. package/dist/internal/types.js +1 -1
  41. package/dist/internal/types.js.map +1 -1
  42. package/dist/rpc-handler.js +1 -1
  43. package/dist/rpc-handler.js.map +1 -1
  44. package/dist/superstruct.d.ts +2 -3
  45. package/dist/superstruct.js +1 -1
  46. package/dist/superstruct.js.map +1 -1
  47. package/dist/utils/types.d.ts +4 -4
  48. package/dist/utils/types.js +1 -1
  49. package/dist/utils/types.js.map +1 -1
  50. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
1
+ export declare const AccountCreatedEventStruct: import("@metamask/superstruct").Struct<{
2
2
  method: "notify:accountCreated";
3
3
  params: {
4
4
  account: {
@@ -12,8 +12,8 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
12
12
  displayConfirmation?: boolean;
13
13
  };
14
14
  }, {
15
- method: import("superstruct").Struct<"notify:accountCreated", "notify:accountCreated">;
16
- params: import("superstruct").Struct<{
15
+ method: import("@metamask/superstruct").Struct<"notify:accountCreated", "notify:accountCreated">;
16
+ params: import("@metamask/superstruct").Struct<{
17
17
  account: {
18
18
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
19
19
  id: string;
@@ -27,22 +27,22 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
27
27
  /**
28
28
  * New account object.
29
29
  */
30
- account: import("superstruct").Struct<{
30
+ account: import("@metamask/superstruct").Struct<{
31
31
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
32
32
  id: string;
33
33
  address: string;
34
34
  options: Record<string, import("@metamask/utils").Json>;
35
35
  methods: string[];
36
36
  }, {
37
- id: import("superstruct").Struct<string, null>;
38
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
37
+ id: import("@metamask/superstruct").Struct<string, null>;
38
+ type: import("@metamask/superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
39
39
  "eip155:eoa": "eip155:eoa";
40
40
  "eip155:erc4337": "eip155:erc4337";
41
41
  "bip122:p2wpkh": "bip122:p2wpkh";
42
42
  }>;
43
- address: import("superstruct").Struct<string, null>;
44
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
45
- methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
43
+ address: import("@metamask/superstruct").Struct<string, null>;
44
+ options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
45
+ methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
46
46
  }>;
47
47
  /**
48
48
  * Account name suggestion provided to the MetaMask client.
@@ -51,15 +51,15 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
51
51
  * client to decide whether to use it. The keyring won't be informed if the
52
52
  * client decides to use a different name.
53
53
  */
54
- accountNameSuggestion: import("superstruct").Struct<string | import("../superstruct").ExactOptionalTag, null>;
54
+ accountNameSuggestion: import("@metamask/superstruct").Struct<string | import("../superstruct").ExactOptionalTag, null>;
55
55
  /**
56
56
  * Instructs MetaMask to display the add account confirmation dialog in the UI.
57
57
  * **Note:** This is not guaranteed to be honored by the MetaMask client.
58
58
  */
59
- displayConfirmation: import("superstruct").Struct<boolean | import("../superstruct").ExactOptionalTag, null>;
59
+ displayConfirmation: import("@metamask/superstruct").Struct<boolean | import("../superstruct").ExactOptionalTag, null>;
60
60
  }>;
61
61
  }>;
62
- export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
62
+ export declare const AccountUpdatedEventStruct: import("@metamask/superstruct").Struct<{
63
63
  method: "notify:accountUpdated";
64
64
  params: {
65
65
  account: {
@@ -71,8 +71,8 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
71
71
  };
72
72
  };
73
73
  }, {
74
- method: import("superstruct").Struct<"notify:accountUpdated", "notify:accountUpdated">;
75
- params: import("superstruct").Struct<{
74
+ method: import("@metamask/superstruct").Struct<"notify:accountUpdated", "notify:accountUpdated">;
75
+ params: import("@metamask/superstruct").Struct<{
76
76
  account: {
77
77
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
78
78
  id: string;
@@ -84,76 +84,76 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
84
84
  /**
85
85
  * Updated account object.
86
86
  */
87
- account: import("superstruct").Struct<{
87
+ account: import("@metamask/superstruct").Struct<{
88
88
  type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
89
89
  id: string;
90
90
  address: string;
91
91
  options: Record<string, import("@metamask/utils").Json>;
92
92
  methods: string[];
93
93
  }, {
94
- id: import("superstruct").Struct<string, null>;
95
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
94
+ id: import("@metamask/superstruct").Struct<string, null>;
95
+ type: import("@metamask/superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
96
96
  "eip155:eoa": "eip155:eoa";
97
97
  "eip155:erc4337": "eip155:erc4337";
98
98
  "bip122:p2wpkh": "bip122:p2wpkh";
99
99
  }>;
100
- address: import("superstruct").Struct<string, null>;
101
- options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
102
- methods: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
100
+ address: import("@metamask/superstruct").Struct<string, null>;
101
+ options: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
102
+ methods: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
103
103
  }>;
104
104
  }>;
105
105
  }>;
106
- export declare const AccountDeletedEventStruct: import("superstruct").Struct<{
106
+ export declare const AccountDeletedEventStruct: import("@metamask/superstruct").Struct<{
107
107
  method: "notify:accountDeleted";
108
108
  params: {
109
109
  id: string;
110
110
  };
111
111
  }, {
112
- method: import("superstruct").Struct<"notify:accountDeleted", "notify:accountDeleted">;
113
- params: import("superstruct").Struct<{
112
+ method: import("@metamask/superstruct").Struct<"notify:accountDeleted", "notify:accountDeleted">;
113
+ params: import("@metamask/superstruct").Struct<{
114
114
  id: string;
115
115
  }, {
116
116
  /**
117
117
  * Deleted account ID.
118
118
  */
119
- id: import("superstruct").Struct<string, null>;
119
+ id: import("@metamask/superstruct").Struct<string, null>;
120
120
  }>;
121
121
  }>;
122
- export declare const RequestApprovedEventStruct: import("superstruct").Struct<{
122
+ export declare const RequestApprovedEventStruct: import("@metamask/superstruct").Struct<{
123
123
  method: "notify:requestApproved";
124
124
  params: {
125
125
  id: string;
126
126
  result: import("@metamask/utils").Json;
127
127
  };
128
128
  }, {
129
- method: import("superstruct").Struct<"notify:requestApproved", "notify:requestApproved">;
130
- params: import("superstruct").Struct<{
129
+ method: import("@metamask/superstruct").Struct<"notify:requestApproved", "notify:requestApproved">;
130
+ params: import("@metamask/superstruct").Struct<{
131
131
  id: string;
132
132
  result: import("@metamask/utils").Json;
133
133
  }, {
134
134
  /**
135
135
  * Request ID.
136
136
  */
137
- id: import("superstruct").Struct<string, null>;
137
+ id: import("@metamask/superstruct").Struct<string, null>;
138
138
  /**
139
139
  * Request result.
140
140
  */
141
- result: import("superstruct").Struct<import("@metamask/utils").Json, unknown>;
141
+ result: import("@metamask/superstruct").Struct<import("@metamask/utils").Json, unknown>;
142
142
  }>;
143
143
  }>;
144
- export declare const RequestRejectedEventStruct: import("superstruct").Struct<{
144
+ export declare const RequestRejectedEventStruct: import("@metamask/superstruct").Struct<{
145
145
  method: "notify:requestRejected";
146
146
  params: {
147
147
  id: string;
148
148
  };
149
149
  }, {
150
- method: import("superstruct").Struct<"notify:requestRejected", "notify:requestRejected">;
151
- params: import("superstruct").Struct<{
150
+ method: import("@metamask/superstruct").Struct<"notify:requestRejected", "notify:requestRejected">;
151
+ params: import("@metamask/superstruct").Struct<{
152
152
  id: string;
153
153
  }, {
154
154
  /**
155
155
  * Request ID.
156
156
  */
157
- id: import("superstruct").Struct<string, null>;
157
+ id: import("@metamask/superstruct").Struct<string, null>;
158
158
  }>;
159
159
  }>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RequestRejectedEventStruct = exports.RequestApprovedEventStruct = exports.AccountDeletedEventStruct = exports.AccountUpdatedEventStruct = exports.AccountCreatedEventStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
4
5
  const utils_1 = require("@metamask/utils");
5
- const superstruct_1 = require("superstruct");
6
6
  const api_1 = require("../api");
7
7
  const events_1 = require("../events");
8
8
  const superstruct_2 = require("../superstruct");
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/internal/events.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,6CAAuD;AAEvD,gCAA8C;AAC9C,sCAAyC;AACzC,gDAAuD;AACvD,oCAAsC;AAEzB,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,OAAO,EAAE,0BAAoB;QAE7B;;;;;;WAMG;QACH,qBAAqB,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QAE9C;;;WAGG;QACH,mBAAmB,EAAE,IAAA,2BAAa,EAAC,IAAA,qBAAO,GAAE,CAAC;KAC9C,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,OAAO,EAAE,0BAAoB;KAC9B,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,EAAE,EAAE,kBAAU;KACf,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,eAAe,EAAE,CAAC;IAClD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,EAAE,EAAE,kBAAU;QAEd;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,eAAe,EAAE,CAAC;IAClD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,EAAE,EAAE,kBAAU;KACf,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport { boolean, literal, string } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\nimport { KeyringEvent } from '../events';\nimport { exactOptional, object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\nexport const AccountCreatedEventStruct = object({\n method: literal(`${KeyringEvent.AccountCreated}`),\n params: object({\n /**\n * New account object.\n */\n account: KeyringAccountStruct,\n\n /**\n * Account name suggestion provided to the MetaMask client.\n *\n * The keyring can suggest a name for the account, but it's up to the\n * client to decide whether to use it. The keyring won't be informed if the\n * client decides to use a different name.\n */\n accountNameSuggestion: exactOptional(string()),\n\n /**\n * Instructs MetaMask to display the add account confirmation dialog in the UI.\n * **Note:** This is not guaranteed to be honored by the MetaMask client.\n */\n displayConfirmation: exactOptional(boolean()),\n }),\n});\n\nexport const AccountUpdatedEventStruct = object({\n method: literal(`${KeyringEvent.AccountUpdated}`),\n params: object({\n /**\n * Updated account object.\n */\n account: KeyringAccountStruct,\n }),\n});\n\nexport const AccountDeletedEventStruct = object({\n method: literal(`${KeyringEvent.AccountDeleted}`),\n params: object({\n /**\n * Deleted account ID.\n */\n id: UuidStruct,\n }),\n});\n\nexport const RequestApprovedEventStruct = object({\n method: literal(`${KeyringEvent.RequestApproved}`),\n params: object({\n /**\n * Request ID.\n */\n id: UuidStruct,\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n});\n\nexport const RequestRejectedEventStruct = object({\n method: literal(`${KeyringEvent.RequestRejected}`),\n params: object({\n /**\n * Request ID.\n */\n id: UuidStruct,\n }),\n});\n"]}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/internal/events.ts"],"names":[],"mappings":";;;AAAA,uDAAiE;AACjE,2CAA6C;AAE7C,gCAA8C;AAC9C,sCAAyC;AACzC,gDAAuD;AACvD,oCAAsC;AAEzB,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,OAAO,EAAE,0BAAoB;QAE7B;;;;;;WAMG;QACH,qBAAqB,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QAE9C;;;WAGG;QACH,mBAAmB,EAAE,IAAA,2BAAa,EAAC,IAAA,qBAAO,GAAE,CAAC;KAC9C,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,OAAO,EAAE,0BAAoB;KAC9B,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,yBAAyB,GAAG,IAAA,oBAAM,EAAC;IAC9C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,cAAc,EAAE,CAAC;IACjD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,EAAE,EAAE,kBAAU;KACf,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,eAAe,EAAE,CAAC;IAClD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,EAAE,EAAE,kBAAU;QAEd;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC;AAEU,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,MAAM,EAAE,IAAA,qBAAO,EAAC,GAAG,qBAAY,CAAC,eAAe,EAAE,CAAC;IAClD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb;;WAEG;QACH,EAAE,EAAE,kBAAU;KACf,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { boolean, literal, string } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { KeyringAccountStruct } from '../api';\nimport { KeyringEvent } from '../events';\nimport { exactOptional, object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\nexport const AccountCreatedEventStruct = object({\n method: literal(`${KeyringEvent.AccountCreated}`),\n params: object({\n /**\n * New account object.\n */\n account: KeyringAccountStruct,\n\n /**\n * Account name suggestion provided to the MetaMask client.\n *\n * The keyring can suggest a name for the account, but it's up to the\n * client to decide whether to use it. The keyring won't be informed if the\n * client decides to use a different name.\n */\n accountNameSuggestion: exactOptional(string()),\n\n /**\n * Instructs MetaMask to display the add account confirmation dialog in the UI.\n * **Note:** This is not guaranteed to be honored by the MetaMask client.\n */\n displayConfirmation: exactOptional(boolean()),\n }),\n});\n\nexport const AccountUpdatedEventStruct = object({\n method: literal(`${KeyringEvent.AccountUpdated}`),\n params: object({\n /**\n * Updated account object.\n */\n account: KeyringAccountStruct,\n }),\n});\n\nexport const AccountDeletedEventStruct = object({\n method: literal(`${KeyringEvent.AccountDeleted}`),\n params: object({\n /**\n * Deleted account ID.\n */\n id: UuidStruct,\n }),\n});\n\nexport const RequestApprovedEventStruct = object({\n method: literal(`${KeyringEvent.RequestApproved}`),\n params: object({\n /**\n * Request ID.\n */\n id: UuidStruct,\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n});\n\nexport const RequestRejectedEventStruct = object({\n method: literal(`${KeyringEvent.RequestRejected}`),\n params: object({\n /**\n * Request ID.\n */\n id: UuidStruct,\n }),\n});\n"]}
@@ -1,4 +1,4 @@
1
- import type { Infer, Struct } from 'superstruct';
1
+ import type { Infer, Struct } from '@metamask/superstruct';
2
2
  import { BtcAccountType, EthAccountType } from '../api';
3
3
  export declare type InternalAccountType = EthAccountType | BtcAccountType;
4
4
  export declare const InternalAccountMetadataStruct: Struct<{
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.InternalAccountStruct = exports.InternalAccountStructs = exports.InternalBtcP2wpkhAccountStruct = exports.InternalEthErc4337AccountStruct = exports.InternalEthEoaAccountStruct = exports.InternalAccountMetadataStruct = void 0;
4
- const superstruct_1 = require("superstruct");
4
+ const superstruct_1 = require("@metamask/superstruct");
5
5
  const api_1 = require("../api");
6
6
  const types_1 = require("../btc/types");
7
7
  const types_2 = require("../eth/types");
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAAsD;AAEtD,gCAA8E;AAC9E,wCAAsD;AACtD,wCAA4E;AAC5E,gDAAuD;AAI1C,QAAA,6BAA6B,GAAG,IAAA,oBAAM,EAAC;IAClD,QAAQ,EAAE,IAAA,oBAAM,EAAC;QACf,IAAI,EAAE,IAAA,oBAAM,GAAE;QACd,IAAI,EAAE,IAAA,2BAAa,EACjB,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,oBAAM,GAAE;YACZ,OAAO,EAAE,IAAA,qBAAO,GAAE;YAClB,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC,CACH;QACD,YAAY,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;QACrC,UAAU,EAAE,IAAA,oBAAM,GAAE;QACpB,OAAO,EAAE,IAAA,oBAAM,EAAC;YACd,IAAI,EAAE,IAAA,oBAAM,GAAE;SACf,CAAC;KACH,CAAC;CACH,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAS,uBAAuB,CAC9B,aAA6C;IAE7C,OAAO,IAAA,oBAAM,EAAC;QACZ,GAAG,aAAa,CAAC,MAAM;QACvB,GAAG,qCAA6B,CAAC,MAAM;KACxC,CAAC,CAAC;AACL,CAAC;AAEY,QAAA,2BAA2B,GACtC,uBAAuB,CAAC,2BAAmB,CAAC,CAAC;AAElC,QAAA,+BAA+B,GAAG,uBAAuB,CACpE,+BAAuB,CACxB,CAAC;AAEW,QAAA,8BAA8B,GAAG,uBAAuB,CACnE,8BAAsB,CACvB,CAAC;AAYW,QAAA,sBAAsB,GAK/B;IACF,CAAC,GAAG,oBAAc,CAAC,GAAG,EAAE,CAAC,EAAE,mCAA2B;IACtD,CAAC,GAAG,oBAAc,CAAC,OAAO,EAAE,CAAC,EAAE,uCAA+B;IAC9D,CAAC,GAAG,oBAAc,CAAC,MAAM,EAAE,CAAC,EAAE,sCAA8B;CAC7D,CAAC;AAOW,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,GAAG,qCAA6B,CAAC,MAAM;CACxC,CAAC,CAAC","sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { boolean, string, number } from 'superstruct';\n\nimport { BtcAccountType, EthAccountType, KeyringAccountStruct } from '../api';\nimport { BtcP2wpkhAccountStruct } from '../btc/types';\nimport { EthEoaAccountStruct, EthErc4337AccountStruct } from '../eth/types';\nimport { exactOptional, object } from '../superstruct';\n\nexport type InternalAccountType = EthAccountType | BtcAccountType;\n\nexport const InternalAccountMetadataStruct = object({\n metadata: object({\n name: string(),\n snap: exactOptional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n lastSelected: exactOptional(number()),\n importTime: number(),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Creates an `InternalAccount` from an existing account `superstruct` object.\n *\n * @param accountStruct - An account `superstruct` object.\n * @returns The `InternalAccount` associated to `accountStruct`.\n */\nfunction asInternalAccountStruct<Account, AccountSchema>(\n accountStruct: Struct<Account, AccountSchema>,\n) {\n return object({\n ...accountStruct.schema,\n ...InternalAccountMetadataStruct.schema,\n });\n}\n\nexport const InternalEthEoaAccountStruct =\n asInternalAccountStruct(EthEoaAccountStruct);\n\nexport const InternalEthErc4337AccountStruct = asInternalAccountStruct(\n EthErc4337AccountStruct,\n);\n\nexport const InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(\n BtcP2wpkhAccountStruct,\n);\n\nexport type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;\n\nexport type InternalEthErc4337Account = Infer<\n typeof InternalEthErc4337AccountStruct\n>;\n\nexport type InternalBtcP2wpkhAccount = Infer<\n typeof InternalBtcP2wpkhAccountStruct\n>;\n\nexport const InternalAccountStructs: Record<\n string,\n | Struct<InternalEthEoaAccount>\n | Struct<InternalEthErc4337Account>\n | Struct<InternalBtcP2wpkhAccount>\n> = {\n [`${EthAccountType.Eoa}`]: InternalEthEoaAccountStruct,\n [`${EthAccountType.Erc4337}`]: InternalEthErc4337AccountStruct,\n [`${BtcAccountType.P2wpkh}`]: InternalBtcP2wpkhAccountStruct,\n};\n\nexport type InternalAccountTypes =\n | InternalEthEoaAccount\n | InternalEthErc4337Account\n | InternalBtcP2wpkhAccount;\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n ...InternalAccountMetadataStruct.schema,\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
1
+ {"version":3,"file":"types.js","s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AAA,qBAAqB,GAAG,IAAA,oBAAM,EAAC;IAC1C,GAAG,0BAAoB,CAAC,MAAM;IAC9B,GAAG,qCAA6B,CAAC,MAAM;CACxC,CAAC,CAAC","sourcesContent":["import type { Infer, Struct } from '@metamask/superstruct';\nimport { boolean, string, number } from '@metamask/superstruct';\n\nimport { BtcAccountType, EthAccountType, KeyringAccountStruct } from '../api';\nimport { BtcP2wpkhAccountStruct } from '../btc/types';\nimport { EthEoaAccountStruct, EthErc4337AccountStruct } from '../eth/types';\nimport { exactOptional, object } from '../superstruct';\n\nexport type InternalAccountType = EthAccountType | BtcAccountType;\n\nexport const InternalAccountMetadataStruct = object({\n metadata: object({\n name: string(),\n snap: exactOptional(\n object({\n id: string(),\n enabled: boolean(),\n name: string(),\n }),\n ),\n lastSelected: exactOptional(number()),\n importTime: number(),\n keyring: object({\n type: string(),\n }),\n }),\n});\n\n/**\n * Creates an `InternalAccount` from an existing account `superstruct` object.\n *\n * @param accountStruct - An account `superstruct` object.\n * @returns The `InternalAccount` associated to `accountStruct`.\n */\nfunction asInternalAccountStruct<Account, AccountSchema>(\n accountStruct: Struct<Account, AccountSchema>,\n) {\n return object({\n ...accountStruct.schema,\n ...InternalAccountMetadataStruct.schema,\n });\n}\n\nexport const InternalEthEoaAccountStruct =\n asInternalAccountStruct(EthEoaAccountStruct);\n\nexport const InternalEthErc4337AccountStruct = asInternalAccountStruct(\n EthErc4337AccountStruct,\n);\n\nexport const InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(\n BtcP2wpkhAccountStruct,\n);\n\nexport type InternalEthEoaAccount = Infer<typeof InternalEthEoaAccountStruct>;\n\nexport type InternalEthErc4337Account = Infer<\n typeof InternalEthErc4337AccountStruct\n>;\n\nexport type InternalBtcP2wpkhAccount = Infer<\n typeof InternalBtcP2wpkhAccountStruct\n>;\n\nexport const InternalAccountStructs: Record<\n string,\n | Struct<InternalEthEoaAccount>\n | Struct<InternalEthErc4337Account>\n | Struct<InternalBtcP2wpkhAccount>\n> = {\n [`${EthAccountType.Eoa}`]: InternalEthEoaAccountStruct,\n [`${EthAccountType.Erc4337}`]: InternalEthErc4337AccountStruct,\n [`${BtcAccountType.P2wpkh}`]: InternalBtcP2wpkhAccountStruct,\n};\n\nexport type InternalAccountTypes =\n | InternalEthEoaAccount\n | InternalEthErc4337Account\n | InternalBtcP2wpkhAccount;\n\nexport const InternalAccountStruct = object({\n ...KeyringAccountStruct.schema,\n ...InternalAccountMetadataStruct.schema,\n});\n\n/**\n * Internal account representation.\n *\n * This type is used internally by MetaMask to add additional metadata to the\n * account object. It's should not be used by external applications.\n */\nexport type InternalAccount = Infer<typeof InternalAccountStruct>;\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleKeyringRequest = exports.MethodNotSupportedError = void 0;
4
- const superstruct_1 = require("superstruct");
4
+ const superstruct_1 = require("@metamask/superstruct");
5
5
  const api_1 = require("./internal/api");
6
6
  const rpc_1 = require("./internal/rpc");
7
7
  const JsonRpcRequest_1 = require("./JsonRpcRequest");
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAcwB;AACxB,wCAAkD;AAElD,qDAAwD;AAExD;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,OAAgB,EAChB,OAAuB;IAEvB,6EAA6E;IAC7E,gCAAgC;IAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAoB,CAAC,CAAC;IAEtC,QAAQ,OAAO,CAAC,MAAM,EAAE;QACtB,KAAK,sBAAgB,CAAC,YAAY,CAAC,CAAC;YAClC,IAAA,oBAAM,EAA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,sBAAgB,CAAC,cAAc,CAAC,CAAC;YACpC,IAAI,OAAO,CAAC,cAAc,KAAK,SAAS,EAAE;gBACxC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,iCAA2B,CAAC,CAAC;YAC7C,OAAO,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACvE;QAED,KAAK,sBAAgB,CAAC,aAAa,CAAC,CAAC;YACnC,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE;gBACvC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAgB,EAChB,OAAuB;IAEvB,IAAI;QACF,OAAO,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAChD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YACzD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,8DAA8D,CAAC;QAErE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAdD,oDAcC","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assert } from 'superstruct';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.GetAccountBalances: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
1
+ {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAI/C,wCAcwB;AACxB,wCAAkD;AAElD,qDAAwD;AAExD;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,OAAgB,EAChB,OAAuB;IAEvB,6EAA6E;IAC7E,gCAAgC;IAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAoB,CAAC,CAAC;IAEtC,QAAQ,OAAO,CAAC,MAAM,EAAE;QACtB,KAAK,sBAAgB,CAAC,YAAY,CAAC,CAAC;YAClC,IAAA,oBAAM,EAAC,OAAO,EAAE,+BAAyB,CAAC,CAAC;YAC3C,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC;SAC/B;QAED,KAAK,sBAAgB,CAAC,UAAU,CAAC,CAAC;YAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,6BAAuB,CAAC,CAAC;YACzC,OAAO,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SAC9C;QAED,KAAK,sBAAgB,CAAC,aAAa,CAAC,CAAC;YACnC,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;SACtD;QAED,KAAK,sBAAgB,CAAC,kBAAkB,CAAC,CAAC;YACxC,IAAI,OAAO,CAAC,kBAAkB,KAAK,SAAS,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AC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAgB,EAChB,OAAuB;IAEvB,IAAI;QACF,OAAO,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAChD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YACzD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,8DAA8D,CAAC;QAErE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAdD,oDAcC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.GetAccountBalances: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
@@ -1,6 +1,5 @@
1
- import type { Infer } from 'superstruct';
2
- import { Struct } from 'superstruct';
3
- import type { ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from 'superstruct/dist/utils';
1
+ import { Struct } from '@metamask/superstruct';
2
+ import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from '@metamask/superstruct';
4
3
  declare const ExactOptionalSymbol: unique symbol;
5
4
  export declare type ExactOptionalTag = {
6
5
  type: typeof ExactOptionalSymbol;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.strictMask = exports.definePattern = exports.exactOptional = exports.object = void 0;
4
- const superstruct_1 = require("superstruct");
4
+ const superstruct_1 = require("@metamask/superstruct");
5
5
  /**
6
6
  * Change the return type of a superstruct object struct to support exact
7
7
  * optional properties.
@@ -1 +1 @@
1
- {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAyE;AAkDzE;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, assert, define, object as stObject } from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from 'superstruct/dist/utils';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
1
+ {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;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C,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import {\n Struct,\n assert,\n define,\n object as stObject,\n} from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from '@metamask/superstruct';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
@@ -1,17 +1,17 @@
1
- import { type Infer } from 'superstruct';
1
+ import { type Infer } from '@metamask/superstruct';
2
2
  /**
3
3
  * UUIDv4 struct.
4
4
  */
5
- export declare const UuidStruct: import("superstruct").Struct<string, null>;
5
+ export declare const UuidStruct: import("@metamask/superstruct").Struct<string, null>;
6
6
  /**
7
7
  * Validates if a given value is a valid URL.
8
8
  *
9
9
  * @param value - The value to be validated.
10
10
  * @returns A boolean indicating if the value is a valid URL.
11
11
  */
12
- export declare const UrlStruct: import("superstruct").Struct<string, null>;
12
+ export declare const UrlStruct: import("@metamask/superstruct").Struct<string, null>;
13
13
  /**
14
14
  * A string which contains a positive float number.
15
15
  */
16
- export declare const StringNumberStruct: import("superstruct").Struct<string, null>;
16
+ export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>;
17
17
  export declare type StringNumber = Infer<typeof StringNumberStruct>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StringNumberStruct = exports.UrlStruct = exports.UuidStruct = void 0;
4
- const superstruct_1 = require("superstruct");
4
+ const superstruct_1 = require("@metamask/superstruct");
5
5
  const superstruct_2 = require("../superstruct");
6
6
  /**
7
7
  * UUIDv4 struct.
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,6CAAiD;AAEjD,gDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;KAC9D;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from 'superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch (_) {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,gDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;KAC9D;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch (_) {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "8.0.0",
3
+ "version": "8.0.1",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -38,11 +38,11 @@
38
38
  "test:watch": "jest --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@metamask/snaps-sdk": "^4.2.0",
42
- "@metamask/utils": "^8.4.0",
41
+ "@metamask/snaps-sdk": "^6.0.0",
42
+ "@metamask/superstruct": "^3.1.0",
43
+ "@metamask/utils": "^9.1.0",
43
44
  "@types/uuid": "^9.0.8",
44
45
  "bech32": "^2.0.0",
45
- "superstruct": "^1.0.3",
46
46
  "uuid": "^9.0.1"
47
47
  },
48
48
  "devDependencies": {
@@ -53,7 +53,7 @@
53
53
  "@metamask/eslint-config-jest": "^12.1.0",
54
54
  "@metamask/eslint-config-nodejs": "^12.1.0",
55
55
  "@metamask/eslint-config-typescript": "^12.1.0",
56
- "@metamask/providers": "^17.0.0",
56
+ "@metamask/providers": "^17.1.1",
57
57
  "@types/jest": "^29.5.12",
58
58
  "@types/node": "^20.12.12",
59
59
  "@typescript-eslint/eslint-plugin": "^5.62.0",