@metamask/keyring-api 8.1.3 → 9.0.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 (56) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/JsonRpcRequest.d.ts +1 -1
  3. package/dist/KeyringClient.d.ts +1 -1
  4. package/dist/KeyringClient.js.map +1 -1
  5. package/dist/KeyringSnapRpcClient.js.map +1 -1
  6. package/dist/api/account.d.ts +2 -2
  7. package/dist/api/account.js +2 -2
  8. package/dist/api/account.js.map +1 -1
  9. package/dist/api/balance.d.ts +1 -1
  10. package/dist/api/caip.d.ts +2 -2
  11. package/dist/api/export.d.ts +1 -1
  12. package/dist/api/index.d.ts +1 -1
  13. package/dist/api/index.js +0 -1
  14. package/dist/api/index.js.map +1 -1
  15. package/dist/api/keyring.d.ts +1 -1
  16. package/dist/api/request.d.ts +1 -1
  17. package/dist/api/response.d.ts +1 -1
  18. package/dist/btc/types.d.ts +5 -5
  19. package/dist/btc/types.js +3 -3
  20. package/dist/btc/types.js.map +1 -1
  21. package/dist/contexts.d.ts +1 -1
  22. package/dist/eth/erc4337/types.d.ts +5 -4
  23. package/dist/eth/erc4337/types.js +1 -0
  24. package/dist/eth/erc4337/types.js.map +1 -1
  25. package/dist/eth/types.d.ts +2 -2
  26. package/dist/eth/types.js +1 -1
  27. package/dist/eth/types.js.map +1 -1
  28. package/dist/events.js +1 -1
  29. package/dist/events.js.map +1 -1
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +0 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/internal/api.d.ts +26 -26
  34. package/dist/internal/api.js +1 -1
  35. package/dist/internal/api.js.map +1 -1
  36. package/dist/internal/eth/EthKeyring.d.ts +1 -1
  37. package/dist/internal/eth/index.d.ts +1 -1
  38. package/dist/internal/eth/index.js +0 -15
  39. package/dist/internal/eth/index.js.map +1 -1
  40. package/dist/internal/index.d.ts +1 -1
  41. package/dist/internal/index.js +0 -1
  42. package/dist/internal/index.js.map +1 -1
  43. package/dist/internal/rpc.js +1 -1
  44. package/dist/internal/rpc.js.map +1 -1
  45. package/dist/internal/types.d.ts +40 -43
  46. package/dist/internal/types.js +12 -15
  47. package/dist/internal/types.js.map +1 -1
  48. package/dist/rpc-handler.js +13 -13
  49. package/dist/rpc-handler.js.map +1 -1
  50. package/dist/superstruct.d.ts +4 -4
  51. package/dist/superstruct.js.map +1 -1
  52. package/dist/utils/types.d.ts +1 -1
  53. package/dist/utils/types.js +1 -1
  54. package/dist/utils/types.js.map +1 -1
  55. package/dist/utils/typing.d.ts +2 -2
  56. package/package.json +7 -6
