@minca/core 0.1.11 → 0.1.12

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 (104) hide show
  1. package/dist/identity/channel.d.ts +1 -1
  2. package/dist/identity/channel.d.ts.map +1 -1
  3. package/dist/identity/channel.js +1 -1
  4. package/dist/identity/channel.js.map +1 -1
  5. package/dist/inbox/inbox.d.ts +1 -9
  6. package/dist/inbox/inbox.d.ts.map +1 -1
  7. package/dist/inbox/inbox.js +3 -18
  8. package/dist/inbox/inbox.js.map +1 -1
  9. package/dist/inbox/index.d.ts +3 -3
  10. package/dist/inbox/index.d.ts.map +1 -1
  11. package/dist/inbox/index.js +2 -2
  12. package/dist/inbox/index.js.map +1 -1
  13. package/dist/index.d.ts +6 -4
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -2
  16. package/dist/index.js.map +1 -1
  17. package/dist/network/introductions.d.ts +1 -1
  18. package/dist/network/introductions.d.ts.map +1 -1
  19. package/dist/network/mesh.d.ts +4 -2
  20. package/dist/network/mesh.d.ts.map +1 -1
  21. package/dist/network/mesh.js +31 -45
  22. package/dist/network/mesh.js.map +1 -1
  23. package/dist/network/peer-auth.d.ts +4 -0
  24. package/dist/network/peer-auth.d.ts.map +1 -1
  25. package/dist/network/peer-auth.js +9 -7
  26. package/dist/network/peer-auth.js.map +1 -1
  27. package/dist/network/relay-minca.d.ts +6 -0
  28. package/dist/network/relay-minca.d.ts.map +1 -0
  29. package/dist/network/relay-minca.js +146 -0
  30. package/dist/network/relay-minca.js.map +1 -0
  31. package/dist/network/relay-nostr.d.ts +10 -0
  32. package/dist/network/relay-nostr.d.ts.map +1 -0
  33. package/dist/network/relay-nostr.js +247 -0
  34. package/dist/network/relay-nostr.js.map +1 -0
  35. package/dist/network/relay-socket.d.ts +87 -0
  36. package/dist/network/relay-socket.d.ts.map +1 -0
  37. package/dist/network/{signaling.js → relay-socket.js} +201 -167
  38. package/dist/network/relay-socket.js.map +1 -0
  39. package/dist/network/relays.d.ts +87 -0
  40. package/dist/network/relays.d.ts.map +1 -0
  41. package/dist/network/relays.js +43 -0
  42. package/dist/network/relays.js.map +1 -0
  43. package/dist/network/remote-transport.d.ts +1 -1
  44. package/dist/network/remote-transport.d.ts.map +1 -1
  45. package/dist/network/remote-transport.js +6 -31
  46. package/dist/network/remote-transport.js.map +1 -1
  47. package/dist/network/rendezvous.d.ts +59 -0
  48. package/dist/network/rendezvous.d.ts.map +1 -0
  49. package/dist/network/rendezvous.js +380 -0
  50. package/dist/network/rendezvous.js.map +1 -0
  51. package/dist/network/rtc-transport.d.ts.map +1 -1
  52. package/dist/network/rtc-transport.js +32 -17
  53. package/dist/network/rtc-transport.js.map +1 -1
  54. package/dist/network/transport.d.ts +7 -5
  55. package/dist/network/transport.d.ts.map +1 -1
  56. package/dist/node/carrier.js +1 -1
  57. package/dist/node/carrier.js.map +1 -1
  58. package/dist/node/node.d.ts.map +1 -1
  59. package/dist/node/node.js +15 -24
  60. package/dist/node/node.js.map +1 -1
  61. package/dist/node/space-runtime.d.ts +4 -1
  62. package/dist/node/space-runtime.d.ts.map +1 -1
  63. package/dist/node/space-runtime.js +3 -6
  64. package/dist/node/space-runtime.js.map +1 -1
  65. package/dist/node/types.d.ts +3 -3
  66. package/dist/node/types.d.ts.map +1 -1
  67. package/dist/session/auth.d.ts +5 -6
  68. package/dist/session/auth.d.ts.map +1 -1
  69. package/dist/session/auth.js +4 -5
  70. package/dist/session/auth.js.map +1 -1
  71. package/dist/session/channel-room.d.ts.map +1 -1
  72. package/dist/session/channel-room.js +3 -2
  73. package/dist/session/channel-room.js.map +1 -1
  74. package/dist/session/connect-code.d.ts +69 -55
  75. package/dist/session/connect-code.d.ts.map +1 -1
  76. package/dist/session/connect-code.js +189 -89
  77. package/dist/session/connect-code.js.map +1 -1
  78. package/dist/session/connect.d.ts +11 -15
  79. package/dist/session/connect.d.ts.map +1 -1
  80. package/dist/session/connect.js +8 -21
  81. package/dist/session/connect.js.map +1 -1
  82. package/dist/session/index.d.ts +2 -2
  83. package/dist/session/index.d.ts.map +1 -1
  84. package/dist/session/index.js +1 -1
  85. package/dist/session/index.js.map +1 -1
  86. package/dist/space/roles.d.ts.map +1 -1
  87. package/dist/space/roles.js +4 -2
  88. package/dist/space/roles.js.map +1 -1
  89. package/docs/agents.md +59 -37
  90. package/docs/inbox.md +1 -1
  91. package/docs/node.md +32 -22
  92. package/docs/sign-in.md +5 -7
  93. package/package.json +2 -1
  94. package/dist/network/mailbox.d.ts +0 -45
  95. package/dist/network/mailbox.d.ts.map +0 -1
  96. package/dist/network/mailbox.js +0 -135
  97. package/dist/network/mailbox.js.map +0 -1
  98. package/dist/network/multi-signaling.d.ts +0 -41
  99. package/dist/network/multi-signaling.d.ts.map +0 -1
  100. package/dist/network/multi-signaling.js +0 -209
  101. package/dist/network/multi-signaling.js.map +0 -1
  102. package/dist/network/signaling.d.ts +0 -95
  103. package/dist/network/signaling.d.ts.map +0 -1
  104. package/dist/network/signaling.js.map +0 -1
