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IAAA,qBAAO,EAAC,GAAG,wBAAgB,CAAC,aAAa,EAAE,CAAC;IACpD,MAAM,EAAE,8BAAoB;CAC7B,CAAC,CAAC;AAIU,QAAA,2BAA2B,GAAG,kBAAU,CAAC","sourcesContent":["import { object, exactOptional, UuidStruct } from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { array, literal, number, string, union } from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { KeyringAccountStruct } from '../../api/account';\nimport { KeyringRequestStruct } from '../../api/request';\nimport { CreateAccountOptionsStruct } from './create-account';\nimport {\n  ExportAccountOptionsStruct,\n  PrivateKeyExportedAccountStruct,\n} from './export-account';\nimport type { Keyring } from './keyring';\n\n/**\n * Keyring interface for keyring methods that can be invoked through\n * RPC calls.\n */\nexport type KeyringRpc = {\n  getAccount: Keyring['getAccount'];\n  getAccounts: Keyring['getAccounts'];\n  createAccounts: Keyring['createAccounts'];\n  deleteAccount: Keyring['deleteAccount'];\n  submitRequest: Keyring['submitRequest'];\n  exportAccount?: Keyring['exportAccount'];\n};\n\n/**\n * Keyring RPC methods used by the API.\n */\nexport const KeyringRpcMethod = {\n  GetAccounts: 'keyring_getAccounts',\n  CreateAccounts: 'keyring_createAccounts',\n  // Inherited from v1 (but method signatures may differ...):\n  // NOTE: We use literals here to avoid circular dependencies.\n  GetAccount: 'keyring_getAccount',\n  DeleteAccount: 'keyring_deleteAccount',\n  ExportAccount: 'keyring_exportAccount',\n  SubmitRequest: 'keyring_submitRequest',\n} as const;\n\n/**\n * Keyring RPC methods used by the API.\n */\nexport type KeyringRpcMethod =\n  (typeof KeyringRpcMethod)[keyof typeof KeyringRpcMethod];\n\n/**\n * Check if a method is a keyring RPC method (v2).\n *\n * @param method - Method to check.\n * @returns Whether the method is a keyring RPC method (v2).\n */\nexport function isKeyringRpcMethod(method: string): method is KeyringRpcMethod {\n  return Object.values(KeyringRpcMethod).includes(method as KeyringRpcMethod);\n}\n\n// ----------------------------------------------------------------------------\n\nconst CommonHeader = {\n  jsonrpc: literal('2.0'),\n  id: union([string(), number(), literal(null)]),\n};\n\n// ----------------------------------------------------------------------------\n// Get accounts\n\nexport const GetAccountsRequestStruct = object({\n  ...CommonHeader,\n  method: literal(`${KeyringRpcMethod.GetAccounts}`),\n});\n\nexport type GetAccountsRequest = Infer<typeof GetAccountsRequestStruct>;\n\nexport const GetAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type GetAccountsResponse = Infer<typeof GetAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Get account\n\nexport const GetAccountRequestStruct = object({\n  ...CommonHeader,\n  method: literal(`${KeyringRpcMethod.GetAccount}`),\n  params: object({\n    id: UuidStruct,\n  }),\n});\n\nexport type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;\n\nexport const GetAccountResponseStruct = KeyringAccountStruct;\n\nexport type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Create accounts\n\nexport const CreateAccountsRequestStruct = object({\n  ...CommonHeader,\n  method: literal(`${KeyringRpcMethod.CreateAccounts}`),\n  params: CreateAccountOptionsStruct,\n});\n\nexport type CreateAccountsRequest = Infer<typeof CreateAccountsRequestStruct>;\n\nexport const CreateAccountsResponseStruct = array(KeyringAccountStruct);\n\nexport type CreateAccountsResponse = Infer<typeof CreateAccountsResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Delete account\n\nexport const DeleteAccountRequestStruct = object({\n  ...CommonHeader,\n  method: literal(`${KeyringRpcMethod.DeleteAccount}`),\n  params: object({\n    id: UuidStruct,\n  }),\n});\n\nexport type DeleteAccountRequest = Infer<typeof DeleteAccountRequestStruct>;\n\nexport const DeleteAccountResponseStruct = literal(null);\n\nexport type DeleteAccountResponse = Infer<typeof DeleteAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Export account\n\nexport const ExportAccountRequestStruct = object({\n  ...CommonHeader,\n  method: literal(`${KeyringRpcMethod.ExportAccount}`),\n  params: object({\n    id: UuidStruct,\n    options: exactOptional(ExportAccountOptionsStruct),\n  }),\n});\n\nexport type ExportAccountRequest = Infer<typeof ExportAccountRequestStruct>;\n\nexport const ExportAccountResponseStruct = PrivateKeyExportedAccountStruct;\n\nexport type ExportAccountResponse = Infer<typeof ExportAccountResponseStruct>;\n\n// ----------------------------------------------------------------------------\n// Submit request\n\nexport const SubmitRequestRequestStruct = object({\n  ...CommonHeader,\n  method: literal(`${KeyringRpcMethod.SubmitRequest}`),\n  params: KeyringRequestStruct,\n});\n\nexport type SubmitRequestRequest = Infer<typeof SubmitRequestRequestStruct>;\n\nexport const SubmitRequestResponseStruct = JsonStruct;\n\nexport type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;\n\n// ----------------------------------------------------------------------------\n\n/**\n * Keyring RPC requests.\n */\nexport type KeyringRpcRequests =\n  | GetAccountsRequest\n  | GetAccountRequest\n  | CreateAccountsRequest\n  | DeleteAccountRequest\n  | ExportAccountRequest\n  | SubmitRequestRequest;\n\n/**\n * Extract the proper request type for a given `KeyringRpcMethod`.\n */\nexport type KeyringRpcRequest<RpcMethod extends KeyringRpcMethod> = Extract<\n  KeyringRpcRequests,\n  { method: `${RpcMethod}` }\n>;\n"]}