@degenerate/sharedata

v0.7.1

Published

This contains the ShareData Adaptive Framework Ecosystem (SAFE) network core code

Readme

Back to @degenerate documentation Back to @degenerate packages documentation

@degenerate/sharedata Package

The @degenerate/sharedata package is a core component of the SAFE system, responsible for ensuring that the share data objects are consistent and maintain integrity in the SAFE Network. This package provides a set of utilities and functions to manage and validate share data objects, ensuring that the system operates within the defined constraints and policies.

Contents

  1. Installation
  2. Persistence

Installation

To install the @degenerate/sharedata package, use the following command:

npm install @degenerate/sharedata

Persistence

ShareData state is durable — it survives a process restart. A ShareDataManager constructed with a ShareDataRepository hydrates its blocks on await manager.hydrate() and write-through-persists every addShareData / applyTransaction / removeShareDataById. Constructed with no repository it behaves exactly as before (in-memory only), so existing callers are untouched.

Loads are a trust gate, never a passthrough: each snapshot is replayed through deserializeShareData, which re-verifies the creation signature, the full structural-proof chain, and an integrity cross-check against the stored expected* values. A snapshot edited out-of-band fails loudly instead of loading silently. Reconstruction needs the block-type builders registered first — call registerShareBlockFactories() from @degenerate/shareblock during start-up.

Three interchangeable implementations of the ShareDataRepository interface ship here:

| Repository | Backing store | Typical use | |---|---|---| | FileShareDataRepository | one JSON file per block (atomic temp-file + rename writes) | single-node durability with no external service | | FirestoreShareDataRepository | one Firestore document per block | hosted/multi-node deployments | | InMemoryShareDataRepository | an in-process Map | tests and parity (still round-trips the trust gate) |

firebase-admin is an optional peer dependency — only install it if you use FirestoreShareDataRepository. The repository takes an injected firestore.Firestore instance (the host initializes its own app); the package never references firebase-admin at runtime.