flows
cifer-sdk API Reference v0.3.1
cifer-sdk API Reference / flows
flows
High-level orchestrated flows for common operations.
Remarks
Flows combine multiple primitives into complete operations and support two modes:
- Plan mode: Returns a plan with steps that would be executed
- Execute mode: Executes the flow using provided callbacks
Interfaces
CreateSecretResult
Defined in: flows/create-secret.ts:27
Result of createSecretAndWaitReady flow
Properties
secretId
secretId:
bigint
Defined in: flows/create-secret.ts:29
The new secret ID
state
state:
SecretState
Defined in: flows/create-secret.ts:31
The final secret state
RetrieveAndDecryptParams
Defined in: flows/decrypt-from-logs.ts:24
Parameters for retrieve-and-decrypt flow
Properties
secretId
secretId:
bigint
Defined in: flows/decrypt-from-logs.ts:26
Secret ID used for encryption
dataId
dataId:
`0x${string}`
Defined in: flows/decrypt-from-logs.ts:28
Data ID to retrieve
commitmentContract
commitmentContract:
`0x${string}`
Defined in: flows/decrypt-from-logs.ts:30
Contract address where the commitment is stored
storedAtBlock?
optionalstoredAtBlock:number
Defined in: flows/decrypt-from-logs.ts:32
Block number where the data was stored (optional - fetched if not provided)
skipIntegrityCheck?
optionalskipIntegrityCheck:boolean
Defined in: flows/decrypt-from-logs.ts:34
Skip integrity verification (default: false)
RetrieveAndDecryptResult
Defined in: flows/decrypt-from-logs.ts:40
Result of retrieveFromLogsThenDecrypt flow
Properties
decryptedMessage
decryptedMessage:
string
Defined in: flows/decrypt-from-logs.ts:42
The decrypted plaintext
secretId
secretId:
bigint
Defined in: flows/decrypt-from-logs.ts:44
The secret ID used
storedAtBlock
storedAtBlock:
number
Defined in: flows/decrypt-from-logs.ts:46
Block where the commitment was stored
EncryptThenCommitParams
Defined in: flows/encrypt-commit.ts:24
Parameters for encrypt-then-commit flow
Properties
secretId
secretId:
bigint
Defined in: flows/encrypt-commit.ts:26
Secret ID to use for encryption
plaintext
plaintext:
string
Defined in: flows/encrypt-commit.ts:28
The plaintext to encrypt
key
key:
`0x${string}`
Defined in: flows/encrypt-commit.ts:30
Key for the commitment (bytes32)
commitmentContract
commitmentContract:
`0x${string}`
Defined in: flows/encrypt-commit.ts:32
Contract address for storing the commitment
storeFunction?
optionalstoreFunction:AbiFunction
Defined in: flows/encrypt-commit.ts:34
Store function ABI (optional - uses default if not provided)
EncryptThenCommitResult
Defined in: flows/encrypt-commit.ts:40
Result of encryptThenPrepareCommitTx flow
Properties
cifer
cifer:
`0x${string}`
Defined in: flows/encrypt-commit.ts:42
The CIFER envelope
encryptedMessage
encryptedMessage:
`0x${string}`
Defined in: flows/encrypt-commit.ts:44
The encrypted message
txIntent
txIntent:
TxIntentWithMeta
Defined in: flows/encrypt-commit.ts:46
The prepared transaction intent
EncryptFileFlowParams
Defined in: flows/file-jobs.ts:25
Parameters for file encryption flow
Properties
secretId
secretId:
bigint
Defined in: flows/file-jobs.ts:27
Secret ID to use for encryption
file
file:
Blob|File
Defined in: flows/file-jobs.ts:29
The file to encrypt
EncryptFileFlowResult
Defined in: flows/file-jobs.ts:35
Result of file encryption flow
Properties
jobId
jobId:
string
Defined in: flows/file-jobs.ts:37
The job ID
job
job:
JobInfo
Defined in: flows/file-jobs.ts:39
Final job status
encryptedFile
encryptedFile:
Blob
Defined in: flows/file-jobs.ts:41
The encrypted file blob
DecryptFileFlowParams
Defined in: flows/file-jobs.ts:181
Parameters for file decryption flow
Properties
secretId
secretId:
bigint
Defined in: flows/file-jobs.ts:183
Secret ID used for encryption
file
file:
Blob|File
Defined in: flows/file-jobs.ts:185
The encrypted .cifer file
DecryptFileFlowResult
Defined in: flows/file-jobs.ts:191
Result of file decryption flow
Properties
jobId
jobId:
string
Defined in: flows/file-jobs.ts:193
The job ID
job
job:
JobInfo
Defined in: flows/file-jobs.ts:195
Final job status
decryptedFile
decryptedFile:
Blob
Defined in: flows/file-jobs.ts:197
The decrypted file blob
DecryptExistingFileFlowParams
Defined in: flows/file-jobs.ts:341
Parameters for decrypting from an existing encrypt job
Properties
secretId
secretId:
bigint
Defined in: flows/file-jobs.ts:343
Secret ID used for the original encryption
encryptJobId
encryptJobId:
string
Defined in: flows/file-jobs.ts:345
Job ID of the completed encrypt job
FlowStep
Defined in: flows/types.ts:24
A single step in a flow
Properties
id
id:
string
Defined in: flows/types.ts:26
Step identifier
description
description:
string
Defined in: flows/types.ts:28
Human-readable description
type
type:
"transaction"|"api_call"|"poll"|"read"|"compute"
Defined in: flows/types.ts:30
Step type
status
status:
StepStatus
Defined in: flows/types.ts:32
Current status
txIntent?
optionaltxIntent:TxIntent
Defined in: flows/types.ts:34
Transaction intent (for transaction steps)
result?
optionalresult:unknown
Defined in: flows/types.ts:36
Result data (after completion)
error?
optionalerror:Error
Defined in: flows/types.ts:38
Error (if failed)
FlowPlan
Defined in: flows/types.ts:44
Flow plan returned in plan mode
Properties
name
name:
string
Defined in: flows/types.ts:46
Flow name
description
description:
string
Defined in: flows/types.ts:48
Human-readable description
steps
steps:
FlowStep[]
Defined in: flows/types.ts:50
Ordered list of steps
estimatedDurationMs?
optionalestimatedDurationMs:number
Defined in: flows/types.ts:52
Estimated total duration (if known)
PollingStrategy
Defined in: flows/types.ts:58
Polling strategy configuration
Properties
intervalMs
intervalMs:
number
Defined in: flows/types.ts:60
Interval between polls in milliseconds
maxAttempts
maxAttempts:
number
Defined in: flows/types.ts:62
Maximum number of polling attempts
backoffMultiplier?
optionalbackoffMultiplier:number
Defined in: flows/types.ts:64
Backoff multiplier (default: 1 = no backoff)
maxIntervalMs?
optionalmaxIntervalMs:number
Defined in: flows/types.ts:66
Maximum interval (for exponential backoff)
FlowContext
Defined in: flows/types.ts:81
Flow context with all dependencies and callbacks
Properties
signer
signer:
SignerAdapter
Defined in: flows/types.ts:83
Signer for authentication
readClient
readClient:
ReadClient
Defined in: flows/types.ts:85
Read client for blockchain queries
blackboxUrl
blackboxUrl:
string
Defined in: flows/types.ts:87
Blackbox URL
chainId
chainId:
number
Defined in: flows/types.ts:89
Chain ID
controllerAddress?
optionalcontrollerAddress:`0x${string}`
Defined in: flows/types.ts:91
SecretsController address (optional - can be resolved from discovery)
txExecutor?
optionaltxExecutor:TxExecutor
Defined in: flows/types.ts:101
Transaction executor callback
Apps provide this to execute transaction intents. The SDK doesn't handle gas estimation or nonce management.
pollingStrategy?
optionalpollingStrategy:PollingStrategy
Defined in: flows/types.ts:106
Polling strategy for operations that require waiting
logger()?
optionallogger: (message) =>void
Defined in: flows/types.ts:111
Logger for progress updates
Parameters
message
string
Returns
void
abortSignal?
optionalabortSignal:AbortSignal
Defined in: flows/types.ts:116
Abort signal for cancellation
fetch()?
optionalfetch: (input,init?) =>Promise<Response>
Defined in: flows/types.ts:121
Custom fetch implementation
Parameters
input
RequestInfo | URL
init?
RequestInit
Returns
Promise<Response>
FlowOptions
Defined in: flows/types.ts:127
Options for flow execution
Properties
mode?
optionalmode:FlowMode
Defined in: flows/types.ts:133
Execution mode
- 'plan': Return a plan without executing
- 'execute': Execute the flow (requires txExecutor)
onStepProgress()?
optionalonStepProgress: (step) =>void
Defined in: flows/types.ts:138
Callback for step progress updates
Parameters
step
Returns
void
FlowResult
Defined in: flows/types.ts:144
Flow execution result
Type Parameters
T
T
Properties
success
success:
boolean
Defined in: flows/types.ts:146
Whether the flow completed successfully
plan
plan:
FlowPlan
Defined in: flows/types.ts:148
The flow plan (steps that were/would be executed)
data?
optionaldata:T
Defined in: flows/types.ts:150
Result data (if successful)
error?
optionalerror:Error
Defined in: flows/types.ts:152
Error (if failed)
receipts?
optionalreceipts:TransactionReceipt[]
Defined in: flows/types.ts:154
Transaction receipts (for flows that submit transactions)
Type Aliases
FlowMode
FlowMode =
"plan"|"execute"
Defined in: flows/types.ts:14
Flow execution mode
StepStatus
StepStatus =
"pending"|"in_progress"|"completed"|"failed"|"skipped"
Defined in: flows/types.ts:19
Flow step status
Variables
DEFAULT_POLLING_STRATEGY
constDEFAULT_POLLING_STRATEGY:PollingStrategy
Defined in: flows/types.ts:72
Default polling strategy
Functions
createSecretAndWaitReady()
createSecretAndWaitReady(
ctx,options?):Promise<FlowResult<CreateSecretResult>>
Defined in: flows/create-secret.ts:66
Create a new secret and wait until it's ready for use
This flow:
- Reads the secret creation fee
- Builds and executes the createSecret transaction
- Extracts the secret ID from the receipt
- Polls until isSyncing becomes false
Parameters
ctx
Flow context
options?
Flow options
Returns
Promise<FlowResult<CreateSecretResult>>
Flow result with secret ID and state
Example
// Plan mode - see what will happen
const plan = await createSecretAndWaitReady(ctx, { mode: 'plan' });
console.log('Steps:', plan.plan.steps.map(s => s.description));
// Execute mode - actually create the secret
const result = await createSecretAndWaitReady({
...ctx,
txExecutor: async (intent) => {
const hash = await wallet.sendTransaction(intent);
return { hash, waitReceipt: () => provider.waitForTransaction(hash) };
},
}, { mode: 'execute' });
console.log('Secret ID:', result.data.secretId);
console.log('Public key CID:', result.data.state.publicKeyCid);
retrieveFromLogsThenDecrypt()
retrieveFromLogsThenDecrypt(
ctx,params,options?):Promise<FlowResult<RetrieveAndDecryptResult>>
Defined in: flows/decrypt-from-logs.ts:76
Retrieve encrypted data from on-chain logs and decrypt it
This flow:
- Fetches commitment metadata (if block not provided)
- Retrieves cifer and encryptedMessage from event logs
- Verifies data integrity (optional)
- Decrypts the data using the blackbox
Parameters
ctx
Flow context
params
Retrieval and decryption parameters
options?
Flow options
Returns
Promise<FlowResult<RetrieveAndDecryptResult>>
Flow result with decrypted message
Example
const result = await retrieveFromLogsThenDecrypt(ctx, {
secretId: 123n,
dataId: '0x...',
commitmentContract: '0x...',
});
if (result.success) {
console.log('Decrypted:', result.data.decryptedMessage);
}
encryptThenPrepareCommitTx()
encryptThenPrepareCommitTx(
ctx,params,options?):Promise<FlowResult<EncryptThenCommitResult>>
Defined in: flows/encrypt-commit.ts:81
Encrypt data and prepare a transaction to store it on-chain
This flow:
- Encrypts the plaintext using the blackbox
- Validates the encrypted data sizes
- Builds a transaction intent for storing the commitment
Note: This flow returns a transaction intent that you can execute with your own wallet/provider.
Parameters
ctx
Flow context
params
Encryption and commitment parameters
options?
Flow options
Returns
Promise<FlowResult<EncryptThenCommitResult>>
Flow result with encrypted data and transaction intent
Example
const result = await encryptThenPrepareCommitTx(ctx, {
secretId: 123n,
plaintext: 'My secret data',
key: keccak256('my-key'),
commitmentContract: '0x...',
});
if (result.success) {
// Execute the transaction
const hash = await wallet.sendTransaction(result.data.txIntent);
console.log('Commitment stored:', hash);
}
encryptFileJobFlow()
encryptFileJobFlow(
ctx,params,options?):Promise<FlowResult<EncryptFileFlowResult>>
Defined in: flows/file-jobs.ts:57
Encrypt a file and download the result
This flow:
- Uploads the file for encryption
- Polls until the job completes
- Downloads the encrypted result
Parameters
ctx
Flow context
params
Encryption parameters
options?
Flow options
Returns
Promise<FlowResult<EncryptFileFlowResult>>
Flow result with encrypted file
decryptFileJobFlow()
decryptFileJobFlow(
ctx,params,options?):Promise<FlowResult<DecryptFileFlowResult>>
Defined in: flows/file-jobs.ts:213
Decrypt a file and download the result
This flow:
- Uploads the encrypted file for decryption
- Polls until the job completes
- Downloads the decrypted result (requires auth)
Parameters
ctx
Flow context
params
Decryption parameters
options?
Flow options
Returns
Promise<FlowResult<DecryptFileFlowResult>>
Flow result with decrypted file
decryptExistingFileJobFlow()
decryptExistingFileJobFlow(
ctx,params,options?):Promise<FlowResult<DecryptFileFlowResult>>
Defined in: flows/file-jobs.ts:356
Decrypt from an existing encrypt job and download the result
This flow:
- Creates a decrypt job from the existing encrypt job
- Polls until the job completes
- Downloads the decrypted result (requires auth)
Parameters
ctx
params
options?
Returns
Promise<FlowResult<DecryptFileFlowResult>>