State Management API Reference
The State Management API enables your TERE applications to securely store and retrieve data within the Trusted Execution Environment. All stored data is encrypted at rest and in transit, with granular access controls to protect sensitive information.
Getting Started
Prerequisites
To use the State Management API, you need:
- The TERE SDK installed (
npm install @praecise/tere
) - A deployed TERE application (see the Runtime API)
How State is Used
State management in TERE works by:
- Your application code using the SDK calls state functions to store and retrieve data
- The TERE runtime securely encrypts the data before storage
- Access controls ensure only authorized code can access specific data
- All state operations are performed securely within the TEE
Working with State
The State Management API is primarily used through the TERE SDK. Here's how to use it:
Using State in TypeScript/JavaScript
For JavaScript or TypeScript applications, use the TERE SDK:
Client-side Usage
From your client application, you interact with state through function execution:
State API Reference
The following API is available within your code running in the TEE:
Retrieves a value from the secure state store by its key.
Parameters
key
: stringRequiredThe unique identifier for the state value
Returns
The retrieved value, or null if the key does not exist
Examples
Basic retrieval
Stores a value in the secure state store with the specified key.
Parameters
key
: stringRequiredThe unique identifier for the state value
value
: Uint8Array | string | objectRequiredThe value to store. Objects are automatically serialized to JSON.
callerId
: stringOptional caller ID for access control verification
Returns
Returns true if the operation was successful
Examples
Storing a value
Removes a value from the secure state store.
Parameters
key
: stringRequiredThe unique identifier for the state value to remove
callerId
: stringOptional caller ID for access control verification
Returns
Returns the removed value if the key was found, or null if the key did not exist
Examples
Removing a value
Checks if a key exists in the secure state store without retrieving its value.
Parameters
key
: stringRequiredThe key to check for existence
Returns
Returns true if the key exists, false otherwise
Examples
Checking if a key exists
Advanced Usage
Advanced Access Control
TERE provides access control for state values to restrict who can read or write specific data:
Advanced Batch Operations
For working with multiple state values efficiently:
Best Practices
- Use Namespaced Keys
Organize your state keys using a hierarchical namespace pattern (e.g.,
app:user:123:preferences
) to avoid key collisions and improve organization.javascript - Consistent Serialization
Use consistent serialization and deserialization methods (e.g., JSON.stringify/parse) for storing complex data structures.
javascript - Apply Access Control
Set appropriate access controls for sensitive data to ensure only authorized callers can read or modify it.
- Maintain State Versions
Include version information in stored data to help with schema migrations as your application evolves.
javascript