Skip to content

@flowsta/holochain

SDK for integrating Holochain apps with Flowsta Vault.

@flowsta/holochain provides functions for agent identity linking, Vault communication, and CAL-compliant backups. It wraps Flowsta Vault's IPC endpoints into a simple TypeScript API.

Installation

bash
npm install @flowsta/holochain

Agent Linking

linkFlowstaIdentity

Request an identity link from the user's Flowsta Vault:

typescript
import { linkFlowstaIdentity } from '@flowsta/holochain';

const result = await linkFlowstaIdentity({
  appName: 'ChessChain',
  clientId: 'flowsta_app_abc123',
  localAgentPubKey: myAgentKey,   // uhCAk... format
});

// Commit to your DHT
await appWebsocket.callZome({
  role_name: 'my-role',
  zome_name: 'agent_linking',
  fn_name: 'create_direct_link',
  payload: {
    other_agent: decodeHashFromBase64(result.payload.vaultAgentPubKey),
    other_signature: base64ToSignature(result.payload.vaultSignature),
  },
});

getFlowstaIdentity

Query linked agents on your DHT. Returns an array of linked agent public keys (as raw bytes):

typescript
import { getFlowstaIdentity } from '@flowsta/holochain';

const linkedAgents = await getFlowstaIdentity({
  appWebsocket,
  roleName: 'my-role',
  agentPubKey: someAgentKey, // Uint8Array from @holochain/client
});

// linkedAgents is Uint8Array[] - array of linked agent public keys
if (linkedAgents.length > 0) {
  console.log(`Linked to ${linkedAgents.length} Flowsta identities`);
}

getVaultStatus

Check if Vault is running and unlocked:

typescript
import { getVaultStatus } from '@flowsta/holochain';

const status = await getVaultStatus();
// { unlocked: boolean, version?: string, agentPubKey?: string }

revokeFlowstaIdentity

Notify Vault that a link has been revoked. Best-effort - if Vault is not running, returns { success: false } without throwing:

typescript
import { revokeFlowstaIdentity } from '@flowsta/holochain';

await revokeFlowstaIdentity({
  appName: 'ChessChain',
  localAgentPubKey: myAgentKey, // uhCAk... format
});

checkFlowstaLinkStatus

Check if Vault still considers an agent linked. Returns { linked: false } if Vault is not running:

typescript
import { checkFlowstaLinkStatus } from '@flowsta/holochain';

const status = await checkFlowstaLinkStatus({
  clientId: 'flowsta_app_abc123',
  localAgentPubKey: myAgentKey, // uhCAk... format
});

if (status.linked) {
  console.log('App name:', status.appName);
}

Backups

startAutoBackup

Start automatic backups to Vault's encrypted local storage:

typescript
import { startAutoBackup } from '@flowsta/holochain';

const stopBackup = startAutoBackup({
  clientId: 'flowsta_app_abc123',
  appName: 'ChessChain',
  getData: async () => {
    // Return whatever data you want backed up
    return { moves: [...], settings: {...} };
  },
  intervalMinutes: 60, // Default: 60
  onSuccess: (result) => console.log('Backup saved:', result.label),
  onError: (err) => console.error('Backup failed:', err),
});

// Stop when your app closes
stopBackup();

backupToVault

Trigger a manual backup:

typescript
import { backupToVault } from '@flowsta/holochain';

const result = await backupToVault(
  {
    clientId: 'flowsta_app_abc123',
    appName: 'ChessChain',
    label: 'latest',
  },
  { moves: [...], settings: {...} },
);

retrieveFromVault

Retrieve a stored backup:

typescript
import { retrieveFromVault } from '@flowsta/holochain';

const data = await retrieveFromVault({
  clientId: 'flowsta_app_abc123',
  label: 'latest',
});

Error Types

ErrorDescription
VaultNotFoundErrorVault not running or not installed
VaultLockedErrorVault is locked
UserDeniedErrorUser rejected the approval dialog
InvalidClientIdErrorClient ID not registered
MissingClientIdErrorNo client_id provided
ApiUnreachableErrorCannot reach Flowsta API

Function Reference

FunctionDescription
linkFlowstaIdentity(options)Request identity link from Vault
getFlowstaIdentity(options)Query linked agents on DHT
getVaultStatus(ipcUrl?)Check Vault status
revokeFlowstaIdentity(options)Notify Vault of revocation
checkFlowstaLinkStatus(options)Check link status in Vault
startAutoBackup(options)Start automatic backups
backupToVault(options, data)Store data in Vault
retrieveFromVault(options)Retrieve stored backup
listVaultBackups(ipcUrl?)List all backups in Vault

Next Steps

Documentation licensed under CC BY-SA 4.0.