-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.html
More file actions
538 lines (500 loc) · 31.7 KB
/
server.html
File metadata and controls
538 lines (500 loc) · 31.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!doctype html>
<html class="no-js" lang="en">
<head><meta charset="utf-8"/>
<meta name="viewport" content="width=device-width,initial-scale=1"/>
<meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<link rel="index" title="Index" href="genindex.html" /><link rel="search" title="Search" href="search.html" /><link rel="next" title="Python Library" href="pylib.html" /><link rel="prev" title="JSLib Reference Manual" href="modules.html" />
<!-- Generated with Sphinx 5.3.0 and Furo 2023.03.27 -->
<title>Snackabra Server - snackabra 1.0 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo.css?digest=fad236701ea90a88636c2a8c73b44ae642ed2a53" />
<link rel="stylesheet" type="text/css" href="_static/graphviz.css" />
<link rel="stylesheet" type="text/css" href="_static/styles/furo-extensions.css?digest=30d1aed668e5c3a91c3e3bf6a60b675221979f0e" />
<link rel="stylesheet" type="text/css" href="_static/css/custom.css" />
<style>
body {
--color-code-background: #f8f8f8;
--color-code-foreground: black;
}
@media not print {
body[data-theme="dark"] {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
--color-code-background: #202020;
--color-code-foreground: #d0d0d0;
}
}
}
</style></head>
<body>
<script>
document.body.dataset.theme = localStorage.getItem("theme") || "auto";
</script>
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<symbol id="svg-toc" viewBox="0 0 24 24">
<title>Contents</title>
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
<path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
</svg>
</symbol>
<symbol id="svg-menu" viewBox="0 0 24 24">
<title>Menu</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
<line x1="3" y1="12" x2="21" y2="12"></line>
<line x1="3" y1="6" x2="21" y2="6"></line>
<line x1="3" y1="18" x2="21" y2="18"></line>
</svg>
</symbol>
<symbol id="svg-arrow-right" viewBox="0 0 24 24">
<title>Expand</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</symbol>
<symbol id="svg-sun" viewBox="0 0 24 24">
<title>Light mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
<circle cx="12" cy="12" r="5"></circle>
<line x1="12" y1="1" x2="12" y2="3"></line>
<line x1="12" y1="21" x2="12" y2="23"></line>
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
<line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
<line x1="1" y1="12" x2="3" y2="12"></line>
<line x1="21" y1="12" x2="23" y2="12"></line>
<line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
<line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
</svg>
</symbol>
<symbol id="svg-moon" viewBox="0 0 24 24">
<title>Dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
</svg>
</symbol>
<symbol id="svg-sun-half" viewBox="0 0 24 24">
<title>Auto light/dark mode</title>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<circle cx="12" cy="12" r="9" />
<path d="M13 12h5" />
<path d="M13 15h4" />
<path d="M13 18h1" />
<path d="M13 9h4" />
<path d="M13 6h1" />
</svg>
</symbol>
</svg>
<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
<div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
<div class="visually-hidden">Hide table of contents sidebar</div>
</label>
<div class="page">
<header class="mobile-header">
<div class="header-left">
<label class="nav-overlay-icon" for="__navigation">
<div class="visually-hidden">Toggle site navigation sidebar</div>
<i class="icon"><svg><use href="#svg-menu"></use></svg></i>
</label>
</div>
<div class="header-center">
<a href="index.html"><div class="brand">snackabra 1.0 documentation</div></a>
</div>
<div class="header-right">
<div class="theme-toggle-container theme-toggle-header">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-header-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
</header>
<aside class="sidebar-drawer">
<div class="sidebar-container">
<div class="sidebar-sticky"><a class="sidebar-brand" href="index.html">
<span class="sidebar-brand-text">snackabra 1.0 documentation</span>
</a><form class="sidebar-search-container" method="get" action="search.html" role="search">
<input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="overview.html">Technical Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="system-architecture.html">System Architecture</a></li>
<li class="toctree-l1"><a class="reference internal" href="discussion.html">Background and Discussion</a></li>
<li class="toctree-l1"><a class="reference internal" href="formal.html">Formal Treatment</a></li>
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="contact.html">Contact and Feedback</a></li>
<li class="toctree-l1"><a class="reference internal" href="glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="future.html">Future Work</a></li>
<li class="toctree-l1"><a class="reference internal" href="references.html">References / Further Reading</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">LICENSE</a></li>
<li class="toctree-l1"><a class="reference internal" href="jslib.html">JSLib User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">JSLib Reference Manual</a></li>
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">Snackabra Server</a></li>
<li class="toctree-l1"><a class="reference internal" href="pylib.html">Python Library</a></li>
<li class="toctree-l1"><a class="reference internal" href="appendix-a-crypto.html">Appendix A: Cryptography</a></li>
<li class="toctree-l1"><a class="reference internal" href="user-guide.html">Appendix B: Privacy.App Chat Room User Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="diag-sample.html">(ignore)</a></li>
<li class="toctree-l1"><a class="reference internal" href="motivation.html">Motivation</a></li>
</ul>
</div>
</div>
</div>
</div>
</aside>
<div class="main">
<div class="content">
<div class="article-container">
<a href="#" class="back-to-top muted-link">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
</svg>
<span>Back to top</span>
</a>
<div class="content-icon-container">
<div class="theme-toggle-container theme-toggle-content">
<button class="theme-toggle">
<div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
<svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
<svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
<svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
</button>
</div>
<label class="toc-overlay-icon toc-content-icon" for="__toc">
<div class="visually-hidden">Toggle table of contents sidebar</div>
<i class="icon"><svg><use href="#svg-toc"></use></svg></i>
</label>
</div>
<article role="main">
<section id="snackabra-server">
<h1>Snackabra Server<a class="headerlink" href="#snackabra-server" title="Permalink to this heading">#</a></h1>
<section id="server-development">
<h2>Server Development<a class="headerlink" href="#server-development" title="Permalink to this heading">#</a></h2>
<p>The sdk supports Deno, Miniflare, Cloudflare, and Workerd.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">yarn</span> <span class="n">install</span>
</pre></div>
</div>
<p>SDK requires a pre-release of ‘jslib’ 0.6.0, which is not yet
published to NPM. When yarn asks, just pick the latest version that
it shows you. Next you need to clone the repo and build it
locally, or you can use one of the pre-built versions in the
<code class="docutils literal notranslate"><span class="pre">setup</span></code> directory - again just pick the highest ‘’0.5.x’’ version
that’s included.</p>
<p>Note that you might want to know about ‘’yarn link’’.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># optional, if you're making your own changes</span>
<span class="n">tsc</span> <span class="o">-</span><span class="n">w</span>
</pre></div>
</div>
<section id="ledger-key">
<h3>Ledger Key<a class="headerlink" href="#ledger-key" title="Permalink to this heading">#</a></h3>
<p>Some of the setups below will require a “LEDGER_KEY” (an RSA-OAEP key,
in ‘jwk’ format). You will need to generate that and copy-paste where instructed.</p>
<p>If you are running Node v15 or higher the mint_keys.js
script will mint and store them locally:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Node 15+</span>
<span class="n">node</span> <span class="o">./</span><span class="n">setup</span><span class="o">/</span><span class="n">mint_keys</span><span class="o">.</span><span class="n">js</span>
<span class="c1"># this should generate two files:</span>
<span class="c1"># my_private_key</span>
<span class="c1"># my_public_key</span>
</pre></div>
</div>
<p>You can also generate these in any modern browser:
open javascript / developer console and enter the following Javascript:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">let</span> <span class="n">keyPair</span> <span class="o">=</span> <span class="k">await</span> <span class="n">window</span><span class="o">.</span><span class="n">crypto</span><span class="o">.</span><span class="n">subtle</span><span class="o">.</span><span class="n">generateKey</span><span class="p">(</span>
<span class="p">{</span>
<span class="n">name</span><span class="p">:</span> <span class="s2">"RSA-OAEP"</span><span class="p">,</span>
<span class="n">modulusLength</span><span class="p">:</span> <span class="mi">4096</span><span class="p">,</span>
<span class="n">publicExponent</span><span class="p">:</span> <span class="n">new</span> <span class="n">Uint8Array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]),</span>
<span class="nb">hash</span><span class="p">:</span> <span class="s2">"SHA-256"</span>
<span class="p">},</span>
<span class="n">true</span><span class="p">,</span>
<span class="p">[</span><span class="s2">"encrypt"</span><span class="p">,</span> <span class="s2">"decrypt"</span><span class="p">]</span>
<span class="p">);</span>
<span class="n">let</span> <span class="n">my_private_key</span> <span class="o">=</span> <span class="k">await</span> <span class="n">window</span><span class="o">.</span><span class="n">crypto</span><span class="o">.</span><span class="n">subtle</span><span class="o">.</span><span class="n">exportKey</span><span class="p">(</span><span class="s2">"jwk"</span><span class="p">,</span> <span class="n">keyPair</span><span class="o">.</span><span class="n">privateKey</span><span class="p">);</span>
<span class="n">let</span> <span class="n">my_public_key</span> <span class="o">=</span> <span class="k">await</span> <span class="n">window</span><span class="o">.</span><span class="n">crypto</span><span class="o">.</span><span class="n">subtle</span><span class="o">.</span><span class="n">exportKey</span><span class="p">(</span><span class="s2">"jwk"</span><span class="p">,</span> <span class="n">keyPair</span><span class="o">.</span><span class="n">publicKey</span><span class="p">);</span>
<span class="n">JSON</span><span class="o">.</span><span class="n">stringify</span><span class="p">(</span><span class="n">my_public_key</span><span class="p">);</span>
</pre></div>
</div>
<p>(See <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey#rsa_key_pair_generation">https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey#rsa_key_pair_generation</a>)</p>
<p>You should get something like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="s1">'{"alg":"RSA-OAEP-256","e":"AQAB","ext":true,"key_ops":["encrypt"],"kty":"RSA","n":"mOmu ....</span>
</pre></div>
</div>
<p>Don’t forget to store the full / private key
somewhere secure: <code class="docutils literal notranslate"><span class="pre">JSON.stringify(my_private_key)</span></code>.</p>
<p>The resulting string (include the quotes) is the string you enter as your “LEDGER_KEY”
as needed in the below instructions (nota bene: the public key) - eg it’ll go into a <code class="docutils literal notranslate"><span class="pre">.env</span></code>
file for local environments, or put into a server secrets manager, etc.</p>
</section>
<section id="webclient">
<h3>Webclient<a class="headerlink" href="#webclient" title="Permalink to this heading">#</a></h3>
<p>If you want to connect an app like ‘’snackabra-webclient’’ to the servers you spin
up per the below instructions, make sure to direct them to your ‘’localhost’’.
For example for webclient you currently need the following in ‘’.env’’ (see the
webclient README for details):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">REACT_APP_CHANNEL_SERVER</span><span class="o">=</span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">4000</span>
<span class="n">REACT_APP_SHARD_SERVER</span><span class="o">=</span><span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">4000</span>
<span class="n">REACT_APP_CHANNEL_SERVER_WS</span><span class="o">=</span><span class="n">ws</span><span class="p">:</span><span class="o">//</span><span class="n">localhost</span><span class="p">:</span><span class="mi">4000</span>
</pre></div>
</div>
<section id="install-miniflare">
<h4>Install (miniflare)<a class="headerlink" href="#install-miniflare" title="Permalink to this heading">#</a></h4>
<p>For details see <a class="reference external" href="https://miniflare.dev/">https://miniflare.dev/</a></p>
<p>Setup is similar as to the full-fledged Cloudflare setup (below):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># copy the template 'toml' file for miniflare</span>
<span class="n">cp</span> <span class="n">setup</span><span class="o">/</span><span class="n">template</span><span class="o">.</span><span class="n">miniflare</span><span class="o">.</span><span class="n">wrangler</span><span class="o">.</span><span class="n">toml</span> <span class="n">miniflare</span><span class="o">.</span><span class="n">wrangler</span><span class="o">.</span><span class="n">toml</span>
</pre></div>
</div>
<p>Generate LEDGER_KEY as above instructions, and create a local file <code class="docutils literal notranslate"><span class="pre">.env</span></code>
that includes it.</p>
<p>Then setup packages and run:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">yarn</span> <span class="n">install</span>
<span class="n">yarn</span> <span class="n">miniflare</span>
</pre></div>
</div>
<p>It should fire up on ‘’<a class="reference external" href="http://127.0.0.1:4000">http://127.0.0.1:4000</a>’’ and ‘’ws://127.0.0.1:4000’’.</p>
</section>
<section id="install-deno">
<h4>Install (deno)<a class="headerlink" href="#install-deno" title="Permalink to this heading">#</a></h4>
<p>TODO.</p>
</section>
<section id="install-workerd">
<h4>Install (workerd)<a class="headerlink" href="#install-workerd" title="Permalink to this heading">#</a></h4>
<p>_(as of 2/8/2023, on Mac M1. this is only partiallly working,
so it is paused for the moment. we can either dig in deep,
or wait for either an update and more documentation from
Cloudlfare, or for Miniflare 3.0.0 to get released)_</p>
<p>2/8/2023: a few things that are problematic now:</p>
<ul class="simple">
<li><p>getting ‘better-sqlite’ to install</p></li>
<li><p>getting pre-release of Miniflare 3.0.0 to install</p></li>
</ul>
<p>Make sure you have latest xCode fully installed, here we are using 14.1</p>
<p>Note, workerd configuration file is documented here:
<a class="reference external" href="https://github.com/cloudflare/workerd/blob/main/src/workerd/server/workerd.capnp">https://github.com/cloudflare/workerd/blob/main/src/workerd/server/workerd.capnp</a></p>
<dl>
<dt>::</dt><dd><p># below we assume you’re “dev” directory is at “~/dev”
cd “~/dev”</p>
<p># need workerd from cloudflare
# currently i clone it at same level of this repo:
git clone <a class="reference external" href="https://github.com/cloudflare/workerd.git">https://github.com/cloudflare/workerd.git</a></p>
<p># to build workerd you need bazel:
brew install bazel</p>
<p># then you need the specific version of bazel for workerd,
# at time of writing bazel 6.0.0 will be installed but
# workerd needs 5.3.0:
cd “/opt/homebrew/Cellar/bazel/6.0.0/libexec/bin”
curl -fLO <a class="reference external" href="https://releases.bazel.build/5.3.0/release/bazel-5.3.0-darwin-arm64">https://releases.bazel.build/5.3.0/release/bazel-5.3.0-darwin-arm64</a>
chmod +x bazel-5.3.0-darwin-arm64</p>
<p># this will require recent/latest clang etc:
cd “~/dev/workerd”
bazel build –config=thin-lto //src/workerd/server:workerd</p>
<p># Note that the binary will land in bazel-bin/src/workerd/server/workerd
export “PATH=$PATH:/Users/<YOUR_USER_ID>/dev/workerd/bazel-bin/src/workerd/server”</p>
<p># now some Yarn stuff
cd ~/dev/sdk-dev
# i prefer this global, we’ll use wrangler later
yarn global add wrangler
# get the other stuff needed locally
yarn install</p>
<p># make sure jslib is available and is the latest
cd ~/dev/snackabra-jslib
git pull</p>
<p># check you have a recent typescript, i am on 4.9.5</p>
</dd>
</dl>
</section>
</section>
<section id="build-and-run-workerd">
<h3>Build and Run (workerd)<a class="headerlink" href="#build-and-run-workerd" title="Permalink to this heading">#</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># open two terminals</span>
<span class="c1"># terminal 1:</span>
<span class="n">cd</span> <span class="o">~/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdk</span><span class="o">-</span><span class="n">dev</span><span class="o">/</span><span class="n">src</span>
<span class="n">tsc</span> <span class="o">--</span><span class="n">watch</span>
<span class="c1"># terminal 2:</span>
<span class="n">cd</span> <span class="o">~/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdk</span><span class="o">-</span><span class="n">dev</span>
<span class="n">yarn</span> <span class="n">start</span>
</pre></div>
</div>
</section>
<section id="compile-workerd">
<h3>Compile (workerd)<a class="headerlink" href="#compile-workerd" title="Permalink to this heading">#</a></h3>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">cd</span> <span class="o">~/</span><span class="n">dev</span><span class="o">/</span><span class="n">sdk</span><span class="o">-</span><span class="n">dev</span>
<span class="n">yarn</span> <span class="n">build</span>
</pre></div>
</div>
<section id="install-cloudflare">
<h4>Install (Cloudflare)<a class="headerlink" href="#install-cloudflare" title="Permalink to this heading">#</a></h4>
<p>The current room server requires a domain name and a Cloudflare (CF)
account. Currently, a free CF account is _almost_ sufficient, but
“durable objects” are not available yet on the free plans, so that
sets a minimum of $5/month to host a personal server (*).</p>
<ul class="simple">
<li><p>Set up a domain (we will call it “example.com”) that you control.
You will need to be able to change the nameservers to be Cloudflare.</p></li>
<li><p>Set up a free account with CF: <a class="reference external" href="https://dash.cloudflare.com/sign-up">https://dash.cloudflare.com/sign-up</a> -
use your domain in the signup process.</p></li>
<li><p>Go to the “workers” section and pick a name for your worker on
CF, we’ll call it “example” here. That sets up a subdomain on
“workers.dev”, e.g. “example.workers.dev.” Later you can set
up “routes” from own domain.</p></li>
<li><p>Click on the “Free” button, you need to upgrade to the
“Pay-as-you-go” plan.</p></li>
</ul>
<p>Now you have the account(s) set up. You might need to check email for
when any nameservers have propagated.</p>
<p>Next set up the CF command line environment, the “Wrangler CLI”, we
use “yarn” in general but the personal server code is pure JS and
does not need any node packages. Follow instructions at
<a class="reference external" href="https://developers.cloudflare.com/workers/cli-wrangler/">https://developers.cloudflare.com/workers/cli-wrangler/</a> -
at time of writing:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># install the CLI:</span>
<span class="n">yarn</span> <span class="k">global</span> <span class="n">add</span> <span class="nd">@cloudflare</span><span class="o">/</span><span class="n">wrangler</span>
<span class="c1"># authenticate your CLI:</span>
<span class="n">wrangler</span> <span class="n">login</span>
<span class="c1"># copy the template 'toml' file</span>
<span class="n">cp</span> <span class="n">setup</span><span class="o">/</span><span class="n">template</span><span class="o">.</span><span class="n">cloudflare</span><span class="o">.</span><span class="n">wrangler</span><span class="o">.</span><span class="n">toml</span> <span class="n">cloudflare</span><span class="o">.</span><span class="n">wrangler</span><span class="o">.</span><span class="n">toml</span>
</pre></div>
</div>
<p>The ‘login’ will open a web page to confirm that your CLI is allowed
to administrate your CF account.</p>
<p>In the above ‘wrangler.toml’ file, you will need to add your ‘Account
ID’ from the dashboard. Next, you will need a few “KV Namespaces”. You
can do that with the CLI:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">wrangler</span> <span class="n">kv</span><span class="p">:</span><span class="n">namespace</span> <span class="n">create</span> <span class="s2">"MESSAGES_NAMESPACE"</span>
<span class="n">wrangler</span> <span class="n">kv</span><span class="p">:</span><span class="n">namespace</span> <span class="n">create</span> <span class="s2">"KEYS_NAMESPACE"</span>
<span class="n">wrangler</span> <span class="n">kv</span><span class="p">:</span><span class="n">namespace</span> <span class="n">create</span> <span class="s2">"LEDGER_NAMESPACE"</span>
<span class="n">wrangler</span> <span class="n">kv</span><span class="p">:</span><span class="n">namespace</span> <span class="n">create</span> <span class="s2">"IMAGES_NAMESPACE"</span>
<span class="n">wrangler</span> <span class="n">kv</span><span class="p">:</span><span class="n">namespace</span> <span class="n">create</span> <span class="s2">"RECOVERY_NAMESPACE"</span>
</pre></div>
</div>
<p>For each of them, you need to copy-paste the corresponding ‘id’ to
your <code class="docutils literal notranslate"><span class="pre">`wrangler.toml`</span></code> file.</p>
<p>Before you deploy, you need to enable “Durable Objects” for your
account. On your “Workers” dashboard there is currently a link
“Durable Objects is now generally available!” - click that.(**)</p>
<p>Finally, you need to make a tiny change to your copy of
the server code, providing a ‘secret’. This is essentially a simple
auth token that your server will request every time you create a new
room, or migrate a room over from somewhere else.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">wrangler</span> <span class="n">secret</span> <span class="n">put</span> <span class="n">SERVER_SECRET</span><span class="o"><</span><span class="n">enter</span><span class="o">></span>
</pre></div>
</div>
<p>It will prompt you to enter the secret.</p>
<p>And next you will need the ledger key from above:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">wrangler</span> <span class="n">secret</span> <span class="n">put</span> <span class="n">LEDGER_KEY</span><span class="o"><</span><span class="n">enter</span><span class="o">></span>
</pre></div>
</div>
<p>(The LEDGER_KEY string should look something like
<code class="docutils literal notranslate"><span class="pre">'{"key_ops":["encrypt"],"ext":true,"kty":"RSA","n":"6WeMtsPoblahblahU3rmDUgsc","e":"AQAB","alg":"RSA-OAEP-256"}'</span></code>).</p>
<p>Now you should be able to start your server:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">wrangler</span> <span class="n">publish</span>
</pre></div>
</div>
<p>And point a client to it!</p>
<p>(*) We are not affiliated with Cloudflare, we’re just fans.</p>
<p>Log into the Cloudflare dashboard > Workers > Durable Objects</p>
</section>
</section>
</section>
</section>
</article>
</div>
<footer>
<div class="related-pages">
<a class="next-page" href="pylib.html">
<div class="page-info">
<div class="context">
<span>Next</span>
</div>
<div class="title">Python Library</div>
</div>
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
</a>
<a class="prev-page" href="modules.html">
<svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
<div class="page-info">
<div class="context">
<span>Previous</span>
</div>
<div class="title">JSLib Reference Manual</div>
</div>
</a>
</div>
<div class="bottom-of-page">
<div class="left-details">
<div class="copyright">
Copyright © 2019-2023, Magnusson Institute
</div>
Made with <a href="https://www.sphinx-doc.org/">Sphinx</a> and <a class="muted-link" href="https://pradyunsg.me">@pradyunsg</a>'s
<a href="https://github.com/pradyunsg/furo">Furo</a>
</div>
<div class="right-details">
</div>
</div>
</footer>
</div>
<aside class="toc-drawer">
<div class="toc-sticky toc-scroll">
<div class="toc-title-container">
<span class="toc-title">
On this page
</span>
</div>
<div class="toc-tree-container">
<div class="toc-tree">
<ul>
<li><a class="reference internal" href="#">Snackabra Server</a><ul>
<li><a class="reference internal" href="#server-development">Server Development</a><ul>
<li><a class="reference internal" href="#ledger-key">Ledger Key</a></li>
<li><a class="reference internal" href="#webclient">Webclient</a><ul>
<li><a class="reference internal" href="#install-miniflare">Install (miniflare)</a></li>
<li><a class="reference internal" href="#install-deno">Install (deno)</a></li>
<li><a class="reference internal" href="#install-workerd">Install (workerd)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#build-and-run-workerd">Build and Run (workerd)</a></li>
<li><a class="reference internal" href="#compile-workerd">Compile (workerd)</a><ul>
<li><a class="reference internal" href="#install-cloudflare">Install (Cloudflare)</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</aside>
</div>
</div><script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/sphinx_highlight.js"></script>
<script src="_static/scripts/furo.js"></script>
</body>
</html>