ehbp 0.0.3 → 0.0.5

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 (69) hide show
  1. package/dist/cjs/client.d.ts +51 -0
  2. package/dist/cjs/client.d.ts.map +1 -0
  3. package/dist/cjs/client.js +160 -0
  4. package/dist/cjs/client.js.map +1 -0
  5. package/dist/cjs/identity.d.ts +52 -0
  6. package/dist/cjs/identity.d.ts.map +1 -0
  7. package/dist/cjs/identity.js +275 -0
  8. package/dist/cjs/identity.js.map +1 -0
  9. package/{src/index.ts → dist/cjs/index.d.ts} +2 -4
  10. package/dist/cjs/index.d.ts.map +1 -0
  11. package/dist/cjs/index.js +19 -0
  12. package/dist/cjs/index.js.map +1 -0
  13. package/dist/cjs/package.json +1 -0
  14. package/dist/cjs/protocol.d.ts +19 -0
  15. package/dist/cjs/protocol.d.ts.map +1 -0
  16. package/dist/cjs/protocol.js +22 -0
  17. package/dist/cjs/protocol.js.map +1 -0
  18. package/dist/esm/client.d.ts +51 -0
  19. package/dist/esm/client.d.ts.map +1 -0
  20. package/dist/esm/client.js +155 -0
  21. package/dist/esm/client.js.map +1 -0
  22. package/dist/esm/example.d.ts +6 -0
  23. package/dist/esm/example.d.ts.map +1 -0
  24. package/dist/esm/example.js +115 -0
  25. package/dist/esm/example.js.map +1 -0
  26. package/dist/esm/identity.d.ts +52 -0
  27. package/dist/esm/identity.d.ts.map +1 -0
  28. package/dist/esm/identity.js +271 -0
  29. package/dist/esm/identity.js.map +1 -0
  30. package/dist/esm/index.d.ts +12 -0
  31. package/dist/esm/index.d.ts.map +1 -0
  32. package/dist/esm/index.js +11 -0
  33. package/dist/esm/index.js.map +1 -0
  34. package/dist/esm/package.json +1 -0
  35. package/dist/esm/protocol.d.ts +19 -0
  36. package/dist/esm/protocol.d.ts.map +1 -0
  37. package/dist/esm/protocol.js +19 -0
  38. package/dist/esm/protocol.js.map +1 -0
  39. package/dist/esm/streaming-test.d.ts +3 -0
  40. package/dist/esm/streaming-test.d.ts.map +1 -0
  41. package/dist/esm/streaming-test.js +102 -0
  42. package/dist/esm/streaming-test.js.map +1 -0
  43. package/dist/esm/test/client.test.d.ts +2 -0
  44. package/dist/esm/test/client.test.d.ts.map +1 -0
  45. package/dist/esm/test/client.test.js +71 -0
  46. package/dist/esm/test/client.test.js.map +1 -0
  47. package/dist/esm/test/identity.test.d.ts +2 -0
  48. package/dist/esm/test/identity.test.d.ts.map +1 -0
  49. package/dist/esm/test/identity.test.js +39 -0
  50. package/dist/esm/test/identity.test.js.map +1 -0
  51. package/dist/esm/test/streaming.test.d.ts +2 -0
  52. package/dist/esm/test/streaming.test.d.ts.map +1 -0
  53. package/dist/esm/test/streaming.test.js +71 -0
  54. package/dist/esm/test/streaming.test.js.map +1 -0
  55. package/package.json +7 -2
  56. package/build-browser.js +0 -54
  57. package/chat.html +0 -285
  58. package/src/client.ts +0 -181
  59. package/src/example.ts +0 -126
  60. package/src/identity.ts +0 -339
  61. package/src/protocol.ts +0 -19
  62. package/src/streaming-test.ts +0 -118
  63. package/src/test/client.test.ts +0 -93
  64. package/src/test/identity.test.ts +0 -46
  65. package/src/test/streaming.test.ts +0 -85
  66. package/test.html +0 -271
  67. package/tsconfig.cjs.json +0 -8
  68. package/tsconfig.esm.json +0 -7
  69. package/tsconfig.json +0 -19
