@dcasegr/skein 0.0.0-stage → 0.1.2
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 +525 -2
- package/bin/skein-host.js +22 -0
- package/bin/skein.js +8 -0
- package/dist/client/admin-cli.d.ts +10 -0
- package/dist/client/admin-cli.js +370 -0
- package/dist/client/admin.d.ts +139 -0
- package/dist/client/admin.js +256 -0
- package/dist/client/bundle.d.ts +9 -0
- package/dist/client/bundle.js +34 -0
- package/dist/client/cli.d.ts +44 -0
- package/dist/client/cli.js +306 -0
- package/dist/client/client.d.ts +161 -0
- package/dist/client/client.js +237 -0
- package/dist/client/config.d.ts +18 -0
- package/dist/client/config.js +31 -0
- package/dist/client/conversation.d.ts +62 -0
- package/dist/client/conversation.js +113 -0
- package/dist/client/raw.d.ts +94 -0
- package/dist/client/raw.js +154 -0
- package/dist/client/target.d.ts +34 -0
- package/dist/client/target.js +158 -0
- package/dist/dev/cli.d.ts +8 -0
- package/dist/dev/cli.js +248 -0
- package/dist/dev/scan.d.ts +15 -0
- package/dist/dev/scan.js +173 -0
- package/dist/envelope-cbor.d.ts +110 -0
- package/dist/envelope-cbor.js +160 -0
- package/dist/envelope.d.ts +38 -0
- package/dist/envelope.js +101 -0
- package/dist/host/arc.d.ts +131 -0
- package/dist/host/arc.js +425 -0
- package/dist/host/billing.d.ts +102 -0
- package/dist/host/billing.js +167 -0
- package/dist/host/boot.d.ts +246 -0
- package/dist/host/boot.js +643 -0
- package/dist/host/cli.d.ts +57 -0
- package/dist/host/cli.js +1253 -0
- package/dist/host/clock.d.ts +3 -0
- package/dist/host/clock.js +8 -0
- package/dist/host/control.d.ts +45 -0
- package/dist/host/control.js +170 -0
- package/dist/host/cron.d.ts +99 -0
- package/dist/host/cron.js +196 -0
- package/dist/host/deliver.d.ts +53 -0
- package/dist/host/deliver.js +251 -0
- package/dist/host/deploy.d.ts +29 -0
- package/dist/host/deploy.js +55 -0
- package/dist/host/door-answer.d.ts +24 -0
- package/dist/host/door-answer.js +21 -0
- package/dist/host/events.d.ts +89 -0
- package/dist/host/events.js +222 -0
- package/dist/host/fake-arcade.d.ts +40 -0
- package/dist/host/fake-arcade.js +149 -0
- package/dist/host/fake-discovery.d.ts +4 -0
- package/dist/host/fake-discovery.js +58 -0
- package/dist/host/feeds.d.ts +127 -0
- package/dist/host/feeds.js +422 -0
- package/dist/host/frontdoor.d.ts +92 -0
- package/dist/host/frontdoor.js +172 -0
- package/dist/host/genesis.d.ts +259 -0
- package/dist/host/genesis.js +353 -0
- package/dist/host/handles.d.ts +40 -0
- package/dist/host/handles.js +88 -0
- package/dist/host/hostenv.d.ts +30 -0
- package/dist/host/hostenv.js +83 -0
- package/dist/host/image-chain.d.ts +127 -0
- package/dist/host/image-chain.js +440 -0
- package/dist/host/install.d.ts +22 -0
- package/dist/host/install.js +139 -0
- package/dist/host/instances.d.ts +227 -0
- package/dist/host/instances.js +430 -0
- package/dist/host/kernel.d.ts +246 -0
- package/dist/host/kernel.js +603 -0
- package/dist/host/liveness.d.ts +65 -0
- package/dist/host/liveness.js +155 -0
- package/dist/host/manifest.d.ts +160 -0
- package/dist/host/manifest.js +597 -0
- package/dist/host/p2p.d.ts +337 -0
- package/dist/host/p2p.js +1002 -0
- package/dist/host/packet.d.ts +121 -0
- package/dist/host/packet.js +562 -0
- package/dist/host/plan.d.ts +154 -0
- package/dist/host/plan.js +418 -0
- package/dist/host/providers.d.ts +238 -0
- package/dist/host/providers.js +565 -0
- package/dist/host/roster.d.ts +72 -0
- package/dist/host/roster.js +172 -0
- package/dist/host/router.d.ts +782 -0
- package/dist/host/router.js +2411 -0
- package/dist/host/signer.d.ts +49 -0
- package/dist/host/signer.js +167 -0
- package/dist/host/store-sqlite.d.ts +39 -0
- package/dist/host/store-sqlite.js +170 -0
- package/dist/host/stores.d.ts +43 -0
- package/dist/host/stores.js +342 -0
- package/dist/host/sync.d.ts +121 -0
- package/dist/host/sync.js +467 -0
- package/dist/host/testbeef.d.ts +21 -0
- package/dist/host/testbeef.js +37 -0
- package/dist/host/testhost.d.ts +149 -0
- package/dist/host/testhost.js +211 -0
- package/dist/host/vcdiff.d.ts +9 -0
- package/dist/host/vcdiff.js +210 -0
- package/dist/host/wasm-kernel.d.ts +87 -0
- package/dist/host/wasm-kernel.js +296 -0
- package/dist/host/wasm-worker.d.ts +1 -0
- package/dist/host/wasm-worker.js +186 -0
- package/dist/peers/cron.d.ts +33 -0
- package/dist/peers/cron.js +75 -0
- package/dist/peers/infer-main.d.ts +2 -0
- package/dist/peers/infer-main.js +74 -0
- package/dist/peers/infer.d.ts +163 -0
- package/dist/peers/infer.js +367 -0
- package/dist/runtime/beef.d.ts +28 -0
- package/dist/runtime/beef.js +107 -0
- package/dist/runtime/bitcoin.d.ts +36 -0
- package/dist/runtime/bitcoin.js +141 -0
- package/dist/runtime/cid.d.ts +14 -0
- package/dist/runtime/cid.js +51 -0
- package/dist/runtime/dispatch.d.ts +92 -0
- package/dist/runtime/dispatch.js +142 -0
- package/dist/runtime/envelope.d.ts +60 -0
- package/dist/runtime/envelope.js +101 -0
- package/dist/runtime/heads.d.ts +25 -0
- package/dist/runtime/heads.js +37 -0
- package/dist/runtime/identity.d.ts +28 -0
- package/dist/runtime/identity.js +67 -0
- package/dist/runtime/index-store.d.ts +152 -0
- package/dist/runtime/index-store.js +715 -0
- package/dist/runtime/log.d.ts +62 -0
- package/dist/runtime/log.js +104 -0
- package/dist/runtime/programs.d.ts +30 -0
- package/dist/runtime/programs.js +61 -0
- package/dist/runtime/records.d.ts +135 -0
- package/dist/runtime/records.js +149 -0
- package/dist/runtime/sqlite.d.ts +33 -0
- package/dist/runtime/sqlite.js +604 -0
- package/dist/runtime/store.d.ts +141 -0
- package/dist/runtime/store.js +24 -0
- package/dist/runtime/syscalls.d.ts +9 -0
- package/dist/runtime/syscalls.js +41 -0
- package/dist/runtime/tree.d.ts +60 -0
- package/dist/runtime/tree.js +196 -0
- package/dist/runtime/types.d.ts +100 -0
- package/dist/runtime/types.js +7 -0
- package/dist/testapps.d.ts +101 -0
- package/dist/testapps.js +275 -0
- package/dist/testkit.d.ts +25 -0
- package/dist/testkit.js +48 -0
- package/dist/wallet.d.ts +35 -0
- package/dist/wallet.js +87 -0
- package/images/README.md +68 -0
- package/images/default/README.md +38 -0
- package/images/default/bin/frontdoor.cid +1 -0
- package/images/default/bin/frontdoor.json +5 -0
- package/images/default/bin/messagebox.cid +1 -0
- package/images/default/bin/messagebox.json +8 -0
- package/images/default/bin/wallet.cid +1 -0
- package/images/default/bin/wallet.json +14 -0
- package/images/default/etc/config.json +1 -0
- package/images/default/etc/dispatch.json +82 -0
- package/images/host/etc/apps.json +8 -0
- package/kernel-zig/README.md +1247 -0
- package/kernel-zig/web/client.js +65 -0
- package/kernel-zig/web/kernel.d.ts +59 -0
- package/kernel-zig/web/kernel.js +329 -0
- package/kernel-zig/web/store.js +67 -0
- package/kernel-zig/web/worker.js +79 -0
- package/kernel-zig/zig-out/web/skein-kernel.wasm +0 -0
- package/package.json +77 -4
- package/wasm/README.md +35 -0
- package/wasm/frontdoor.wasm +0 -0
- package/wasm/messagebox.wasm +0 -0
- package/wasm/resolve.wasm +0 -0
- package/wasm/wallet.wasm +0 -0
- package/wasm/wire-probe.wasm +0 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import type { Libp2p, PeerId } from "@libp2p/interface";
|
|
2
|
+
import type { PrivateKey } from "@bsv/sdk";
|
|
3
|
+
import type { Store } from "../runtime/store.ts";
|
|
4
|
+
import { CID } from "multiformats/cid";
|
|
5
|
+
import { Liveness, type Live, type LiveBeat } from "./liveness.ts";
|
|
6
|
+
export type DhtMode = "off" | "client" | "server";
|
|
7
|
+
/** The host-wide settings: every node gets these. */
|
|
8
|
+
export interface P2PHostConfig {
|
|
9
|
+
listen: string[];
|
|
10
|
+
bootstrap: string[];
|
|
11
|
+
dht: DhtMode;
|
|
12
|
+
relays: string[];
|
|
13
|
+
mdns: boolean;
|
|
14
|
+
/** PEM certificate and key for the WebSocket listener (WSS). */
|
|
15
|
+
tls?: {
|
|
16
|
+
cert: string;
|
|
17
|
+
key: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** One instance's libp2p config (the genesis's `libp2p`): what the router subscribes and serves for it. */
|
|
21
|
+
export interface P2PInstanceConfig {
|
|
22
|
+
topics: string[];
|
|
23
|
+
protocols: string[];
|
|
24
|
+
/** This instance's listen addresses (over the host's): a fixed port belongs to one node. */
|
|
25
|
+
listen?: string[];
|
|
26
|
+
}
|
|
27
|
+
/** The default listeners: loopback TCP and WebSocket, ports chosen by the OS (plain WS on loopback: dev only). */
|
|
28
|
+
export declare const DEFAULT_LISTEN: string[];
|
|
29
|
+
/** What the front door is called with for an inbound message or stream frame (#51). */
|
|
30
|
+
export interface InboundCall {
|
|
31
|
+
transport: "libp2p";
|
|
32
|
+
topic?: string;
|
|
33
|
+
protocol?: string;
|
|
34
|
+
/** The publisher's peer ID (topics) or the remote peer's (streams): its multihash bytes. */
|
|
35
|
+
from: Uint8Array;
|
|
36
|
+
seqno?: Uint8Array;
|
|
37
|
+
signature?: Uint8Array;
|
|
38
|
+
body: Uint8Array;
|
|
39
|
+
}
|
|
40
|
+
/** The front door's answer: the verdict for GossipSub; for a stream frame, what to write back and whether to close. */
|
|
41
|
+
export interface InboundAnswer {
|
|
42
|
+
verdict: "accept" | "reject" | "ignore";
|
|
43
|
+
body?: Uint8Array;
|
|
44
|
+
close?: boolean;
|
|
45
|
+
reason?: string;
|
|
46
|
+
}
|
|
47
|
+
/** A frame read from a dialled stream, or its end. */
|
|
48
|
+
export type Frame = {
|
|
49
|
+
body: Uint8Array;
|
|
50
|
+
} | {
|
|
51
|
+
closed: true;
|
|
52
|
+
error?: string;
|
|
53
|
+
};
|
|
54
|
+
/** The stream protocol a signed message travels on to an instance (#70). */
|
|
55
|
+
export declare const MESSAGE_PROTOCOL = "/skein/message/1.0.0";
|
|
56
|
+
/**
|
|
57
|
+
* The overlay's receive row (skein-overlay etc/app.json; the settled sync design, David 2026-10-30):
|
|
58
|
+
* the host's OWN entry for the BEEFs it fetched (sync.ts `deliver` → Router.p2pInbound), never served
|
|
59
|
+
* to peers ("not a good door to have": a node takes BEEFs only from paths it chose). Whatever rows an
|
|
60
|
+
* instance declares, no node handles it inbound.
|
|
61
|
+
*/
|
|
62
|
+
export declare const RECEIVE_PROTOCOL = "/skein/overlay/beef/1.0.0";
|
|
63
|
+
export interface P2POptions {
|
|
64
|
+
host: P2PHostConfig;
|
|
65
|
+
/** The instance's peer key (signer.ts peerKey). */
|
|
66
|
+
keyOf(handle: string): PrivateKey;
|
|
67
|
+
/** One front-door call for an inbound message or frame (Router.p2pInbound). */
|
|
68
|
+
inbound(handle: string, call: InboundCall): Promise<InboundAnswer>;
|
|
69
|
+
log?(source: string, line: string): void;
|
|
70
|
+
/**
|
|
71
|
+
* Signs `data` with the instance's signer (#126 beacons), as the host signs
|
|
72
|
+
* an intention request (Router's `sign`: [2, "metanet handles envelope"],
|
|
73
|
+
* key ID `send`, counterparty anyone). With `identity` (the instance's
|
|
74
|
+
* identity key, 33 bytes). Absent: a beacon publishes nothing.
|
|
75
|
+
*/
|
|
76
|
+
sign?(handle: string, data: Uint8Array): Promise<Uint8Array>;
|
|
77
|
+
identity?(handle: string): Promise<Uint8Array | undefined>;
|
|
78
|
+
/** How often topics are re-advertised and looked up in the DHT, and bootstrap peers redialled (ms). */
|
|
79
|
+
discoveryMs?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Protocols the host itself serves on every node, beside /skein/message/1.0.0: each inbound frame
|
|
82
|
+
* answered by the handler, its answer written back; nothing reaches the front door. (The router
|
|
83
|
+
* names none: the overlay's sync, its one user under #150, is a row an app declares since #154.)
|
|
84
|
+
*/
|
|
85
|
+
hostProtocols?: Record<string, (handle: string, remote: PeerId, frame: Uint8Array) => Promise<Uint8Array>>;
|
|
86
|
+
/** Each beat the liveness tool newly keeps from another peer (shruggr/skein#150). */
|
|
87
|
+
beat?(handle: string, topic: string, beat: LiveBeat): void;
|
|
88
|
+
}
|
|
89
|
+
/** A bsv secp256k1 key as a libp2p private key. */
|
|
90
|
+
export declare function libp2pKey(k: PrivateKey): import("@libp2p/interface").PrivateKey;
|
|
91
|
+
/** The peer ID of a key: the identity multihash of its protobuf (secp256k1, compressed). */
|
|
92
|
+
export declare function peerIdOf(k: PrivateKey): PeerId;
|
|
93
|
+
/** The compressed secp256k1 key a peer ID embeds (hex), or undefined for another kind. */
|
|
94
|
+
export declare function keyOfPeerId(id: string | Uint8Array): string | undefined;
|
|
95
|
+
/** A topic name's rendezvous CID: v1 raw over sha2-256 of the name (go-libp2p's nsToCid). */
|
|
96
|
+
export declare function topicCid(topic: string): Promise<CID>;
|
|
97
|
+
/** The host-wide settings: the environment's SKEIN_LIBP2P_*, else $SKEIN_HOME/host.env's. */
|
|
98
|
+
export declare function hostP2PConfig(vars: Record<string, string | undefined>, home?: string): P2PHostConfig;
|
|
99
|
+
/** The libp2p config a genesis carries (`libp2p: {topics?, protocols?, listen?}`), or undefined: no node. */
|
|
100
|
+
export declare function libp2pOf(g: Record<string, unknown> | null | undefined): P2PInstanceConfig | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* An instance's libp2p config as it stands (#72, #77): the genesis's
|
|
103
|
+
* (libp2pOf: a tree names what its node subscribes in `config.libp2p`),
|
|
104
|
+
* plus the topics and protocols named by the dispatch table's `libp2p`
|
|
105
|
+
* rows added since the genesis (an app's install; address: a topic) — a
|
|
106
|
+
* genesis topic row alone subscribes nothing, as a route alone did not — and
|
|
107
|
+
* every stream protocol a `libp2p` row names (`/<protocol>`), whatever
|
|
108
|
+
* installed it, the genesis included (#155: an image-born instance serves its
|
|
109
|
+
* sync row; the overlay's receive row stays unserved, P2PHost), plus the
|
|
110
|
+
* topics the apps subscribed (#119, `subscribed`).
|
|
111
|
+
* `beacons` (#126): an app's beacon (or its liveness, #138: P2PHost.liveness
|
|
112
|
+
* subscribes those topics itself) needs the node, and adds no topic.
|
|
113
|
+
* Undefined: no node — the genesis declares none and nothing needs one.
|
|
114
|
+
*/
|
|
115
|
+
export declare function libp2pConfig(g: Record<string, unknown> | null | undefined, rows: Array<Record<string, unknown>>, subscribed?: string[], beacons?: boolean): P2PInstanceConfig | undefined;
|
|
116
|
+
export interface Subscription {
|
|
117
|
+
app: string;
|
|
118
|
+
topic: string;
|
|
119
|
+
program: string;
|
|
120
|
+
fn: string;
|
|
121
|
+
filter?: string;
|
|
122
|
+
}
|
|
123
|
+
export type SubscriptionEvent = {
|
|
124
|
+
event: "subscribe";
|
|
125
|
+
sub: Subscription;
|
|
126
|
+
} | {
|
|
127
|
+
event: "unsubscribe";
|
|
128
|
+
app: string;
|
|
129
|
+
topic: string;
|
|
130
|
+
};
|
|
131
|
+
export declare const isTopic: (t: unknown) => t is string;
|
|
132
|
+
/** A `subscribe` / `unsubscribe` event record, read (subscriptions.zig eventOf); or why it is not one this host follows. */
|
|
133
|
+
export declare function subscriptionEvent(rec: Record<string, unknown>): SubscriptionEvent | {
|
|
134
|
+
refused: string;
|
|
135
|
+
};
|
|
136
|
+
/** Fold subscription events in order (subscriptions.zig apply). */
|
|
137
|
+
export declare function foldSubscriptions(events: Iterable<SubscriptionEvent>, into?: Subscription[]): Subscription[];
|
|
138
|
+
/** The topics the subscriptions take (each once): what the node subscribes for the apps. */
|
|
139
|
+
export declare const subscribedTopics: (subs: Subscription[]) => string[];
|
|
140
|
+
/**
|
|
141
|
+
* The subscriptions, folded from the store's log (#119, the host's recovery
|
|
142
|
+
* at hydrate; subscriptions.zig fold): the `subscribe` / `unsubscribe`
|
|
143
|
+
* records each step's update lists in `emitted`, in log order — by the entry
|
|
144
|
+
* the step processed (`input`'s `n`), the step's time, its thread's start,
|
|
145
|
+
* the thread's CID, its place in the thread and in `emitted`. Read only.
|
|
146
|
+
*/
|
|
147
|
+
export declare function subscriptionsOf(store: Pick<Store, "get" | "chains" | "edges">): Promise<Subscription[]>;
|
|
148
|
+
/**
|
|
149
|
+
* The beacons standing (#126), folded from the store's log as the
|
|
150
|
+
* subscriptions are: the `beacon` / `unbeacon` records the steps' updates
|
|
151
|
+
* list, in log order, keyed by (app, topic). Read only.
|
|
152
|
+
*/
|
|
153
|
+
export declare function beaconsOf(store: Pick<Store, "get" | "chains" | "edges">): Promise<Beacon[]>;
|
|
154
|
+
/**
|
|
155
|
+
* An emitted event's place in the log (the fold order, subscriptions.zig): the entry its step
|
|
156
|
+
* processed (`n`, the update's `input`), the step's time (`at`, the update's), its thread (origin),
|
|
157
|
+
* its place in the thread (`seq`), the event record's place in the update's `emitted` (`i`) and
|
|
158
|
+
* the record's CID.
|
|
159
|
+
*/
|
|
160
|
+
export interface EmittedAt {
|
|
161
|
+
n: number;
|
|
162
|
+
at: number;
|
|
163
|
+
thread: CID;
|
|
164
|
+
seq: number;
|
|
165
|
+
i: number;
|
|
166
|
+
record: CID;
|
|
167
|
+
}
|
|
168
|
+
/** The event records the steps' updates list in `emitted` that `read` takes, in log order (the kernel's fold order, subscriptions.zig); `read` gets each one's place too. */
|
|
169
|
+
export declare function emittedEvents<T>(store: Pick<Store, "get" | "chains" | "edges">, read: (rec: Record<string, unknown>, place: EmittedAt) => T | undefined): Promise<T[]>;
|
|
170
|
+
export interface Beacon {
|
|
171
|
+
app: string;
|
|
172
|
+
topic: string;
|
|
173
|
+
every: number;
|
|
174
|
+
body: Uint8Array;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A beat as published (#126): dag-cbor {body, at, sender, signature}. `at`:
|
|
178
|
+
* the beat's time (ms since the epoch, the host's clock); `sender`: the
|
|
179
|
+
* instance's identity key (33 bytes); `signature`: the instance's (DER),
|
|
180
|
+
* [2, "metanet handles envelope"] / `send` / counterparty anyone, over
|
|
181
|
+
* sha2-256 of beaconPreimage — dag-cbor {kind: "beacon", topic, body, at,
|
|
182
|
+
* sender}: the topic is signed, not carried. A receiver checks the signature
|
|
183
|
+
* (beaconProblem) and `at` against its own clock.
|
|
184
|
+
*/
|
|
185
|
+
export interface BeaconBeat {
|
|
186
|
+
body: Uint8Array;
|
|
187
|
+
at: number;
|
|
188
|
+
sender: Uint8Array;
|
|
189
|
+
signature: Uint8Array;
|
|
190
|
+
}
|
|
191
|
+
/** What a beat's signature covers. */
|
|
192
|
+
export declare function beaconPreimage(topic: string, b: Omit<BeaconBeat, "signature">): Uint8Array;
|
|
193
|
+
/** A beat's frame for `topic`, signed by `sign` (the instance's signer). */
|
|
194
|
+
export declare function beaconFrame(topic: string, body: Uint8Array, at: number, sender: Uint8Array, sign: (data: Uint8Array) => Promise<Uint8Array>): Promise<Uint8Array>;
|
|
195
|
+
/** A beat read from a frame on `topic`, its signature checked against its sender; or why it is not one. */
|
|
196
|
+
export declare function beaconBeat(topic: string, frame: Uint8Array): BeaconBeat | {
|
|
197
|
+
problem: string;
|
|
198
|
+
};
|
|
199
|
+
export type BeaconEvent = {
|
|
200
|
+
event: "beacon";
|
|
201
|
+
beacon: Beacon;
|
|
202
|
+
} | {
|
|
203
|
+
event: "unbeacon";
|
|
204
|
+
app: string;
|
|
205
|
+
topic: string;
|
|
206
|
+
};
|
|
207
|
+
/** A `beacon` / `unbeacon` event record, read; or why it is not one this host follows. */
|
|
208
|
+
export declare function beaconEvent(rec: Record<string, unknown>): BeaconEvent | {
|
|
209
|
+
refused: string;
|
|
210
|
+
};
|
|
211
|
+
/** Fold beacon events in order: a beacon replaces the app's own on the topic, an unbeacon removes it. */
|
|
212
|
+
export declare function foldBeacons(events: Iterable<BeaconEvent>, into?: Beacon[]): Beacon[];
|
|
213
|
+
/** The answer to a stream whose first frame names no topic where several instances declare its protocol (#160). */
|
|
214
|
+
export declare const TOPIC_REQUIRED = "topic required";
|
|
215
|
+
export declare class P2PHost {
|
|
216
|
+
readonly o: P2POptions;
|
|
217
|
+
/** The liveness tool's state (#138): the apps' liveness and the beats kept, in memory. */
|
|
218
|
+
readonly live: Liveness;
|
|
219
|
+
/** The nodes, by peer ID (#160: one per key). */
|
|
220
|
+
private nodes;
|
|
221
|
+
/** Each handle's node. */
|
|
222
|
+
private byHandle;
|
|
223
|
+
/** Each handle's peer ID, as derived (keyOf). */
|
|
224
|
+
private ids;
|
|
225
|
+
/** Each key's declares, in order (one at a time). */
|
|
226
|
+
private starting;
|
|
227
|
+
private stopped;
|
|
228
|
+
constructor(o: P2POptions);
|
|
229
|
+
private say;
|
|
230
|
+
/** A node's name in a log line: its one handle (as before #160), else its first. */
|
|
231
|
+
private nameOf;
|
|
232
|
+
/** The node of an instance, if it has one. */
|
|
233
|
+
node(handle: string): Libp2p | undefined;
|
|
234
|
+
/** An instance's peer ID (derived: whether or not its node runs). */
|
|
235
|
+
peerId(handle: string): string;
|
|
236
|
+
/** The handles on `handle`'s node (#160: one in a master-key host; every one sharing its key in a one-key host). */
|
|
237
|
+
handlesOn(handle: string): string[];
|
|
238
|
+
/** How many nodes run (#160: one per key). */
|
|
239
|
+
nodeCount(): number;
|
|
240
|
+
/** Where an instance's node listens (with /p2p/<id>). */
|
|
241
|
+
addrs(handle: string): string[];
|
|
242
|
+
/**
|
|
243
|
+
* `handle`'s libp2p config is this: its key's node started (once) with its peer key, the handle's
|
|
244
|
+
* topics subscribed with the validator, its protocols handled. Declared again, the handle is brought
|
|
245
|
+
* to the new config. No config: the handle leaves its node; the node stops with its last handle.
|
|
246
|
+
*/
|
|
247
|
+
declare(handle: string, config: P2PInstanceConfig | undefined): Promise<void>;
|
|
248
|
+
/** The topics and protocols an instance's node serves for it now. */
|
|
249
|
+
served(handle: string): {
|
|
250
|
+
topics: string[];
|
|
251
|
+
protocols: string[];
|
|
252
|
+
} | undefined;
|
|
253
|
+
/** Bring `handle` on a running node to `config` (joining it if it is new there): subscribe and handle what is new, unsubscribe and unhandle what no handle takes any more. */
|
|
254
|
+
private reconfigure;
|
|
255
|
+
private subscribe;
|
|
256
|
+
/** The topics `handle` takes: its config's and its apps' liveness topics (#138). */
|
|
257
|
+
private takes;
|
|
258
|
+
/** Subscribe what the handles' configs and liveness tools (#138) take, unsubscribe the rest: the topics added and removed. */
|
|
259
|
+
private resubscribe;
|
|
260
|
+
/** Handle the protocols the handles declare, unhandle those none declares any more (the host's own aside). */
|
|
261
|
+
private rehandle;
|
|
262
|
+
/** The topics `handle`'s node subscribes for it now: its config's and its apps' liveness topics (#138). */
|
|
263
|
+
listening(handle: string): string[];
|
|
264
|
+
/**
|
|
265
|
+
* The liveness `handle`'s apps keep (#138, liveness.ts): the tool keeps it, and the node subscribes
|
|
266
|
+
* each topic (not admitting its messages) and leaves those no liveness nor config takes. One line
|
|
267
|
+
* when a topic is taken or left. No node: kept for when it starts.
|
|
268
|
+
*/
|
|
269
|
+
liveness(handle: string, lives: Live[]): void;
|
|
270
|
+
/** Whether the host serves `protocol` on every node itself (/skein/message/1.0.0, `hostProtocols`). */
|
|
271
|
+
private hostServed;
|
|
272
|
+
private handleHostProtocol;
|
|
273
|
+
private handleProtocol;
|
|
274
|
+
private start;
|
|
275
|
+
/** Keep the bootstrap peers connected; with the DHT on, advertise each topic and dial its providers. */
|
|
276
|
+
private discover;
|
|
277
|
+
private pubsub;
|
|
278
|
+
/**
|
|
279
|
+
* The topic validator: for every handle on the node that takes the topic, one front-door call (or,
|
|
280
|
+
* for a topic only its apps' liveness takes, #138, the liveness tool's verdict alone: nothing
|
|
281
|
+
* admitted); GossipSub's verdict (async: forwarding waits on it) is Accept if any handle accepts,
|
|
282
|
+
* Reject only if every one rejects, else Ignore (#160).
|
|
283
|
+
*/
|
|
284
|
+
private validate;
|
|
285
|
+
/** One handle's verdict on a topic message (the validator as it was per node before #160). */
|
|
286
|
+
private validateFor;
|
|
287
|
+
/**
|
|
288
|
+
* Which handle an inbound stream on `protocol` is for (#160), by its first frame: the handles that
|
|
289
|
+
* declare the protocol (every handle declares /skein/message/1.0.0); the frame's `topic` (dag-cbor
|
|
290
|
+
* {topic, …}) picks the one among them that takes it; a frame naming none, or a topic none of them
|
|
291
|
+
* takes, goes to the one handle that declares the protocol; with several, a problem.
|
|
292
|
+
*/
|
|
293
|
+
private streamHandle;
|
|
294
|
+
/** An inbound stream on a handled protocol: its first frame picks the handle (#160); each frame one front-door call, its answer's body written back. */
|
|
295
|
+
private serve;
|
|
296
|
+
private nodeOf;
|
|
297
|
+
/**
|
|
298
|
+
* The beacons `handle`'s node beats (#126): each a new frame (beaconFrame:
|
|
299
|
+
* the body, the beat's time, the instance's signature) published on its topic
|
|
300
|
+
* every `every` ms — the topic not subscribed; nothing logged per beat (a
|
|
301
|
+
* failed beat is dropped: the next one is the retry). The FIRST beacon on a
|
|
302
|
+
* topic publishes at once. A beacon REPLACING one (the same app and topic, a
|
|
303
|
+
* new body and/or `every`; the settled sync design, David 2026-10-30) swaps
|
|
304
|
+
* what the next beat carries and leaves the timer alone — no publish now, no
|
|
305
|
+
* reset — unless `every` changed, when the timer is reset to the new
|
|
306
|
+
* interval (still no publish now). One line when a beacon starts or stops.
|
|
307
|
+
* No node: nothing beats.
|
|
308
|
+
*/
|
|
309
|
+
beacons(handle: string, beacons: Beacon[]): void;
|
|
310
|
+
/** Publish `body` on `topic` from `handle`'s node (signed with its peer key): the message's seqno, and how many peers took it. */
|
|
311
|
+
publish(handle: string, topic: string, body: Uint8Array): Promise<{
|
|
312
|
+
seqno: Uint8Array;
|
|
313
|
+
recipients: number;
|
|
314
|
+
}>;
|
|
315
|
+
/** Open a stream from `handle`'s node to a peer (a peer ID, or a multiaddr with /p2p/<id>): its id; each frame read from it, and its end, to `frames`. */
|
|
316
|
+
dial(handle: string, peer: string, protocol: string, frames: (f: Frame) => void): Promise<number>;
|
|
317
|
+
/**
|
|
318
|
+
* One request to a peer on `protocol` (a host protocol, shruggr/skein#150): a stream opened, one
|
|
319
|
+
* frame written, one frame read back, the stream closed. → the answer's bytes.
|
|
320
|
+
*/
|
|
321
|
+
request(handle: string, peer: string, protocol: string, body: Uint8Array, timeoutMs?: number): Promise<Uint8Array>;
|
|
322
|
+
/** The protocols `handle`'s node handles inbound now (the libp2p node's own registry: its rows', the host's, /skein/message/1.0.0). */
|
|
323
|
+
handledProtocols(handle: string): string[];
|
|
324
|
+
/** The addresses `handle`'s node knows for `peer` (its peer store), as multiaddr strings. */
|
|
325
|
+
peerAddrs(handle: string, peer: string): Promise<string[]>;
|
|
326
|
+
/** Dial `peer` from `handle`'s node, at `addrs` when given (a start's persisted peers), else as the peer store knows it. */
|
|
327
|
+
connect(handle: string, peer: string, addrs?: string[]): Promise<void>;
|
|
328
|
+
/** The peers `handle`'s node knows subscribe `topic` (GossipSub's view), as peer ID strings. */
|
|
329
|
+
subscribers(handle: string, topic: string): string[];
|
|
330
|
+
/** Write one length-prefixed frame on a dialled stream. */
|
|
331
|
+
send(handle: string, id: number, body: Uint8Array): Promise<void>;
|
|
332
|
+
/** Close a dialled stream (our side), and forget it. */
|
|
333
|
+
close(handle: string, id: number): Promise<void>;
|
|
334
|
+
/** `handle` leaves its node (its beats stopped, its liveness forgotten); the node stops with its last handle, else follows the handles left. */
|
|
335
|
+
private drop;
|
|
336
|
+
stop(): Promise<void>;
|
|
337
|
+
}
|