@toon-protocol/townhouse 0.1.0-rc5

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/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 TOON Protocol Contributors
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,386 @@
1
+ # @toon-protocol/townhouse
2
+
3
+ Host-native orchestrator and dashboard for Docker-containerized TOON nodes (Town, Mill, DVM) behind a shared standalone connector.
4
+
5
+ ## Local Dev Loop (Townhouse Dev Stack)
6
+
7
+ Stories 21.9–21.13 (dashboard views) and 21.8.5 (design system) **must** be developed against the Townhouse dev stack, not against mocks or the SDK E2E topology (D21-009).
8
+
9
+ ### One-command boot
10
+
11
+ ```bash
12
+ ./scripts/townhouse-dev-infra.sh up
13
+ ```
14
+
15
+ This command:
16
+ 1. Builds `toon:town`, `toon:mill`, `toon:dvm` Docker images (Docker layer cache applies on subsequent runs)
17
+ 2. Starts Anvil (EVM), Solana test-validator, and Mina lightnet chain devnets
18
+ 3. Deploys Mock USDC to Anvil and the Solana payment-channel program
19
+ 4. Starts the standalone connector with all 5 child peers registered
20
+ 5. Starts 5 child nodes with deterministic Nostr keys
21
+ 6. Polls each child's `/health` endpoint until ready (60 s timeout per node)
22
+ 7. Prints a success banner listing every endpoint URL
23
+ 8. Writes `.env.townhouse-dev` at the workspace root
24
+
25
+ **First run** (no cached images): ~5 minutes (dominated by image pulls).
26
+ **Subsequent runs**: ~90 seconds (cached images, warm Docker daemon).
27
+
28
+ ### Endpoint banner
29
+
30
+ On success, the script prints every endpoint grouped by category. Copy these URLs into your browser or `curl` to verify the stack manually:
31
+
32
+ ```
33
+ Connector http://127.0.0.1:28080
34
+ town-01 relay ws://127.0.0.1:28700
35
+ town-01 health http://127.0.0.1:28100
36
+ town-02 relay ws://127.0.0.1:28710
37
+ town-02 health http://127.0.0.1:28110
38
+ mill-01 health http://127.0.0.1:28200 (EVM↔Solana)
39
+ mill-02 health http://127.0.0.1:28210 (EVM↔Mina)
40
+ dvm-01 health http://127.0.0.1:28400
41
+ Anvil RPC http://127.0.0.1:28545
42
+ Solana RPC http://127.0.0.1:28899
43
+ Mina GraphQL http://127.0.0.1:28085
44
+ Mina Accounts http://127.0.0.1:28181
45
+ SOCKS5 socks5://127.0.0.1:28050
46
+ ```
47
+
48
+ ### Host-Fastify integration via `.env.townhouse-dev`
49
+
50
+ The script writes `.env.townhouse-dev` at the workspace root. Story 21.8.5 wires a `pnpm dev:docker` script in `packages/townhouse-web` that sources this file at startup so the host-side Fastify API knows the connector admin URL and child node addresses without any manual configuration.
51
+
52
+ The contract (env var names the Fastify API reads):
53
+ - `TOWNHOUSE_CONNECTOR_ADMIN_URL` — connector admin base URL
54
+ - `TOWNHOUSE_DEV_TOWN_01_RELAY`, `TOWNHOUSE_DEV_TOWN_02_RELAY` — relay WebSocket URLs
55
+ - `TOWNHOUSE_DEV_TOWN_0{1,2}_HEALTH`, `TOWNHOUSE_DEV_MILL_0{1,2}_HEALTH`, `TOWNHOUSE_DEV_DVM_01_HEALTH` — BLS health URLs
56
+ - `TOWNHOUSE_DEV_ANVIL_RPC`, `TOWNHOUSE_DEV_SOLANA_RPC`, `TOWNHOUSE_DEV_MINA_GRAPHQL` — chain RPC URLs
57
+ - `SOLANA_PROGRAM_ID`, `MINA_ZKAPP_ADDRESS`, `TOON_USDC_ADDRESS` — deployed contract addresses
58
+ - `TOWNHOUSE_DEV_WALLET_MNEMONIC` — **DEV ONLY** BIP-39 test-vector-zero mnemonic (`abandon … about`); read by `api-server.mjs` to auto-initialize the `WalletManager` without running `townhouse init`. This is the publicly known test vector — NEVER use in production. The dev API loop **rejects any other value** at startup so a developer who pastes a real mnemonic by accident gets a loud error rather than silent address derivation.
59
+
60
+ When the dev mnemonic is loaded, the API loop also writes `~/.townhouse/wallet.enc` (if absent) encrypted with the documented dev password `townhouse-dev`. This makes `POST /wallet/reveal` exercisable against the live dev stack — open the wallet view, click "Reveal seed phrase", enter `townhouse-dev`, see the 12-word mnemonic. The on-disk file is never overwritten if it already exists, so an operator who later runs the production `townhouse init` flow keeps their real wallet.
61
+
62
+ `.env.townhouse-dev` is git-ignored. Never commit it.
63
+
64
+ ### TURBO_TOKEN
65
+
66
+ `TURBO_TOKEN` is used by the DVM container for Arweave uploads via Turbo. It is passed through from the host environment.
67
+
68
+ - **Working on Town/Mill views (21.9–21.11):** No `TURBO_TOKEN` needed. The DVM starts in disabled-upload mode and its health endpoint still responds 200.
69
+ - **Working on DVM views (21.12) or upload flows:** Set `TURBO_TOKEN` in your shell before running `up`.
70
+
71
+ The script logs a warning (not an error) when `TURBO_TOKEN` is unset, then continues.
72
+
73
+ ### Teardown
74
+
75
+ ```bash
76
+ ./scripts/townhouse-dev-infra.sh down # Stop containers + remove .env.townhouse-dev
77
+ ./scripts/townhouse-dev-infra.sh down-v # Same + delete named volumes (fresh state next run)
78
+ ./scripts/townhouse-dev-infra.sh status # Show container state + health summary
79
+ ```
80
+
81
+ Use `down-v` when you want a completely fresh channel/data state on the next `up`.
82
+
83
+ ### Port allocation
84
+
85
+ All ports are `127.0.0.1` only (never `0.0.0.0`). Full table also in `CLAUDE.md` "Townhouse Dev Stack (28xxx)".
86
+
87
+ | Host Port | Service |
88
+ |-----------|---------|
89
+ | 28080 | Connector admin |
90
+ | 28050 | SOCKS5 proxy |
91
+ | 28100 | town-01 BLS health |
92
+ | 28110 | town-02 BLS health |
93
+ | 28200 | mill-01 BLS health (EVM↔Solana) |
94
+ | 28210 | mill-02 BLS health (EVM↔Mina) |
95
+ | 28400 | dvm-01 BLS health |
96
+ | 28700 | town-01 relay WebSocket |
97
+ | 28710 | town-02 relay WebSocket |
98
+ | 28545 | Anvil JSON-RPC |
99
+ | 28899 | Solana RPC |
100
+ | 28900 | Solana WebSocket |
101
+ | 28085 | Mina GraphQL |
102
+ | 28181 | Mina accounts manager |
103
+
104
+ ### What this stack is NOT
105
+
106
+ - **Not a production deployment.** The Townhouse production compose (`docker-compose-townhouse.yml`) describes one operator's actual node. This file describes a contributor's rig. Do not confuse them.
107
+ - **Not the SDK E2E topology.** The SDK E2E stack (`docker-compose-sdk-e2e.yml` / `scripts/sdk-e2e-infra.sh`) uses embedded connectors inside SDK peers. The Townhouse dev stack uses a standalone connector fronting separate child nodes — the production Townhouse shape.
108
+ - **Not for performance testing.** Boot-and-smoke only. Performance tuning is out of scope for this stack; it belongs in a dedicated story.
109
+ - **Not multi-tenant.** The 5 child nodes use deterministic dev keys that never change across `up`/`down`/`up` cycles. They are NOT for use as real TOON nodes.
110
+
111
+ ## Running E2E Tests (Story 21.16)
112
+
113
+ There are two test harnesses with different purposes:
114
+
115
+ ### 1. Dev stack integration (contributor dev loop)
116
+
117
+ Uses `townhouse-dev-infra.sh` (multi-peer fixtures, deterministic keys, 28xxx ports).
118
+ See "Local Dev Loop" above.
119
+
120
+ ```bash
121
+ ./scripts/townhouse-dev-infra.sh up
122
+ pnpm --filter @toon-protocol/townhouse test:integration -- dev-stack-smoke
123
+ ```
124
+
125
+ ### 2. Real-CLI E2E (operator-facing lifecycle — Story 21.16)
126
+
127
+ Uses `townhouse-test-infra.sh` (image pre-warm only; tests run the real CLI).
128
+
129
+ ```bash
130
+ # One-time image cache warm-up (pulls connector image + builds toon:{town,mill,dvm})
131
+ bash scripts/townhouse-test-infra.sh up
132
+
133
+ # Run the integration suite (CLI lifecycle + config propagation)
134
+ RUN_DOCKER_INTEGRATION=1 pnpm --filter @toon-protocol/townhouse test:integration
135
+
136
+ # Or: combined script (up + test + down)
137
+ pnpm --filter @toon-protocol/townhouse test:e2e:docker
138
+ ```
139
+
140
+ **Key differences from the dev stack:**
141
+
142
+ | | Dev stack (`townhouse-dev-infra.sh`) | Real-CLI E2E (`townhouse-test-infra.sh`) |
143
+ |---|---|---|
144
+ | Starts containers? | Yes (multi-peer compose) | No (tests run the real CLI) |
145
+ | Keys | Deterministic dev keys | Fresh wallet per test (mkdtempSync) |
146
+ | Topology | 2 Town + 2 Mill + 1 DVM + SOCKS5 | 1 Town + 1 Mill + 1 DVM |
147
+ | Port range | 28xxx | 9400 (API), 9401 (connector admin) |
148
+ | Audience | Dashboard developers | CI / publish gate validation |
149
+
150
+ **Diagnostic runbook:** see the header comment in `scripts/townhouse-test-infra.sh`.
151
+
152
+ **Playwright SPA tests (mock-driven + real-stack):**
153
+
154
+ ```bash
155
+ # Mock-driven specs (transport flip, config change) — no real stack needed
156
+ pnpm --filter @toon-protocol/townhouse-web e2e
157
+
158
+ # Real-stack lifecycle spec — requires townhouse up to be running
159
+ TOWNHOUSE_E2E_REAL_STACK=1 pnpm --filter @toon-protocol/townhouse-web e2e:real
160
+ ```
161
+
162
+ ## Compose Templates (npm tarball, Story 45.2)
163
+
164
+ The published `@toon-protocol/townhouse` package ships two Docker Compose templates:
165
+
166
+ | Profile | File in tarball | Purpose |
167
+ |---------|-----------------|---------|
168
+ | `hs` | `dist/compose/townhouse-hs.yml` | Operator-facing apex boot — digest-pinned GHCR images |
169
+ | `dev` | `dist/compose/townhouse-dev.yml` | Contributor dev stack — local `toon:*` build images |
170
+
171
+ > **Port collision warning.** The HS template binds canonical ports
172
+ > (`127.0.0.1:9401`, `:28090`, `:7100`, `:3100`, `:3200`, `:3400`); the
173
+ > contributor dev stack binds 28xxx-namespaced equivalents (28080:9401,
174
+ > 28100:3100, 28110:3100, 28200:3200, 28210:3200, 28400:3400, 28700:7100,
175
+ > 28710:7100). HS-mode and the dev stack (`scripts/townhouse-dev-infra.sh`)
176
+ > **must not run concurrently on the same machine** — host:9401, host:3100,
177
+ > host:3200, host:3400, host:7100 will conflict. The HS template's
178
+ > single-tenant defaults are intentional for the apex operator path
179
+ > (Story 45.4 `townhouse hs up`); open an enhancement issue if multi-tenant
180
+ > bindings become a real need.
181
+
182
+ ### API
183
+
184
+ ```typescript
185
+ import { loadComposeTemplate, materializeComposeTemplate } from '@toon-protocol/townhouse';
186
+
187
+ // Read the rendered YAML for a profile (read-only, returns a string).
188
+ const yaml = loadComposeTemplate('hs');
189
+
190
+ // Write the compose file + image-manifest.json to ~/.townhouse/ (side-effecting).
191
+ // Both output files are written with mode 0o600 (NFR8 — operator-secret).
192
+ const { composePath, manifestPath } = materializeComposeTemplate('hs');
193
+ // composePath → ~/.townhouse/compose/townhouse-hs.yml
194
+ // manifestPath → ~/.townhouse/image-manifest.json
195
+ ```
196
+
197
+ Both functions accept an optional `options` object:
198
+
199
+ ```typescript
200
+ interface ComposeLoaderOptions {
201
+ townhouseHome?: string; // Override ~/.townhouse/ write target (useful in tests)
202
+ distDir?: string; // Override dist/ read root (useful in tests)
203
+ }
204
+ ```
205
+
206
+ ### `image-manifest.json` schema
207
+
208
+ The manifest pinning every image to a content-addressed `sha256:` digest:
209
+
210
+ ```json
211
+ {
212
+ "schemaVersion": 1,
213
+ "townhouseVersion": "0.1.0",
214
+ "builtAt": "<ISO timestamp>",
215
+ "images": {
216
+ "townhouse-api": { "name": "ghcr.io/toon-protocol/townhouse-api", "tag": "0.1.0", "digest": "sha256:..." },
217
+ "town": { "name": "ghcr.io/toon-protocol/town", "tag": "0.1.0", "digest": "sha256:..." },
218
+ "mill": { "name": "ghcr.io/toon-protocol/mill", "tag": "0.1.0", "digest": "sha256:..." },
219
+ "dvm": { "name": "ghcr.io/toon-protocol/dvm", "tag": "0.1.0", "digest": "sha256:..." },
220
+ "connector": { "name": "ghcr.io/toon-protocol/connector", "tag": "3.4.1", "digest": "sha256:..." }
221
+ }
222
+ }
223
+ ```
224
+
225
+ Full schema source: `scripts/build-image-manifest.mjs` (lines 44–67).
226
+
227
+ ### Dev stack compose (canonical source)
228
+
229
+ The package-local `packages/townhouse/compose/townhouse-dev.yml` is the canonical source of the dev template. It is shipped verbatim in the npm tarball (no digest substitution — uses local `toon:*` image tags).
230
+
231
+ For backward compatibility, `docker-compose-townhouse-dev.yml` at the repo root is preserved and continues to be used by `scripts/townhouse-dev-infra.sh`. A follow-up story will route the script through the package-local copy.
232
+
233
+ ## Running the townhouse as a hidden service (laptop)
234
+
235
+ `docker-compose-townhouse-hs.yml` brings up the full operator stack —
236
+ apex connector + town + mill + dvm + (optional) Anvil + Solana + EVM
237
+ faucet — with the connector publishing a `.anyone` hidden service via
238
+ the Anyone Protocol overlay. External peers reach the townhouse only
239
+ through that `.anyone` address; the laptop never exposes anything to
240
+ the public clearnet.
241
+
242
+ ```bash
243
+ # 1. Build the local node images (one-time, until they're on ghcr)
244
+ docker compose -f docker-compose-townhouse.yml --profile town --profile mill --profile dvm build
245
+
246
+ # 2. Pick a chain profile (localnet is the default — copy when ready to switch)
247
+ cp .env.townhouse-hs.example .env
248
+
249
+ # 3. Boot the HS stack. Profiles select what runs:
250
+ # --profile localnet bundles anvil + solana (skip for real testnets)
251
+ # --profile town/mill/dvm child nodes
252
+ # --profile faucet EVM ETH + Mock USDC faucet UI on :3500
253
+ docker compose -f docker-compose-townhouse-hs.yml \
254
+ --profile localnet --profile town --profile mill --profile dvm --profile faucet up -d
255
+
256
+ # 4. Wait ~30-90s for anon to bootstrap and publish the descriptor.
257
+ # Then read your published .anyone address:
258
+ docker compose -f docker-compose-townhouse-hs.yml exec connector \
259
+ cat /var/lib/anon/hs/hostname
260
+ # → eag2qnhil4vpvfo2eu3qtqj3rzzkrzbmboivwwbbgzr4svfvjigoxpad.anyone
261
+
262
+ # 5. Share that address with peers. They reach you over Tor at:
263
+ # wss://<address>.anyone/btp
264
+ ```
265
+
266
+ ### Chain configuration
267
+
268
+ Mill and the faucet read chain endpoints from environment variables, with
269
+ localnet defaults. Override via `.env` to switch profiles — see
270
+ `.env.townhouse-hs.example` for the four supported shapes:
271
+
272
+ | Profile | EVM | Solana | Mock USDC |
273
+ |---|---|---|---|
274
+ | **localnet** (default) | bundled Anvil at `anvil:8545` | bundled validator at `solana:8899` | pre-deployed in both bundled images |
275
+ | **Akash devnet** | `anvil` lease URL from `deploy/akash/leases.json` | `solana` lease URL from same | baked into `akash-anvil` + `akash-solana` images (same addresses as localnet) |
276
+ | **Public testnet** | Sepolia (`infura.io/v3/<KEY>`) | `api.devnet.solana.com` | real Circle testnet USDC contracts |
277
+ | **Mainnet** | mainnet RPC | `api.mainnet-beta.solana.com` | real Circle mainnet USDC — **disable the faucet profile** |
278
+
279
+ Variables consumed: `EVM_RPC_URL`, `EVM_CHAIN_ID`, `EVM_USDC_ADDRESS`,
280
+ `SOLANA_RPC_URL`, `SOLANA_USDC_MINT`. Setting these in `.env` configures
281
+ the laptop compose AND the Akash deploy (`scripts/akash-deploy.sh
282
+ townhouse`) identically.
283
+
284
+ ### Faucet workflow
285
+
286
+ **EVM ETH + Mock USDC** — bundled `faucet` service runs at
287
+ `http://127.0.0.1:3500`. Operator pastes their address, gets ETH for gas
288
+ and Mock USDC for transfers. Rate-limited 1 request per address per hour
289
+ by default (override via `FAUCET_RATE_LIMIT_HOURS`). The faucet uses
290
+ well-known Anvil dev keys — only meaningful against localnet or the
291
+ Akash devnet; harmless against testnets/mainnet (transactions just fail).
292
+
293
+ **Solana SOL + Mock USDC** — the standalone EVM faucet container does
294
+ NOT yet handle Solana. Two paths until that gap closes:
295
+
296
+ 1. **Dashboard panel**: the townhouse host API (`pnpm --filter
297
+ @toon-protocol/townhouse-web dev` + the host-side townhouse API)
298
+ exposes a Faucet panel that does both EVM and Solana drips through
299
+ `POST /api/faucet`. Best for live operator use.
300
+ 2. **Script**: `scripts/faucet-sol-usdc.mjs <recipient>` from the host —
301
+ talks to whatever `SOLANA_RPC_URL` resolves to in `leases.json`.
302
+
303
+ Both options use the bootstrap-baked Mock USDC mint
304
+ (`6GbdrVghwNKTz9raga7y3Y4qqX5Zgg3AC4d48Kt7C59Q`) and faucet authority
305
+ keypair at `infra/solana/keys/faucet-authority.json`.
306
+
307
+ ### Persistence
308
+
309
+ The `townhouse-hs-anon` named docker volume preserves
310
+ `hs_ed25519_secret_key` across `docker compose down` cycles — the
311
+ `.anyone` address is stable for as long as the volume exists. Delete the
312
+ volume to rotate the address.
313
+
314
+ ### What's exposed on the host (loopback only)
315
+
316
+ - Connector admin: `127.0.0.1:9401` — no auth, **never expose publicly**
317
+ - Anvil RPC: `127.0.0.1:8545` (localnet profile)
318
+ - Solana RPC: `127.0.0.1:8899`, WS `127.0.0.1:8900` (localnet profile)
319
+ - Town Nostr relay clearnet: `127.0.0.1:7100` — direct local clients
320
+ bypass the HS, handy for debugging
321
+ - EVM faucet UI: `127.0.0.1:3500` (faucet profile)
322
+
323
+ ### Akash deployment of the same stack
324
+
325
+ `deploy/akash/townhouse.sdl.yaml` deploys apex + town + mill + dvm +
326
+ faucet to Akash with the same architecture. Chain devnets stay as
327
+ separate Akash leases (clearnet) — see `scripts/akash-deploy.sh`'s
328
+ `cmd_townhouse` (TODO) for the leases.json wiring. The faucet's HTTP
329
+ port is the SDL's "one global service" validator scaffolding;
330
+ operationally, external peers reach the townhouse only via the `.anyone`
331
+ hidden service.
332
+
333
+ ## Package overview
334
+
335
+ The `@toon-protocol/townhouse` package provides:
336
+
337
+ - **DockerOrchestrator** — manages container lifecycle for Town/Mill/DVM nodes
338
+ - **ConnectorConfigGenerator** — generates connector peer config from node identities
339
+ - **ConnectorAdminClient** — typed HTTP client for the connector admin API (`/health`, `/admin/peers`, `/admin/metrics.json`)
340
+ - **HD wallet management** — BIP-44 key derivation per node type (story 21.4)
341
+ - **Fastify REST/WebSocket metrics API** — host-side API for the dashboard (story 21.8)
342
+
343
+ See `packages/townhouse/src/index.ts` for the full public API surface.
344
+
345
+ ## Transport configuration
346
+
347
+ The `transport` block selects how the connector reaches peers (outbound) and
348
+ how peers reach the connector (inbound).
349
+
350
+ ```yaml
351
+ transport:
352
+ mode: direct # 'direct' | 'ator'
353
+ socksProxy: socks5h://proxy.ator.io:9050 # required when mode='ator'
354
+ externalUrl: wss://my-connector.example/btp # see below
355
+ hiddenService: # optional — connector publishes its own .anyone HS
356
+ dir: /var/lib/anon/hs
357
+ port: 3000
358
+ startupTimeoutMs: 60000 # optional
359
+ stopTimeoutMs: 10000 # optional
360
+ externalUrl: wss://forced.anyone/btp # optional override of "auto"
361
+ ```
362
+
363
+ **`mode: 'direct'`** — clearnet TCP, no overlay. Default for development.
364
+
365
+ **`mode: 'ator'`** — outbound BTP through the Anyone Protocol (ATOR) overlay
366
+ via SOCKS5. Requires either `externalUrl` (operator-managed anon binary
367
+ external to the connector) OR `hiddenService` (connector manages its own
368
+ anon binary in-process and publishes a `.anyone` hidden service). Without
369
+ one of these the connector rejects the manifest at boot — the validator
370
+ catches this case before deploy.
371
+
372
+ **`hiddenService` (Story 35.5 of the connector repo)** — when set, the
373
+ connector boots `@anyone-protocol/anyone-client` in-process, spawns the
374
+ `anon` binary, and publishes a v3 hidden service. The keypair lives at
375
+ `dir`; persist that path on a mounted volume to keep the `.anyone` address
376
+ stable across redeploys, or delete it to rotate. The connector reads
377
+ `${dir}/hostname` after publish and advertises `wss://<hostname>.anyone/btp`
378
+ to peers (you can override with an explicit `externalUrl` if needed).
379
+
380
+ **Wire-format note (silent-bug fix in this story):** the previous shape
381
+ emitted `transport: { mode: 'ator', socksProxy }` to the connector image,
382
+ but the connector at 3.3.x reads a discriminated union keyed on `type`
383
+ (`'direct' | 'socks5'`). The unknown `mode` field was silently discarded,
384
+ defaulting to direct — operators toggling ATOR got direct traffic anyway.
385
+ The current generator emits the correct `type: 'socks5'` shape with
386
+ `externalUrl`, `managed`, and `managedOptions` per the connector contract.