@dcasegr/skein 0.0.0-stage → 0.1.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.
Files changed (176) hide show
  1. package/README.md +522 -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 +773 -0
  89. package/dist/host/router.js +2389 -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,238 @@
1
+ import { type PrivateKey } from "@bsv/sdk";
2
+ import type { CID } from "multiformats/cid";
3
+ /** The signing a provider's answer and an intention's request get (BRC-169 §7.2, on skein's mail record); an emit is unsigned (#126 step 4). */
4
+ export declare const MESSAGE_PROTOCOL: [2, string];
5
+ export declare const MESSAGE_KEY_ID = "send";
6
+ /** The stream protocol a signed message travels on to a libp2p recipient. */
7
+ export declare const MESSAGE_STREAM = "/skein/message/1.0.0";
8
+ /** A message as the kernel keeps it: an emit's unsigned, a provider's answer and an intention's request signed. */
9
+ export interface MailRecord {
10
+ kind: "mail";
11
+ op: "put";
12
+ sender: Uint8Array;
13
+ recipient: Uint8Array;
14
+ box: string;
15
+ body: CID;
16
+ subject?: CID;
17
+ nonce?: Uint8Array;
18
+ signature?: Uint8Array;
19
+ [k: string]: unknown;
20
+ }
21
+ /** What the kernel hands over (the serve frame `emit`). */
22
+ export interface Outgoing {
23
+ message: MailRecord;
24
+ body: Uint8Array;
25
+ transport: string;
26
+ address: string;
27
+ /** #148: an event's place in the log, beside the record (the kernel's notice): the entry its step processed, the update's seq, the index in `emitted`, the thread. */
28
+ place?: {
29
+ n: number | bigint;
30
+ seq: number | bigint;
31
+ i: number | bigint;
32
+ thread: CID;
33
+ };
34
+ }
35
+ /** The stock providers' names (each one's address on this host: `local`, <name>). */
36
+ export declare const PROVIDERS: readonly ["fetch", "waker", "cron", "libp2p", "status", "manager", "certifier", "billing"];
37
+ /** The providers only the host skein's address book names (#90, #113): they act for it alone. */
38
+ export declare const HOST_SKEIN_PROVIDERS: readonly ProviderName[];
39
+ /** Keys no address book names (#130: the host's billing key signs its ticks; it is not reached). */
40
+ export declare const UNADDRESSED: readonly ProviderName[];
41
+ export type ProviderName = typeof PROVIDERS[number];
42
+ /** The intentions a step records and the runtime answers (#126). */
43
+ export type Intention = "fetch" | "deadline";
44
+ export type HttpRequest = {
45
+ method: string;
46
+ url: string;
47
+ headers?: Record<string, string>;
48
+ body?: Uint8Array;
49
+ timeoutMs?: number;
50
+ maxBytes?: number;
51
+ };
52
+ export type HttpResponse = {
53
+ status: number;
54
+ headers: Record<string, string>;
55
+ body: Uint8Array;
56
+ };
57
+ export interface ProvidersOptions {
58
+ /** A provider's key (the reference host: a child of its master secret). */
59
+ keyOf(name: ProviderName): PrivateKey;
60
+ /** The instance `handle`'s identity key (33 bytes), or undefined when it is not known. */
61
+ identity(handle: string): Promise<Uint8Array | undefined>;
62
+ /** Append a message (its package: a provider's signed answer, or the loopback's own emit) into `handle` as a `local` request. */
63
+ append(handle: string, pkg: {
64
+ kind: "message";
65
+ message: MailRecord;
66
+ body: Uint8Array;
67
+ }): Promise<unknown>;
68
+ /**
69
+ * Sign `data` with the instance `handle`'s own key, BRC-169's way ([2, "metanet handles
70
+ * envelope"], key "send", counterparty anyone) → the DER signature (#126: the request the
71
+ * runtime sends for an intention a step recorded is the instance's, signed by its wallet).
72
+ */
73
+ sign(handle: string, data: Uint8Array): Promise<Uint8Array>;
74
+ /**
75
+ * Where this host sends an intention (#126) — host wiring, not an instance setting nor an
76
+ * address-book role: the service by name (`fetch`: the HTTP proxy; `deadline`: the waker), on
77
+ * this host (`local`, the only transport wired so far). Default: this host's own providers.
78
+ */
79
+ route?: Partial<Record<Intention, {
80
+ transport: "local";
81
+ address: ProviderName;
82
+ }>>;
83
+ /** The HTTP proxy's network: one request, this host's own URLs in process. */
84
+ fetch(req: HttpRequest, from: string): Promise<HttpResponse>;
85
+ /** The broadcaster (#58, #65: the host's Arcade), when the host has one: a broadcast event's transaction and BEEF, queued. */
86
+ broadcast?(handle: string, tx: Uint8Array, beef?: Uint8Array): void;
87
+ /** The libp2p node's subscriptions (#119), beacons (#126) and liveness (#138): a `subscribe` / `unsubscribe` / `beacon` / `unbeacon` / `liveness` / `unliveness` record {kind: "event", event, app, topic, …} from `handle`. Absent: no libp2p node (dropped). */
88
+ topicEvent?(handle: string, record: Record<string, unknown>): void;
89
+ /** #148: every event record {kind: "event", event, …} from `handle`, whatever its name, as it is handed over (after its step's commit), with its place in the log — sent on to the event streams (events.ts). Besides what its name is wired to. */
90
+ emitted?(handle: string, record: Record<string, unknown>, place: {
91
+ n: number;
92
+ seq: number;
93
+ i: number;
94
+ thread: CID;
95
+ }): void;
96
+ /** The cron provider's schedule (#69, cron.ts): a request from `handle` (key `sender`), the message `id` → the answer body. Absent: no cron provider. */
97
+ cron?(handle: string, sender: string, id: string, body: unknown): Record<string, unknown>;
98
+ /**
99
+ * The instance manager (#90, Router): `from()` names the host skein (its
100
+ * handle and identity, hex) — the one sender it acts for (none: it acts for
101
+ * nobody); `request` does a create, start or stop → the answer body.
102
+ */
103
+ manager?: {
104
+ from(): {
105
+ handle: string;
106
+ identity: string;
107
+ } | undefined;
108
+ /** #162 (SKEIN_MANAGER_FOR): the other instances the instance manager acts for (not the certifier), each its handle and identity (hex). */
109
+ alsoFor?(): Array<{
110
+ handle: string;
111
+ identity: string;
112
+ }>;
113
+ request(box: string, body: Record<string, unknown>): Promise<Record<string, unknown>>;
114
+ };
115
+ /** The certifier (#113): an issue request from the host skein → the answer body (handles.ts). Absent: none. */
116
+ certifier?(box: string, body: Record<string, unknown>): Promise<Record<string, unknown>>;
117
+ /**
118
+ * #164: an application host's wiring — an event record {kind: "event", event, app?, …} from `handle`
119
+ * whose name no stock wiring takes (not broadcast, an intention, payment, nor the libp2p node's),
120
+ * handed over after its step's commit as `topicEvent`'s are. Absent: logged as ignored.
121
+ */
122
+ appEvent?(handle: string, record: Record<string, unknown>): void;
123
+ /**
124
+ * #157: a `deliver` event from `handle` (its CID and record): the host carries it (deliver.ts) and
125
+ * admits the answer → whether an answer was admitted. Handed over again at the instance's next
126
+ * start while the thread awaits it: carried again then only if no answer came. Absent: ignored.
127
+ */
128
+ deliver?(handle: string, event: CID, record: Record<string, unknown>): Promise<boolean>;
129
+ /** #130: a `payment` event from `handle` — its pay step's (the kernel lets no other step emit one). Absent: no billing (ignored). */
130
+ payment?(handle: string, record: Record<string, unknown>): void;
131
+ /** The libp2p host, when there is one: the instance's node does the work. */
132
+ p2p?: {
133
+ publish(handle: string, topic: string, body: Uint8Array): Promise<{
134
+ seqno: Uint8Array;
135
+ recipients: number;
136
+ }>;
137
+ dial(handle: string, peer: string, protocol: string, frames: (f: {
138
+ body: Uint8Array;
139
+ } | {
140
+ closed: true;
141
+ error?: string;
142
+ }) => void): Promise<number>;
143
+ send(handle: string, stream: number, body: Uint8Array): Promise<void>;
144
+ close(handle: string, stream: number): Promise<void>;
145
+ };
146
+ /** The clock (ms), as entries are stamped. */
147
+ now(): number;
148
+ log?(source: string, line: string): void;
149
+ }
150
+ /** The fetch provider's refusal of a response over the request's `maxBytes` (#91). */
151
+ export declare const tooLarge: (max: number) => string;
152
+ export declare class Providers {
153
+ readonly o: ProvidersOptions;
154
+ private wallets;
155
+ private keys;
156
+ /** Messages taken (handle + CID), so a message handed over again (a kernel's start) is acted on once. */
157
+ private taken;
158
+ /** The waker's timers, by handle + the wake-me's CID. */
159
+ private timers;
160
+ /** Messages being carried now, and the waker's answers being appended. */
161
+ private inflight;
162
+ private stopped;
163
+ constructor(o: ProvidersOptions);
164
+ private say;
165
+ /** A provider's identity key (hex). */
166
+ key(name: ProviderName): string;
167
+ private wallet;
168
+ /** The address book entries a genesis seeds for this host's providers: key, transport `local`, address the name (#126: no role). */
169
+ entries(names?: readonly ProviderName[]): Array<{
170
+ key: Uint8Array;
171
+ transport: "local";
172
+ address: string;
173
+ }>;
174
+ /** Stop the timers; nothing more is carried. */
175
+ stop(): void;
176
+ /** A message (or an event, #65) from `handle` to carry out (the kernel's `emit` notice). */
177
+ deliver(handle: string, out: Outgoing): void;
178
+ private track;
179
+ /** Whether anything is being carried now (a waker's timer is not: it is waiting). */
180
+ busy(): boolean;
181
+ /** Until what is being carried now is done (tests, the corpus: Router.settled). */
182
+ idle(): Promise<void>;
183
+ /**
184
+ * An event out (#65, #119): addressed to no one, acted on by its name —
185
+ * `broadcast` → the broadcaster (Arcade); `subscribe` / `unsubscribe` → the
186
+ * libp2p node (the topics it subscribes: p2p.ts; delivery is the kernel's, by the subscription); any other name: the application host's `appEvent` when it has one (#164), else a log
187
+ * line, nothing else (the step is not told). A broadcast is acted on every
188
+ * time it is handed over (a kernel's start hands over again what a waiting
189
+ * thread awaits: the queue takes a transaction once); any other event is
190
+ * handed over once.
191
+ */
192
+ private event;
193
+ private carry;
194
+ /** A signed message from provider `name` to the instance that sent `to`, in `to`'s box: {replyTo, …answer}, appended. */
195
+ answer(handle: string, name: ProviderName, to: MailRecord, id: CID, answer: Record<string, unknown>, box?: string): Promise<void>;
196
+ /**
197
+ * A signed message from provider `name` to `recipient` (the instance
198
+ * `handle`), in `box`, its body `body` — an answer, a tick (#69), a status
199
+ * (#65) — appended there as a `local` request (what the append answers:
200
+ * the entry). Its own message (two like bodies are two messages:
201
+ * `nonce`), about `subject` if given.
202
+ */
203
+ send(handle: string, name: ProviderName, recipient: Uint8Array, box: string, body: Record<string, unknown>, subject?: CID): Promise<unknown>;
204
+ /** A message to the fetch provider (a module on an SDK before #126: fetch was a message to it). */
205
+ private fetch;
206
+ /** The HTTP proxy (#70, #126): one request {method, url, headers?, body?, timeoutMs?, maxBytes?} → {status, headers, body} | {error}. */
207
+ private proxy;
208
+ /**
209
+ * An intention a step recorded (#126: a `deadline`, a `fetch` event), handed
210
+ * over once its step is committed: the request is the instance's, signed by
211
+ * its wallet — the mail record {kind: "mail", op: "put", sender: <the
212
+ * instance>, recipient: <the service's key>, box, body: <the event's CID>,
213
+ * nonce, signature} — sent where this host is wired (`route`: its own waker
214
+ * or HTTP proxy, `local`). The service's answer is a signed message from its
215
+ * key whose body names the event (`replyTo`) and carries that request
216
+ * (`request`), appended as a `local` request: the front door checks its
217
+ * signature, the kernel the request's (scheduler.zig intentionAnswer), and
218
+ * the thread awaiting the event steps — `woke` at a deadline, `reply` with a
219
+ * fetch's response ({status, headers, body} | {error}).
220
+ */
221
+ private intention;
222
+ /** Run `fire` at `at` (by the clock `now`), once per (handle, id). */
223
+ private timer;
224
+ /** A wake-me message (a kernel before #126: a deadline was a message to the waker), kept for such a log's waiting threads. */
225
+ private wake;
226
+ /**
227
+ * Answer now every wake-me that is due by the clock (`now`): what the
228
+ * timers do in real time, for a clock that is not (a script clock: tests,
229
+ * the corpus). The answers are being appended when it returns (idle()).
230
+ */
231
+ wakeDue(): void;
232
+ /** The earliest wake the waker owes `handle` (ms), if any (the host page). */
233
+ nextWake(handle: string): number | undefined;
234
+ private p2p;
235
+ /** A message to a libp2p recipient: its package published on the topic, or written to the peer on MESSAGE_STREAM. */
236
+ private libp2pRecipient;
237
+ private cron;
238
+ }