@metamask/keyring-api 6.2.1 → 6.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/dist/KeyringClient.js +9 -9
  3. package/dist/KeyringClient.js.map +1 -1
  4. package/dist/api/account.d.ts +62 -0
  5. package/dist/api/account.js +56 -0
  6. package/dist/api/account.js.map +1 -0
  7. package/dist/api/balance.d.ts +9 -0
  8. package/dist/api/balance.js +11 -0
  9. package/dist/api/balance.js.map +1 -0
  10. package/dist/api/caip.d.ts +37 -0
  11. package/dist/api/caip.js +48 -0
  12. package/dist/api/caip.js.map +1 -0
  13. package/dist/api/export.d.ts +8 -0
  14. package/dist/api/export.js +7 -0
  15. package/dist/api/export.js.map +1 -0
  16. package/dist/api/index.d.ts +7 -0
  17. package/dist/api/index.js +24 -0
  18. package/dist/api/index.js.map +1 -0
  19. package/dist/{api.d.ts → api/keyring.d.ts} +34 -125
  20. package/dist/api/keyring.js +3 -0
  21. package/dist/api/keyring.js.map +1 -0
  22. package/dist/api/request.d.ts +39 -0
  23. package/dist/api/request.js +29 -0
  24. package/dist/api/request.js.map +1 -0
  25. package/dist/api/response.d.ts +24 -0
  26. package/dist/api/response.js +44 -0
  27. package/dist/api/response.js.map +1 -0
  28. package/dist/btc/types.d.ts +4 -7
  29. package/dist/btc/types.js +10 -12
  30. package/dist/btc/types.js.map +1 -1
  31. package/dist/eth/erc4337/types.d.ts +1 -1
  32. package/dist/eth/erc4337/types.js +2 -1
  33. package/dist/eth/erc4337/types.js.map +1 -1
  34. package/dist/eth/types.d.ts +9 -15
  35. package/dist/eth/types.js +23 -29
  36. package/dist/eth/types.js.map +1 -1
  37. package/dist/eth/utils.d.ts +3 -2
  38. package/dist/eth/utils.js +3 -2
  39. package/dist/eth/utils.js.map +1 -1
  40. package/dist/internal/api.d.ts +94 -112
  41. package/dist/internal/api.js +35 -22
  42. package/dist/internal/api.js.map +1 -1
  43. package/dist/internal/events.d.ts +40 -92
  44. package/dist/internal/rpc.d.ts +1 -0
  45. package/dist/internal/rpc.js +1 -0
  46. package/dist/internal/rpc.js.map +1 -1
  47. package/dist/internal/types.d.ts +65 -6
  48. package/dist/internal/types.js +7 -9
  49. package/dist/internal/types.js.map +1 -1
  50. package/dist/rpc-handler.d.ts +12 -0
  51. package/dist/rpc-handler.js +40 -2
  52. package/dist/rpc-handler.js.map +1 -1
  53. package/dist/superstruct.d.ts +9 -4
  54. package/dist/superstruct.js +14 -14
  55. package/dist/superstruct.js.map +1 -1
  56. package/dist/utils/index.d.ts +2 -0
  57. package/dist/utils/index.js +19 -0
  58. package/dist/utils/index.js.map +1 -0
  59. package/dist/utils/types.d.ts +17 -0
  60. package/dist/utils/types.js +29 -0
  61. package/dist/utils/types.js.map +1 -0
  62. package/dist/utils/typing.d.ts +32 -0
  63. package/dist/utils/typing.js +21 -0
  64. package/dist/utils/typing.js.map +1 -0
  65. package/package.json +1 -1
  66. package/dist/api.js +0 -108
  67. package/dist/api.js.map +0 -1
  68. package/dist/base-types.d.ts +0 -62
  69. package/dist/base-types.js +0 -32
  70. package/dist/base-types.js.map +0 -1
  71. package/dist/utils.d.ts +0 -26
  72. package/dist/utils.js +0 -26
  73. package/dist/utils.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring.js","sourceRoot":"","sources":["../../src/api/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from './account';\nimport type { Balance } from './balance';\nimport type { CaipAssetType } from './caip';\nimport type { KeyringAccountData } from './export';\nimport type { KeyringRequest } from './request';\nimport type { KeyringResponse } from './response';\n\n/**\n * Keyring interface.\n *\n * Represents the functionality and operations related to managing accounts and\n * handling requests.\n */\nexport type Keyring = {\n /**\n * List accounts.\n *\n * Retrieves an array of KeyringAccount objects representing the available\n * accounts.\n *\n * @returns A promise that resolves to an array of KeyringAccount objects.\n */\n listAccounts(): Promise<KeyringAccount[]>;\n\n /**\n * Get an account.\n *\n * Retrieves the KeyringAccount object for the given account ID.\n *\n * @param id - The ID of the account to retrieve.\n * @returns A promise that resolves to the KeyringAccount object if found, or\n * undefined otherwise.\n */\n getAccount(id: string): Promise<KeyringAccount | undefined>;\n\n /**\n * Create an account.\n *\n * Creates a new account with optional, keyring-defined, account options.\n *\n * @param options - Keyring-defined options for the account (optional).\n * @returns A promise that resolves to the newly created KeyringAccount\n * object without any private information.\n */\n createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;\n\n /**\n * Retrieve the balances of a given account.\n *\n * This method fetches the balances of specified assets for a given account\n * ID. It returns a promise that resolves to an object where the keys are\n * asset types and the values are balance objects containing the amount and\n * unit.\n *\n * @example\n * ```ts\n * await keyring.getAccountBalances(\n * '43550276-c7d6-4fac-87c7-00390ad0ce90',\n * ['bip122:000000000019d6689c085ae165831e93/slip44:0']\n * );\n * // Returns something similar to:\n * // {\n * // 'bip122:000000000019d6689c085ae165831e93/slip44:0': {\n * // amount: '0.0001',\n * // unit: 'BTC',\n * // }\n * // }\n * ```\n * @param id - ID of the account to retrieve the balances for.\n * @param assets - Array of asset types (CAIP-19) to retrieve balances for.\n * @returns A promise that resolves to an object mapping asset types to their\n * respective balances.\n */\n getAccountBalances?(\n id: string,\n assets: CaipAssetType[],\n ): Promise<Record<CaipAssetType, Balance>>;\n\n /**\n * Filter supported chains for a given account.\n *\n * @param id - ID of the account to be checked.\n * @param chains - List of chains (CAIP-2) to be checked.\n * @returns A Promise that resolves to a filtered list of CAIP-2 IDs\n * representing the supported chains.\n */\n filterAccountChains(id: string, chains: string[]): Promise<string[]>;\n\n /**\n * Update an account.\n *\n * Updates the account with the given account object. Does nothing if the\n * account does not exist.\n *\n * @param account - The updated account object.\n * @returns A promise that resolves when the account is successfully updated.\n */\n updateAccount(account: KeyringAccount): Promise<void>;\n\n /**\n * Delete an account from the keyring.\n *\n * Deletes the account with the given ID from the keyring.\n *\n * @param id - The ID of the account to delete.\n * @returns A promise that resolves when the account is successfully deleted.\n */\n deleteAccount(id: string): Promise<void>;\n\n /**\n * Exports an account's private key.\n *\n * If the keyring cannot export a private key, this function should throw an\n * error.\n *\n * @param id - The ID of the account to export.\n * @returns A promise that resolves to the exported account.\n */\n exportAccount?(id: string): Promise<KeyringAccountData>;\n\n /**\n * List all submitted requests.\n *\n * Retrieves an array of KeyringRequest objects representing the submitted\n * requests.\n *\n * @returns A promise that resolves to an array of KeyringRequest objects.\n */\n listRequests?(): Promise<KeyringRequest[]>;\n\n /**\n * Get a request.\n *\n * Retrieves the KeyringRequest object for the given request ID.\n *\n * @param id - The ID of the request to retrieve.\n * @returns A promise that resolves to the KeyringRequest object if found, or\n * undefined otherwise.\n */\n getRequest?(id: string): Promise<KeyringRequest | undefined>;\n\n /**\n * Submit a request.\n *\n * Submits the given KeyringRequest object.\n *\n * @param request - The KeyringRequest object to submit.\n * @returns A promise that resolves to the request response.\n */\n submitRequest(request: KeyringRequest): Promise<KeyringResponse>;\n\n /**\n * Approve a request.\n *\n * Approves the request with the given ID and sets the response if provided.\n *\n * @param id - The ID of the request to approve.\n * @param data - The response to the request (optional).\n * @returns A promise that resolves when the request is successfully\n * approved.\n */\n approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;\n\n /**\n * Reject a request.\n *\n * Rejects the request with the given ID.\n *\n * @param id - The ID of the request to reject.\n * @returns A promise that resolves when the request is successfully\n * rejected.\n */\n rejectRequest?(id: string): Promise<void>;\n};\n"]}
