@nekosuneprojects/vector-sdk 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -0
  3. package/package.json +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Luke Larsen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # Vector Bot SDK (Node.js)
2
+
3
+ A JavaScript/TypeScript port of the Vector Bot SDK that mirrors the structure of the original Rust crate while staying idiomatic for the Node.js ecosystem. It provides helpers for creating Vector bots, sending encrypted private messages and files, building metadata, subscribing to gift-wrap events, and uploading data through a NIP-96 server.
4
+
5
+ ## Highlights
6
+
7
+ - `VectorBot` and `Channel` classes that wrap a Nostr client for message, reaction, typing, and file flows.
8
+ - Metadata builders, filters, and utilities ported from the Rust implementation.
9
+ - AES-256-GCM file encryption helpers and attachment helpers with extension inference.
10
+ - Upload helpers that target the trusted NIP-96 server used by Vector and emit progress callbacks.
11
+
12
+ ## Getting Started
13
+
14
+ ```bash
15
+ npm install @vector/vector-sdk
16
+ ```
17
+
18
+ Then import the pieces you need:
19
+
20
+ ```ts
21
+ import { VectorBotClient } from '@vector/vector-sdk';
22
+
23
+ const client = new VectorBotClient({
24
+ privateKey: process.env.NOSTR_PRIVATE_KEY,
25
+ relays: (process.env.NOSTR_RELAYS ?? 'wss://jskitty.cat/nostr')
26
+ .split(',')
27
+ .map((relay) => relay.trim())
28
+ .filter(Boolean),
29
+ debug: process.env.DEBUG === '1',
30
+ reconnect: true,
31
+ reconnectIntervalMs: 15000,
32
+ profile: {
33
+ name: 'testnekobot',
34
+ displayName: 'NekoSune TestBOT',
35
+ about: 'Vector bot created with the SDK',
36
+ picture: 'https://example.com/avatar.png',
37
+ banner: 'https://example.com/banner.png',
38
+ },
39
+ });
40
+
41
+ client.on('ready', ({ pubkey, profile }) => {
42
+ const name = profile?.displayName || profile?.name || 'unknown';
43
+ console.log(`Logged in as ${name} (${pubkey})`);
44
+ });
45
+
46
+ client.on('disconnect', ({ relay, error }) => {
47
+ const reason = error instanceof Error ? error.message : String(error ?? '');
48
+ console.warn(`Disconnected from ${relay}${reason ? `: ${reason}` : ''}`);
49
+ });
50
+
51
+ client.on('reconnect', ({ relay }) => {
52
+ console.log(`Reconnected to ${relay}`);
53
+ });
54
+
55
+ client.on('error', (error) => {
56
+ console.error('Bot error:', error);
57
+ });
58
+
59
+ client.on('message', async (channel, tags, message, self) => {
60
+ if (self) return;
61
+
62
+ console.log(`${channel}: ${message}`);
63
+
64
+ if (message.startsWith('!ping')) {
65
+ await client.sendMessage(channel, 'pong');
66
+ return;
67
+ }
68
+
69
+ if (message.startsWith('!upload')) {
70
+ if (!process.env.UPLOAD_FILE_PATH) {
71
+ await client.sendMessage(channel, 'Set UPLOAD_FILE_PATH to send a file.');
72
+ return;
73
+ }
74
+ await client.sendFile(channel, process.env.UPLOAD_FILE_PATH);
75
+ }
76
+ });
77
+
78
+ client.connect().catch((error) => {
79
+ console.error('Bot failed to start:', error);
80
+ process.exit(1);
81
+ });
82
+
83
+ process.on('SIGINT', () => {
84
+ client.close();
85
+ process.exit(0);
86
+ });
87
+ ```
88
+
89
+ ## Building
90
+
91
+ The package is authored in TypeScript. Run `npm run build` to emit the `dist/` artifacts used by consumers.
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@nekosuneprojects/vector-sdk",
3
+ "version": "1.0.1",
4
+ "description": "Node.js reimplementation of the Vector Bot SDK",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "npm run build"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/NekoSuneProjects/vector-sdk-js.git"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/NekoSuneProjects/vector-sdk-js/issues"
21
+ },
22
+ "keywords": [
23
+ "nostr",
24
+ "vector",
25
+ "bot",
26
+ "crypto",
27
+ "sdk"
28
+ ],
29
+ "license": "MIT",
30
+ "dependencies": {
31
+ "@noble/hashes": "^1.5.0",
32
+ "@noble/secp256k1": "^1.5.0",
33
+ "file-type": "^18.0.0",
34
+ "form-data": "^4.0.5",
35
+ "mime-types": "^3.0.2",
36
+ "node-fetch": "^3.3.1",
37
+ "nostr-tools": "^2.19.4"
38
+ },
39
+ "devDependencies": {
40
+ "@types/mime-types": "^2.1.4",
41
+ "@types/node": "^20.7.0",
42
+ "typescript": "^5.5.2"
43
+ }
44
+ }