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AC;IAC1D,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,0BAA0B,EAAE,CAAC;IAC7D,MAAM,EAAE,MAAM,CAAC;QACb;;WAEG;QACH,YAAY,EAAE,MAAM;QAClB;;WAEG;QACH,eAAe;QAEf;;WAEG;QACH,KAAK,CAAC,iBAAiB,CAAC,CACzB;KACF,CAAC;CACH,CAAC,CAAC;AAOH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,MAAM,CAAC;IACvD,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY,CAAC,uBAAuB,EAAE,CAAC;IAC1D,MAAM,EAAE,MAAM,CAAC;QACb;;WAEG;QACH,MAAM,EAAE,MAAM;QACZ;;WAEG;QACH,eAAe;QAEf;;WAEG;QACH,MAAM,CAAC;YACL;;eAEG;YACH,KAAK,EAAE,KAAK,CAAC,uBAAuB,CAAC;YAErC;;eAEG;YACH,OAAO,EAAE,KAAK,CAAC,uBAAuB,CAAC;SACxC,CAAC,CACH;KACF,CAAC;CACH,CAAC,CAAC","sourcesContent":["import {\n  exactOptional,\n  object,\n  UuidStruct,\n  AccountIdStruct,\n} from '@metamask/keyring-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { array, boolean, literal, record, string } from '@metamask/superstruct';\nimport {\n  CaipAssetTypeStruct,\n  CaipAssetTypeOrIdStruct,\n  JsonStruct,\n} from '@metamask/utils';\n\nimport {\n  FungibleAssetAmountStruct,\n  KeyringAccountStruct,\n  TransactionStruct,\n  MetaMaskOptionsStruct,\n} from './api';\n\n/**\n * Supported keyring events.\n */\nexport enum KeyringEvent {\n  // Account events\n  AccountCreated = 'notify:accountCreated',\n  AccountUpdated = 'notify:accountUpdated',\n  AccountDeleted = 'notify:accountDeleted',\n\n  // Request events\n  RequestApproved = 'notify:requestApproved',\n  RequestRejected = 'notify:requestRejected',\n\n  // Assets related events\n  AccountBalancesUpdated = 'notify:accountBalancesUpdated',\n  AccountAssetListUpdated = 'notify:accountAssetListUpdated',\n  AccountTransactionsUpdated = 'notify:accountTransactionsUpdated',\n}\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     *\n     * **Note:** This is not guaranteed to be honored by the MetaMask client.\n     */\n    displayConfirmation: exactOptional(boolean()),\n\n    /**\n     * Instructs MetaMask to display the name confirmation dialog in the UI.\n     * Otherwise, the account will be added with the suggested name, if it's not\n     * already in use; if it is, a suffix will be appended to the name to make it\n     * unique.\n     *\n     * **Note:** This is not guaranteed to be honored by the MetaMask client.\n     */\n    displayAccountNameSuggestion: exactOptional(boolean()),\n\n    /**\n     * Metamask internal options.\n     */\n    ...MetaMaskOptionsStruct.schema,\n  }),\n});\nexport type AccountCreatedEvent = Infer<typeof AccountCreatedEventStruct>;\nexport type AccountCreatedEventPayload = AccountCreatedEvent['params'];\n\nexport const AccountUpdatedEventStruct = object({\n  method: literal(`${KeyringEvent.AccountUpdated}`),\n  params: object({\n    /**\n     * Updated account object.\n     */\n    account: KeyringAccountStruct,\n  }),\n});\nexport type AccountUpdatedEvent = Infer<typeof AccountUpdatedEventStruct>;\nexport type AccountUpdatedEventPayload = AccountUpdatedEvent['params'];\n\nexport const AccountDeletedEventStruct = object({\n  method: literal(`${KeyringEvent.AccountDeleted}`),\n  params: object({\n    /**\n     * Deleted account ID.\n     */\n    id: UuidStruct,\n  }),\n});\nexport type AccountDeletedEvent = Infer<typeof AccountDeletedEventStruct>;\nexport type AccountDeletedEventPayload = AccountDeletedEvent['params'];\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});\nexport type RequestApprovedEvent = Infer<typeof RequestApprovedEventStruct>;\nexport type RequestApprovedEventPayload = RequestApprovedEvent['params'];\n\nexport const RequestRejectedEventStruct = object({\n  method: literal(`${KeyringEvent.RequestRejected}`),\n  params: object({\n    /**\n     * Request ID.\n     */\n    id: UuidStruct,\n  }),\n});\nexport type RequestRejectedEvent = Infer<typeof RequestRejectedEventStruct>;\nexport type RequestRejectedEventPayload = RequestRejectedEvent['params'];\n\n// Assets related events:\n// -----------------------------------------------------------------------------------------------\n\n/**\n * Event emitted when the balances of an account are updated.\n *\n * Only changes are reported.\n *\n * The Snap can choose to emit this event for multiple accounts at once.\n */\nexport const AccountBalancesUpdatedEventStruct = object({\n  method: literal(`${KeyringEvent.AccountBalancesUpdated}`),\n  params: object({\n    /**\n     * Balances updates of accounts owned by the Snap.\n     */\n    balances: record(\n      /**\n       * Account ID.\n       */\n      AccountIdStruct,\n\n      /**\n       * Mapping of each owned assets and their respective balances for that account.\n       */\n      record(\n        /**\n         * Asset type (CAIP-19).\n         */\n        CaipAssetTypeStruct,\n\n        /**\n         * Balance information for a given asset.\n         */\n        FungibleAssetAmountStruct,\n      ),\n    ),\n  }),\n});\nexport type AccountBalancesUpdatedEvent = Infer<\n  typeof AccountBalancesUpdatedEventStruct\n>;\nexport type AccountBalancesUpdatedEventPayload =\n  AccountBalancesUpdatedEvent['params'];\n\n/**\n * Event emitted when the transactions of an account are updated (added or\n * changed).\n *\n * Only changes are reported.\n *\n * The Snap can choose to emit this event for multiple accounts at once.\n */\nexport const AccountTransactionsUpdatedEventStruct = object({\n  method: literal(`${KeyringEvent.AccountTransactionsUpdated}`),\n  params: object({\n    /**\n     * Transactions updates of accounts owned by the Snap.\n     */\n    transactions: record(\n      /**\n       * Account ID.\n       */\n      AccountIdStruct,\n\n      /**\n       * List of updated transactions for that account.\n       */\n      array(TransactionStruct),\n    ),\n  }),\n});\nexport type AccountTransactionsUpdatedEvent = Infer<\n  typeof AccountTransactionsUpdatedEventStruct\n>;\nexport type AccountTransactionsUpdatedEventPayload =\n  AccountTransactionsUpdatedEvent['params'];\n\n/**\n * Event emitted when the assets of an account are updated.\n *\n * Only changes are reported.\n *\n * The Snap can choose to emit this event for multiple accounts at once.\n */\nexport const AccountAssetListUpdatedEventStruct = object({\n  method: literal(`${KeyringEvent.AccountAssetListUpdated}`),\n  params: object({\n    /**\n     * Asset list update of accounts owned by the Snap.\n     */\n    assets: record(\n      /**\n       * Account ID.\n       */\n      AccountIdStruct,\n\n      /**\n       * Asset list changes for that account.\n       */\n      object({\n        /**\n         * New assets detected.\n         */\n        added: array(CaipAssetTypeOrIdStruct),\n\n        /**\n         * Assets no longer available on that account.\n         */\n        removed: array(CaipAssetTypeOrIdStruct),\n      }),\n    ),\n  }),\n});\nexport type AccountAssetListUpdatedEvent = Infer<\n  typeof AccountAssetListUpdatedEventStruct\n>;\nexport type AccountAssetListUpdatedEventPayload =\n  AccountAssetListUpdatedEvent['params'];\n\n/**\n * Keyring events.\n */\n// For some reason, eslint sometimes infer one of those members as `any`...\ntype KeyringEvents =\n  | AccountCreatedEvent\n  | AccountUpdatedEvent\n  | AccountDeletedEvent\n  | AccountAssetListUpdatedEvent\n  | AccountBalancesUpdatedEvent\n  | AccountTransactionsUpdatedEvent\n  | RequestApprovedEvent\n  | RequestRejectedEvent;\n\n/**\n * Extract the payload for a given `KeyringEvent` event.\n */\nexport type KeyringEventPayload<Event extends KeyringEvent> = Extract<\n  KeyringEvents,\n  // We need to use a literal string here, since that is what `KeyringEvents`\n  // is using (probably because of `superstruct`.\n  { method: `${Event}` }\n>['params'];\n"]}