@stvor/sdk 2.0.0 → 2.0.2

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.
@@ -0,0 +1,52 @@
1
+ /**
2
+ * STVOR DX Facade - Type Definitions
3
+ */
4
+ /**
5
+ * AppToken from developer dashboard
6
+ * Replaces "API key" terminology for better DX
7
+ */
8
+ export type AppToken = string;
9
+ /**
10
+ * Configuration for SDK initialization
11
+ */
12
+ export interface StvorAppConfig {
13
+ /** AppToken from STVOR developer dashboard */
14
+ appToken: string;
15
+ /** Relay server URL (optional, defaults to stvor.io) */
16
+ relayUrl?: string;
17
+ /** Connection timeout in ms (optional, default 10000) */
18
+ timeout?: number;
19
+ }
20
+ /**
21
+ * User identifier in your application
22
+ * Can be email, username, or UUID
23
+ */
24
+ export type UserId = string;
25
+ /**
26
+ * Message content - text or binary data
27
+ */
28
+ export type MessageContent = string | Uint8Array;
29
+ /**
30
+ * Result of receiving a decrypted message
31
+ */
32
+ export interface DecryptedMessage {
33
+ /** Unique message identifier */
34
+ id: string;
35
+ /** Sender's user ID */
36
+ senderId: UserId;
37
+ /** Decrypted content */
38
+ content: MessageContent;
39
+ /** Timestamp when message was sent */
40
+ timestamp: Date;
41
+ }
42
+ /**
43
+ * Sealed payload for encrypting files/binary data
44
+ */
45
+ export interface SealedPayload {
46
+ /** Encrypted ciphertext */
47
+ ciphertext: Uint8Array;
48
+ /** Nonce used for encryption */
49
+ nonce: Uint8Array;
50
+ /** Recipient user ID this was sealed for */
51
+ recipientId: UserId;
52
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * STVOR DX Facade - Type Definitions
3
+ */
4
+ export {};
@@ -0,0 +1,5 @@
1
+ /**
2
+ * STVOR SDK - Main exports
3
+ */
4
+ export * from './legacy';
5
+ export * from './facade';
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * STVOR SDK - Main exports
3
3
  */
4
-
5
4
  // Legacy core API (for migration)
6
5
  export * from './legacy';
7
-
8
6
  // New DX Facade API
9
7
  export * from './facade';
@@ -0,0 +1,31 @@
1
+ /**
2
+ * STVOR SDK - Legacy Core API
3
+ * Kept for backwards compatibility
4
+ */
5
+ export interface StvorConfig {
6
+ apiKey: string;
7
+ serverUrl?: string;
8
+ }
9
+ export interface Peer {
10
+ id: string;
11
+ publicKey: any;
12
+ }
13
+ export interface EncryptedMessage {
14
+ ciphertext: string;
15
+ nonce: string;
16
+ from: string;
17
+ }
18
+ export declare class StvorClient {
19
+ private config;
20
+ private myKeyPair;
21
+ private myId;
22
+ private peers;
23
+ constructor(config: StvorConfig);
24
+ ready(): Promise<void>;
25
+ createPeer(name: string): Promise<Peer>;
26
+ send({ to, message }: {
27
+ to: string;
28
+ message: string;
29
+ }): Promise<EncryptedMessage>;
30
+ receive(encrypted: EncryptedMessage): Promise<string>;
31
+ }
package/dist/legacy.js ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * STVOR SDK - Legacy Core API
3
+ * Kept for backwards compatibility
4
+ */
5
+ export class StvorClient {
6
+ constructor(config) {
7
+ this.myKeyPair = null;
8
+ this.myId = '';
9
+ this.peers = new Map();
10
+ this.config = {
11
+ serverUrl: 'http://localhost:3001',
12
+ ...config,
13
+ };
14
+ }
15
+ async ready() {
16
+ if (!this.config.apiKey) {
17
+ throw new Error('API key is required');
18
+ }
19
+ this.myKeyPair = await crypto.subtle.generateKey({ name: 'ECDH', namedCurve: 'P-256' }, true, ['deriveKey', 'deriveBits']);
20
+ this.myId = this.config.apiKey.substring(0, 8);
21
+ }
22
+ async createPeer(name) {
23
+ if (!this.myKeyPair)
24
+ throw new Error('Call ready() first');
25
+ const publicKey = await crypto.subtle.exportKey('jwk', this.myKeyPair.publicKey);
26
+ const res = await fetch(`${this.config.serverUrl}/register`, {
27
+ method: 'POST',
28
+ headers: { 'Content-Type': 'application/json' },
29
+ body: JSON.stringify({ user_id: name, publicKey }),
30
+ });
31
+ if (!res.ok) {
32
+ const err = await res.json();
33
+ throw new Error(`Registration failed: ${JSON.stringify(err)}`);
34
+ }
35
+ return { id: name, publicKey };
36
+ }
37
+ async send({ to, message }) {
38
+ if (!this.myKeyPair)
39
+ throw new Error('Call ready() first');
40
+ let recipientKey = this.peers.get(to);
41
+ if (!recipientKey) {
42
+ const res = await fetch(`${this.config.serverUrl}/public-key/${to}`);
43
+ if (!res.ok)
44
+ throw new Error(`Peer ${to} not found`);
45
+ const { publicKey } = await res.json();
46
+ recipientKey = await crypto.subtle.importKey('jwk', publicKey, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
47
+ this.peers.set(to, recipientKey);
48
+ }
49
+ const sharedKey = await crypto.subtle.deriveKey({ name: 'ECDH', public: recipientKey }, this.myKeyPair.privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
50
+ const iv = crypto.getRandomValues(new Uint8Array(12));
51
+ const encoder = new TextEncoder();
52
+ const encrypted = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, sharedKey, encoder.encode(message));
53
+ const sendRes = await fetch(`${this.config.serverUrl}/message`, {
54
+ method: 'POST',
55
+ headers: { 'Content-Type': 'application/json' },
56
+ body: JSON.stringify({
57
+ from: this.myId,
58
+ to,
59
+ ciphertext: Buffer.from(encrypted).toString('base64'),
60
+ nonce: Buffer.from(iv).toString('base64'),
61
+ }),
62
+ });
63
+ if (!sendRes.ok) {
64
+ throw new Error('Failed to send message');
65
+ }
66
+ return {
67
+ ciphertext: Buffer.from(encrypted).toString('base64'),
68
+ nonce: Buffer.from(iv).toString('base64'),
69
+ from: this.myId
70
+ };
71
+ }
72
+ async receive(encrypted) {
73
+ if (!this.myKeyPair)
74
+ throw new Error('Call ready() first');
75
+ let senderKey = this.peers.get(encrypted.from);
76
+ if (!senderKey) {
77
+ const res = await fetch(`${this.config.serverUrl}/public-key/${encrypted.from}`);
78
+ if (!res.ok)
79
+ throw new Error(`Sender ${encrypted.from} not found`);
80
+ const { publicKey } = await res.json();
81
+ senderKey = await crypto.subtle.importKey('jwk', publicKey, { name: 'ECDH', namedCurve: 'P-256' }, false, []);
82
+ this.peers.set(encrypted.from, senderKey);
83
+ }
84
+ const sharedKey = await crypto.subtle.deriveKey({ name: 'ECDH', public: senderKey }, this.myKeyPair.privateKey, { name: 'AES-GCM', length: 256 }, false, ['encrypt', 'decrypt']);
85
+ const iv = Buffer.from(encrypted.nonce, 'base64');
86
+ const ciphertext = Buffer.from(encrypted.ciphertext, 'base64');
87
+ const decrypted = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, sharedKey, ciphertext);
88
+ return new TextDecoder().decode(decrypted);
89
+ }
90
+ }
package/package.json CHANGED
@@ -1,20 +1,13 @@
1
1
  {
2
2
  "name": "@stvor/sdk",
3
- "version": "2.0.0",
4
- "description": "Stvor - is a security infrastructure for the quantum era.",
3
+ "version": "2.0.2",
4
+ "description": "STVOR DX Facade - Simple E2EE SDK for client-side encryption",
5
5
  "type": "module",
6
- "main": "index.ts",
7
- "types": "index.ts",
6
+ "main": "./dist/index.js",
8
7
  "exports": {
9
- ".": {
10
- "types": "./index.ts",
11
- "import": "./index.ts"
12
- },
13
- "./facade": {
14
- "types": "./facade/index.ts",
15
- "import": "./facade/index.ts"
16
- }
8
+ ".": "./dist/index.js"
17
9
  },
10
+ "files": ["dist"],
18
11
  "keywords": [
19
12
  "e2ee",
20
13
  "encryption",
@@ -30,5 +23,8 @@
30
23
  "bugs": {
31
24
  "url": "https://github.com/stvor/sdk/issues"
32
25
  },
33
- "homepage": "https://stvor.xyz"
26
+ "homepage": "https://stvor.xyz",
27
+ "scripts": {
28
+ "build": "tsc"
29
+ }
34
30
  }