@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
1 lines • 2.87 kB
Source Map (JSON)
{"version":3,"file":"manage-state.mjs","sourceRoot":"","sources":["../../../src/types/methods/manage-state.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,4CAAoB,CAAA;IACpB,wCAAgB,CAAA;IAChB,8CAAsB,CAAA;AACxB,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B","sourcesContent":["import type { Json } from '@metamask/utils';\n\nimport type { EnumToUnion } from '../../internals';\n\n/**\n * The operations that can be performed on the state.\n */\nexport enum ManageStateOperation {\n ClearState = 'clear',\n GetState = 'get',\n UpdateState = 'update',\n}\n\n/**\n * The `clear` operation, which deletes all stored state.\n */\nexport type ClearStateOperation = {\n /**\n * The literal string \"clear\" to indicate that this is a clear operation.\n */\n operation: EnumToUnion<ManageStateOperation.ClearState>;\n\n /**\n * Whether to use the encrypted or unencrypted state. Defaults to `true`\n * (encrypted). Encrypted state is only accessible when the wallet is\n * unlocked, while unencrypted state is accessible whether the wallet is\n * locked or unlocked. State can be cleared regardless of the wallet's lock\n * state, but this parameter determines which state is cleared.\n */\n encrypted?: boolean;\n};\n\n/**\n * The `get` operation, which retrieves the stored state.\n */\nexport type GetStateOperation = {\n /**\n * The literal string \"get\" to indicate that this is a get operation.\n */\n operation: EnumToUnion<ManageStateOperation.GetState>;\n\n /**\n * Whether to use the encrypted or unencrypted state. Defaults to `true`\n * (encrypted). Encrypted state is only accessible when the wallet is\n * unlocked, while unencrypted state is accessible whether the wallet is\n * locked or unlocked.\n */\n encrypted?: boolean;\n};\n\n/**\n * The `update` operation, which replaces the stored state with a new value.\n */\nexport type UpdateStateOperation = {\n /**\n * The literal string \"update\" to indicate that this is an update operation.\n */\n operation: EnumToUnion<ManageStateOperation.UpdateState>;\n\n /**\n * Whether to use the encrypted or unencrypted state. Defaults to `true`\n * (encrypted). Encrypted state is only accessible when the wallet is\n * unlocked, while unencrypted state is accessible whether the wallet is\n * locked or unlocked.\n */\n encrypted?: boolean;\n\n /**\n * The new state to store. Must be a JSON-serializable object.\n */\n newState: Record<string, Json>;\n};\n\n/**\n * An object containing the parameters for the `snap_manageState` method.\n */\nexport type ManageStateParams =\n | ClearStateOperation\n | GetStateOperation\n | UpdateStateOperation;\n\n/**\n * If the operation is `get`, the result is the state. Otherwise, the result is\n * `null`.\n */\nexport type ManageStateResult = Record<string, Json> | null;\n"]}