snap_getEntropy
Description
Get a deterministic 256-bit entropy value, specific to the Snap and the user's account. You can use this entropy to generate a private key, or any other value that requires a high level of randomness. Other Snaps can't access this entropy, and it changes if the user's secret recovery phrase changes.
You can optionally specify a salt to generate different entropy for different purposes. Using a salt results in entropy unrelated to the entropy generated without a salt.
This value is deterministic: it's always the same for the same Snap, user account, and salt.
Parameters
The request parameters for the snap_getEntropy method.
version
1The version of the entropy to retrieve. This is reserved for future use, and as of now, only version 1 is supported.
salt
string | nullAn arbitrary string to be used as a salt for the entropy. This can be used to generate different entropy for different purposes.
source
string | nullThe ID of the entropy source to use. If not specified, the primary entropy
source will be used. For a list of available entropy sources, see the
snap_listEntropySources method.
Returns
The entropy as a hexadecimal string.
Example
- Manifest
- Usage
{
"initialPermissions": {
"snap_getEntropy": {}
}
}
const entropy = await snap.request({
method: "snap_getEntropy",
params: {
version: 1,
salt: "foo", // Optional.
},
});
// '0x...'
console.log(entropy);