ehbp 0.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.
- package/build-browser.js +54 -0
- package/chat.html +285 -0
- package/dist/client.d.ts +47 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +145 -0
- package/dist/client.js.map +1 -0
- package/dist/example.d.ts +6 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +115 -0
- package/dist/example.js.map +1 -0
- package/dist/identity.d.ts +52 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +270 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +19 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +19 -0
- package/dist/protocol.js.map +1 -0
- package/dist/streaming-test.d.ts +3 -0
- package/dist/streaming-test.d.ts.map +1 -0
- package/dist/streaming-test.js +102 -0
- package/dist/streaming-test.js.map +1 -0
- package/dist/test/client.test.d.ts +2 -0
- package/dist/test/client.test.d.ts.map +1 -0
- package/dist/test/client.test.js +70 -0
- package/dist/test/client.test.js.map +1 -0
- package/dist/test/identity.test.d.ts +2 -0
- package/dist/test/identity.test.d.ts.map +1 -0
- package/dist/test/identity.test.js +39 -0
- package/dist/test/identity.test.js.map +1 -0
- package/dist/test/streaming.test.d.ts +2 -0
- package/dist/test/streaming.test.d.ts.map +1 -0
- package/dist/test/streaming.test.js +71 -0
- package/dist/test/streaming.test.js.map +1 -0
- package/package.json +42 -0
- package/src/client.ts +170 -0
- package/src/example.ts +126 -0
- package/src/identity.ts +339 -0
- package/src/index.ts +14 -0
- package/src/protocol.ts +19 -0
- package/src/streaming-test.ts +118 -0
- package/src/test/client.test.ts +91 -0
- package/src/test/identity.test.ts +46 -0
- package/src/test/streaming.test.ts +85 -0
- package/test.html +271 -0
- package/tsconfig.json +19 -0
package/build-browser.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Build script to create a browser-compatible bundle
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { build } from 'esbuild';
|
|
8
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
9
|
+
import { join, dirname } from 'path';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = dirname(__filename);
|
|
14
|
+
|
|
15
|
+
async function buildBrowser() {
|
|
16
|
+
console.log('Building browser bundle...');
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
// Build the main bundle
|
|
20
|
+
await build({
|
|
21
|
+
entryPoints: ['src/index.ts'],
|
|
22
|
+
bundle: true,
|
|
23
|
+
outfile: 'dist/browser.js',
|
|
24
|
+
format: 'esm',
|
|
25
|
+
target: 'es2020',
|
|
26
|
+
platform: 'browser',
|
|
27
|
+
external: [],
|
|
28
|
+
sourcemap: true,
|
|
29
|
+
minify: false,
|
|
30
|
+
define: {
|
|
31
|
+
'process.env.NODE_ENV': '"production"'
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Create a simple wrapper that exports everything
|
|
36
|
+
const wrapper = `
|
|
37
|
+
// Browser-compatible wrapper for EHBP client
|
|
38
|
+
export * from './browser.js';
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
writeFileSync(join(__dirname, 'dist', 'index.js'), wrapper);
|
|
42
|
+
|
|
43
|
+
console.log('Browser bundle created successfully!');
|
|
44
|
+
console.log('Files created:');
|
|
45
|
+
console.log(' - dist/browser.js (main bundle)');
|
|
46
|
+
console.log(' - dist/index.js (wrapper)');
|
|
47
|
+
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error('Build failed:', error);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
buildBrowser();
|
package/chat.html
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>EHBP Chat Interface</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
max-width: 800px;
|
|
11
|
+
margin: 0 auto;
|
|
12
|
+
padding: 20px;
|
|
13
|
+
background-color: #f5f5f5;
|
|
14
|
+
}
|
|
15
|
+
.container {
|
|
16
|
+
background: white;
|
|
17
|
+
padding: 0;
|
|
18
|
+
height: 95vh;
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
border-radius: 0;
|
|
22
|
+
}
|
|
23
|
+
h1 {
|
|
24
|
+
color: #333;
|
|
25
|
+
text-align: center;
|
|
26
|
+
margin: 15px 0 10px 0;
|
|
27
|
+
padding: 0 20px;
|
|
28
|
+
}
|
|
29
|
+
.chat-container {
|
|
30
|
+
flex: 1;
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: column;
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
}
|
|
35
|
+
.messages {
|
|
36
|
+
flex: 1;
|
|
37
|
+
padding: 20px;
|
|
38
|
+
overflow-y: auto;
|
|
39
|
+
}
|
|
40
|
+
.message {
|
|
41
|
+
margin-bottom: 12px;
|
|
42
|
+
padding: 8px 12px;
|
|
43
|
+
border-radius: 4px;
|
|
44
|
+
max-width: 80%;
|
|
45
|
+
}
|
|
46
|
+
.message.user {
|
|
47
|
+
background-color: #007bff;
|
|
48
|
+
color: white;
|
|
49
|
+
margin-left: auto;
|
|
50
|
+
text-align: right;
|
|
51
|
+
border: none;
|
|
52
|
+
}
|
|
53
|
+
.message.assistant {
|
|
54
|
+
background-color: #f8f9fa;
|
|
55
|
+
color: #333;
|
|
56
|
+
margin-right: auto;
|
|
57
|
+
border: none;
|
|
58
|
+
}
|
|
59
|
+
.message.system {
|
|
60
|
+
background-color: #fff3cd;
|
|
61
|
+
color: #856404;
|
|
62
|
+
margin: 0 auto;
|
|
63
|
+
text-align: center;
|
|
64
|
+
font-style: italic;
|
|
65
|
+
border: none;
|
|
66
|
+
}
|
|
67
|
+
.input-area {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
70
|
+
padding: 15px 20px;
|
|
71
|
+
gap: 8px;
|
|
72
|
+
border-top: 1px solid #eee;
|
|
73
|
+
background-color: white;
|
|
74
|
+
}
|
|
75
|
+
.input-area input {
|
|
76
|
+
flex: 1;
|
|
77
|
+
padding: 8px 10px;
|
|
78
|
+
border: 1px solid #ddd;
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
height: 32px;
|
|
81
|
+
font-family: inherit;
|
|
82
|
+
font-size: 13px;
|
|
83
|
+
outline: none;
|
|
84
|
+
box-sizing: border-box;
|
|
85
|
+
}
|
|
86
|
+
.input-area input:focus {
|
|
87
|
+
border-color: #007bff;
|
|
88
|
+
}
|
|
89
|
+
.input-area button {
|
|
90
|
+
padding: 8px 16px;
|
|
91
|
+
background-color: #007bff;
|
|
92
|
+
color: white;
|
|
93
|
+
border: none;
|
|
94
|
+
border-radius: 4px;
|
|
95
|
+
cursor: pointer;
|
|
96
|
+
font-size: 13px;
|
|
97
|
+
font-weight: 500;
|
|
98
|
+
min-width: 60px;
|
|
99
|
+
}
|
|
100
|
+
.input-area button:hover {
|
|
101
|
+
background-color: #0056b3;
|
|
102
|
+
}
|
|
103
|
+
.input-area button:disabled {
|
|
104
|
+
background-color: #6c757d;
|
|
105
|
+
cursor: not-allowed;
|
|
106
|
+
}
|
|
107
|
+
.typing-indicator {
|
|
108
|
+
padding: 10px;
|
|
109
|
+
font-style: italic;
|
|
110
|
+
color: #666;
|
|
111
|
+
display: none;
|
|
112
|
+
}
|
|
113
|
+
</style>
|
|
114
|
+
</head>
|
|
115
|
+
<body>
|
|
116
|
+
<div class="container">
|
|
117
|
+
<h1>EHBP Chat Interface</h1>
|
|
118
|
+
<div class="chat-container">
|
|
119
|
+
<div id="messages" class="messages"></div>
|
|
120
|
+
<div class="typing-indicator" id="typingIndicator">Assistant is typing...</div>
|
|
121
|
+
<div class="input-area">
|
|
122
|
+
<input type="text" id="messageInput" placeholder="Type your message here..." onkeydown="handleKeyDown(event)" />
|
|
123
|
+
<button id="sendBtn" onclick="sendMessage()">Send</button>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<script type="module">
|
|
129
|
+
import { Identity, createTransport } from './dist/browser.js';
|
|
130
|
+
|
|
131
|
+
const serverUrl = 'http://localhost:8443';
|
|
132
|
+
|
|
133
|
+
let transport = null;
|
|
134
|
+
let clientIdentity = null;
|
|
135
|
+
let conversationHistory = [];
|
|
136
|
+
|
|
137
|
+
async function initializeClient() {
|
|
138
|
+
try {
|
|
139
|
+
clientIdentity = await Identity.generate();
|
|
140
|
+
transport = await createTransport(serverUrl, clientIdentity);
|
|
141
|
+
return true;
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error('Failed to connect:', error.message);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function addMessage(role, content) {
|
|
149
|
+
const messagesContainer = document.getElementById('messages');
|
|
150
|
+
const messageDiv = document.createElement('div');
|
|
151
|
+
messageDiv.className = `message ${role}`;
|
|
152
|
+
messageDiv.textContent = content;
|
|
153
|
+
messagesContainer.appendChild(messageDiv);
|
|
154
|
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
|
155
|
+
|
|
156
|
+
if (role !== 'system') {
|
|
157
|
+
conversationHistory.push({ role, content });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function showTypingIndicator() {
|
|
162
|
+
document.getElementById('typingIndicator').style.display = 'block';
|
|
163
|
+
const messagesContainer = document.getElementById('messages');
|
|
164
|
+
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function hideTypingIndicator() {
|
|
168
|
+
document.getElementById('typingIndicator').style.display = 'none';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function sendMessage() {
|
|
172
|
+
const messageInput = document.getElementById('messageInput');
|
|
173
|
+
const sendBtn = document.getElementById('sendBtn');
|
|
174
|
+
const message = messageInput.value.trim();
|
|
175
|
+
|
|
176
|
+
if (!message) return;
|
|
177
|
+
|
|
178
|
+
messageInput.disabled = true;
|
|
179
|
+
sendBtn.disabled = true;
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
if (!transport) {
|
|
183
|
+
const initialized = await initializeClient();
|
|
184
|
+
if (!initialized) return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
addMessage('user', message);
|
|
188
|
+
messageInput.value = '';
|
|
189
|
+
showTypingIndicator();
|
|
190
|
+
|
|
191
|
+
const response = await transport.request(`${serverUrl}/v1/chat/completions`, {
|
|
192
|
+
method: 'POST',
|
|
193
|
+
headers: { 'Content-Type': 'application/json' },
|
|
194
|
+
body: JSON.stringify({
|
|
195
|
+
model: "qwen:0.5b",
|
|
196
|
+
messages: conversationHistory,
|
|
197
|
+
stream: true
|
|
198
|
+
})
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
hideTypingIndicator();
|
|
202
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
203
|
+
await handleStreamingResponse(response);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
hideTypingIndicator();
|
|
206
|
+
addMessage('system', `Error: ${error.message}`);
|
|
207
|
+
console.error('Chat error:', error);
|
|
208
|
+
} finally {
|
|
209
|
+
messageInput.disabled = false;
|
|
210
|
+
sendBtn.disabled = false;
|
|
211
|
+
messageInput.focus();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function handleStreamingResponse(response) {
|
|
216
|
+
const reader = response.body?.getReader();
|
|
217
|
+
if (!reader) {
|
|
218
|
+
throw new Error('No readable stream available');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const decoder = new TextDecoder();
|
|
222
|
+
let assistantMessage = '';
|
|
223
|
+
let messageDiv = null;
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
while (true) {
|
|
227
|
+
const { done, value } = await reader.read();
|
|
228
|
+
if (done) break;
|
|
229
|
+
|
|
230
|
+
const text = decoder.decode(value, { stream: true });
|
|
231
|
+
const lines = text.split('\n');
|
|
232
|
+
|
|
233
|
+
for (const line of lines) {
|
|
234
|
+
if (line.trim() === '') continue;
|
|
235
|
+
if (line.startsWith('data: ')) {
|
|
236
|
+
const data = line.slice(6);
|
|
237
|
+
if (data === '[DONE]') continue;
|
|
238
|
+
|
|
239
|
+
try {
|
|
240
|
+
const parsed = JSON.parse(data);
|
|
241
|
+
const delta = parsed.choices?.[0]?.delta;
|
|
242
|
+
if (delta?.content) {
|
|
243
|
+
assistantMessage += delta.content;
|
|
244
|
+
if (!messageDiv) {
|
|
245
|
+
const messagesContainer = document.getElementById('messages');
|
|
246
|
+
messageDiv = document.createElement('div');
|
|
247
|
+
messageDiv.className = 'message assistant';
|
|
248
|
+
messagesContainer.appendChild(messageDiv);
|
|
249
|
+
}
|
|
250
|
+
messageDiv.textContent = assistantMessage;
|
|
251
|
+
document.getElementById('messages').scrollTop = document.getElementById('messages').scrollHeight;
|
|
252
|
+
}
|
|
253
|
+
} catch (parseError) {
|
|
254
|
+
console.warn('Failed to parse streaming data:', parseError);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (assistantMessage) {
|
|
261
|
+
conversationHistory.push({ role: 'assistant', content: assistantMessage });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
} finally {
|
|
265
|
+
reader.releaseLock();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
function handleKeyDown(event) {
|
|
271
|
+
if (event.key === 'Enter' && !event.shiftKey) {
|
|
272
|
+
event.preventDefault();
|
|
273
|
+
sendMessage();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
window.sendMessage = sendMessage;
|
|
278
|
+
window.handleKeyDown = handleKeyDown;
|
|
279
|
+
|
|
280
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
281
|
+
document.getElementById('messageInput').focus();
|
|
282
|
+
});
|
|
283
|
+
</script>
|
|
284
|
+
</body>
|
|
285
|
+
</html>
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Identity } from './identity.js';
|
|
2
|
+
/**
|
|
3
|
+
* HTTP transport for EHBP
|
|
4
|
+
*/
|
|
5
|
+
export declare class Transport {
|
|
6
|
+
private clientIdentity;
|
|
7
|
+
private serverHost;
|
|
8
|
+
private serverPublicKey;
|
|
9
|
+
constructor(clientIdentity: Identity, serverHost: string, serverPublicKey: CryptoKey);
|
|
10
|
+
/**
|
|
11
|
+
* Create a new transport by fetching server public key
|
|
12
|
+
*/
|
|
13
|
+
static create(serverURL: string, clientIdentity: Identity): Promise<Transport>;
|
|
14
|
+
/**
|
|
15
|
+
* Get the server public key
|
|
16
|
+
*/
|
|
17
|
+
getServerPublicKey(): Promise<CryptoKey>;
|
|
18
|
+
/**
|
|
19
|
+
* Get the client public key
|
|
20
|
+
*/
|
|
21
|
+
getClientPublicKey(): Promise<CryptoKey>;
|
|
22
|
+
/**
|
|
23
|
+
* Make an encrypted HTTP request
|
|
24
|
+
*/
|
|
25
|
+
request(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
26
|
+
/**
|
|
27
|
+
* Convenience method for GET requests
|
|
28
|
+
*/
|
|
29
|
+
get(url: string | URL, init?: RequestInit): Promise<Response>;
|
|
30
|
+
/**
|
|
31
|
+
* Convenience method for POST requests
|
|
32
|
+
*/
|
|
33
|
+
post(url: string | URL, body?: BodyInit, init?: RequestInit): Promise<Response>;
|
|
34
|
+
/**
|
|
35
|
+
* Convenience method for PUT requests
|
|
36
|
+
*/
|
|
37
|
+
put(url: string | URL, body?: BodyInit, init?: RequestInit): Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* Convenience method for DELETE requests
|
|
40
|
+
*/
|
|
41
|
+
delete(url: string | URL, init?: RequestInit): Promise<Response>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a new transport instance
|
|
45
|
+
*/
|
|
46
|
+
export declare function createTransport(serverURL: string, clientIdentity: Identity): Promise<Transport>;
|
|
47
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC;;GAEG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,cAAc,CAAW;IACjC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,eAAe,CAAY;gBAEvB,cAAc,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS;IAMpF;;OAEG;WACU,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAwBpF;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,SAAS,CAAC;IAI9C;;OAEG;IACG,kBAAkB,IAAI,OAAO,CAAC,SAAS,CAAC;IAI9C;;OAEG;IACG,OAAO,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0E9E;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAInE;;OAEG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIrF;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAIpF;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGvE;AAED;;GAEG;AACH,wBAAsB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAErG"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Identity } from './identity.js';
|
|
2
|
+
import { PROTOCOL } from './protocol.js';
|
|
3
|
+
/**
|
|
4
|
+
* HTTP transport for EHBP
|
|
5
|
+
*/
|
|
6
|
+
export class Transport {
|
|
7
|
+
clientIdentity;
|
|
8
|
+
serverHost;
|
|
9
|
+
serverPublicKey;
|
|
10
|
+
constructor(clientIdentity, serverHost, serverPublicKey) {
|
|
11
|
+
this.clientIdentity = clientIdentity;
|
|
12
|
+
this.serverHost = serverHost;
|
|
13
|
+
this.serverPublicKey = serverPublicKey;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a new transport by fetching server public key
|
|
17
|
+
*/
|
|
18
|
+
static async create(serverURL, clientIdentity) {
|
|
19
|
+
const url = new URL(serverURL);
|
|
20
|
+
const serverHost = url.host;
|
|
21
|
+
// Fetch server public key
|
|
22
|
+
const keysURL = new URL(PROTOCOL.KEYS_PATH, serverURL);
|
|
23
|
+
const response = await fetch(keysURL.toString());
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
throw new Error(`Failed to get server public key: ${response.status}`);
|
|
26
|
+
}
|
|
27
|
+
const contentType = response.headers.get('content-type');
|
|
28
|
+
if (contentType !== PROTOCOL.KEYS_MEDIA_TYPE) {
|
|
29
|
+
throw new Error(`Invalid content type: ${contentType}`);
|
|
30
|
+
}
|
|
31
|
+
const keysData = new Uint8Array(await response.arrayBuffer());
|
|
32
|
+
const serverIdentity = await Identity.unmarshalPublicConfig(keysData);
|
|
33
|
+
const serverPublicKey = serverIdentity.getPublicKey();
|
|
34
|
+
return new Transport(clientIdentity, serverHost, serverPublicKey);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the server public key
|
|
38
|
+
*/
|
|
39
|
+
async getServerPublicKey() {
|
|
40
|
+
return this.serverPublicKey;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the client public key
|
|
44
|
+
*/
|
|
45
|
+
async getClientPublicKey() {
|
|
46
|
+
return this.clientIdentity.getPublicKey();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Make an encrypted HTTP request
|
|
50
|
+
*/
|
|
51
|
+
async request(input, init) {
|
|
52
|
+
// Extract body from init or original request before creating Request object
|
|
53
|
+
let requestBody = null;
|
|
54
|
+
if (input instanceof Request) {
|
|
55
|
+
// If input is a Request, extract its body
|
|
56
|
+
if (input.body) {
|
|
57
|
+
requestBody = await input.arrayBuffer();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// If input is URL/string, get body from init
|
|
62
|
+
requestBody = init?.body || null;
|
|
63
|
+
}
|
|
64
|
+
// Create the URL with correct host
|
|
65
|
+
let url;
|
|
66
|
+
let method;
|
|
67
|
+
let headers;
|
|
68
|
+
if (input instanceof Request) {
|
|
69
|
+
url = new URL(input.url);
|
|
70
|
+
method = input.method;
|
|
71
|
+
headers = input.headers;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
url = new URL(input);
|
|
75
|
+
method = init?.method || 'GET';
|
|
76
|
+
headers = init?.headers || {};
|
|
77
|
+
}
|
|
78
|
+
url.host = this.serverHost;
|
|
79
|
+
let request = new Request(url.toString(), {
|
|
80
|
+
method,
|
|
81
|
+
headers,
|
|
82
|
+
body: requestBody,
|
|
83
|
+
duplex: 'half'
|
|
84
|
+
});
|
|
85
|
+
// Encrypt request body if present (check the original requestBody, not request.body)
|
|
86
|
+
if (requestBody !== null && requestBody !== undefined) {
|
|
87
|
+
request = await this.clientIdentity.encryptRequest(request, this.serverPublicKey);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// No body, just set client public key header
|
|
91
|
+
const headers = new Headers(request.headers);
|
|
92
|
+
headers.set(PROTOCOL.CLIENT_PUBLIC_KEY_HEADER, await this.clientIdentity.getPublicKeyHex());
|
|
93
|
+
request = new Request(request.url, {
|
|
94
|
+
method: request.method,
|
|
95
|
+
headers,
|
|
96
|
+
body: null
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
// Make the request
|
|
100
|
+
const response = await fetch(request);
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
console.warn(`Server returned non-OK status: ${response.status}`);
|
|
103
|
+
}
|
|
104
|
+
// Check for encapsulated key header
|
|
105
|
+
const encapKeyHeader = response.headers.get(PROTOCOL.ENCAPSULATED_KEY_HEADER);
|
|
106
|
+
if (!encapKeyHeader) {
|
|
107
|
+
throw new Error(`Missing ${PROTOCOL.ENCAPSULATED_KEY_HEADER} encapsulated key header`);
|
|
108
|
+
}
|
|
109
|
+
// Decode encapsulated key
|
|
110
|
+
const serverEncapKey = new Uint8Array(encapKeyHeader.match(/.{2}/g).map(byte => parseInt(byte, 16)));
|
|
111
|
+
// Decrypt response
|
|
112
|
+
return await this.clientIdentity.decryptResponse(response, serverEncapKey);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Convenience method for GET requests
|
|
116
|
+
*/
|
|
117
|
+
async get(url, init) {
|
|
118
|
+
return this.request(url, { ...init, method: 'GET' });
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Convenience method for POST requests
|
|
122
|
+
*/
|
|
123
|
+
async post(url, body, init) {
|
|
124
|
+
return this.request(url, { ...init, method: 'POST', body });
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Convenience method for PUT requests
|
|
128
|
+
*/
|
|
129
|
+
async put(url, body, init) {
|
|
130
|
+
return this.request(url, { ...init, method: 'PUT', body });
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Convenience method for DELETE requests
|
|
134
|
+
*/
|
|
135
|
+
async delete(url, init) {
|
|
136
|
+
return this.request(url, { ...init, method: 'DELETE' });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Create a new transport instance
|
|
141
|
+
*/
|
|
142
|
+
export async function createTransport(serverURL, clientIdentity) {
|
|
143
|
+
return Transport.create(serverURL, clientIdentity);
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;GAEG;AACH,MAAM,OAAO,SAAS;IACZ,cAAc,CAAW;IACzB,UAAU,CAAS;IACnB,eAAe,CAAY;IAEnC,YAAY,cAAwB,EAAE,UAAkB,EAAE,eAA0B;QAClF,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MA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AAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,GAAiB,EAAE,IAAe,EAAE,IAAkB;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,GAAiB,EAAE,IAAe,EAAE,IAAkB;QAC9D,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,GAAiB,EAAE,IAAkB;QAChD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,SAAiB,EAAE,cAAwB;IAC/E,OAAO,SAAS,CAAC,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":";AAEA;;GAEG"}
|
package/dist/example.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Example usage of the EHBP JavaScript client
|
|
4
|
+
*/
|
|
5
|
+
import { Identity, createTransport } from './index.js';
|
|
6
|
+
async function main() {
|
|
7
|
+
console.log('EHBP JavaScript Client Example');
|
|
8
|
+
console.log('==============================');
|
|
9
|
+
try {
|
|
10
|
+
// Create client identity
|
|
11
|
+
console.log('Creating client identity...');
|
|
12
|
+
const clientIdentity = await Identity.generate();
|
|
13
|
+
console.log('Client public key:', await clientIdentity.getPublicKeyHex());
|
|
14
|
+
// Create transport (this will fetch server public key)
|
|
15
|
+
console.log('Creating transport...');
|
|
16
|
+
const serverURL = 'http://localhost:8080'; // Adjust as needed
|
|
17
|
+
const transport = await createTransport(serverURL, clientIdentity);
|
|
18
|
+
console.log('Transport created successfully');
|
|
19
|
+
// Example 1: GET request to secure endpoint
|
|
20
|
+
console.log('\n--- GET Request ---');
|
|
21
|
+
try {
|
|
22
|
+
const getResponse = await transport.get(`${serverURL}/secure`);
|
|
23
|
+
console.log('GET Response status:', getResponse.status);
|
|
24
|
+
if (getResponse.ok) {
|
|
25
|
+
const getData = await getResponse.text();
|
|
26
|
+
console.log('GET Response:', getData);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.log('GET Request failed with status:', getResponse.status);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.log('GET Request failed:', error instanceof Error ? error.message : String(error));
|
|
34
|
+
}
|
|
35
|
+
// Example 2: POST request with JSON data
|
|
36
|
+
console.log('\n--- POST Request ---');
|
|
37
|
+
try {
|
|
38
|
+
const postData = { message: 'Hello from JavaScript client!', timestamp: new Date().toISOString() };
|
|
39
|
+
const postResponse = await transport.post(`${serverURL}/secure`, JSON.stringify(postData), { headers: { 'Content-Type': 'application/json' } });
|
|
40
|
+
console.log('POST Response status:', postResponse.status);
|
|
41
|
+
if (postResponse.ok) {
|
|
42
|
+
const responseData = await postResponse.text();
|
|
43
|
+
console.log('POST Response:', responseData);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.log('POST Request failed with status:', postResponse.status);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.log('POST Request failed:', error instanceof Error ? error.message : String(error));
|
|
51
|
+
}
|
|
52
|
+
// Example 3: PUT request
|
|
53
|
+
console.log('\n--- PUT Request ---');
|
|
54
|
+
try {
|
|
55
|
+
const putData = { id: 1, name: 'Updated Item' };
|
|
56
|
+
const putResponse = await transport.put(`${serverURL}/secure`, JSON.stringify(putData), { headers: { 'Content-Type': 'application/json' } });
|
|
57
|
+
console.log('PUT Response status:', putResponse.status);
|
|
58
|
+
if (putResponse.ok) {
|
|
59
|
+
const putResponseData = await putResponse.text();
|
|
60
|
+
console.log('PUT Response:', putResponseData);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.log('PUT Request failed with status:', putResponse.status);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
console.log('PUT Request failed:', error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
69
|
+
// Example 4: Streaming request
|
|
70
|
+
console.log('\n--- Streaming Request ---');
|
|
71
|
+
try {
|
|
72
|
+
const streamResponse = await transport.get(`${serverURL}/stream`);
|
|
73
|
+
console.log('Stream Response status:', streamResponse.status);
|
|
74
|
+
if (streamResponse.ok) {
|
|
75
|
+
console.log('Streaming response (should show numbers 1-20):');
|
|
76
|
+
const reader = streamResponse.body?.getReader();
|
|
77
|
+
if (reader) {
|
|
78
|
+
const decoder = new TextDecoder();
|
|
79
|
+
let chunkCount = 0;
|
|
80
|
+
while (true) {
|
|
81
|
+
const { done, value } = await reader.read();
|
|
82
|
+
if (done)
|
|
83
|
+
break;
|
|
84
|
+
const text = decoder.decode(value, { stream: true });
|
|
85
|
+
process.stdout.write(text);
|
|
86
|
+
chunkCount++;
|
|
87
|
+
}
|
|
88
|
+
console.log(`\nStream completed with ${chunkCount} chunks`);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log('No readable stream available');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
console.log('Stream Request failed with status:', streamResponse.status);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.log('Stream Request failed:', error instanceof Error ? error.message : String(error));
|
|
100
|
+
}
|
|
101
|
+
console.log('\nExample completed successfully!');
|
|
102
|
+
console.log('\nTo test with a real server:');
|
|
103
|
+
console.log('1. Start the Go server: go run pkg/server/main.go');
|
|
104
|
+
console.log('2. Run this example: npm run example');
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error('Error:', error);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Run the example
|
|
112
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
113
|
+
main().catch(console.error);
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"example.js","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":";AAEA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEvD,KAAK,UAAU,IAAI;IACjB,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAE9C,IAAI,CAAC;QACH,yBAAyB;QACzB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;QAC3C,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,MAAM,cAAc,CAAC,eAAe,EAAE,CAAC,CAAC;QAE1E,uDAAuD;QACvD,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACrC,MAAM,SAAS,GAAG,uBAAuB,CAAC,CAAC,mBAAmB;QAC9D,MAAM,SAAS,GAAG,MAAM,eAAe,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;QACnE,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAE9C,4CAA4C;QAC5C,OAAO,CAAC,GAAG,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