@metamask/keyring-api 6.2.0 → 6.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +32 -1
  2. package/dist/KeyringClient.js +9 -9
  3. package/dist/KeyringClient.js.map +1 -1
  4. package/dist/api/account.d.ts +62 -0
  5. package/dist/api/account.js +56 -0
  6. package/dist/api/account.js.map +1 -0
  7. package/dist/api/balance.d.ts +9 -0
  8. package/dist/api/balance.js +11 -0
  9. package/dist/api/balance.js.map +1 -0
  10. package/dist/api/export.d.ts +8 -0
  11. package/dist/api/export.js +7 -0
  12. package/dist/api/export.js.map +1 -0
  13. package/dist/api/index.d.ts +6 -0
  14. package/dist/api/index.js +23 -0
  15. package/dist/api/index.js.map +1 -0
  16. package/dist/{api.d.ts → api/keyring.d.ts} +34 -125
  17. package/dist/api/keyring.js +3 -0
  18. package/dist/api/keyring.js.map +1 -0
  19. package/dist/api/request.d.ts +39 -0
  20. package/dist/api/request.js +29 -0
  21. package/dist/api/request.js.map +1 -0
  22. package/dist/api/response.d.ts +24 -0
  23. package/dist/api/response.js +44 -0
  24. package/dist/api/response.js.map +1 -0
  25. package/dist/btc/types.d.ts +4 -7
  26. package/dist/btc/types.js +10 -12
  27. package/dist/btc/types.js.map +1 -1
  28. package/dist/eth/erc4337/types.d.ts +1 -1
  29. package/dist/eth/erc4337/types.js +2 -1
  30. package/dist/eth/erc4337/types.js.map +1 -1
  31. package/dist/eth/types.d.ts +9 -15
  32. package/dist/eth/types.js +23 -29
  33. package/dist/eth/types.js.map +1 -1
  34. package/dist/eth/utils.d.ts +3 -2
  35. package/dist/eth/utils.js +3 -2
  36. package/dist/eth/utils.js.map +1 -1
  37. package/dist/internal/api.d.ts +94 -112
  38. package/dist/internal/api.js +35 -22
  39. package/dist/internal/api.js.map +1 -1
  40. package/dist/internal/events.d.ts +44 -96
  41. package/dist/internal/events.js +10 -10
  42. package/dist/internal/events.js.map +1 -1
  43. package/dist/internal/rpc.d.ts +1 -0
  44. package/dist/internal/rpc.js +1 -0
  45. package/dist/internal/rpc.js.map +1 -1
  46. package/dist/internal/types.d.ts +65 -6
  47. package/dist/internal/types.js +7 -9
  48. package/dist/internal/types.js.map +1 -1
  49. package/dist/rpc-handler.d.ts +12 -0
  50. package/dist/rpc-handler.js +40 -2
  51. package/dist/rpc-handler.js.map +1 -1
  52. package/dist/superstruct.d.ts +9 -4
  53. package/dist/superstruct.js +14 -14
  54. package/dist/superstruct.js.map +1 -1
  55. package/dist/utils/caip.d.ts +37 -0
  56. package/dist/utils/caip.js +48 -0
  57. package/dist/utils/caip.js.map +1 -0
  58. package/dist/utils/index.d.ts +3 -0
  59. package/dist/utils/index.js +20 -0
  60. package/dist/utils/index.js.map +1 -0
  61. package/dist/utils/types.d.ts +17 -0
  62. package/dist/utils/types.js +29 -0
  63. package/dist/utils/types.js.map +1 -0
  64. package/dist/utils/typing.d.ts +32 -0
  65. package/dist/utils/typing.js +21 -0
  66. package/dist/utils/typing.js.map +1 -0
  67. package/package.json +26 -26
  68. package/dist/api.js +0 -108
  69. package/dist/api.js.map +0 -1
  70. package/dist/base-types.d.ts +0 -62
  71. package/dist/base-types.js +0 -32
  72. package/dist/base-types.js.map +0 -1
  73. package/dist/utils.d.ts +0 -26
  74. package/dist/utils.js +0 -26
  75. package/dist/utils.js.map +0 -1
