@zenchain-protocol/zazen v0.0.6
@zenchain-protocol/zazen
This Metamask snap, Zazen, is intended to store validator cloud access keys in an encrypted, secure manner within Metamask. In the future, it may be used to store other types of data. This snap was forked from the MetaMask manage-state example snap at version 2.2.2.
Snap manifest
Note: Using
snap_manageStaterequires thesnap_manageStatepermissions. Refer to the documentation for more information.
Along with other permissions, the manifest of this snap includes the snap_manageState permission:
{
"initialPermissions": {
"snap_manageState": {}
}
}This permission does not require any additional configuration.
Snap usage
The state is stored in the snap using the following structure:
type State = {
staking: {
nodeCloudAccessKeys: {
onFinality: {
accessKey: string;
secretKey: string;
workspaceId: string;
};
};
};
};This snap exposes an onRpcRequest handler, which supports the following JSON-RPC methods:
setState- Set the state to the provided parameters. This assumes the new state is an object using the above structure. The state is always stored encrypted.getState- Get the state from the snap. This returns the current state if one is set, or a default state otherwise. The state from the encrypted store is always retrieved.clearState- Reset the state to the default state. The state from the encrypted store is always cleared.
Encrypted storage requires MetaMask to be unlocked.
For more information, you can refer to the end-to-end tests.
Running the Snap Locally
Prerequisites
Make sure you have nvm (Node Version Manager) installed. If not, you can install it by following the instructions here.
Without Docker
Install the correct Node.js version:
nvm install nvm useThis will use the Node.js version specified in the
.nvmrcfile.Install the dependencies:
yarn installBuild the project:
yarn buildStart the Snap:
yarn startRun tests:
yarn test
With Docker
You can also build and run this snap locally using Docker.
Build the Docker image
Navigate to the directory containing the
Dockerfileand run:docker build -t zazen-snap .Run the Docker container
docker run -d -p 8014:8014 zazen-snap
This command will run the container and map port 8081 of the container to port 8081 of your host machine, allowing you to access the snap locally for testing.