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

@fleetmesh/textile

Complete package surface: layer primitives, vault, codecs, and shared application helpers.

@fleetmesh/textile/primitives

Core layer classes, constants, and the leaf reconciliation bridge, excluding application helpers.

@fleetmesh/textile/sdk

Standalone SDK surface: primitives, Bao hashing, canonical CBOR and JSON codecs, signing, sealing, and storage backends.

@fleetmesh/textile/vectors/*

Frozen cross-language conformance test vectors.

3.3. Data Plane Layers#

Layer

Base Class

Description

Fiber

TextileFiber

Atomic content-addressed byte sequence. Subclasses include MediaFiber, MetadataFiber, TimedFiber, IdentityFiber, SealedShardFiber (XChaCha20-Poly1305), and ChunkedFiber.

Strand

TextileStrand

Role-tagged fiber references (FiberRefCollection) composed into a versioned asset, with domain subclasses for media, subtitles, comments, code repositories, arcade releases, products, groups, and tombstone notices.

Spool

TextileSpool

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: ChannelSpool, LiveBroadcastSpool, DmSpool, SensorSpool, and LogSpool.

Fabric

TextileFabric

Ordered or key-indexed collection of strands supporting deterministic merges (playlists, feeds, catalogs, and ledgers).

Quilt

TextileQuilt

Composite container of an identity’s or circle’s fabrics, identity fibers, and sealed shards, supporting per-audience projection (SovereignIdentityQuilt and GroupCircleQuilt).

Suit

TextileSuit

Self-contained .fiberpack identity archive for offline portability across devices.

Fit

TextileFit

Content-addressed policy object defining storage quotas, pinning rules, tombstone boundaries, and sealed-shard leak prevention.

Tombstone

TextileTombstone

Cross-layer retraction and eviction record indexed by TombstoneLedgerRepository.

All layer classes inherit from AbstractTextilePrimitive (and composite containers from CompositeTextilePrimitive), exposing a uniform interface:

  • Manifest serialization: toManifest() and static fromManifest(). A primitive’s root is the Bao root of its canonicalPayload().

  • Subtree traversal: Containers expose childRefs(), childRoots(), and verifySubtree(resolver).

  • Deterministic merging: merge(remote) on strands, fabrics, and quilts is commutative, associative, and idempotent; merging A into B and B into A yields identical roots.

  • BIP-340 signatures: signWithKey(skHex), sign(signer), and verifySignature(envelope) provide BIP-340 signing and verification. Statements may also be carried as the content of a kind 30899 Nostr 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.