@optimystic/db-p2p 0.13.5 → 0.14.1
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 +6 -6
- package/dist/src/cluster/block-transfer-service.d.ts +67 -8
- package/dist/src/cluster/block-transfer-service.d.ts.map +1 -1
- package/dist/src/cluster/block-transfer-service.js +101 -62
- package/dist/src/cluster/block-transfer-service.js.map +1 -1
- package/dist/src/cluster/client.d.ts +18 -1
- package/dist/src/cluster/client.d.ts.map +1 -1
- package/dist/src/cluster/client.js +55 -39
- package/dist/src/cluster/client.js.map +1 -1
- package/dist/src/cluster/cluster-error.d.ts +38 -0
- package/dist/src/cluster/cluster-error.d.ts.map +1 -0
- package/dist/src/cluster/cluster-error.js +51 -0
- package/dist/src/cluster/cluster-error.js.map +1 -0
- package/dist/src/cluster/cluster-repo.d.ts +135 -3
- package/dist/src/cluster/cluster-repo.d.ts.map +1 -1
- package/dist/src/cluster/cluster-repo.js +333 -58
- package/dist/src/cluster/cluster-repo.js.map +1 -1
- package/dist/src/cluster/commit-cert.d.ts +63 -0
- package/dist/src/cluster/commit-cert.d.ts.map +1 -0
- package/dist/src/cluster/commit-cert.js +108 -0
- package/dist/src/cluster/commit-cert.js.map +1 -0
- package/dist/src/cluster/service.d.ts +46 -11
- package/dist/src/cluster/service.d.ts.map +1 -1
- package/dist/src/cluster/service.js +97 -33
- package/dist/src/cluster/service.js.map +1 -1
- package/dist/src/cluster/spread-on-churn.d.ts +13 -0
- package/dist/src/cluster/spread-on-churn.d.ts.map +1 -1
- package/dist/src/cluster/spread-on-churn.js +34 -4
- package/dist/src/cluster/spread-on-churn.js.map +1 -1
- package/dist/src/cohort-topic/bootstrap-evidence-builder.d.ts +59 -0
- package/dist/src/cohort-topic/bootstrap-evidence-builder.d.ts.map +1 -0
- package/dist/src/cohort-topic/bootstrap-evidence-builder.js +79 -0
- package/dist/src/cohort-topic/bootstrap-evidence-builder.js.map +1 -0
- package/dist/src/cohort-topic/bootstrap-evidence-verifiers.d.ts +81 -0
- package/dist/src/cohort-topic/bootstrap-evidence-verifiers.d.ts.map +1 -0
- package/dist/src/cohort-topic/bootstrap-evidence-verifiers.js +93 -0
- package/dist/src/cohort-topic/bootstrap-evidence-verifiers.js.map +1 -0
- package/dist/src/cohort-topic/bootstrap-parent-reference.d.ts +108 -0
- package/dist/src/cohort-topic/bootstrap-parent-reference.d.ts.map +1 -0
- package/dist/src/cohort-topic/bootstrap-parent-reference.js +108 -0
- package/dist/src/cohort-topic/bootstrap-parent-reference.js.map +1 -0
- package/dist/src/cohort-topic/change-bridge.d.ts +65 -0
- package/dist/src/cohort-topic/change-bridge.d.ts.map +1 -0
- package/dist/src/cohort-topic/change-bridge.js +76 -0
- package/dist/src/cohort-topic/change-bridge.js.map +1 -0
- package/dist/src/cohort-topic/cohort-gossip-driver.d.ts +74 -0
- package/dist/src/cohort-topic/cohort-gossip-driver.d.ts.map +1 -0
- package/dist/src/cohort-topic/cohort-gossip-driver.js +87 -0
- package/dist/src/cohort-topic/cohort-gossip-driver.js.map +1 -0
- package/dist/src/cohort-topic/cohort-gossip-transport.d.ts +42 -0
- package/dist/src/cohort-topic/cohort-gossip-transport.d.ts.map +1 -0
- package/dist/src/cohort-topic/cohort-gossip-transport.js +57 -0
- package/dist/src/cohort-topic/cohort-gossip-transport.js.map +1 -0
- package/dist/src/cohort-topic/fret-trust-anchor.d.ts +100 -0
- package/dist/src/cohort-topic/fret-trust-anchor.d.ts.map +1 -0
- package/dist/src/cohort-topic/fret-trust-anchor.js +115 -0
- package/dist/src/cohort-topic/fret-trust-anchor.js.map +1 -0
- package/dist/src/cohort-topic/host.d.ts +573 -0
- package/dist/src/cohort-topic/host.d.ts.map +1 -0
- package/dist/src/cohort-topic/host.js +1460 -0
- package/dist/src/cohort-topic/host.js.map +1 -0
- package/dist/src/cohort-topic/index.d.ts +14 -0
- package/dist/src/cohort-topic/index.d.ts.map +1 -0
- package/dist/src/cohort-topic/index.js +14 -0
- package/dist/src/cohort-topic/index.js.map +1 -0
- package/dist/src/cohort-topic/membership-publish-sink.d.ts +14 -0
- package/dist/src/cohort-topic/membership-publish-sink.d.ts.map +1 -0
- package/dist/src/cohort-topic/membership-publish-sink.js +17 -0
- package/dist/src/cohort-topic/membership-publish-sink.js.map +1 -0
- package/dist/src/cohort-topic/membership-source.d.ts +36 -0
- package/dist/src/cohort-topic/membership-source.d.ts.map +1 -0
- package/dist/src/cohort-topic/membership-source.js +58 -0
- package/dist/src/cohort-topic/membership-source.js.map +1 -0
- package/dist/src/cohort-topic/peer-codec.d.ts +18 -0
- package/dist/src/cohort-topic/peer-codec.d.ts.map +1 -0
- package/dist/src/cohort-topic/peer-codec.js +26 -0
- package/dist/src/cohort-topic/peer-codec.js.map +1 -0
- package/dist/src/cohort-topic/peer-sig.d.ts +52 -0
- package/dist/src/cohort-topic/peer-sig.d.ts.map +1 -0
- package/dist/src/cohort-topic/peer-sig.js +83 -0
- package/dist/src/cohort-topic/peer-sig.js.map +1 -0
- package/dist/src/cohort-topic/protocols.d.ts +49 -0
- package/dist/src/cohort-topic/protocols.d.ts.map +1 -0
- package/dist/src/cohort-topic/protocols.js +58 -0
- package/dist/src/cohort-topic/protocols.js.map +1 -0
- package/dist/src/cohort-topic/reactivity-membership-gate.d.ts +49 -0
- package/dist/src/cohort-topic/reactivity-membership-gate.d.ts.map +1 -0
- package/dist/src/cohort-topic/reactivity-membership-gate.js +42 -0
- package/dist/src/cohort-topic/reactivity-membership-gate.js.map +1 -0
- package/dist/src/cohort-topic/size-estimator.d.ts +16 -0
- package/dist/src/cohort-topic/size-estimator.d.ts.map +1 -0
- package/dist/src/cohort-topic/size-estimator.js +16 -0
- package/dist/src/cohort-topic/size-estimator.js.map +1 -0
- package/dist/src/cohort-topic/stream-util.d.ts +19 -0
- package/dist/src/cohort-topic/stream-util.d.ts.map +1 -0
- package/dist/src/cohort-topic/stream-util.js +76 -0
- package/dist/src/cohort-topic/stream-util.js.map +1 -0
- package/dist/src/cohort-topic/threshold-crypto.d.ts +94 -0
- package/dist/src/cohort-topic/threshold-crypto.d.ts.map +1 -0
- package/dist/src/cohort-topic/threshold-crypto.js +178 -0
- package/dist/src/cohort-topic/threshold-crypto.js.map +1 -0
- package/dist/src/cohort-topic/topic-router.d.ts +41 -0
- package/dist/src/cohort-topic/topic-router.d.ts.map +1 -0
- package/dist/src/cohort-topic/topic-router.js +63 -0
- package/dist/src/cohort-topic/topic-router.js.map +1 -0
- package/dist/src/dispute/cascade.d.ts +179 -0
- package/dist/src/dispute/cascade.d.ts.map +1 -0
- package/dist/src/dispute/cascade.js +315 -0
- package/dist/src/dispute/cascade.js.map +1 -0
- package/dist/src/dispute/client.d.ts +2 -1
- package/dist/src/dispute/client.d.ts.map +1 -1
- package/dist/src/dispute/client.js +12 -3
- package/dist/src/dispute/client.js.map +1 -1
- package/dist/src/dispute/dispute-service.d.ts +41 -1
- package/dist/src/dispute/dispute-service.d.ts.map +1 -1
- package/dist/src/dispute/dispute-service.js +147 -21
- package/dist/src/dispute/dispute-service.js.map +1 -1
- package/dist/src/dispute/index.d.ts +2 -0
- package/dist/src/dispute/index.d.ts.map +1 -1
- package/dist/src/dispute/index.js +2 -0
- package/dist/src/dispute/index.js.map +1 -1
- package/dist/src/dispute/invalidation.d.ts +266 -0
- package/dist/src/dispute/invalidation.d.ts.map +1 -0
- package/dist/src/dispute/invalidation.js +405 -0
- package/dist/src/dispute/invalidation.js.map +1 -0
- package/dist/src/dispute/types.d.ts +14 -0
- package/dist/src/dispute/types.d.ts.map +1 -1
- package/dist/src/dispute/types.js.map +1 -1
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/libp2p-key-network.d.ts +7 -0
- package/dist/src/libp2p-key-network.d.ts.map +1 -1
- package/dist/src/libp2p-key-network.js +49 -5
- package/dist/src/libp2p-key-network.js.map +1 -1
- package/dist/src/libp2p-node-base.d.ts +45 -3
- package/dist/src/libp2p-node-base.d.ts.map +1 -1
- package/dist/src/libp2p-node-base.js +522 -5
- package/dist/src/libp2p-node-base.js.map +1 -1
- package/dist/src/matchmaking/aggregate-counts.d.ts +67 -0
- package/dist/src/matchmaking/aggregate-counts.d.ts.map +1 -0
- package/dist/src/matchmaking/aggregate-counts.js +60 -0
- package/dist/src/matchmaking/aggregate-counts.js.map +1 -0
- package/dist/src/matchmaking/index.d.ts +20 -0
- package/dist/src/matchmaking/index.d.ts.map +1 -0
- package/dist/src/matchmaking/index.js +20 -0
- package/dist/src/matchmaking/index.js.map +1 -0
- package/dist/src/matchmaking/module.d.ts +181 -0
- package/dist/src/matchmaking/module.d.ts.map +1 -0
- package/dist/src/matchmaking/module.js +221 -0
- package/dist/src/matchmaking/module.js.map +1 -0
- package/dist/src/matchmaking/protocols.d.ts +37 -0
- package/dist/src/matchmaking/protocols.d.ts.map +1 -0
- package/dist/src/matchmaking/protocols.js +42 -0
- package/dist/src/matchmaking/protocols.js.map +1 -0
- package/dist/src/matchmaking/provider-manager.d.ts +52 -0
- package/dist/src/matchmaking/provider-manager.d.ts.map +1 -0
- package/dist/src/matchmaking/provider-manager.js +74 -0
- package/dist/src/matchmaking/provider-manager.js.map +1 -0
- package/dist/src/matchmaking/query-handler.d.ts +34 -0
- package/dist/src/matchmaking/query-handler.d.ts.map +1 -0
- package/dist/src/matchmaking/query-handler.js +62 -0
- package/dist/src/matchmaking/query-handler.js.map +1 -0
- package/dist/src/matchmaking/query-transport.d.ts +180 -0
- package/dist/src/matchmaking/query-transport.d.ts.map +1 -0
- package/dist/src/matchmaking/query-transport.js +315 -0
- package/dist/src/matchmaking/query-transport.js.map +1 -0
- package/dist/src/matchmaking/seeker-manager.d.ts +39 -0
- package/dist/src/matchmaking/seeker-manager.d.ts.map +1 -0
- package/dist/src/matchmaking/seeker-manager.js +49 -0
- package/dist/src/matchmaking/seeker-manager.js.map +1 -0
- package/dist/src/matchmaking/seeker-walk-client.d.ts +127 -0
- package/dist/src/matchmaking/seeker-walk-client.d.ts.map +1 -0
- package/dist/src/matchmaking/seeker-walk-client.js +189 -0
- package/dist/src/matchmaking/seeker-walk-client.js.map +1 -0
- package/dist/src/matchmaking/traffic-validation.d.ts +128 -0
- package/dist/src/matchmaking/traffic-validation.d.ts.map +1 -0
- package/dist/src/matchmaking/traffic-validation.js +105 -0
- package/dist/src/matchmaking/traffic-validation.js.map +1 -0
- package/dist/src/network/network-manager-service.d.ts +4 -2
- package/dist/src/network/network-manager-service.d.ts.map +1 -1
- package/dist/src/network/network-manager-service.js +9 -3
- package/dist/src/network/network-manager-service.js.map +1 -1
- package/dist/src/protocol-client.d.ts +13 -0
- package/dist/src/protocol-client.d.ts.map +1 -1
- package/dist/src/protocol-client.js +74 -2
- package/dist/src/protocol-client.js.map +1 -1
- package/dist/src/reactivity/forwarder-host.d.ts +198 -0
- package/dist/src/reactivity/forwarder-host.d.ts.map +1 -0
- package/dist/src/reactivity/forwarder-host.js +355 -0
- package/dist/src/reactivity/forwarder-host.js.map +1 -0
- package/dist/src/reactivity/index.d.ts +19 -0
- package/dist/src/reactivity/index.d.ts.map +1 -0
- package/dist/src/reactivity/index.js +19 -0
- package/dist/src/reactivity/index.js.map +1 -0
- package/dist/src/reactivity/notify-transport.d.ts +70 -0
- package/dist/src/reactivity/notify-transport.d.ts.map +1 -0
- package/dist/src/reactivity/notify-transport.js +111 -0
- package/dist/src/reactivity/notify-transport.js.map +1 -0
- package/dist/src/reactivity/origination-manager.d.ts +110 -0
- package/dist/src/reactivity/origination-manager.d.ts.map +1 -0
- package/dist/src/reactivity/origination-manager.js +129 -0
- package/dist/src/reactivity/origination-manager.js.map +1 -0
- package/dist/src/reactivity/protocols.d.ts +43 -0
- package/dist/src/reactivity/protocols.d.ts.map +1 -0
- package/dist/src/reactivity/protocols.js +50 -0
- package/dist/src/reactivity/protocols.js.map +1 -0
- package/dist/src/reactivity/push-state-gossip.d.ts +132 -0
- package/dist/src/reactivity/push-state-gossip.d.ts.map +1 -0
- package/dist/src/reactivity/push-state-gossip.js +231 -0
- package/dist/src/reactivity/push-state-gossip.js.map +1 -0
- package/dist/src/reactivity/recover-transport.d.ts +167 -0
- package/dist/src/reactivity/recover-transport.d.ts.map +1 -0
- package/dist/src/reactivity/recover-transport.js +308 -0
- package/dist/src/reactivity/recover-transport.js.map +1 -0
- package/dist/src/reactivity/rotation-rereg-scheduler.d.ts +142 -0
- package/dist/src/reactivity/rotation-rereg-scheduler.d.ts.map +1 -0
- package/dist/src/reactivity/rotation-rereg-scheduler.js +223 -0
- package/dist/src/reactivity/rotation-rereg-scheduler.js.map +1 -0
- package/dist/src/reactivity/subscriber-registry.d.ts +47 -0
- package/dist/src/reactivity/subscriber-registry.d.ts.map +1 -0
- package/dist/src/reactivity/subscriber-registry.js +87 -0
- package/dist/src/reactivity/subscriber-registry.js.map +1 -0
- package/dist/src/reactivity/subscription-manager.d.ts +221 -0
- package/dist/src/reactivity/subscription-manager.d.ts.map +1 -0
- package/dist/src/reactivity/subscription-manager.js +302 -0
- package/dist/src/reactivity/subscription-manager.js.map +1 -0
- package/dist/src/reactivity/topic-bytes.d.ts +32 -0
- package/dist/src/reactivity/topic-bytes.d.ts.map +1 -0
- package/dist/src/reactivity/topic-bytes.js +34 -0
- package/dist/src/reactivity/topic-bytes.js.map +1 -0
- package/dist/src/repo/client.d.ts.map +1 -1
- package/dist/src/repo/client.js +51 -23
- package/dist/src/repo/client.js.map +1 -1
- package/dist/src/repo/service.d.ts +46 -1
- package/dist/src/repo/service.d.ts.map +1 -1
- package/dist/src/repo/service.js +79 -45
- package/dist/src/repo/service.js.map +1 -1
- package/dist/src/rpc-deadline.d.ts +37 -0
- package/dist/src/rpc-deadline.d.ts.map +1 -0
- package/dist/src/rpc-deadline.js +31 -0
- package/dist/src/rpc-deadline.js.map +1 -0
- package/dist/src/storage/block-storage.d.ts +2 -0
- package/dist/src/storage/block-storage.d.ts.map +1 -1
- package/dist/src/storage/block-storage.js +95 -2
- package/dist/src/storage/block-storage.js.map +1 -1
- package/dist/src/storage/i-block-storage.d.ts +25 -0
- package/dist/src/storage/i-block-storage.d.ts.map +1 -1
- package/dist/src/storage/storage-repo.d.ts +53 -2
- package/dist/src/storage/storage-repo.d.ts.map +1 -1
- package/dist/src/storage/storage-repo.js +193 -9
- package/dist/src/storage/storage-repo.js.map +1 -1
- package/dist/src/sync/client.d.ts +4 -1
- package/dist/src/sync/client.d.ts.map +1 -1
- package/dist/src/sync/client.js +5 -2
- package/dist/src/sync/client.js.map +1 -1
- package/dist/src/testing/cohort-topic-mesh-harness.d.ts +219 -0
- package/dist/src/testing/cohort-topic-mesh-harness.d.ts.map +1 -0
- package/dist/src/testing/cohort-topic-mesh-harness.js +467 -0
- package/dist/src/testing/cohort-topic-mesh-harness.js.map +1 -0
- package/dist/src/testing/matchmaking-mesh-harness.d.ts +187 -0
- package/dist/src/testing/matchmaking-mesh-harness.d.ts.map +1 -0
- package/dist/src/testing/matchmaking-mesh-harness.js +358 -0
- package/dist/src/testing/matchmaking-mesh-harness.js.map +1 -0
- package/dist/src/testing/mesh-harness.d.ts.map +1 -1
- package/dist/src/testing/mesh-harness.js +23 -1
- package/dist/src/testing/mesh-harness.js.map +1 -1
- package/dist/src/testing/reactivity-mesh-harness.d.ts +298 -0
- package/dist/src/testing/reactivity-mesh-harness.d.ts.map +1 -0
- package/dist/src/testing/reactivity-mesh-harness.js +663 -0
- package/dist/src/testing/reactivity-mesh-harness.js.map +1 -0
- package/package.json +7 -4
- package/src/cluster/block-transfer-service.ts +133 -68
- package/src/cluster/client.ts +64 -45
- package/src/cluster/cluster-error.ts +64 -0
- package/src/cluster/cluster-repo.ts +405 -55
- package/src/cluster/commit-cert.ts +139 -0
- package/src/cluster/service.ts +116 -44
- package/src/cluster/spread-on-churn.ts +328 -285
- package/src/cohort-topic/bootstrap-evidence-builder.ts +122 -0
- package/src/cohort-topic/bootstrap-evidence-verifiers.ts +132 -0
- package/src/cohort-topic/bootstrap-parent-reference.ts +159 -0
- package/src/cohort-topic/change-bridge.ts +109 -0
- package/src/cohort-topic/cohort-gossip-driver.ts +144 -0
- package/src/cohort-topic/cohort-gossip-transport.ts +74 -0
- package/src/cohort-topic/fret-trust-anchor.ts +153 -0
- package/src/cohort-topic/host.ts +2175 -0
- package/src/cohort-topic/index.ts +13 -0
- package/src/cohort-topic/membership-publish-sink.ts +20 -0
- package/src/cohort-topic/membership-source.ts +68 -0
- package/src/cohort-topic/peer-codec.ts +31 -0
- package/src/cohort-topic/peer-sig.ts +86 -0
- package/src/cohort-topic/protocols.ts +71 -0
- package/src/cohort-topic/reactivity-membership-gate.ts +77 -0
- package/src/cohort-topic/size-estimator.ts +16 -0
- package/src/cohort-topic/stream-util.ts +87 -0
- package/src/cohort-topic/threshold-crypto.ts +239 -0
- package/src/cohort-topic/topic-router.ts +77 -0
- package/src/dispute/cascade.ts +517 -0
- package/src/dispute/client.ts +12 -2
- package/src/dispute/dispute-service.ts +171 -24
- package/src/dispute/index.ts +42 -0
- package/src/dispute/invalidation.ts +587 -0
- package/src/dispute/types.ts +14 -0
- package/src/index.ts +4 -0
- package/src/libp2p-key-network.ts +49 -6
- package/src/libp2p-node-base.ts +620 -12
- package/src/matchmaking/aggregate-counts.ts +104 -0
- package/src/matchmaking/index.ts +20 -0
- package/src/matchmaking/module.ts +363 -0
- package/src/matchmaking/protocols.ts +51 -0
- package/src/matchmaking/provider-manager.ts +95 -0
- package/src/matchmaking/query-handler.ts +88 -0
- package/src/matchmaking/query-transport.ts +483 -0
- package/src/matchmaking/seeker-manager.ts +64 -0
- package/src/matchmaking/seeker-walk-client.ts +293 -0
- package/src/matchmaking/traffic-validation.ts +195 -0
- package/src/network/network-manager-service.ts +9 -2
- package/src/protocol-client.ts +64 -3
- package/src/reactivity/forwarder-host.ts +438 -0
- package/src/reactivity/index.ts +19 -0
- package/src/reactivity/notify-transport.ts +144 -0
- package/src/reactivity/origination-manager.ts +192 -0
- package/src/reactivity/protocols.ts +61 -0
- package/src/reactivity/push-state-gossip.ts +291 -0
- package/src/reactivity/recover-transport.ts +408 -0
- package/src/reactivity/rotation-rereg-scheduler.ts +256 -0
- package/src/reactivity/subscriber-registry.ts +96 -0
- package/src/reactivity/subscription-manager.ts +450 -0
- package/src/reactivity/topic-bytes.ts +37 -0
- package/src/repo/client.ts +54 -23
- package/src/repo/service.ts +90 -42
- package/src/rpc-deadline.ts +45 -0
- package/src/storage/block-storage.ts +106 -3
- package/src/storage/i-block-storage.ts +27 -0
- package/src/storage/storage-repo.ts +209 -13
- package/src/sync/client.ts +5 -2
- package/src/testing/cohort-topic-mesh-harness.ts +613 -0
- package/src/testing/matchmaking-mesh-harness.ts +475 -0
- package/src/testing/mesh-harness.ts +22 -2
- package/src/testing/reactivity-mesh-harness.ts +922 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cohort-topic `k − x` threshold-signature crypto — real collected Ed25519 multi-signature.
|
|
3
|
+
*
|
|
4
|
+
* Closes gap 1 (the interim single-signer `sha256(payload)` digest, which could never satisfy
|
|
5
|
+
* `CohortSigner.verifyThreshold`'s `≥ minSigs` distinct-member rule at `minSigs = 14`). The scheme is
|
|
6
|
+
* a **collected multisig**: `thresholdSig` is the aligned concatenation of fixed-width 64-byte Ed25519
|
|
7
|
+
* signatures, one per `signers[i]`, each produced by that member's libp2p peer key over the *exact*
|
|
8
|
+
* canonical payload. It needs **no trusted setup, no new crypto dependency, and no aggregation round**
|
|
9
|
+
* (unlike BLS or FROST), maps directly onto the existing `(thresholdSig, signers)` contract, and reuses
|
|
10
|
+
* the per-member peer-key signing primitive (`peer-sig.ts`) the codebase already uses for cluster-repo
|
|
11
|
+
* commit signatures. Size is O(k) (≤ ~14 × 64 = 896 bytes at production `minSigs`) — negligible for
|
|
12
|
+
* k ≤ 16; if size ever matters at larger k the scheme can be swapped behind the unchanged
|
|
13
|
+
* {@link ICohortThresholdCrypto} port.
|
|
14
|
+
*
|
|
15
|
+
* **Coord-scoped.** `assemble(payload, minSigs)` carries no coord, so the adapter is constructed per
|
|
16
|
+
* served coord (one per {@link import("./host.js").CoordEngine}): it knows the cohort around its coord,
|
|
17
|
+
* the node's peer key (to add self's own signature without an RPC), and a `dialSign` seam over the
|
|
18
|
+
* `/sign` protocol to collect the other members' endorsements.
|
|
19
|
+
*
|
|
20
|
+
* **Verify is synchronous** — `ICohortThresholdCrypto.verify` is called from the sync
|
|
21
|
+
* `CohortSigner.verifyThreshold` on the participant path. {@link verifyCollectedMultisig} splits the
|
|
22
|
+
* blob into `signers.length` 64-byte chunks and {@link verifyPeerSig}-checks each against the
|
|
23
|
+
* corresponding signer's embedded Ed25519 key (noble, sync). Do not make it async.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import type { PrivateKey } from "@libp2p/interface";
|
|
27
|
+
import type { ICohortThresholdCrypto, RingCoord, SignKind, SignReplyV1, SignRequestV1 } from "@optimystic/db-core";
|
|
28
|
+
import { bytesToB64url, b64urlToBytes, compareBytes } from "@optimystic/db-core";
|
|
29
|
+
import { signPeer, verifyPeerSig } from "./peer-sig.js";
|
|
30
|
+
import { bytesToPeerIdString } from "./peer-codec.js";
|
|
31
|
+
|
|
32
|
+
/** Width of an Ed25519 signature in bytes — the fixed stride of the concatenated `thresholdSig`. */
|
|
33
|
+
export const ED25519_SIG_BYTES = 64;
|
|
34
|
+
|
|
35
|
+
/** Default per-round deadline for collecting cohort endorsements (ms). */
|
|
36
|
+
export const DEFAULT_SIGN_COLLECT_TIMEOUT_MS = 5_000;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Verify a collected Ed25519 multi-signature: `thresholdSig` must be exactly `signers.length × 64`
|
|
40
|
+
* bytes, and chunk `i` must be a valid peer-key signature by `signers[i]` over `payload`. Pure and
|
|
41
|
+
* synchronous; total (returns `false`, never throws). The db-core `CohortSigner.verifyThreshold` layer
|
|
42
|
+
* adds the distinct-signer / `signers ⊆ cert.members` / `≥ minSigs` checks on top of this.
|
|
43
|
+
*/
|
|
44
|
+
export function verifyCollectedMultisig(payload: Uint8Array, thresholdSig: Uint8Array, signers: readonly Uint8Array[]): boolean {
|
|
45
|
+
if (signers.length === 0) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (thresholdSig.length !== signers.length * ED25519_SIG_BYTES) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
for (let i = 0; i < signers.length; i++) {
|
|
52
|
+
const chunk = thresholdSig.subarray(i * ED25519_SIG_BYTES, (i + 1) * ED25519_SIG_BYTES);
|
|
53
|
+
if (!verifyPeerSig(signers[i]!, payload, chunk)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Dependencies for a coord-scoped {@link FretCohortThresholdCrypto}. The host supplies these per
|
|
62
|
+
* {@link import("./host.js").CoordEngine}; the `kind` selects the endorsement policy the dialed
|
|
63
|
+
* members apply (membership cert vs promotion / demotion notice).
|
|
64
|
+
*/
|
|
65
|
+
export interface CohortThresholdCryptoDeps {
|
|
66
|
+
/** What this signer assembles — sent in each {@link SignRequestV1} so members apply the right policy. */
|
|
67
|
+
readonly kind: SignKind;
|
|
68
|
+
/** The node's libp2p Ed25519 private key — signs self's own chunk locally (no RPC to self). */
|
|
69
|
+
readonly privateKey: PrivateKey;
|
|
70
|
+
/** Self's dialable member id (UTF-8 of the peer-id string); self is always a signer. */
|
|
71
|
+
readonly selfMember: Uint8Array;
|
|
72
|
+
/** The served coord whose cohort threshold-signs. */
|
|
73
|
+
readonly coord: () => RingCoord;
|
|
74
|
+
/** Current cohort epoch (raw bytes) for {@link coord}. */
|
|
75
|
+
readonly cohortEpoch: () => Uint8Array;
|
|
76
|
+
/** Current cohort member peer-id strings around {@link coord} (self may be included; excluded internally). */
|
|
77
|
+
readonly cohortMembers: () => string[];
|
|
78
|
+
/** Dial one cohort member's `/sign` RPC and return its reply. */
|
|
79
|
+
readonly dialSign: (peerIdStr: string, request: SignRequestV1) => Promise<SignReplyV1>;
|
|
80
|
+
/** Per-round collection deadline (ms). Default {@link DEFAULT_SIGN_COLLECT_TIMEOUT_MS}. */
|
|
81
|
+
readonly collectTimeoutMs?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Whether self may contribute its own signature to this assembly. Default `true` (self is always a
|
|
84
|
+
* member of the cohort it signs over). The **rotation** producer scopes the assembly to the
|
|
85
|
+
* *predecessor* cohort (`cohortMembers` = the prior epoch's members); when self was not a member of
|
|
86
|
+
* that prior cohort it must NOT self-sign — its chunk would be dropped by the verifier (a signer not in
|
|
87
|
+
* the predecessor cert's `members`), desyncing the count from what the verifier accepts. Returning
|
|
88
|
+
* `false` then makes the quorum genuinely the outgoing cohort. See `cohort-topic-trust-anchor-rotation-production`.
|
|
89
|
+
*/
|
|
90
|
+
readonly selfEligible?: () => boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** A collected, verified per-member signature awaiting concatenation. */
|
|
94
|
+
interface CollectedSig {
|
|
95
|
+
readonly signer: Uint8Array;
|
|
96
|
+
readonly sig: Uint8Array;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Real coord-scoped {@link ICohortThresholdCrypto}. `assemble` signs locally, concurrently dials the
|
|
101
|
+
* rest of the cohort over the `/sign` protocol, verifies each returned signature before counting it,
|
|
102
|
+
* and concatenates `≥ minSigs` distinct signatures into the threshold blob — or throws if a quorum is
|
|
103
|
+
* unreachable (it must **never** fabricate a single-signer sig, the interim bug). `verify` is the pure
|
|
104
|
+
* split-and-check.
|
|
105
|
+
*/
|
|
106
|
+
export class FretCohortThresholdCrypto implements ICohortThresholdCrypto {
|
|
107
|
+
constructor(private readonly deps: CohortThresholdCryptoDeps) {}
|
|
108
|
+
|
|
109
|
+
async assemble(payload: Uint8Array, minSigs: number): Promise<{ thresholdSig: Uint8Array; signers: Uint8Array[] }> {
|
|
110
|
+
const collected = new Map<string, CollectedSig>();
|
|
111
|
+
const selfStr = bytesToPeerIdString(this.deps.selfMember);
|
|
112
|
+
|
|
113
|
+
// Self is normally a signer — it is the acting member, even if a stale table omits it from its own
|
|
114
|
+
// assembly. Sign locally (no RPC to self). A rotation producer that was NOT in the predecessor cohort
|
|
115
|
+
// (`selfEligible` → false) skips this: its chunk would be dropped by the verifier (signer ∉ predecessor
|
|
116
|
+
// cert members), so it must collect a quorum purely from the outgoing cohort instead.
|
|
117
|
+
if (this.deps.selfEligible?.() ?? true) {
|
|
118
|
+
const selfSig = await signPeer(this.deps.privateKey, payload);
|
|
119
|
+
if (selfSig.length !== ED25519_SIG_BYTES) {
|
|
120
|
+
throw new Error(`cohort threshold sign: self produced a ${selfSig.length}-byte signature (expected ${ED25519_SIG_BYTES}); non-Ed25519 identity?`);
|
|
121
|
+
}
|
|
122
|
+
collected.set(bytesToB64url(this.deps.selfMember), { signer: this.deps.selfMember, sig: selfSig });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Concurrently collect endorsements from the rest of the cohort, up to the deadline.
|
|
126
|
+
const others = this.deps.cohortMembers().filter((m) => m !== selfStr);
|
|
127
|
+
if (others.length > 0 && collected.size < minSigs) {
|
|
128
|
+
const request: SignRequestV1 = {
|
|
129
|
+
v: 1,
|
|
130
|
+
kind: this.deps.kind,
|
|
131
|
+
coord: bytesToB64url(this.deps.coord()),
|
|
132
|
+
cohortEpoch: bytesToB64url(this.deps.cohortEpoch()),
|
|
133
|
+
payload: bytesToB64url(payload),
|
|
134
|
+
};
|
|
135
|
+
const timeoutMs = this.deps.collectTimeoutMs ?? DEFAULT_SIGN_COLLECT_TIMEOUT_MS;
|
|
136
|
+
await Promise.all(others.map((peerStr) => this.collectFrom(peerStr, request, payload, collected, timeoutMs)));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (collected.size < minSigs) {
|
|
140
|
+
// Quorum unreachable / unwilling: no notice this round. The promotion / cert path re-fires next
|
|
141
|
+
// tick. NEVER fabricate a single-signer sig — that is exactly the interim bug this replaces.
|
|
142
|
+
throw new Error(`cohort threshold sign: gathered ${collected.size} of ${minSigs} required signatures`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Deterministic order (ascending by signer id) so the concatenation is reproducible and aligns
|
|
146
|
+
// signers[i] ↔ chunk i for the verifier.
|
|
147
|
+
const ordered = [...collected.values()].sort((a, b) => compareBytes(a.signer, b.signer));
|
|
148
|
+
const signers = ordered.map((e) => e.signer);
|
|
149
|
+
const thresholdSig = concatSigs(ordered.map((e) => e.sig));
|
|
150
|
+
return { thresholdSig, signers };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
verify(payload: Uint8Array, thresholdSig: Uint8Array, signers: readonly Uint8Array[]): boolean {
|
|
154
|
+
return verifyCollectedMultisig(payload, thresholdSig, signers);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Dial one member, verify-before-count its endorsement, and add it to `collected` (dropping bad/dupe). */
|
|
158
|
+
private async collectFrom(
|
|
159
|
+
peerStr: string,
|
|
160
|
+
request: SignRequestV1,
|
|
161
|
+
payload: Uint8Array,
|
|
162
|
+
collected: Map<string, CollectedSig>,
|
|
163
|
+
timeoutMs: number,
|
|
164
|
+
): Promise<void> {
|
|
165
|
+
try {
|
|
166
|
+
const reply = await withTimeout(this.deps.dialSign(peerStr, request), timeoutMs);
|
|
167
|
+
if (reply === undefined || "refused" in reply) {
|
|
168
|
+
return; // unreachable (timed out) or the member declined to endorse
|
|
169
|
+
}
|
|
170
|
+
const signerBytes = b64urlToBytes(reply.signer);
|
|
171
|
+
const sigBytes = b64urlToBytes(reply.signature);
|
|
172
|
+
if (sigBytes.length !== ED25519_SIG_BYTES) {
|
|
173
|
+
return; // a malformed chunk would desync the fixed-stride concatenation
|
|
174
|
+
}
|
|
175
|
+
// Verify before counting: a member must not be able to poison the blob with a bad signature.
|
|
176
|
+
if (!verifyPeerSig(signerBytes, payload, sigBytes)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const key = bytesToB64url(signerBytes);
|
|
180
|
+
if (collected.has(key)) {
|
|
181
|
+
return; // a duplicate signer cannot pad the count toward minSigs
|
|
182
|
+
}
|
|
183
|
+
collected.set(key, { signer: signerBytes, sig: sigBytes });
|
|
184
|
+
} catch {
|
|
185
|
+
// Unreachable member or malformed reply — drop it; collection continues with the rest.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A verify-only {@link ICohortThresholdCrypto} for the participant-side verifier, which never assembles
|
|
192
|
+
* (it only checks inbound threshold-signed messages). `assemble` rejects so a misuse surfaces loudly
|
|
193
|
+
* rather than fabricating a signature.
|
|
194
|
+
*/
|
|
195
|
+
export function createVerifyOnlyThresholdCrypto(): ICohortThresholdCrypto {
|
|
196
|
+
return {
|
|
197
|
+
assemble: (): Promise<{ thresholdSig: Uint8Array; signers: Uint8Array[] }> =>
|
|
198
|
+
Promise.reject(new Error("verify-only cohort threshold crypto cannot assemble signatures")),
|
|
199
|
+
verify: verifyCollectedMultisig,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Concatenate equal-width signature chunks into one fixed-stride blob aligned with the signer order. */
|
|
204
|
+
function concatSigs(sigs: readonly Uint8Array[]): Uint8Array {
|
|
205
|
+
const out = new Uint8Array(sigs.length * ED25519_SIG_BYTES);
|
|
206
|
+
for (let i = 0; i < sigs.length; i++) {
|
|
207
|
+
out.set(sigs[i]!, i * ED25519_SIG_BYTES);
|
|
208
|
+
}
|
|
209
|
+
return out;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Resolve `p`, or `undefined` if `timeoutMs` elapses first (bounds wall-clock against an unreachable peer). */
|
|
213
|
+
function withTimeout<T>(p: Promise<T>, timeoutMs: number): Promise<T | undefined> {
|
|
214
|
+
return new Promise<T | undefined>((resolve) => {
|
|
215
|
+
let settled = false;
|
|
216
|
+
const timer = setTimeout(() => {
|
|
217
|
+
if (!settled) {
|
|
218
|
+
settled = true;
|
|
219
|
+
resolve(undefined);
|
|
220
|
+
}
|
|
221
|
+
}, timeoutMs);
|
|
222
|
+
void p.then(
|
|
223
|
+
(value) => {
|
|
224
|
+
if (!settled) {
|
|
225
|
+
settled = true;
|
|
226
|
+
clearTimeout(timer);
|
|
227
|
+
resolve(value);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
() => {
|
|
231
|
+
if (!settled) {
|
|
232
|
+
settled = true;
|
|
233
|
+
clearTimeout(timer);
|
|
234
|
+
resolve(undefined);
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { ITopicRouter, PeerRef, RingCoord } from "@optimystic/db-core";
|
|
2
|
+
import { bytesToB64url, b64urlToBytes, encodeCohortMessage } from "@optimystic/db-core";
|
|
3
|
+
import type { Libp2p } from "libp2p";
|
|
4
|
+
import type { FretService, RouteAndMaybeActV1, NearAnchorV1 } from "p2p-fret";
|
|
5
|
+
import { bytesToPeerId } from "./peer-codec.js";
|
|
6
|
+
import { requestResponse, DEFAULT_STREAM_MAX_BYTES } from "./stream-util.js";
|
|
7
|
+
import { PROTOCOL_COHORT_REGISTER } from "./protocols.js";
|
|
8
|
+
|
|
9
|
+
/** A FRET `routeAct` result carrying a cohort reply. */
|
|
10
|
+
function isCommit(res: NearAnchorV1 | { commitCertificate: string }): res is { commitCertificate: string } {
|
|
11
|
+
return typeof res === "object" && res !== null && "commitCertificate" in res;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FretTopicRouterOptions {
|
|
15
|
+
/** The `/register` protocol id (defaults to the canonical one). */
|
|
16
|
+
readonly registerProtocol?: string;
|
|
17
|
+
/** RPC TTL hops for `RouteAndMaybeAct`. Default 16. */
|
|
18
|
+
readonly ttl?: number;
|
|
19
|
+
/** Per-frame ceiling. Default {@link DEFAULT_STREAM_MAX_BYTES}. */
|
|
20
|
+
readonly maxBytes?: number;
|
|
21
|
+
/** Monotonic clock (unix ms); injectable for tests. Default `Date.now`. */
|
|
22
|
+
readonly clock?: () => number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* FRET-backed {@link ITopicRouter}.
|
|
27
|
+
*
|
|
28
|
+
* `routeAndAct` maps onto FRET's `RouteAndMaybeAct` (`FretService.routeAct`): the `RegisterV1` frame
|
|
29
|
+
* rides the `activity` field (base64url), routed to the cohort owning `key = coord_d(self, topicId)`,
|
|
30
|
+
* collecting `want_k = k` participants and `min_sigs = k − x`. The cohort's activity callback (set by
|
|
31
|
+
* the host) runs the willingness / cold-start / admission decision and returns the encoded
|
|
32
|
+
* `RegisterReplyV1` as the `commitCertificate`; this adapter decodes it back to bytes. A bare
|
|
33
|
+
* `NearAnchorV1` (no in-cluster activity ran) is surfaced to the walk as `no_state`.
|
|
34
|
+
*
|
|
35
|
+
* `dialMember` is the post-registration direct path: a libp2p dial of the `/register` protocol to the
|
|
36
|
+
* cached primary, used by the renewal ping (`docs/cohort-topic.md` §FRET integration L457-460).
|
|
37
|
+
*/
|
|
38
|
+
export class FretTopicRouter implements ITopicRouter {
|
|
39
|
+
private readonly registerProtocol: string;
|
|
40
|
+
private readonly ttl: number;
|
|
41
|
+
private readonly maxBytes: number;
|
|
42
|
+
private readonly clock: () => number;
|
|
43
|
+
|
|
44
|
+
constructor(private readonly node: Libp2p, private readonly fret: FretService, options: FretTopicRouterOptions = {}) {
|
|
45
|
+
this.registerProtocol = options.registerProtocol ?? PROTOCOL_COHORT_REGISTER;
|
|
46
|
+
this.ttl = options.ttl ?? 16;
|
|
47
|
+
this.maxBytes = options.maxBytes ?? DEFAULT_STREAM_MAX_BYTES;
|
|
48
|
+
this.clock = options.clock ?? ((): number => Date.now());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async routeAndAct(key: RingCoord, activity: Uint8Array, opts: { wantK: number; minSigs: number }): Promise<Uint8Array> {
|
|
52
|
+
const now = this.clock();
|
|
53
|
+
const msg: RouteAndMaybeActV1 = {
|
|
54
|
+
v: 1,
|
|
55
|
+
key: bytesToB64url(key),
|
|
56
|
+
want_k: opts.wantK,
|
|
57
|
+
min_sigs: opts.minSigs,
|
|
58
|
+
ttl: this.ttl,
|
|
59
|
+
activity: bytesToB64url(activity),
|
|
60
|
+
correlation_id: bytesToB64url(key) + ":" + now,
|
|
61
|
+
timestamp: now,
|
|
62
|
+
signature: "",
|
|
63
|
+
};
|
|
64
|
+
const res = await this.fret.routeAct(msg);
|
|
65
|
+
if (isCommit(res)) {
|
|
66
|
+
return b64urlToBytes(res.commitCertificate);
|
|
67
|
+
}
|
|
68
|
+
// No in-cluster activity ran (we only reached an anchor hint): the walk treats this as NoState
|
|
69
|
+
// and steps toward the root.
|
|
70
|
+
return encodeCohortMessage({ v: 1, result: "no_state" }, this.maxBytes);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async dialMember(member: PeerRef, activity: Uint8Array): Promise<Uint8Array> {
|
|
74
|
+
const peer = bytesToPeerId(member.id);
|
|
75
|
+
return requestResponse(this.node, peer, this.registerProtocol, activity, this.maxBytes);
|
|
76
|
+
}
|
|
77
|
+
}
|