TypeScript SDK for building applications on AfterCrypt Protocol - the permissionless, AI-monitored vault infrastructure for Web3.
npm install @vault/protocol-sdk
# or
yarn add @vault/protocol-sdk
# or
pnpm add @vault/protocol-sdk- Vault Management - Create, read, update, and manage vaults
- Time-Based Releases - Scheduled unlocks and dead-man switch functionality
- AI Monitoring - Multi-agent consensus with liveness and risk scoring
- Cross-Chain Support - 8+ chains via LayerZero (Ethereum, Polygon, Arbitrum, Optimism, Base, BSC, Avalanche, opBNB)
- Client-Side Encryption - AES-256-GCM encryption for vault contents
- FHE Support - Fully Homomorphic Encryption for advanced privacy
- Event Monitoring - Real-time WebSocket event subscriptions
- Decentralized Storage - Arweave, IPFS, and Ceramic integration
import {
createVaultClient,
VaultManager,
TimeManager,
ReleaseType
} from '@vault/protocol-sdk';
// Option 1: Backend/Scripts - Private key mode
const client = createVaultClient({
chainId: 97, // BSC Testnet
privateKey: '0x...'
});
// Option 2: Frontend - External wallet mode (MetaMask, WalletConnect)
const client = createVaultClient({
chainId: 97,
walletClient: existingWalletClient,
account: '0x...'
});
// Option 3: Read-only mode
const client = createReadOnlyClient(97);
// Initialize managers with the client
const vaultManager = new VaultManager(client);
const timeManager = new TimeManager(client);
// Create a vault
const vault = await vaultManager.createVault({
releaseType: ReleaseType.DEADMAN,
recipients: ['0x...'],
contentCID: 'QmYourContent...',
config: {
checkInPeriod: 30 * 24 * 60 * 60, // 30 days
}
});
// Check in to reset dead-man timer
await timeManager.checkIn(vault.id);| Chain | Chain ID | Status | VaultManager | VaultTimeManager |
|---|---|---|---|---|
| BSC Testnet | 97 | Active | 0x116865F62E1714D9B512Fd9E4f35e6fDb53D019C |
0x68e41639B0c5C56F6E6b0f0Cf9612acac089ff4D |
| opBNB Mainnet | 204 | Pending | - | - |
| opBNB Testnet | 5611 | Pending | - | - |
The SDK uses a client factory pattern that supports three wallet modes:
import { createPrivateKeyClient, VaultManager } from '@vault/protocol-sdk';
const client = createPrivateKeyClient(
97, // Chain ID
'0x...', // Private key
'https://custom-rpc.example.com' // Optional custom RPC
);
const vaultManager = new VaultManager(client);import { createWalletClientWrapper, VaultManager } from '@vault/protocol-sdk';
// Use with MetaMask, WalletConnect, etc.
const client = createWalletClientWrapper(
97, // Chain ID
walletClient, // viem WalletClient from your wallet provider
'0x...' // Account address
);
const vaultManager = new VaultManager(client);import { createReadOnlyClient, VaultManager } from '@vault/protocol-sdk';
// For querying without signing capability
const client = createReadOnlyClient(97);
const vaultManager = new VaultManager(client);
const vaults = await vaultManager.getVaultsByOwner('0x...');Unlocks at a specific date/time.
import { VaultManager, ReleaseType } from '@vault/protocol-sdk';
const vault = await vaultManager.createVault({
releaseType: ReleaseType.SCHEDULED,
recipients: ['0x...'],
contentCID: 'QmContent...',
config: {
unlockTime: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60 // 1 year
}
});Requires periodic check-ins to prevent automatic release.
const vault = await vaultManager.createVault({
releaseType: ReleaseType.DEADMAN,
recipients: ['0x...'],
contentCID: 'QmContent...',
config: {
checkInPeriod: 30 * 24 * 60 * 60 // 30 days in seconds
}
});
// Check in periodically to reset the timer
const timeManager = new TimeManager(client);
await timeManager.checkIn(vault.address);Combines scheduled release with dead-man switch.
const vault = await vaultManager.createVault({
releaseType: ReleaseType.HYBRID,
recipients: ['0x...'],
contentCID: 'QmContent...',
config: {
unlockTime: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60,
checkInPeriod: 30 * 24 * 60 * 60
}
});Enable AI-powered monitoring for liveness detection and risk assessment.
import { AIVaultManager } from '@vault/protocol-sdk';
const aiManager = new AIVaultManager(client);
// Enable monitoring for a vault
await aiManager.enableMonitoring(vaultAddress);
// Get liveness score (0-100)
const livenessScore = await aiManager.getLivenessScore(vaultAddress);
// Get risk score (0-100)
const riskScore = await aiManager.getRiskScore(vaultAddress);
// Get AI recommendations
const recommendations = await aiManager.getRecommendations(vaultAddress);
console.log(recommendations);
// ['Enable AI verification for enhanced security monitoring', ...]
// Check if AI would prevent release
const { shouldPrevent, reason } = await aiManager.shouldPreventRelease(vaultAddress);
// Get full AI state
const state = await aiManager.getVaultAIState(vaultAddress);
console.log(state);
// {
// livenessScore: 85,
// riskScore: 15,
// lastAIPrediction: 1702345678,
// aiCheckCount: 42,
// aiVerificationEnabled: true,
// isPausedByAI: false,
// lastAIReason: ''
// }Decentralized attestation with Byzantine Fault Tolerance (5-of-7 consensus).
import { AttestationClient, AttestationType } from '@vault/protocol-sdk';
const attestation = new AttestationClient(client);
// Submit an attestation request
const requestId = await attestation.submitAttestation({
type: AttestationType.DEATH_VERIFICATION,
data: vaultAddress,
consensus: 5, // 5-of-7 BFT
expirationTime: Math.floor(Date.now() / 1000) + 86400 // 24 hours
});
// Verify attestation result
const result = await attestation.verifyAttestation(requestId);
console.log(result); // { reached: true, result: true }
// Get attestation status
const status = await attestation.getAttestationStatus(requestId);
// Get attestation responses from oracles
const responses = await attestation.getAttestationResponses(requestId);
// Register as an oracle agent (requires staking)
await attestation.registerAgent(BigInt('100000000000000000000000')); // 100,000 VAULT tokensSync vaults across multiple chains via LayerZero.
import { CrossChainClient } from '@vault/protocol-sdk';
const crossChain = new CrossChainClient(client);
// Check supported chains
console.log(crossChain.isSupportedChain(137)); // true (Polygon)
console.log(crossChain.isSupportedChain(204)); // true (opBNB Mainnet)
// Sync vault to another chain
await crossChain.syncVault(vaultAddress, 137); // Sync to Polygon
// Send cross-chain message
await crossChain.sendMessage({
sourceChain: 204,
destChain: 137,
vaultId: vaultAddress,
operation: 'sync',
data: {}
});
// Check message status
const status = await crossChain.getMessageStatus(messageId);Client-side AES-256-GCM encryption utilities.
import {
generateEncryptionKey,
encryptData,
decryptData,
exportKey,
importKey
} from '@vault/protocol-sdk';
// Generate a new encryption key
const key = await generateEncryptionKey();
// Encrypt data
const { encrypted, iv } = await encryptData('sensitive data', key);
// Decrypt data
const decrypted = await decryptData(encrypted, key, iv);
// Export key for storage (base64)
const exportedKey = await exportKey(key);
// Import key from storage
const importedKey = await importKey(exportedKey);import { StorageClient } from '@vault/protocol-sdk';
const storage = new StorageClient({
ipfsApiKey: process.env.PINATA_API_KEY,
ipfsApiSecret: process.env.PINATA_API_SECRET,
arweaveKey: process.env.ARWEAVE_KEY,
ceramicNodeUrl: 'https://ceramic-clay.3boxlabs.com'
});
// Upload to IPFS (via Pinata)
const ipfsResult = await storage.uploadToIPFS(data, {
name: 'vault-content',
pinataMetadata: { vaultId: '123' }
});
console.log(ipfsResult);
// { provider: 'ipfs', cid: 'Qm...', url: 'https://gateway.pinata.cloud/ipfs/Qm...', size: 1024 }
// Upload to Arweave
const arweaveResult = await storage.uploadToArweave(data, {
tags: [{ name: 'Content-Type', value: 'application/json' }]
});
// Upload to Ceramic
const ceramicResult = await storage.uploadToCeramic(data, schema);
// Retrieve from any provider
const content = await storage.retrieveFromIPFS(cid);
const arContent = await storage.retrieveFromArweave(transactionId);Subscribe to real-time vault events.
import { EventMonitor, createVaultClient } from '@vault/protocol-sdk';
const client = createReadOnlyClient(97);
const monitor = new EventMonitor(client);
// Subscribe to vault events
const unsubscribe = await monitor.subscribe(vaultAddress, (event) => {
console.log('Event:', event.type, event.data);
});
// Subscribe to all events from a contract
const unsubscribeAll = await monitor.subscribeAll((event) => {
console.log('Global event:', event);
});
// Cleanup
unsubscribe();| Chain | Chain ID | Status |
|---|---|---|
| opBNB (Primary) | 204 | Mainnet |
| opBNB Testnet | 5611 | Testnet |
| BSC Testnet | 97 | Active (Testing) |
| Ethereum | 1 | Supported |
| Polygon | 137 | Supported |
| Arbitrum | 42161 | Supported |
| Optimism | 10 | Planned |
| Base | 8453 | Planned |
| BSC | 56 | Planned |
| Avalanche | 43114 | Planned |
import type {
VaultConfig,
VaultContent,
ReleaseType,
TimeManagerConfig,
AttestationProof,
CrossChainMessage,
AIMonitoringConfig,
VaultEvent,
VaultClient,
VaultClientConfig
} from '@vault/protocol-sdk';createVaultClient(config)- Create client with full configurationcreateReadOnlyClient(chainId, rpcUrl?)- Create read-only clientcreatePrivateKeyClient(chainId, privateKey, rpcUrl?)- Create client with private keycreateWalletClientWrapper(chainId, walletClient, account, rpcUrl?)- Create client with external walletcanWrite(client)- Check if client can sign transactionsgetAccountOrThrow(client)- Get account address or throw
createVault(config)- Create a new vaultgetVault(vaultAddress)- Get vault by addressupdateVault(vaultAddress, contentCID)- Update vault contentuploadContent(vaultAddress, content)- Upload content to vaultisUnlocked(vaultAddress)- Check if vault is unlockedunlockVault(vaultAddress)- Unlock vault (if conditions met)getVaultsByOwner(owner)- Get all vaults for an owner
configureScheduledRelease(vaultAddress, unlockTime)- Set scheduled unlockconfigureDeadmanSwitch(vaultAddress, checkInPeriod)- Set dead-man switchconfigureHybridRelease(vaultAddress, unlockTime, checkInPeriod)- Set hybrid modecheckIn(vaultAddress)- Check in to reset dead-man timergetTimeUntilUnlock(vaultAddress)- Get time remainingisDeadmanTriggered(vaultAddress)- Check if dead-man triggeredsetUnlockTime(vaultAddress, time)- Set unlock timegetLastCheckIn(vaultAddress)- Get last check-in timestamp
enableMonitoring(vaultAddress, config?)- Enable AI monitoringdisableMonitoring(vaultAddress)- Disable AI monitoringgetLivenessScore(vaultAddress)- Get liveness score (0-100)getRiskScore(vaultAddress)- Get risk score (0-100)getVaultAIState(vaultAddress)- Get full AI statepredictUnlockTime(vaultAddress)- Predict unlock timegetRecommendations(vaultAddress)- Get AI recommendationsshouldPreventRelease(vaultAddress)- Check if AI would prevent releaseshouldReleaseVault(vaultAddress)- Check if vault can be releasedresumeVault(vaultAddress)- Resume AI-paused vault
submitAttestation(params)- Submit attestation requestverifyAttestation(requestId)- Verify attestation resultgetAttestationStatus(requestId)- Get request statusgetAttestationResponses(requestId)- Get oracle responsesregisterAgent(stakeAmount)- Register as oracle agentderegisterAgent()- Deregister as oracle agentgetOracleNode(address)- Get oracle node infogetActiveOracles()- Get active oracle addressesprovideAttestation(requestId, result, proof, signature)- Submit oracle response
sendMessage(message)- Send cross-chain messagegetMessageStatus(messageId)- Get message statussyncVault(vaultAddress, targetChain)- Sync vault across chainsisSupportedChain(chainId)- Check if chain is supportedgetSupportedChains()- Get list of supported chains
uploadToIPFS(data, options?)- Upload to IPFS via PinatauploadToArweave(data, options?)- Upload to ArweaveuploadToCeramic(data, schema)- Upload to CeramicretrieveFromIPFS(cid)- Retrieve from IPFSretrieveFromArweave(txId)- Retrieve from ArweaveretrieveFromCeramic(streamId)- Retrieve from Ceramic
generateEncryptionKey()- Generate AES-256-GCM keyencryptData(data, key)- Encrypt datadecryptData(encrypted, key, iv)- Decrypt dataexportKey(key)- Export key to base64importKey(keyData)- Import key from base64
MIT