@@ -1,46 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
- import { Identity } from '../identity.js';
4
-
5
- describe('Identity', () => {
6
- it('should generate a new identity', async () => {
7
- const identity = await Identity.generate();
8
-
9
- assert(identity.getPublicKey() instanceof CryptoKey, 'Public key should be a CryptoKey');
10
- assert(identity.getPrivateKey() instanceof CryptoKey, 'Private key should be a CryptoKey');
11
- const publicKeyHex = await identity.getPublicKeyHex();
12
- assert(publicKeyHex.length > 0, 'Public key hex should not be empty');
13
- });
14
-
15
- it('should serialize and deserialize identity', async () => {
16
- const original = await Identity.generate();
17
- const json = await original.toJSON();
18
- const restored = await Identity.fromJSON(json);
19
-
20
- const originalHex = await original.getPublicKeyHex();
21
- const restoredHex = await restored.getPublicKeyHex();
22
- assert(originalHex === restoredHex, 'Public keys should match');
23
- assert(original.getPrivateKey() instanceof CryptoKey, 'Private key should be a CryptoKey');
24
- assert(restored.getPrivateKey() instanceof CryptoKey, 'Private key should be a CryptoKey');
25
- });
26
-
27
- it('should marshal configuration', async () => {
28
- const identity = await Identity.generate();
29
- const config = await identity.marshalConfig();
30
-
31
- assert(config.length > 0, 'Config should not be empty');
32
- assert(config[0] === 0, 'Key ID should be 0');
33
- assert(config[1] === 0x00, 'KEM ID high byte should be 0x00');
34
- assert(config[2] === 0x20, 'KEM ID low byte should be 0x20');
35
- });
36
-
37
- it('should unmarshal public configuration', async () => {
38
- const identity = await Identity.generate();
39
- const config = await identity.marshalConfig();
40
- const restored = await Identity.unmarshalPublicConfig(config);
41
-
42
- const originalHex = await identity.getPublicKeyHex();
43
- const restoredHex = await restored.getPublicKeyHex();
44
- assert(restoredHex === originalHex, 'Public keys should match');
45
- });
46
- });
@@ -1,85 +0,0 @@
1
- import { describe, it } from 'node:test';
2
- import assert from 'node:assert';
3
-
4
- describe('Streaming', () => {
5
-
6
- it('should handle streaming responses', async () => {
7
- // Create a mock streaming response
8
- const mockStreamData = 'Number: 1\nNumber: 2\nNumber: 3\n';
9
- const mockResponse = new Response(mockStreamData, {
10
- status: 200,
11
- headers: {
12
- 'Content-Type': 'text/plain',
13
- 'Ehbp-Encapsulated-Key': 'abcd1234' // Mock encapsulated key
14
- }
15
- });
16
-
17
- // Test that we can read from a stream
18
- const reader = mockResponse.body?.getReader();
19
- assert(reader, 'Response should have a readable stream');
20
-
21
- const decoder = new TextDecoder();
22
- let receivedData = '';
23
-
24
- while (true) {
25
- const { done, value } = await reader.read();
26
- if (done) break;
27
-
28
- const text = decoder.decode(value, { stream: true });
29
- receivedData += text;
30
- }
31
-
32
- assert(receivedData === mockStreamData, 'Should receive all stream data');
33
- });
34
-
35
- it('should handle empty streams', async () => {
36
- const emptyResponse = new Response('', {
37
- status: 200,
38
- headers: {
39
- 'Ehbp-Encapsulated-Key': 'abcd1234'
40
- }
41
- });
42
-
43
- const reader = emptyResponse.body?.getReader();
44
- assert(reader, 'Response should have a readable stream');
45
-
46
- const { done } = await reader.read();
47
- assert(done, 'Empty stream should be done immediately');
48
- });
49
-
50
- it('should handle chunked data correctly', async () => {
51
- // Simulate chunked data
52
- const chunks = ['Hello', ' ', 'World', '!'];
53
- const stream = new ReadableStream({
54
- start(controller) {
55
- chunks.forEach(chunk => {
56
- controller.enqueue(new TextEncoder().encode(chunk));
57
- });
58
- controller.close();
59
- }
60
- });
61
-
62
- const response = new Response(stream, {
63
- status: 200,
64
- headers: {
65
- 'Ehbp-Encapsulated-Key': 'abcd1234'
66
- }
67
- });
68
-
69
- const reader = response.body?.getReader();
70
- assert(reader, 'Response should have a readable stream');
71
-
72
- const decoder = new TextDecoder();
73
- let receivedData = '';
74
-
75
- while (true) {
76
- const { done, value } = await reader.read();
77
- if (done) break;
78
-
79
- const text = decoder.decode(value, { stream: true });
80
- receivedData += text;
81
- }
82
-
83
- assert(receivedData === 'Hello World!', 'Should receive all chunks correctly');
84
- });
85
- });
package/test.html DELETED
@@ -1,271 +0,0 @@
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 Streaming Test</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: 20px;
18
- border-radius: 8px;
19
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
20
- }
21
- h1 {
22
- color: #333;
23
- text-align: center;
24
- }
25
- .test-section {
26
- margin: 20px 0;
27
- padding: 15px;
28
- border: 1px solid #ddd;
29
- border-radius: 5px;
30
- }
31
- .test-section h3 {
32
- margin-top: 0;
33
- color: #555;
34
- }
35
- button {
36
- background-color: #007bff;
37
- color: white;
38
- border: none;
39
- padding: 10px 20px;
40
- border-radius: 4px;
41
- cursor: pointer;
42
- margin: 5px;
43
- }
44
- button:hover {
45
- background-color: #0056b3;
46
- }
47
- button:disabled {
48
- background-color: #6c757d;
49
- cursor: not-allowed;
50
- }
51
- .output {
52
- background-color: #f8f9fa;
53
- border: 1px solid #dee2e6;
54
- border-radius: 4px;
55
- padding: 10px;
56
- margin: 10px 0;
57
- height: 100px;
58
- font-family: monospace;
59
- white-space: pre-wrap;
60
- overflow-y: auto;
61
- }
62
- .status {
63
- padding: 10px;
64
- margin: 10px 0;
65
- border-radius: 4px;
66
- }
67
- .status.success {
68
- background-color: #d4edda;
69
- color: #155724;
70
- border: 1px solid #c3e6cb;
71
- }
72
- .status.error {
73
- background-color: #f8d7da;
74
- color: #721c24;
75
- border: 1px solid #f5c6cb;
76
- }
77
- .status.info {
78
- background-color: #d1ecf1;
79
- color: #0c5460;
80
- border: 1px solid #bee5eb;
81
- }
82
- .clear-btn {
83
- background-color: #6c757d;
84
- }
85
- .clear-btn:hover {
86
- background-color: #545b62;
87
- }
88
- </style>
89
- </head>
90
- <body>
91
- <div class="container">
92
- <h1>EHBP Test</h1>
93
-
94
- <div class="test-section">
95
- <h3>Server Configuration</h3>
96
- <label for="serverUrl">Server URL:</label>
97
- <input type="text" id="serverUrl" value="http://localhost:8080" style="width: 300px; padding: 5px; margin: 5px;">
98
- <div id="serverStatus" class="status info">Ready to test</div>
99
- </div>
100
-
101
- <div class="test-section">
102
- <h3>Test 1: POST to /secure</h3>
103
- <button id="test1Btn" onclick="runTest1()">Run POST Test</button>
104
- <button class="clear-btn" onclick="clearOutput('test1Output')">Clear</button>
105
- <div id="test1Output" class="output"></div>
106
- </div>
107
-
108
- <div class="test-section">
109
- <h3>Test 2: Streaming</h3>
110
- <button id="test2Btn" onclick="runTest2()">Run Streaming Test</button>
111
- <button class="clear-btn" onclick="clearOutput('test2Output')">Clear</button>
112
- <div id="test2Output" class="output"></div>
113
- </div>
114
-
115
- </div>
116
-
117
- <script type="module">
118
- import { Identity, createTransport } from './dist/browser.js';
119
-
120
- let transport = null;
121
- let clientIdentity = null;
122
-
123
- async function initializeClient() {
124
- try {
125
- updateStatus('serverStatus', 'info', 'Initializing client...');
126
- clientIdentity = await Identity.generate();
127
- const serverUrl = document.getElementById('serverUrl').value;
128
- transport = await createTransport(serverUrl, clientIdentity);
129
- updateStatus('serverStatus', 'success', `Connected to ${serverUrl}`);
130
- return true;
131
- } catch (error) {
132
- updateStatus('serverStatus', 'error', `Failed to connect: ${error.message}`);
133
- return false;
134
- }
135
- }
136
-
137
- function updateStatus(elementId, type, message) {
138
- const element = document.getElementById(elementId);
139
- element.className = `status ${type}`;
140
- element.textContent = message;
141
- }
142
-
143
- function appendOutput(elementId, text) {
144
- const element = document.getElementById(elementId);
145
- element.textContent += text;
146
- element.scrollTop = element.scrollHeight;
147
- }
148
-
149
- function clearOutput(elementId) {
150
- document.getElementById(elementId).textContent = '';
151
- }
152
-
153
- function clearAllOutputs() {
154
- clearOutput('test1Output');
155
- clearOutput('test2Output');
156
- }
157
-
158
- async function runTest1() {
159
- const btn = document.getElementById('test1Btn');
160
- const output = document.getElementById('test1Output');
161
-
162
- btn.disabled = true;
163
- clearOutput('test1Output');
164
-
165
- let endpoint = '/secure';
166
- const exampleName = 'John Doe';
167
-
168
- appendOutput('test1Output', 'Starting POST ' + endpoint + ' test...\n');
169
-
170
- try {
171
- if (!transport) {
172
- const initialized = await initializeClient();
173
- if (!initialized) return;
174
- }
175
-
176
- const serverUrl = document.getElementById('serverUrl').value;
177
-
178
- try {
179
- const testBody = "John Doe";
180
- appendOutput('test1Output', `Sending POST request with body: ${testBody}\n`);
181
-
182
- const response1 = await transport.post(`${serverUrl}${endpoint}`, testBody, {
183
- headers: {
184
- 'Content-Type': 'text/plain'
185
- }
186
- });
187
-
188
- appendOutput('test1Output', `Response status: ${response1.status}\n`);
189
- if (response1.ok) {
190
- const responseText = await response1.text();
191
- appendOutput('test1Output', `Response body: ${responseText}\n`);
192
- if (responseText !== "Hello, "+exampleName) {
193
- appendOutput('test1Output', '✗ Basic POST test failed with response: '+responseText+'\n\n');
194
- return;
195
- } else {
196
- appendOutput('test1Output', '✓ Basic POST test passed\n\n');
197
- }
198
- } else {
199
- appendOutput('test1Output', `✗ Basic POST test failed with status: ${response1.status}\n\n`);
200
- }
201
- } catch (error) {
202
- appendOutput('test1Output', `✗ Basic POST test failed with error: ${error.message}\n\n`);
203
- }
204
-
205
- appendOutput('test1Output', 'POST ' + endpoint + ' test completed!\n');
206
- } catch (error) {
207
- appendOutput('test1Output', `Error: ${error.message}\n`);
208
- } finally {
209
- btn.disabled = false;
210
- }
211
- }
212
-
213
- async function runTest2() {
214
- const btn = document.getElementById('test2Btn');
215
- const output = document.getElementById('test2Output');
216
-
217
- btn.disabled = true;
218
- clearOutput('test2Output');
219
- appendOutput('test2Output', 'Starting basic streaming test...\n');
220
-
221
- try {
222
- if (!transport) {
223
- const initialized = await initializeClient();
224
- if (!initialized) return;
225
- }
226
-
227
- const serverUrl = document.getElementById('serverUrl').value;
228
- const response = await transport.get(`${serverUrl}/stream`);
229
-
230
- appendOutput('test2Output', `Stream response status: ${response.status}\n`);
231
-
232
- if (response.ok) {
233
- appendOutput('test2Output', 'Reading stream data...\n');
234
- const reader = response.body?.getReader();
235
-
236
- if (reader) {
237
- const decoder = new TextDecoder();
238
-
239
- while (true) {
240
- const { done, value } = await reader.read();
241
- if (done) break;
242
-
243
- const text = decoder.decode(value, { stream: true });
244
- appendOutput('test2Output', text);
245
- }
246
-
247
- appendOutput('test2Output', '\nStream completed!\n');
248
- } else {
249
- appendOutput('test2Output', 'No readable stream available\n');
250
- }
251
- } else {
252
- appendOutput('test2Output', `Stream request failed with status: ${response.status}\n`);
253
- }
254
- } catch (error) {
255
- appendOutput('test2Output', `Error: ${error.message}\n`);
256
- } finally {
257
- btn.disabled = false;
258
- }
259
- }
260
-
261
- window.runTest1 = runTest1;
262
- window.runTest2 = runTest2;
263
- window.clearOutput = clearOutput;
264
- window.clearAllOutputs = clearAllOutputs;
265
-
266
- document.addEventListener('DOMContentLoaded', () => {
267
- updateStatus('serverStatus', 'info', 'Ready to test - click a test button to start');
268
- });
269
- </script>
270
- </body>
271
- </html>
package/tsconfig.cjs.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "CommonJS",
5
- "outDir": "./dist/cjs"
6
- },
7
- "exclude": ["node_modules", "dist", "src/example.ts", "src/streaming-test.ts", "src/test"]
8
- }
package/tsconfig.esm.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "module": "ESNext",
5
- "outDir": "./dist/esm"
6
- }
7
- }
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "ESNext",
5
- "moduleResolution": "node",
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "declaration": true,
13
- "declarationMap": true,
14
- "sourceMap": true,
15
- "resolveJsonModule": true
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist"]
19
- }