package/docs/agents.md CHANGED
@@ -32,62 +32,84 @@ await runAction(node, 'records_put', { space, collection: 'app.todo.item', body:
32
32
  From `@minca/cli`, the `minca` command:
33
33
 
34
34
  ```bash
35
- npx @minca/cli connect mc_… # the code from "Connect an agent" in an app
35
+ npx @minca/cli connect
36
36
  ```
37
37
 
38
- It makes a key for this computer's agent, waits while the person allows it at
39
- their account home, and adds `minca mcp` to the agents it finds (Claude Code,
40
- Claude Desktop, Cursor, VS Code, Windsurf, Zed, Codex and more). The agent is then a node of its own: it follows
41
- the account's spaces and keeps working with every tab closed.
38
+ It makes a key for this computer's agent and opens the person's account home
39
+ in the browser, where they sign in, or make an account, and allow it. The
40
+ home then shows six digits, which the person types into the terminal: the
41
+ agent keeps its note only once they match. Then it
42
+ adds `minca mcp` to the agents it finds (Claude Code, Claude Desktop, Cursor,
43
+ VS Code, Windsurf, Zed, Codex and more). The agent is then a node of its own:
44
+ it follows the account's spaces and keeps working with every tab closed.
45
+
46
+ An agent can also start `minca mcp` before it is connected, from settings
47
+ added by hand. Until it is, the server offers one tool, which opens the
48
+ account home the same way, and gives the model the link only when no
49
+ browser opened. The model asks the person for the six digits the home shows
50
+ and gives them back to the same tool
51
+ ([the CLI's README](https://github.com/leifriksheim/minca/blob/main/packages/cli/README.md#agents)). Once the
52
+ person has allowed it, every tool arrives (`notifications/tools/list_changed`)
53
+ without a restart.
42
54
 
43
55
  `minca agent` runs the same agent without a chat client: it chats in the
44
56
  terminal and thinks with the person's own Anthropic API key, offering the model
45
57
  the same tools. See `packages/cli/README.md`.
46
58
 
47
- ## Connecting with a code
59
+ ## Connecting at your account home
48
60
 
49
61
  The code, the channel it opens and the messages the two sides trade are
50
62
  protocol, and know nothing of agents
51
63
  ([spec 06 §3](https://github.com/leifriksheim/minca/blob/main/spec/06-nodes-and-sessions.md)).
52
- The library's two sides are `offerConnectCode` (the app) and `connectWithCode`
53
- (the program).
54
-
55
- - `offerConnectCode({ relays, account, origin? }, onStage)` makes a code that
56
- names `account`, the account the app is signed in to, and tells the
57
- program `origin` (default: the page's). On `asking` it hands the app the
58
- program's ask (`did`, `name`, `proof`, `recordsOnly`) and two answers,
59
- `allow(grant)` and `deny(reason?)`. What the program asked for is only a
60
- request: the app decides, and denies an ask it won't grant as asked.
61
- - `connectWithCode({ code, key, name, recordsOnly, network, onWaiting? })`
62
- signs the proof itself once it learns the app's origin
63
- (`keyProof(key, { via: 'code', recordsOnly, origin })`), tells
64
- `onWaiting({ origin })` when the app has heard, and refuses a grant from any
65
- account but the one the code names.
64
+ The library's two sides are `connectWithCode` (the program) and
65
+ `receiveConnectCode` (the account home).
66
+
67
+ - `newConnectCode()` makes a code, and `connectCodeUrl(home, code)` the link
68
+ to open: `https://home.minca.social/connect#mc_…`.
69
+ - `connectWithCode({ home, code, key, name, network, check, onWaiting? })`
70
+ waits in the code's room, signs the proof once it learns the home's origin
71
+ (`keyProof(key, { via: 'code', recordsOnly: true, origin })`), tells
72
+ `onWaiting({ origin })` when the home has heard, and keeps only a
73
+ records-only note made out to its key, once `check(matches)` has had the
74
+ person give the six digits the home showed.
75
+ - `receiveConnectCode({ code, relays, onAnswered? })`, on the home's connect
76
+ page, answers the program and gives back the same `IncomingRequest` an
77
+ app's popup does: records only, in the whole account, for 30 days, with
78
+ `check`, the six digits to show.
79
+ `connectCodeIn(location.hash)` finds the code. `answerConnectCode` is the
80
+ same exchange without the request around it.
66
81
 
67
82
  What the reference sides add:
68
83
 
69
- - The terminal (`minca connect`) asks for records only, and shows the app's
70
- origin while the person decides.
71
- - The app (`apps/example/src/components/ConnectAgent.tsx`) shows the code. It
72
- gives a program records only (`apps/example/src/program-terms.ts`): it
73
- denies an ask without `recordsOnly: true`, and otherwise shows the
74
- program's name and what it may do, and asks the person to allow it.
75
- - Allowing opens the account home (`connectToHome` with `audience` and
76
- `audienceProof`, which adds `via: 'code'`) with `access: write`,
77
- `scope: account`, `chooseSpaces: false`, `recordsOnly: true` and the
78
- lifetime the person chose. The home warns in red when a request by code asks
79
- for more than records.
80
- - The app shows the agent connected when `code:done` arrives.
81
- - The terminal waits 60 s to hear `code:heard`, then 10 minutes for the
82
- answer, and checks the grant with `checkGrant(grant, did, { recordsOnly: true })`
83
- before keeping it, and again each time it starts.
84
- - The terminal makes a new key for each code. Connecting again, after a
84
+ - The terminal asks which account home to open, with home.minca.social, or
85
+ the one it connected at last, filled in so Enter takes it.
86
+ `--account-home` or `MINCA_ACCOUNT_HOME` names it ahead. The MCP server's
87
+ connect tool takes no home: the model never chooses where the person signs
88
+ in. Anywhere nothing can be asked, it uses the usual one.
89
+ - It opens the link in the browser, and shows it only when none opens (a
90
+ server, a terminal over SSH), since whoever else holds it could answer as
91
+ the home. The link works from any device.
92
+ - `connectWithCode` asks only the home it opened, and keeps that home in the
93
+ grant, whatever the answer names; it prints the account's DID beside its
94
+ name.
95
+ - The home (`apps/home/src/components/ConnectPage.tsx`) takes the code out
96
+ of the address bar, shows the program's name and says to allow it only if
97
+ the person started it just now. Once answered it says so, and the tab can
98
+ be closed. When no program asks within a minute, it says the link was
99
+ used or has run out.
100
+ - The terminal waits 10 minutes for the home to open, since the person may
101
+ make an account first, then 30 minutes for the answer. It checks the grant
102
+ with `checkGrant(grant, did, { recordsOnly: true })` before keeping it, and
103
+ again each time it starts, and says whose account it joined.
104
+ - The terminal makes a new key for each connect. Connecting again, after a
85
105
  disconnect or to renew, gives a new key and note; a running `minca mcp`
86
106
  takes them up without a restart. The earlier connection stays in the
87
107
  account home until it is disconnected there, and nothing can use it: its
88
108
  key is gone from the computer.
109
+ - An app only says how: "Connect an agent" in the example app shows the
110
+ command (`apps/example/src/components/ConnectAgent.tsx`).
89
111
 
90
- _Source: `packages/core/src/session/connect-code.ts`, `packages/cli/src/agent.ts` (`connectAgent`, `startAgentNode`, `reloadOnConnect`), `apps/example/src/components/ConnectAgent.tsx`, `apps/example/src/program-terms.ts`, `apps/home/src/components/ConnectPage.tsx`. Tests: `packages/core/tests/connect-code.test.ts`, `packages/core/tests/records-only.test.ts` ("a program connected by code, through the account home"), `apps/example/tests/program-terms.test.ts`, `packages/cli/tests/agent-reconnect.test.ts`._
112
+ _Source: `packages/core/src/session/connect-code.ts`, `packages/cli/src/agent.ts` (`connectAgent`, `openInBrowser`, `startAgentNode`, `reloadOnConnect`), `packages/cli/src/main.ts` (`chooseAccountHome`), `packages/cli/src/mcp.ts` (`connectWaiting`, `waitingMcp`), `apps/home/src/components/ConnectPage.tsx`. Tests: `packages/core/tests/connect-code.test.ts`, `packages/core/tests/records-only.test.ts` ("a program connected by code, through the account home"), `packages/cli/tests/agent-reconnect.test.ts`, `packages/cli/tests/cli.test.ts` ("not connected yet, it offers agent_connect…")._
91
113
 
92
114
  ## Tools an agent gets
93
115
 
package/docs/inbox.md CHANGED
@@ -122,7 +122,7 @@ The calls are listed with the rest of the node, in [node.md](node.md#the-inbox).
122
122
  `watch`. The default mailbox client opens a fresh WebSocket to a relay for
123
123
  each call.
124
124
 
125
- _Source: `packages/core/src/network/mailbox.ts` (`createMailboxClient`)._
125
+ _Source: `packages/core/src/network/relays.ts` (`createMailboxClient`)._
126
126
 
127
127
  ## Not yet built
128
128
 
package/docs/node.md CHANGED
@@ -23,7 +23,7 @@ conveniences.
23
23
  | `stores` | `StoreFactory` | Where the registry and each space's store live ([stores](#stores)). |
24
24
  | `provider` | `CryptoProvider`, optional | Default: P-256 over WebCrypto. |
25
25
  | `collections` | `CollectionDef[]`, optional | Schemas the node knows, used when a space does not describe a collection itself. Writes are checked against them; reads are flagged `conforms`. Nothing is refused on arrival for its shape ([02](https://github.com/leifriksheim/minca/blob/main/spec/02-records.md)). |
26
- | `network` | optional | `relays` (WebRTC signaling, browsers), `nodes` (always-on nodes to dial, `wss://host/peer#<DID>`; the fragment pins the node, spec 04 §5.2; `ws://` only on this machine), `iceServers`, `transports` (extra transports per space). Omitted: offline. |
26
+ | `network` | optional | `relays` (where peers meet: Minca `wss://` and Nostr `nostr+wss://` relays), `nodes` (always-on nodes to dial, `wss://host/peer#<DID>`; the fragment pins the node, spec 04 §5.2; `ws://` only on this machine), `iceServers`, `transports` (extra transports per space). Omitted: offline. |
27
27
  | `sessionTtlSeconds` | number, optional | Lifetime of each session note. Default `3600`. |
28
28
  | `sessionKey` | `CryptoKeyPair`, optional | Sign with this key instead of a fresh one. Used when the signer's note names a specific key (an app's key, an agent's key, [spec 06 §2](https://github.com/leifriksheim/minca/blob/main/spec/06-nodes-and-sessions.md), [spec 06 §3](https://github.com/leifriksheim/minca/blob/main/spec/06-nodes-and-sessions.md)). |
29
29
  | `writerKey` | `WriterKeySource`, optional | Keep a signing key across runs, so this device keeps one log in each space ([writer keys](#writer-keys)). Ignored with `sessionKey`. |
@@ -537,17 +537,17 @@ A received live message is emitted as a `message` event,
537
537
 
538
538
  `spaces.status(id)` returns `SpaceStatus`:
539
539
 
540
- | Field | Meaning |
541
- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
542
- | `connection` | `offline` (no network), `connecting`, `connected` (while any one transport is connected: a relay socket open, or a peer), `error` (the first connect failed and nothing has connected since), `refused` (nothing connected, and every relay refused this node's DID with `4009` because another node with the same key holds it, [spec 04 §1.2](https://github.com/leifriksheim/minca/blob/main/spec/04-network.md)). A space whose relays all drop and whose peers leave is `connecting` again, not `connected`. |
543
- | `peers` | Session DIDs connected in the space. |
544
- | `own` | Of `peers`, the account's own other devices and apps: those also connected in the account registry, minus carriers. Empty without an account key. |
545
- | `carriers` | Of `peers`, the account's carriers, by the keys `sys.carrier` records name. |
546
- | `accounts` | Session DID → account, for each peer that showed a valid note. |
547
- | `fingerprint` | A fingerprint of every version held; equal on two nodes means identical data ([the store in memory](storage.md#the-store-in-memory)). |
548
- | `rejected` | How many versions peers sent failed validation. |
549
- | `holds` | `"all"`, or the sorted list of collections held ([holding part of a space](#holding-part-of-a-space)). |
550
- | `pending` | This node's writes still waiting for keepers ([holding part of a space](#holding-part-of-a-space)). |
540
+ | Field | Meaning |
541
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
542
+ | `connection` | `offline` (no network), `connecting`, `connected` (while any one transport is connected: a relay socket open, or a peer), `error` (the first connect failed and nothing has connected since). A space whose relays all drop and whose peers leave is `connecting` again, not `connected`. |
543
+ | `peers` | Session DIDs connected in the space. |
544
+ | `own` | Of `peers`, the account's own other devices and apps: those also connected in the account registry, minus carriers. Empty without an account key. |
545
+ | `carriers` | Of `peers`, the account's carriers, by the keys `sys.carrier` records name. |
546
+ | `accounts` | Session DID → account, for each peer that showed a valid note. |
547
+ | `fingerprint` | A fingerprint of every version held; equal on two nodes means identical data ([the store in memory](storage.md#the-store-in-memory)). |
548
+ | `rejected` | How many versions peers sent failed validation. |
549
+ | `holds` | `"all"`, or the sorted list of collections held ([holding part of a space](#holding-part-of-a-space)). |
550
+ | `pending` | This node's writes still waiting for keepers ([holding part of a space](#holding-part-of-a-space)). |
551
551
 
552
552
  > Rationale: a peer's key does not say whose it is, but only the account's own
553
553
  > devices and apps can read its registry, so a peer there is one of ours.
@@ -633,25 +633,35 @@ How the node uses relays, always-on nodes and WebRTC, where
633
633
  leaves it the choice. Another implementation may pick other values and still
634
634
  meet this one.
635
635
 
636
- **Redialling a relay** (spec 04 §2). The client waits 1, 2, 4, 8, 16 s and
636
+ **Redialling a relay** (spec 04 §2.1). The client waits 1, 2, 4, 8, 16 s and
637
637
  then 30 s between attempts, each ±25% so peers that dropped together do not
638
- return together, and never stops until `disconnect`. After a `4009` it emits
639
- `refused` and waits 10 s, doubling with each refusal in a row up to 60 s. It
640
- tries at once when the page becomes visible again, and when asked
638
+ return together, and never stops until `disconnect`. It tries at once when the page becomes visible again, and when asked
641
639
  (`reconnect`). A successful open resets the count. A socket can die without
642
640
  closing, and after a sleep it has: so the client looks at the clock every
643
641
  5 s, and a look more than 30 s after the last means the device slept; it
644
642
  then lets go of its socket and dials again at once, as it does when the
645
- browser reports `online`. An open socket that has heard nothing for 30 s
646
- also sends `ping`; once its relay has answered one, two going unanswered end
643
+ browser reports `online`. An open socket to a Minca relay that has heard
644
+ nothing for 30 s also sends `ping`; once its relay has answered one, two going unanswered end
647
645
  the socket ("The relay stopped answering.") and it redials. Each relay's state
648
646
  (`connecting`, `open`, `waiting` with the time of the next attempt and why the
649
647
  last one failed, `stopped`) is readable as `RelayStatus`, and through a node
650
648
  as `network.status()`.
651
649
 
652
- **Several relays** (spec 04 §3). The signaling layer raises `peer-joined`
653
- when a peer's set of relays in a room becomes non-empty, and `peer-left` when
654
- it empties. `requestIce` asks every connected relay for TURN.
650
+ **Meeting** (spec 04 §2, §3). A node says hello in each room when it joins,
651
+ on every relay as its socket opens, and every 2 minutes. It remembers, per
652
+ room, the times it acted on from each peer in the last 2 minutes (at most
653
+ 256 a peer), and the failed tries of the last 512 peers. It
654
+ says hello back in a room at most once every 10 s; one due sooner waits
655
+ for the 10 s, once for everyone who said hello meanwhile. Each socket
656
+ sends at most 20 messages a second, in bursts of 40, and queues the rest. A
657
+ connection attempt that times out is retried on the peer's next hello. `requestIce`
658
+ asks every connected relay for TURN. Each WebRTC offer or answer waits for
659
+ ICE gathering to finish, or 2 s, and carries what it found.
660
+
661
+ **Kinds of relay** (spec 04 §1.2). `network.relays` may mix kinds:
662
+ `['wss://minca.fly.dev', 'nostr+wss://relay.damus.io']`. A relay of a kind
663
+ this library doesn't speak is left out of `network.status()`. On a Nostr
664
+ relay, each event is signed with a key made for it and forgotten.
655
665
 
656
666
  **A space's relays** (spec 04 §4). A relay socket opened only for spaces'
657
667
  own relays is closed once no room needs it. A node whose account may invoke
@@ -690,7 +700,7 @@ to every connected relay and waits up to 1.5 s for an answer (relays without
690
700
  TURN never answer), then returns what it has. A node with no relays returns
691
701
  the configured servers.
692
702
 
693
- _Source: `packages/core/src/network/signaling.ts` (`createSignalingClient`, `RelayStatus`), `packages/core/src/network/multi-signaling.ts` (`release`), `packages/core/src/network/ws-transport.ts`, `packages/core/src/network/local-transport.ts` (`createLocalHub`), `packages/core/src/node/carrier.ts` (`carry`), `packages/core/src/network/mesh.ts` (`CONNECT_TIMEOUT_MS`, `closeIfIdle`, `iceServers`, `ICE_REFRESH_MS`, `ICE_WAIT_MS`), `packages/core/src/network/introductions.ts` (`createSeenSignals`), `packages/core/src/network/rtc-transport.ts` (`DEFAULT_ICE_SERVERS`), `packages/core/src/node/space-runtime.ts` (`nameRelays`), `packages/core/src/node/node.ts` (`iceServers`), `packages/cli/src/serve.ts` (`onPeer`). Tests: `packages/core/tests/signaling.test.ts` ("signaling reconnects"), `packages/core/tests/relay-refusal.test.ts`, `packages/core/tests/introductions.test.ts`, `packages/core/tests/space-relays.test.ts`, `packages/core/tests/ws-transport.test.ts`, `packages/core/tests/carrier.test.ts`; the client-side ICE refresh is untested._
703
+ _Source: `packages/core/src/network/relay-socket.ts` (`createRelaySocket`, `RelayStatus`), `packages/core/src/network/rendezvous.ts` (`createRendezvous`, `HELLO_MS`, `release`), `packages/core/src/network/relay-nostr.ts`, `packages/core/src/network/rtc-transport.ts` (`GATHER_MS`), `packages/core/src/network/ws-transport.ts`, `packages/core/src/network/local-transport.ts` (`createLocalHub`), `packages/core/src/node/carrier.ts` (`carry`), `packages/core/src/network/mesh.ts` (`CONNECT_TIMEOUT_MS`, `closeIfIdle`, `iceServers`, `ICE_REFRESH_MS`, `ICE_WAIT_MS`), `packages/core/src/network/introductions.ts` (`createSeenSignals`), `packages/core/src/network/rtc-transport.ts` (`DEFAULT_ICE_SERVERS`), `packages/core/src/node/space-runtime.ts` (`nameRelays`), `packages/core/src/node/node.ts` (`iceServers`), `packages/cli/src/serve.ts` (`onPeer`). Tests: `packages/core/tests/relay-socket.test.ts`, `packages/core/tests/rendezvous.test.ts`, `packages/core/tests/relay-nostr.test.ts`, `packages/core/tests/introductions.test.ts`, `packages/core/tests/space-relays.test.ts`, `packages/core/tests/ws-transport.test.ts`, `packages/core/tests/carrier.test.ts`; the client-side ICE refresh is untested._
694
704
 
695
705
  ## A node acting as an agent
696
706
 
package/docs/sign-in.md CHANGED
@@ -397,17 +397,15 @@ the keys it replaced go in `retired`, for disconnecting to revoke. Nothing
397
397
  revokes an app on its own, not even once its time has passed: a revoke keeps
398
398
  only what this home has seen of the key, and a home that is seldom open has
399
399
  seen little ([spec 06 §2.9](https://github.com/leifriksheim/minca/blob/main/spec/06-nodes-and-sessions.md)). A connection with `via: 'code'` (a
400
- program connected by code through the app) is keyed by its audience instead,
400
+ program connected by code, at the home's own origin) is keyed by its audience instead,
401
401
  so each such program is its own (`connectionKey`). A carrier is kept apart from the app at its
402
402
  origin: connecting either replaces only its own kind, and one key is never
403
403
  both. `auth.connections()` lists them.
404
404
 
405
- **Disconnecting.** `auth.disconnect(origin, { byCode?, audience? })` removes
406
- the app's connections (by default the app and every program connected through
407
- it by code; `byCode: true` only those programs; `audience` only that key),
408
- revokes the keys of those with `access: write` and every key in their
409
- `retired`, and, unless only programs
410
- connected by code go, removes the automations the app proposed. A carrier at
405
+ **Disconnecting.** `auth.disconnect(origin, { audience? })` removes the
406
+ connections made from that origin (`audience`: only that key), revokes the
407
+ keys of those with `access: write` and every key in their `retired`, and
408
+ removes the automations the app proposed. A carrier at
411
409
  that origin stays: it goes by its key alone (`audience`), and takes nothing of
412
410
  the app's with it. The app hears of it when the revokes reach it,
413
411
  from this home or a device that has them: `waitMs` waits up to that long for
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minca/core",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "description": "Self-sovereign P2P protocol for the browser — identity, schemas, storage, networking, and gossip sync",
6
6
  "repository": {
@@ -91,6 +91,7 @@
91
91
  "dependencies": {
92
92
  "@cfworker/json-schema": "^4.1.1",
93
93
  "@noble/curves": "^2.4.0",
94
+ "@noble/hashes": "^2.4.0",
94
95
  "@scure/base": "^2.4.0",
95
96
  "aws4fetch": "^1.0.20"
96
97
  },
@@ -1,45 +0,0 @@
1
- /**
2
- * Talking to a relay's mailbox: leaving a sealed knock under an inbox's topic,
3
- * and reading what was left under one's own (`packages/relay/relay.mjs`).
4
- *
5
- * Each call opens its own short-lived socket, says one thing, waits for the
6
- * answer and closes. A mailbox socket never joins a room, so it names no DID,
7
- * and the relay can't tie a knock to the peer that left it or fetched it.
8
- *
9
- * client → { type: 'drop', topic, blob, ttl? } relay → { type: 'dropped', topic, id } | { type: 'refused', topic, reason }
10
- * client → { type: 'fetch', topic, after? } relay → { type: 'mail', topic, items: [{ seq, id, at, blob }], more }
11
- * client → { type: 'challenge' } relay → { type: 'challenge', nonce }
12
- * client → { type: 'purge', topic, sign, ids?, sig } relay → { type: 'purged', topic, count } | { type: 'refused', topic, reason }
13
- */
14
- /** One sealed knock, as a relay holds it */
15
- export interface MailItem {
16
- /** Increases with every drop on that relay */
17
- readonly seq: number;
18
- /** base64url SHA-256 of the blob: the same on every relay it was left at */
19
- readonly id: string;
20
- /** When it was dropped, ms, by the relay's clock */
21
- readonly at: number;
22
- readonly blob: string;
23
- }
24
- export interface MailboxClient {
25
- /**
26
- * Leaves a blob under a topic.
27
- * @throws When the relay refuses it, or can't be reached
28
- */
29
- drop(relay: string, topic: string, blob: string, ttlSeconds?: number): Promise<string>;
30
- /** Everything a relay holds under a topic, after a sequence number, in at most `pages` pages (default 8) */
31
- fetch(relay: string, topic: string, after?: number, pages?: number): Promise<ReadonlyArray<MailItem>>;
32
- /**
33
- * Clears knocks from a topic — all of them, or those named — as the inbox's
34
- * owner: shows the signing key and signs the relay's challenge with it.
35
- */
36
- purge(relay: string, topic: string, sign: string, ids: ReadonlyArray<string> | null, signChallenge: (nonce: string) => Promise<string>): Promise<number>;
37
- }
38
- export interface MailboxOptions {
39
- /** How long to wait for a relay to answer. Default 8 seconds. */
40
- readonly timeoutMs?: number;
41
- /** The WebSocket to use. Default the global one (browsers, Node 22+). */
42
- readonly WebSocket?: typeof WebSocket;
43
- }
44
- export declare function createMailboxClient(options?: MailboxOptions): MailboxClient;
45
- //# sourceMappingURL=mailbox.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mailbox.d.ts","sourceRoot":"","sources":["../../src/network/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,4CAA4C;AAC5C,MAAM,WAAW,QAAQ;IACvB,8CAA8C;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvF,4GAA4G;IAC5G,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtG;;;OAGG;IACH,KAAK,CACH,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,GAAG,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,IAAI,EACjC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,GAChD,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,yEAAyE;IACzE,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;CACvC;AAKD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CA2H/E"}
@@ -1,135 +0,0 @@
1
- /**
2
- * Talking to a relay's mailbox: leaving a sealed knock under an inbox's topic,
3
- * and reading what was left under one's own (`packages/relay/relay.mjs`).
4
- *
5
- * Each call opens its own short-lived socket, says one thing, waits for the
6
- * answer and closes. A mailbox socket never joins a room, so it names no DID,
7
- * and the relay can't tie a knock to the peer that left it or fetched it.
8
- *
9
- * client → { type: 'drop', topic, blob, ttl? } relay → { type: 'dropped', topic, id } | { type: 'refused', topic, reason }
10
- * client → { type: 'fetch', topic, after? } relay → { type: 'mail', topic, items: [{ seq, id, at, blob }], more }
11
- * client → { type: 'challenge' } relay → { type: 'challenge', nonce }
12
- * client → { type: 'purge', topic, sign, ids?, sig } relay → { type: 'purged', topic, count } | { type: 'refused', topic, reason }
13
- */
14
- import { isObject } from '../utils/guards.js';
15
- /** At most this many pages per fetch: 16 knocks each, and an inbox holds 64 */
16
- const MAX_PAGES = 8;
17
- export function createMailboxClient(options = {}) {
18
- const timeoutMs = options.timeoutMs ?? 8000;
19
- /** Opens a socket, sends one message, and resolves with the first answer `pick` accepts */
20
- function ask(relay, message, pick) {
21
- return talk(relay, (send) => send(message), async (answer) => pick(answer));
22
- }
23
- /**
24
- * Opens a socket and holds a short conversation: `start` says the first
25
- * thing, `hear` answers what comes back (it may `send` again) and settles it
26
- * by returning a value.
27
- */
28
- function talk(relay, start, hear) {
29
- const Socket = options.WebSocket ?? globalThis.WebSocket;
30
- if (!Socket)
31
- return Promise.reject(new Error('No WebSocket here to reach a relay with'));
32
- return new Promise((resolve, reject) => {
33
- let settled = false;
34
- const ws = new Socket(relay);
35
- const settle = () => {
36
- if (settled)
37
- return false;
38
- settled = true;
39
- clearTimeout(timer);
40
- try {
41
- ws.close();
42
- }
43
- catch {
44
- // already closing
45
- }
46
- return true;
47
- };
48
- const fail = (error) => {
49
- if (settle())
50
- reject(error);
51
- };
52
- const timer = setTimeout(() => fail(new Error(`${relay} did not answer`)), timeoutMs);
53
- const say = (message) => ws.send(JSON.stringify(message));
54
- ws.onopen = () => start(say);
55
- ws.onerror = () => fail(new Error(`Could not reach ${relay}`));
56
- ws.onclose = () => fail(new Error(`${relay} closed the connection`));
57
- ws.onmessage = (event) => {
58
- let answer;
59
- try {
60
- answer = JSON.parse(String(event.data));
61
- }
62
- catch {
63
- return;
64
- }
65
- if (!isObject(answer))
66
- return;
67
- hear(answer, say).then((value) => {
68
- if (value !== undefined && settle())
69
- resolve(value);
70
- }, (error) => fail(error instanceof Error ? error : new Error(String(error))));
71
- };
72
- });
73
- }
74
- const client = {
75
- drop(relay, topic, blob, ttlSeconds) {
76
- return ask(relay, { type: 'drop', topic, blob, ...(ttlSeconds ? { ttl: ttlSeconds } : {}) }, (answer) => {
77
- if (answer.topic !== topic)
78
- return undefined;
79
- if (answer.type === 'dropped' && typeof answer.id === 'string')
80
- return answer.id;
81
- if (answer.type === 'refused')
82
- throw new Error(`${relay} refused the knock: ${reasonOf(answer)}`);
83
- return undefined;
84
- });
85
- },
86
- async fetch(relay, topic, after = 0, pages = MAX_PAGES) {
87
- const found = [];
88
- let from = after;
89
- for (let page = 0; page < pages; page++) {
90
- const { items, more } = await ask(relay, { type: 'fetch', topic, after: from }, (answer) => answer.type === 'mail' && answer.topic === topic && Array.isArray(answer.items)
91
- ? { items: answer.items.filter(isMailItem), more: answer.more === true }
92
- : undefined);
93
- found.push(...items);
94
- if (!more || items.length === 0)
95
- break;
96
- from = Math.max(...items.map((item) => item.seq));
97
- }
98
- return found;
99
- },
100
- purge(relay, topic, sign, ids, signChallenge) {
101
- return talk(relay, (send) => send({ type: 'challenge' }), async (answer, send) => {
102
- if (answer.type === 'challenge' && typeof answer.nonce === 'string') {
103
- send({
104
- type: 'purge',
105
- topic,
106
- sign,
107
- ...(ids ? { ids: [...ids] } : {}),
108
- sig: await signChallenge(answer.nonce),
109
- });
110
- return undefined;
111
- }
112
- if (answer.topic !== topic)
113
- return undefined;
114
- if (answer.type === 'purged' && typeof answer.count === 'number')
115
- return answer.count;
116
- if (answer.type === 'refused')
117
- throw new Error(`${relay} refused to clear the inbox: ${reasonOf(answer)}`);
118
- return undefined;
119
- });
120
- },
121
- };
122
- return Object.freeze(client);
123
- }
124
- /** Why a relay refused; relays send a string */
125
- function reasonOf(answer) {
126
- return typeof answer.reason === 'string' ? answer.reason : 'no reason given';
127
- }
128
- function isMailItem(value) {
129
- return (isObject(value) &&
130
- Number.isSafeInteger(value.seq) &&
131
- typeof value.id === 'string' &&
132
- typeof value.at === 'number' &&
133
- typeof value.blob === 'string');
134
- }
135
- //# sourceMappingURL=mailbox.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mailbox.js","sourceRoot":"","sources":["../../src/network/mailbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAyC9C,+EAA+E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AC;gBACD,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK;oBAAE,OAAO,SAAS,CAAC;gBAC7C,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ;oBAAE,OAAO,MAAM,CAAC,KAAK,CAAC;gBACtF,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;oBAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,gCAAgC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;gBAC9E,OAAO,SAAS,CAAC;YACnB,CAAC,CACF,CAAC;QACJ,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED,gDAAgD;AAChD,SAAS,QAAQ,CAAC,MAA+B;IAC/C,OAAO,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,iBAAiB,CAAC;AAC/E,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,OAAO,CACL,QAAQ,CAAC,KAAK,CAAC;QACf,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC;QAC/B,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAC5B,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ;QAC5B,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAC/B,CAAC;AACJ,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Several rendezvous points behind one interface.
3
- *
4
- * A relay is a phone book, not an authority: it forwards connection offers and
5
- * never sees a version. But with exactly one of them configured there is
6
- * still, in practice, a single point of failure and a single operator who can
7
- * decide nobody gets introduced today. Pointing at several removes that without
8
- * changing what any of them can do.
9
- *
10
- * They are used all at once rather than in order. Failover would still leave two
11
- * people stranded when one is on the first relay and the other on the second;
12
- * being present on all of them means they meet wherever either is looking. The
13
- * cost is a handful of websockets, which is what a torrent client has always
14
- * done with its tracker list.
15
- *
16
- * Peers are announced once per room however many relays mention them, because a
17
- * duplicate announcement would have both sides opening a second connection.
18
- *
19
- * A room can name relays of its own: a space says where its members meet
20
- * (`sys.relays`), so two people whose apps use different relays still find
21
- * each other there. Those are joined for that room only, and dropped once no
22
- * room names them.
23
- */
24
- import { type RelayStatus, type SignalingClient, type SignalingEvents } from './signaling.js';
25
- /** A client over several relays, where a room may name relays of its own */
26
- export interface MultiSignalingClient extends Omit<SignalingClient, 'status' | 'on' | 'off'> {
27
- /** Joins a room on every relay, and on `relays` as well — joining again with a different list moves to it */
28
- readonly join: (room: string, relays?: ReadonlyArray<string>) => void;
29
- /** Every relay in use and where its socket stands */
30
- readonly relays: () => ReadonlyArray<RelayStatus>;
31
- readonly on: <K extends keyof MultiSignalingEvents>(event: K, callback: MultiSignalingEvents[K]) => void;
32
- readonly off: <K extends keyof MultiSignalingEvents>(event: K, callback: MultiSignalingEvents[K]) => void;
33
- }
34
- /** One relay's `status` becomes the whole list's */
35
- export type MultiSignalingEvents = Omit<SignalingEvents, 'status'> & {
36
- /** A relay opened, closed or is waiting to try again; carries every relay */
37
- status: (relays: ReadonlyArray<RelayStatus>) => void;
38
- };
39
- /** Creates a signaling client spanning several relays. */
40
- export declare function createMultiSignalingClient(urls: ReadonlyArray<string>, did: string): MultiSignalingClient;
41
- //# sourceMappingURL=multi-signaling.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"multi-signaling.d.ts","sourceRoot":"","sources":["../../src/network/multi-signaling.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,eAAe,EAErB,MAAM,gBAAgB,CAAC;AAExB,4EAA4E;AAC5E,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC;IAC1F,6GAA6G;IAC7G,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IACtE,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,aAAa,CAAC,WAAW,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IACzG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;CAC3G;AAED,oDAAoD;AACpD,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,eAAe,EAAE,QAAQ,CAAC,GAAG;IACnE,6EAA6E;IAC7E,MAAM,EAAE,CAAC,MAAM,EAAE,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,0DAA0D;AAC1D,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,oBAAoB,CA2LzG"}