@wishcore/wish-sdk
Version:
Wish API for node. Used for building Wish Apps.
62 lines (46 loc) • 1.55 kB
Markdown
Node.js SDK for building peer-to-peer applications on the Wish protocol.
**Features:**
- Cryptographic identity-based P2P networking
- Protocol-based service discovery
- End-to-end encrypted communication
```sh
npm install @wishcore/wish-sdk
```
```js
const { App, WishCoreRunner } = require('@wishcore/wish-sdk');
// Start wish-core (bundles pre-built binaries for macOS/Linux)
await WishCoreRunner.start({ appPort: 9094 });
const app = new App({
name: 'MyApp',
corePort: 9094,
protocols: ['chat']
});
app.on('ready', async () => {
// Create or get identity
const identities = await app.request('identity.list', []);
const identity = identities[0] || await app.request('identity.create', ['Alice']);
console.log('Ready as:', identity.alias);
});
app.on('online', async (peer) => {
// Send message to peer
await app.request('services.send', [peer, Buffer.from('Hello!')]);
});
app.on('frame', async (peer, data) => {
// Receive message from peer
const identity = await app.request('identity.get', [peer.ruid]);
console.log(`${identity.alias}: ${data.toString()}`);
});
```
- `identity.create(alias)` - Create new identity
- `identity.list()` - List identities
- `identity.get(uid)` - Get identity details
- `services.send(peer, buffer)` - Send data to peer
- `ready` - Connected to wish-core
- `online(peer)` - Peer came online
- `offline(peer)` - Peer went offline
- `frame(peer, data)` - Received data from peer