@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.
Files changed (176) hide show
  1. package/README.md +525 -2
  2. package/bin/skein-host.js +22 -0
  3. package/bin/skein.js +8 -0
  4. package/dist/client/admin-cli.d.ts +10 -0
  5. package/dist/client/admin-cli.js +370 -0
  6. package/dist/client/admin.d.ts +139 -0
  7. package/dist/client/admin.js +256 -0
  8. package/dist/client/bundle.d.ts +9 -0
  9. package/dist/client/bundle.js +34 -0
  10. package/dist/client/cli.d.ts +44 -0
  11. package/dist/client/cli.js +306 -0
  12. package/dist/client/client.d.ts +161 -0
  13. package/dist/client/client.js +237 -0
  14. package/dist/client/config.d.ts +18 -0
  15. package/dist/client/config.js +31 -0
  16. package/dist/client/conversation.d.ts +62 -0
  17. package/dist/client/conversation.js +113 -0
  18. package/dist/client/raw.d.ts +94 -0
  19. package/dist/client/raw.js +154 -0
  20. package/dist/client/target.d.ts +34 -0
  21. package/dist/client/target.js +158 -0
  22. package/dist/dev/cli.d.ts +8 -0
  23. package/dist/dev/cli.js +248 -0
  24. package/dist/dev/scan.d.ts +15 -0
  25. package/dist/dev/scan.js +173 -0
  26. package/dist/envelope-cbor.d.ts +110 -0
  27. package/dist/envelope-cbor.js +160 -0
  28. package/dist/envelope.d.ts +38 -0
  29. package/dist/envelope.js +101 -0
  30. package/dist/host/arc.d.ts +131 -0
  31. package/dist/host/arc.js +425 -0
  32. package/dist/host/billing.d.ts +102 -0
  33. package/dist/host/billing.js +167 -0
  34. package/dist/host/boot.d.ts +246 -0
  35. package/dist/host/boot.js +643 -0
  36. package/dist/host/cli.d.ts +57 -0
  37. package/dist/host/cli.js +1253 -0
  38. package/dist/host/clock.d.ts +3 -0
  39. package/dist/host/clock.js +8 -0
  40. package/dist/host/control.d.ts +45 -0
  41. package/dist/host/control.js +170 -0
  42. package/dist/host/cron.d.ts +99 -0
  43. package/dist/host/cron.js +196 -0
  44. package/dist/host/deliver.d.ts +53 -0
  45. package/dist/host/deliver.js +251 -0
  46. package/dist/host/deploy.d.ts +29 -0
  47. package/dist/host/deploy.js +55 -0
  48. package/dist/host/door-answer.d.ts +24 -0
  49. package/dist/host/door-answer.js +21 -0
  50. package/dist/host/events.d.ts +89 -0
  51. package/dist/host/events.js +222 -0
  52. package/dist/host/fake-arcade.d.ts +40 -0
  53. package/dist/host/fake-arcade.js +149 -0
  54. package/dist/host/fake-discovery.d.ts +4 -0
  55. package/dist/host/fake-discovery.js +58 -0
  56. package/dist/host/feeds.d.ts +127 -0
  57. package/dist/host/feeds.js +422 -0
  58. package/dist/host/frontdoor.d.ts +92 -0
  59. package/dist/host/frontdoor.js +172 -0
  60. package/dist/host/genesis.d.ts +259 -0
  61. package/dist/host/genesis.js +353 -0
  62. package/dist/host/handles.d.ts +40 -0
  63. package/dist/host/handles.js +88 -0
  64. package/dist/host/hostenv.d.ts +30 -0
  65. package/dist/host/hostenv.js +83 -0
  66. package/dist/host/image-chain.d.ts +127 -0
  67. package/dist/host/image-chain.js +440 -0
  68. package/dist/host/install.d.ts +22 -0
  69. package/dist/host/install.js +139 -0
  70. package/dist/host/instances.d.ts +227 -0
  71. package/dist/host/instances.js +430 -0
  72. package/dist/host/kernel.d.ts +246 -0
  73. package/dist/host/kernel.js +603 -0
  74. package/dist/host/liveness.d.ts +65 -0
  75. package/dist/host/liveness.js +155 -0
  76. package/dist/host/manifest.d.ts +160 -0
  77. package/dist/host/manifest.js +597 -0
  78. package/dist/host/p2p.d.ts +337 -0
  79. package/dist/host/p2p.js +1002 -0
  80. package/dist/host/packet.d.ts +121 -0
  81. package/dist/host/packet.js +562 -0
  82. package/dist/host/plan.d.ts +154 -0
  83. package/dist/host/plan.js +418 -0
  84. package/dist/host/providers.d.ts +238 -0
  85. package/dist/host/providers.js +565 -0
  86. package/dist/host/roster.d.ts +72 -0
  87. package/dist/host/roster.js +172 -0
  88. package/dist/host/router.d.ts +782 -0
  89. package/dist/host/router.js +2411 -0
  90. package/dist/host/signer.d.ts +49 -0
  91. package/dist/host/signer.js +167 -0
  92. package/dist/host/store-sqlite.d.ts +39 -0
  93. package/dist/host/store-sqlite.js +170 -0
  94. package/dist/host/stores.d.ts +43 -0
  95. package/dist/host/stores.js +342 -0
  96. package/dist/host/sync.d.ts +121 -0
  97. package/dist/host/sync.js +467 -0
  98. package/dist/host/testbeef.d.ts +21 -0
  99. package/dist/host/testbeef.js +37 -0
  100. package/dist/host/testhost.d.ts +149 -0
  101. package/dist/host/testhost.js +211 -0
  102. package/dist/host/vcdiff.d.ts +9 -0
  103. package/dist/host/vcdiff.js +210 -0
  104. package/dist/host/wasm-kernel.d.ts +87 -0
  105. package/dist/host/wasm-kernel.js +296 -0
  106. package/dist/host/wasm-worker.d.ts +1 -0
  107. package/dist/host/wasm-worker.js +186 -0
  108. package/dist/peers/cron.d.ts +33 -0
  109. package/dist/peers/cron.js +75 -0
  110. package/dist/peers/infer-main.d.ts +2 -0
  111. package/dist/peers/infer-main.js +74 -0
  112. package/dist/peers/infer.d.ts +163 -0
  113. package/dist/peers/infer.js +367 -0
  114. package/dist/runtime/beef.d.ts +28 -0
  115. package/dist/runtime/beef.js +107 -0
  116. package/dist/runtime/bitcoin.d.ts +36 -0
  117. package/dist/runtime/bitcoin.js +141 -0
  118. package/dist/runtime/cid.d.ts +14 -0
  119. package/dist/runtime/cid.js +51 -0
  120. package/dist/runtime/dispatch.d.ts +92 -0
  121. package/dist/runtime/dispatch.js +142 -0
  122. package/dist/runtime/envelope.d.ts +60 -0
  123. package/dist/runtime/envelope.js +101 -0
  124. package/dist/runtime/heads.d.ts +25 -0
  125. package/dist/runtime/heads.js +37 -0
  126. package/dist/runtime/identity.d.ts +28 -0
  127. package/dist/runtime/identity.js +67 -0
  128. package/dist/runtime/index-store.d.ts +152 -0
  129. package/dist/runtime/index-store.js +715 -0
  130. package/dist/runtime/log.d.ts +62 -0
  131. package/dist/runtime/log.js +104 -0
  132. package/dist/runtime/programs.d.ts +30 -0
  133. package/dist/runtime/programs.js +61 -0
  134. package/dist/runtime/records.d.ts +135 -0
  135. package/dist/runtime/records.js +149 -0
  136. package/dist/runtime/sqlite.d.ts +33 -0
  137. package/dist/runtime/sqlite.js +604 -0
  138. package/dist/runtime/store.d.ts +141 -0
  139. package/dist/runtime/store.js +24 -0
  140. package/dist/runtime/syscalls.d.ts +9 -0
  141. package/dist/runtime/syscalls.js +41 -0
  142. package/dist/runtime/tree.d.ts +60 -0
  143. package/dist/runtime/tree.js +196 -0
  144. package/dist/runtime/types.d.ts +100 -0
  145. package/dist/runtime/types.js +7 -0
  146. package/dist/testapps.d.ts +101 -0
  147. package/dist/testapps.js +275 -0
  148. package/dist/testkit.d.ts +25 -0
  149. package/dist/testkit.js +48 -0
  150. package/dist/wallet.d.ts +35 -0
  151. package/dist/wallet.js +87 -0
  152. package/images/README.md +68 -0
  153. package/images/default/README.md +38 -0
  154. package/images/default/bin/frontdoor.cid +1 -0
  155. package/images/default/bin/frontdoor.json +5 -0
  156. package/images/default/bin/messagebox.cid +1 -0
  157. package/images/default/bin/messagebox.json +8 -0
  158. package/images/default/bin/wallet.cid +1 -0
  159. package/images/default/bin/wallet.json +14 -0
  160. package/images/default/etc/config.json +1 -0
  161. package/images/default/etc/dispatch.json +82 -0
  162. package/images/host/etc/apps.json +8 -0
  163. package/kernel-zig/README.md +1247 -0
  164. package/kernel-zig/web/client.js +65 -0
  165. package/kernel-zig/web/kernel.d.ts +59 -0
  166. package/kernel-zig/web/kernel.js +329 -0
  167. package/kernel-zig/web/store.js +67 -0
  168. package/kernel-zig/web/worker.js +79 -0
  169. package/kernel-zig/zig-out/web/skein-kernel.wasm +0 -0
  170. package/package.json +77 -4
  171. package/wasm/README.md +35 -0
  172. package/wasm/frontdoor.wasm +0 -0
  173. package/wasm/messagebox.wasm +0 -0
  174. package/wasm/resolve.wasm +0 -0
  175. package/wasm/wallet.wasm +0 -0
  176. package/wasm/wire-probe.wasm +0 -0
