@dmarket/p2p-tracker-headless 0.0.0-bootstrap.0

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 (102) hide show
  1. package/Kotlin-DateTime-library-kotlinx-datetime.mjs +4 -0
  2. package/Kotlin-DateTime-library-kotlinx-datetime.mjs.map +1 -0
  3. package/VERSION +14 -0
  4. package/dmarket-p2p-tracker-core-domain.mjs +16699 -0
  5. package/dmarket-p2p-tracker-core-domain.mjs.map +1 -0
  6. package/index.d.ts +195 -0
  7. package/kotlin-kotlin-stdlib.mjs +18834 -0
  8. package/kotlin-kotlin-stdlib.mjs.map +1 -0
  9. package/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs +4 -0
  10. package/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs.map +1 -0
  11. package/kotlinx-atomicfu.mjs +251 -0
  12. package/kotlinx-atomicfu.mjs.map +1 -0
  13. package/kotlinx-browser.mjs +8 -0
  14. package/kotlinx-browser.mjs.map +1 -0
  15. package/kotlinx-coroutines-core.mjs +12437 -0
  16. package/kotlinx-coroutines-core.mjs.map +1 -0
  17. package/kotlinx-io-kotlinx-io-bytestring.mjs +202 -0
  18. package/kotlinx-io-kotlinx-io-bytestring.mjs.map +1 -0
  19. package/kotlinx-io-kotlinx-io-core.mjs +2034 -0
  20. package/kotlinx-io-kotlinx-io-core.mjs.map +1 -0
  21. package/kotlinx-serialization-kotlinx-serialization-core.mjs +6163 -0
  22. package/kotlinx-serialization-kotlinx-serialization-core.mjs.map +1 -0
  23. package/kotlinx-serialization-kotlinx-serialization-json-io.mjs +4 -0
  24. package/kotlinx-serialization-kotlinx-serialization-json-io.mjs.map +1 -0
  25. package/kotlinx-serialization-kotlinx-serialization-json.mjs +5957 -0
  26. package/kotlinx-serialization-kotlinx-serialization-json.mjs.map +1 -0
  27. package/ktor-ktor-client-content-negotiation.mjs +4 -0
  28. package/ktor-ktor-client-content-negotiation.mjs.map +1 -0
  29. package/ktor-ktor-client-core.mjs +9986 -0
  30. package/ktor-ktor-client-core.mjs.map +1 -0
  31. package/ktor-ktor-events.mjs +82 -0
  32. package/ktor-ktor-events.mjs.map +1 -0
  33. package/ktor-ktor-http-cio.mjs +2253 -0
  34. package/ktor-ktor-http-cio.mjs.map +1 -0
  35. package/ktor-ktor-http.mjs +3261 -0
  36. package/ktor-ktor-http.mjs.map +1 -0
  37. package/ktor-ktor-io.mjs +3546 -0
  38. package/ktor-ktor-io.mjs.map +1 -0
  39. package/ktor-ktor-openapi-schema.mjs +4 -0
  40. package/ktor-ktor-openapi-schema.mjs.map +1 -0
  41. package/ktor-ktor-serialization-kotlinx-json.mjs +4 -0
  42. package/ktor-ktor-serialization-kotlinx-json.mjs.map +1 -0
  43. package/ktor-ktor-serialization-kotlinx.mjs +4 -0
  44. package/ktor-ktor-serialization-kotlinx.mjs.map +1 -0
  45. package/ktor-ktor-serialization.mjs +4 -0
  46. package/ktor-ktor-serialization.mjs.map +1 -0
  47. package/ktor-ktor-sse.mjs +4 -0
  48. package/ktor-ktor-sse.mjs.map +1 -0
  49. package/ktor-ktor-utils.mjs +3427 -0
  50. package/ktor-ktor-utils.mjs.map +1 -0
  51. package/ktor-ktor-websocket-serialization.mjs +4 -0
  52. package/ktor-ktor-websocket-serialization.mjs.map +1 -0
  53. package/ktor-ktor-websockets.mjs +2589 -0
  54. package/ktor-ktor-websockets.mjs.map +1 -0
  55. package/p2p-tracker-core.mjs +41977 -0
  56. package/p2p-tracker-core.mjs.map +1 -0
  57. package/p2p-tracker-headless.mjs +4939 -0
  58. package/p2p-tracker-headless.mjs.map +1 -0
  59. package/package.json +58 -0
  60. package/pkg/README.md +104 -0
  61. package/pkg/client_wasm.d.ts +316 -0
  62. package/pkg/client_wasm.js +1199 -0
  63. package/pkg/client_wasm_bg.wasm +0 -0
  64. package/pkg/client_wasm_bg.wasm.d.ts +32 -0
  65. package/pkg/package.json +19 -0
  66. package/pkg/snippets/web-spawn-05868593a72e2d44/js/spawn.js +73 -0
  67. package/pkg/spawn.js +73 -0
  68. package/prover-child.mjs +2 -0
  69. package/transport/README.md +240 -0
  70. package/transport/dist/channel.d.ts +48 -0
  71. package/transport/dist/channel.d.ts.map +1 -0
  72. package/transport/dist/channel.js +150 -0
  73. package/transport/dist/channel.js.map +1 -0
  74. package/transport/dist/index.d.ts +10 -0
  75. package/transport/dist/index.d.ts.map +1 -0
  76. package/transport/dist/index.js +19 -0
  77. package/transport/dist/index.js.map +1 -0
  78. package/transport/dist/node.d.ts +4 -0
  79. package/transport/dist/node.d.ts.map +1 -0
  80. package/transport/dist/node.js +62 -0
  81. package/transport/dist/node.js.map +1 -0
  82. package/transport/dist/prover.d.ts +105 -0
  83. package/transport/dist/prover.d.ts.map +1 -0
  84. package/transport/dist/prover.js +139 -0
  85. package/transport/dist/prover.js.map +1 -0
  86. package/transport/dist/tcp.d.ts +38 -0
  87. package/transport/dist/tcp.d.ts.map +1 -0
  88. package/transport/dist/tcp.js +88 -0
  89. package/transport/dist/tcp.js.map +1 -0
  90. package/transport/dist/transport.d.ts +31 -0
  91. package/transport/dist/transport.d.ts.map +1 -0
  92. package/transport/dist/transport.js +75 -0
  93. package/transport/dist/transport.js.map +1 -0
  94. package/transport/dist/types.d.ts +162 -0
  95. package/transport/dist/types.d.ts.map +1 -0
  96. package/transport/dist/types.js +21 -0
  97. package/transport/dist/types.js.map +1 -0
  98. package/transport/dist/wasm-compat.d.ts +2 -0
  99. package/transport/dist/wasm-compat.d.ts.map +1 -0
  100. package/transport/dist/wasm-compat.js +15 -0
  101. package/transport/dist/wasm-compat.js.map +1 -0
  102. package/transport/package.json +34 -0
