API Reference
This section contains the complete API reference for the Swarm ID library.
Main Classes
SwarmIdClient
The main client for parent dApp windows. Used to integrate Swarm ID authentication into your application.
import { SwarmIdClient } from '@swarm-id/lib'
const client = new SwarmIdClient(options)Key methods:
initialize()- Create and embed the hidden iframeisAuthenticated()- Check authentication statusuploadData(data, options?)- Upload data to SwarmdownloadData(reference)- Download data from Swarmdestroy()- Clean up resources
SwarmIdProxy
Runs inside the hidden iframe. Generally not used directly by dApp developers.
import { initProxy } from '@swarm-id/lib'
const proxy = initProxy(options)SwarmIdAuth
Runs in the authentication popup. Generally not used directly by dApp developers.
import { initAuth } from '@swarm-id/lib'
const auth = await initAuth(options)Utility Functions
Key Derivation
import { deriveSecret, generateMasterKey } from '@swarm-id/lib'
// Generate a new master keyconst masterKey = await generateMasterKey()
// Derive an app-specific secretconst appSecret = await deriveSecret(masterKey, 'https://my-app.com')Hex Utilities
import { hexToUint8Array, uint8ArrayToHex } from '@swarm-id/lib'
const bytes = hexToUint8Array('deadbeef')const hex = uint8ArrayToHex(new Uint8Array([222, 173, 190, 239]))Types
The library exports TypeScript types for all public APIs:
import type { ClientOptions, ProxyOptions, AuthOptions, UploadOptions, DownloadOptions, UploadResult, Reference, BatchId,} from '@swarm-id/lib'Source Code
For the most up-to-date API information, see the library source code and TypeScript definitions.