@oxy.so/federation 1.0.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 (78) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +16 -0
  3. package/dist/cjs/.tsbuildinfo +1 -0
  4. package/dist/cjs/actorObject.js +216 -0
  5. package/dist/cjs/apContext.js +48 -0
  6. package/dist/cjs/apUri.js +132 -0
  7. package/dist/cjs/httpSignature.js +187 -0
  8. package/dist/cjs/index.js +99 -0
  9. package/dist/cjs/networkIdentity.js +487 -0
  10. package/dist/cjs/node/actorResolver.js +625 -0
  11. package/dist/cjs/node/actorRouter.js +307 -0
  12. package/dist/cjs/node/delivery.js +415 -0
  13. package/dist/cjs/node/identityBridge.js +133 -0
  14. package/dist/cjs/node/inboundDispatch.js +268 -0
  15. package/dist/cjs/node/index.js +63 -0
  16. package/dist/cjs/node/signedFetch.js +122 -0
  17. package/dist/cjs/node/webfingerRouter.js +166 -0
  18. package/dist/cjs/urls.js +55 -0
  19. package/dist/esm/.tsbuildinfo +1 -0
  20. package/dist/esm/actorObject.js +210 -0
  21. package/dist/esm/apContext.js +45 -0
  22. package/dist/esm/apUri.js +126 -0
  23. package/dist/esm/httpSignature.js +179 -0
  24. package/dist/esm/index.js +65 -0
  25. package/dist/esm/networkIdentity.js +472 -0
  26. package/dist/esm/node/actorResolver.js +620 -0
  27. package/dist/esm/node/actorRouter.js +304 -0
  28. package/dist/esm/node/delivery.js +412 -0
  29. package/dist/esm/node/identityBridge.js +130 -0
  30. package/dist/esm/node/inboundDispatch.js +263 -0
  31. package/dist/esm/node/index.js +51 -0
  32. package/dist/esm/node/signedFetch.js +119 -0
  33. package/dist/esm/node/webfingerRouter.js +163 -0
  34. package/dist/esm/urls.js +50 -0
  35. package/dist/types/.tsbuildinfo +1 -0
  36. package/dist/types/actorObject.d.ts +182 -0
  37. package/dist/types/apContext.d.ts +35 -0
  38. package/dist/types/apUri.d.ts +107 -0
  39. package/dist/types/httpSignature.d.ts +113 -0
  40. package/dist/types/index.d.ts +336 -0
  41. package/dist/types/networkIdentity.d.ts +509 -0
  42. package/dist/types/node/actorResolver.d.ts +287 -0
  43. package/dist/types/node/actorRouter.d.ts +108 -0
  44. package/dist/types/node/delivery.d.ts +248 -0
  45. package/dist/types/node/identityBridge.d.ts +84 -0
  46. package/dist/types/node/inboundDispatch.d.ts +156 -0
  47. package/dist/types/node/index.d.ts +51 -0
  48. package/dist/types/node/signedFetch.d.ts +74 -0
  49. package/dist/types/node/webfingerRouter.d.ts +62 -0
  50. package/dist/types/urls.d.ts +55 -0
  51. package/package.json +119 -0
  52. package/src/__tests__/actorObject.test.ts +258 -0
  53. package/src/__tests__/actorResolver.test.ts +252 -0
  54. package/src/__tests__/actorResolverNetworkIdentity.test.ts +297 -0
  55. package/src/__tests__/apUri.test.ts +53 -0
  56. package/src/__tests__/delivery.test.ts +432 -0
  57. package/src/__tests__/federationHost.test.ts +281 -0
  58. package/src/__tests__/httpSignature.test.ts +343 -0
  59. package/src/__tests__/inboundDispatch.test.ts +381 -0
  60. package/src/__tests__/index.test.ts +8 -0
  61. package/src/__tests__/networkIdentity.test.ts +525 -0
  62. package/src/__tests__/routers.test.ts +460 -0
  63. package/src/__tests__/urls.test.ts +26 -0
  64. package/src/actorObject.ts +313 -0
  65. package/src/apContext.ts +45 -0
  66. package/src/apUri.ts +161 -0
  67. package/src/httpSignature.ts +282 -0
  68. package/src/index.ts +419 -0
  69. package/src/networkIdentity.ts +731 -0
  70. package/src/node/actorResolver.ts +839 -0
  71. package/src/node/actorRouter.ts +438 -0
  72. package/src/node/delivery.ts +729 -0
  73. package/src/node/identityBridge.ts +230 -0
  74. package/src/node/inboundDispatch.ts +420 -0
  75. package/src/node/index.ts +136 -0
  76. package/src/node/signedFetch.ts +177 -0
  77. package/src/node/webfingerRouter.ts +226 -0
  78. package/src/urls.ts +71 -0
