1.0.3 • Published 3 months ago
smart-widget-builder v1.0.3
Smart Widget (SW) - Nostr Integration Library
A JavaScript library for creating and managing Smart Widgets on the Nostr protocol.
Installation
npm install smart-widget-builder
Features
- Create and publish Smart Widgets to Nostr relays
- Flexible relay configuration
- Event signing and publishing
- Nostr event searching capabilities
Quick start
const { SW, Image, Input, Button, SWComponentsSet } = require('smart-widget-builder');
// Initialize Smart Widget
const sw = new SW(['wss://relay.example.com']);
// Create components
const components = new SWComponentsSet([
new Image('https://example.com/image.jpg'),
new Input('Enter text here'),
new Button(1, 'Click Me', 'redirect', 'https://example.com')
]);
// Connect and publish
async function publishWidget() {
await sw.init();
const result = await sw.publish(components, 'My Widget');
console.log(result);
}
Classes
SW
Main Smart Widget class for managing Nostr connections and publications
constructor(relaySet, secretKey)
- A preset relays list and a randomly generated secret key will be used if the construction params are left emptyinit()
- Connect to relayspublish(components, title, identifier, timeout)
- Publish a widgetsignEvent(components, title, identifier)
- Sign a widget eventsearchNostr(filter)
- Search Nostr events
Components
Image(url)
- Image componentInput(label)
- Input field componentButton(index, label, type, url)
- Button component- Button types:
redirect
,nostr
,zap
,post
,app
redirect
a URL redirectnostr
a nostr schema URL (ie: nostr:npub.. , nevent1..)zap
a lightning address or a lightning invoice to proceeding for zappingpost
aPOST
request to an endpoint that returns a smart widget eventapp
an internally opened URL
- Button types:
SWComponentsSet(components)
- Component collection
Configuration (optional if used in NodeJS)
Create a .env file for the secret key, this will be used as a fallback if the SW() constructor was not provided with one to sign and publish event
SECRET_KEY=your-hex-secret-key