@@ -0,0 +1,39 @@
1
+ import type { Infer } from 'superstruct';
2
+ export declare const KeyringRequestStruct: import("superstruct").Struct<{
3
+ id: string;
4
+ scope: string;
5
+ account: string;
6
+ request: {
7
+ method: string;
8
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
9
+ };
10
+ }, {
11
+ /**
12
+ * Keyring request ID (UUIDv4).
13
+ */
14
+ id: import("superstruct").Struct<string, null>;
15
+ /**
16
+ * Request's scope (CAIP-2 chain ID).
17
+ */
18
+ scope: import("superstruct").Struct<string, null>;
19
+ /**
20
+ * Account ID (UUIDv4).
21
+ */
22
+ account: import("superstruct").Struct<string, null>;
23
+ /**
24
+ * Inner request sent by the client application.
25
+ */
26
+ request: import("superstruct").Struct<{
27
+ method: string;
28
+ params?: import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>;
29
+ }, {
30
+ method: import("superstruct").Struct<string, null>;
31
+ params: import("superstruct").Struct<import("../superstruct").ExactOptionalTag | import("@metamask/utils").Json[] | Record<string, import("@metamask/utils").Json>, null>;
32
+ }>;
33
+ }>;
34
+ /**
35
+ * Keyring request.
36
+ *
37
+ * Represents a request made to the keyring for account-related operations.
38
+ */
39
+ export declare type KeyringRequest = Infer<typeof KeyringRequestStruct>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringRequestStruct = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const superstruct_1 = require("superstruct");
6
+ const superstruct_2 = require("../superstruct");
7
+ const utils_2 = require("../utils");
8
+ exports.KeyringRequestStruct = (0, superstruct_2.object)({
9
+ /**
10
+ * Keyring request ID (UUIDv4).
11
+ */
12
+ id: utils_2.UuidStruct,
13
+ /**
14
+ * Request's scope (CAIP-2 chain ID).
15
+ */
16
+ scope: (0, superstruct_1.string)(),
17
+ /**
18
+ * Account ID (UUIDv4).
19
+ */
20
+ account: utils_2.UuidStruct,
21
+ /**
22
+ * Inner request sent by the client application.
23
+ */
24
+ request: (0, superstruct_2.object)({
25
+ method: (0, superstruct_1.string)(),
26
+ params: (0, superstruct_2.exactOptional)((0, superstruct_1.union)([(0, superstruct_1.array)(utils_1.JsonStruct), (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)])),
27
+ }),
28
+ });
29
+ //# sourceMappingURL=request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/api/request.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAA2D;AAE3D,gDAAuD;AACvD,oCAAsC;AAEzB,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,EAAE,EAAE,kBAAU;IAEd;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC;QACd,MAAM,EAAE,IAAA,oBAAM,GAAE;QAChB,MAAM,EAAE,IAAA,2BAAa,EACnB,IAAA,mBAAK,EAAC,CAAC,IAAA,mBAAK,EAAC,kBAAU,CAAC,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC,CACzD;KACF,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, record, string, union } from 'superstruct';\n\nimport { exactOptional, object } from '../superstruct';\nimport { UuidStruct } from '../utils';\n\nexport const KeyringRequestStruct = object({\n /**\n * Keyring request ID (UUIDv4).\n */\n id: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Inner request sent by the client application.\n */\n request: object({\n method: string(),\n params: exactOptional(\n union([array(JsonStruct), record(string(), JsonStruct)]),\n ),\n }),\n});\n\n/**\n * Keyring request.\n *\n * Represents a request made to the keyring for account-related operations.\n */\nexport type KeyringRequest = Infer<typeof KeyringRequestStruct>;\n"]}
@@ -0,0 +1,24 @@
1
+ import type { Infer } from 'superstruct';
2
+ export declare const KeyringResponseStruct: import("superstruct").Struct<{
3
+ pending: true;
4
+ redirect?: {
5
+ message?: string;
6
+ url?: string;
7
+ };
8
+ } | {
9
+ pending: false;
10
+ result: import("@metamask/utils").Json;
11
+ }, null>;
12
+ /**
13
+ * Response to a call to `submitRequest`.
14
+ *
15
+ * Keyring implementations must return a response with `pending: true` if the
16
+ * request will be handled asynchronously. Otherwise, the response must contain
17
+ * the result of the request and `pending: false`.
18
+ *
19
+ * In the asynchronous case, the keyring can return a redirect URL and message
20
+ * to be shown to the user. The user can choose to follow the link or cancel
21
+ * the request. The main use case for this is to redirect the user to the snap
22
+ * dapp to review the request.
23
+ */
24
+ export declare type KeyringResponse = Infer<typeof KeyringResponseStruct>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringResponseStruct = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const superstruct_1 = require("superstruct");
6
+ const superstruct_2 = require("../superstruct");
7
+ exports.KeyringResponseStruct = (0, superstruct_1.union)([
8
+ (0, superstruct_2.object)({
9
+ /**
10
+ * Pending flag.
11
+ *
12
+ * Setting the pending flag to true indicates that the request will be
13
+ * handled asynchronously. The keyring must be called with `approveRequest`
14
+ * or `rejectRequest` to resolve the request.
15
+ */
16
+ pending: (0, superstruct_1.literal)(true),
17
+ /**
18
+ * Redirect URL.
19
+ *
20
+ * If present in the response, MetaMask will display a confirmation dialog
21
+ * with a link to the redirect URL. The user can choose to follow the link
22
+ * or cancel the request.
23
+ */
24
+ redirect: (0, superstruct_2.exactOptional)((0, superstruct_2.object)({
25
+ message: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
26
+ url: (0, superstruct_2.exactOptional)((0, superstruct_1.string)()),
27
+ })),
28
+ }),
29
+ (0, superstruct_2.object)({
30
+ /**
31
+ * Pending flag.
32
+ *
33
+ * Setting the pending flag to false indicates that the request will be
34
+ * handled synchronously. The keyring must return the result of the
35
+ * request execution.
36
+ */
37
+ pending: (0, superstruct_1.literal)(false),
38
+ /**
39
+ * Request result.
40
+ */
41
+ result: utils_1.JsonStruct,
42
+ }),
43
+ ]);
44
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"response.js","sourceRoot":"","sources":["../../src/api/response.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAE7C,6CAAqD;AAErD,gDAAuD;AAE1C,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,IAAI,CAAC;QAEtB;;;;;;WAMG;QACH,QAAQ,EAAE,IAAA,2BAAa,EACrB,IAAA,oBAAM,EAAC;YACL,OAAO,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;YAChC,GAAG,EAAE,IAAA,2BAAa,EAAC,IAAA,oBAAM,GAAE,CAAC;SAC7B,CAAC,CACH;KACF,CAAC;IACF,IAAA,oBAAM,EAAC;QACL;;;;;;WAMG;QACH,OAAO,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,kBAAU;KACnB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { literal, string, union } from 'superstruct';\n\nimport { exactOptional, object } from '../superstruct';\n\nexport const KeyringResponseStruct = union([\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to true indicates that the request will be\n * handled asynchronously. The keyring must be called with `approveRequest`\n * or `rejectRequest` to resolve the request.\n */\n pending: literal(true),\n\n /**\n * Redirect URL.\n *\n * If present in the response, MetaMask will display a confirmation dialog\n * with a link to the redirect URL. The user can choose to follow the link\n * or cancel the request.\n */\n redirect: exactOptional(\n object({\n message: exactOptional(string()),\n url: exactOptional(string()),\n }),\n ),\n }),\n object({\n /**\n * Pending flag.\n *\n * Setting the pending flag to false indicates that the request will be\n * handled synchronously. The keyring must return the result of the\n * request execution.\n */\n pending: literal(false),\n\n /**\n * Request result.\n */\n result: JsonStruct,\n }),\n]);\n\n/**\n * Response to a call to `submitRequest`.\n *\n * Keyring implementations must return a response with `pending: true` if the\n * request will be handled asynchronously. Otherwise, the response must contain\n * the result of the request and `pending: false`.\n *\n * In the asynchronous case, the keyring can return a redirect URL and message\n * to be shown to the user. The user can choose to follow the link or cancel\n * the request. The main use case for this is to redirect the user to the snap\n * dapp to review the request.\n */\nexport type KeyringResponse = Infer<typeof KeyringResponseStruct>;\n"]}
@@ -6,12 +6,6 @@ export declare const BtcP2wpkhAddressStruct: import("superstruct").Struct<string
6
6
  export declare enum BtcMethod {
7
7
  SendMany = "btc_sendmany"
8
8
  }
