dignity.js 0.5.3 → 0.6.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.
- package/README.md +61 -3
- package/dist/dignity.cjs.js +603 -65
- package/dist/dignity.cjs.js.map +4 -4
- package/dist/dignity.esm.js +603 -65
- package/dist/dignity.esm.js.map +3 -3
- package/dist/dignity.min.js +27 -27
- package/docs/assets/dignity.esm.js +477 -51
- package/docs/index.html +346 -6
- package/docs/openapi-like.json +40 -5
- package/examples/decentralized-chess-lite.js +9 -0
- package/package.json +2 -1
- package/src/core/dignity-p2p.js +506 -20
- package/src/gossip/peer-group.js +64 -0
- package/src/index.js +13 -1
- package/src/network/in-memory-network.js +42 -0
- package/src/network/peerjs-network.js +28 -0
- package/src/persistence/indexeddb-persistence.js +2 -0
- package/src/security/message-security-service.js +10 -2
- package/src/security/sloth-vdf.js +11 -5
- package/src/signaling/websocket-signaling-provider.js +11 -2
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/dignity.js)
|
|
7
7
|
[](https://www.npmjs.com/package/dignity.js)
|
|
8
8
|
[](https://github.com/jose-compu/dignity.js/actions/workflows/ci.yml)
|
|
9
|
-

|
|
10
|
+

|
|
11
11
|

|
|
12
12
|
|
|
13
13
|
REST-like P2P object API for decentralized JavaScript applications.
|
|
@@ -29,6 +29,7 @@ REST-like P2P object API for decentralized JavaScript applications.
|
|
|
29
29
|
- Optimistic concurrency helpers (`expectedVersion`, `updateWithRetry`, `conflict` events)
|
|
30
30
|
- PeerJS mesh bootstrap: connect before announce/broadcast, auto `publicKey` in presence
|
|
31
31
|
- Late-joiner sync via `pushRecordSnapshot` (full record catch-up when create was missed)
|
|
32
|
+
- Content hashes on active records via `record.hash` (`sha512:` over canonicalized `data`)
|
|
32
33
|
- Auto `connectToPeers` on create/update/delete replication (owner + collaborators)
|
|
33
34
|
- Optional IndexedDB persistence for browser reload survival
|
|
34
35
|
- Optional React hooks via `dignity.js/react`
|
|
@@ -40,6 +41,10 @@ REST-like P2P object API for decentralized JavaScript applications.
|
|
|
40
41
|
npm install dignity.js
|
|
41
42
|
```
|
|
42
43
|
|
|
44
|
+
## Tutorial
|
|
45
|
+
|
|
46
|
+
**New to dignity.js?** Start with [TUTORIAL.md](./TUTORIAL.md) — eight short lessons from two in-memory peers to browser PeerJS and PeerGroup spectators. The [docs site tutorial](https://jose-compu.github.io/dignity.js/#tutorial) covers the same path.
|
|
47
|
+
|
|
43
48
|
## Quick Start
|
|
44
49
|
|
|
45
50
|
```js
|
|
@@ -119,6 +124,24 @@ await node.create('matches', { mode: 'coop' }, {
|
|
|
119
124
|
|
|
120
125
|
Peers with a different password for `coop:red` cannot decrypt that broadcast traffic.
|
|
121
126
|
|
|
127
|
+
## PeerGroup Gossip (scalable PubSub)
|
|
128
|
+
|
|
129
|
+
For high-fanout object updates (millions of subscribers per published object), use multiplexed gossip groups. Each peer keeps a bounded number of active transports (`maxActivePeers` per group, `globalMaxOpenConnections` per node).
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
// Follow 200 accounts = 200 joined groups, few connections each
|
|
133
|
+
await node.joinPeerGroup('feed:alice', {
|
|
134
|
+
bootstrapPeerIds: ['publisher-peer-id'],
|
|
135
|
+
fanout: 3,
|
|
136
|
+
maxActivePeers: 8
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await node.publishRecordToPeerGroup('feed:alice', 'posts', 'post-1');
|
|
140
|
+
await node.leavePeerGroup('feed:alice');
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Small collaborations (chess players, document co-editing) should keep using direct `connectToPeers` mesh. Large read-only audiences (chess spectators, public timelines) should use PeerGroup gossip. See the [docs PeerGroup section](https://jose-compu.github.io/dignity.js/#peer-groups).
|
|
144
|
+
|
|
122
145
|
## Room / Team Discovery
|
|
123
146
|
|
|
124
147
|
Use scoped discovery to find active peers in a room (for example `main`, `team:red`, `raid-42`).
|
|
@@ -161,6 +184,23 @@ await node.updateWithRetry('games', 'g1', (current) => ({
|
|
|
161
184
|
|
|
162
185
|
Use `expectedVersion` for fail-fast local writes. Use `updateWithRetry` for read-modify-write loops in fast multiplayer state.
|
|
163
186
|
|
|
187
|
+
## Record Content Hashes
|
|
188
|
+
|
|
189
|
+
Active records returned by `create`, `read`, `list`, `update`, and `pushRecordSnapshot` include a `hash` field:
|
|
190
|
+
|
|
191
|
+
```js
|
|
192
|
+
const record = await node.create('notes', { title: 'hello' }, { id: 'n1' });
|
|
193
|
+
console.log(record.hash); // sha512:...
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Hash details:
|
|
197
|
+
|
|
198
|
+
- The algorithm is `sha512`, matching `tweetnacl.hash` in both browser and Node builds.
|
|
199
|
+
- The digest covers only `record.data`, not `id`, `ownerId`, timestamps, collaborators, or version.
|
|
200
|
+
- Data is canonicalized with `stableStringify`, so object key order does not affect the hash.
|
|
201
|
+
- Snapshot restore recomputes the digest locally and emits a `warning` with type `content-hash-mismatch` if a remote advertised hash does not match the received `data`.
|
|
202
|
+
- Deleted tombstones returned by `list(collection, { includeDeleted: true })` intentionally omit `hash`.
|
|
203
|
+
|
|
164
204
|
## IndexedDB Persistence
|
|
165
205
|
|
|
166
206
|
Persist replicated collections across page reloads:
|
|
@@ -291,6 +331,24 @@ The joiner applies the snapshot via `restoreRecord`, then subsequent move update
|
|
|
291
331
|
|
|
292
332
|
## Development
|
|
293
333
|
|
|
334
|
+
| Script | Purpose | Notes |
|
|
335
|
+
| --- | --- | --- |
|
|
336
|
+
| `npm test` | Run the full Jest suite with coverage. | Standard local validation before opening a PR or publishing. |
|
|
337
|
+
| `npm run test:unit` | Run the unit-test subset only. | Useful for faster local iteration. |
|
|
338
|
+
| `npm run test:cloudflare-live` | Run the live Cloudflare signaling integration test. | Opt-in; set `RUN_CLOUDFLARE_LIVE_TESTS=1`. |
|
|
339
|
+
| `npm run test:pow-calibrate` | Run the Sloth VDF timing calibration test without coverage. | Opt-in; set `RUN_POW_CALIBRATE=1`. |
|
|
340
|
+
| `npm run build` | Build the published package bundles into `dist/`. | Run after changing library source files. |
|
|
341
|
+
| `npm run build:chess` | Rebuild the browser chess demo bundle only. | Used by the docs site and local chess demo. |
|
|
342
|
+
| `npm run docs:favicon` | Regenerate the docs favicon assets. | Docs maintenance helper. |
|
|
343
|
+
| `npm run docs:build` | Build the docs-specific assets. | Currently rebuilds the chess demo bundle. |
|
|
344
|
+
| `npm run docs:dev` | Start the local docs server. | Serves the main docs and chess demo; auto-builds chess if needed. |
|
|
345
|
+
| `npm run docs:serve` | Start the same local docs server via an alias. | Equivalent to `docs:dev`. |
|
|
346
|
+
| `npm run docs:stop` | Stop the background docs server from a previous run. | Useful if port `4173` is stuck. |
|
|
347
|
+
| `npm run docs:check` | Verify the generated docs assets exist. | Good quick check after docs asset generation. |
|
|
348
|
+
| `npm run example:tictactoe` | Run the Node tic-tac-toe example. | Demonstrates a minimal replicated game flow. |
|
|
349
|
+
| `npm run example:chess` | Run the Node chess example. | Demonstrates the lighter-weight chess sample. |
|
|
350
|
+
| `npm run prepublishOnly` | Run the publish gate locally. | Publish/CI-oriented hook; runs tests and build before `npm publish`. |
|
|
351
|
+
|
|
294
352
|
```bash
|
|
295
353
|
npm test
|
|
296
354
|
npm run build
|
|
@@ -324,7 +382,7 @@ If 4173 is busy, `docs:dev` auto-picks the next free port (4174, 4175, …) and
|
|
|
324
382
|
|
|
325
383
|
- **Documentation:** [jose-compu.github.io/dignity.js](https://jose-compu.github.io/dignity.js/)
|
|
326
384
|
- Docs site source: `docs/index.html` (local: `npm run docs:dev`)
|
|
327
|
-
- **3D Chess demo:** `docs/chess/` → [local chess demo](http://127.0.0.1:4173/chess/) when `docs:dev` is running
|
|
385
|
+
- **3D Chess demo:** `docs/chess/` — PeerJS mesh, dual-signed resume links, IndexedDB → [local chess demo](http://127.0.0.1:4173/chess/) when `docs:dev` is running
|
|
328
386
|
- API metadata: `docs/openapi-like.json`
|
|
329
387
|
- Minimal demos:
|
|
330
388
|
- `examples/decentralized-tictactoe.js`
|