@cryptforge/key-exchange 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # @cryptforge/key-exchange
2
+
3
+ Key exchange package for CryptForge SDK. Provides secure key exchange functionality across different environments: browser, Node.js server, and Electron.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @cryptforge/key-exchange
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ This package provides **separate entry points** for different environments to ensure safe usage without mixing incompatible APIs.
14
+
15
+ ### Browser/Web Client
16
+
17
+ ```typescript
18
+ import { KeyTransportClient } from "@cryptforge/key-exchange";
19
+
20
+ const client = new KeyTransportClient("ws://localhost:3001");
21
+ const broadcastId = await client.enableBroadcast();
22
+ ```
23
+
24
+ ### Node.js Server
25
+
26
+ ```typescript
27
+ import { KeyExchangeServer } from "@cryptforge/key-exchange/server";
28
+
29
+ const server = new KeyExchangeServer();
30
+ await server.start();
31
+ ```
32
+
33
+ ### Electron
34
+
35
+ Electron has three separate contexts that must not be mixed:
36
+
37
+ #### Main Process (Node.js environment)
38
+
39
+ ```typescript
40
+ // In your main.js or main.ts
41
+ import {} from /* your exports */ "@cryptforge/key-exchange/electron-main";
42
+
43
+ // Main process code with access to Node.js and Electron APIs
44
+ ```
45
+
46
+ #### Preload Script (Isolated context)
47
+
48
+ ```typescript
49
+ // In your preload.js or preload.ts
50
+ import {} from /* your exports */ "@cryptforge/key-exchange/electron-preload";
51
+
52
+ // Preload script that bridges main and renderer processes
53
+ // Use contextBridge to safely expose APIs to renderer
54
+ ```
55
+
56
+ #### Renderer Process (Browser-like environment)
57
+
58
+ ```typescript
59
+ // In your renderer/app code
60
+ import {} from /* your exports */ "@cryptforge/key-exchange/electron-renderer";
61
+
62
+ // Renderer process code - browser-like environment
63
+ ```
64
+
65
+ ## Architecture
66
+
67
+ ### Why Separate Entry Points?
68
+
69
+ Each environment has different capabilities and restrictions:
70
+
71
+ - **Browser (`/`)**: No Node.js APIs, WebSocket only
72
+ - **Server (`/server`)**: Full Node.js APIs, can use hyperswarm
73
+ - **Electron Main (`/electron-main`)**: Node.js + Electron main process APIs
74
+ - **Electron Preload (`/electron-preload`)**: Limited Node.js APIs in isolated context
75
+ - **Electron Renderer (`/electron-renderer`)**: Browser-like with IPC to main process
76
+
77
+ Mixing these would cause runtime errors or security issues.
78
+
79
+ ## Project Structure
80
+
81
+ ```
82
+ src/
83
+ ├── index.ts # Browser/web client entry point
84
+ ├── server.ts # Node.js server entry point
85
+ ├── electron-main.ts # Electron main process entry point
86
+ ├── electron-preload.ts # Electron preload script entry point
87
+ ├── electron-renderer.ts # Electron renderer process entry point
88
+ ├── client/ # Browser client implementation
89
+ ├── server/ # Server implementation
90
+ ├── electron/
91
+ │ ├── main/ # Electron main process code
92
+ │ ├── preload/ # Electron preload script code
93
+ │ └── renderer/ # Electron renderer process code
94
+ └── types/ # Shared TypeScript types
95
+ ```
96
+
97
+ ## Features
98
+
99
+ - Secure key exchange protocol
100
+ - Browser and Node.js support
101
+ - Full Electron support (main, preload, renderer)
102
+ - TypeScript support with full type definitions
103
+ - WebSocket-based communication for web/browser
104
+ - Hyperswarm support for server-to-server
105
+
106
+ ## License
107
+
108
+ ISC
@@ -0,0 +1,41 @@
1
+ import { OnSetupEventCallback, StoredIdentity, ClientConnectionState } from '@cryptforge/core';
2
+
3
+ declare const setupKeyExchangeHandlers: () => void;
4
+
5
+ interface DeviceInfo {
6
+ id: string;
7
+ name: string;
8
+ }
9
+
10
+ /**
11
+ * Core transport logic that can be shared across different transport implementations.
12
+ * This class contains all the business logic without any transport-specific code.
13
+ */
14
+ declare class CoreTransportLogic {
15
+ private syncServer;
16
+ private syncClient;
17
+ private presence;
18
+ private deviceInfo?;
19
+ private handleEvent;
20
+ private presenceConnected;
21
+ constructor(handleEvent?: OnSetupEventCallback);
22
+ private initializeDeviceInfo;
23
+ private onStateUpdate;
24
+ private onStateRequest;
25
+ private delay;
26
+ enableBroadcast(): Promise<string>;
27
+ connect(topic: string, name: string, app: string): Promise<void>;
28
+ requestKeystore(pin: string): Promise<void>;
29
+ approveRequest(data: {
30
+ identity: StoredIdentity;
31
+ appId: number;
32
+ }): Promise<void>;
33
+ denyRequest(): Promise<void>;
34
+ disableBroadcast(): Promise<void>;
35
+ getDeviceInfo(): Promise<DeviceInfo>;
36
+ getHostname(): Promise<string>;
37
+ connectPresence(topic: string): Promise<void>;
38
+ broadcastClientState(id: string, state: ClientConnectionState): void;
39
+ }
40
+
41
+ export { CoreTransportLogic, setupKeyExchangeHandlers };
@@ -0,0 +1,41 @@
1
+ import { OnSetupEventCallback, StoredIdentity, ClientConnectionState } from '@cryptforge/core';
2
+
3
+ declare const setupKeyExchangeHandlers: () => void;
4
+
5
+ interface DeviceInfo {
6
+ id: string;
7
+ name: string;
8
+ }
9
+
10
+ /**
11
+ * Core transport logic that can be shared across different transport implementations.
12
+ * This class contains all the business logic without any transport-specific code.
13
+ */
14
+ declare class CoreTransportLogic {
15
+ private syncServer;
16
+ private syncClient;
17
+ private presence;
18
+ private deviceInfo?;
19
+ private handleEvent;
20
+ private presenceConnected;
21
+ constructor(handleEvent?: OnSetupEventCallback);
22
+ private initializeDeviceInfo;
23
+ private onStateUpdate;
24
+ private onStateRequest;
25
+ private delay;
26
+ enableBroadcast(): Promise<string>;
27
+ connect(topic: string, name: string, app: string): Promise<void>;
28
+ requestKeystore(pin: string): Promise<void>;
29
+ approveRequest(data: {
30
+ identity: StoredIdentity;
31
+ appId: number;
32
+ }): Promise<void>;
33
+ denyRequest(): Promise<void>;
34
+ disableBroadcast(): Promise<void>;
35
+ getDeviceInfo(): Promise<DeviceInfo>;
36
+ getHostname(): Promise<string>;
37
+ connectPresence(topic: string): Promise<void>;
38
+ broadcastClientState(id: string, state: ClientConnectionState): void;
39
+ }
40
+
41
+ export { CoreTransportLogic, setupKeyExchangeHandlers };