@@ -2,74 +2,48 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
2
2
  method: "notify:accountCreated";
3
3
  params: {
4
4
  account: {
5
- type: "bip122:p2wpkh";
5
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
6
6
  id: string;
7
7
  address: string;
8
8
  options: Record<string, import("@metamask/utils").Json>;
9
- methods: "btc_sendmany"[];
10
- } | {
11
- type: "eip155:eoa";
12
- id: string;
13
- address: string;
14
- options: Record<string, import("@metamask/utils").Json>;
15
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
16
- } | {
17
- type: "eip155:erc4337";
18
- id: string;
19
- address: string;
20
- options: Record<string, import("@metamask/utils").Json>;
21
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
9
+ methods: string[];
22
10
  };
23
- accountNameSuggestion: string | import("../superstruct").ExactOptionalTag;
24
- displayConfirmation: boolean | import("../superstruct").ExactOptionalTag;
11
+ accountNameSuggestion?: string;
12
+ displayConfirmation?: boolean;
25
13
  };
26
14
  }, {
27
15
  method: import("superstruct").Struct<"notify:accountCreated", "notify:accountCreated">;
28
16
  params: import("superstruct").Struct<{
29
17
  account: {
30
- type: "bip122:p2wpkh";
18
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
31
19
  id: string;
32
20
  address: string;
33
21
  options: Record<string, import("@metamask/utils").Json>;
34
- methods: "btc_sendmany"[];
35
- } | {
36
- type: "eip155:eoa";
37
- id: string;
38
- address: string;
39
- options: Record<string, import("@metamask/utils").Json>;
40
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
41
- } | {
42
- type: "eip155:erc4337";
43
- id: string;
44
- address: string;
45
- options: Record<string, import("@metamask/utils").Json>;
46
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
22
+ methods: string[];
47
23
  };
48
- accountNameSuggestion: string | import("../superstruct").ExactOptionalTag;
49
- displayConfirmation: boolean | import("../superstruct").ExactOptionalTag;
24
+ accountNameSuggestion?: string;
25
+ displayConfirmation?: boolean;
50
26
  }, {
51
27
  /**
52
28
  * New account object.
53
29
  */
54
30
  account: import("superstruct").Struct<{
55
- type: "bip122:p2wpkh";
56
- id: string;
57
- address: string;
58
- options: Record<string, import("@metamask/utils").Json>;
59
- methods: "btc_sendmany"[];
60
- } | {
61
- type: "eip155:eoa";
62
- id: string;
63
- address: string;
64
- options: Record<string, import("@metamask/utils").Json>;
65
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
66
- } | {
67
- type: "eip155:erc4337";
68
- id: string;
69
- address: string;
70
- options: Record<string, import("@metamask/utils").Json>;
71
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
72
- }, null>;
31
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
32
+ id: string;
33
+ address: string;
34
+ options: Record<string, import("@metamask/utils").Json>;
35
+ methods: string[];
36
+ }, {
37
+ id: import("superstruct").Struct<string, null>;
38
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
39
+ "eip155:eoa": "eip155:eoa";
40
+ "eip155:erc4337": "eip155:erc4337";
41
+ "bip122:p2wpkh": "bip122:p2wpkh";
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>>;
46
+ }>;
73
47
  /**
74
48
  * Account name suggestion provided to the MetaMask client.
75
49
  *
@@ -89,70 +63,44 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
89
63
  method: "notify:accountUpdated";
90
64
  params: {
91
65
  account: {
92
- type: "bip122:p2wpkh";
66
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
93
67
  id: string;
94
68
  address: string;
95
69
  options: Record<string, import("@metamask/utils").Json>;
96
- methods: "btc_sendmany"[];
97
- } | {
98
- type: "eip155:eoa";
99
- id: string;
100
- address: string;
101
- options: Record<string, import("@metamask/utils").Json>;
102
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
103
- } | {
104
- type: "eip155:erc4337";
105
- id: string;
106
- address: string;
107
- options: Record<string, import("@metamask/utils").Json>;
108
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
70
+ methods: string[];
109
71
  };
110
72
  };
111
73
  }, {
112
74
  method: import("superstruct").Struct<"notify:accountUpdated", "notify:accountUpdated">;
113
75
  params: import("superstruct").Struct<{
114
76
  account: {
115
- type: "bip122:p2wpkh";
77
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
116
78
  id: string;
117
79
  address: string;
118
80
  options: Record<string, import("@metamask/utils").Json>;
119
- methods: "btc_sendmany"[];
120
- } | {
121
- type: "eip155:eoa";
122
- id: string;
123
- address: string;
124
- options: Record<string, import("@metamask/utils").Json>;
125
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
126
- } | {
127
- type: "eip155:erc4337";
128
- id: string;
129
- address: string;
130
- options: Record<string, import("@metamask/utils").Json>;
131
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
81
+ methods: string[];
132
82
  };
133
83
  }, {
134
84
  /**
135
85
  * Updated account object.
136
86
  */
137
87
  account: import("superstruct").Struct<{
138
- type: "bip122:p2wpkh";
139
- id: string;
140
- address: string;
141
- options: Record<string, import("@metamask/utils").Json>;
142
- methods: "btc_sendmany"[];
143
- } | {
144
- type: "eip155:eoa";
145
- id: string;
146
- address: string;
147
- options: Record<string, import("@metamask/utils").Json>;
148
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
149
- } | {
150
- type: "eip155:erc4337";
151
- id: string;
152
- address: string;
153
- options: Record<string, import("@metamask/utils").Json>;
154
- methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
155
- }, null>;
88
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
89
+ id: string;
90
+ address: string;
91
+ options: Record<string, import("@metamask/utils").Json>;
92
+ methods: string[];
93
+ }, {
94
+ id: import("superstruct").Struct<string, null>;
95
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
96
+ "eip155:eoa": "eip155:eoa";
97
+ "eip155:erc4337": "eip155:erc4337";
98
+ "bip122:p2wpkh": "bip122:p2wpkh";
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>>;
103
+ }>;
156
104
  }>;