9
- /**
10
- * Supported Bitcoin account types.
11
- */
12
- export declare enum BtcAccountType {
13
- P2wpkh = "bip122:p2wpkh"
14
- }
15
9
  export declare const BtcP2wpkhAccountStruct: import("superstruct").Struct<{
16
10
  type: "bip122:p2wpkh";
17
11
  id: string;
@@ -19,6 +13,10 @@ export declare const BtcP2wpkhAccountStruct: import("superstruct").Struct<{
19
13
  options: Record<string, import("@metamask/utils").Json>;
20
14
  methods: "btc_sendmany"[];
21
15
  }, {
16
+ /**
17
+ * Account address.
18
+ */
19
+ address: import("superstruct").Struct<string, null>;
22
20
  /**
23
21
  * Account type.
24
22
  */
@@ -30,7 +28,6 @@ export declare const BtcP2wpkhAccountStruct: import("superstruct").Struct<{
30
28
  btc_sendmany: "btc_sendmany";
31
29
  }>>;
32
30
  id: import("superstruct").Struct<string, null>;
33
- address: import("superstruct").Struct<string, null>;
34
31
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
35
32
  }>;
36
33
  export declare type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;
package/dist/btc/types.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BtcP2wpkhAccountStruct = exports.BtcAccountType = exports.BtcMethod = exports.BtcP2wpkhAddressStruct = void 0;
3
+ exports.BtcP2wpkhAccountStruct = exports.BtcMethod = exports.BtcP2wpkhAddressStruct = void 0;
4
4
  const bech32_1 = require("bech32");
5
5
  const superstruct_1 = require("superstruct");
6
- const base_types_1 = require("../base-types");
6
+ const api_1 = require("../api");
7
+ const superstruct_2 = require("../superstruct");
7
8
  exports.BtcP2wpkhAddressStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'BtcP2wpkhAddressStruct', (address) => {
8
9
  try {
9
10
  bech32_1.bech32.decode(address);
@@ -21,19 +22,16 @@ var BtcMethod;
21
22
  // General transaction methods
22
23
  BtcMethod["SendMany"] = "btc_sendmany";
23
24
  })(BtcMethod = exports.BtcMethod || (exports.BtcMethod = {}));
24
- /**
25
- * Supported Bitcoin account types.
26
- */
27
- var BtcAccountType;
28
- (function (BtcAccountType) {
29
- BtcAccountType["P2wpkh"] = "bip122:p2wpkh";
30
- })(BtcAccountType = exports.BtcAccountType || (exports.BtcAccountType = {}));
31
- exports.BtcP2wpkhAccountStruct = (0, superstruct_1.object)({
32
- ...base_types_1.BaseAccount,
25
+ exports.BtcP2wpkhAccountStruct = (0, superstruct_2.object)({
26
+ ...api_1.KeyringAccountStruct.schema,
27
+ /**
28
+ * Account address.
29
+ */
30
+ address: exports.BtcP2wpkhAddressStruct,
33
31
  /**
34
32
  * Account type.
35
33
  */
36
- type: (0, superstruct_1.literal)(`${BtcAccountType.P2wpkh}`),
34
+ type: (0, superstruct_1.literal)(`${api_1.BtcAccountType.P2wpkh}`),
37
35
  /**
38
36
  * Account supported methods.
39
37
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,6CAA4E;AAE5E,8CAA4C;AAE/B,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAC1C,IAAA,oBAAM,GAAE,EACR,wBAAwB,EACxB,CAAC,OAAe,EAAE,EAAE;IAClB,IAAI;QACF,eAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KACxB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,KAAK,CACd,oCAAqC,KAAe,CAAC,OAAO,EAAE,CAC/D,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAA8B;IAC9B,sCAAyB,CAAA;AAC3B,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AAED;;GAEG;AACH,IAAY,cAEX;AAFD,WAAY,cAAc;IACxB,0CAAwB,CAAA;AAC1B,CAAC,EAFW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAEzB;AAEY,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAAC;IAC3C,GAAG,wBAAW;IAEd;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC;IAEzC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,mBAAK,EAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;CACjD,CAAC,CAAC","sourcesContent":["import { bech32 } from 'bech32';\nimport type { Infer } from 'superstruct';\nimport { object, string, array, enums, literal, refine } from 'superstruct';\n\nimport { BaseAccount } from '../base-types';\n\nexport const BtcP2wpkhAddressStruct = refine(\n string(),\n 'BtcP2wpkhAddressStruct',\n (address: string) => {\n try {\n bech32.decode(address);\n } catch (error) {\n return new Error(\n `Could not decode P2WPKH address: ${(error as Error).message}`,\n );\n }\n return true;\n },\n);\n\n/**\n * Supported Bitcoin methods.\n */\nexport enum BtcMethod {\n // General transaction methods\n SendMany = 'btc_sendmany',\n}\n\n/**\n * Supported Bitcoin account types.\n */\nexport enum BtcAccountType {\n P2wpkh = 'bip122:p2wpkh',\n}\n\nexport const BtcP2wpkhAccountStruct = object({\n ...BaseAccount,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2wpkh}`),\n\n /**\n * Account supported methods.\n */\n methods: array(enums([`${BtcMethod.SendMany}`])),\n});\n\nexport type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,6CAAoE;AAEpE,gCAA8D;AAC9D,gDAAwC;AAE3B,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAC1C,IAAA,oBAAM,GAAE,EACR,wBAAwB,EACxB,CAAC,OAAe,EAAE,EAAE;IAClB,IAAI;QACF,eAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;KACxB;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,IAAI,KAAK,CACd,oCAAqC,KAAe,CAAC,OAAO,EAAE,CAC/D,CAAC;KACH;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,IAAY,SAGX;AAHD,WAAY,SAAS;IACnB,8BAA8B;IAC9B,sCAAyB,CAAA;AAC3B,CAAC,EAHW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAGpB;AAEY,QAAA,sBAAsB,GAAG,IAAA,oBAAM,EAAC;IAC3C,GAAG,0BAAoB,CAAC,MAAM;IAE9B;;OAEG;IACH,OAAO,EAAE,8BAAsB;IAE/B;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,MAAM,EAAE,CAAC;IAEzC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EAAC,IAAA,mBAAK,EAAC,CAAC,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;CACjD,CAAC,CAAC","sourcesContent":["import { bech32 } from 'bech32';\nimport type { Infer } from 'superstruct';\nimport { string, array, enums, refine, literal } from 'superstruct';\n\nimport { KeyringAccountStruct, BtcAccountType } from '../api';\nimport { object } from '../superstruct';\n\nexport const BtcP2wpkhAddressStruct = refine(\n string(),\n 'BtcP2wpkhAddressStruct',\n (address: string) => {\n try {\n bech32.decode(address);\n } catch (error) {\n return new Error(\n `Could not decode P2WPKH address: ${(error as Error).message}`,\n );\n }\n return true;\n },\n);\n\n/**\n * Supported Bitcoin methods.\n */\nexport enum BtcMethod {\n // General transaction methods\n SendMany = 'btc_sendmany',\n}\n\nexport const BtcP2wpkhAccountStruct = object({\n ...KeyringAccountStruct.schema,\n\n /**\n * Account address.\n */\n address: BtcP2wpkhAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${BtcAccountType.P2wpkh}`),\n\n /**\n * Account supported methods.\n */\n methods: array(enums([`${BtcMethod.SendMany}`])),\n});\n\nexport type BtcP2wpkhAccount = Infer<typeof BtcP2wpkhAccountStruct>;\n"]}
@@ -35,8 +35,8 @@ export declare type EthUserOperation = Infer<typeof EthUserOperationStruct>;
35
35
  */
36
36
  export declare const EthBaseTransactionStruct: import("superstruct").Struct<{
37
37
  value: string;
38
- to: string;
39
38
  data: string;
39
+ to: string;
40
40
  }, {
41
41
  /**
42
42
  * Address of the transaction recipient.
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EthUserOperationPatchStruct = exports.EthBaseUserOperationStruct = exports.EthBaseTransactionStruct = exports.EthUserOperationStruct = void 0;
4
4
  const superstruct_1 = require("../../superstruct");
5
+ const utils_1 = require("../../utils");
5
6
  const types_1 = require("../types");
6
7
  /**
7
8
  * Struct of a UserOperation as defined by ERC-4337.
@@ -49,7 +50,7 @@ exports.EthBaseUserOperationStruct = (0, superstruct_1.object)({
49
50
  })),
50
51
  dummyPaymasterAndData: types_1.EthBytesStruct,
51
52
  dummySignature: types_1.EthBytesStruct,
52
- bundlerUrl: superstruct_1.UrlStruct,
53
+ bundlerUrl: utils_1.UrlStruct,
53
54
  });
54
55
  exports.EthUserOperationPatchStruct = (0, superstruct_1.object)({
55
56
  paymasterAndData: types_1.EthBytesStruct,
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/eth/erc4337/types.ts"],"names":[],"mappings":";;;AAEA,mDAAqE;AACr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type Infer } from 'superstruct';\n\nimport { UrlStruct, exactOptional, object } from '../../superstruct';\nimport { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';\n\n/**\n * Struct of a UserOperation as defined by ERC-4337.\n * @see https://eips.ethereum.org/EIPS/eip-4337#definitions\n */\nexport const EthUserOperationStruct = object({\n sender: EthAddressStruct,\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n maxFeePerGas: EthUint256Struct,\n maxPriorityFeePerGas: EthUint256Struct,\n paymasterAndData: EthBytesStruct,\n signature: EthBytesStruct,\n});\n\nexport type EthUserOperation = Infer<typeof EthUserOperationStruct>;\n\n/**\n * Struct containing the most basic transaction information required to\n * construct a UserOperation.\n */\nexport const EthBaseTransactionStruct = object({\n /**\n * Address of the transaction recipient.\n */\n to: EthAddressStruct,\n\n /**\n * Amount of wei to transfer to the recipient.\n */\n value: EthUint256Struct,\n\n /**\n * Data to pass to the recipient.\n */\n data: EthBytesStruct,\n});\n\nexport type EthBaseTransaction = Infer<typeof EthBaseTransactionStruct>;\n\nexport const EthBaseUserOperationStruct = object({\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n gasLimits: exactOptional(\n object({\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n }),\n ),\n dummyPaymasterAndData: EthBytesStruct,\n dummySignature: EthBytesStruct,\n bundlerUrl: UrlStruct,\n});\n\nexport type EthBaseUserOperation = Infer<typeof EthBaseUserOperationStruct>;\n\nexport const EthUserOperationPatchStruct = object({\n paymasterAndData: EthBytesStruct,\n callGasLimit: exactOptional(EthUint256Struct),\n verificationGasLimit: exactOptional(EthUint256Struct),\n preVerificationGas: exactOptional(EthUint256Struct),\n});\n\nexport type EthUserOperationPatch = Infer<typeof EthUserOperationPatchStruct>;\n"]}
1
+ {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AAC,wBAAgB,CAAC;IACrD,kBAAkB,EAAE,IAAA,2BAAa,EAAC,wBAAgB,CAAC;CACpD,CAAC,CAAC","sourcesContent":["import { type Infer } from 'superstruct';\n\nimport { exactOptional, object } from '../../superstruct';\nimport { UrlStruct } from '../../utils';\nimport { EthAddressStruct, EthBytesStruct, EthUint256Struct } from '../types';\n\n/**\n * Struct of a UserOperation as defined by ERC-4337.\n * @see https://eips.ethereum.org/EIPS/eip-4337#definitions\n */\nexport const EthUserOperationStruct = object({\n sender: EthAddressStruct,\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n maxFeePerGas: EthUint256Struct,\n maxPriorityFeePerGas: EthUint256Struct,\n paymasterAndData: EthBytesStruct,\n signature: EthBytesStruct,\n});\n\nexport type EthUserOperation = Infer<typeof EthUserOperationStruct>;\n\n/**\n * Struct containing the most basic transaction information required to\n * construct a UserOperation.\n */\nexport const EthBaseTransactionStruct = object({\n /**\n * Address of the transaction recipient.\n */\n to: EthAddressStruct,\n\n /**\n * Amount of wei to transfer to the recipient.\n */\n value: EthUint256Struct,\n\n /**\n * Data to pass to the recipient.\n */\n data: EthBytesStruct,\n});\n\nexport type EthBaseTransaction = Infer<typeof EthBaseTransactionStruct>;\n\nexport const EthBaseUserOperationStruct = object({\n nonce: EthUint256Struct,\n initCode: EthBytesStruct,\n callData: EthBytesStruct,\n gasLimits: exactOptional(\n object({\n callGasLimit: EthUint256Struct,\n verificationGasLimit: EthUint256Struct,\n preVerificationGas: EthUint256Struct,\n }),\n ),\n dummyPaymasterAndData: EthBytesStruct,\n dummySignature: EthBytesStruct,\n bundlerUrl: UrlStruct,\n});\n\nexport type EthBaseUserOperation = Infer<typeof EthBaseUserOperationStruct>;\n\nexport const EthUserOperationPatchStruct = object({\n paymasterAndData: EthBytesStruct,\n callGasLimit: exactOptional(EthUint256Struct),\n verificationGasLimit: exactOptional(EthUint256Struct),\n preVerificationGas: exactOptional(EthUint256Struct),\n});\n\nexport type EthUserOperationPatch = Infer<typeof EthUserOperationPatchStruct>;\n"]}
@@ -11,23 +11,11 @@ export declare enum EthMethod {
11
11
  SignTransaction = "eth_signTransaction",
12
12
  SignTypedDataV1 = "eth_signTypedData_v1",
13
13
  SignTypedDataV3 = "eth_signTypedData_v3",
14
- SignTypedDataV4 = "eth_signTypedData_v4"
15
- }
16
- /**
17
- * Supported Ethereum methods for ERC-4337 (Account Abstraction) accounts.
18
- */
19
- export declare enum EthErc4337Method {
14
+ SignTypedDataV4 = "eth_signTypedData_v4",
20
15
  PrepareUserOperation = "eth_prepareUserOperation",
21
16
  PatchUserOperation = "eth_patchUserOperation",
22
17
  SignUserOperation = "eth_signUserOperation"
23
18
  }
24
- /**
25
- * Supported Ethereum account types.
26
- */
27
- export declare enum EthAccountType {
28
- Eoa = "eip155:eoa",
29
- Erc4337 = "eip155:erc4337"
30
- }
31
19
  export declare const EthEoaAccountStruct: import("superstruct").Struct<{
32
20
  type: "eip155:eoa";
33
21
  id: string;
@@ -35,6 +23,10 @@ export declare const EthEoaAccountStruct: import("superstruct").Struct<{
35
23
  options: Record<string, import("@metamask/utils").Json>;
36
24
  methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
37
25
  }, {
26
+ /**
27
+ * Account address.
28
+ */
29
+ address: import("superstruct").Struct<string, null>;
38
30
  /**
39
31
  * Account type.
40
32
  */
@@ -51,7 +43,6 @@ export declare const EthEoaAccountStruct: import("superstruct").Struct<{
51
43
  eth_signTypedData_v4: "eth_signTypedData_v4";
52
44
  }>>;
53
45
  id: import("superstruct").Struct<string, null>;
54
- address: import("superstruct").Struct<string, null>;
55
46
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
56
47
  }>;
57
48
  export declare type EthEoaAccount = Infer<typeof EthEoaAccountStruct>;
@@ -62,6 +53,10 @@ export declare const EthErc4337AccountStruct: import("superstruct").Struct<{
62
53
  options: Record<string, import("@metamask/utils").Json>;
63
54
  methods: ("personal_sign" | "eth_sign" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
64
55
  }, {
56
+ /**
57
+ * Account address.
58
+ */
59
+ address: import("superstruct").Struct<string, null>;
65
60
  /**
66
61
  * Account type.
67
62
  */
@@ -80,7 +75,6 @@ export declare const EthErc4337AccountStruct: import("superstruct").Struct<{
80
75
  eth_signUserOperation: "eth_signUserOperation";
81
76
  }>>;
82
77
  id: import("superstruct").Struct<string, null>;
83
- address: import("superstruct").Struct<string, null>;
84
78
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
85
79
  }>;
86
80
  export declare type EthErc4337Account = Infer<typeof EthErc4337AccountStruct>;
package/dist/eth/types.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EthErc4337AccountStruct = exports.EthEoaAccountStruct = exports.EthAccountType = exports.EthErc4337Method = exports.EthMethod = exports.EthUint256Struct = exports.EthAddressStruct = exports.EthBytesStruct = void 0;
3
+ exports.EthErc4337AccountStruct = exports.EthEoaAccountStruct = exports.EthMethod = exports.EthUint256Struct = exports.EthAddressStruct = exports.EthBytesStruct = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
- const base_types_1 = require("../base-types");
5
+ const api_1 = require("../api");
6
6
  const superstruct_2 = require("../superstruct");
7
7
  exports.EthBytesStruct = (0, superstruct_2.definePattern)('EthBytes', /^0x[0-9a-f]*$/iu);
8
8
  exports.EthAddressStruct = (0, superstruct_2.definePattern)('EthAddress', /^0x[0-9a-f]{40}$/iu);
@@ -19,31 +19,21 @@ var EthMethod;
19
19
  EthMethod["SignTypedDataV1"] = "eth_signTypedData_v1";
20
20
  EthMethod["SignTypedDataV3"] = "eth_signTypedData_v3";
21
21
  EthMethod["SignTypedDataV4"] = "eth_signTypedData_v4";
22
- })(EthMethod = exports.EthMethod || (exports.EthMethod = {}));
23
- /**
24
- * Supported Ethereum methods for ERC-4337 (Account Abstraction) accounts.
25
- */
26
- var EthErc4337Method;
27
- (function (EthErc4337Method) {
28
22
  // ERC-4337 methods
29
- EthErc4337Method["PrepareUserOperation"] = "eth_prepareUserOperation";
30
- EthErc4337Method["PatchUserOperation"] = "eth_patchUserOperation";
31
- EthErc4337Method["SignUserOperation"] = "eth_signUserOperation";
32
- })(EthErc4337Method = exports.EthErc4337Method || (exports.EthErc4337Method = {}));
33
- /**
34
- * Supported Ethereum account types.
35
- */
36
- var EthAccountType;
37
- (function (EthAccountType) {
38
- EthAccountType["Eoa"] = "eip155:eoa";
39
- EthAccountType["Erc4337"] = "eip155:erc4337";
40
- })(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
41
- exports.EthEoaAccountStruct = (0, superstruct_1.object)({
42
- ...base_types_1.BaseAccount,
23
+ EthMethod["PrepareUserOperation"] = "eth_prepareUserOperation";
24
+ EthMethod["PatchUserOperation"] = "eth_patchUserOperation";
25
+ EthMethod["SignUserOperation"] = "eth_signUserOperation";
26
+ })(EthMethod = exports.EthMethod || (exports.EthMethod = {}));
27
+ exports.EthEoaAccountStruct = (0, superstruct_2.object)({
28
+ ...api_1.KeyringAccountStruct.schema,
29
+ /**
30
+ * Account address.
31
+ */
32
+ address: exports.EthAddressStruct,
43
33
  /**
44
34
  * Account type.
45
35
  */
46
- type: (0, superstruct_1.literal)(`${EthAccountType.Eoa}`),
36
+ type: (0, superstruct_1.literal)(`${api_1.EthAccountType.Eoa}`),
47
37
  /**
48
38
  * Account supported methods.
49
39
  */
@@ -56,12 +46,16 @@ exports.EthEoaAccountStruct = (0, superstruct_1.object)({
56
46
  `${EthMethod.SignTypedDataV4}`,
57
47
  ])),
58
48
  });
59
- exports.EthErc4337AccountStruct = (0, superstruct_1.object)({
60
- ...base_types_1.BaseAccount,
49
+ exports.EthErc4337AccountStruct = (0, superstruct_2.object)({
50
+ ...api_1.KeyringAccountStruct.schema,
51
+ /**
52
+ * Account address.
53
+ */
54
+ address: exports.EthAddressStruct,
61
55
  /**
62
56
  * Account type.
63
57
  */
64
- type: (0, superstruct_1.literal)(`${EthAccountType.Erc4337}`),
58
+ type: (0, superstruct_1.literal)(`${api_1.EthAccountType.Erc4337}`),
65
59
  /**
66
60
  * Account supported methods.
67
61
  */
@@ -71,9 +65,9 @@ exports.EthErc4337AccountStruct = (0, superstruct_1.object)({
71
65
  `${EthMethod.SignTypedDataV1}`,
72
66
  `${EthMethod.SignTypedDataV3}`,
73
67
  `${EthMethod.SignTypedDataV4}`,
74
- `${EthErc4337Method.PrepareUserOperation}`,
75
- `${EthErc4337Method.PatchUserOperation}`,
76
- `${EthErc4337Method.SignUserOperation}`,
68
+ `${EthMethod.PrepareUserOperation}`,
69
+ `${EthMethod.PatchUserOperation}`,
70
+ `${EthMethod.SignUserOperation}`,
77
71
  ])),
78
72
  });
79
73
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/eth/types.ts"],"names":[],"mappings":";;;AACA,6CAA4D;AAE5D,8CAA4C;AAC5C,gDAA+C;AAElC,QAAA,cAAc,GAAG,IAAA,2BAAa,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAE9D,QAAA,gBAAgB,GAAG,IAAA,2BAAa,EAC3C,YAAY,EACZ,oBAAoB,CACrB,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,2BAAa,EAC3C,YAAY,EACZ,6BAA6B,CAC9B,CAAC;AAEF;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,0BAA0B;IAC1B,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CA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QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,gBAAgB,CAAC,oBAAoB,EAAE;QAC1C,GAAG,gBAAgB,CAAC,kBAAkB,EAAE;QACxC,GAAG,gBAAgB,CAAC,iBAAiB,EAAE;KACxC,CAAC,CACH;CACF,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { object, array, enums, literal } from 'superstruct';\n\nimport { BaseAccount } from '../base-types';\nimport { definePattern } from '../superstruct';\n\nexport const EthBytesStruct = definePattern('EthBytes', /^0x[0-9a-f]*$/iu);\n\nexport const EthAddressStruct = definePattern(\n 'EthAddress',\n /^0x[0-9a-f]{40}$/iu,\n);\n\nexport const EthUint256Struct = definePattern(\n 'EthUint256',\n /^0x([1-9a-f][0-9a-f]*|0)$/iu,\n);\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n // General signing methods\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n}\n\n/**\n * Supported Ethereum methods for ERC-4337 (Account Abstraction) accounts.\n */\nexport enum EthErc4337Method {\n // ERC-4337 methods\n PrepareUserOperation = 'eth_prepareUserOperation',\n PatchUserOperation = 'eth_patchUserOperation',\n SignUserOperation = 'eth_signUserOperation',\n}\n\n/**\n * Supported Ethereum account types.\n */\nexport enum EthAccountType {\n Eoa = 'eip155:eoa',\n Erc4337 = 'eip155:erc4337',\n}\n\nexport const EthEoaAccountStruct = object({\n ...BaseAccount,\n\n /**\n * Account type.\n */\n type: literal(`${EthAccountType.Eoa}`),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n});\n\nexport type EthEoaAccount = Infer<typeof EthEoaAccountStruct>;\n\nexport const EthErc4337AccountStruct = object({\n ...BaseAccount,\n\n /**\n * Account type.\n */\n type: literal(`${EthAccountType.Erc4337}`),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n `${EthErc4337Method.PrepareUserOperation}`,\n `${EthErc4337Method.PatchUserOperation}`,\n `${EthErc4337Method.SignUserOperation}`,\n ]),\n ),\n});\n\nexport type EthErc4337Account = Infer<typeof EthErc4337AccountStruct>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/eth/types.ts"],"names":[],"mappings":";;;AACA,6CAAoD;AAEpD,gCAA8D;AAC9D,gDAAuD;AAE1C,QAAA,cAAc,GAAG,IAAA,2BAAa,EAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAE9D,QAAA,gBAAgB,GAAG,IAAA,2BAAa,EAC3C,YAAY,EACZ,oBAAoB,CACrB,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAA,2BAAa,EAC3C,YAAY,EACZ,6BAA6B,CAC9B,CAAC;AAEF;;GAEG;AACH,IAAY,SAYX;AAZD,WAAY,SAAS;IACnB,0BAA0B;IAC1B,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,mBAAmB;IACnB,8DAAiD,CAAA;IACjD,0DAA6C,CAAA;IAC7C,wDAA2C,CAAA;AAC7C,CAAC,EAZW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAYpB;AAEY,QAAA,mBAAmB,GAAG,IAAA,oBAAM,EAAC;IACxC,GAAG,0BAAoB,CAAC,MAAM;IAE9B;;OAEG;IACH,OAAO,EAAE,wBAAgB;IAEzB;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,GAAG,EAAE,CAAC;IAEtC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EACZ,IAAA,mBAAK,EAAC;QACJ,GAAG,SAAS,CAAC,YAAY,EAAE;QAC3B,GAAG,SAAS,CAAC,IAAI,EAAE;QACnB,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;KAC/B,CAAC,CACH;CACF,CAAC,CAAC;AAIU,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,GAAG,0BAAoB,CAAC,MAAM;IAE9B;;OAEG;IACH,OAAO,EAAE,wBAAgB;IAEzB;;OAEG;IACH,IAAI,EAAE,IAAA,qBAAO,EAAC,GAAG,oBAAc,CAAC,OAAO,EAAE,CAAC;IAE1C;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EACZ,IAAA,mBAAK,EAAC;QACJ,GAAG,SAAS,CAAC,YAAY,EAAE;QAC3B,GAAG,SAAS,CAAC,IAAI,EAAE;QACnB,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,oBAAoB,EAAE;QACnC,GAAG,SAAS,CAAC,kBAAkB,EAAE;QACjC,GAAG,SAAS,CAAC,iBAAiB,EAAE;KACjC,CAAC,CACH;CACF,CAAC,CAAC","sourcesContent":["import type { Infer } from 'superstruct';\nimport { array, enums, literal } from 'superstruct';\n\nimport { EthAccountType, KeyringAccountStruct } from '../api';\nimport { object, definePattern } from '../superstruct';\n\nexport const EthBytesStruct = definePattern('EthBytes', /^0x[0-9a-f]*$/iu);\n\nexport const EthAddressStruct = definePattern(\n 'EthAddress',\n /^0x[0-9a-f]{40}$/iu,\n);\n\nexport const EthUint256Struct = definePattern(\n 'EthUint256',\n /^0x([1-9a-f][0-9a-f]*|0)$/iu,\n);\n\n/**\n * Supported Ethereum methods.\n */\nexport enum EthMethod {\n // General signing methods\n PersonalSign = 'personal_sign',\n Sign = 'eth_sign',\n SignTransaction = 'eth_signTransaction',\n SignTypedDataV1 = 'eth_signTypedData_v1',\n SignTypedDataV3 = 'eth_signTypedData_v3',\n SignTypedDataV4 = 'eth_signTypedData_v4',\n // ERC-4337 methods\n PrepareUserOperation = 'eth_prepareUserOperation',\n PatchUserOperation = 'eth_patchUserOperation',\n SignUserOperation = 'eth_signUserOperation',\n}\n\nexport const EthEoaAccountStruct = object({\n ...KeyringAccountStruct.schema,\n\n /**\n * Account address.\n */\n address: EthAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${EthAccountType.Eoa}`),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTransaction}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n ]),\n ),\n});\n\nexport type EthEoaAccount = Infer<typeof EthEoaAccountStruct>;\n\nexport const EthErc4337AccountStruct = object({\n ...KeyringAccountStruct.schema,\n\n /**\n * Account address.\n */\n address: EthAddressStruct,\n\n /**\n * Account type.\n */\n type: literal(`${EthAccountType.Erc4337}`),\n\n /**\n * Account supported methods.\n */\n methods: array(\n enums([\n `${EthMethod.PersonalSign}`,\n `${EthMethod.Sign}`,\n `${EthMethod.SignTypedDataV1}`,\n `${EthMethod.SignTypedDataV3}`,\n `${EthMethod.SignTypedDataV4}`,\n `${EthMethod.PrepareUserOperation}`,\n `${EthMethod.PatchUserOperation}`,\n `${EthMethod.SignUserOperation}`,\n ]),\n ),\n});\n\nexport type EthErc4337Account = Infer<typeof EthErc4337AccountStruct>;\n"]}
@@ -1,7 +1,8 @@
1
- import type { InternalAccountType } from '../internal';
1
+ import type { KeyringAccountType } from '../api';
2
2
  /**
3
3
  * Checks if the given type is an EVM account type.
4
+ *
4
5
  * @param type - The type to check.
5
6
  * @returns Returns true if the type is an EVM account type, false otherwise.
6
7
  */
7
- export declare function isEvmAccountType(type: InternalAccountType | string): boolean;
8
+ export declare function isEvmAccountType(type: KeyringAccountType): boolean;
package/dist/eth/utils.js CHANGED
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isEvmAccountType = void 0;
4
- const types_1 = require("./types");
4
+ const api_1 = require("../api");
5
5
  /**
6
6
  * Checks if the given type is an EVM account type.
7
+ *
7
8
  * @param type - The type to check.
8
9
  * @returns Returns true if the type is an EVM account type, false otherwise.
9
10
  */
10
11
  function isEvmAccountType(type) {
11
- return type === types_1.EthAccountType.Eoa || type === types_1.EthAccountType.Erc4337;
12
+ return type === api_1.EthAccountType.Eoa || type === api_1.EthAccountType.Erc4337;
12
13
  }
13
14
  exports.isEvmAccountType = isEvmAccountType;
14
15
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/eth/utils.ts"],"names":[],"mappings":";;;AACA,mCAAyC;AAEzC;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,IAAkC;IACjE,OAAO,IAAI,KAAK,sBAAc,CAAC,GAAG,IAAI,IAAI,KAAK,sBAAc,CAAC,OAAO,CAAC;AACxE,CAAC;AAFD,4CAEC","sourcesContent":["import type { InternalAccountType } from '../internal';\nimport { EthAccountType } from './types';\n\n/**\n * Checks if the given type is an EVM account type.\n * @param type - The type to check.\n * @returns Returns true if the type is an EVM account type, false otherwise.\n */\nexport function isEvmAccountType(type: InternalAccountType | string): boolean {\n return type === EthAccountType.Eoa || type === EthAccountType.Erc4337;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/eth/utils.ts"],"names":[],"mappings":";;;AACA,gCAAwC;AAExC;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,IAAwB;IACvD,OAAO,IAAI,KAAK,oBAAc,CAAC,GAAG,IAAI,IAAI,KAAK,oBAAc,CAAC,OAAO,CAAC;AACxE,CAAC;AAFD,4CAEC","sourcesContent":["import type { KeyringAccountType } from '../api';\nimport { EthAccountType } from '../api';\n\n/**\n * Checks if the given type is an EVM account type.\n *\n * @param type - The type to check.\n * @returns Returns true if the type is an EVM account type, false otherwise.\n */\nexport function isEvmAccountType(type: KeyringAccountType): boolean {\n return type === EthAccountType.Eoa || type === EthAccountType.Erc4337;\n}\n"]}