@peerbit/server 2.0.0 → 3.0.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.
Files changed (43) hide show
  1. package/lib/esm/cli.js +67 -20
  2. package/lib/esm/cli.js.map +1 -1
  3. package/lib/esm/client.d.ts +7 -1
  4. package/lib/esm/client.js +48 -31
  5. package/lib/esm/client.js.map +1 -1
  6. package/lib/esm/config.d.ts +3 -3
  7. package/lib/esm/config.js +18 -16
  8. package/lib/esm/config.js.map +1 -1
  9. package/lib/esm/peerbit.d.ts +2 -0
  10. package/lib/esm/peerbit.js +1 -0
  11. package/lib/esm/peerbit.js.map +1 -1
  12. package/lib/esm/remotes.d.ts +1 -2
  13. package/lib/esm/remotes.js +1 -2
  14. package/lib/esm/remotes.js.map +1 -1
  15. package/lib/esm/routes.d.ts +1 -0
  16. package/lib/esm/routes.js +1 -0
  17. package/lib/esm/routes.js.map +1 -1
  18. package/lib/esm/server.d.ts +2 -6
  19. package/lib/esm/server.js +161 -176
  20. package/lib/esm/server.js.map +1 -1
  21. package/lib/esm/signes-request.d.ts +5 -0
  22. package/lib/esm/signes-request.js +54 -0
  23. package/lib/esm/signes-request.js.map +1 -0
  24. package/lib/esm/trust.browser.d.ts +0 -0
  25. package/lib/esm/trust.browser.js +3 -0
  26. package/lib/esm/trust.browser.js.map +1 -0
  27. package/lib/esm/trust.d.ts +9 -0
  28. package/lib/esm/trust.js +36 -0
  29. package/lib/esm/trust.js.map +1 -0
  30. package/lib/ui/assets/index-cac7195d.js +77 -0
  31. package/lib/ui/index.html +1 -1
  32. package/package.json +4 -4
  33. package/src/cli.ts +81 -25
  34. package/src/client.ts +77 -35
  35. package/src/config.ts +21 -23
  36. package/src/peerbit.ts +3 -0
  37. package/src/remotes.ts +1 -3
  38. package/src/routes.ts +1 -1
  39. package/src/server.ts +205 -241
  40. package/src/signes-request.ts +84 -0
  41. package/src/trust.browser.ts +1 -0
  42. package/src/trust.ts +39 -0
  43. package/lib/ui/assets/index-73eaa3bc.js +0 -53
@@ -0,0 +1 @@
1
+ // Not supported
package/src/trust.ts ADDED
@@ -0,0 +1,39 @@
1
+ import fs from "fs";
2
+
3
+ export class Trust {
4
+ private trusted: string[];
5
+ constructor(readonly path: string) {
6
+ if (fs.existsSync(path)) {
7
+ this.trusted = JSON.parse(
8
+ fs.readFileSync(path).toString("utf-8")
9
+ ) as string[];
10
+ } else {
11
+ this.trusted = [];
12
+ }
13
+ }
14
+
15
+ save() {
16
+ fs.writeFileSync(this.path, JSON.stringify(this.trusted));
17
+ }
18
+
19
+ isTrusted(hashcode: string) {
20
+ return this.trusted.includes(hashcode);
21
+ }
22
+
23
+ add(key: string) {
24
+ if (this.isTrusted(key)) {
25
+ return;
26
+ }
27
+ this.trusted.push(key);
28
+ this.save();
29
+ }
30
+
31
+ remove(hashcode: string) {
32
+ const existing = this.trusted.findIndex((x) => (x = hashcode));
33
+ if (existing >= 0) {
34
+ this.trusted.splice(existing, 1);
35
+ return true;
36
+ }
37
+ return false;
38
+ }
39
+ }