3. @fleetmesh/textile#
@fleetmesh/textile implements the Textile content-addressed data plane in TypeScript, providing byte-for-byte parity with fleetmesh_core.textile. It encompasses content-addressed data structures, Bao Merkle roots, deterministic merges, the privacy ladder, sealed shards, a local content-addressed vault, and NIP-77 vault reconciliation. It serves as the foundation for @fleetmesh/circles, @fleetmesh/dm, @fleetmesh/grasp, and @fleetmesh/arcade. Its host-side counterpart is Textile Host Stores (fleetmesh_protocols.textile).
3.1. Installation#
npm install @fleetmesh/textile@next @fleetmesh/leaf@next
Runtime dependencies consist of @fleetmesh/leaf (for shared codecs and negentropy) and exact-pinned versions of the audited @noble/* libraries.
3.2. Entry Points#
Import Path |
Exports |
|---|---|
|
Complete package surface: layer primitives, vault, codecs, and shared application helpers. |
|
Core layer classes, constants, and the leaf reconciliation bridge, excluding application helpers. |
|
Standalone SDK surface: primitives, Bao hashing, canonical CBOR and JSON codecs, signing, sealing, and storage backends. |
|
Frozen cross-language conformance test vectors. |
3.3. Data Plane Layers#
Layer |
Base Class |
Description |
|---|---|---|
Fiber |
|
Atomic content-addressed byte sequence. Subclasses include |
Strand |
|
Role-tagged fiber references ( |
Spool |
|
Append-only live buffer of timed fibers governed by a signed operation chain; cutting a spool compacts its window into strands and a fabric. Subclasses: |
Fabric |
|
Ordered or key-indexed collection of strands supporting deterministic merges (playlists, feeds, catalogs, and ledgers). |
Quilt |
|
Composite container of an identity’s or circle’s fabrics, identity fibers, and sealed shards, supporting per-audience projection ( |
Suit |
|
Self-contained |
Fit |
|
Content-addressed policy object defining storage quotas, pinning rules, tombstone boundaries, and sealed-shard leak prevention. |
Tombstone |
|
Cross-layer retraction and eviction record indexed by |
All layer classes inherit from AbstractTextilePrimitive (and composite containers from CompositeTextilePrimitive), exposing a uniform interface:
Manifest serialization:
toManifest()and staticfromManifest(). A primitive’srootis the Bao root of itscanonicalPayload().Subtree traversal: Containers expose
childRefs(),childRoots(), andverifySubtree(resolver).Deterministic merging:
merge(remote)on strands, fabrics, and quilts is commutative, associative, and idempotent; mergingAintoBandBintoAyields identical roots.BIP-340 signatures:
signWithKey(skHex),sign(signer), andverifySignature(envelope)provide BIP-340 signing and verification. Statements may also be carried as the content of a kind30899Nostr event signed by a NIP-07 browser extension (browserSigner).
3.4. Bao Roots#
A Textile root is computed as a SHA-256 Bao Merkle tree over 1,024-byte leaf chunks (using 0x00 leaf and 0x01 interior node domain separators, duplicating unpaired odd nodes, and organizing 8 MiB subtree segments), finalized with the payload length:
sha256(0x02 || u64be(length) || tree_root)
Including the length prefix disambiguates distinct inputs that would otherwise produce identical tree roots. computeBaoRootSync computes the length-wrapped root and computeBaoTreeRootSync computes the raw tree root. Normative parameters are defined in schema/constants.json under textile.bao.
3.5. Privacy Ladder#
Each primitive occupies a rung on the ordered privacy ladder: offline_only, private, private_group, public_group, public, and tombstoned. escalatePrivacyRung(next) advances the rung monotonically; attempting a downward transition returns false without modifying state (canEscalatePrivacyRung tests validity beforehand). Audience projection on a quilt omits all elements outside the target audience’s visibility rung.
3.6. Vault and Reconciliation#
FiberVaultRepository persists content-addressed blobs keyed by Bao root, verifying each payload’s root before insertion (put, get, putPrimitive, pin, unpin) and evicting unpinned entries when storage quotas are exceeded. Supported storage backends are MemoryStorageBackend and IndexedDbStorageBackend.
The leaf bridge converts primitive collections or vaults into negentropy sets (primitivesToNegentropySet, vaultToNegentropySet) and reconciles them via reconcileTextilePrimitiveSets over the NIP-77 implementation in @fleetmesh/leaf.
3.7. Conformance#
The test suite (npm test, Vitest in Node.js) validates every primitive against vectors/textile-v1.json, the same cross-language vector set verified by the Python reference implementation.