# Documentation Project: **Eth Keyring Controller** Link: https://github.com/MetaMask/KeyringController ## ChatGPT Generated documentation The `KeyringController` is a class that manages keyrings (collections of keys) and their associated data. It allows users to create, import, export, and delete keyrings and keys, as well as lock and unlock the keyrings. The `KeyringController` uses the ObservableStore class to store data and the `EventEmitter` class to emit events when data is updated. It also uses the `encryptor` module to encrypt and decrypt data. The `KeyringController` constructor takes an options object as an argument with the following optional properties: - `initState`: Initial state object for the observable store. - `keyringBuilders`: An array of keyring builders to use for creating keyrings. The default keyring builders are SimpleKeyring and HdKeyring. - `encryptor`: An object that has encrypt and decrypt functions for encrypting and decrypting data. The default is @metamask/browser-passworder. - `cacheEncryptionKey`: A boolean indicating whether the controller should cache an exported key for use in decrypting and encrypting data without a password. The default is `false`. The KeyringController has the following public methods: - `fullUpdate()`: Emits the update event and returns a Promise that resolves to the current state. - `createNewVaultAndKeychain(password)`: Destroys any old encrypted data, creates a new encrypted store with the given password, creates a new HD wallet with 1 account, and faucets that account on the testnet. - `createNewVaultAndRestore(password, seedPhrase)`: Destroys any old encrypted data, creates a new encrypted store with the given password, and creates a new HD wallet from the given seed phrase with 1 account. - `addNewKeyring(type, opts)`: Adds a new keyring of the given type with the given options. - `addKeyring(keyring)`: Adds the given keyring. - `removeKeyring(keyring)`: Removes the given keyring. - `getAccounts()`: Returns an array of all accounts. - `getAccountsForAllKeyrings()`: Returns an array of all accounts for all keyrings. - `getKeyringForAccount(account)`: Returns the keyring for the given account. - `getKeyringForType(keyringType)`: Returns the keyring for the given type. - `unlock(password)`: Unlocks the keyrings with the given password. - `lock()`: Locks the keyrings. - `clear()`: Clears all data. The `KeyringController` also has the following private methods: - `createFirstKeyTree()`: Creates a new HD wallet with 1 account. - `setUnlocked()`: Sets the state to indicate that the keyrings are unlocked. - `setLocked()`: Sets the state to indicate that the keyrings are locked. - `addKeyringToKeyrings(keyring)`: Adds the given keyring to the keyrings array. - `removeKeyringFromKeyrings(keyring)`: Removes the given keyring from the keyrings array.