@@ -27,70 +27,70 @@ async function dispatchRequest(keyring, request) {
27
27
  // we can check its method name.
28
28
  (0, superstruct_1.assert)(request, JsonRpcRequest_1.JsonRpcRequestStruct);
29
29
  switch (request.method) {
30
- case rpc_1.KeyringRpcMethod.ListAccounts: {
30
+ case `${rpc_1.KeyringRpcMethod.ListAccounts}`: {
31
31
  (0, superstruct_1.assert)(request, api_1.ListAccountsRequestStruct);
32
32
  return keyring.listAccounts();
33
33
  }
34
- case rpc_1.KeyringRpcMethod.GetAccount: {
34
+ case `${rpc_1.KeyringRpcMethod.GetAccount}`: {
35
35
  (0, superstruct_1.assert)(request, api_1.GetAccountRequestStruct);
36
36
  return keyring.getAccount(request.params.id);
37
37
  }
38
- case rpc_1.KeyringRpcMethod.CreateAccount: {
38
+ case `${rpc_1.KeyringRpcMethod.CreateAccount}`: {
39
39
  (0, superstruct_1.assert)(request, api_1.CreateAccountRequestStruct);
40
40
  return keyring.createAccount(request.params.options);
41
41
  }
42
- case rpc_1.KeyringRpcMethod.GetAccountBalances: {
42
+ case `${rpc_1.KeyringRpcMethod.GetAccountBalances}`: {
43
43
  if (keyring.getAccountBalances === undefined) {
44
44
  throw new MethodNotSupportedError(request.method);
45
45
  }
46
46
  (0, superstruct_1.assert)(request, api_1.GetAccountBalancesRequestStruct);
47
47
  return keyring.getAccountBalances(request.params.id, request.params.assets);
48
48
  }
49
- case rpc_1.KeyringRpcMethod.FilterAccountChains: {
49
+ case `${rpc_1.KeyringRpcMethod.FilterAccountChains}`: {
50
50
  (0, superstruct_1.assert)(request, api_1.FilterAccountChainsStruct);
51
51
  return keyring.filterAccountChains(request.params.id, request.params.chains);
52
52
  }
53
- case rpc_1.KeyringRpcMethod.UpdateAccount: {
53
+ case `${rpc_1.KeyringRpcMethod.UpdateAccount}`: {
54
54
  (0, superstruct_1.assert)(request, api_1.UpdateAccountRequestStruct);
55
55
  return keyring.updateAccount(request.params.account);
56
56
  }
57
- case rpc_1.KeyringRpcMethod.DeleteAccount: {
57
+ case `${rpc_1.KeyringRpcMethod.DeleteAccount}`: {
58
58
  (0, superstruct_1.assert)(request, api_1.DeleteAccountRequestStruct);
59
59
  return keyring.deleteAccount(request.params.id);
60
60
  }
61
- case rpc_1.KeyringRpcMethod.ExportAccount: {
61
+ case `${rpc_1.KeyringRpcMethod.ExportAccount}`: {
62
62
  if (keyring.exportAccount === undefined) {
63
63
  throw new MethodNotSupportedError(request.method);
64
64
  }
65
65
  (0, superstruct_1.assert)(request, api_1.ExportAccountRequestStruct);
66
66
  return keyring.exportAccount(request.params.id);
67
67
  }
68
- case rpc_1.KeyringRpcMethod.ListRequests: {
68
+ case `${rpc_1.KeyringRpcMethod.ListRequests}`: {
69
69
  if (keyring.listRequests === undefined) {
70
70
  throw new MethodNotSupportedError(request.method);
71
71
  }
72
72
  (0, superstruct_1.assert)(request, api_1.ListRequestsRequestStruct);
73
73
  return keyring.listRequests();
74
74
  }
75
- case rpc_1.KeyringRpcMethod.GetRequest: {
75
+ case `${rpc_1.KeyringRpcMethod.GetRequest}`: {
76
76
  if (keyring.getRequest === undefined) {
77
77
  throw new MethodNotSupportedError(request.method);
78
78
  }
79
79
  (0, superstruct_1.assert)(request, api_1.GetRequestRequestStruct);
80
80
  return keyring.getRequest(request.params.id);
81
81
  }
82
- case rpc_1.KeyringRpcMethod.SubmitRequest: {
82
+ case `${rpc_1.KeyringRpcMethod.SubmitRequest}`: {
83
83
  (0, superstruct_1.assert)(request, api_1.SubmitRequestRequestStruct);
84
84
  return keyring.submitRequest(request.params);
85
85
  }
86
- case rpc_1.KeyringRpcMethod.ApproveRequest: {
86
+ case `${rpc_1.KeyringRpcMethod.ApproveRequest}`: {
87
87
  if (keyring.approveRequest === undefined) {
88
88
  throw new MethodNotSupportedError(request.method);
89
89
  }
90
90
  (0, superstruct_1.assert)(request, api_1.ApproveRequestRequestStruct);
91
91
  return keyring.approveRequest(request.params.id, request.params.data);
92
92
  }
93
- case rpc_1.KeyringRpcMethod.RejectRequest: {
93
+ case `${rpc_1.KeyringRpcMethod.RejectRequest}`: {
94
94
  if (keyring.rejectRequest === undefined) {
95
95
  throw new MethodNotSupportedError(request.method);
96
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rpc-handler.js","sourceRoot":"","sources":["../src/rpc-handler.ts"],"names":[],"mappings":";;;AAAA,uDAA+C;AAI/C,wCAcwB;AACxB,wCAAkD;AAElD,qDAAwD;AAExD;;GAEG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,MAAc;QACxB,KAAK,CAAC,yBAAyB,MAAM,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF;AAJD,0DAIC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,OAAgB,EAChB,OAAuB;IAEvB,6EAA6E;IAC7E,gCAAgC;IAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,qCAAoB,CAAC,CAAC;IAEtC,QAAQ,OAAO,CAAC,MAAM,EAAE;QACtB,KAAK,sBAAgB,CAAC,YAAY,CAAC,CAAC;YAClC,IAAA,oBAAM,EAAC,OAAO,EAAE,+BAAyB,CAAC,CAAC;YAC3C,OAAO,OAAO,CAAC,YAAY,EAAE,CAAC;SAC/B;QAED,KAAK,sBAAgB,CAAC,UAAU,CAAC,CAAC;YAChC,IAAA,oBAAM,EAAC,OAAO,EAAE,6BAAuB,CAA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AO,EAAE,iCAA2B,CAAC,CAAC;YAC7C,OAAO,OAAO,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACvE;QAED,KAAK,sBAAgB,CAAC,aAAa,CAAC,CAAC;YACnC,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE;gBACvC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;aACnD;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;SACjD;QAED,OAAO,CAAC,CAAC;YACP,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;SACnD;KACF;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAgB,EAChB,OAAuB;IAEvB,IAAI;QACF,OAAO,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAChD;IAAC,OAAO,KAAK,EAAE;QACd,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;YACzD,CAAC,CAAC,KAAK,CAAC,OAAO;YACf,CAAC,CAAC,8DAA8D,CAAC;QAErE,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;AACH,CAAC;AAdD,oDAcC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case KeyringRpcMethod.ListAccounts: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case KeyringRpcMethod.GetAccount: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case KeyringRpcMethod.CreateAccount: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case KeyringRpcMethod.GetAccountBalances: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case KeyringRpcMethod.FilterAccountChains: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case KeyringRpcMethod.UpdateAccount: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case KeyringRpcMethod.DeleteAccount: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ExportAccount: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case KeyringRpcMethod.ListRequests: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case KeyringRpcMethod.GetRequest: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case KeyringRpcMethod.SubmitRequest: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case KeyringRpcMethod.ApproveRequest: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case KeyringRpcMethod.RejectRequest: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
1
+ {"version":3,"file":"rpc-handler.js","sourceRo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Aa,EAAE,CAAC,CAAC,CAAC;YACzC,IAAI,OAAO,CAAC,aAAa,KAAK,SAAS,EAAE,CAAC;gBACxC,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACpD,CAAC;YACD,IAAA,oBAAM,EAAC,OAAO,EAAE,gCAA0B,CAAC,CAAC;YAC5C,OAAO,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,CAAC,CAAC,CAAC;YACR,MAAM,IAAI,uBAAuB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,oBAAoB,CACxC,OAAgB,EAChB,OAAuB;IAEvB,IAAI,CAAC;QACH,OAAO,MAAM,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,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;IAC3B,CAAC;AACH,CAAC;AAdD,oDAcC","sourcesContent":["import { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\n\nimport type { Keyring } from './api';\nimport {\n GetAccountRequestStruct,\n CreateAccountRequestStruct,\n ApproveRequestRequestStruct,\n DeleteAccountRequestStruct,\n ExportAccountRequestStruct,\n GetRequestRequestStruct,\n RejectRequestRequestStruct,\n SubmitRequestRequestStruct,\n UpdateAccountRequestStruct,\n FilterAccountChainsStruct,\n ListAccountsRequestStruct,\n ListRequestsRequestStruct,\n GetAccountBalancesRequestStruct,\n} from './internal/api';\nimport { KeyringRpcMethod } from './internal/rpc';\nimport type { JsonRpcRequest } from './JsonRpcRequest';\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\n\n/**\n * Error thrown when a keyring JSON-RPC method is not supported.\n */\nexport class MethodNotSupportedError extends Error {\n constructor(method: string) {\n super(`Method not supported: ${method}`);\n }\n}\n\n/**\n * Inner function that dispatches JSON-RPC request to the associated Keyring\n * methods.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n */\nasync function dispatchRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n // We first have to make sure that the request is a valid JSON-RPC request so\n // we can check its method name.\n assert(request, JsonRpcRequestStruct);\n\n switch (request.method) {\n case `${KeyringRpcMethod.ListAccounts}`: {\n assert(request, ListAccountsRequestStruct);\n return keyring.listAccounts();\n }\n\n case `${KeyringRpcMethod.GetAccount}`: {\n assert(request, GetAccountRequestStruct);\n return keyring.getAccount(request.params.id);\n }\n\n case `${KeyringRpcMethod.CreateAccount}`: {\n assert(request, CreateAccountRequestStruct);\n return keyring.createAccount(request.params.options);\n }\n\n case `${KeyringRpcMethod.GetAccountBalances}`: {\n if (keyring.getAccountBalances === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetAccountBalancesRequestStruct);\n return keyring.getAccountBalances(\n request.params.id,\n request.params.assets,\n );\n }\n\n case `${KeyringRpcMethod.FilterAccountChains}`: {\n assert(request, FilterAccountChainsStruct);\n return keyring.filterAccountChains(\n request.params.id,\n request.params.chains,\n );\n }\n\n case `${KeyringRpcMethod.UpdateAccount}`: {\n assert(request, UpdateAccountRequestStruct);\n return keyring.updateAccount(request.params.account);\n }\n\n case `${KeyringRpcMethod.DeleteAccount}`: {\n assert(request, DeleteAccountRequestStruct);\n return keyring.deleteAccount(request.params.id);\n }\n\n case `${KeyringRpcMethod.ExportAccount}`: {\n if (keyring.exportAccount === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ExportAccountRequestStruct);\n return keyring.exportAccount(request.params.id);\n }\n\n case `${KeyringRpcMethod.ListRequests}`: {\n if (keyring.listRequests === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ListRequestsRequestStruct);\n return keyring.listRequests();\n }\n\n case `${KeyringRpcMethod.GetRequest}`: {\n if (keyring.getRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, GetRequestRequestStruct);\n return keyring.getRequest(request.params.id);\n }\n\n case `${KeyringRpcMethod.SubmitRequest}`: {\n assert(request, SubmitRequestRequestStruct);\n return keyring.submitRequest(request.params);\n }\n\n case `${KeyringRpcMethod.ApproveRequest}`: {\n if (keyring.approveRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, ApproveRequestRequestStruct);\n return keyring.approveRequest(request.params.id, request.params.data);\n }\n\n case `${KeyringRpcMethod.RejectRequest}`: {\n if (keyring.rejectRequest === undefined) {\n throw new MethodNotSupportedError(request.method);\n }\n assert(request, RejectRequestRequestStruct);\n return keyring.rejectRequest(request.params.id);\n }\n\n default: {\n throw new MethodNotSupportedError(request.method);\n }\n }\n}\n\n/**\n * Handles a keyring JSON-RPC request.\n *\n * This function is meant to be used as a handler for Keyring JSON-RPC requests\n * in an Accounts Snap.\n *\n * @param keyring - Keyring instance.\n * @param request - Keyring JSON-RPC request.\n * @returns A promise that resolves to the keyring response.\n * @example\n * ```ts\n * export const onKeyringRequest: OnKeyringRequestHandler = async ({\n * origin,\n * request,\n * }) => {\n * return await handleKeyringRequest(keyring, request);\n * };\n * ```\n */\nexport async function handleKeyringRequest(\n keyring: Keyring,\n request: JsonRpcRequest,\n): Promise<Json | void> {\n try {\n return await dispatchRequest(keyring, request);\n } catch (error) {\n const message =\n error instanceof Error && typeof error.message === 'string'\n ? error.message\n : 'An unknown error occurred while handling the keyring request';\n\n throw new Error(message);\n }\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { Struct } from '@metamask/superstruct';
2
2
  import type { Infer, ObjectSchema, OmitBy, Optionalize, PickBy, Simplify } from '@metamask/superstruct';
3
3
  declare const ExactOptionalSymbol: unique symbol;
4
- export declare type ExactOptionalTag = {
4
+ export type ExactOptionalTag = {
5
5
  type: typeof ExactOptionalSymbol;
6
6
  };
7
7
  /**
@@ -13,7 +13,7 @@ export declare type ExactOptionalTag = {
13
13
  * // Bar = { a: string, b: number }
14
14
  * ```
15
15
  */
16
- export declare type ExcludeType<Obj, Type> = {
16
+ export type ExcludeType<Obj, Type> = {
17
17
  [K in keyof Obj]: Exclude<Obj[K], Type>;
18
18
  };
19
19
  /**
@@ -25,11 +25,11 @@ export declare type ExcludeType<Obj, Type> = {
25
25
  * // Bar = { a?: string; b: number}
26
26
  * ```
27
27
  */
28
- export declare type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
28
+ export type ExactOptionalize<Schema extends object> = OmitBy<Schema, ExactOptionalTag> & Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;
29
29
  /**
30
30
  * Infer a type from an superstruct object schema.
31
31
  */
32
- export declare type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
32
+ export type ObjectType<Schema extends ObjectSchema> = Simplify<ExactOptionalize<Optionalize<{
33
33
  [K in keyof Schema]: Infer<Schema[K]>;
34
34
  }>>>;
35
35
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAoD/B;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import {\n Struct,\n assert,\n define,\n object as stObject,\n} from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from '@metamask/superstruct';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
1
+ {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AAAA,uDAK+B;AAqD/B;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import {\n Struct,\n assert,\n define,\n object as stObject,\n} from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from '@metamask/superstruct';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
@@ -14,4 +14,4 @@ export declare const UrlStruct: import("@metamask/superstruct").Struct<string, n
14
14
  * A string which contains a positive float number.
15
15
  */
16
16
  export declare const StringNumberStruct: import("@metamask/superstruct").Struct<string, null>;
17
- export declare type StringNumber = Infer<typeof StringNumberStruct>;
17
+ export type StringNumber = Infer<typeof StringNumberStruct>;
@@ -18,7 +18,7 @@ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
18
18
  const url = new URL(value);
19
19
  return url.protocol === 'http:' || url.protocol === 'https:';
20
20
  }
21
- catch (_) {
21
+ catch {
22
22
  return false;
23
23
  }
24
24
  });
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,gDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI;QACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;KAC9D;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch (_) {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAE3D,gDAA+C;AAE/C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAEF;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,2BAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\n\nimport { definePattern } from '../superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n"]}
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>
8
8
  */
9
- export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
9
+ export type OmitUnion<Type, Key extends keyof any> = Type extends any ? Omit<Type, Key> : never;
10
10
  /**
11
11
  * Type that resolves to `true` if `Child` extends `Base`, otherwise `false`.
12
12
  *
@@ -16,7 +16,7 @@ export declare type OmitUnion<Type, Key extends keyof any> = Type extends any ?
16
16
  * type B = Extends<{a: string}, {a: string, b: string}>; // false
17
17
  * ```
18
18
  */
19
- export declare type Extends<Child, Base> = Child extends Base ? true : false;
19
+ export type Extends<Child, Base> = Child extends Base ? true : false;
20
20
  /**
21
21
  * Assert that a type extends `true`. It can be used, for example, to assert
22
22
  * that a given type extends another type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "8.1.3",
3
+ "version": "9.0.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -32,16 +32,16 @@
32
32
  "test:clean": "jest --clearCache",
33
33
  "test:source": "jest && jest-it-up",
34
34
  "test:types": "tsd",
35
- "test:verbose": "jest --verbose",
36
35
  "test:watch": "jest --watch"
37
36
  },
38
37
  "dependencies": {
39
- "@metamask/snaps-sdk": "^6.5.1",
38
+ "@metamask/snaps-sdk": "^6.7.0",
40
39
  "@metamask/superstruct": "^3.1.0",
41
40
  "@metamask/utils": "^9.2.1",
42
41
  "@types/uuid": "^9.0.8",
43
42
  "bech32": "^2.0.0",
44
- "uuid": "^9.0.1"
43
+ "uuid": "^9.0.1",
44
+ "webextension-polyfill": "^0.12.0"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@lavamoat/allow-scripts": "^3.2.1",
@@ -50,16 +50,17 @@
50
50
  "@metamask/providers": "^17.2.0",
51
51
  "@types/jest": "^29.5.12",
52
52
  "@types/node": "^20.12.12",
53
+ "@types/webextension-polyfill": "^0.12.1",
53
54
  "deepmerge": "^4.2.2",
54
55
  "depcheck": "^1.4.7",
55
56
  "jest": "^29.5.0",
56
57
  "jest-it-up": "^3.1.0",
57
- "rimraf": "^5.0.7",
58
+ "rimraf": "^5.0.10",
58
59
  "ts-jest": "^29.0.5",
59
60
  "ts-node": "^10.9.2",
60
61
  "tsd": "^0.31.0",
61
62
  "typedoc": "^0.25.13",
62
- "typescript": "~4.8.4"
63
+ "typescript": "~5.4.5"
63
64
  },
64
65
  "peerDependencies": {
65
66
  "@metamask/providers": "^17.2.0"