@@ -0,0 +1,509 @@
1
+ /**
2
+ * WHICH HOSTS REPUBLISH ANOTHER NETWORK'S ACCOUNTS, AND HOW TO READ THE REAL
3
+ * IDENTITY BACK OUT OF THEM.
4
+ *
5
+ * A BRIDGE is a fediverse host that mirrors accounts from somewhere else. The
6
+ * account it publishes as `@WIRED@mastox.eu` is not a person on mastox.eu — it is
7
+ * WIRED, on X, copied. Naming that account after the bridge tells a reader
8
+ * nothing they can act on: the hostname is an implementation detail of how the
9
+ * post reached us, and the thing they actually want to know is which account on
10
+ * which network wrote it. So an actor from a listed bridge is stored and rendered
11
+ * under the NETWORK it came from — `@wired@x.com` — exactly as an atproto actor
12
+ * with a custom-domain handle is stored under `bsky.social` rather than under the
13
+ * domain the handle happens to spell.
14
+ *
15
+ * WHY THE MECHANISM LIVES HERE BUT THE ENTRIES DO NOT
16
+ *
17
+ * Two different questions must stay separate. An app's connector DERIVES the
18
+ * identity at ingest (`createBridgeRelabeller(entries)` with entries the app
19
+ * commits and answers for), and oxy-api's `PUT /users/resolve` DECIDES
20
+ * WHETHER TO BELIEVE IT — that endpoint binds an actor URI's hostname to the
21
+ * domain the caller asserts, precisely so a service cannot claim to vouch for
22
+ * a user on a host it does not own. A bridged identity is the one case where
23
+ * those legitimately differ. The shared package ships the derivation machinery
24
+ * and network vocabulary; each side keeps its own reviewed list and they fail
25
+ * CLOSED in both directions — an app that derives for a bridge the API does
26
+ * not trust simply has its resolve refused, and a host the API trusts that no
27
+ * app derives for does nothing at all.
28
+ *
29
+ * A WRONG ENTRY HERE MISATTRIBUTES SOMEBODY'S WRITING
30
+ *
31
+ * That is a heavier failure than the blocklist's. A wrong block loses content
32
+ * and somebody complains; a wrong bridge entry silently publishes one person's
33
+ * posts under another person's name, on a network they may not even use. So
34
+ * every entry records what was actually VERIFIED against a live actor
35
+ * ({@link FederationBridgeEntry.evidence}) separately from what is merely
36
+ * ASSUMED ({@link FederationBridgeEntry.assumption}), and every entry an app
37
+ * ships should carry a stored fixture and a test that fails if its rule stops
38
+ * round-tripping. Derivation is per-ACTOR and fails closed: an actor that does
39
+ * not satisfy its bridge's rule keeps the bridge hostname, because a bridge's
40
+ * own admin and service accounts are real accounts on that host and relabelling
41
+ * them would invent an upstream person who does not exist.
42
+ *
43
+ * THIS IS NOT THE BLOCKLIST, AND MUST NEVER BE MERGED WITH IT
44
+ *
45
+ * Blocking and bridge-trust are opposite decisions about a host, and the
46
+ * blocklist wins: a blocked host is refused before any actor from it is ever
47
+ * built, so no relabel can resurrect it. Keeping them in separate structures
48
+ * means neither can be edited into the other by accident.
49
+ */
50
+ /**
51
+ * A network accounts can be bridged FROM.
52
+ *
53
+ * `domain` is the identity domain — the part after the `@` in a rendered handle,
54
+ * and the `domain` bound to a federated Oxy username. It is the network's
55
+ * canonical public host (`x.com`, not `twitter.com`), because that is what a
56
+ * reader recognises and what a profile link resolves to.
57
+ */
58
+ export interface FederationNetwork {
59
+ /** Stable key for this network (used to group bridges that mirror the same one). */
60
+ readonly id: string;
61
+ /** Human name, for logs and review output. */
62
+ readonly name: string;
63
+ /** The identity domain handles are rendered and stored under. */
64
+ readonly domain: string;
65
+ /**
66
+ * Every host a profile URL for this network can be pasted from — the canonical
67
+ * one FIRST, then aliases (`x.com` and `twitter.com` are one network;
68
+ * `instagram.com` and `www.instagram.com` differ only by a prefix the
69
+ * canonicaliser already strips).
70
+ */
71
+ readonly profileHosts: readonly string[];
72
+ /** Fixed path segments before the handle (`bsky.app/profile/<handle>` ⇒ `['profile']`). */
73
+ readonly profilePathPrefix: readonly string[];
74
+ /**
75
+ * The LOCAL PART an upstream handle is stored under in Oxy.
76
+ *
77
+ * Not the identity function: X and Instagram treat handles
78
+ * case-insensitively so they are lowered, and a default Bluesky handle drops
79
+ * its now-redundant `.bsky.social` suffix once the domain already says
80
+ * `bsky.social`. It belongs to the NETWORK rather than to any bridge entry
81
+ * because it is a protocol fact about how that network names accounts, not a
82
+ * judgement about an operator.
83
+ *
84
+ * Both the ingest path and the search path go through this ONE function.
85
+ * That is the whole point: a pasted `https://bsky.app/profile/x.bsky.social`
86
+ * has to arrive at the same username the connector stored, or search finds
87
+ * nothing and looks exactly like "we do not have that account".
88
+ */
89
+ readonly storedUsername: (handle: string) => string;
90
+ }
91
+ /**
92
+ * The networks Oxy re-labels accounts onto.
93
+ *
94
+ * Bluesky is here for a reason beyond bridging: it is the network the atproto
95
+ * connector ingests DIRECTLY, and its domain used to be a constant private to
96
+ * that connector. Both readers now take it from here, so a Bluesky account
97
+ * reaching us over atproto and the same account reaching us over ActivityPub
98
+ * through Bridgy Fed cannot end up under two different domains — which is what
99
+ * would happen if the two paths each named the network themselves.
100
+ */
101
+ export declare const FEDERATION_NETWORKS: {
102
+ readonly x: {
103
+ readonly id: "x";
104
+ readonly name: "X";
105
+ readonly domain: "x.com";
106
+ readonly profileHosts: readonly ["x.com", "twitter.com", "mobile.twitter.com", "mobile.x.com"];
107
+ readonly profilePathPrefix: readonly [];
108
+ readonly storedUsername: (handle: string) => string;
109
+ };
110
+ readonly instagram: {
111
+ readonly id: "instagram";
112
+ readonly name: "Instagram";
113
+ readonly domain: "instagram.com";
114
+ readonly profileHosts: readonly ["instagram.com"];
115
+ readonly profilePathPrefix: readonly [];
116
+ readonly storedUsername: (handle: string) => string;
117
+ };
118
+ readonly bluesky: {
119
+ readonly id: "bluesky";
120
+ readonly name: "Bluesky";
121
+ readonly domain: "bsky.social";
122
+ readonly profileHosts: readonly ["bsky.app"];
123
+ readonly profilePathPrefix: readonly ["profile"];
124
+ readonly storedUsername: (handle: string) => string;
125
+ };
126
+ };
127
+ /**
128
+ * The upstream profile URL for a handle on a network.
129
+ *
130
+ * Deliberately the SAME declaration {@link parseUpstreamProfileUrl} reads
131
+ * backwards. Rendering a link and recognising a pasted one are the same fact
132
+ * stated in two directions, and holding them as two independent tables is how
133
+ * they drift — with the failure landing on the parsing side, where a search that
134
+ * silently finds nothing is indistinguishable from "we do not have that account"
135
+ * and so nobody ever reports it.
136
+ */
137
+ export declare function upstreamProfileUrl(network: FederationNetwork, handle: string): string;
138
+ /**
139
+ * The network and handle a pasted upstream profile URL names, or `undefined` when
140
+ * it is not one.
141
+ *
142
+ * Query strings and fragments are dropped (a pasted URL usually carries tracking
143
+ * parameters) and a trailing slash is tolerated. Purely syntactic: it never
144
+ * fetches the URL — resolving a user-supplied URL by fetching it would be an SSRF
145
+ * surface, and there is nothing here that needs the network.
146
+ */
147
+ export declare function parseUpstreamProfileUrl(candidateUrl: string, networks?: readonly FederationNetwork[]): {
148
+ network: FederationNetwork;
149
+ handle: string;
150
+ } | undefined;
151
+ /** The Bluesky network's canonical identity domain — see {@link FEDERATION_NETWORKS}. */
152
+ export declare const BSKY_NETWORK_DOMAIN: "bsky.social";
153
+ /** A profile field as the actor cache stores it (only what a derivation rule reads). */
154
+ export interface BridgedActorField {
155
+ readonly name: string;
156
+ readonly value: string;
157
+ }
158
+ /**
159
+ * One FEP-fffd `proxyOf` entry: an actor stating, in machine-readable form, that
160
+ * it is a proxy for an object on another protocol.
161
+ *
162
+ * Observed on the wire (momostr.pink, 2026-08-02):
163
+ *
164
+ * "proxyOf": [{
165
+ * "protocol": "https://github.com/nostr-protocol/nostr",
166
+ * "proxied": "npub1sg6plz…",
167
+ * "authoritative": true
168
+ * }]
169
+ *
170
+ * `protocol` is a URI naming the upstream protocol, `proxied` its identifier
171
+ * there, and `authoritative` says whether this actor is the canonical
172
+ * representation rather than one copy among several.
173
+ */
174
+ export interface ProxyDeclaration {
175
+ readonly protocol: string;
176
+ readonly proxied: string;
177
+ readonly authoritative: boolean;
178
+ }
179
+ /**
180
+ * Parse an actor's `proxyOf` into well-formed declarations, dropping anything
181
+ * malformed. Pure; accepts `unknown` because it reads an untrusted document.
182
+ *
183
+ * `authoritative` DEFAULTS TO FALSE when absent. FEP-fffd leaves it optional, and
184
+ * the conservative reading is the only safe one here: the flag is what
185
+ * distinguishes "this actor IS that upstream account" from "this actor is one
186
+ * copy of it", and only the former could ever justify moving an identity.
187
+ */
188
+ export declare function readProxyDeclarations(value: unknown): ProxyDeclaration[];
189
+ /**
190
+ * Everything a derivation rule may look at. Every field is a value the caller has
191
+ * already derived and verified, so a rule never re-parses the actor document.
192
+ */
193
+ export interface NetworkIdentityCandidate {
194
+ /** The lowercase host the actor is authoritative for (post-redirect). */
195
+ readonly host: string;
196
+ /** The canonical `user@host` acct — the actor's PROTOCOL address. */
197
+ readonly acct: string;
198
+ /** `preferredUsername` verbatim, case preserved. */
199
+ readonly preferredUsername: string;
200
+ /** The actor's own `id`. */
201
+ readonly actorUri: string;
202
+ /** The AP `type` (`Person` / `Service` / `Application` / …). */
203
+ readonly actorType: string;
204
+ /** `alsoKnownAs`, verbatim (empty when the actor publishes none). */
205
+ readonly alsoKnownAs: readonly string[];
206
+ /** The actor's profile fields (PropertyValue), already sanitized. */
207
+ readonly fields: readonly BridgedActorField[];
208
+ /** The actor's FEP-fffd `proxyOf` declarations (empty when it publishes none). */
209
+ readonly proxyOf: readonly ProxyDeclaration[];
210
+ /** The actor's bio as plain text. */
211
+ readonly bio: string;
212
+ }
213
+ /**
214
+ * An actor re-labelled onto the network its identity really belongs to.
215
+ *
216
+ * `federatedUsername` MUST end with `@${instanceDomain}` — oxy-api binds a
217
+ * federated username to its domain — and the caller REFUSES a result that does
218
+ * not, rather than minting an identity oxy-api would reject.
219
+ */
220
+ export interface NetworkIdentity {
221
+ /** The canonical `<user>@<network-domain>` identity (e.g. `wired@x.com`). */
222
+ readonly federatedUsername: string;
223
+ /** The network domain the identity belongs to (e.g. `x.com`). */
224
+ readonly instanceDomain: string;
225
+ /** The bio with the bridge's own appended boilerplate removed. */
226
+ readonly bio: string;
227
+ }
228
+ /**
229
+ * App-supplied re-labelling of an ingested actor onto its real network. Returns
230
+ * `undefined` for anything not recognised — which is the overwhelmingly common
231
+ * case, and the correct answer whenever the derivation is not certain.
232
+ */
233
+ export type DeriveNetworkIdentity = (candidate: NetworkIdentityCandidate) => NetworkIdentity | undefined;
234
+ /**
235
+ * Whether the people mirrored by a bridge asked to be.
236
+ *
237
+ * Recorded because it is the question a mirrored person asks first, and because
238
+ * it changes what a reasonable response to a complaint is. It deliberately does
239
+ * NOT gate the relabel: an unconsented mirror is still that person's writing, and
240
+ * attributing it to them is more honest than attributing it to the bridge.
241
+ *
242
+ * - `opt-in` the upstream account took an action to enable the bridge.
243
+ * - `unconsented` the bridge mirrors without asking; removal is on request.
244
+ */
245
+ export type BridgeConsentModel = 'opt-in' | 'unconsented';
246
+ /** How the upstream handle is recovered from a bridged actor. */
247
+ export type BridgeDerivation = (candidate: NetworkIdentityCandidate) => string | undefined;
248
+ /** One reviewed bridge. */
249
+ export interface FederationBridgeEntry {
250
+ /**
251
+ * The bridge's host, CANONICAL — lowercase, bare host, no scheme, no `www.`.
252
+ * Matching is exact canonical-host membership, so a subdomain is a different
253
+ * host and needs its own reviewed entry.
254
+ */
255
+ readonly host: string;
256
+ /** The network accounts here are mirrored FROM. */
257
+ readonly network: FederationNetwork;
258
+ /** Who runs the bridge, as they identify themselves. */
259
+ readonly operator: string;
260
+ /** The bridge software, as its own nodeinfo reports it. */
261
+ readonly software: string;
262
+ /**
263
+ * Recover the upstream handle from ONE actor, or `undefined` when this actor
264
+ * does not satisfy the rule — which is how the bridge's own admin/service
265
+ * accounts, and anything whose shape changed, are left alone.
266
+ */
267
+ readonly derive: BridgeDerivation;
268
+ /**
269
+ * What to do with the recovered handle's case before storing it.
270
+ *
271
+ * - `lowercase` the upstream network treats handles case-insensitively, so
272
+ * lowercasing loses no addressability and keeps the handle rendering like
273
+ * every other federated handle (AP acct normalisation lowercases them all).
274
+ * - `preserve` the handle is a DNS name and is already canonical; touching it
275
+ * would change what it addresses.
276
+ */
277
+ readonly caseRule: 'lowercase' | 'preserve';
278
+ /**
279
+ * Whether re-labelling this bridge's actors is SAFE TO APPLY yet.
280
+ *
281
+ * Re-labelling does not merely coexist with duplicates, it MANUFACTURES them:
282
+ * two bridges of one network that render as visibly different accounts today
283
+ * both render the SAME handle afterwards — identical, adjacent in search and in
284
+ * follow lists, and reading as a bug in a way the status quo does not. Where a
285
+ * network's collision set is non-empty, the merge has to land first.
286
+ *
287
+ * - `enabled` the identity moves.
288
+ * - `pending_dedup` the entry is committed and reviewed, and deliberately
289
+ * INERT: the derivation is exercised by tests but no actor
290
+ * is re-labelled, because doing so would create twins.
291
+ */
292
+ readonly relabel: 'enabled' | 'pending_dedup';
293
+ /**
294
+ * How stable the upstream identifier this rule derives actually is.
295
+ *
296
+ * - `stable` an immutable upstream id (an atproto DID, an ORCID iD). Two
297
+ * rows sharing it are the same account, permanently.
298
+ * - `recyclable` a HANDLE. X and Instagram release abandoned handles, so two
299
+ * bridges capturing years apart can derive the same key for two
300
+ * different humans, and Bluesky handles are mutable — which is
301
+ * exactly why the atproto connector keys on the DID instead.
302
+ *
303
+ * Named rather than silently carried: it is the residual risk a merge inherits,
304
+ * and a reader deciding whether to trust a merge needs it stated.
305
+ */
306
+ readonly upstreamIdStability: 'stable' | 'recyclable';
307
+ /**
308
+ * The bridge's own appended boilerplate, to strip from the bio.
309
+ *
310
+ * Per-bridge and anchored, never a general "looks like boilerplate" heuristic:
311
+ * a pattern that does not match leaves the bio EXACTLY as written, which is the
312
+ * only safe behaviour when the alternative is deleting a line the author wrote.
313
+ * Several bridges emit the same notice in more than one language, so this is a
314
+ * list and every variant that has been observed is listed.
315
+ */
316
+ readonly boilerplate: readonly RegExp[];
317
+ /** Whether the mirrored accounts asked to be mirrored. */
318
+ readonly consent: BridgeConsentModel;
319
+ /** What was VERIFIED against a live actor, and where the fixture came from. */
320
+ readonly evidence: string;
321
+ /**
322
+ * What is ASSUMED rather than verified. Empty string means the derivation reads
323
+ * an assertion the actor itself publishes, so nothing is being guessed.
324
+ */
325
+ readonly assumption: string;
326
+ /** `YYYY-MM-DD` — the day the entry took effect. */
327
+ readonly since: string;
328
+ }
329
+ /**
330
+ * Read the upstream handle out of a named profile field that links to the
331
+ * upstream profile — the STRONGEST rule available, because the bridge is
332
+ * publishing a machine-readable assertion of which account this mirrors rather
333
+ * than leaving us to infer it from the username.
334
+ */
335
+ export declare function upstreamHandleFromProfileField(options: {
336
+ readonly fieldName: string;
337
+ readonly hosts: readonly string[];
338
+ /** Fixed path segments before the handle (`bsky.app/profile/<handle>` ⇒ `['profile']`). */
339
+ readonly pathPrefix?: readonly string[];
340
+ }): BridgeDerivation;
341
+ /**
342
+ * Read the upstream handle out of `alsoKnownAs` profile URLs — the shape where an
343
+ * actor publishes a profile link there rather than in a named profile field.
344
+ *
345
+ * ⚠ UNMATCHED BY ANY ACTOR WE ACTUALLY HOLD. On all three Bridgy Fed actors
346
+ * captured from production, `alsoKnownAs` contains ONLY the atproto DID
347
+ * (`["did:plc:…"]`) and no `bsky.app` URL, so this returns `undefined` for the
348
+ * entire real corpus; the shipped Bridgy entry reads the `Web site` profile
349
+ * field, which every one of them does carry. Written against the documented
350
+ * shape rather than an observed one — so verify against a live actor before
351
+ * building on it, and do not read a green test suite as evidence that it fires.
352
+ *
353
+ * `alsoKnownAs` is also NOT a generic upstream backlink. It is one on Bridgy,
354
+ * but on the stock-Mastodon mirror farms it is a Mastodon MIGRATION pointer at a
355
+ * sibling farm domain — following it there would attribute an account to
356
+ * whatever that pointer happens to name. Only use this where a reviewed entry
357
+ * states that the bridge publishes an upstream link in that field.
358
+ */
359
+ export declare function upstreamHandleFromAlsoKnownAs(options: {
360
+ readonly hosts: readonly string[];
361
+ /** Fixed path segments before the handle (`bsky.app/profile/<handle>` ⇒ `['profile']`). */
362
+ readonly pathPrefix?: readonly string[];
363
+ }): BridgeDerivation;
364
+ /**
365
+ * Read the upstream identifier out of an actor's FEP-fffd `proxyOf` declaration.
366
+ *
367
+ * THIS IS A STRATEGY A REVIEWED ENTRY OPTS INTO — NOT A REGISTRY-FREE LANE, AND
368
+ * THE DIFFERENCE IS THE WHOLE SECURITY ARGUMENT.
369
+ *
370
+ * `proxyOf` is attractive precisely because it is self-describing: the actor
371
+ * states what it proxies, in a ratified format, with no list to maintain. That
372
+ * is exactly why it cannot be believed on its own. It is a claim made by an
373
+ * UNTRUSTED REMOTE ACTOR about its own identity, and every field in it is
374
+ * attacker-controlled. Honouring it wherever it appears would mean any actor on
375
+ * any instance could publish
376
+ *
377
+ * "proxyOf": [{ "protocol": "…", "proxied": "elonmusk", "authoritative": true }]
378
+ *
379
+ * and be stored, rendered and searchable as that person on that network. The
380
+ * reviewed bridge list is not bureaucracy around this; it IS the thing that
381
+ * makes a re-attribution believable, because we checked who runs the host.
382
+ *
383
+ * Inside an entry the claim is safe for the same reason the entry's other rules
384
+ * are: we already decided we believe this operator about who it mirrors. So the
385
+ * strategy exists, it is tested, and it is reachable only from a host somebody
386
+ * reviewed.
387
+ *
388
+ * `authoritative` must be true — a non-authoritative proxy says the actor is one
389
+ * copy of the upstream object, not that it stands in for it.
390
+ *
391
+ * NOTHING WE INGEST USES THIS YET. The only actors in our corpus that publish
392
+ * `proxyOf` are the two Nostr bridges, and Nostr identities are npubs with no
393
+ * `@handle@domain` form to re-label onto, so no shipped entry names it. It is
394
+ * here so a bridge that adopts FEP-fffd needs an entry rather than new code —
395
+ * do not read its passing tests as evidence that it fires in production.
396
+ */
397
+ export declare function upstreamHandleFromProxyOf(options: {
398
+ /** The protocol URIs this entry accepts, exactly as the actor spells them. */
399
+ readonly protocols: readonly string[];
400
+ /** Map the raw `proxied` identifier to an upstream handle; omit for verbatim. */
401
+ readonly handleFromProxied?: (proxied: string) => string | undefined;
402
+ }): BridgeDerivation;
403
+ /**
404
+ * Use the actor's own `preferredUsername` as the upstream handle, but ONLY for an
405
+ * actor that carries one of the bridge's mirror notices.
406
+ *
407
+ * The notice is what distinguishes a mirrored account from a real account on the
408
+ * bridge host: the operator's own admin account lives there too and is not a
409
+ * mirror of anything. Without the marker requirement this rule would relabel that
410
+ * person onto a network they may not even be on.
411
+ */
412
+ /**
413
+ * A mirror identified by the actor DECLARING ITSELF AUTOMATED, with the handle
414
+ * read from `preferredUsername`.
415
+ *
416
+ * For a bridge that runs stock server software there is nothing to fingerprint:
417
+ * somebody points a mirror bot at an ordinary instance and the result is
418
+ * indistinguishable from any other server. The tempting fallback is to match the
419
+ * per-account notice such a bridge writes into each bio — and that fails, because
420
+ * a notice is free text with LANGUAGES. One deployment served the same sentence
421
+ * in English, French and Spanish; an entry listing two of them silently left
422
+ * every account of the third under the bridge's own hostname, with the notice
423
+ * still in its bio, looking exactly like an ordinary account.
424
+ *
425
+ * `type` is the same claim without the prose. ActivityPub already distinguishes
426
+ * an automated actor (`Service`/`Application`) from a `Person`, every mirror is
427
+ * published as one, and the operator's own account is not — so the bridge's
428
+ * machine-readable declaration replaces a guess about wording. It is still a
429
+ * per-ACTOR proof, which is what keeps a human on that host from being
430
+ * re-attributed to another network.
431
+ *
432
+ * NOT a general "this actor is a bot" rule: it is only ever consulted for a host
433
+ * already reviewed into a bridge policy. Plenty of ordinary fediverse accounts
434
+ * are `Service`, and none of them are on a listed bridge.
435
+ */
436
+ export declare function upstreamHandleFromAutomatedActor(): BridgeDerivation;
437
+ export declare function upstreamHandleFromPreferredUsername(markers: readonly RegExp[]): BridgeDerivation;
438
+ /**
439
+ * The username a Bluesky handle is stored under, given that the instance domain
440
+ * is ALWAYS `bsky.social`.
441
+ *
442
+ * A Bluesky handle is a whole DNS name identifying the account, not a `local@host`
443
+ * address, so the account is on the Bluesky network however many labels the handle
444
+ * has. Once the instance domain is already `bsky.social`, the `.bsky.social`
445
+ * suffix on a DEFAULT handle is redundant and is dropped — otherwise the handle
446
+ * renders as the doubled `@skylee1.bsky.social@bsky.social`. A CUSTOM domain
447
+ * handle is not a `.bsky.social` handle, so it is kept whole:
448
+ *
449
+ * - `skylee1.bsky.social` → `skylee1`
450
+ * - `gothamist.com` → `gothamist.com`
451
+ * - `mayor.nyc.gov` → `mayor.nyc.gov` (never the bogus `nyc.gov` instance)
452
+ * - `jay.bsky.team` → `jay.bsky.team` (`.bsky.team` is not `.bsky.social`)
453
+ *
454
+ * Exported, and used by BOTH paths a Bluesky account can reach us by — the atproto
455
+ * connector reading it directly, and the Bridgy Fed entry below reading it over
456
+ * ActivityPub. That is the point: the same account arriving by two protocols has
457
+ * to produce the same username or the two rows are two people.
458
+ *
459
+ * `bsky.social` itself is guarded: stripping would leave an empty username, so the
460
+ * whole handle is kept.
461
+ */
462
+ export declare function blueskyUsernameFromHandle(handle: string): string;
463
+ /** A reviewed bridge registry, and the readers an app drives it with. */
464
+ export interface BridgeRelabeller {
465
+ /** The reviewed entry for a host, or `undefined` — most hosts are not bridges. */
466
+ findBridge: (host: string) => FederationBridgeEntry | undefined;
467
+ /**
468
+ * Whether `actorHost` is a reviewed bridge mirroring `networkDomain`. Both
469
+ * halves must match: a bridge vouches ONLY for the one network it mirrors, so
470
+ * being listed is never on its own a licence to claim any domain.
471
+ */
472
+ vouchesForNetwork: (actorHost: string, networkDomain: string) => boolean;
473
+ /** The {@link DeriveNetworkIdentity} hook an ingest path installs. */
474
+ deriveNetworkIdentity: DeriveNetworkIdentity;
475
+ }
476
+ /**
477
+ * Build the readers for a set of reviewed bridge entries.
478
+ *
479
+ * The entries are a PARAMETER and this package ships none. Deciding that a given
480
+ * operator may be trusted to re-attribute somebody's account is a moderation
481
+ * judgement, not a platform fact — bake one app's list in here and every Oxy app
482
+ * silently inherits it, including consent calls their owners never made. Oxy holds
483
+ * the capability; the app holds the policy, commits it, and answers for it.
484
+ *
485
+ * A blocked host must be refused by the caller's domain policy BEFORE this is
486
+ * consulted: blocking and bridge-trust are opposite decisions about a host and the
487
+ * block wins. No blocklist is accepted here, so this can never be mistaken for the
488
+ * place that decision is made.
489
+ */
490
+ export declare function createBridgeRelabeller(entries: readonly FederationBridgeEntry[]): BridgeRelabeller;
491
+ /** Strip a bridge's own boilerplate, leaving anything it does not match untouched. */
492
+ export declare function stripBridgeBoilerplate(bio: string, entry: FederationBridgeEntry): string;
493
+ /**
494
+ * The exact federated username Oxy stores for a pasted upstream profile URL —
495
+ * `https://x.com/NASA` → `nasa@x.com`, `https://bsky.app/profile/alice.bsky.social`
496
+ * → `alice@bsky.social` — or `undefined` when the URL names no known network.
497
+ *
498
+ * This is the SEARCH direction of the same declaration the ingest path reads
499
+ * forwards, and it deliberately routes through `network.storedUsername` rather
500
+ * than reimplementing the normalisation. A search built on a second, parallel
501
+ * rule would work for X (where the rule is just lowercasing) and fail silently
502
+ * for Bluesky (where a default handle's `.bsky.social` suffix is dropped),
503
+ * returning nothing for an account we hold — a result indistinguishable from
504
+ * "we do not have that account", which is why nobody would ever report it.
505
+ *
506
+ * Purely syntactic: it never fetches the URL. Resolving a user-supplied URL by
507
+ * fetching it would be an SSRF surface, and nothing here needs the network.
508
+ */
509
+ export declare function federatedUsernameFromUpstreamUrl(candidateUrl: string, networks?: readonly FederationNetwork[]): string | undefined;