157
105
  }>;
158
106
  export declare const AccountDeletedEventStruct: import("superstruct").Struct<{
@@ -7,9 +7,9 @@ const api_1 = require("../api");
7
7
  const events_1 = require("../events");
8
8
  const superstruct_2 = require("../superstruct");
9
9
  const utils_2 = require("../utils");
10
- exports.AccountCreatedEventStruct = (0, superstruct_1.object)({
10
+ exports.AccountCreatedEventStruct = (0, superstruct_2.object)({
11
11
  method: (0, superstruct_1.literal)(`${events_1.KeyringEvent.AccountCreated}`),
12
- params: (0, superstruct_1.object)({
12
+ params: (0, superstruct_2.object)({
13
13
  /**
14
14
  * New account object.
15
15
  */
@@ -29,27 +29,27 @@ exports.AccountCreatedEventStruct = (0, superstruct_1.object)({
29
29
  displayConfirmation: (0, superstruct_2.exactOptional)((0, superstruct_1.boolean)()),
30
30
  }),
31
31
  });
32
- exports.AccountUpdatedEventStruct = (0, superstruct_1.object)({
32
+ exports.AccountUpdatedEventStruct = (0, superstruct_2.object)({
33
33
  method: (0, superstruct_1.literal)(`${events_1.KeyringEvent.AccountUpdated}`),
34
- params: (0, superstruct_1.object)({
34
+ params: (0, superstruct_2.object)({
35
35
  /**
36
36
  * Updated account object.
37
37
  */
38
38
  account: api_1.KeyringAccountStruct,
39
39
  }),
40
40
  });
41
- exports.AccountDeletedEventStruct = (0, superstruct_1.object)({
41
+ exports.AccountDeletedEventStruct = (0, superstruct_2.object)({
42
42
  method: (0, superstruct_1.literal)(`${events_1.KeyringEvent.AccountDeleted}`),
43
- params: (0, superstruct_1.object)({
43
+ params: (0, superstruct_2.object)({
44
44
  /**
45
45
  * Deleted account ID.
46
46
  */
47
47
  id: utils_2.UuidStruct,
48
48
  }),
49
49
  });
50
- exports.RequestApprovedEventStruct = (0, superstruct_1.object)({
50
+ exports.RequestApprovedEventStruct = (0, superstruct_2.object)({
51
51
  method: (0, superstruct_1.literal)(`${events_1.KeyringEvent.RequestApproved}`),
52
- params: (0, superstruct_1.object)({
52
+ params: (0, superstruct_2.object)({
53
53
  /**
54
54
  * Request ID.
55
55
  */
@@ -60,9 +60,9 @@ exports.RequestApprovedEventStruct = (0, superstruct_1.object)({
60
60
  result: utils_1.JsonStruct,
61
61
  }),
62
62
  });
63
- exports.RequestRejectedEventStruct = (0, superstruct_1.object)({
63
+ exports.RequestRejectedEventStruct = (0, superstruct_2.object)({
64
64
  method: (0, superstruct_1.literal)(`${events_1.KeyringEvent.RequestRejected}`),
65
- params: (0, superstruct_1.object)({
65
+ params: (0, superstruct_2.object)({
66
66
  /**
67
67
  * Request ID.
68
68
  */
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/internal/events.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7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AAE,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, object, string } from 'superstruct';\n\nimport { KeyringAccountStruct } from '../api';\nimport { KeyringEvent } from '../events';\nimport { exactOptional } 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,2CAA6C;AAC7C,6C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AAA,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"]}
@@ -5,6 +5,7 @@ export declare enum KeyringRpcMethod {
5
5
  ListAccounts = "keyring_listAccounts",
6
6
  GetAccount = "keyring_getAccount",
7
7
  CreateAccount = "keyring_createAccount",
8
+ GetAccountBalances = "keyring_getAccountBalances",
8
9
  FilterAccountChains = "keyring_filterAccountChains",
9
10
  UpdateAccount = "keyring_updateAccount",
10
11
  DeleteAccount = "keyring_deleteAccount",
@@ -9,6 +9,7 @@ var KeyringRpcMethod;
9
9
  KeyringRpcMethod["ListAccounts"] = "keyring_listAccounts";
10
10
  KeyringRpcMethod["GetAccount"] = "keyring_getAccount";
11
11
  KeyringRpcMethod["CreateAccount"] = "keyring_createAccount";
12
+ KeyringRpcMethod["GetAccountBalances"] = "keyring_getAccountBalances";
12
13
  KeyringRpcMethod["FilterAccountChains"] = "keyring_filterAccountChains";
13
14
  KeyringRpcMethod["UpdateAccount"] = "keyring_updateAccount";
14
15
  KeyringRpcMethod["DeleteAccount"] = "keyring_deleteAccount";
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/internal/rpc.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAaX;AAbD,WAAY,gBAAgB;IAC1B,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,uEAAmD,CAAA;IACnD,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,6DAAyC,CAAA;IACzC,2DAAuC,CAAA;AACzC,CAAC,EAbW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAa3B;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,MAA0B,CAAC,CAAC;AAC9E,CAAC;AAFD,gDAEC","sourcesContent":["/**\n * Keyring RPC methods used by the API.\n */\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Check if a method is a keyring RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a keyring RPC method.\n */\nexport function isKeyringRpcMethod(method: string): boolean {\n return Object.values(KeyringRpcMethod).includes(method as KeyringRpcMethod);\n}\n"]}
1
+ {"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../src/internal/rpc.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,IAAY,gBAcX;AAdD,WAAY,gBAAgB;IAC1B,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,qEAAiD,CAAA;IACjD,uEAAmD,CAAA;IACnD,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,2DAAuC,CAAA;IACvC,yDAAqC,CAAA;IACrC,qDAAiC,CAAA;IACjC,2DAAuC,CAAA;IACvC,6DAAyC,CAAA;IACzC,2DAAuC,CAAA;AACzC,CAAC,EAdW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAc3B;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAAc;IAC/C,OAAO,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,MAA0B,CAAC,CAAC;AAC9E,CAAC;AAFD,gDAEC","sourcesContent":["/**\n * Keyring RPC methods used by the API.\n */\nexport enum KeyringRpcMethod {\n ListAccounts = 'keyring_listAccounts',\n GetAccount = 'keyring_getAccount',\n CreateAccount = 'keyring_createAccount',\n GetAccountBalances = 'keyring_getAccountBalances',\n FilterAccountChains = 'keyring_filterAccountChains',\n UpdateAccount = 'keyring_updateAccount',\n DeleteAccount = 'keyring_deleteAccount',\n ExportAccount = 'keyring_exportAccount',\n ListRequests = 'keyring_listRequests',\n GetRequest = 'keyring_getRequest',\n SubmitRequest = 'keyring_submitRequest',\n ApproveRequest = 'keyring_approveRequest',\n RejectRequest = 'keyring_rejectRequest',\n}\n\n/**\n * Check if a method is a keyring RPC method.\n *\n * @param method - Method to check.\n * @returns Whether the method is a keyring RPC method.\n */\nexport function isKeyringRpcMethod(method: string): boolean {\n return Object.values(KeyringRpcMethod).includes(method as KeyringRpcMethod);\n}\n"]}
@@ -1,6 +1,5 @@
1
1
  import type { Infer, Struct } from 'superstruct';
2
- import { BtcAccountType } from '../btc/types';
3
- import { EthAccountType } from '../eth/types';
2
+ import { BtcAccountType, EthAccountType } from '../api';
4
3
  export declare type InternalAccountType = EthAccountType | BtcAccountType;
5
4
  export declare const InternalAccountMetadataStruct: Struct<{
6
5
  metadata: {
@@ -69,6 +68,7 @@ export declare const InternalEthEoaAccountStruct: Struct<{
69
68
  lastSelected?: number;
70
69
  };
71
70
  }, {
71
+ address: Struct<string, null>;
72
72
  type: Struct<"eip155:eoa", "eip155:eoa">;
73
73
  methods: Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
74
74
  personal_sign: "personal_sign";
@@ -79,7 +79,6 @@ export declare const InternalEthEoaAccountStruct: Struct<{
79
79
  eth_signTypedData_v4: "eth_signTypedData_v4";
80
80
  }>>;
81
81
  id: Struct<string, null>;
82
- address: Struct<string, null>;
83
82
  options: Struct<Record<string, import("@metamask/utils").Json>, null>;
84
83
  } & {
85
84
  metadata: Struct<{
@@ -134,6 +133,7 @@ export declare const InternalEthErc4337AccountStruct: Struct<{
134
133
  lastSelected?: number;
135
134
  };
136
135
  }, {
136
+ address: Struct<string, null>;
137
137
  type: Struct<"eip155:erc4337", "eip155:erc4337">;
138
138
  methods: Struct<("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], Struct<"personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
139
139
  personal_sign: "personal_sign";
@@ -146,7 +146,6 @@ export declare const InternalEthErc4337AccountStruct: Struct<{
146
146
  eth_signUserOperation: "eth_signUserOperation";
147
147
  }>>;
148
148
  id: Struct<string, null>;
149
- address: Struct<string, null>;
150
149
  options: Struct<Record<string, import("@metamask/utils").Json>, null>;
151
150
  } & {
152
151
  metadata: Struct<{
@@ -201,12 +200,12 @@ export declare const InternalBtcP2wpkhAccountStruct: Struct<{
201
200
  lastSelected?: number;
202
201
  };
203
202
  }, {
203
+ address: Struct<string, null>;
204
204
  type: Struct<"bip122:p2wpkh", "bip122:p2wpkh">;
205
205
  methods: Struct<"btc_sendmany"[], Struct<"btc_sendmany", {
206
206
  btc_sendmany: "btc_sendmany";
207
207
  }>>;
208
208
  id: Struct<string, null>;
209
- address: Struct<string, null>;
210
209
  options: Struct<Record<string, import("@metamask/utils").Json>, null>;
211
210
  } & {
212
211
  metadata: Struct<{
@@ -246,7 +245,67 @@ export declare type InternalEthErc4337Account = Infer<typeof InternalEthErc4337A
246
245
  export declare type InternalBtcP2wpkhAccount = Infer<typeof InternalBtcP2wpkhAccountStruct>;
247
246
  export declare const InternalAccountStructs: Record<string, Struct<InternalEthEoaAccount> | Struct<InternalEthErc4337Account> | Struct<InternalBtcP2wpkhAccount>>;
248
247
  export declare type InternalAccountTypes = InternalEthEoaAccount | InternalEthErc4337Account | InternalBtcP2wpkhAccount;
249
- export declare const InternalAccountStruct: Struct<InternalAccountTypes, null>;
248
+ export declare const InternalAccountStruct: Struct<{
249
+ type: "eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh";
250
+ id: string;
251
+ address: string;
252
+ options: Record<string, import("@metamask/utils").Json>;
253
+ methods: string[];
254
+ metadata: {
255
+ name: string;
256
+ importTime: number;
257
+ keyring: {
258
+ type: string;
259
+ };
260
+ snap?: {
261
+ id: string;
262
+ name: string;
263
+ enabled: boolean;
264
+ };
265
+ lastSelected?: number;
266
+ };
267
+ }, {
268
+ metadata: Struct<{
269
+ name: string;
270
+ importTime: number;
271
+ keyring: {
272
+ type: string;
273
+ };
274
+ snap?: {
275
+ id: string;
276
+ name: string;
277
+ enabled: boolean;
278
+ };
279
+ lastSelected?: number;
280
+ }, {
281
+ name: Struct<string, null>;
282
+ snap: Struct<import("../superstruct").ExactOptionalTag | {
283
+ id: string;
284
+ name: string;
285
+ enabled: boolean;
286
+ }, {
287
+ id: Struct<string, null>;
288
+ enabled: Struct<boolean, null>;
289
+ name: Struct<string, null>;
290
+ }>;
291
+ lastSelected: Struct<number | import("../superstruct").ExactOptionalTag, null>;
292
+ importTime: Struct<number, null>;
293
+ keyring: Struct<{
294
+ type: string;
295
+ }, {
296
+ type: Struct<string, null>;
297
+ }>;
298
+ }>;
299
+ id: Struct<string, null>;
300
+ type: Struct<"eip155:eoa" | "eip155:erc4337" | "bip122:p2wpkh", {
301
+ "eip155:eoa": "eip155:eoa";
302
+ "eip155:erc4337": "eip155:erc4337";
303
+ "bip122:p2wpkh": "bip122:p2wpkh";
304
+ }>;
305
+ address: Struct<string, null>;
306
+ options: Struct<Record<string, import("@metamask/utils").Json>, null>;
307
+ methods: Struct<string[], Struct<string, null>>;
308
+ }>;
250
309
  /**
251
310
  * Internal account representation.
252
311
  *
@@ -25,7 +25,7 @@ exports.InternalAccountMetadataStruct = (0, superstruct_2.object)({
25
25
  * Creates an `InternalAccount` from an existing account `superstruct` object.
26
26
  *
27
27
  * @param accountStruct - An account `superstruct` object.
28
- * @returns The `InternalAccount` assocaited to `accountStruct`.
28
+ * @returns The `InternalAccount` associated to `accountStruct`.
29
29
  */
30
30
  function asInternalAccountStruct(accountStruct) {
31
31
  return (0, superstruct_2.object)({
@@ -37,14 +37,12 @@ exports.InternalEthEoaAccountStruct = asInternalAccountStruct(types_2.EthEoaAcco
37
37
  exports.InternalEthErc4337AccountStruct = asInternalAccountStruct(types_2.EthErc4337AccountStruct);
38
38
  exports.InternalBtcP2wpkhAccountStruct = asInternalAccountStruct(types_1.BtcP2wpkhAccountStruct);
39
39
  exports.InternalAccountStructs = {
40
- [`${types_2.EthAccountType.Eoa}`]: exports.InternalEthEoaAccountStruct,
41
- [`${types_2.EthAccountType.Erc4337}`]: exports.InternalEthErc4337AccountStruct,
42
- [`${types_1.BtcAccountType.P2wpkh}`]: exports.InternalBtcP2wpkhAccountStruct,
40
+ [`${api_1.EthAccountType.Eoa}`]: exports.InternalEthEoaAccountStruct,
41
+ [`${api_1.EthAccountType.Erc4337}`]: exports.InternalEthErc4337AccountStruct,
42
+ [`${api_1.BtcAccountType.P2wpkh}`]: exports.InternalBtcP2wpkhAccountStruct,
43
43
  };
44
- exports.InternalAccountStruct = (0, superstruct_1.define)('InternalAccount', (value) => {
45
- const account = (0, superstruct_1.mask)(value, api_1.BaseKeyringAccountStruct);
46
- // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`
47
- const [error] = (0, superstruct_1.validate)(value, exports.InternalAccountStructs[account.type]);
48
- return error ?? true;
44
+ exports.InternalAccountStruct = (0, superstruct_2.object)({
45
+ ...api_1.KeyringAccountStruct.schema,
46
+ ...exports.InternalAccountMetadataStruct.schema,
49
47
  });
50
48
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":";;;AACA,6CAA8E;AAE9E,gCAAkD;AAClD,wCAAsE;AACtE,wCAIsB;AACtB,gDAAuD;AAI1C,QAAA,6BAA6B,GAAG,IAAA,oBAAM,EAAC;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;IAC/F,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EACtB,KAAK,EACL,8BAAsB,CAAC,OAAO,CAAC,IAAI,CAAW,CAC/C,CAAC;IAEF,OAAO,KAAK,IAAI,IAAI,CAAC;AACvB,CAAC,CACF,CAAC","sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { boolean, string, number, define, mask, validate } from 'superstruct';\n\nimport { BaseKeyringAccountStruct } from '../api';\nimport { BtcP2wpkhAccountStruct, BtcAccountType } from '../btc/types';\nimport {\n EthEoaAccountStruct,\n EthErc4337AccountStruct,\n EthAccountType,\n} 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` assocaited 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 = define<InternalAccountTypes>(\n 'InternalAccount',\n (value: unknown) => {\n const account = mask(value, BaseKeyringAccountStruct);\n\n // At this point, we know that `value.type` can be used as an index for `KeyringAccountStructs`\n const [error] = validate(\n value,\n InternalAccountStructs[account.type] as Struct,\n );\n\n return error ?? true;\n },\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","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"]}
@@ -10,8 +10,20 @@ export declare class MethodNotSupportedError extends Error {
10
10
  /**
11
11
  * Handles a keyring JSON-RPC request.
12
12
  *
13
+ * This function is meant to be used as a handler for Keyring JSON-RPC requests
14
+ * in an Accounts Snap.
15
+ *
13
16
  * @param keyring - Keyring instance.
14
17
  * @param request - Keyring JSON-RPC request.
15
18
  * @returns A promise that resolves to the keyring response.
19
+ * @example
20
+ * ```ts
21
+ * export const onKeyringRequest: OnKeyringRequestHandler = async ({
22
+ * origin,
23
+ * request,
24
+ * }) => {
25
+ * return await handleKeyringRequest(keyring, request);
26
+ * };
27
+ * ```
16
28
  */
17
29
  export declare function handleKeyringRequest(keyring: Keyring, request: JsonRpcRequest): Promise<Json | void>;
@@ -15,13 +15,14 @@ class MethodNotSupportedError extends Error {
15
15
  }
16
16
  exports.MethodNotSupportedError = MethodNotSupportedError;
17
17
  /**
18
- * Handles a keyring JSON-RPC request.
18
+ * Inner function that dispatches JSON-RPC request to the associated Keyring
19
+ * methods.
19
20
  *
20
21
  * @param keyring - Keyring instance.
21
22
  * @param request - Keyring JSON-RPC request.
22
23
  * @returns A promise that resolves to the keyring response.
23
24
  */
24
- async function handleKeyringRequest(keyring, request) {
25
+ async function dispatchRequest(keyring, request) {
25
26
  // We first have to make sure that the request is a valid JSON-RPC request so
26
27
  // we can check its method name.
27
28
  (0, superstruct_1.assert)(request, JsonRpcRequest_1.JsonRpcRequestStruct);
@@ -38,6 +39,13 @@ async function handleKeyringRequest(keyring, request) {
38
39
  (0, superstruct_1.assert)(request, api_1.CreateAccountRequestStruct);
39
40
  return keyring.createAccount(request.params.options);
40
41
  }
42
+ case rpc_1.KeyringRpcMethod.GetAccountBalances: {
43
+ if (keyring.getAccountBalances === undefined) {
44
+ throw new MethodNotSupportedError(request.method);
45
+ }
46
+ (0, superstruct_1.assert)(request, api_1.GetAccountBalancesRequestStruct);
47
+ return keyring.getAccountBalances(request.params.id, request.params.assets);
48
+ }
41
49
  case rpc_1.KeyringRpcMethod.FilterAccountChains: {
42
50
  (0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);
43
51
  return keyring.filterAccountChains(request.params.id, request.params.chains);
@@ -94,5 +102,35 @@ async function handleKeyringRequest(keyring, request) {
94
102
  }
95
103
  }
96
104
  }
105
+ /**
106
+ * Handles a keyring JSON-RPC request.
107
+ *
108
+ * This function is meant to be used as a handler for Keyring JSON-RPC requests
109
+ * in an Accounts Snap.
110
+ *
111
+ * @param keyring - Keyring instance.
112
+ * @param request - Keyring JSON-RPC request.
113
+ * @returns A promise that resolves to the keyring response.
114
+ * @example
115
+ * ```ts
116
+ * export const onKeyringRequest: OnKeyringRequestHandler = async ({
117
+ * origin,
118
+ * request,
119
+ * }) => {
120
+ * return await handleKeyringRequest(keyring, request);
121
+ * };
122
+ * ```
123
+ */
124
+ async function handleKeyringRequest(keyring, request) {
125
+ try {
126
+ return await dispatchRequest(keyring, request);
127
+ }
128
+ catch (error) {
129
+ const message = error instanceof Error && typeof error.message === 'string'
130
+ ? error.message
131
+ : 'An unknown error occurred while handling the keyring request';
132
+ throw new Error(message);
133
+ }
134
+ }
97
135
  exports.handleKeyringRequest = handleKeyringRequest;
98
136
  //# sourceMappingURL=rpc-handler.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAawB;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;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,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,U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O,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;AA3FD,oDA2FC","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} 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 * Handles a keyring JSON-RPC request.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nexport async function handleKeyringRequest(\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.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"]}
1
+ {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AACA,6CAAqC;AAGrC,wCAcwB;AACxB,wCAAkD;AAElD,qDAAwD;AAExD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B,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"]}
@@ -70,10 +70,15 @@ export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>
70
70
  */
71
71
  export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
72
72
  /**
73
- * Validates if a given value is a valid URL.
73
+ * Assert that a value is valid according to a struct.
74
74
  *
75
- * @param value - The value to be validated.
76
- * @returns A boolean indicating if the value is a valid URL.
75
+ * It is similar to superstruct's mask function, but it does not ignore extra
76
+ * properties.
77
+ *
78
+ * @param value - Value to check.
79
+ * @param struct - Struct to validate the value against.
80
+ * @param message - Error message to throw if the value is not valid.
81
+ * @returns The value if it is valid.
77
82
  */
78
- export declare const UrlStruct: Struct<string, null>;
83
+ export declare function strictMask<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, message?: string): Type;
79
84
  export {};