Skip to main content

Installation

This guide will help you install and set up the Vaultys Peer SDK in your project.

Prerequisites​

Before installing the SDK, ensure you have:

  • Node.js version 16.0.0 or higher
  • npm or yarn package manager
  • TypeScript 4.5+ (for TypeScript projects)

Installation Methods​

NPM​

npm install @vaultys/peer-sdk

Yarn​

yarn add @vaultys/peer-sdk

pnpm​

pnpm add @vaultys/peer-sdk

Peer Dependencies​

The SDK has optional peer dependencies that you may need to install depending on your use case:

For Browser Applications​

No additional dependencies needed! The SDK works out of the box in modern browsers.

For Node.js Applications​

Install the WebRTC implementation for Node.js:

npm install @roamhq/wrtc

For Identity Management​

If you're using Vaultys identity features:

npm install @vaultys/id

Platform-Specific Setup​

Browser Setup​

For browser applications, you can use the SDK directly:

import { 
setupVaultysPeerSDK,
BrowserStorageProvider
} from '@vaultys/peer-sdk';

// SDK is ready to use

Using CDN​

You can also include the SDK via CDN:

<script type="module">
import {
setupVaultysPeerSDK
} from 'https://cdn.jsdelivr.net/npm/@vaultys/peer-sdk/dist/index.mjs';

// Your code here
</script>

Node.js Setup​

For Node.js applications, you need to set up WebRTC:

import { 
setupVaultysPeerSDK,
NodeFSStorageProvider,
setupNodeWebRTC
} from '@vaultys/peer-sdk';
import wrtc from '@roamhq/wrtc';

// Set up WebRTC for Node.js
setupNodeWebRTC(wrtc);

// Now you can use the SDK

TypeScript Configuration​

If you're using TypeScript, add these settings to your tsconfig.json:

{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"types": ["node"]
}
}

Webpack Configuration​

If you're using Webpack, you might need to add these configurations:

module.exports = {
resolve: {
fallback: {
"crypto": false,
"stream": false,
"buffer": false
}
}
};

Vite Configuration​

For Vite projects, the SDK works without additional configuration. However, for optimal performance:

// vite.config.js
export default {
optimizeDeps: {
include: ['@vaultys/peer-sdk']
}
};

Verifying Installation​

Create a simple test file to verify the installation:

import { 
PeerService,
BrowserStorageProvider
} from '@vaultys/peer-sdk';

async function test() {
console.log('Vaultys Peer SDK loaded successfully!');

// Create a simple peer service
const peerService = new PeerService({
storageProvider: new BrowserStorageProvider()
});

console.log('PeerService created');
}

test();

Run the test:

# For Node.js
node test.js

# For browser
# Open your HTML file in a browser and check the console

Common Installation Issues​

Issue: Module not found​

Solution: Ensure you've installed the package correctly:

npm list @vaultys/peer-sdk

Issue: WebRTC not available in Node.js​

Solution: Install and configure wrtc:

npm install @roamhq/wrtc

Then set it up before using the SDK:

import wrtc from '@roamhq/wrtc';
import { setupNodeWebRTC } from '@vaultys/peer-sdk';

setupNodeWebRTC(wrtc);

Issue: TypeScript type errors​

Solution: Ensure TypeScript is configured correctly and types are installed:

npm install --save-dev @types/node

Issue: CORS errors in browser​

Solution: Ensure you're serving your application from a web server (not file:// protocol):

# Use a local server
npx serve .
# or
python -m http.server 8000

Environment-Specific Builds​

The SDK provides different builds for different environments:

  • ESM (.mjs): For modern browsers and Node.js with ES modules
  • CommonJS (.js): For Node.js with CommonJS
  • TypeScript (.d.ts): Type definitions for TypeScript projects

The correct build is automatically selected based on your environment.

Next Steps​

Now that you have the SDK installed, proceed to:

  1. Quick Start Guide - Build your first P2P application
  2. Configuration - Learn about configuration options
  3. Examples - See example implementations

Version Compatibility​

SDK VersionNode.jsBrowser Support
1.0.x16+Chrome 86+, Firefox 78+, Safari 14+
0.9.x14+Chrome 80+, Firefox 72+, Safari 13+

Upgrading​

To upgrade to the latest version:

# NPM
npm update @vaultys/peer-sdk

# Yarn
yarn upgrade @vaultys/peer-sdk

# To a specific version
npm install @vaultys/peer-sdk@1.0.0

Check the Migration Guide when upgrading between major versions.