keyring-controller
A module for managing key material for multiple crypto networks, called
"keyrings", useful for building and managing wallets.
Originally forked from the library to manage key material in MetaMask,
keyring-controller
has the additional goals of strict type safety, strong test
coverage, and greater cross-chain flexibility.
A KeyringController
has two main responsibilities:
- Generating keyrings and using them to sign messages and transactions
- Providing encrypted serialization and deserialization of secret material.
Installation
npm install @tallyho/keyring-controller --save
Usage
import KeyringController from "@tallyho/keyring-controller"
import SimpleKeyring from "eth-simple-keyring"
const persistedVaults: string[] = []
const keyringController = new KeyringController({
keyringTypes: [SimpleKeyring],
initState: { ... },
encryptor: {
encrypt: async (password: string, data: any) => {
return "encrypted!"
},
decrypt: async (password: string, cipherText: string) => {
return { foo: "bar" }
},
},
persistVault: async (encryptedVault: string) => {
persistedVaults.push(encryptedVault)
}
})
this.keyringController.on("newAccount", (address: string) => {
console.log(`New account created: ${address}`)
})
this.keyringController.on("removedAccount", handleThat)
Extension
To add new account types to a KeyringController
, just make sure it follows
the Keyring class protocol.
Methods
Currently the methods are heavily commented in the source, so
it's the best place to look until we aggregate it here as well.