Skip to main content
TinyCloud uses Sign-In with Ethereum (SIWE) for authentication. Users prove wallet ownership to establish sessions that authorize access to their space.

How SIWE Works

1

Connect wallet

The user connects their Ethereum wallet (MetaMask, WalletConnect, etc.)
2

Sign message

The SDK constructs a SIWE message containing domain, address, and session parameters. The user signs this message with their wallet.
3

Session created

TinyCloud verifies the signature and creates a session. The session key can perform operations on behalf of the user until expiry.

Sign In

import { TinyCloudWeb } from '@tinycloudlabs/web-sdk';

const tc = new TinyCloudWeb({
  host: 'https://api.tinycloud.xyz',
  prefix: 'my-app',
});

// Triggers wallet popup for signature
await tc.signIn();

// Session is now active
console.log('Signed in as:', tc.userAuthorization.getSpaceId());

Session Persistence

Sessions can be persisted to survive page reloads (Web) or process restarts (Node).
const tc = new TinyCloudWeb({
  host: 'https://api.tinycloud.xyz',
  prefix: 'my-app',
  sessionConfig: {
    // 'localStorage' persists across tabs/sessions
    // 'sessionStorage' clears when tab closes
    // 'memory' clears on page reload
    storageType: 'localStorage',
  },
});

Resume Existing Session

Check for and resume a persisted session without requiring a new signature.
const tc = new TinyCloudWeb({
  host: 'https://api.tinycloud.xyz',
  prefix: 'my-app',
  sessionConfig: { storageType: 'localStorage' },
});

// Try to resume existing session
const resumed = await tc.tryResumeSession();

if (resumed) {
  console.log('Session resumed');
} else {
  // No valid session, need fresh sign-in
  await tc.signIn();
}

Node SDK Sign Strategies

The Node SDK supports different strategies for signing the SIWE message.
Signs automatically using the provided private key.
const tc = new TinyCloudNode({
  privateKey: process.env.WALLET_PRIVATE_KEY,
  // signStrategy defaults to 'auto'
});

await tc.signIn(); // Signs immediately

Session Expiry

Sessions have a limited lifetime. Handle expiry gracefully.
const tc = new TinyCloudWeb({
  host: 'https://api.tinycloud.xyz',
  prefix: 'my-app',
  sessionConfig: {
    storageType: 'localStorage',
    expirationTime: '24h', // Session duration
  },
});

// Check if session is still valid
if (tc.isSessionExpired()) {
  await tc.signIn(); // Re-authenticate
}

Sign Out

Clear the current session.
await tc.signOut();
// Session cleared from storage
After signing out, all operations will fail until a new signIn() is completed.