Account management Snap security guidelines
Refer to the following security guidelines when creating an account management Snap.
Do not add secret information to account objects
Ensure that you do not store any secret information in account objects, since they are exposed to dapps and MetaMask. For example:
-
❌ Do NOT do this:
const account: KeyringAccount = {
id: uuid(),
options: {
privateKey: "0x01234...78", // !!! DO NOT DO THIS !!!
},
address,
methods: [
EthMethod.PersonalSign,
EthMethod.Sign,
EthMethod.SignTransaction,
EthMethod.SignTypedDataV1,
EthMethod.SignTypedDataV3,
EthMethod.SignTypedDataV4,
],
type: EthAccountType.Eoa,
} -
✅ Do this instead:
Store any secret information that you need in the Snap's state:
await snap.request({
method: "snap_manageState",
params: {
operation: "update",
newState: {
// Your Snap's state here.
privateKey: "0x01234...78",
},
},
})
Limit the methods exposed to dapps
By default, MetaMask enforces the following restrictions on calling Account Management API methods on your Snap based on the caller origin:
| Method | MetaMask origin | Dapp origin |
|---|---|---|
keyring_listAccounts | ✅ | ✅ |
keyring_getAccount | ✅ | ✅ |
keyring_createAccount | ❌ | ✅ |
keyring_filterAccountChains | ✅ | ✅ |
keyring_updateAccount | ❌ | ✅ |
keyring_deleteAccount | ✅ | ✅ |
keyring_exportAccount | ❌ | ✅ |
keyring_listRequests | ✅ |