@@ -0,0 +1,246 @@
1
+ import type { DispatchRow } from "../runtime/dispatch.ts";
2
+ import { type ChildProcess } from "node:child_process";
3
+ import { type WalletInterface } from "@bsv/sdk";
4
+ import type { CID } from "multiformats/cid";
5
+ import type { EntryBody } from "../runtime/log.ts";
6
+ import type { Stamp } from "../runtime/syscalls.ts";
7
+ import { type Store } from "../runtime/store.ts";
8
+ import type { Outgoing } from "./providers.ts";
9
+ /** The kernel binary: $SKEIN_KERNEL_BIN, else kernel-zig's release build. */
10
+ export declare const KERNEL_BIN: string;
11
+ type Frame = Record<string, unknown>;
12
+ /** A request thread's answer (#66, the `answer` frame): at rest (finished | errored), or not yet at the wait's bound. */
13
+ export type RequestAnswer = {
14
+ thread?: CID;
15
+ state: "finished";
16
+ answer: Uint8Array;
17
+ } | {
18
+ thread?: CID;
19
+ state: "errored";
20
+ error: string;
21
+ } | {
22
+ thread?: CID;
23
+ state: "waiting" | "running" | "new" | "pending";
24
+ };
25
+ export { DoorAnswered, doorAnswer, type DoorAnswer } from "./door-answer.ts";
26
+ /** The host chain as the kernel answers it (#156): its record's CID and tip; `headers`/`chain-import` also count. */
27
+ export type HostChainTip = {
28
+ root: CID;
29
+ height: number;
30
+ hash: string;
31
+ added?: number;
32
+ replaced?: number;
33
+ };
34
+ /** A kernel call's answer (#40): the program's stdout, or its error; the fuel it used either way. */
35
+ export type CallAnswer = {
36
+ ok: true;
37
+ result: Uint8Array;
38
+ fuel: number;
39
+ } | {
40
+ ok: false;
41
+ error: string;
42
+ fuel: number;
43
+ };
44
+ export interface KernelOptions {
45
+ /** The store file, or a set of the host's LMDB environment, `lmdb:<env dir>#<handle>` (#96: the kernel gets SKEIN_STORE). */
46
+ db: string;
47
+ handle: string;
48
+ domain: string;
49
+ /** Answers the kernel's `wallet` frames: the instance's signer. Absent: every wallet call fails. */
50
+ wallet?: WalletInterface;
51
+ /** A message (#70) or an event (#65) the kernel hands over to carry out (the `emit` notice): a `local` provider's, the libp2p node's, the broadcaster's (providers.ts). Absent: dropped. */
52
+ emit?(o: Outgoing): void;
53
+ /** Log lines (the kernel's stderr and this side's notes). */
54
+ log?(line: string): void;
55
+ /** The process exited (code or signal). */
56
+ exited?(code: number | null, signal: string | null): void;
57
+ /** Environment for the process, added to this one's. */
58
+ env?: Record<string, string | undefined>;
59
+ command?: string;
60
+ }
61
+ /**
62
+ * What the router holds of an instance's kernel, whichever process runs it (#158): the frames
63
+ * above, as calls. `call` is the transport's; the rest is built on it.
64
+ */
65
+ export declare abstract class KernelSurface {
66
+ abstract readonly o: KernelOptions;
67
+ /** Pending calls in both directions: the router stops a kernel only when this is 0. */
68
+ busy: number;
69
+ last: number;
70
+ gone: boolean;
71
+ /** The kernel process's pid (a hosted instance's: the host process's). */
72
+ abstract get pid(): number | undefined;
73
+ abstract call(op: string, v?: unknown): Promise<unknown>;
74
+ /** Print the ready line (`skein runtime <identity> (<handle>@<domain>) · pid …`). */
75
+ abstract running(identity: string): Promise<void>;
76
+ abstract stop(killAfterMs?: number): Promise<void>;
77
+ abstract exited(): Promise<void>;
78
+ readonly store: Store;
79
+ /** Any block, whatever its codec. */
80
+ hasBlock(cid: CID): Promise<boolean>;
81
+ /** A block minted elsewhere (git-raw, raw, dag-cbor, bitcoin-*), hash-checked by the kernel (#4: the loader's pre-fill). */
82
+ putBlock(cid: CID, bytes: Uint8Array): Promise<void>;
83
+ /** Adopt a checkpoint's state record (its blocks put first) as this empty store's state (#4). */
84
+ restore(state: CID): Promise<void>;
85
+ boxes(): Promise<string[]>;
86
+ /** The dispatch table as it stands (#77): its chain's tip (the change key; null before the genesis is processed) and its rows. */
87
+ dispatch(): Promise<{
88
+ tip: CID | null;
89
+ rows: DispatchRow[];
90
+ }>;
91
+ genesis(): Promise<Record<string, unknown>>;
92
+ /**
93
+ * Admit an arrival (#163): its entry's body and its stamp (`time`, the host's clock at
94
+ * admission; default now) — the kernel appends it, assigning `prev` and `n` from its own tip.
95
+ * A request's record beside it (#121: the kernel puts it, after the door), an event's likewise
96
+ * (#164: through the door when its box's route names kernel.beef), else put first. A request
97
+ * or event the door turns away or answers writes no entry (#143): DoorAnswered. The entry's CID.
98
+ */
99
+ admit(body: EntryBody, records?: {
100
+ body?: Uint8Array;
101
+ request?: Record<string, unknown>;
102
+ event?: Record<string, unknown>;
103
+ }, time?: Stamp): Promise<CID>;
104
+ /**
105
+ * The kernel's `call` (#40): a program's function (by CID, or a genesis
106
+ * program's name) over the current state — no entry, no writes, the signer
107
+ * and http answered but not recorded; fuel-limited (`callFuelLimit`). The
108
+ * result is what the program wrote to stdout; `fuel` is reported either way
109
+ * (the router's ledger). On a hosted kernel (#158) it reads the state as
110
+ * committed, beside a step that may be running.
111
+ */
112
+ invoke(program: CID | string, fn: string, arg: Uint8Array, o?: {
113
+ caller?: Uint8Array;
114
+ now?: number;
115
+ }): Promise<CallAnswer>;
116
+ /**
117
+ * A synchronous client's wait (#66): the answer of the thread a request
118
+ * entry launched (the middleware stepped on it), once that thread has come
119
+ * to rest for good — finished (`answer`: the middleware's dag-cbor answer)
120
+ * or errored — or, `waitMs` on, its state as it stands (`waiting`; or
121
+ * `pending`: the entry not processed yet). The kernel keeps the bound, so
122
+ * this always settles.
123
+ */
124
+ answer(entry: CID, waitMs: number): Promise<RequestAnswer>;
125
+ idle(): Promise<void>;
126
+ start(): Promise<void>;
127
+ /** #156: a run of headers (parents first) into the host chain this instance reads; its record and tip after. */
128
+ chainHeaders(raws: Uint8Array[]): Promise<HostChainTip>;
129
+ /** #156: an image's chain/headers (the tree `root`, held by this instance) into the empty host chain. */
130
+ chainImport(root: CID): Promise<HostChainTip>;
131
+ /** #156: the host chain as it stands, or undefined (empty). */
132
+ chainTip(): Promise<HostChainTip | undefined>;
133
+ tip(): Promise<CID | undefined>;
134
+ }
135
+ export declare class Kernel extends KernelSurface {
136
+ readonly o: KernelOptions;
137
+ readonly proc: ChildProcess;
138
+ private nextId;
139
+ private waiting;
140
+ private reader;
141
+ private wire?;
142
+ private done;
143
+ constructor(o: KernelOptions);
144
+ get pid(): number | undefined;
145
+ private write;
146
+ call(op: string, v?: unknown): Promise<unknown>;
147
+ private onFrame;
148
+ /** Print the ready line (`skein runtime <identity> (<handle>@<domain>) · pid …`). */
149
+ running(identity: string): Promise<void>;
150
+ /** Close the channel; the kernel stops at EOF. SIGTERM after `killAfterMs`, SIGKILL after twice that. */
151
+ stop(killAfterMs?: number): Promise<void>;
152
+ exited(): Promise<void>;
153
+ }
154
+ export interface KernelHostOptions {
155
+ command?: string;
156
+ /** Environment for the process, added to this one's (SKEIN_WORKERS, SKEIN_HOME…). */
157
+ env?: Record<string, string | undefined>;
158
+ /** The process's own lines (not an instance's). */
159
+ log?(line: string): void;
160
+ }
161
+ /**
162
+ * The host's one `skein-kernel host` process over the RocksDB database at `dir` (#158): every
163
+ * instance of the host in it, each a `HostedKernel`. One per database per node process
164
+ * (`KernelHost.acquire`, counted: the routers and one-shot boots of a process share it; the last
165
+ * `release` stops it). The process is started at acquire; if it dies, every instance's view is
166
+ * gone (their `exited` called) and the next `open` starts it again (the router hydrates on demand,
167
+ * replay at hydrate as for serve).
168
+ */
169
+ export declare class KernelHost {
170
+ private static all;
171
+ /** The process for the database at `dir`, started if this node process has none. */
172
+ static acquire(dir: string, o?: KernelHostOptions): KernelHost;
173
+ /** Whether this node process runs the kernel process for `dir` (stores.ts waits for its socket then). */
174
+ static running(dir: string): boolean;
175
+ readonly dir: string;
176
+ readonly o: KernelHostOptions;
177
+ proc?: ChildProcess;
178
+ private holders;
179
+ private nextId;
180
+ private waiting;
181
+ private views;
182
+ /** A handle's close in flight: its next open waits for it. */
183
+ private closing;
184
+ private done?;
185
+ private dead;
186
+ /** #156: the last `headers` runs asked for (their answers shared). */
187
+ private recent;
188
+ private constructor();
189
+ private ensure;
190
+ private write;
191
+ /** A frame to the process (`h`: an instance's, else a host-level op) and its answer. */
192
+ request(h: string | undefined, op: string, v?: unknown): Promise<unknown>;
193
+ /** A frame that wants no answer. */
194
+ tell(h: string, op: string, v?: unknown): void;
195
+ private onFrame;
196
+ /** Hydrate an instance (#158 `open`): its set opened in the process, its runtime built (replay at hydrate). */
197
+ open(o: KernelOptions): Promise<HostedKernel>;
198
+ /** Dehydrate (#158 `close`): after its inbox drains, its runtime freed. */
199
+ close(v: HostedKernel): Promise<void>;
200
+ /** The instances open in the process (#158 `instances`). */
201
+ instances(): Promise<string[]>;
202
+ /** The host reads (#158): a block by CID — through `set`'s gate if named, else whichever set holds it; a set's committed state pointer. */
203
+ get(cid: CID, set?: string): Promise<Uint8Array | undefined>;
204
+ has(cid: CID, set?: string): Promise<boolean>;
205
+ /** A host read, through `set`'s gate when one is named. */
206
+ private hostRead;
207
+ state(set: string): Promise<CID | undefined>;
208
+ /**
209
+ * #156: a run of headers into the host chain (the frame `headers`, run in order on the process's
210
+ * chain thread). The same run asked for again while it is in flight or just answered (every
211
+ * instance subscribed to one feed asks for the same SSE event) is one frame: its answer shared.
212
+ */
213
+ chainHeaders(raws: Uint8Array[]): Promise<HostChainTip>;
214
+ /** #156: an image's chain/headers (the tree `root`, whose blocks the set `set` holds) into the empty host chain. */
215
+ chainImport(set: string, root: CID): Promise<HostChainTip>;
216
+ /** #156: the host chain as it stands, or undefined (empty). */
217
+ chainTip(): Promise<HostChainTip | undefined>;
218
+ /** One holder less; the last one's release stops the process (every instance closed, the database flushed). */
219
+ release(): Promise<void>;
220
+ /** `stop`: the process finishes what runs, closes every instance and the database, exits. */
221
+ shutdown(killAfterMs?: number): Promise<void>;
222
+ /** Until the process has exited. */
223
+ exited(): Promise<void>;
224
+ }
225
+ /** One instance of the host's one kernel process (#158): the `Kernel` surface over frames tagged `h`. */
226
+ export declare class HostedKernel extends KernelSurface {
227
+ readonly o: KernelOptions;
228
+ readonly host: KernelHost;
229
+ private wire?;
230
+ private resolveDone;
231
+ private done;
232
+ constructor(host: KernelHost, o: KernelOptions);
233
+ get pid(): number | undefined;
234
+ call(op: string, v?: unknown): Promise<unknown>;
235
+ onKernelFrame(f: Frame, answer: (ok: unknown) => void, fail: (e: unknown) => void): Promise<void>;
236
+ running(identity: string): Promise<void>;
237
+ /** #156: the host chain is the process's, not the instance's: its host-level frames. */
238
+ chainHeaders(raws: Uint8Array[]): Promise<HostChainTip>;
239
+ chainImport(root: CID): Promise<HostChainTip>;
240
+ chainTip(): Promise<HostChainTip | undefined>;
241
+ /** Close the instance in the process (its inbox drained first); the process keeps running. */
242
+ stop(): Promise<void>;
243
+ /** Gone: closed, or the process exited (code/signal), or its open failed (`quiet`: no exited). */
244
+ lost(code: number | null, signal: string | null, quiet?: boolean): void;
245
+ exited(): Promise<void>;
246
+ }