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:
- Quick Start Guide - Build your first P2P application
- Configuration - Learn about configuration options
- Examples - See example implementations
Version Compatibilityβ
| SDK Version | Node.js | Browser Support |
|---|---|---|
| 1.0.x | 16+ | Chrome 86+, Firefox 78+, Safari 14+ |
| 0.9.x | 14+ | 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.