package/index.d.ts ADDED
@@ -0,0 +1,195 @@
1
+ // Types of @dmarket/p2p-tracker-headless.
2
+ //
3
+ // Written by hand: the declarations the compiler generates cannot say what the functions return (a union keyed by
4
+ // `type`, a record of deadlines, `string | null`), and they declare the web extension's exports too, which this
5
+ // package's entry does not have. A change to what a function returns changes this file in the same commit.
6
+ //
7
+ // Times are epoch milliseconds, durations milliseconds, ids strings. A field the library has no value for is
8
+ // `null`, never missing.
9
+
10
+ declare const trackerHandle: unique symbol;
11
+
12
+ /**
13
+ * Identifies one tracker. An empty frozen object with no prototype: it carries nothing, and the tracker it stands
14
+ * for stays inside the library.
15
+ */
16
+ export interface TrackerHandle {
17
+ readonly [trackerHandle]: never;
18
+ }
19
+
20
+ /** The `prover` option: with it the tracker proves, each proof in a prover process of its own. */
21
+ export interface ProverOptions {
22
+ /** The notary proofs go to, and the one each upgrade is signed for; the tracker's `notaryUrl` when unset. */
23
+ notaryUrl?: string;
24
+ /** Proofs at once, 1 or 2 (1 by default); each holds a process of up to ~700 MB. */
25
+ maxConcurrency?: number;
26
+ /** Proofs one prover process serves before it is ended, 1 to 5 (1 by default). */
27
+ proofsPerChild?: number;
28
+ /** The prover's MPC threads per process, 1 to 16 (4 by default). */
29
+ threadCount?: number;
30
+ /** Where the prover's `pkg/` and `transport/` are; this package's directory by default. */
31
+ assetsDir?: string;
32
+ /** From a proof's start to its process asking for the upgrade headers; 30 000 by default. */
33
+ connectDeadlineMs?: number;
34
+ /** From that ask to the proof's answer; 240 000 by default. */
35
+ sessionDeadlineMs?: number;
36
+ }
37
+
38
+ /** Where a line given to `onProverLine` comes from: a prover process's output, or the host's own line about one. */
39
+ export type ProverLineStream = "stdout" | "stderr" | "host";
40
+
41
+ export interface HeadlessTrackerOptions {
42
+ /** Where each Steam account's loop state is kept. The pushed secrets are never written there, or anywhere. */
43
+ dataDir: string;
44
+ /** The DMarket gateway; `defaultBaseUrl()` by default. */
45
+ baseUrl?: string;
46
+ /** `false` for an account that only buys: no Steam offer is created or cancelled. `true` by default. */
47
+ steamWrites?: boolean;
48
+ /** The notary proofs go to; `defaultNotaryUrl()` by default. */
49
+ notaryUrl?: string;
50
+ /** Without it the tracker makes no proof. */
51
+ prover?: ProverOptions;
52
+ /** Each of the loop's events, as a JSON string with no secret in it. */
53
+ onEvent?: (json: string) => void;
54
+ /** How each proof ended, before the loop's event about it. */
55
+ onProofOutcome?: (outcome: ProofOutcome) => void;
56
+ /** Each line of a prover process's output, and each of the host's lines about them (a JSON object), redacted. */
57
+ onProverLine?: (stream: ProverLineStream, line: string) => void;
58
+ /** The clock, in epoch milliseconds; the system clock by default. */
59
+ nowMs?: () => number;
60
+ }
61
+
62
+ /** What became of a pushed key compared with the one held before it. */
63
+ export type KeyChange = "FIRST" | "SAME" | "ROTATED" | "REPLACED";
64
+
65
+ /** A Trading API key push's result. No case carries the secret key. */
66
+ export type TradingApiKeyPushResult =
67
+ | { readonly type: "held"; readonly publicKey: string; readonly change: KeyChange }
68
+ | { readonly type: "invalid"; readonly reason: string }
69
+ | {
70
+ readonly type: "accountChanged";
71
+ readonly publicKey: string;
72
+ readonly heldPublicKey: string;
73
+ readonly linkedSteamId: string;
74
+ readonly keyLinkedSteamId: string | null;
75
+ }
76
+ | { readonly type: "unverified"; readonly publicKey: string; readonly reason: string };
77
+
78
+ /** A Steam token push's result. No case carries the token. */
79
+ export type SteamTokenPushResult =
80
+ | { readonly type: "held"; readonly steamId: string; readonly expiresAtMs: number }
81
+ | { readonly type: "wrongAccount"; readonly tokenSteamId: string; readonly linkedSteamId: string | null }
82
+ | { readonly type: "invalid"; readonly reason: string };
83
+
84
+ /** What the tracker holds right now, without either secret. */
85
+ export interface TrackerState {
86
+ readonly hasTradingApiKey: boolean;
87
+ readonly steamTokenSteamId: string | null;
88
+ readonly steamTokenExpiresAtMs: number | null;
89
+ readonly linkedSteamId: string | null;
90
+ readonly readySinceMs: number | null;
91
+ readonly trackedDealIds: readonly string[];
92
+ readonly clockOffsetMs: number | null;
93
+ readonly clockSkewed: boolean;
94
+ readonly steamNotLinked: boolean;
95
+ readonly updateRequired: boolean;
96
+ readonly updateDueTimeMs: number | null;
97
+ /** Each tracked deal's deadline, by deal id. */
98
+ readonly dealDeadlines: Readonly<Record<string, number>>;
99
+ }
100
+
101
+ /** Why a prover process ended before its proof did. */
102
+ export type KillCause = "out_of_memory" | "connect_deadline" | "session_deadline" | "exited";
103
+
104
+ /** Why a proof produced nothing. Every text in it, `summary` included, is redacted. */
105
+ export type ProofFailure =
106
+ | { readonly type: "upgrade_refused"; readonly status: number; readonly summary: string }
107
+ | { readonly type: "session_closed"; readonly code: number; readonly reason: string | null; readonly summary: string }
108
+ | { readonly type: "notary_unreachable"; readonly detail: string; readonly summary: string }
109
+ | { readonly type: "version_mismatch"; readonly detail: string; readonly summary: string }
110
+ | { readonly type: "steam_failed"; readonly status: number | null; readonly detail: string; readonly summary: string }
111
+ | { readonly type: "limits_exceeded"; readonly detail: string; readonly summary: string }
112
+ | { readonly type: "prover_killed"; readonly cause: KillCause; readonly detail: string | null; readonly summary: string }
113
+ | { readonly type: "not_started"; readonly reason: string; readonly summary: string }
114
+ | { readonly type: "other"; readonly detail: string; readonly summary: string };
115
+
116
+ /** How a proof ended: `failure` is `null` for a proof made. */
117
+ export interface ProofOutcome {
118
+ readonly dealId: string;
119
+ readonly failure: ProofFailure | null;
120
+ }
121
+
122
+ /**
123
+ * Builds a tracker for one process and one Steam account. Nothing runs until `start`. Throws on an unknown option
124
+ * or a value of the wrong type, naming the option and never the value; with `prover`, throws "prover files not
125
+ * found" when the child script or the prover's files are missing.
126
+ */
127
+ export declare function createHeadlessTracker(options: HeadlessTrackerOptions): TrackerHandle;
128
+
129
+ /** Starts the driver: a cycle now, then one per wake the loop asks for. A second call does nothing. */
130
+ export declare function start(handle: TrackerHandle): void;
131
+
132
+ /** Runs one cycle now, behind the cycle in flight. */
133
+ export declare function cycle(handle: TrackerHandle): Promise<void>;
134
+
135
+ /** Stops the tracker and kills every prover process at once. Every later call with the handle is refused. */
136
+ export declare function stop(handle: TrackerHandle): Promise<void>;
137
+
138
+ /** Pushes the DMarket Trading API key pair (hex). */
139
+ export declare function pushTradingApiKey(
140
+ handle: TrackerHandle,
141
+ publicKey: string,
142
+ secretKey: string,
143
+ ): Promise<TradingApiKeyPushResult>;
144
+
145
+ /** Pushes a Steam access token. */
146
+ export declare function pushSteamToken(handle: TrackerHandle, accessToken: string): Promise<SteamTokenPushResult>;
147
+
148
+ /** What the tracker holds right now. */
149
+ export declare function trackerState(handle: TrackerHandle): TrackerState;
150
+
151
+ /** The `reason` texts of the events that say why a write or a proof did not run. The same frozen object each call. */
152
+ export declare function reasons(): Readonly<{
153
+ offerWritesDisabled: "refused: offer writes are disabled on this client";
154
+ steamSessionMissing: "not run: no usable Steam session on this client";
155
+ tokenExpiringDefer: "the Steam token expires before a create could be confirmed";
156
+ proofTokenExpiring: "the Steam token is too close to its expiry to start a proof";
157
+ noProver: "no notary prover is configured on this host";
158
+ }>;
159
+
160
+ /** The `kind` of a failed-cancel check, by name. The same frozen object each call. */
161
+ export declare function failedCancelKinds(): Readonly<{
162
+ alreadyInactive: "already_inactive";
163
+ alreadyTraded: "already_traded";
164
+ stillOpen: "still_open";
165
+ unread: "unread";
166
+ }>;
167
+
168
+ /** The `kind` of a directive, by name. The same frozen object each call. */
169
+ export declare function directiveActions(): Readonly<{
170
+ createOffer: "create_offer";
171
+ cancelOffer: "cancel_offer";
172
+ reportInventory: "report_inventory";
173
+ unknown: "unknown";
174
+ }>;
175
+
176
+ /** The gateway's error code for a heartbeat refused because the DMarket account links no Steam account. */
177
+ export declare function steamNotLinkedCode(): "P2P_STEAM_NOT_LINKED";
178
+
179
+ /** Under this much token life no create or proof starts. */
180
+ export declare function minWriteTokenLifetimeMs(): number;
181
+
182
+ /** How far this host's clock may be off DMarket's before `clockSkewed` is set. */
183
+ export declare function maxClockSkewMs(): number;
184
+
185
+ /** The production notary: `notaryUrl`'s default. */
186
+ export declare function defaultNotaryUrl(): string;
187
+
188
+ /** The production DMarket gateway: `baseUrl`'s default. */
189
+ export declare function defaultBaseUrl(): string;
190
+
191
+ /** The version of the library inside this package: the one the tracker reports on every heartbeat. */
192
+ export declare function headlessVersion(): string;
193
+
194
+ /** The entry of a prover process; the package's `prover-child.mjs` calls it. A host never does. */
195
+ export declare function runProverChild(): void;