@optimystic/db-p2p 0.1.2 → 0.2.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 (45) hide show
  1. package/README.md +44 -0
  2. package/dist/index.min.js +17 -17
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/cluster/client.d.ts +1 -2
  5. package/dist/src/cluster/client.d.ts.map +1 -1
  6. package/dist/src/cluster/client.js.map +1 -1
  7. package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
  8. package/dist/src/cluster/cluster-repo.js +10 -1
  9. package/dist/src/cluster/cluster-repo.js.map +1 -1
  10. package/dist/src/libp2p-key-network.d.ts.map +1 -1
  11. package/dist/src/libp2p-key-network.js +4 -4
  12. package/dist/src/libp2p-key-network.js.map +1 -1
  13. package/dist/src/libp2p-node-base.d.ts +53 -0
  14. package/dist/src/libp2p-node-base.d.ts.map +1 -0
  15. package/dist/src/libp2p-node-base.js +291 -0
  16. package/dist/src/libp2p-node-base.js.map +1 -0
  17. package/dist/src/libp2p-node-rn.d.ts +11 -0
  18. package/dist/src/libp2p-node-rn.d.ts.map +1 -0
  19. package/dist/src/libp2p-node-rn.js +19 -0
  20. package/dist/src/libp2p-node-rn.js.map +1 -0
  21. package/dist/src/libp2p-node.d.ts +3 -37
  22. package/dist/src/libp2p-node.d.ts.map +1 -1
  23. package/dist/src/libp2p-node.js +6 -287
  24. package/dist/src/libp2p-node.js.map +1 -1
  25. package/dist/src/protocol-client.d.ts +1 -2
  26. package/dist/src/protocol-client.d.ts.map +1 -1
  27. package/dist/src/protocol-client.js.map +1 -1
  28. package/dist/src/repo/client.d.ts +1 -2
  29. package/dist/src/repo/client.d.ts.map +1 -1
  30. package/dist/src/repo/client.js.map +1 -1
  31. package/dist/src/rn.d.ts +29 -0
  32. package/dist/src/rn.d.ts.map +1 -0
  33. package/dist/src/rn.js +29 -0
  34. package/dist/src/rn.js.map +1 -0
  35. package/package.json +6 -2
  36. package/src/cluster/client.ts +1 -2
  37. package/src/cluster/cluster-repo.ts +9 -1
  38. package/src/index.ts +0 -2
  39. package/src/libp2p-key-network.ts +5 -6
  40. package/src/libp2p-node-base.ts +386 -0
  41. package/src/libp2p-node-rn.ts +30 -0
  42. package/src/libp2p-node.ts +14 -364
  43. package/src/protocol-client.ts +3 -3
  44. package/src/repo/client.ts +1 -2
  45. package/src/rn.ts +28 -0
package/README.md CHANGED
@@ -483,6 +483,50 @@ const node = await createLibp2pNode({
483
483
  });
484
484
  ```
485
485
 
486
+ #### Custom transports (including React Native)
487
+
488
+ By default, `createLibp2pNode()` uses TCP + circuit-relay transport.
489
+
490
+ To use non-default transports, pass `transports` (and typically `listenAddrs`):
491
+
492
+ ```typescript
493
+ import { webSockets } from '@libp2p/websockets';
494
+ import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
495
+ import { createLibp2pNode } from '@optimystic/db-p2p';
496
+
497
+ const node = await createLibp2pNode({
498
+ networkName: 'mynet',
499
+ bootstrapNodes: ['/dns4/relay.example.com/tcp/443/wss/p2p/12D3...'],
500
+ transports: [webSockets(), circuitRelayTransport()],
501
+ listenAddrs: [], // client-only; no incoming connections
502
+ });
503
+ ```
504
+
505
+ #### React Native
506
+
507
+ For React Native, import from `@optimystic/db-p2p/rn` instead of the root entrypoint.
508
+ The `/rn` entrypoint does **not** import `@libp2p/tcp`, so Metro/Hermes won't try to
509
+ bundle Node-only native modules. It requires `options.transports` explicitly:
510
+
511
+ ```typescript
512
+ import { webSockets } from '@libp2p/websockets';
513
+ import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
514
+ import { createLibp2pNode } from '@optimystic/db-p2p/rn';
515
+
516
+ const node = await createLibp2pNode({
517
+ networkName: 'mynet',
518
+ bootstrapNodes: ['/dns4/relay.example.com/tcp/443/wss/p2p/12D3...'],
519
+ transports: [webSockets(), circuitRelayTransport()],
520
+ });
521
+ ```
522
+
523
+ RN environments (Hermes, JSC) may also need polyfills for globals that libp2p
524
+ and its dependencies expect. Install these early (e.g. in your app's entry file
525
+ before any other imports):
526
+
527
+ - `crypto.getRandomValues` — e.g. `react-native-get-random-values`
528
+ - `TextEncoder` / `TextDecoder` — e.g. `text-encoding` or `fast-text-encoding`
529
+
486
530
  ### Ring Transitions
487
531
 
488
532
  Nodes automatically transition between rings based on capacity thresholds: